@@ -315,13 +315,17 @@ unsigned char *intraDepMap, *intraDepMapMove;
315
315
long intraDepMapLen ;
316
316
int intraDepFd ;
317
317
void unload_intra_frame_mb_dependency (void ) {
318
+ LOGI (10 , "unload_intra_frame_mb_dependency: %d" , intraDepMapLen );
318
319
close (intraDepFd );
319
- munmap (intraDepMap , intraDepMapLen );
320
+ if (munmap (intraDepMap , intraDepMapLen )!= 0 ) {
321
+ LOGE (1 , "munmap error!" );
322
+ exit (0 );
323
+ }
320
324
}
321
- static void load_intra_frame_mb_dependency (int p_videoFileIndex ) {
325
+ static void load_intra_frame_mb_dependency (int p_videoFileIndex , int p_gopNumber ) {
322
326
char l_depIntraFileName [100 ];
323
327
struct stat sbuf ;
324
- sprintf (l_depIntraFileName , "./%s_intra_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], g_decode_gop_num );
328
+ sprintf (l_depIntraFileName , "./%s_intra_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], p_gopNumber );
325
329
LOGI (10 , "+++++load_intra_frame_mb_dependency, file: %s" , l_depIntraFileName );
326
330
if ((intraDepFd = open (l_depIntraFileName , O_RDONLY )) == -1 ) {
327
331
LOGE (1 , "file open error" );
@@ -569,7 +573,7 @@ static void load_pre_computation_result(int p_videoFileIndex, int _stFrame, int
569
573
//load_frame_mb_index(p_videoFileIndex, _stFrame, _edFrame); //the mb index position
570
574
load_frame_mb_stindex (p_videoFileIndex ); //the mb index position
571
575
load_frame_mb_edindex (p_videoFileIndex ); //the mb index position
572
- load_intra_frame_mb_dependency (p_videoFileIndex ); //the intra-frame dependency
576
+ load_intra_frame_mb_dependency (p_videoFileIndex , g_decode_gop_num ); //the intra-frame dependency
573
577
load_inter_frame_mb_dependency (p_videoFileIndex ); //the inter-frame dependency
574
578
load_gop_dc_pred_direction (p_videoFileIndex ); //the dc prediction direction
575
579
}
@@ -684,10 +688,15 @@ static void compute_mb_mask_from_intra_frame_dependency_for_single_mb(int p_vide
684
688
struct MBIdx l_mb , l_mb2 ;
685
689
int l_i ;
686
690
unsigned char * p , * pframe ;
691
+ //FILE *testF;
692
+ //char testFileName[50];
687
693
694
+ //sprintf(testFileName, "testi_%d_%d", _frameNum, _stFrame);
695
+ //testF = fopen(testFileName, "a+");
688
696
initQueue (& l_q );
689
697
enqueue (& l_q , _Pmb );
690
- pframe = intraDepMapMove + (_frameNum - _stFrame )* _height * _width * 6 ;
698
+ pframe = intraDepMap + (_frameNum - _stFrame )* _height * _width * 6 ;
699
+ //fprintf(testF, "location: %d\n", intraDepMap);
691
700
while (ifEmpty (& l_q ) == 0 ) {
692
701
//get the front value
693
702
l_mb = front (& l_q );
@@ -697,17 +706,21 @@ static void compute_mb_mask_from_intra_frame_dependency_for_single_mb(int p_vide
697
706
dequeue (& l_q );
698
707
continue ;
699
708
}
709
+ //fprintf(testF, "dequeue: %d:%d: ", l_mb.h, l_mb.w);
700
710
gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_mb .h ][l_mb .w ]++ ;
701
711
for (l_i = 0 ; l_i < 3 ; ++ l_i ) {
702
712
p = pframe + (l_mb .h * _width + l_mb .w )* 6 + l_i * 2 ;
703
713
if ((* p != 0 ) || (* (p + 1 ) != 0 )) {
704
714
l_mb2 .h = * p ;
705
715
l_mb2 .w = * (p + 1 );
706
716
enqueue (& l_q , l_mb2 );
717
+ //fprintf(testF, "enqueue: %d:%d: ", l_mb2.h, l_mb2.w);
707
718
}
708
719
}
709
720
dequeue (& l_q );
710
721
}
722
+ //fprintf(testF, "\n");
723
+ //fclose(testF);
711
724
}
712
725
713
726
/*based on the start pos (_stH, _stW) and end pos (_edH, _edW), compute the mb needed to decode the roi due to inter-frame dependency
@@ -734,14 +747,13 @@ static void compute_mb_mask_from_intra_frame_dependency(int p_videoFileIndex, in
734
747
if the calculation is forward, then the case below might occur:
735
748
mb 3 in frame 3 depends on mb 2 on frame 2, but mb 2 is not decoded
736
749
if we know the roi for the entire GOP, we can pre-calculate the needed mbs at every frame*/
737
- //TODO: the inter dependency list contains some negative values, we haven't figured it out yet
738
750
static void compute_mb_mask_from_inter_frame_dependency (int p_videoFileIndex , int _stFrame , int _edFrame , int _stH , int _stW , int _edH , int _edW ) {
739
751
int l_i , l_j , l_k , l_m ;
740
752
int l_mbHeight , l_mbWidth ;
741
- FILE * tf , * tf1 ;
753
+ // FILE *tf, *tf1;
742
754
char logFileName [100 ];
743
- sprintf (logFileName , "test1_%d.txt" , _stFrame );
744
- tf = fopen (logFileName , "w" );
755
+ // sprintf(logFileName, "test1_%d.txt", _stFrame);
756
+ // tf = fopen(logFileName, "w");
745
757
//tf1 = fopen("test2.txt", "w");
746
758
l_mbHeight = (gVideoCodecCtxList [p_videoFileIndex ]-> height + 15 ) / 16 ;
747
759
l_mbWidth = (gVideoCodecCtxList [p_videoFileIndex ]-> width + 15 ) / 16 ;
@@ -776,7 +788,7 @@ static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, in
776
788
} else
777
789
if (((* interDepMapMove ) == 0 ) && (* (interDepMapMove + 1 ) == 0 )) {
778
790
} else {
779
- fprintf (tf , "%d,%d,%d,%d,%d,%d\n" , l_i , l_j , l_k , l_m , * interDepMapMove , * (interDepMapMove + 1 ));
791
+ // fprintf(tf, "%d,%d,%d,%d,%d,%d\n", l_i, l_j, l_k, l_m, *interDepMapMove, *(interDepMapMove+1));
780
792
//fprintf(tf, "%d,%d,%d,%d,%d\n", l_i, l_j, l_k, *interDepMapMove, *(interDepMapMove+1));
781
793
interDepMask [l_i - 1 - _stFrame ][* interDepMapMove ][* (interDepMapMove + 1 )] = 1 ;
782
794
}
@@ -788,7 +800,7 @@ static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, in
788
800
}
789
801
}
790
802
}
791
- fclose (tf );
803
+ // fclose(tf);
792
804
//fclose(tf1);
793
805
//we can unload the inter frame dependency file here
794
806
unload_inter_frame_mb_dependency ();
@@ -837,9 +849,9 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
837
849
FILE * tmpF , * postF ;
838
850
unsigned char interDep [8 ];
839
851
unsigned char intraDep [6 ];
840
- char aLine [40 ], * aToken ;
852
+ char aLine [80 ], * aToken , testLine [ 80 ] ;
841
853
unsigned char l_depH , l_depW , l_curDepIdx ;
842
- int l_idxF , l_idxH , l_idxW ;
854
+ int l_idxF , l_idxH , l_idxW , lidxF = -1 , lidxH = -1 , lidxW = -1 ;
843
855
int i , j , k , m ;
844
856
LOGI (10 , "dep_decode_a_video_packet for video: %d" , p_videoFileIndex );
845
857
while (av_read_frame (gFormatCtxDepList [p_videoFileIndex ], & gVideoPacketDepList [p_videoFileIndex ]) >= 0 ) {
@@ -885,7 +897,7 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
885
897
tmpF = fopen (l_depInterFileName , "r" );
886
898
postF = fopen (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_interDepFileName , "w" );
887
899
LOGI (10 , "...........processing %s to %s" , l_depInterFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_interDepFileName );
888
- while (fgets (aLine , 40 , tmpF ) != NULL ) {
900
+ while (fgets (aLine , 80 , tmpF ) != NULL ) {
889
901
memset (interDep , 0 , 8 );
890
902
if ((aToken = strtok (aLine , ":" )) != NULL ) //get the frame number, mb position first
891
903
l_idxF = atoi (aToken );
@@ -939,18 +951,22 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
939
951
tmpF = fopen (l_depIntraFileName , "r" );
940
952
postF = fopen (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_intraDepFileName , "w" );
941
953
LOGI (10 , "...........processing %s to %s" , l_depIntraFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_intraDepFileName );
942
- while (fgets (aLine , 40 , tmpF ) != NULL ) {
954
+ while (fgets (aLine , 80 , tmpF ) != NULL ) {
955
+ //memcpy(testLine, aLine, 80);
943
956
memset (intraDep , 0 , 6 );
944
957
if ((aToken = strtok (aLine , ":" )) != NULL ) //get the frame number, mb position first
945
958
l_idxF = atoi (aToken );
946
959
if ((aToken = strtok (NULL , ":" )) != NULL )
947
960
l_idxH = atoi (aToken );
948
961
if ((aToken = strtok (NULL , ":" )) != NULL )
949
962
l_idxW = atoi (aToken );
950
- //get the dependency mb
951
- if ((l_idxF == 18 ) && (l_idxH == 4 ) && (l_idxW == 0 )) {
952
- LOGI (1 , "line: %s" , aLine );
953
- }
963
+ //LOGE(1, "testLine: %s", testLine);
964
+ /*if ((l_idxF < lidxF) || ((l_idxF == lidxF) && (l_idxH <= lidxH) && (l_idxW <= lidxW)) ) {
965
+ LOGE(1, "error:%d:%d:%d:%d:%d:%d", l_idxF, l_idxH, l_idxW, lidxF, lidxH, lidxW);
966
+
967
+ exit(1);
968
+ }
969
+ lidxF = l_idxF; lidxH = l_idxH; lidxW = l_idxW;*/
954
970
do {
955
971
aToken = strtok (NULL , ":" );
956
972
if (aToken != NULL ) l_depH = (unsigned char ) atoi (aToken );
@@ -973,21 +989,15 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
973
989
}
974
990
} while (aToken != NULL );
975
991
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
- }
980
992
}
981
993
fclose (tmpF );
982
994
fclose (postF );
983
995
//[REMOVE]for verification of file: verified the content written to binary file is correct
984
996
//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);
997
+ /*load_intra_frame_mb_dependency(p_videoFileIndex, gVideoPacketQueueList[p_videoFileIndex].dep_gop_num);
987
998
intraDepMapMove = intraDepMap;
988
999
sprintf(l_depIntraFileName, "%s_intra_gop%d.txt.ver", gVideoFileNameList[p_videoFileIndex], gVideoPacketQueueList[p_videoFileIndex].dep_gop_num);
989
1000
tmpF = fopen(l_depIntraFileName, "w");
990
- postF = fopen(gVideoCodecCtxDepList[p_videoFileIndex]->g_intraDepFileName, "r");
991
1001
for (i = 13; i <= 24; ++i) {
992
1002
for (j =0; j < (gVideoCodecCtxList[p_videoFileIndex]->height + 15) / 16; ++j) {
993
1003
for (k = 0; k < (gVideoCodecCtxList[p_videoFileIndex]->width + 15) / 16; ++k) {
@@ -1001,7 +1011,6 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
1001
1011
}
1002
1012
}
1003
1013
fclose(tmpF);
1004
- fclose(postF);
1005
1014
unload_intra_frame_mb_dependency();*/
1006
1015
}
1007
1016
++ gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num ;
@@ -1111,7 +1120,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
1111
1120
FILE * l_maskF ;
1112
1121
#endif
1113
1122
//FILE *l_yuvF;
1114
- FILE * lTestF ;
1123
+ // FILE *lTestF;
1115
1124
/*read the next video packet*/
1116
1125
LOGI (10 , "decode_a_video_packet %d: (%d, %d) (%d, %d)" , gVideoPacketNum , _roiStH , _roiStW , _roiEdH , _roiEdW );
1117
1126
if (gVideoCodecCtxList [p_videoFileIndex ]-> debug_selective == 1 ) {
@@ -1268,7 +1277,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
1268
1277
fclose (l_maskF );
1269
1278
#endif
1270
1279
//based on the mask, compose the video packet
1271
- lTestF = fopen ("test.txt" , "a+" );
1280
+ // lTestF = fopen("test.txt", "a+");
1272
1281
int * lMbStPos = mbStartPos , * lMbEdPos = mbEndPos ;
1273
1282
l_selectiveDecodingDataSize = 0 ;
1274
1283
lMbStPos += (gVideoPacketNum - gStFrame )* l_mbHeight * l_mbWidth ;
@@ -1288,7 +1297,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
1288
1297
}
1289
1298
}
1290
1299
LOGI (10 , "total number of bits: %d" , l_selectiveDecodingDataSize );
1291
- fprintf (lTestF , "%d\n" , l_selectiveDecodingDataSize );
1300
+ // fprintf(lTestF, "%d\n", l_selectiveDecodingDataSize);
1292
1301
l_numOfStuffingBits = (l_selectiveDecodingDataSize + 7 ) / 8 * 8 - l_selectiveDecodingDataSize ;
1293
1302
l_selectiveDecodingDataSize = (l_selectiveDecodingDataSize + 7 ) / 8 ;
1294
1303
LOGI (10 , "total number of bytes: %d; number of stuffing bits: %d" , l_selectiveDecodingDataSize , l_numOfStuffingBits );
@@ -1308,13 +1317,13 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
1308
1317
//put the data bits into the composed video packet
1309
1318
if (gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_i ][l_j ] == 1 ) {
1310
1319
l_bufPos = copy_bits (gVideoPacket .data , gVideoPacket2 .data , * lMbStPos , (* lMbEdPos ) - (* lMbStPos ), l_bufPos );
1311
- fprintf (lTestF , "%d:%d:%d:%d\n" , l_i , l_j , (* lMbStPos ), (* lMbEdPos ));
1320
+ // fprintf(lTestF, "%d:%d:%d:%d\n", l_i, l_j, (*lMbStPos), (*lMbEdPos));
1312
1321
}
1313
1322
++ lMbEdPos ;
1314
1323
++ lMbStPos ;
1315
1324
}
1316
1325
}
1317
- fflush (lTestF );
1326
+ // fflush(lTestF);
1318
1327
//stuffing the last byte
1319
1328
for (l_i = 0 ; l_i < l_numOfStuffingBits ; ++ l_i ) {
1320
1329
gVideoPacket2 .data [l_selectiveDecodingDataSize - 1 ] |= (0x01 << l_i );
0 commit comments