Commit 36f862e0 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'a0f29460'

* commit 'a0f29460':
  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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 07a79cf8 a0f29460
......@@ -51,7 +51,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
memset(pp, 0, sizeof(*pp));
/* Configure current picture */
fill_picture_entry(&pp->CurrPic,
ff_dxva2_get_surface_index(ctx, &current_picture->f),
ff_dxva2_get_surface_index(ctx, current_picture->f),
h->picture_structure == PICT_BOTTOM_FIELD);
/* Configure the set of references */
pp->UsedForReferenceFlags = 0;
......@@ -67,7 +67,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context
}
if (r) {
fill_picture_entry(&pp->RefFrameList[i],
ff_dxva2_get_surface_index(ctx, &r->f),
ff_dxva2_get_surface_index(ctx, r->f),
r->long_ref != 0);
if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX)
......@@ -244,9 +244,9 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
unsigned plane;
unsigned index;
if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO)
index = ff_dxva2_get_surface_index(ctx, &r->f);
index = ff_dxva2_get_surface_index(ctx, r->f);
else
index = get_refpic_index(pp, ff_dxva2_get_surface_index(ctx, &r->f));
index = get_refpic_index(pp, ff_dxva2_get_surface_index(ctx, r->f));
fill_picture_entry(&slice->RefPicList[list][i], index,
r->reference == PICT_BOTTOM_FIELD);
for (plane = 0; plane < 3; plane++) {
......@@ -454,7 +454,7 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx)
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
return -1;
ret = ff_dxva2_common_end_frame(avctx, &h->cur_pic_ptr->f,
ret = ff_dxva2_common_end_frame(avctx, h->cur_pic_ptr->f,
&ctx_pic->pp, sizeof(ctx_pic->pp),
&ctx_pic->qm, sizeof(ctx_pic->qm),
commit_bitstream_and_slice_buffer);
......
This diff is collapsed.
......@@ -290,8 +290,7 @@ typedef struct MMCO {
} MMCO;
typedef struct H264Picture {
struct AVFrame f;
uint8_t avframe_padding[1024]; // hack to allow linking to a avutil with larger AVFrame
AVFrame *f;
ThreadFrame tf;
AVBufferRef *qscale_table_buf;
......
......@@ -57,9 +57,9 @@ static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContex
const int block_h = 16 >> h->chroma_y_shift;
const int chroma422 = CHROMA422(h);
dest_y = h->cur_pic.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;
dest_cb = h->cur_pic.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
dest_cr = h->cur_pic.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
dest_y = h->cur_pic.f->data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;
dest_cb = h->cur_pic.f->data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
dest_cr = h->cur_pic.f->data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;
h->vdsp.prefetch(dest_y + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT), sl->linesize, 4);
h->vdsp.prefetch(dest_cb + (sl->mb_x & 7) * sl->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2);
......@@ -283,7 +283,7 @@ static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceCo
const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) ? 3 : 1;
for (p = 0; p < plane_count; p++) {
dest[p] = h->cur_pic.f.data[p] +
dest[p] = h->cur_pic.f->data[p] +
((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;
h->vdsp.prefetch(dest[p] + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT),
sl->linesize, 4);
......
......@@ -49,7 +49,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
int off = offsetof(H264Picture, tf) + sizeof(pic->tf);
int i;
if (!pic->f.buf[0])
if (!pic->f || !pic->f->buf[0])
return;
ff_thread_release_buffer(h->avctx, &pic->tf);
......@@ -69,11 +69,11 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
{
int ret, i;
av_assert0(!dst->f.buf[0]);
av_assert0(src->f.buf[0]);
av_assert0(!dst->f->buf[0]);
av_assert0(src->f->buf[0]);
src->tf.f = &src->f;
dst->tf.f = &dst->f;
src->tf.f = src->f;
dst->tf.f = dst->f;
ret = ff_thread_ref_frame(&dst->tf, &src->tf);
if (ret < 0)
goto fail;
......@@ -138,7 +138,7 @@ void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
if (!src)
return;
dst->f = &src->f;
dst->f = src->f;
dst->tf = &src->tf;
for (i = 0; i < 2; i++) {
......@@ -196,15 +196,15 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
* causes problems for the first MB line, too.
*/
if (!FIELD_PICTURE(h) && h->current_slice && !h->sps.new && h->enable_er) {
int use_last_pic = h->last_pic_for_ec.f.buf[0] && !sl->ref_count[0];
int use_last_pic = h->last_pic_for_ec.f->buf[0] && !sl->ref_count[0];
ff_h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);
if (use_last_pic) {
ff_h264_set_erpic(&sl->er.last_pic, &h->last_pic_for_ec);
sl->ref_list[0][0].parent = &h->last_pic_for_ec;
memcpy(sl->ref_list[0][0].data, h->last_pic_for_ec.f.data, sizeof(sl->ref_list[0][0].data));
memcpy(sl->ref_list[0][0].linesize, h->last_pic_for_ec.f.linesize, sizeof(sl->ref_list[0][0].linesize));
memcpy(sl->ref_list[0][0].data, h->last_pic_for_ec.f->data, sizeof(sl->ref_list[0][0].data));
memcpy(sl->ref_list[0][0].linesize, h->last_pic_for_ec.f->linesize, sizeof(sl->ref_list[0][0].linesize));
sl->ref_list[0][0].reference = h->last_pic_for_ec.reference;
} else if (sl->ref_count[0]) {
ff_h264_set_erpic(&sl->er.last_pic, sl->ref_list[0][0].parent);
......
......@@ -50,8 +50,8 @@ static void pic_as_field(H264Ref *pic, const int parity)
static void ref_from_h264pic(H264Ref *dst, H264Picture *src)
{
memcpy(dst->data, src->f.data, sizeof(dst->data));
memcpy(dst->linesize, src->f.linesize, sizeof(dst->linesize));
memcpy(dst->data, src->f->data, sizeof(dst->data));
memcpy(dst->linesize, src->f->linesize, sizeof(dst->linesize));
dst->reference = src->reference;
dst->poc = src->poc;
dst->pic_id = src->pic_id;
......@@ -155,8 +155,8 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl)
if (lens[0] == lens[1] && lens[1] > 1) {
for (i = 0; i < lens[0] &&
h->default_ref_list[0][i].parent->f.buf[0]->buffer ==
h->default_ref_list[1][i].parent->f.buf[0]->buffer; i++);
h->default_ref_list[0][i].parent->f->buf[0]->buffer ==
h->default_ref_list[1][i].parent->f->buf[0]->buffer; i++);
if (i == lens[0]) {
FFSWAP(H264Ref, h->default_ref_list[1][0], h->default_ref_list[1][1]);
}
......@@ -177,14 +177,14 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl)
ff_tlog(h->avctx, "List0: %s fn:%d 0x%p\n",
h->default_ref_list[0][i].parent ? (h->default_ref_list[0][i].parent->long_ref ? "LT" : "ST") : "NULL",
h->default_ref_list[0][i].pic_id,
h->default_ref_list[0][i].parent ? h->default_ref_list[0][i].parent->f.data[0] : 0);
h->default_ref_list[0][i].parent ? h->default_ref_list[0][i].parent->f->data[0] : 0);
}
if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
for (i = 0; i < sl->ref_count[1]; i++) {
ff_tlog(h->avctx, "List1: %s fn:%d 0x%p\n",
h->default_ref_list[1][i].parent ? (h->default_ref_list[1][i].parent->long_ref ? "LT" : "ST") : "NULL",
h->default_ref_list[1][i].pic_id,
h->default_ref_list[1][i].parent ? h->default_ref_list[1][i].parent->f.data[0] : 0);
h->default_ref_list[1][i].parent ? h->default_ref_list[1][i].parent->f->data[0] : 0);
}
}
#endif
......@@ -341,7 +341,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
else
return -1;
}
av_assert0(av_buffer_get_ref_count(sl->ref_list[list][index].parent->f.buf[0]) > 0);
av_assert0(av_buffer_get_ref_count(sl->ref_list[list][index].parent->f->buf[0]) > 0);
}
}
......@@ -366,7 +366,7 @@ void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl)
field[1] = field[0];
for (j = 0; j < 3; j++)
field[1].data[j] += frame->parent->f.linesize[j];
field[1].data[j] += frame->parent->f->linesize[j];
field[1].reference = PICT_BOTTOM_FIELD;
field[1].poc = field[1].parent->field_poc[1];
......@@ -497,7 +497,7 @@ void ff_h264_remove_all_refs(H264Context *h)
}
assert(h->long_ref_count == 0);
if (h->short_ref_count && !h->last_pic_for_ec.f.data[0]) {
if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) {
ff_h264_unref_picture(h, &h->last_pic_for_ec);
ff_h264_ref_picture(h, &h->last_pic_for_ec, h->short_ref[0]);
}
......@@ -527,7 +527,7 @@ static void print_short_term(H264Context *h)
for (i = 0; i < h->short_ref_count; i++) {
H264Picture *pic = h->short_ref[i];
av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n",
i, pic->frame_num, pic->poc, pic->f.data[0]);
i, pic->frame_num, pic->poc, pic->f->data[0]);
}
}
}
......@@ -544,7 +544,7 @@ static void print_long_term(H264Context *h)
H264Picture *pic = h->long_ref[i];
if (pic) {
av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n",
i, pic->frame_num, pic->poc, pic->f.data[0]);
i, pic->frame_num, pic->poc, pic->f->data[0]);
}
}
}
......@@ -789,7 +789,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
&& h->long_ref_count==0
&& (h->short_ref_count<=2 || h->pps.ref_count[0] <= 1 && h->pps.ref_count[1] <= 1 && pps_count == 1)
&& h->pps.ref_count[0]<=2 + (h->picture_structure != PICT_FRAME) + (2*!h->has_recovery_point)
&& h->cur_pic_ptr->f.pict_type == AV_PICTURE_TYPE_I){
&& h->cur_pic_ptr->f->pict_type == AV_PICTURE_TYPE_I){
h->cur_pic_ptr->recovered |= 1;
if(!h->avctx->has_b_frames)
h->frame_recovered |= FRAME_RECOVERED_SEI;
......
......@@ -154,7 +154,7 @@ static void release_unused_pictures(H264Context *h, int remove_current)
/* release non reference frames */
for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
if (h->DPB[i].f.buf[0] && !h->DPB[i].reference &&
if (h->DPB[i].f->buf[0] && !h->DPB[i].reference &&
(remove_current || &h->DPB[i] != h->cur_pic_ptr)) {
ff_h264_unref_picture(h, &h->DPB[i]);
}
......@@ -224,9 +224,9 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
{
int i, ret = 0;
av_assert0(!pic->f.data[0]);
av_assert0(!pic->f->data[0]);
pic->tf.f = &pic->f;
pic->tf.f = pic->f;
ret = ff_thread_get_buffer(h->avctx, &pic->tf, pic->reference ?
AV_GET_BUFFER_FLAG_REF : 0);
if (ret < 0)
......@@ -246,15 +246,15 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;
}
}
if (CONFIG_GRAY && !h->avctx->hwaccel && h->flags & CODEC_FLAG_GRAY && pic->f.data[2]) {
if (CONFIG_GRAY && !h->avctx->hwaccel && h->flags & CODEC_FLAG_GRAY && pic->f->data[2]) {
int h_chroma_shift, v_chroma_shift;
av_pix_fmt_get_chroma_sub_sample(pic->f.format,
av_pix_fmt_get_chroma_sub_sample(pic->f->format,
&h_chroma_shift, &v_chroma_shift);
for(i=0; i<FF_CEIL_RSHIFT(h->avctx->height, v_chroma_shift); i++) {
memset(pic->f.data[1] + pic->f.linesize[1]*i,
memset(pic->f->data[1] + pic->f->linesize[1]*i,
0x80, FF_CEIL_RSHIFT(h->avctx->width, h_chroma_shift));
memset(pic->f.data[2] + pic->f.linesize[2]*i,
memset(pic->f->data[2] + pic->f->linesize[2]*i,
0x80, FF_CEIL_RSHIFT(h->avctx->width, h_chroma_shift));
}
}
......@@ -291,7 +291,7 @@ fail:
static inline int pic_is_unused(H264Context *h, H264Picture *pic)
{
if (!pic->f.buf[0])
if (!pic->f->buf[0])
return 1;
return 0;
}
......@@ -500,14 +500,14 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
ff_h264_unref_picture(h, &h->DPB[i]);
if (h1->DPB[i].f.buf[0] &&
if (h1->DPB[i].f->buf[0] &&
(ret = ff_h264_ref_picture(h, &h->DPB[i], &h1->DPB[i])) < 0)
return ret;
}
h->cur_pic_ptr = REBASE_PICTURE(h1->cur_pic_ptr, h, h1);
ff_h264_unref_picture(h, &h->cur_pic);
if (h1->cur_pic.f.buf[0]) {
if (h1->cur_pic.f->buf[0]) {
ret = ff_h264_ref_picture(h, &h->cur_pic, &h1->cur_pic);
if (ret < 0)
return ret;
......@@ -594,7 +594,7 @@ static int h264_frame_start(H264Context *h)
pic = &h->DPB[i];
pic->reference = h->droppable ? 0 : h->picture_structure;
pic->f.coded_picture_number = h->coded_picture_number++;
pic->f->coded_picture_number = h->coded_picture_number++;
pic->field_picture = h->picture_structure != PICT_FRAME;
/*
......@@ -602,7 +602,7 @@ static int h264_frame_start(H264Context *h)
* in later.
* See decode_nal_units().
*/
pic->f.key_frame = 0;
pic->f->key_frame = 0;
pic->mmco_reset = 0;
pic->recovered = 0;
pic->invalid_gap = 0;
......@@ -612,7 +612,7 @@ static int h264_frame_start(H264Context *h)
return ret;
if(!h->frame_recovered && !h->avctx->hwaccel &&
!(h->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU))
avpriv_color_frame(&pic->f, c);
avpriv_color_frame(pic->f, c);
h->cur_pic_ptr = pic;
ff_h264_unref_picture(h, &h->cur_pic);
......@@ -624,8 +624,8 @@ static int h264_frame_start(H264Context *h)
return ret;
for (i = 0; i < h->nb_slice_ctx; i++) {
h->slice_ctx[i].linesize = h->cur_pic_ptr->f.linesize[0];
h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f.linesize[1];
h->slice_ctx[i].linesize = h->cur_pic_ptr->f->linesize[0];
h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f->linesize[1];
}
if (CONFIG_ERROR_RESILIENCE && h->enable_er) {
......@@ -635,14 +635,14 @@ static int h264_frame_start(H264Context *h)
}
for (i = 0; i < 16; i++) {
h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f.linesize[0] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f.linesize[0] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
}
for (i = 0; i < 16; i++) {
h->block_offset[16 + i] =
h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f.linesize[1] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[48 + 16 + i] =
h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f.linesize[1] * ((scan8[i] - scan8[0]) >> 3);
h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
}
/* We mark the current picture as non-reference after allocating it, so
......@@ -1460,7 +1460,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
* since that can modify h->cur_pic_ptr. */
if (h->first_field) {
av_assert0(h->cur_pic_ptr);
av_assert0(h->cur_pic_ptr->f.buf[0]);
av_assert0(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
/* Mark old field/frame as completed */
......@@ -1545,10 +1545,10 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
* is not noticeable by comparison, but it should be fixed. */
if (h->short_ref_count) {
if (prev) {
av_image_copy(h->short_ref[0]->f.data,
h->short_ref[0]->f.linesize,
(const uint8_t **)prev->f.data,
prev->f.linesize,
av_image_copy(h->short_ref[0]->f->data,
h->short_ref[0]->f->linesize,
(const uint8_t **)prev->f->data,
prev->f->linesize,
h->avctx->pix_fmt,
h->mb_width * 16,
h->mb_height * 16);
......@@ -1563,7 +1563,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
* frame, or to allocate a new one. */
if (h->first_field) {
av_assert0(h->cur_pic_ptr);
av_assert0(h->cur_pic_ptr->f.buf[0]);
av_assert0(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
/* figure out if we have a complementary field pair */
......@@ -1833,16 +1833,16 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
for (i = 0; i < 16; i++) {
id_list[i] = 60;
if (j < sl->list_count && i < sl->ref_count[j] &&
sl->ref_list[j][i].parent->f.buf[0]) {
sl->ref_list[j][i].parent->f->buf[0]) {
int k;
AVBuffer *buf = sl->ref_list[j][i].parent->f.buf[0]->buffer;
AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;
for (k = 0; k < h->short_ref_count; k++)
if (h->short_ref[k]->f.buf[0]->buffer == buf) {
if (h->short_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = k;
break;
}
for (k = 0; k < h->long_ref_count; k++)
if (h->long_ref[k] && h->long_ref[k]->f.buf[0]->buffer == buf) {
if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) {
id_list[i] = h->short_ref_count + k;
break;
}
......@@ -2161,12 +2161,12 @@ static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x,
sl->mb_x = mb_x;
sl->mb_y = mb_y;
dest_y = h->cur_pic.f.data[0] +
dest_y = h->cur_pic.f->data[0] +
((mb_x << pixel_shift) + mb_y * sl->linesize) * 16;
dest_cb = h->cur_pic.f.data[1] +
dest_cb = h->cur_pic.f->data[1] +
(mb_x << pixel_shift) * (8 << CHROMA444(h)) +
mb_y * sl->uvlinesize * block_h;
dest_cr = h->cur_pic.f.data[2] +
dest_cr = h->cur_pic.f->data[2] +
(mb_x << pixel_shift) * (8 << CHROMA444(h)) +
mb_y * sl->uvlinesize * block_h;
// FIXME simplify above
......@@ -2271,8 +2271,8 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
int lf_x_start = sl->mb_x;
int ret;
sl->linesize = h->cur_pic_ptr->f.linesize[0];
sl->uvlinesize = h->cur_pic_ptr->f.linesize[1];
sl->linesize = h->cur_pic_ptr->f->linesize[0];
sl->uvlinesize = h->cur_pic_ptr->f->linesize[1];
ret = alloc_scratch_buffers(sl, sl->linesize);
if (ret < 0)
......
......@@ -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);
......
......@@ -59,7 +59,7 @@ static void fill_vaapi_pic(VAPictureH264 *va_pic,
pic_structure = pic->reference;
pic_structure &= PICT_FRAME; /* PICT_TOP_FIELD|PICT_BOTTOM_FIELD */
va_pic->picture_id = ff_vaapi_get_surface_id(&pic->f);
va_pic->picture_id = ff_vaapi_get_surface_id(pic->f);
va_pic->frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
va_pic->flags = 0;
......@@ -99,7 +99,7 @@ static int dpb_add(DPB *dpb, H264Picture *pic)
for (i = 0; i < dpb->size; i++) {
VAPictureH264 * const va_pic = &dpb->va_pics[i];
if (va_pic->picture_id == ff_vaapi_get_surface_id(&pic->f)) {
if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
VAPictureH264 temp_va_pic;
fill_vaapi_pic(&temp_va_pic, pic, 0);
......@@ -301,7 +301,7 @@ static int vaapi_h264_end_frame(AVCodecContext *avctx)
if (ret < 0)
goto finish;
ret = ff_vaapi_render_picture(vactx, ff_vaapi_get_surface_id(&h->cur_pic_ptr->f));
ret = ff_vaapi_render_picture(vactx, ff_vaapi_get_surface_id(h->cur_pic_ptr->f));
if (ret < 0)
goto finish;
......
......@@ -143,7 +143,7 @@ static int vda_old_h264_end_frame(AVCodecContext *avctx)
H264Context *h = avctx->priv_data;
VDAContext *vda = avctx->internal->hwaccel_priv_data;
struct vda_context *vda_ctx = avctx->hwaccel_context;
AVFrame *frame = &h->cur_pic_ptr->f;
AVFrame *frame = h->cur_pic_ptr->f;
struct vda_buffer *context;
AVBufferRef *buffer;
int status;
......@@ -375,7 +375,7 @@ static int vda_h264_end_frame(AVCodecContext *avctx)
H264Context *h = avctx->priv_data;
VDAContext *vda = avctx->internal->hwaccel_priv_data;
AVVDAContext *vda_ctx = avctx->hwaccel_context;
AVFrame *frame = &h->cur_pic_ptr->f;
AVFrame *frame = h->cur_pic_ptr->f;
uint32_t flush_flags = 1 << 0; ///< kVDADecoderFlush_emitFrames
CFDataRef coded_frame;
OSStatus status;
......
......@@ -364,7 +364,7 @@ void ff_vdpau_h264_set_reference_frames(H264Context *h)
H264Picture *pic;
int i, list, pic_frame_idx;
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
render = (struct vdpau_render_state *)h->cur_pic_ptr->f->data[0];
assert(render);
rf = &render->info.h264.referenceFrames[0];
......@@ -380,7 +380,7 @@ void ff_vdpau_h264_set_reference_frames(H264Context *h)
continue;
pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
render_ref = (struct vdpau_render_state *)pic->f.data[0];
render_ref = (struct vdpau_render_state *)pic->f->data[0];
assert(render_ref);
rf2 = &render->info.h264.referenceFrames[0];
......@@ -448,7 +448,7 @@ void ff_vdpau_h264_picture_start(H264Context *h)
struct vdpau_render_state *render;
int i;
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
render = (struct vdpau_render_state *)h->cur_pic_ptr->f->data[0];
assert(render);
for (i = 0; i < 2; ++i) {
......@@ -465,7 +465,7 @@ void ff_vdpau_h264_picture_complete(H264Context *h)
{
struct vdpau_render_state *render;
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
render = (struct vdpau_render_state *)h->cur_pic_ptr->f->data[0];
assert(render);
render->info.h264.slice_count = h->current_slice;
......
......@@ -51,7 +51,7 @@ static void vdpau_h264_clear_rf(VdpReferenceFrameH264 *rf)
static void vdpau_h264_set_rf(VdpReferenceFrameH264 *rf, H264Picture *pic,
int pic_structure)
{
VdpVideoSurface surface = ff_vdpau_get_surface_id(&pic->f);
VdpVideoSurface surface = ff_vdpau_get_surface_id(pic->f);
if (pic_structure == 0)
pic_structure = pic->reference;
......@@ -88,7 +88,7 @@ static void vdpau_h264_set_reference_frames(AVCodecContext *avctx)
if (!pic || !pic->reference)
continue;
pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
surface_ref = ff_vdpau_get_surface_id(&pic->f);
surface_ref = ff_vdpau_get_surface_id(pic->f);
rf2 = &info->referenceFrames[0];
while (rf2 != rf) {
......@@ -203,7 +203,7 @@ static int vdpau_h264_end_frame(AVCodecContext *avctx)
struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
int val;
val = ff_vdpau_common_end_frame(avctx, &pic->f, pic_ctx);
val = ff_vdpau_common_end_frame(avctx, pic->f, pic_ctx);
if (val < 0)
return val;
......
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