Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/librav1e: export extradata on init()
Date: Wed, 12 Oct 2022 10:08:27 -0300
Message-ID: <20221012130829.2392-2-jamrial@gmail.com> (raw)
In-Reply-To: <20221012130829.2392-1-jamrial@gmail.com>

librav1e provides a function to create extradata, so use it instead of
extracting the sequence header OBU from packets.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 configure             |  1 -
 libavcodec/librav1e.c | 66 +++++++++++--------------------------------
 2 files changed, 17 insertions(+), 50 deletions(-)

diff --git a/configure b/configure
index ab6ff27249..84641fd03e 100755
--- a/configure
+++ b/configure
@@ -3378,7 +3378,6 @@ libopus_decoder_deps="libopus"
 libopus_encoder_deps="libopus"
 libopus_encoder_select="audio_frame_queue"
 librav1e_encoder_deps="librav1e"
-librav1e_encoder_select="extract_extradata_bsf"
 librsvg_decoder_deps="librsvg"
 libshine_encoder_deps="libshine"
 libshine_encoder_select="audio_frame_queue mpegaudioheader"
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index a13d6c9eaf..604115476c 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -30,7 +30,6 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avcodec.h"
-#include "bsf.h"
 #include "codec_internal.h"
 #include "encode.h"
 #include "internal.h"
@@ -41,7 +40,6 @@ typedef struct librav1eContext {
     RaContext *ctx;
     AVFrame *frame;
     RaFrame *rframe;
-    AVBSFContext *bsf;
 
     uint8_t *pass_data;
     size_t pass_pos;
@@ -176,7 +174,6 @@ static av_cold int librav1e_encode_close(AVCodecContext *avctx)
     }
 
     av_frame_free(&ctx->frame);
-    av_bsf_free(&ctx->bsf);
     av_freep(&ctx->pass_data);
 
     return 0;
@@ -245,36 +242,6 @@ static av_cold int librav1e_encode_init(AVCodecContext *avctx)
         }
     }
 
-    if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
-         const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
-         int bret;
-
-         if (!filter) {
-            av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream filter "
-                   "not found. This is a bug, please report it.\n");
-            ret = AVERROR_BUG;
-            goto end;
-         }
-
-         bret = av_bsf_alloc(filter, &ctx->bsf);
-         if (bret < 0) {
-             ret = bret;
-             goto end;
-         }
-
-         bret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
-         if (bret < 0) {
-             ret = bret;
-             goto end;
-         }
-
-         bret = av_bsf_init(ctx->bsf);
-         if (bret < 0) {
-             ret = bret;
-             goto end;
-         }
-    }
-
     {
         AVDictionaryEntry *en = NULL;
         while ((en = av_dict_get(ctx->rav1e_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
@@ -427,6 +394,23 @@ static av_cold int librav1e_encode_init(AVCodecContext *avctx)
         goto end;
     }
 
+    if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
+        RaData *seq_hdr = rav1e_container_sequence_header(ctx->ctx);
+
+        if (seq_hdr)
+            avctx->extradata = av_mallocz(seq_hdr->len + AV_INPUT_BUFFER_PADDING_SIZE);
+        if (!seq_hdr || !avctx->extradata) {
+            rav1e_data_unref(seq_hdr);
+            av_log(avctx, AV_LOG_ERROR, "Failed to get extradata.\n");
+            ret = seq_hdr ? AVERROR(ENOMEM) : AVERROR_EXTERNAL;
+            goto end;
+        }
+
+        memcpy(avctx->extradata, seq_hdr->data, seq_hdr->len);
+        avctx->extradata_size = seq_hdr->len;
+        rav1e_data_unref(seq_hdr);
+    }
+
     ret = 0;
 
 end:
@@ -556,22 +540,6 @@ retry:
     av_free(rpkt->opaque);
     rav1e_packet_unref(rpkt);
 
-    if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
-        int ret = av_bsf_send_packet(ctx->bsf, pkt);
-        if (ret < 0) {
-            av_log(avctx, AV_LOG_ERROR, "extradata extraction send failed.\n");
-            av_packet_unref(pkt);
-            return ret;
-        }
-
-        ret = av_bsf_receive_packet(ctx->bsf, pkt);
-        if (ret < 0) {
-            av_log(avctx, AV_LOG_ERROR, "extradata extraction receive failed.\n");
-            av_packet_unref(pkt);
-            return ret;
-        }
-    }
-
     return 0;
 }
 
-- 
2.37.3

_______________________________________________
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".

  reply	other threads:[~2022-10-12 13:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 13:08 [FFmpeg-devel] [PATCH 1/4 v2] avcodec/librav1e: support setting sample aspect ratio James Almer
2022-10-12 13:08 ` James Almer [this message]
2022-10-12 13:08 ` [FFmpeg-devel] [PATCH 3/4] avcodec/librav1e: support AV_CODEC_CAP_ENCODER_RECON_FRAME James Almer
2022-10-12 13:08 ` [FFmpeg-devel] [PATCH 4/4] avcodec/librav1e: use lavu image helpers where adequate James Almer
2022-10-18 22:38 ` [FFmpeg-devel] [PATCH 1/4 v2] avcodec/librav1e: support setting sample aspect ratio James Almer

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=20221012130829.2392-2-jamrial@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