@@ -185,8 +185,10 @@ void free_selected_decoding_fields(int p_videoFileIndex, int _mbHeight) {
185
185
186
186
int * mbStartPos ;
187
187
int mapStLen ;
188
+ int mbStartFd ;
188
189
int * mbEndPos ;
189
190
int mapEdLen ;
191
+ int mbEndFd ;
190
192
191
193
struct MBIdx intraDep [MAX_FRAME_NUM_IN_GOP ][MAX_MB_H ][MAX_MB_W ][MAX_DEP_MB ];
192
194
struct MBIdx interDep [MAX_FRAME_NUM_IN_GOP ][MAX_MB_H ][MAX_MB_W ][MAX_DEP_MB ];
@@ -241,28 +243,22 @@ int interDepMask[MAX_FRAME_NUM_IN_GOP][MAX_MB_H][MAX_MB_W];
241
243
}*/
242
244
243
245
void unload_frame_mb_stindex (void ) {
246
+ close (mbStartFd );
244
247
munmap (mbStartPos , mapStLen );
245
248
}
246
249
247
250
void unload_frame_mb_edindex (void ) {
251
+ close (mbEndFd );
248
252
munmap (mbEndPos , mapEdLen );
249
253
}
250
254
251
255
void load_frame_mb_stindex (int p_videoFileIndex ) {
252
256
char curDir [100 ];
253
- int fd ;
254
257
struct stat sbuf ;
255
- char filename [100 ];
256
258
char * data ;
257
- sprintf (filename , "./%s_mbstpos_gop%d.txt" , "h1_1280_720_5m.mp4" , 1 );
258
259
LOGI (10 , "+++++load_frame_mb_stindex: %s" , gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName );
259
- if (strcmp (gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName , filename ) == 0 ) {
260
- LOGI (10 , "two strings are equal" );
261
- }
262
- getcwd (curDir , 100 );
263
- LOGI (10 , "current dir: %s, file: %s = %s" , curDir , filename , gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName );
264
260
//if (fd = open(gVideoCodecCtxList[p_videoFileIndex]->g_mbStPosFileName, O_RDONLY) == -1) {
265
- if ((fd = open (gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName , O_RDONLY )) == -1 ) {
261
+ if ((mbStartFd = open (gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName , O_RDONLY )) == -1 ) {
266
262
LOGE (1 , "file open error: %s" , gVideoCodecCtxList [p_videoFileIndex ]-> g_mbStPosFileName );
267
263
perror ("file open error: " );
268
264
exit (1 );
@@ -277,7 +273,7 @@ void load_frame_mb_stindex(int p_videoFileIndex) {
277
273
//mbStartPos = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
278
274
//mbStartPos = mmap(0, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
279
275
mapStLen = sbuf .st_size ;
280
- mbStartPos = mmap (0 , sbuf .st_size , PROT_READ , MAP_PRIVATE , fd , 0 ) ;
276
+ mbStartPos = mmap (0 , sbuf .st_size , PROT_READ , MAP_PRIVATE , mbStartFd , 0 ) ;
281
277
//mbStartPos = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
282
278
if (mbStartPos == MAP_FAILED ) {
283
279
LOGE (1 , "mmap error" );
@@ -289,10 +285,9 @@ void load_frame_mb_stindex(int p_videoFileIndex) {
289
285
}
290
286
291
287
void load_frame_mb_edindex (int p_videoFileIndex ) {
292
- int fd ;
293
288
struct stat sbuf ;
294
289
LOGI (10 , "+++++load_frame_mb_edindex, file: %s" , gVideoCodecCtxList [p_videoFileIndex ]-> g_mbEdPosFileName );
295
- if ((fd = open (gVideoCodecCtxList [p_videoFileIndex ]-> g_mbEdPosFileName , O_RDONLY )) == -1 ) {
290
+ if ((mbEndFd = open (gVideoCodecCtxList [p_videoFileIndex ]-> g_mbEdPosFileName , O_RDONLY )) == -1 ) {
296
291
LOGE (1 , "file open error" );
297
292
exit (1 );
298
293
}
@@ -304,7 +299,7 @@ void load_frame_mb_edindex(int p_videoFileIndex) {
304
299
//mbEndPos = mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
305
300
//mbEndPos = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
306
301
mapEdLen = sbuf .st_size ;
307
- mbEndPos = mmap (0 , sbuf .st_size , PROT_READ , MAP_PRIVATE , fd , 0 );
302
+ mbEndPos = mmap (0 , sbuf .st_size , PROT_READ , MAP_PRIVATE , mbEndFd , 0 );
308
303
if (mbEndPos == MAP_FAILED ) {
309
304
LOGE (1 , "mmap error" );
310
305
perror ("mmap error: " );
@@ -412,11 +407,60 @@ static void load_inter_frame_mb_dependency(int p_videoFileIndex, int _stFrame, i
412
407
}
413
408
}
414
409
415
- static void load_frame_dc_pred_direction (int p_videoFileIndex , int _frameNum , int _height , int _width ) {
410
+ long dcpMapLen ;
411
+ unsigned char * dcpPos , * dcpPosMove ;
412
+ int dcpFd ;
413
+ void unload_frame_dc_pred_direction (void ) {
414
+ close (dcpFd );
415
+ munmap (dcpPos , dcpMapLen );
416
+ }
417
+
418
+ static void load_gop_dc_pred_direction (int p_videoFileIndex ) {
419
+ struct stat sbuf ;
420
+ LOGI (10 , "load_gop_dc_pred_direction: %s\n" , gVideoCodecCtxList [p_videoFileIndex ]-> g_dcPredFileName );
421
+ if ((dcpFd = open (gVideoCodecCtxList [p_videoFileIndex ]-> g_dcPredFileName , O_RDONLY )) == -1 ) {
422
+ LOGE (1 , "file open error: %s" , gVideoCodecCtxList [p_videoFileIndex ]-> g_dcPredFileName );
423
+ perror ("file open error: " );
424
+ exit (1 );
425
+ }
426
+ if (stat (gVideoCodecCtxList [p_videoFileIndex ]-> g_dcPredFileName , & sbuf ) == -1 ) {
427
+ LOGE (1 , "stat error" );
428
+ exit (1 );
429
+ }
430
+ dcpMapLen = sbuf .st_size ;
431
+ LOGI (9 , "file size: %ld" , dcpMapLen );
432
+ dcpPos = mmap (0 , dcpMapLen , PROT_READ , MAP_PRIVATE , dcpFd , 0 );
433
+ dcpPosMove = dcpPos ;
434
+ if (dcpPos == MAP_FAILED ) {
435
+ LOGE (1 , "map error" );
436
+ perror ("mmap error:" );
437
+ exit (1 );
438
+ }
439
+ LOGI (10 , "load_gop_dc_pred_direction done\n" );
440
+ }
441
+
442
+
443
+ static void load_frame_dc_pred_direction (int p_videoFileIndex , int _height , int _width ) {
444
+ FILE * testF ;
445
+ int i , j ;
446
+ LOGI (10 , "load_frame_dc_pred_direction\n" );
447
+ memset (gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir , 0 , _height * _width * sizeof (gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir [0 ][0 ]));
448
+ gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir = dcpPosMove ;
449
+ testF = fopen ("test.txt" , "a+" );
450
+ for (i = 0 ; i < _height ; ++ i ) {
451
+ for (j = 0 ; j < _width ; ++ j ) {
452
+ fprintf ("%d:%d:%d\n" , i , j , gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir [i ][j ]);
453
+ }
454
+ }
455
+ fclose (testF );
456
+ dcpPosMove += _height * _width ;
457
+ LOGI (10 , "load_frame_dc_pred_direction done\n" );
458
+ }
459
+
460
+ /*static void load_frame_dc_pred_direction(int p_videoFileIndex, int _frameNum, int _height, int _width) {
416
461
int l_i, l_j, l_idxF, l_idxH, l_idxW, l_idxDir;
417
462
char aLine[40], *aToken;
418
463
LOGI(10, "load_frame_dc_pred_direction\n");
419
- //g_dcPredF = fopen("/sdcard/r10videocam/dcp.txt", "r");
420
464
if (gVideoCodecCtxList[p_videoFileIndex]->g_dcPredF==NULL) {
421
465
LOGI(1, "no valid dc pred!!!");
422
466
}
@@ -432,15 +476,15 @@ static void load_frame_dc_pred_direction(int p_videoFileIndex, int _frameNum, in
432
476
if (l_idxF < _frameNum) {
433
477
continue;
434
478
} else if (l_idxF > _frameNum) {
435
- //continue to parse the string to get length
436
- l_i = strlen (aToken ) + 1 ;
437
- aToken = strtok (NULL , "\n" );
438
- l_i += strlen (aToken ) + 1 ;
439
- //go back to the previous line
440
- fseek (gVideoCodecCtxList [p_videoFileIndex ]-> g_dcPredF , - l_i , SEEK_CUR );
441
- //LOGI(10, "go back: %d", l_i);
442
- break ;
443
- }
479
+ //continue to parse the string to get length
480
+ l_i = strlen(aToken) + 1;
481
+ aToken = strtok(NULL, "\n");
482
+ l_i += strlen(aToken) + 1;
483
+ //go back to the previous line
484
+ fseek(gVideoCodecCtxList[p_videoFileIndex]->g_dcPredF, -l_i, SEEK_CUR);
485
+ //LOGI(10, "go back: %d", l_i);
486
+ break;
487
+ }
444
488
if ((aToken = strtok(NULL, ":")) != NULL)
445
489
l_idxH = atoi(aToken);
446
490
if ((aToken = strtok(NULL, ":")) != NULL)
@@ -451,7 +495,7 @@ static void load_frame_dc_pred_direction(int p_videoFileIndex, int _frameNum, in
451
495
gVideoCodecCtxList[p_videoFileIndex]->pred_dc_dir[l_idxH][l_idxW] = l_idxDir;
452
496
}
453
497
LOGI(10, "load_frame_dc_pred_direction done\n");
454
- }
498
+ }*/
455
499
456
500
/*done on a GOP basis*/
457
501
static void load_pre_computation_result (int p_videoFileIndex , int _stFrame , int _edFrame ) {
@@ -460,6 +504,7 @@ static void load_pre_computation_result(int p_videoFileIndex, int _stFrame, int
460
504
load_frame_mb_edindex (p_videoFileIndex ); //the mb index position
461
505
load_intra_frame_mb_dependency (p_videoFileIndex , _stFrame , _edFrame ); //the intra-frame dependency
462
506
load_inter_frame_mb_dependency (p_videoFileIndex , _stFrame , _edFrame ); //the inter-frame dependency
507
+ load_gop_dc_pred_direction (p_videoFileIndex ); //the dc prediction direction
463
508
}
464
509
465
510
void dump_frame_to_file (int _frameNum ) {
@@ -693,7 +738,7 @@ int if_dependency_complete(int p_videoFileIndex, int p_gopNum) {
693
738
}
694
739
695
740
void dep_decode_a_video_packet (int p_videoFileIndex ) {
696
- char l_depGopRecFileName [100 ], l_depIntraFileName [100 ], l_depInterFileName [100 ], l_depDcpFileName [ 100 ] ;
741
+ char l_depGopRecFileName [100 ], l_depIntraFileName [100 ], l_depInterFileName [100 ];
697
742
AVFrame * l_videoFrame = avcodec_alloc_frame ();
698
743
int l_numOfDecodedFrames , l_frameType ;
699
744
int ti , tj ;
@@ -746,27 +791,27 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
746
791
sprintf (l_depInterFileName , "%s_inter_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
747
792
sprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName , "%s_mbstpos_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
748
793
sprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName , "%s_mbedpos_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
749
- sprintf (l_depDcpFileName , "%s_dcp_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
794
+ sprintf (gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName , "%s_dcp_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
750
795
751
796
#else
752
797
sprintf (l_depGopRecFileName , "%s_goprec_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
753
798
sprintf (l_depIntraFileName , "%s_intra_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
754
799
sprintf (l_depInterFileName , "%s_inter_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
755
800
sprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName , "%s_mbstpos_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
756
801
sprintf (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName , "%s_mbedpos_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
757
- sprintf (l_depDcpFileName , "%s_dcp_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
802
+ sprintf (gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName , "%s_dcp_gop%d.txt" , gVideoFileNameList [p_videoFileIndex ], gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
758
803
#endif
759
- LOGI (10 , "dependency files %s, %s, %s, %s, %s, %s for video %d gop %d" , l_depGopRecFileName , l_depIntraFileName , l_depInterFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName , l_depDcpFileName , p_videoFileIndex , gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
804
+ LOGI (10 , "dependency files %s, %s, %s, %s, %s, %s for video %d gop %d" , l_depGopRecFileName , l_depIntraFileName , l_depInterFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName , gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName , gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName , p_videoFileIndex , gVideoPacketQueueList [p_videoFileIndex ].dep_gop_num );
760
805
#ifdef CLEAR_DEP_BEFORE_START
761
806
remove (l_depGopRecFileName );
762
807
remove (l_depIntraFileName );
763
808
remove (l_depInterFileName );
764
809
remove (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName );
765
810
remove (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName );
766
- remove (l_depDcpFileName );
811
+ remove (gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName );
767
812
#endif
768
813
gVideoCodecCtxDepList [p_videoFileIndex ]-> dump_dependency = 1 ;
769
- if ((if_file_exists (l_depGopRecFileName )) && (if_file_exists (l_depIntraFileName )) && (if_file_exists (l_depInterFileName )) && (if_file_exists (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName )) && (if_file_exists (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName )) && (if_file_exists (l_depDcpFileName ))) {
814
+ if ((if_file_exists (l_depGopRecFileName )) && (if_file_exists (l_depIntraFileName )) && (if_file_exists (l_depInterFileName )) && (if_file_exists (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosFileName )) && (if_file_exists (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbEdPosFileName )) && (if_file_exists (gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName ))) {
770
815
//if all files exist, further check l_depGopRecFileName file content, see if it actually contains both GOP start and end frame
771
816
gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF = fopen (l_depGopRecFileName , "r" );
772
817
if (load_gop_info (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_gopF , & ti , & tj ) != 0 ) {
@@ -790,7 +835,7 @@ void dep_decode_a_video_packet(int p_videoFileIndex) {
790
835
if (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_mbStPosF == NULL ) {
791
836
LOGI (10 , "cannot open mb pos file to write" );
792
837
}
793
- gVideoCodecCtxDepList [p_videoFileIndex ]-> g_dcPredF = fopen (l_depDcpFileName , "w" );
838
+ gVideoCodecCtxDepList [p_videoFileIndex ]-> g_dcPredF = fopen (gVideoCodecCtxDepList [ p_videoFileIndex ] -> g_dcPredFileName , "w" );
794
839
if (gVideoCodecCtxDepList [p_videoFileIndex ]-> g_dcPredF == NULL ) {
795
840
LOGE (10 , "cannot open dc prediction file to write" );
796
841
}
@@ -924,8 +969,8 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
924
969
gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_i ][l_j ] = 1 ;
925
970
}
926
971
}
927
- //load the dc prediction direction
928
- load_frame_dc_pred_direction (p_videoFileIndex , gVideoPacketNum , l_mbHeight , l_mbWidth );
972
+ //load the dc prediction direction
973
+ load_frame_dc_pred_direction (p_videoFileIndex , l_mbHeight , l_mbWidth );
929
974
#ifdef DUMP_SELECTIVE_DEP
930
975
FILE * l_dcpF ;
931
976
char l_dcpFName [50 ];
@@ -936,10 +981,10 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
936
981
#endif
937
982
l_dcpF = fopen (l_dcpFName , "w" );
938
983
for (l_i = 0 ; l_i < l_mbHeight ; ++ l_i ) {
939
- for (l_j = 0 ; l_j < l_mbWidth ; ++ l_j ) {
940
- fprintf (l_dcpF , "%d:" , gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir [l_i ][l_j ]);
984
+ for (l_j = 0 ; l_j < l_mbWidth ; ++ l_j ) {
985
+ fprintf (l_dcpF , "%d:" , gVideoCodecCtxList [p_videoFileIndex ]-> pred_dc_dir [l_i ][l_j ]);
941
986
}
942
- fprintf (l_dcpF , "\n" );
987
+ fprintf (l_dcpF , "\n" );
943
988
}
944
989
fclose (l_dcpF );
945
990
#endif
@@ -948,7 +993,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
948
993
//if a mb is selected multiple times, set it to 1
949
994
for (l_i = 0 ; l_i < l_mbHeight ; ++ l_i ) {
950
995
for (l_j = 0 ; l_j < l_mbWidth ; ++ l_j ) {
951
- if (gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_i ][l_j ] > 1 ) {
996
+ if (gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_i ][l_j ] > 1 ) {
952
997
gVideoCodecCtxList [p_videoFileIndex ]-> selected_mb_mask [l_i ][l_j ] = 1 ;
953
998
}
954
999
}
0 commit comments