Skip to content

Commit 6950b16

Browse files
committed
workable mmap for all 4 files
1 parent 344a8e3 commit 6950b16

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

dependency.c

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ unsigned char *intraDepMap, *intraDepMapMove;
315315
long intraDepMapLen;
316316
int intraDepFd;
317317
void unload_intra_frame_mb_dependency(void) {
318+
LOGI(10, "unload_intra_frame_mb_dependency: %d", intraDepMapLen);
318319
close(intraDepFd);
319-
munmap(intraDepMap, intraDepMapLen);
320+
if (munmap(intraDepMap, intraDepMapLen)!=0) {
321+
LOGE(1, "munmap error!");
322+
exit(0);
323+
}
320324
}
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) {
322326
char l_depIntraFileName[100];
323327
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);
325329
LOGI(10, "+++++load_intra_frame_mb_dependency, file: %s", l_depIntraFileName);
326330
if ((intraDepFd = open(l_depIntraFileName, O_RDONLY)) == -1) {
327331
LOGE(1, "file open error");
@@ -569,7 +573,7 @@ static void load_pre_computation_result(int p_videoFileIndex, int _stFrame, int
569573
//load_frame_mb_index(p_videoFileIndex, _stFrame, _edFrame); //the mb index position
570574
load_frame_mb_stindex(p_videoFileIndex); //the mb index position
571575
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
573577
load_inter_frame_mb_dependency(p_videoFileIndex); //the inter-frame dependency
574578
load_gop_dc_pred_direction(p_videoFileIndex); //the dc prediction direction
575579
}
@@ -684,10 +688,15 @@ static void compute_mb_mask_from_intra_frame_dependency_for_single_mb(int p_vide
684688
struct MBIdx l_mb, l_mb2;
685689
int l_i;
686690
unsigned char *p, *pframe;
691+
//FILE *testF;
692+
//char testFileName[50];
687693

694+
//sprintf(testFileName, "testi_%d_%d", _frameNum, _stFrame);
695+
//testF = fopen(testFileName, "a+");
688696
initQueue(&l_q);
689697
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);
691700
while (ifEmpty(&l_q) == 0) {
692701
//get the front value
693702
l_mb = front(&l_q);
@@ -697,17 +706,21 @@ static void compute_mb_mask_from_intra_frame_dependency_for_single_mb(int p_vide
697706
dequeue(&l_q);
698707
continue;
699708
}
709+
//fprintf(testF, "dequeue: %d:%d: ", l_mb.h, l_mb.w);
700710
gVideoCodecCtxList[p_videoFileIndex]->selected_mb_mask[l_mb.h][l_mb.w]++;
701711
for (l_i = 0; l_i < 3; ++l_i) {
702712
p = pframe + (l_mb.h*_width + l_mb.w)*6 + l_i*2;
703713
if ((*p !=0) || (*(p+1) != 0)) {
704714
l_mb2.h = *p;
705715
l_mb2.w = *(p+1);
706716
enqueue(&l_q, l_mb2);
717+
//fprintf(testF, "enqueue: %d:%d: ", l_mb2.h, l_mb2.w);
707718
}
708719
}
709720
dequeue(&l_q);
710721
}
722+
//fprintf(testF, "\n");
723+
//fclose(testF);
711724
}
712725

