Skip to content

Commit 344a8e3

Browse files
committed
intra-frame dependency computation doesn't match on second gop onwards
1 parent 6587231 commit 344a8e3

File tree

3 files changed

+88
-19
lines changed

3 files changed

+88
-19
lines changed

dependency.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,10 @@ if we know the roi for the entire GOP, we can pre-calculate the needed mbs at ev
738738
static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, int _stFrame, int _edFrame, int _stH, int _stW, int _edH, int _edW) {
739739
int l_i, l_j, l_k, l_m;
740740
int l_mbHeight, l_mbWidth;
741-
//FILE *tf, *tf1;
742-
//tf = fopen("test1.txt", "w");
741+
FILE *tf, *tf1;
742+
char logFileName[100];
743+
sprintf(logFileName, "test1_%d.txt", _stFrame);
744+
tf = fopen(logFileName, "w");
743745
//tf1 = fopen("test2.txt", "w");
744746
l_mbHeight = (gVideoCodecCtxList[p_videoFileIndex]->height + 15) / 16;
745747
l_mbWidth = (gVideoCodecCtxList[p_videoFileIndex]->width + 15) / 16;
@@ -774,7 +776,7 @@ static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, in
774776
} else
775777
if (((*interDepMapMove) == 0) && (*(interDepMapMove+1) == 0)) {
776778
} else {
777-
//fprintf(tf, "%d,%d,%d,%d,%d,%d\n", l_i, l_j, l_k, l_m, *interDepMapMove, *(interDepMapMove+1));
779+
fprintf(tf, "%d,%d,%d,%d,%d,%d\n", l_i, l_j, l_k, l_m, *interDepMapMove, *(interDepMapMove+1));
778780
//fprintf(tf, "%d,%d,%d,%d,%d\n", l_i, l_j, l_k, *interDepMapMove, *(interDepMapMove+1));
779781
interDepMask[l_i - 1 - _stFrame][*interDepMapMove][*(interDepMapMove+1)] = 1;
780782
}
@@ -786,8 +788,10 @@ static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, in
786788
}
787789
}
788790
}
789-
//fclose(tf);
791+
fclose(tf);
790792
//fclose(tf1);
793+
//we can unload the inter frame dependency file here
794+
unload_inter_frame_mb_dependency();
791795
LOGI(10, "end of compute_mb_mask_from_inter_frame_dependency");
792796
}
793797

