Skip to content

Commit 8784744

Browse files
committed
further dev for spreading the files
1 parent 39409d0 commit 8784744

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed

dependency.c

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
8888
LOGE(1, "Error: cannot open the video codec!");
8989
return;
9090
}
91-
gVideoCodecCtxDepList[l_i]->dump_dependency = 1;
9291
#endif
9392
/***
9493
The following section are initialization for decoding
@@ -130,7 +129,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
130129
LOGI(10, "SELECTIVE_DECODING is disabled");
131130
gVideoCodecCtxList[l_i]->allow_selective_decoding = 0;
132131
#endif
133-
gVideoCodecCtxList[l_i]->dump_dependency = 0;
134132
/*set the debug option*/
135133
gVideoCodecCtxList[l_i]->debug_selective = p_debug;
136134
if (gVideoCodecCtxList[l_i]->debug_selective == 1) {
@@ -575,6 +573,30 @@ static void compute_mb_mask_from_inter_frame_dependency(int _stFrame, int _edFra
575573
LOGI(10, "end of compute_mb_mask_from_inter_frame_dependency");
576574
}
577575

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+
578600
void dep_decode_a_video_packet(int p_videoFileIndex) {
579601
char l_depGopRecFileName[100], l_depIntraFileName[100], l_depInterFileName[100], l_depMbPosFileName[100], l_depDcpFileName[100];
580602
AVFrame *l_videoFrame = avcodec_alloc_frame();
@@ -627,21 +649,31 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
627649
remove(l_depMbPosFileName);
628650
remove(l_depDcpFileName);
629651
#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) {
633663
packet_queue_init(&gVideoPacketQueueList[p_videoFileIndex]); //initialize the packet queue
634664
gVideoCodecCtxDepList[p_videoFileIndex]->g_gopF = fopen(l_depGopRecFileName, "w");
635665
gVideoCodecCtxDepList[p_videoFileIndex]->g_mbPosF = fopen(l_depMbPosFileName, "w");
636666
gVideoCodecCtxDepList[p_videoFileIndex]->g_dcPredF = fopen(l_depDcpFileName, "w");
637667
gVideoCodecCtxDepList[p_videoFileIndex]->g_intraDepF = fopen(l_depIntraFileName, "w");
638668
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);
639671
}
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);
642672
}
643673
/*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+
}
645677
//av_free_packet(&gVideoPacketDepList[p_videoFileIndex]);
646678
break;
647679
} else {
@@ -886,25 +918,25 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
886918
av_free(l_videoFrame);
887919
}
888920

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) {
891923
char l_gopRecLine[50];
892924
char *l_aToken;
893925
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);
895926
if (fgets(l_gopRecLine, 50, p_gopRecFile) == NULL)
896-
return;
927+
return -1;
897928
if ((l_aToken = strtok(l_gopRecLine, ":")) != NULL)
898929
l_stFrame = atoi(l_aToken);
899930
else
900-
return;
931+
return -1;
901932
if ((l_aToken = strtok(NULL, ":")) != NULL)
902933
l_edFrame = atoi(l_aToken);
903934
else
904-
return;
935+
return -1;
905936
gGopStart = l_stFrame;
906937
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;
908940
}
909941

910942
/*load the pre computation for a gop and also compute the inter frame dependency for a gop*/

dependency.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void free_selected_decoding_fields(int p_videoFileIndex, int _mbHeight);
102102
void dump_frame_to_file(int _frameNum);
103103
void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _roiEdH, int _roiEdW);
104104
void dep_decode_a_video_packet(int p_videoFileIndex);
105-
void load_gop_info(int p_videoFileIndex, FILE* p_gopRecFile);
105+
int load_gop_info(FILE* p_gopRecFile);
106+
int if_dependency_complete(int p_videoFileIndex, int p_gopNum);
106107
void prepare_decode_of_gop(int p_videoFileIndex, int _stFrame, int _edFrame, int _roiSh, int _roiSw, int _roiEh, int _roiEw);
107108

108109

ffplay.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ void *decode_video(void *arg);
6565

6666
static void wait_get_dependency() {
6767
/*wait for the dump dependency thread to finish dumping dependency info first before start decoding a frame*/
68-
if (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->dump_dependency) {
68+
//if (if_dependency_complete(gCurrentDecodingVideoFileIndex, g_decode_gop_num)) {
6969
while (g_decode_gop_num >= gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
7070
/*[TODO]it might be more appropriate to use some sort of signal*/
7171
usleep(50);
7272
}
7373
LOGI(10, "%d:%d:%d", gNumOfGop, g_decode_gop_num, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num);
74-
}
74+
//}
7575
}
7676