713726
/*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
734747
if the calculation is forward, then the case below might occur:
735748
mb 3 in frame 3 depends on mb 2 on frame 2, but mb 2 is not decoded
736749
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
738750
static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, int _stFrame, int _edFrame, int _stH, int _stW, int _edH, int _edW) {
739751
int l_i, l_j, l_k, l_m;
740752
int l_mbHeight, l_mbWidth;
741-
FILE *tf, *tf1;
753+
//FILE *tf, *tf1;
742754
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");
745757
//tf1 = fopen("test2.txt", "w");
746758
l_mbHeight = (gVideoCodecCtxList[p_videoFileIndex]->height + 15) / 16;
747759
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
776788
} else
777789
if (((*interDepMapMove) == 0) && (*(interDepMapMove+1) == 0)) {
778790
} 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));
780792
//fprintf(tf, "%d,%d,%d,%d,%d\n", l_i, l_j, l_k, *interDepMapMove, *(interDepMapMove+1));
781793
interDepMask[l_i - 1 - _stFrame][*interDepMapMove][*(interDepMapMove+1)] = 1;
782794
}
@@ -788,7 +800,7 @@ static void compute_mb_mask_from_inter_frame_dependency(int p_videoFileIndex, in
788800
}
789801
}
790802
}
791-
fclose(tf);
803+
//fclose(tf);
792804
//fclose(tf1);
793805
//we can unload the inter frame dependency file here
794806
unload_inter_frame_mb_dependency();
@@ -837,9 +849,9 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
837849
FILE *tmpF, *postF;
838850
unsigned char interDep[8];
839851
unsigned char intraDep[6];
840-
char aLine[40], *aToken;
852+
char aLine[80], *aToken, testLine[80];
841853
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;
843855
int i, j, k, m;
844856
LOGI(10, "dep_decode_a_video_packet for video: %d", p_videoFileIndex);
845857
while (av_read_frame(gFormatCtxDepList[p_videoFileIndex], &gVideoPacketDepList[p_videoFileIndex]) >= 0) {
@@ -885,7 +897,7 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
885897
tmpF = fopen(l_depInterFileName, "r");
886898
postF = fopen(gVideoCodecCtxDepList[p_videoFileIndex]->g_interDepFileName, "w");
887899
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) {
889901
memset(interDep, 0, 8);
890902
if ((aToken = strtok(aLine, ":")) != NULL) //get the frame number, mb position first
891903
l_idxF = atoi(aToken);
@@ -939,18 +951,22 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
939951
tmpF = fopen(l_depIntraFileName, "r");
940952
postF = fopen(gVideoCodecCtxDepList[p_videoFileIndex]->g_intraDepFileName, "w");
941953
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);
943956
memset(intraDep, 0, 6);
944957
if ((aToken = strtok(aLine, ":")) != NULL) //get the frame number, mb position first
945958
l_idxF = atoi(aToken);
946959
if ((aToken = strtok(NULL, ":")) != NULL)
947960
l_idxH = atoi(aToken);
948961
if ((aToken = strtok(NULL, ":")) != NULL)
949962
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;*/
954970
do {
955971
aToken = strtok(NULL, ":");
956972
if (aToken != NULL) l_depH = (unsigned char) atoi(aToken);
@@ -973,21 +989,15 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
973989
}
974990
} while (aToken != NULL);
975991
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-
}
980992
}
981993
fclose(tmpF);
982994
fclose(postF);
983995
//[REMOVE]for verification of file: verified the content written to binary file is correct
984996
//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);
987998
intraDepMapMove = intraDepMap;
988999
sprintf(l_depIntraFileName, "%s_intra_gop%d.txt.ver", gVideoFileNameList[p_videoFileIndex], gVideoPacketQueueList[p_videoFileIndex].dep_gop_num);
9891000
tmpF = fopen(l_depIntraFileName, "w");
990-
postF = fopen(gVideoCodecCtxDepList[p_videoFileIndex]->g_intraDepFileName, "r");
9911001
for (i = 13; i <= 24; ++i) {
9921002
for (j =0; j < (gVideoCodecCtxList[p_videoFileIndex]->height + 15) / 16; ++j) {
9931003
for (k = 0; k < (gVideoCodecCtxList[p_videoFileIndex]->width + 15) / 16; ++k) {
@@ -1001,7 +1011,6 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
10011011
}
10021012
}
10031013
fclose(tmpF);
1004-
fclose(postF);
10051014
unload_intra_frame_mb_dependency();*/
10061015
}
10071016
++gVideoPacketQueueList[p_videoFileIndex].dep_gop_num;
@@ -1111,7 +1120,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
11111120
FILE *l_maskF;
11121121
#endif
11131122
//FILE *l_yuvF;
1114-
FILE *lTestF;
1123+
//FILE *lTestF;
11151124
/*read the next video packet*/
11161125
LOGI(10, "decode_a_video_packet %d: (%d, %d) (%d, %d)", gVideoPacketNum, _roiStH, _roiStW, _roiEdH, _roiEdW);
11171126
if (gVideoCodecCtxList[p_videoFileIndex]->debug_selective == 1) {
@@ -1268,7 +1277,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
12681277
fclose(l_maskF);
12691278
#endif
12701279
//based on the mask, compose the video packet
1271-
lTestF = fopen("test.txt", "a+");
1280+
//lTestF = fopen("test.txt", "a+");
12721281
int *lMbStPos = mbStartPos, *lMbEdPos = mbEndPos;
12731282
l_selectiveDecodingDataSize = 0;
12741283
lMbStPos += (gVideoPacketNum - gStFrame)*l_mbHeight*l_mbWidth;
@@ -1288,7 +1297,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
12881297
}
12891298
}
12901299
LOGI(10, "total number of bits: %d", l_selectiveDecodingDataSize);
1291-
fprintf(lTestF, "%d\n", l_selectiveDecodingDataSize);
1300+
//fprintf(lTestF, "%d\n", l_selectiveDecodingDataSize);
12921301
l_numOfStuffingBits = (l_selectiveDecodingDataSize + 7) / 8 * 8 - l_selectiveDecodingDataSize;
12931302
l_selectiveDecodingDataSize = (l_selectiveDecodingDataSize + 7) / 8;
12941303
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 _
13081317
//put the data bits into the composed video packet
13091318
if (gVideoCodecCtxList[p_videoFileIndex]->selected_mb_mask[l_i][l_j] == 1) {
13101319
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));
13121321
}
13131322
++lMbEdPos;
13141323
++lMbStPos;
13151324
}
13161325
}
1317-
fflush(lTestF);
1326+
//fflush(lTestF);
13181327
//stuffing the last byte
13191328
for (l_i = 0; l_i < l_numOfStuffingBits; ++l_i) {
13201329
gVideoPacket2.data[l_selectiveDecodingDataSize - 1] |= (0x01 << l_i);

dependency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//#define NORM_DECODE_DEBUG //uncommented: dump dependency for normal decoding mode; should be commented at //selective decoding mode
4747
//#define DUMP_SELECTED_MB_MASK //enabled: dump the mask for the mb needed;
4848
//#define DUMP_VIDEO_FRAME_BYTES //enabled: dump the bytes to a binary file
49-
#define DUMP_SELECTIVE_DEP //enabled: dump the relationship in memory to files
49+
//#define DUMP_SELECTIVE_DEP //enabled: dump the relationship in memory to files
5050

5151
#define MAX_FRAME_NUM_IN_GOP 50
5252
#define MAX_MB_H 100

0 commit comments

Comments
 (0)