Commit 36603827 authored by tmmm's avatar tmmm

fix decoder so that ffmpeg does not crash, at least not right away


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@1838 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 13e9e4dc
...@@ -210,8 +210,6 @@ static int ModeAlphabet[7][CODING_MODE_COUNT] = ...@@ -210,8 +210,6 @@ static int ModeAlphabet[7][CODING_MODE_COUNT] =
typedef struct Vp3DecodeContext { typedef struct Vp3DecodeContext {
AVCodecContext *avctx; AVCodecContext *avctx;
int width, height; int width, height;
unsigned char *current_picture[3]; /* picture structure */
int linesize[3];
AVFrame golden_frame; AVFrame golden_frame;
AVFrame last_frame; AVFrame last_frame;
AVFrame current_frame; AVFrame current_frame;
...@@ -1966,20 +1964,20 @@ static void render_fragments(Vp3DecodeContext *s, ...@@ -1966,20 +1964,20 @@ static void render_fragments(Vp3DecodeContext *s,
if (plane == 0) { if (plane == 0) {
dequantizer = s->intra_y_dequant; dequantizer = s->intra_y_dequant;
output_plane = s->current_frame.data[0]; output_plane = s->current_frame.data[0];
last_plane = s->current_frame.data[0]; last_plane = s->last_frame.data[0];
golden_plane = s->current_frame.data[0]; golden_plane = s->golden_frame.data[0];
stride = -s->current_frame.linesize[0]; stride = -s->current_frame.linesize[0];
} else if (plane == 1) { } else if (plane == 1) {
dequantizer = s->intra_c_dequant; dequantizer = s->intra_c_dequant;
output_plane = s->current_frame.data[1]; output_plane = s->current_frame.data[1];
last_plane = s->current_frame.data[1]; last_plane = s->last_frame.data[1];
golden_plane = s->current_frame.data[1]; golden_plane = s->golden_frame.data[1];
stride = -s->current_frame.linesize[1]; stride = -s->current_frame.linesize[1];
} else { } else {
dequantizer = s->intra_c_dequant; dequantizer = s->intra_c_dequant;
output_plane = s->current_frame.data[2]; output_plane = s->current_frame.data[2];
last_plane = s->current_frame.data[2]; last_plane = s->last_frame.data[2];
golden_plane = s->current_frame.data[2]; golden_plane = s->golden_frame.data[2];
stride = -s->current_frame.linesize[2]; stride = -s->current_frame.linesize[2];
} }
...@@ -2189,6 +2187,12 @@ static int vp3_decode_init(AVCodecContext *avctx) ...@@ -2189,6 +2187,12 @@ static int vp3_decode_init(AVCodecContext *avctx)
s->macroblock_coded = av_malloc(s->macroblock_count + 1); s->macroblock_coded = av_malloc(s->macroblock_count + 1);
init_block_mapping(s); init_block_mapping(s);
/* make sure that frames are available to be freed on the first decode */
if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {
printf("vp3: get_buffer() failed\n");
return -1;
}
return 0; return 0;
} }
...@@ -2220,7 +2224,6 @@ static int vp3_decode_frame(AVCodecContext *avctx, ...@@ -2220,7 +2224,6 @@ static int vp3_decode_frame(AVCodecContext *avctx,
if (s->keyframe) { if (s->keyframe) {
/* release the previous golden frame and get a new one */ /* release the previous golden frame and get a new one */
if (counter > 1)
avctx->release_buffer(avctx, &s->golden_frame); avctx->release_buffer(avctx, &s->golden_frame);
s->golden_frame.reference = 0; s->golden_frame.reference = 0;
...@@ -2229,11 +2232,8 @@ static int vp3_decode_frame(AVCodecContext *avctx, ...@@ -2229,11 +2232,8 @@ static int vp3_decode_frame(AVCodecContext *avctx,
return -1; return -1;
} }
/* last frame is hereby invalidated */
avctx->release_buffer(avctx, &s->last_frame);
/* golden frame is also the current frame */ /* golden frame is also the current frame */
s->current_frame = s->golden_frame; memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame));
/* time to figure out pixel addresses? */ /* time to figure out pixel addresses? */
if (!s->pixel_addresses_inited) if (!s->pixel_addresses_inited)
...@@ -2276,15 +2276,14 @@ static int vp3_decode_frame(AVCodecContext *avctx, ...@@ -2276,15 +2276,14 @@ static int vp3_decode_frame(AVCodecContext *avctx,
render_fragments(s, s->v_fragment_start, render_fragments(s, s->v_fragment_start,
s->fragment_width / 2, s->fragment_height / 2, 2); s->fragment_width / 2, s->fragment_height / 2, 2);
*data_size=sizeof(AVFrame); *data_size=sizeof(AVFrame);
*(AVFrame*)data= s->current_frame; *(AVFrame*)data= s->current_frame;
/* release the last frame, if it was allocated */ /* release the last frame, if it was allocated */
avctx->release_buffer(avctx, &s->last_frame); avctx->release_buffer(avctx, &s->last_frame);
/* shuffle frames */ /* shuffle frames (last = current) */
s->last_frame = s->current_frame; memcpy(&s->last_frame, &s->current_frame, sizeof(AVFrame));
return buf_size; return buf_size;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment