@@ -88,7 +88,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
88
88
LOGE (1 , "Error: cannot open the video codec!" );
89
89
return ;
90
90
}
91
- gVideoCodecCtxDepList [l_i ]-> dump_dependency = 1 ;
92
91
#endif
93
92
/***
94
93
The following section are initialization for decoding
@@ -130,7 +129,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
130
129
LOGI (10 , "SELECTIVE_DECODING is disabled" );
131
130
gVideoCodecCtxList [l_i ]-> allow_selective_decoding = 0 ;
132
131
#endif
133
- gVideoCodecCtxList [l_i ]-> dump_dependency = 0 ;
134
132
/*set the debug option*/
135
133
gVideoCodecCtxList [l_i ]-> debug_selective = p_debug ;
136
134
if (gVideoCodecCtxList [l_i ]-> debug_selective == 1 ) {
@@ -575,6 +573,30 @@ static void compute_mb_mask_from_inter_frame_dependency(int _stFrame, int _edFra
575
573
LOGI (10 , "end of compute_mb_mask_from_inter_frame_dependency" );
576
574
}
577
575
576
+ /*called by decoding thread, to check if needs to wait for dumping thread to dump dependency*/
577
+ /*or called by dumping thread, see if it needs to generate dependency files for this gop*/
578
+ /*return 1 if it's complete; otherwise, return 0*/
579
+ int if_dependency_complete (int p_videoFileIndex , int p_gopNum ) {
580
+ char l_depGopRecFileName [100 ], l_depIntraFileName [100 ], l_depInterFileName [100 ], l_depMbPosFileName [100 ], l_depDcpFileName [100 ];
581
+ FILE * lGopF ;
582
+ int ret ;
583
+ /*check if the dependency files exist, if not, we'll need to dump the dependencies*/
584
+ sprintf (l_depGopRecFileName , "./%s_goprec_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNum );
585
+ sprintf (l_depIntraFileName , "./%s_intra_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNum );
586
+ sprintf (l_depInterFileName , "./%s_inter_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNum );
587
+ sprintf (l_depMbPosFileName , "./%s_mbpos_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNum );
588
+ sprintf (l_depDcpFileName , "./%s_dcp_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNum );
589
+ if ((!if_file_exists (l_depGopRecFileName )) || (!if_file_exists (l_depIntraFileName )) || (!if_file_exists (l_depInterFileName )) || (!if_file_exists (l_depMbPosFileName )) || (!if_file_exists (l_depDcpFileName ))) {
590
+ return 0 ;
591
+ } else {
592
+ //further check if the gop file contains both start frame and end frame
593
+ lGopF = fopen (l_depGopRecFileName , "r" );
594
+ ret = load_gop_info (lGopF );
595
+ fclose (lGopF );
596
+ return ((ret == 0 )?1 :0 );
597
+ }
598
+ }
599
+
578
600
void dep_decode_a_video_packet (int p_videoFileIndex ) {
579
601
char l_depGopRecFileName [100 ], l_depIntraFileName [100 ], l_depInterFileName [100 ], l_depMbPosFileName [100 ], l_depDcpFileName [100 ];
580
602
AVFrame * l_videoFrame = avcodec_alloc_frame ();
@@ -627,21 +649,31 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
627
649
remove (l_depMbPosFileName );
628
650
remove (l_depDcpFileName );
629
651
#endif
630
- if ((!if_file_exists (l_depGopRecFileName )) || (!if_file_exists (l_depIntraFileName )) || (!if_file_exists (l_depInterFileName )) || (!if_file_exists (l_depMbPosFileName )) || (!if_file_exists (l_depDcpFileName ))) {
631
- //TODO: we should also check l_depGopRecFileName file content, see if it actually contains both GOP start and end frame
632
- //if any of the dependency files are missing, we still do dumping
652
+ gVideoCodecCtxDepList [p_videoFileIndex ]-> dump_dependency = 1 ;
653
+ if ((if_file_exists (l_depGopRecFileName )) && (if_file_exists (l_depIntraFileName )) && (if_file_exists (l_depInterFileName )) && (if_file_exists (l_depMbPosFileName )) && (if_file_exists (l_depDcpFileName ))) {
654
+ //if all files exist, further check l_depGopRecFileName file content, see if it actually contains both GOP start and end frame
655
+ gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF = fopen (l_depGopRecFileName , "r" );
656
+ if (load_gop_info (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF ) != 0 ) {
657
+ //the file content is complete, don't dump dependency
658
+ gVideoCodecCtxDepList [p_videoFileIndex ]-> dump_dependency = 0 ;
659
+ }
660
+ fclose (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF );
661
+ }
662
+ if (gVideoCodecCtxDepList [p_videoFileIndex ]-> dump_dependency ) {
633
663
packet_queue_init (& gVideoPacketQueueList [p_videoFileIndex ]); //initialize the packet queue
634
664
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF = fopen (l_depGopRecFileName , "w" );
635
665
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbPosF = fopen (l_depMbPosFileName , "w" );
636
666
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_dcPredF = fopen (l_depDcpFileName , "w" );
637
667
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_intraDepF = fopen (l_depIntraFileName , "w" );
638
668
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_interDepF = fopen (l_depInterFileName , "w" );
669
+ //dump the start frame number for the new gop
670
+ fprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF , "%d:" , gVideoCodecCtxDepList [p_videoFileIndex ]-> dep_video_packet_num );
639
671
}
640
- //dump the start frame number for the new gop
641
- fprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF , "%d:" , gVideoCodecCtxDepList [p_videoFileIndex ]-> dep_video_packet_num );
642
672
}
643
673
/*dump the dependency info*/
644
- avcodec_decode_video2_dep (gVideoCodecCtxDepList [p_videoFileIndex ], l_videoFrame , & l_numOfDecodedFrames , & gVideoPacketDepList [p_videoFileIndex ]);
674
+ if (gVideoCodecCtxDepList [p_videoFileIndex ]-> dump_dependency ) {
675
+ avcodec_decode_video2_dep (gVideoCodecCtxDepList [p_videoFileIndex ], l_videoFrame , & l_numOfDecodedFrames , & gVideoPacketDepList [p_videoFileIndex ]);
676
+ }
645
677
//av_free_packet(&gVideoPacketDepList[p_videoFileIndex]);
646
678
break ;
647
679
} else {
@@ -886,25 +918,25 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
886
918
av_free (l_videoFrame );
887
919
}
888
920
889
- /*load the gop information*/
890
- void load_gop_info (int p_videoFileIndex , FILE * p_gopRecFile ) {
921
+ /*load the gop information, return 0 if everything goes well; otherwise, return a non-zero value */
922
+ int load_gop_info (FILE * p_gopRecFile ) {
891
923
char l_gopRecLine [50 ];
892
924
char * l_aToken ;
893
925
int l_stFrame = 0 , l_edFrame = 0 ;
894
- LOGI (10 , "load gop info starts: %d, %d" , gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num , g_decode_gop_num );
895
926
if (fgets (l_gopRecLine , 50 , p_gopRecFile ) == NULL )
896
- return ;
927
+ return -1 ;
897
928
if ((l_aToken = strtok (l_gopRecLine , ":" )) != NULL )
898
929
l_stFrame = atoi (l_aToken );
899
930
else
900
- return ;
931
+ return -1 ;
901
932
if ((l_aToken = strtok (NULL , ":" )) != NULL )
902
933
l_edFrame = atoi (l_aToken );
903
934
else
904
- return ;
935
+ return -1 ;
905
936
gGopStart = l_stFrame ;
906
937
gGopEnd = l_edFrame ;
907
- LOGI (10 , "load gop info ends: %d" , p_videoFileIndex );
938
+ LOGI (10 , "load gop info ends: %d-%d" , gGopStart , gGopEnd );
939
+ return 0 ;
908
940
}
909
941
910
942
/*load the pre computation for a gop and also compute the inter frame dependency for a gop*/
0 commit comments