comparison mpeg12.c @ 9644:15660ad4c641 libavcodec

decode mpeg-2 closed gop first b frames, fix issue #824
author bcoudurier
date Fri, 15 May 2009 05:39:44 +0000
parents bd3e11b60ccd
children 6d75bcdeaa30
comparison
equal deleted inserted replaced
9643:5c9d3a72aabf 9644:15660ad4c641
28 //#define DEBUG 28 //#define DEBUG
29 #include "internal.h" 29 #include "internal.h"
30 #include "avcodec.h" 30 #include "avcodec.h"
31 #include "dsputil.h" 31 #include "dsputil.h"
32 #include "mpegvideo.h" 32 #include "mpegvideo.h"
33 #include "mpegvideo_common.h"
33 34
34 #include "mpeg12.h" 35 #include "mpeg12.h"
35 #include "mpeg12data.h" 36 #include "mpeg12data.h"
36 #include "mpeg12decdata.h" 37 #include "mpeg12decdata.h"
37 #include "bytestream.h" 38 #include "bytestream.h"
2137 MpegEncContext *s = &s1->mpeg_enc_ctx; 2138 MpegEncContext *s = &s1->mpeg_enc_ctx;
2138 2139
2139 int drop_frame_flag; 2140 int drop_frame_flag;
2140 int time_code_hours, time_code_minutes; 2141 int time_code_hours, time_code_minutes;
2141 int time_code_seconds, time_code_pictures; 2142 int time_code_seconds, time_code_pictures;
2142 int closed_gop, broken_link; 2143 int broken_link;
2143 2144
2144 init_get_bits(&s->gb, buf, buf_size*8); 2145 init_get_bits(&s->gb, buf, buf_size*8);
2145 2146
2146 drop_frame_flag = get_bits1(&s->gb); 2147 drop_frame_flag = get_bits1(&s->gb);
2147 2148
2149 time_code_minutes = get_bits(&s->gb,6); 2150 time_code_minutes = get_bits(&s->gb,6);
2150 skip_bits1(&s->gb);//marker bit 2151 skip_bits1(&s->gb);//marker bit
2151 time_code_seconds = get_bits(&s->gb,6); 2152 time_code_seconds = get_bits(&s->gb,6);
2152 time_code_pictures = get_bits(&s->gb,6); 2153 time_code_pictures = get_bits(&s->gb,6);
2153 2154
2154 closed_gop = get_bits1(&s->gb); 2155 s->closed_gop = get_bits1(&s->gb);
2155 /*broken_link indicate that after editing the 2156 /*broken_link indicate that after editing the
2156 reference frames of the first B-Frames after GOP I-Frame 2157 reference frames of the first B-Frames after GOP I-Frame
2157 are missing (open gop)*/ 2158 are missing (open gop)*/
2158 broken_link = get_bits1(&s->gb); 2159 broken_link = get_bits1(&s->gb);
2159 2160
2160 if(s->avctx->debug & FF_DEBUG_PICT_INFO) 2161 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
2161 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n", 2162 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n",
2162 time_code_hours, time_code_minutes, time_code_seconds, 2163 time_code_hours, time_code_minutes, time_code_seconds,
2163 time_code_pictures, closed_gop, broken_link); 2164 time_code_pictures, s->closed_gop, broken_link);
2164 } 2165 }
2165 /** 2166 /**
2166 * Finds the end of the current frame in the bitstream. 2167 * Finds the end of the current frame in the bitstream.
2167 * @return the position of the first byte of the next frame, or -1 2168 * @return the position of the first byte of the next frame, or -1
2168 */ 2169 */
2352 if (start_code >= SLICE_MIN_START_CODE && 2353 if (start_code >= SLICE_MIN_START_CODE &&
2353 start_code <= SLICE_MAX_START_CODE) { 2354 start_code <= SLICE_MAX_START_CODE) {
2354 int mb_y= start_code - SLICE_MIN_START_CODE; 2355 int mb_y= start_code - SLICE_MIN_START_CODE;
2355 2356
2356 if(s2->last_picture_ptr==NULL){ 2357 if(s2->last_picture_ptr==NULL){
2357 /* Skip B-frames if we do not have reference frames. */ 2358 /* Skip B-frames if we do not have reference frames and gop is not closed */
2358 if(s2->pict_type==FF_B_TYPE) break; 2359 if(s2->pict_type==FF_B_TYPE){
2360 int i;
2361 if(!s2->closed_gop)
2362 break;
2363 /* Allocate a dummy frame */
2364 i= ff_find_unused_picture(s2, 0);
2365 s2->last_picture_ptr= &s2->picture[i];
2366 if(alloc_picture(s2, s2->last_picture_ptr, 0) < 0)
2367 return -1;
2368 }
2359 } 2369 }
2360 if(s2->next_picture_ptr==NULL){ 2370 if(s2->next_picture_ptr==NULL){
2361 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ 2371 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */
2362 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; 2372 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break;
2363 } 2373 }