Permalink
Browse files

increase number of GOP allowed

  • Loading branch information...
roman10 committed Oct 20, 2011
1 parent 78693b4 commit 9ccb6babf52730eadf64d6ff54e8042f63dd0800
Showing with 41 additions and 32 deletions.
  1. +5 −5 dependency.c
  2. +1 −1 dependency.h
  3. +30 −24 ffplay.c
  4. +1 −1 packetqueue.c
  5. +4 −1 packetqueue.h
View
@@ -47,9 +47,12 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
gVideoStreamIndexList = (int*)malloc(gNumOfVideoFiles*sizeof(int));
gVideoCodecCtxList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
gVideoPacketQueueList = (PacketQueue*)malloc(gNumOfVideoFiles*sizeof(PacketQueue));
+ gFormatCtxDepList = (AVFormatContext*)malloc(gNumOfVideoFiles*sizeof(AVFormatContext));
+ gVideoCodecCtxDepList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
+ gVideoPacketDepList = (AVPacket*)malloc(gNumOfVideoFiles*sizeof(AVPacket));
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
gVideoPacketQueueList[l_i].dep_gop_num = 0;
- gVideoPacketQueueList[l_i].decode_gop_num = 0;
+ g_decode_gop_num = 0;
gVideoPacketQueueList[l_i].nb_packets = 0;
}
for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
@@ -69,9 +72,6 @@ void get_video_info(char **p_videoFilenameList, int p_debug) {
#endif
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))) {
l_dumpDep = 1;
- gFormatCtxDepList = (AVFormatContext*)malloc(gNumOfVideoFiles*sizeof(AVFormatContext));
- gVideoCodecCtxDepList = (AVCodecContext*)malloc(gNumOfVideoFiles*sizeof(AVCodecContext));
- gVideoPacketDepList = (AVPacket*)malloc(gNumOfVideoFiles*sizeof(AVPacket));
} else {
l_dumpDep = 0;
}
@@ -689,7 +689,7 @@ void decode_a_video_packet(int p_videoFileIndex, int _roiStH, int _roiStW, int _
av_free_packet(&gVideoPacket);
}
}
- LOGI(10, "read selected video file frame %d", (gFormatCtxList == NULL)?0:1);
+ LOGI(10, "read selected video file frame for video %d", p_videoFileIndex);
if (gVideoCodecCtxList[p_videoFileIndex]->dump_dependency) {
//lGetPacketStatus = packet_queue_get(&gVideoPacketQueue, &gVideoPacket);
lGetPacketStatus = av_read_frame(gFormatCtxList[p_videoFileIndex], &gVideoPacket);
View
@@ -42,7 +42,7 @@
//#define DUMP_VIDEO_FRAME_BYTES //enabled: dump the bytes to a binary file
//#define DUMP_SELECTIVE_DEP //enabled: dump the relationship in memory to files
-#define MAX_NUM_OF_GOP 50
+#define MAX_NUM_OF_GOP 500
#define MAX_FRAME_NUM_IN_GOP 50
#define MAX_MB_H 100
#define MAX_MB_W 100
View
@@ -63,29 +63,33 @@ int gZoomLevelUpdate;
void *test_thread(void *arg);
void *decode_video(void *arg);
-/*for testing: we dump the decoded frame to a file: here (_roiSh, _roiSw) and (_roiEh, _roiEw) are in pixel*/
-static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float _roiSh, float _roiSw, float _roiEh, float _roiEw) {
- int li;
- int l_roiSh, l_roiSw, l_roiEh, l_roiEw;
- LOGI(10, "render_a_frame");
- gVideoPicture.height = _height;
- gVideoPicture.width = _width;
- ++gVideoPacketNum;
- /*wait for the dump dependency thread to finish dumping dependency info first before start decoding a frame*/
+static void wait_get_dependency() {
+ /*wait for the dump dependency thread to finish dumping dependency info first before start decoding a frame*/
if (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->dump_dependency) {
- while (gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num >= gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
+ while (g_decode_gop_num >= gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
/*[TODO]it might be more appropriate to use some sort of signal*/
//pthread_mutex_lock(&gVideoPacketQueue.mutex);
//pthread_cond_wait(&gVideoPacketQueue.cond, &gVideoPacketQueue.mutex);
//pthread_mutex_unlock(&gVideoPacketQueue.mutex);
usleep(50);
}
- LOGI(10, "%d:%d:%d", gNumOfGop, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num);
+ LOGI(10, "%d:%d:%d", gNumOfGop, g_decode_gop_num, gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num);
//update the gop start and end to memory data structure
if (gNumOfGop < gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].dep_gop_num) {
load_gop_info(gCurrentDecodingVideoFileIndex, gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->g_gopF);
}
}
+}
+
+/*for testing: we dump the decoded frame to a file: here (_roiSh, _roiSw) and (_roiEh, _roiEw) are in pixel*/
+static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float _roiSh, float _roiSw, float _roiEh, float _roiEw) {
+ int li;
+ int l_roiSh, l_roiSw, l_roiEh, l_roiEw;
+ LOGI(10, "render_a_frame");
+ gVideoPicture.height = _height;
+ gVideoPicture.width = _width;
+ ++gVideoPacketNum;
+ wait_get_dependency();
/*see if it's a gop start, if so, load the gop info*/
LOGI(10, "gVideoPacketNum = %d; gNumOfGop = %d;", gVideoPacketNum, gNumOfGop);
for (li = 0; li < gNumOfGop; ++li) {
@@ -99,22 +103,24 @@ static void render_a_frame(int p_zoomLevelUpdate, int _width, int _height, float
gCurrentDecodingVideoFileIndex = 0;
}
gZoomLevelUpdate = 0;
+ //after zoom level is updated, we'll need to check if we need to wait for dumping dependency
+ wait_get_dependency();
}
//start of a gop
gStFrame = gGopStart[li];
- //start of a gop indicates the previous gop is done decoding
- gVideoPacketQueueList[gCurrentDecodingVideoFileIndex].decode_gop_num = li;
- //3.0 based on roi pixel coordinates, calculate the mb-based roi coordinates
- l_roiSh = (_roiSh - 15) > 0 ? (_roiSh - 15):0;
- l_roiSw = (_roiSw - 15) > 0 ? (_roiSw - 15):0;
- l_roiEh = (_roiEh + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height ? (_roiEh + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
- l_roiEw = (_roiEw + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width ? (_roiEw + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
- l_roiSh = l_roiSh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
- l_roiSw = l_roiSw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
- l_roiEh = l_roiEh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
- l_roiEw = l_roiEw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
- //3.1 check if it's a beginning of a gop, if so, load the pre computation result and compute the inter frame dependency
- LOGI(10, "decode video %d with roi (%d:%d) to (%d:%d)", gCurrentDecodingVideoFileIndex, l_roiSh, l_roiSw, l_roiEh, l_roiEw);
+ //start of a gop indicates the previous gop is done decoding
+ g_decode_gop_num = li;
+ //3.0 based on roi pixel coordinates, calculate the mb-based roi coordinates
+ l_roiSh = (_roiSh - 15) > 0 ? (_roiSh - 15):0;
+ l_roiSw = (_roiSw - 15) > 0 ? (_roiSw - 15):0;
+ l_roiEh = (_roiEh + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height ? (_roiEh + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
+ l_roiEw = (_roiEw + 15) < gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width ? (_roiEw + 15):gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
+ l_roiSh = l_roiSh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
+ l_roiSw = l_roiSw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
+ l_roiEh = l_roiEh * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->height;
+ l_roiEw = l_roiEw * (gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width/16) / gVideoCodecCtxList[gCurrentDecodingVideoFileIndex]->width;
+ //3.1 check if it's a beginning of a gop, if so, load the pre computation result and compute the inter frame dependency
+ LOGI(10, "decode video %d with roi (%d:%d) to (%d:%d)", gCurrentDecodingVideoFileIndex, l_roiSh, l_roiSw, l_roiEh, l_roiEw);
prepare_decode_of_gop(gCurrentDecodingVideoFileIndex, gGopStart[li], gGopEnd[li], l_roiSh, l_roiSw, l_roiEh, l_roiEw);
break;
} else if (gVideoPacketNum < gGopEnd[li]) {
View
@@ -59,7 +59,7 @@ int packet_queue_get(PacketQueue *q, AVPacket *pPkt) {
//pthread_mutex_lock(&q->mutex);
for (;;) {
lPktList = q->first_pkt;
- if (q->dep_gop_num > q->decode_gop_num && lPktList) {
+ if (q->dep_gop_num > g_decode_gop_num && lPktList) {
q->first_pkt = lPktList->next;
if (!q->first_pkt) {
q->last_pkt = NULL;
View
@@ -8,15 +8,18 @@ So that when the dependency dump thread is done with a GOP. The selective decodi
typedef struct PacketQueue {
AVPacketList *first_pkt, *last_pkt;
int dep_gop_num; //number of gop that its dependency has been dumped
- int decode_gop_num; //number of gop that its frames have been decoded, if decode_gop_num < dep_gop_num,
+ //int decode_gop_num; //number of gop that its frames have been decoded, if decode_gop_num < dep_gop_num,
//the selective decoding of next gop can start; otherwise, we'll need to wait
+ //note: move this to global as there's only a single decoding queue but multiple dependency dumping queue
int nb_packets;
//pthread_mutex_t mutex;
//pthread_cond_t cond;
} PacketQueue;
PacketQueue *gVideoPacketQueueList;
+int g_decode_gop_num;
+
void packet_queue_init(PacketQueue *q);
void packet_queue_flush(PacketQueue *q);
int packet_queue_put(PacketQueue *q, AVPacket *pkt);

0 comments on commit 9ccb6ba

Please sign in to comment.