@@ -944,6 +948,9 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
944948
if ((aToken = strtok(NULL, ":")) != NULL)
945949
l_idxW = atoi(aToken);
946950
//get the dependency mb
951+
if ((l_idxF == 18) && (l_idxH == 4) && (l_idxW == 0)) {
952+
LOGI(1, "line: %s", aLine);
953+
}
947954
do {
948955
aToken = strtok(NULL, ":");
949956
if (aToken != NULL) l_depH = (unsigned char) atoi(aToken);
@@ -952,23 +959,50 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
952959
if (aToken != NULL) l_depW = (unsigned char) atoi(aToken);
953960
else break;
954961
//put the dependencies into the array
955-
if (l_depH == l_idxH - 1 && l_depW == l_idxW) {
962+
if ((l_depH == l_idxH - 1) && (l_depW == l_idxW)) {
956963
intraDep[0] = l_depH;
957964
intraDep[1] = l_depW;
958-
} else if (l_depH == l_idxH - 1 && l_depW == l_idxW + 1) {
965+
} else if ((l_depH == l_idxH - 1) && (l_depW == l_idxW + 1)) {
959966
intraDep[2] = l_depH;
960967
intraDep[3] = l_depW;
961-
} else if (l_depH == l_idxH && l_depW == l_idxW - 1) {
968+
} else if ((l_depH == l_idxH) && (l_depW == l_idxW - 1)) {
962969
intraDep[4] = l_depH;
963970
intraDep[5] = l_depW;
964971
} else {
965972
LOGE(1, "EEEEEEEEEerror: intra dependency unexpected dependency");
966973
}
967974
} while (aToken != NULL);
968975
fwrite(intraDep, 1, 6, postF);
976+
if ((l_idxF == 18) && (l_idxH == 4) && (l_idxW == 0)) {
977+
LOGI(1, "line: %d:%d:%d:%d:%d:%d:", intraDep[0], intraDep[1], intraDep[2], intraDep[3], intraDep[4], intraDep[5]);
978+
//exit(0);
979+
}
969980
}
970981
fclose(tmpF);
971982
fclose(postF);
983+
//[REMOVE]for verification of file: verified the content written to binary file is correct
984+
//if we want to debug for 2nd gop onwards, we'll need to change the interface to include gop number
985+
//TODO: the output file differs from .tmp file
986+
/*load_intra_frame_mb_dependency(p_videoFileIndex);
987+
intraDepMapMove = intraDepMap;
988+
sprintf(l_depIntraFileName, "%s_intra_gop%d.txt.ver", gVideoFileNameList[p_videoFileIndex], gVideoPacketQueueList[p_videoFileIndex].dep_gop_num);
989+
tmpF = fopen(l_depIntraFileName, "w");
990+
postF = fopen(gVideoCodecCtxDepList[p_videoFileIndex]->g_intraDepFileName, "r");
991+
for (i = 13; i <= 24; ++i) {
992+
for (j =0; j < (gVideoCodecCtxList[p_videoFileIndex]->height + 15) / 16; ++j) {
993+
for (k = 0; k < (gVideoCodecCtxList[p_videoFileIndex]->width + 15) / 16; ++k) {
994+
fprintf(tmpF, "%d:%d:%d:", i, j, k);
995+
for (m = 0; m < 3; ++m) {
996+
fprintf(tmpF, "%d:%d:", *intraDepMapMove, *(intraDepMapMove+1));
997+
intraDepMapMove += 2;
998+
}
999+
fprintf(tmpF, "\n");
1000+
}
1001+
}
1002+
}
1003+
fclose(tmpF);
1004+
fclose(postF);
1005+
unload_intra_frame_mb_dependency();*/
9721006
}
9731007
++gVideoPacketQueueList[p_videoFileIndex].dep_gop_num;
9741008
}

ffplay.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ static void render_a_frame(int _width, int _height, float _roiSh, float _roiSw,
154154
unload_frame_mb_stindex();
155155
unload_frame_mb_edindex();
156156
unload_frame_dc_pred_direction();
157-
unload_inter_frame_mb_dependency();
158157
unload_intra_frame_mb_dependency();
159158
load_gop_info(gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF, &gGopStart, &gGopEnd);
160159
}

