diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-10-08 12:25:07 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-06-12 11:38:13 +0200 |
commit | fe6037fd04db8837dcdb9013f9c4ad4e7eb0592e (patch) | |
tree | f1d9d01bd96a2ae05710d737961340c40986e35b /libavcodec/rv34.c | |
parent | dac15a5b6edec3c055a3add853a80b99246d6829 (diff) | |
download | ffmpeg-fe6037fd04db8837dcdb9013f9c4ad4e7eb0592e.tar.gz |
avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary Pic
There are two types of MPVPictures: Three (cur_pic, last_pic, next_pic)
that are directly part of MpegEncContext and an array of MPVPictures
that are separately allocated and are mostly accessed via pointers
(cur|last|next)_pic_ptr; they are also used to store AVFrames in the
encoder (necessary due to B-frames). As the name implies, each of the
former is directly associated with one of the _ptr pointers:
They actually share the same underlying buffers, but the ones
that are part of the context can have their data pointers offset
and their linesize doubled for field pictures.
Up until now, each of these had their own references; in particular,
there was an underlying av_frame_ref() to sync cur_pic and cur_pic_ptr
etc. This is wasteful.
This commit changes this relationship: cur_pic, last_pic and next_pic
now become MPVWorkPictures; this structure does not have an AVFrame
at all any more, but only the cached values of data and linesize.
It also contains a pointer to the corresponding MPVPicture, establishing
a more natural relationsship between the two.
This already means that creating the context-pictures from the pointers
can no longer fail.
What has not been changed is the fact that the MPVPicture* pointers
are not ownership pointers and that the MPVPictures are part of an
array of MPVPictures that is owned by a single AVCodecContext.
Doing so will be done in a latter commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/rv34.c')
-rw-r--r-- | libavcodec/rv34.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 20e91c20ff..6424c7b982 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -567,7 +567,7 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) int has_A = 0, has_B = 0, has_C = 0; int mx, my; int i, j; - MPVPicture *cur_pic = &s->cur_pic; + MPVWorkPicture *cur_pic = &s->cur_pic; const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0; int type = cur_pic->mb_type[mb_pos]; @@ -721,7 +721,7 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type, if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) { /* wait for the referenced mb row to be finished */ int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4); - const ThreadFrame *f = dir ? &s->next_pic_ptr->tf : &s->last_pic_ptr->tf; + const ThreadFrame *f = dir ? &s->next_pic.ptr->tf : &s->last_pic.ptr->tf; ff_thread_await_progress(f, mb_row, 0); } @@ -901,7 +901,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) //surprisingly, it uses motion scheme from next reference frame /* wait for the current mb row to be finished */ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_await_progress(&s->next_pic_ptr->tf, FFMAX(0, s->mb_y-1), 0); + ff_thread_await_progress(&s->next_pic.ptr->tf, FFMAX(0, s->mb_y-1), 0); next_bt = s->next_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride]; if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){ @@ -1485,7 +1485,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int r->loop_filter(r, s->mb_y - 2); if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_report_progress(&s->cur_pic_ptr->tf, + ff_thread_report_progress(&s->cur_pic.ptr->tf, s->mb_y - 2, 0); } @@ -1583,19 +1583,19 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) s->mb_num_left = 0; if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_report_progress(&s->cur_pic_ptr->tf, INT_MAX, 0); + ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0); if (s->pict_type == AV_PICTURE_TYPE_B) { - if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0) + if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0) return ret; - ff_print_debug_info(s, s->cur_pic_ptr, pict); - ff_mpv_export_qp_table(s, pict, s->cur_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1); + ff_print_debug_info(s, s->cur_pic.ptr, pict); + ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); got_picture = 1; - } else if (s->last_pic_ptr) { - if ((ret = av_frame_ref(pict, s->last_pic_ptr->f)) < 0) + } else if (s->last_pic.ptr) { + if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0) return ret; - ff_print_debug_info(s, s->last_pic_ptr, pict); - ff_mpv_export_qp_table(s, pict, s->last_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1); + ff_print_debug_info(s, s->last_pic.ptr, pict); + ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1); got_picture = 1; } @@ -1630,10 +1630,10 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, /* no supplementary picture */ if (buf_size == 0) { /* special case for last picture */ - if (s->next_pic_ptr) { - if ((ret = av_frame_ref(pict, s->next_pic_ptr->f)) < 0) + if (s->next_pic.ptr) { + if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0) return ret; - s->next_pic_ptr = NULL; + s->next_pic.ptr = NULL; *got_picture_ptr = 1; } @@ -1656,7 +1656,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n"); return AVERROR_INVALIDDATA; } - if ((!s->last_pic_ptr || !s->last_pic_ptr->f->data[0]) && + if ((!s->last_pic.ptr || !s->last_pic.ptr->f->data[0]) && si.type == AV_PICTURE_TYPE_B) { av_log(avctx, AV_LOG_ERROR, "Invalid decoder state: B-frame without " "reference data.\n"); @@ -1669,7 +1669,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, /* first slice */ if (si.start == 0) { - if (s->mb_num_left > 0 && s->cur_pic_ptr) { + if (s->mb_num_left > 0 && s->cur_pic.ptr) { av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", s->mb_num_left); if (!s->context_reinit) @@ -1794,7 +1794,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, break; } - if (s->cur_pic_ptr) { + if (s->cur_pic.ptr) { if (last) { if(r->loop_filter) r->loop_filter(r, s->mb_height - 1); @@ -1811,7 +1811,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, ff_er_frame_end(&s->er, NULL); ff_mpv_frame_end(s); s->mb_num_left = 0; - ff_thread_report_progress(&s->cur_pic_ptr->tf, INT_MAX, 0); + ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0); return AVERROR_INVALIDDATA; } } |