[FFmpeg-devel] [PATCH 2/4] avcodec/librav1e: export extradata on init()

James Almer jamrial at gmail.com
Wed Oct 12 16:08:27 EEST 2022


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 at 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



More information about the ffmpeg-devel mailing list