From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/av1dec: honor the requested skip_frame level Date: Tue, 11 Jan 2022 09:45:31 -0300 Message-ID: <2efd5730-5116-a439-c96c-afe4febeda03@gmail.com> (raw) In-Reply-To: <20220109191855.2106-1-jamrial@gmail.com> On 1/9/2022 4:18 PM, James Almer wrote: > This supports dropping non-intra, non-key, or all frames. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > Now dropping the frames without decoding them. > > Untested with actual hardware. Tested by nevcairiel and confirmed to work, so will apply. > > libavcodec/av1dec.c | 68 ++++++++++++++++++++++++++------------------- > 1 file changed, 39 insertions(+), 29 deletions(-) > > diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c > index 09df2bf421..62d459cded 100644 > --- a/libavcodec/av1dec.c > +++ b/libavcodec/av1dec.c > @@ -585,16 +585,19 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s > { > int ret; > > - ret = ff_thread_ref_frame(&dst->tf, &src->tf); > + ret = av_buffer_replace(&dst->header_ref, src->header_ref); > if (ret < 0) > return ret; > > - dst->header_ref = av_buffer_ref(src->header_ref); > - if (!dst->header_ref) > - goto fail; > - > dst->raw_frame_header = src->raw_frame_header; > > + if (!src->tf.f->buf[0]) > + return 0; > + > + ret = ff_thread_ref_frame(&dst->tf, &src->tf); > + if (ret < 0) > + goto fail; > + > if (src->hwaccel_picture_private) { > dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); > if (!dst->hwaccel_priv_buf) > @@ -800,12 +803,6 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) > return ret; > } > > - f->header_ref = av_buffer_ref(s->header_ref); > - if (!f->header_ref) > - return AVERROR(ENOMEM); > - > - f->raw_frame_header = s->raw_frame_header; > - > if ((ret = ff_thread_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF)) < 0) > goto fail; > > @@ -945,8 +942,7 @@ static int update_reference_list(AVCodecContext *avctx) > > for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) { > if (header->refresh_frame_flags & (1 << i)) { > - if (s->ref[i].tf.f->buf[0]) > - av1_frame_unref(avctx, &s->ref[i]); > + av1_frame_unref(avctx, &s->ref[i]); > if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) { > av_log(avctx, AV_LOG_ERROR, > "Failed to update frame %d in reference list\n", i); > @@ -962,19 +958,32 @@ static int get_current_frame(AVCodecContext *avctx) > AV1DecContext *s = avctx->priv_data; > int ret; > > - if (s->cur_frame.tf.f->buf[0]) > - av1_frame_unref(avctx, &s->cur_frame); > + av1_frame_unref(avctx, &s->cur_frame); > > - ret = av1_frame_alloc(avctx, &s->cur_frame); > + s->cur_frame.header_ref = av_buffer_ref(s->header_ref); > + if (!s->cur_frame.header_ref) > + return AVERROR(ENOMEM); > + > + s->cur_frame.raw_frame_header = s->raw_frame_header; > + > + ret = init_tile_data(s); > if (ret < 0) { > - av_log(avctx, AV_LOG_ERROR, > - "Failed to allocate space for current frame.\n"); > + av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n"); > return ret; > } > > - ret = init_tile_data(s); > + if ((avctx->skip_frame >= AVDISCARD_NONINTRA && > + (s->raw_frame_header->frame_type != AV1_FRAME_KEY && > + s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) || > + (avctx->skip_frame >= AVDISCARD_NONKEY && > + s->raw_frame_header->frame_type != AV1_FRAME_KEY) || > + avctx->skip_frame >= AVDISCARD_ALL) > + return 0; > + > + ret = av1_frame_alloc(avctx, &s->cur_frame); > if (ret < 0) { > - av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n"); > + av_log(avctx, AV_LOG_ERROR, > + "Failed to allocate space for current frame.\n"); > return ret; > } > > @@ -1077,8 +1086,7 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > s->raw_frame_header = &obu->obu.frame_header; > > if (s->raw_frame_header->show_existing_frame) { > - if (s->cur_frame.tf.f->buf[0]) > - av1_frame_unref(avctx, &s->cur_frame); > + av1_frame_unref(avctx, &s->cur_frame); > > ret = av1_frame_ref(avctx, &s->cur_frame, > &s->ref[s->raw_frame_header->frame_to_show_map_idx]); > @@ -1093,9 +1101,11 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > goto end; > } > > - ret = set_output_frame(avctx, frame, pkt, got_frame); > - if (ret < 0) > - av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); > + if (s->cur_frame.tf.f->buf[0]) { > + ret = set_output_frame(avctx, frame, pkt, got_frame); > + if (ret < 0) > + av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); > + } > > s->raw_frame_header = NULL; > > @@ -1111,7 +1121,7 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > s->cur_frame.spatial_id = header->spatial_id; > s->cur_frame.temporal_id = header->temporal_id; > > - if (avctx->hwaccel) { > + if (avctx->hwaccel && s->cur_frame.tf.f->buf[0]) { > ret = avctx->hwaccel->start_frame(avctx, unit->data, > unit->data_size); > if (ret < 0) { > @@ -1138,7 +1148,7 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > if (ret < 0) > goto end; > > - if (avctx->hwaccel) { > + if (avctx->hwaccel && s->cur_frame.tf.f->buf[0]) { > ret = avctx->hwaccel->decode_slice(avctx, > raw_tile_group->tile_data.data, > raw_tile_group->tile_data.data_size); > @@ -1161,7 +1171,7 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > } > > if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) { > - if (avctx->hwaccel) { > + if (avctx->hwaccel && s->cur_frame.tf.f->buf[0]) { > ret = avctx->hwaccel->end_frame(avctx); > if (ret < 0) { > av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n"); > @@ -1175,7 +1185,7 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, > goto end; > } > > - if (s->raw_frame_header->show_frame) { > + if (s->raw_frame_header->show_frame && s->cur_frame.tf.f->buf[0]) { > ret = set_output_frame(avctx, frame, pkt, got_frame); > if (ret < 0) { > av_log(avctx, AV_LOG_ERROR, "Set output frame error\n"); _______________________________________________ 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".
prev parent reply other threads:[~2022-01-11 12:45 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-09 19:18 James Almer 2022-01-11 12:45 ` James Almer [this message]
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=2efd5730-5116-a439-c96c-afe4febeda03@gmail.com \ --to=jamrial@gmail.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