From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/snow: Split ff_snow_get_buffer() Date: Mon, 25 Sep 2023 20:04:54 +0200 Message-ID: <AS8P250MB07445E095A140693F39559048FFCA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB0744D7FEB3A2719DC2D9F0EA8FFCA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> The part of said function that is common to both encoder and decoder is negligible since c954cf1e1b766a0d1992d5be0a8be0055a8e1a6a and more than offset by the costs of "Am I an encoder?" checks. So move allocating the frames to the encoder and decoder directly. Also rename ff_snow_frame_start() to ff_snow_frames_prepare(), because a frame without a buffer has not been properly started. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/snow.c | 46 +++++--------------------------------------- libavcodec/snow.h | 3 +-- libavcodec/snowdec.c | 9 ++++++++- libavcodec/snowenc.c | 29 ++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 5eb3ee1e9e..09f2d60f47 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -22,7 +22,6 @@ #include "libavutil/thread.h" #include "avcodec.h" #include "decode.h" -#include "encode.h" #include "snow_dwt.h" #include "snow.h" #include "snowdata.h" @@ -61,36 +60,6 @@ void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_ } } -int ff_snow_get_buffer(SnowContext *s, AVFrame *frame) -{ - int ret, i; - int edges_needed = av_codec_is_encoder(s->avctx->codec); - - frame->width = s->avctx->width ; - frame->height = s->avctx->height; - if (edges_needed) { - frame->width += 2 * EDGE_WIDTH; - frame->height += 2 * EDGE_WIDTH; - - ret = ff_encode_alloc_frame(s->avctx, frame); - } else - ret = ff_get_buffer(s->avctx, frame, AV_GET_BUFFER_FLAG_REF); - if (ret < 0) - return ret; - if (edges_needed) { - for (i = 0; frame->data[i]; i++) { - int offset = (EDGE_WIDTH >> (i ? s->chroma_v_shift : 0)) * - frame->linesize[i] + - (EDGE_WIDTH >> (i ? s->chroma_h_shift : 0)); - frame->data[i] += offset; - } - frame->width = s->avctx->width; - frame->height = s->avctx->height; - } - - return 0; -} - void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts int plane_index, level, orientation; @@ -589,20 +558,21 @@ void ff_snow_release_buffer(AVCodecContext *avctx) } } -int ff_snow_frame_start(SnowContext *s){ +int ff_snow_frames_prepare(SnowContext *s) +{ AVFrame *tmp; - int i, ret; ff_snow_release_buffer(s->avctx); tmp= s->last_picture[s->max_ref_frames-1]; - for(i=s->max_ref_frames-1; i>0; i--) + for (int i = s->max_ref_frames - 1; i > 0; i--) s->last_picture[i] = s->last_picture[i-1]; s->last_picture[0] = s->current_picture; s->current_picture = tmp; if(s->keyframe){ s->ref_frames= 0; + s->current_picture->flags |= AV_FRAME_FLAG_KEY; }else{ int i; for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++) @@ -613,14 +583,8 @@ int ff_snow_frame_start(SnowContext *s){ av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); return AVERROR_INVALIDDATA; } - } - if ((ret = ff_snow_get_buffer(s, s->current_picture)) < 0) - return ret; - - if (s->keyframe) - s->current_picture->flags |= AV_FRAME_FLAG_KEY; - else s->current_picture->flags &= ~AV_FRAME_FLAG_KEY; + } return 0; } diff --git a/libavcodec/snow.h b/libavcodec/snow.h index ed0f9abb42..73c4535ec1 100644 --- a/libavcodec/snow.h +++ b/libavcodec/snow.h @@ -245,11 +245,10 @@ void ff_snow_common_end(SnowContext *s); void ff_snow_release_buffer(AVCodecContext *avctx); void ff_snow_reset_contexts(SnowContext *s); int ff_snow_alloc_blocks(SnowContext *s); -int ff_snow_frame_start(SnowContext *s); +int ff_snow_frames_prepare(SnowContext *s); void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, ptrdiff_t stride, int sx, int sy, int b_w, int b_h, const BlockNode *block, int plane_index, int w, int h); -int ff_snow_get_buffer(SnowContext *s, AVFrame *frame); /* common inline functions */ //XXX doublecheck all of them should stay inlined diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c index e014d5087f..489c09324e 100644 --- a/libavcodec/snowdec.c +++ b/libavcodec/snowdec.c @@ -24,6 +24,7 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "codec_internal.h" +#include "decode.h" #include "snow_dwt.h" #include "snow.h" @@ -475,7 +476,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture, ff_snow_alloc_blocks(s); - if((res = ff_snow_frame_start(s)) < 0) + if ((res = ff_snow_frames_prepare(s)) < 0) + return res; + + s->current_picture->width = s->avctx->width; + s->current_picture->height = s->avctx->height; + res = ff_get_buffer(s->avctx, s->current_picture, AV_GET_BUFFER_FLAG_REF); + if (res < 0) return res; s->current_picture->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 14a59ca67b..f954a686c1 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -39,6 +39,28 @@ #include "mpegvideo.h" #include "h263enc.h" +static int get_encode_buffer(SnowContext *s, AVFrame *frame) +{ + int ret; + + frame->width = s->avctx->width + 2 * EDGE_WIDTH; + frame->height = s->avctx->height + 2 * EDGE_WIDTH; + + ret = ff_encode_alloc_frame(s->avctx, frame); + if (ret < 0) + return ret; + for (int i = 0; frame->data[i]; i++) { + int offset = (EDGE_WIDTH >> (i ? s->chroma_v_shift : 0)) * + frame->linesize[i] + + (EDGE_WIDTH >> (i ? s->chroma_h_shift : 0)); + frame->data[i] += offset; + } + frame->width = s->avctx->width; + frame->height = s->avctx->height; + + return 0; +} + static av_cold int encode_init(AVCodecContext *avctx) { SnowContext *s = avctx->priv_data; @@ -140,7 +162,7 @@ static av_cold int encode_init(AVCodecContext *avctx) if (!s->input_picture) return AVERROR(ENOMEM); - if ((ret = ff_snow_get_buffer(s, s->input_picture)) < 0) + if ((ret = get_encode_buffer(s, s->input_picture)) < 0) return ret; if(s->motion_est == FF_ME_ITER){ @@ -1659,7 +1681,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, emms_c(); } - ff_snow_frame_start(s); + ff_snow_frames_prepare(s); + ret = get_encode_buffer(s, s->current_picture); + if (ret < 0) + return ret; s->m.current_picture_ptr= &s->m.current_picture; s->m.current_picture.f = s->current_picture; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-09-25 18:05 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-25 17:53 [FFmpeg-devel] [PATCH 1/9] avfilter/bwdif: Add proper BWDIFDSPContext Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 2/9] avfilter/vf_bwdif: Move DSP code to a new file Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 3/9] avfilter/bwdifdsp: Constify Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 4/9] avfilter/bwdifdsp: Avoid including ff_bwdif_filter_line3_c() Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 5/9] checkasm/motion: Don't allocate AVCodecContext Andreas Rheinhardt 2023-09-25 18:04 ` Andreas Rheinhardt [this message] 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 7/9] avcodec/snow: Move decoder parts out of ff_snow_common_init_after_header Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 8/9] avcodec/aacsbrdata: Move ff_sbr_noise_table to sbrdsp_template.c Andreas Rheinhardt 2023-09-25 18:04 ` [FFmpeg-devel] [PATCH 9/9] avcodec/tests/.gitignore: Add bitstream test tools Andreas Rheinhardt 2023-09-26 22:11 ` [FFmpeg-devel] [PATCH 1/9] avfilter/bwdif: Add proper BWDIFDSPContext Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB07445E095A140693F39559048FFCA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git