libavcodec/mpegvideo_common.h

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,60 @@ if(s->quarter_sample)
267267
the motion vector is pixel wise, sub-pixel wise, or quarter-pixel wise*/
268268
/* we don't have to really process motion compensation
269269
*/
270+
/*[TODO: doubts]
271+
src_y and src_x can be negative, where a padding process is applied. we record the dependency macroblock as edge block
272+
*/
270273
//#undef printf
271274
//printf("mpeg_motion: mb (%d, %d), motion (%d, %d); src pixel pos(%d, %d); dump: %d\n", s->mb_y, s->mb_x, motion_y, motion_x, src_y, src_x, dump_dep);
272275
if (dump_dep) {
276+
#undef exit
273277
#undef fprintf
278+
#undef printf
279+
/*if (src_x < 0 || src_y < 0) {
280+
printf("!!!!!!!!%d:%d:%d:%d:\n", src_y, src_x, src_y/16, src_x/16);
281+
}*/
274282
if ((src_x % 16 == 0) && (src_y % 16 == 0)) {
275-
//a single mb contains the entire reference mb
276-
//printf("&&&%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16);
277-
fprintf(s->avctx->g_interDepF, "%d:%d:", src_y/16, src_x/16);
283+
//a single mb contains the entire reference mb
284+
//printf("&&&%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16);
285+
fprintf(s->avctx->g_interDepF, "%d:%d:", src_y/16>=0 ? src_y/16:0, src_x/16>=0 ? src_x/16:0);
286+
//printf("%d:%d:\n", src_y/16, src_x/16);
287+
//if (src_y/16 < 0) {
288+
// printf("%d:%d:", src_y/16, src_x/16);
289+
//exit(1);
290+
//}
278291
} else if (src_x % 16 == 0) {
279292
// RA two mb contains the entire reference mb
280293
// RB
281294
//printf("&&&%d:%d:%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16, src_y/16 + 1, src_x/16);
282-
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16+1, src_x/16);
295+
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:", src_y/16>=0 ? src_y/16:0, src_x/16>=0?src_x/16:0, (src_y/16+1)>=0?(src_y/16+1):0, src_x/16>=0?src_x/16:0);
296+
//printf("%d:%d:%d:%d:\n", src_y/16, src_x/16, src_y/16+1, src_x/16);
297+
//if (src_y/16 < 0) {
298+
// printf("%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16+1, src_x/16);
299+
//exit(1);
300+
//}
301+
//if (src_y/16 + 1 < 0) {
302+
// printf("%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16+1, src_x/16);
303+
//exit(1);
304+
//}
283305
} else if (src_y % 16 == 0) {
284-
// RA RB: two mb contains the entire reference mb
285-
//printf("&&&%d:%d:%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16, src_y/16, src_x/16 + 1);
286-
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16, src_x/16 + 1);
306+
// RA RB: two mb contains the entire reference mb
307+
//printf("&&&%d:%d:%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16, src_y/16, src_x/16 + 1);
308+
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:", src_y/16>=0?src_y/16:0, src_x/16>=0?src_x/16:0, src_y/16>=0?src_y/16:0, (src_x/16+1)>=0?(src_x/16 + 1):0);
309+
//printf("%d:%d:%d:%d:\n", src_y/16, src_x/16, src_y/16, src_x/16 + 1);
310+
//if (src_y/16 < 0) {
311+
// printf("%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16, src_x/16 + 1);
312+
//exit(1);
313+
//}
287314
} else {
288-
// RA RB: four mb contains the entire reference mb
289-
// RC RC
290-
//printf("&&&%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16, src_y/16+1, src_x/16, src_y/16, src_x/16+1, src_y/16+1, src_x/16+1);
291-
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16+1, src_x/16, src_y/16, src_x/16+1, src_y/16+1, src_x/16+1);
315+
// RA RB: four mb contains the entire reference mb
316+
// RC RC
317+
//printf("&&&%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:\n", s->mb_y, s->mb_x, src_y/16, src_x/16, src_y/16+1, src_x/16, src_y/16, src_x/16+1, src_y/16+1, src_x/16+1);
318+
fprintf(s->avctx->g_interDepF, "%d:%d:%d:%d:%d:%d:%d:%d:", src_y/16>=0?src_y/16:0, src_x/16>=0?src_x/16:0, (src_y/16+1)>=0?(src_y/16+1):0, src_x/16>=0?src_x/16:0, src_y/16>=0?src_y/16:0, (src_x/16+1)>=0?(src_x/16+1):0, (src_y/16+1)>=0?(src_y/16+1):0, (src_x/16+1)>=0?(src_x/16+1):0);
319+
//printf("%d:%d:%d:%d:%d:%d:%d:%d:\n", src_y/16, src_x/16, src_y/16+1, src_x/16, src_y/16, src_x/16+1, src_y/16+1, src_x/16+1);
320+
//if (src_y/16 < 0) {
321+
// printf("%d:%d:%d:%d:%d:%d:%d:%d:", src_y/16, src_x/16, src_y/16+1, src_x/16, src_y/16, src_x/16+1, src_y/16+1, src_x/16+1);
322+
//exit(1);
323+
//}
292324
}
293325
}
294326

@@ -352,6 +384,10 @@ if(s->quarter_sample)
352384
src_x, src_y<<field_based,
353385
s->h_edge_pos, s->v_edge_pos);
354386
ptr_y = s->edge_emu_buffer;
387+
//printf("dump_dep = %d, src_y, src_x %d:%d\n", dump_dep, src_y, src_x);
388+
//if (src_y/16 < 0) {
389+
// exit(1);
390+
//}
355391
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
356392
uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
357393
s->dsp.emulated_edge_mc(uvbuf ,

0 commit comments

Comments
 (0)