7777
/*for testing: we dump the decoded frame to a file: here (_roiSh, _roiSw) and (_roiEh, _roiEw) are in pixel*/
@@ -90,7 +90,7 @@ static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float
9090
wait_get_dependency();
9191
sprintf(l_depGopRecFileName, "./%s_goprec_gop%d.txt", gVideoFileNameList[gCurrentDecodingVideoFileIndex], g_decode_gop_num);
9292
gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF = fopen(l_depGopRecFileName, "r");
93-
load_gop_info(gCurrentDecodingVideoFileIndex, gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
93+
load_gop_info(gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
9494
}
9595
if (gVideoPacketNum == gGopStart) {
9696
//start of a gop
@@ -146,7 +146,7 @@ static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float
146146
wait_get_dependency();
147147
sprintf(l_depGopRecFileName, "./%s_goprec_gop%d.txt", gVideoFileNameList[gCurrentDecodingVideoFileIndex], g_decode_gop_num);
148148
gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF = fopen(l_depGopRecFileName, "r");
149-
load_gop_info(gCurrentDecodingVideoFileIndex, gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
149+
load_gop_info(gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
150150
}
151151
}
152152

@@ -156,13 +156,6 @@ static void andzop_init(char **pFileNameList, int pDebug) {
156156
gVideoPacketNum = 0;
157157
gNumOfGop = 0;
158158
#ifdef SELECTIVE_DECODING
159-
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
160-
LOGI(10, "load gop info for %d out of %d", l_i, gNumOfVideoFiles);
161-
if (!gVideoCodecCtxList[l_i]->dump_dependency) {
162-
load_gop_info(l_i, gVideoCodecCtxList[l_i]->g_gopF);
163-
}
164-
}
165-
LOGI(10, "load gop info done for all");
166159
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
167160
LOGI(10, "allocate_selected_decoding_fields for %d", l_i);
168161
l_mbH = (gVideoCodecCtxList[l_i]->height + 15) / 16;
@@ -268,20 +261,16 @@ int main(int argc, char **argv) {
268261
gNumOfVideoFiles = argc-2;
269262
andzop_init(&argv[2], l_i);
270263

271-
if (gVideoCodecCtxList[0]->dump_dependency) {
272-
LOGI(10, "initialize dumping thread");
273-
gDepDumpThreadList = (pthread_t*)malloc((argc-2)*sizeof(pthread_t));
274-
gDumpThreadParams = (DUMP_DEP_PARAMS *)malloc(sizeof(DUMP_DEP_PARAMS)*(argc-2));
275-
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
276-
if (gVideoCodecCtxList[l_i]->dump_dependency) {
277-
/*if we need to dump dependency, start a background thread for it*/
278-
gDumpThreadParams[l_i].videoFileIndex = l_i;
279-
if (pthread_create(&gDepDumpThreadList[l_i], NULL, dump_dependency_function, (void *)&gDumpThreadParams[l_i])) {
280-
LOGE(1, "Error: failed to create a native thread for dumping dependency");
281-
}
282-
LOGI(10, "tttttt: dependency dumping thread started! tttttt");
283-
}
264+
LOGI(10, "initialize dumping thread");
265+
gDepDumpThreadList = (pthread_t*)malloc((argc-2)*sizeof(pthread_t));
266+
gDumpThreadParams = (DUMP_DEP_PARAMS *)malloc(sizeof(DUMP_DEP_PARAMS)*(argc-2));
267+
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
268+
/*start a background thread for dependency dumping*/
269+
gDumpThreadParams[l_i].videoFileIndex = l_i;
270+
if (pthread_create(&gDepDumpThreadList[l_i], NULL, dump_dependency_function, (void *)&gDumpThreadParams[l_i])) {
271+
LOGE(1, "Error: failed to create a native thread for dumping dependency");
284272
}
273+
LOGI(10, "tttttt: dependency dumping thread started! tttttt");
285274
}
286275
LOGI(10, "create decoding thread");
287276
if (pthread_create(&gVideoDecodeThread, NULL, decode_video, NULL)) {
@@ -291,11 +280,8 @@ int main(int argc, char **argv) {
291280
}
292281

293282
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
294-
LOGI(10, "access gVideoCodecCtxList[%d] of %d", l_i, gNumOfVideoFiles);
295-
if (gVideoCodecCtxList[l_i]->dump_dependency) {
296-
LOGI(10, "join a dep dump thread");
297-
pthread_join(gDepDumpThreadList[l_i], NULL);
298-
}
283+
LOGI(10, "join a dep dump thread");
284+
pthread_join(gDepDumpThreadList[l_i], NULL);
299285
}
300286
LOGI(10, "join decoding thread");
301287
pthread_join(gVideoDecodeThread, NULL);

0 commit comments

Comments
 (0)