aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/svq3.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-04-29 15:44:21 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-04-29 16:35:24 +0200
commit36f862e04c2afe37c1fd541e01013c6cef4c6015 (patch)
tree3983371af49a7234d87bf999b35b17875db09a64 /libavcodec/svq3.c
parent07a79cf8694ac685ae8f579ccc33d113eb46fe3d (diff)
parenta0f2946068c62e18cb05ac25c0df3d86077251a6 (diff)
downloadffmpeg-36f862e04c2afe37c1fd541e01013c6cef4c6015.tar.gz
Merge commit 'a0f2946068c62e18cb05ac25c0df3d86077251a6'
* commit 'a0f2946068c62e18cb05ac25c0df3d86077251a6': h264: use properly allocated AVFrames Conflicts: libavcodec/h264.c libavcodec/h264.h libavcodec/h264_refs.c libavcodec/h264_slice.c libavcodec/svq3.c libavcodec/vda_h264.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/svq3.c')
-rw-r--r--libavcodec/svq3.c90
1 files changed, 49 insertions, 41 deletions
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 05fc9b723b..a5920fb2fb 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -320,8 +320,8 @@ static inline void svq3_mc_dir_part(SVQ3Context *s,
}
/* form component predictions */
- dest = h->cur_pic.f.data[0] + x + y * sl->linesize;
- src = pic->f.data[0] + mx + my * sl->linesize;
+ dest = h->cur_pic.f->data[0] + x + y * sl->linesize;
+ src = pic->f->data[0] + mx + my * sl->linesize;
if (emu) {
h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, src,
@@ -347,8 +347,8 @@ static inline void svq3_mc_dir_part(SVQ3Context *s,
blocksize++;
for (i = 1; i < 3; i++) {
- dest = h->cur_pic.f.data[i] + (x >> 1) + (y >> 1) * sl->uvlinesize;
- src = pic->f.data[i] + mx + my * sl->uvlinesize;
+ dest = h->cur_pic.f->data[i] + (x >> 1) + (y >> 1) * sl->uvlinesize;
+ src = pic->f->data[i] + mx + my * sl->uvlinesize;
if (emu) {
h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, src,
@@ -890,9 +890,18 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx)
goto fail;
}
+ s->cur_pic->f = av_frame_alloc();
+ s->last_pic->f = av_frame_alloc();
+ s->next_pic->f = av_frame_alloc();
+ if (!s->cur_pic->f || !s->last_pic->f || !s->next_pic->f)
+ return AVERROR(ENOMEM);
+
if ((ret = ff_h264_decode_init(avctx)) < 0)
goto fail;
+ // we will overwrite it later during decoding
+ av_frame_free(&h->cur_pic.f);
+
ff_h264dsp_init(&h->h264dsp, 8, 1);
av_assert0(h->sps.bit_depth_chroma == 0);
ff_h264_pred_init(&h->hpc, AV_CODEC_ID_SVQ3, 8, 1);
@@ -1088,7 +1097,7 @@ static void free_picture(AVCodecContext *avctx, H264Picture *pic)
}
av_buffer_unref(&pic->mb_type_buf);
- av_frame_unref(&pic->f);
+ av_frame_unref(pic->f);
}
static int get_buffer(AVCodecContext *avctx, H264Picture *pic)
@@ -1124,19 +1133,19 @@ static int get_buffer(AVCodecContext *avctx, H264Picture *pic)
}
pic->reference = !(h->pict_type == AV_PICTURE_TYPE_B);
- ret = ff_get_buffer(avctx, &pic->f,
+ ret = ff_get_buffer(avctx, pic->f,
pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
if (ret < 0)
goto fail;
if (!sl->edge_emu_buffer) {
- sl->edge_emu_buffer = av_mallocz_array(pic->f.linesize[0], 17);
+ sl->edge_emu_buffer = av_mallocz_array(pic->f->linesize[0], 17);
if (!sl->edge_emu_buffer)
return AVERROR(ENOMEM);
}
- sl->linesize = pic->f.linesize[0];
- sl->uvlinesize = pic->f.linesize[1];
+ sl->linesize = pic->f->linesize[0];
+ sl->uvlinesize = pic->f->linesize[1];
return 0;
fail:
@@ -1157,8 +1166,8 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
/* special case for last picture */
if (buf_size == 0) {
- if (s->next_pic->f.data[0] && !h->low_delay && !s->last_frame_output) {
- ret = av_frame_ref(data, &s->next_pic->f);
+ if (s->next_pic->f->data[0] && !h->low_delay && !s->last_frame_output) {
+ ret = av_frame_ref(data, s->next_pic->f);
if (ret < 0)
return ret;
s->last_frame_output = 1;
@@ -1189,22 +1198,18 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
if (h->pict_type != AV_PICTURE_TYPE_B)
FFSWAP(H264Picture*, s->next_pic, s->last_pic);
- av_frame_unref(&s->cur_pic->f);
+ av_frame_unref(s->cur_pic->f);
/* for skipping the frame */
- s->cur_pic->f.pict_type = h->pict_type;
- s->cur_pic->f.key_frame = (h->pict_type == AV_PICTURE_TYPE_I);
+ s->cur_pic->f->pict_type = h->pict_type;
+ s->cur_pic->f->key_frame = (h->pict_type == AV_PICTURE_TYPE_I);
ret = get_buffer(avctx, s->cur_pic);
if (ret < 0)
return ret;
h->cur_pic_ptr = s->cur_pic;
- av_frame_unref(&h->cur_pic.f);
- memcpy(&h->cur_pic.tf, &s->cur_pic->tf, sizeof(h->cur_pic) - offsetof(H264Picture, tf));
- ret = av_frame_ref(&h->cur_pic.f, &s->cur_pic->f);
- if (ret < 0)
- return ret;
+ h->cur_pic = *s->cur_pic;
for (i = 0; i < 16; i++) {
h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * sl->linesize * ((scan8[i] - scan8[0]) >> 3);
@@ -1218,30 +1223,30 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
}
if (h->pict_type != AV_PICTURE_TYPE_I) {
- if (!s->last_pic->f.data[0]) {
+ if (!s->last_pic->f->data[0]) {
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
- av_frame_unref(&s->last_pic->f);
+ av_frame_unref(s->last_pic->f);
ret = get_buffer(avctx, s->last_pic);
if (ret < 0)
return ret;
- memset(s->last_pic->f.data[0], 0, avctx->height * s->last_pic->f.linesize[0]);
- memset(s->last_pic->f.data[1], 0x80, (avctx->height / 2) *
- s->last_pic->f.linesize[1]);
- memset(s->last_pic->f.data[2], 0x80, (avctx->height / 2) *
- s->last_pic->f.linesize[2]);
+ memset(s->last_pic->f->data[0], 0, avctx->height * s->last_pic->f->linesize[0]);
+ memset(s->last_pic->f->data[1], 0x80, (avctx->height / 2) *
+ s->last_pic->f->linesize[1]);
+ memset(s->last_pic->f->data[2], 0x80, (avctx->height / 2) *
+ s->last_pic->f->linesize[2]);
}
- if (h->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f.data[0]) {
+ if (h->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
- av_frame_unref(&s->next_pic->f);
+ av_frame_unref(s->next_pic->f);
ret = get_buffer(avctx, s->next_pic);
if (ret < 0)
return ret;
- memset(s->next_pic->f.data[0], 0, avctx->height * s->next_pic->f.linesize[0]);
- memset(s->next_pic->f.data[1], 0x80, (avctx->height / 2) *
- s->next_pic->f.linesize[1]);
- memset(s->next_pic->f.data[2], 0x80, (avctx->height / 2) *
- s->next_pic->f.linesize[2]);
+ memset(s->next_pic->f->data[0], 0, avctx->height * s->next_pic->f->linesize[0]);
+ memset(s->next_pic->f->data[1], 0x80, (avctx->height / 2) *
+ s->next_pic->f->linesize[1]);
+ memset(s->next_pic->f->data[2], 0x80, (avctx->height / 2) *
+ s->next_pic->f->linesize[2]);
}
}
@@ -1331,8 +1336,8 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
(h->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
}
- ff_draw_horiz_band(avctx, &s->cur_pic->f,
- s->last_pic->f.data[0] ? &s->last_pic->f : NULL,
+ ff_draw_horiz_band(avctx, s->cur_pic->f,
+ s->last_pic->f->data[0] ? s->last_pic->f : NULL,
16 * sl->mb_y, 16, h->picture_structure, 0,
h->low_delay);
}
@@ -1350,20 +1355,20 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
}
if (h->pict_type == AV_PICTURE_TYPE_B || h->low_delay)
- ret = av_frame_ref(data, &s->cur_pic->f);
- else if (s->last_pic->f.data[0])
- ret = av_frame_ref(data, &s->last_pic->f);
+ ret = av_frame_ref(data, s->cur_pic->f);
+ else if (s->last_pic->f->data[0])
+ ret = av_frame_ref(data, s->last_pic->f);
if (ret < 0)
return ret;
/* Do not output the last pic after seeking. */
- if (s->last_pic->f.data[0] || h->low_delay)
+ if (s->last_pic->f->data[0] || h->low_delay)
*got_frame = 1;
if (h->pict_type != AV_PICTURE_TYPE_B) {
FFSWAP(H264Picture*, s->cur_pic, s->next_pic);
} else {
- av_frame_unref(&s->cur_pic->f);
+ av_frame_unref(s->cur_pic->f);
}
return buf_size;
@@ -1377,11 +1382,14 @@ static av_cold int svq3_decode_end(AVCodecContext *avctx)
free_picture(avctx, s->cur_pic);
free_picture(avctx, s->next_pic);
free_picture(avctx, s->last_pic);
+ av_frame_free(&s->cur_pic->f);
+ av_frame_free(&s->next_pic->f);
+ av_frame_free(&s->last_pic->f);
av_freep(&s->cur_pic);
av_freep(&s->next_pic);
av_freep(&s->last_pic);
- av_frame_unref(&h->cur_pic.f);
+ memset(&h->cur_pic, 0, sizeof(h->cur_pic));
ff_h264_free_context(h);