Skip to content

Commit 9ccb6ba

Browse files
committed
increase number of GOP allowed
1 parent 78693b4 commit 9ccb6ba

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

dependency.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
4747
gVideoStreamIndexList = (int*)malloc(gNumOfVideoFiles*sizeof(int));
4848
gVideoCodecCtxList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
4949
gVideoPacketQueueList = (PacketQueue*)malloc(gNumOfVideoFiles*sizeof(PacketQueue));
50+
gFormatCtxDepList = (AVFormatContext*)malloc(gNumOfVideoFiles*sizeof(AVFormatContext));
51+
gVideoCodecCtxDepList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
52+
gVideoPacketDepList = (AVPacket*)malloc(gNumOfVideoFiles*sizeof(AVPacket));
5053
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
5154
gVideoPacketQueueList[l_i].dep_gop_num = 0;
52-
gVideoPacketQueueList[l_i].decode_gop_num = 0;
55+
g_decode_gop_num = 0;
5356
gVideoPacketQueueList[l_i].nb_packets = 0;
5457
}
5558
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
@@ -69,9 +72,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
6972
#endif
7073
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))) {
7174
l_dumpDep = 1;
72-
gFormatCtxDepList = (AVFormatContext*)malloc(gNumOfVideoFiles*sizeof(AVFormatContext));
73-
gVideoCodecCtxDepList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
74-
gVideoPacketDepList = (AVPacket*)malloc(gNumOfVideoFiles*sizeof(AVPacket));
7575
} else {
7676
l_dumpDep = 0;
7777
}
@@ -689,7 +689,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
689689
av_free_packet(&gVideoPacket);
690690
}
691691
}
692-
LOGI(10, "read selected video file frame %d", (gFormatCtxList == NULL)?0:1);
692+
LOGI(10, "read selected video file frame for video %d", p_videoFileIndex);
693693
if (gVideoCodecCtxList[p_videoFileIndex]->dump_dependency) {
694694
//lGetPacketStatus = packet_queue_get(&gVideoPacketQueue, &gVideoPacket);
695695
lGetPacketStatus = av_read_frame(gFormatCtxList[p_videoFileIndex], &gVideoPacket);

dependency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//#define DUMP_VIDEO_FRAME_BYTES //enabled: dump the bytes to a binary file
4343
//#define DUMP_SELECTIVE_DEP //enabled: dump the relationship in memory to files
4444

45-
#define MAX_NUM_OF_GOP 50
45+
#define MAX_NUM_OF_GOP 500
4646
#define MAX_FRAME_NUM_IN_GOP 50
4747
#define MAX_MB_H 100
4848
#define MAX_MB_W 100

ffplay.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,33 @@ int gZoomLevelUpdate;
6363
void *test_thread(void *arg);
6464
void *decode_video(void *arg);
6565

66-
/*for testing: we dump the decoded frame to a file: here (_roiSh, _roiSw) and (_roiEh, _roiEw) are in pixel*/
67-
static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float _roiSh, float _roiSw, float _roiEh, float _roiEw) {
68-
int li;
69-
int l_roiSh, l_roiSw, l_roiEh, l_roiEw;
70-
LOGI(10, "render_a_frame");
71-
gVideoPicture.height = _height;
72-
gVideoPicture.width = _width;
73-
++gVideoPacketNum;
74-
/*wait for the dump dependency thread to finish dumping dependency info first before start decoding a frame*/
66+
static void wait_get_dependency() {
67+
/*wait for the dump dependency thread to finish dumping dependency info first before start decoding a frame*/
7568
if (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->dump_dependency) {
76-
while (gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num >= gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
69+
while (g_decode_gop_num >= gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
7770
/*[TODO]it might be more appropriate to use some sort of signal*/
7871
//pthread_mutex_lock(&gVideoPacketQueue.mutex);
7972
//pthread_cond_wait(&gVideoPacketQueue.cond, &gVideoPacketQueue.mutex);
8073
//pthread_mutex_unlock(&gVideoPacketQueue.mutex);
8174
usleep(50);
8275
}
83-
LOGI(10, "%d:%d:%d", gNumOfGop, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num);
76+
LOGI(10, "%d:%d:%d", gNumOfGop, g_decode_gop_num, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num);
8477
//update the gop start and end to memory data structure
8578
if (gNumOfGop < gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
8679
load_gop_info(gCurrentDecodingVideoFileIndex, gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
8780
}
8881
}
82+
}
83+
84+
/*for testing: we dump the decoded frame to a file: here (_roiSh, _roiSw) and (_roiEh, _roiEw) are in pixel*/
85+
static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float _roiSh, float _roiSw, float _roiEh, float _roiEw) {
86+
int li;
87+
int l_roiSh, l_roiSw, l_roiEh, l_roiEw;
88+
LOGI(10, "render_a_frame");
89+
gVideoPicture.height = _height;
90+
gVideoPicture.width = _width;
91+
++gVideoPacketNum;
92+
wait_get_dependency();
8993
/*see if it's a gop start, if so, load the gop info*/
9094
LOGI(10, "gVideoPacketNum = %d; gNumOfGop = %d;", gVideoPacketNum, gNumOfGop);
9195
for (li = 0; li < gNumOfGop; ++li) {
@@ -99,22 +103,24 @@ static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float
99103
gCurrentDecodingVideoFileIndex = 0;
100104
}
101105
gZoomLevelUpdate = 0;
106+
//after zoom level is updated, we'll need to check if we need to wait for dumping dependency
107+
wait_get_dependency();
102108
}
103109
//start of a gop
104110
gStFrame = gGopStart[li];
105-
//start of a gop indicates the previous gop is done decoding
106-
gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num = li;
107-
//3.0 based on roi pixel coordinates, calculate the mb-based roi coordinates
108-
l_roiSh = (_roiSh - 15) > 0 ? (_roiSh - 15):0;
109-
l_roiSw = (_roiSw - 15) > 0 ? (_roiSw - 15):0;
110-
l_roiEh = (_roiEh + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height ? (_roiEh + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
111-
l_roiEw = (_roiEw + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width ? (_roiEw + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
112-
l_roiSh = l_roiSh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
113-
l_roiSw = l_roiSw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
114-
l_roiEh = l_roiEh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
115-
l_roiEw = l_roiEw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
116-
//3.1 check if it's a beginning of a gop, if so, load the pre computation result and compute the inter frame dependency
117-
LOGI(10, "decode video %d with roi (%d:%d) to (%d:%d)", gCurrentDecodingVideoFileIndex, l_roiSh, l_roiSw, l_roiEh, l_roiEw);
111+
//start of a gop indicates the previous gop is done decoding
112+
g_decode_gop_num = li;
113+
//3.0 based on roi pixel coordinates, calculate the mb-based roi coordinates
114+
l_roiSh = (_roiSh - 15) > 0 ? (_roiSh - 15):0;
115+
l_roiSw = (_roiSw - 15) > 0 ? (_roiSw - 15):0;
116+
l_roiEh = (_roiEh + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height ? (_roiEh + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
117+
l_roiEw = (_roiEw + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width ? (_roiEw + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
118+
l_roiSh = l_roiSh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
119+
l_roiSw = l_roiSw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
120+
l_roiEh = l_roiEh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
121+
l_roiEw = l_roiEw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
122+
//3.1 check if it's a beginning of a gop, if so, load the pre computation result and compute the inter frame dependency
123+
LOGI(10, "decode video %d with roi (%d:%d) to (%d:%d)", gCurrentDecodingVideoFileIndex, l_roiSh, l_roiSw, l_roiEh, l_roiEw);
118124
prepare_decode_of_gop(gCurrentDecodingVideoFileIndex, gGopStart[li], gGopEnd[li], l_roiSh, l_roiSw, l_roiEh, l_roiEw);
119125
break;
120126
} else if (gVideoPacketNum < gGopEnd[li]) {

packetqueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int packet_queue_get(PacketQueue *q, AVPacket *pPkt) {
5959
//pthread_mutex_lock(&q->mutex);
6060
for (;;) {
6161
lPktList = q->first_pkt;
62-
if (q->dep_gop_num > q->decode_gop_num && lPktList) {
62+
if (q->dep_gop_num > g_decode_gop_num && lPktList) {
6363
q->first_pkt = lPktList->next;
6464
if (!q->first_pkt) {
6565
q->last_pkt = NULL;

packetqueue.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ So that when the dependency dump thread is done with a GOP. The selective decodi
88
typedef struct PacketQueue {
99
AVPacketList *first_pkt, *last_pkt;
1010
int dep_gop_num; //number of gop that its dependency has been dumped
11-
int decode_gop_num; //number of gop that its frames have been decoded, if decode_gop_num < dep_gop_num,
11+
//int decode_gop_num; //number of gop that its frames have been decoded, if decode_gop_num < dep_gop_num,
1212
//the selective decoding of next gop can start; otherwise, we'll need to wait
13+
//note: move this to global as there's only a single decoding queue but multiple dependency dumping queue
1314
int nb_packets;
1415
//pthread_mutex_t mutex;
1516
//pthread_cond_t cond;
1617
} PacketQueue;
1718

1819
PacketQueue *gVideoPacketQueueList;
1920

21+
int g_decode_gop_num;
22+
2023
void packet_queue_init(PacketQueue *q);
2124
void packet_queue_flush(PacketQueue *q);
2225
int packet_queue_put(PacketQueue *q, AVPacket *pkt);

0 commit comments

Comments
 (0)