]> git.sesse.net Git - ffmpeg/commitdiff
avformat: only allow a single bitstream filter when muxing
authorMarton Balint <cus@passwd.hu>
Sat, 18 Apr 2020 08:49:54 +0000 (10:49 +0200)
committerMarton Balint <cus@passwd.hu>
Sun, 26 Apr 2020 20:39:01 +0000 (22:39 +0200)
Current muxers only use a single bitstream filter, so there is no need to
maintain code which operates on a list of bitstream filters. When multiple
bitstream filters are needed muxers can simply use a list bitstream filter.

If there is a use case in the future when different bitstream filters should be
added at subsequent packets then a new API possibly involving reconfiguring the
list bitstream filter can be added knowing the exact requirements.

Signed-off-by: Marton Balint <cus@passwd.hu>
libavformat/dashenc.c
libavformat/internal.h
libavformat/mux.c
libavformat/segment.c
libavformat/utils.c

index b08253618d11adaf05cf4958a4db02be2a937a7f..9f837857925cac23867f5b62da6564408c4d6e65 100644 (file)
@@ -2325,10 +2325,8 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt
         if (ret == 1) {
             AVStream *st = s->streams[avpkt->stream_index];
             AVStream *ost = oc->streams[0];
-            st->internal->bsfcs = ost->internal->bsfcs;
-            st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
-            ost->internal->bsfcs = NULL;
-            ost->internal->nb_bsfcs = 0;
+            st->internal->bsfc = ost->internal->bsfc;
+            ost->internal->bsfc = NULL;
         }
         return ret;
     }
index 329b2e972d65cbeebe372c0d10a773f358c53833..6786b732aca9bf6a2026500a3c8860c92046cd69 100644 (file)
@@ -152,12 +152,11 @@ struct AVStreamInternal {
     int reorder;
 
     /**
-     * bitstream filters to run on stream
+     * bitstream filter to run on stream
      * - encoding: Set by muxer using ff_stream_add_bitstream_filter
      * - decoding: unused
      */
-    AVBSFContext **bsfcs;
-    int nb_bsfcs;
+    AVBSFContext *bsfc;
 
     /**
      * Whether or not check_bitstream should still be run on each packet
index c348b8fdc81e5f530d5103944a35094a4a9eb7cc..3d1f71ab1add237451e04942ad778a6ed9c70713 100644 (file)
@@ -811,7 +811,7 @@ static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt)
 
 static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
     AVStream *st = s->streams[pkt->stream_index];
-    int i, ret;
+    int ret;
 
     if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
         return 1;
@@ -825,8 +825,8 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
         }
     }
 
-    for (i = 0; i < st->internal->nb_bsfcs; i++) {
-        AVBSFContext *ctx = st->internal->bsfcs[i];
+    if (st->internal->bsfc) {
+        AVBSFContext *ctx = st->internal->bsfc;
         // TODO: when any bitstream filter requires flushing at EOF, we'll need to
         // flush each stream's BSF chain on write_trailer.
         if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
index 60b72b7d15edb2afb69d03eac615b7cbcb1ad54f..32c09827eb61ca820bb4347954efc8c8f31c8cde 100644 (file)
@@ -1034,10 +1034,8 @@ static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
         if (ret == 1) {
             AVStream *st = s->streams[pkt->stream_index];
             AVStream *ost = oc->streams[pkt->stream_index];
-            st->internal->bsfcs = ost->internal->bsfcs;
-            st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
-            ost->internal->bsfcs = NULL;
-            ost->internal->nb_bsfcs = 0;
+            st->internal->bsfc = ost->internal->bsfc;
+            ost->internal->bsfc = NULL;
         }
         return ret;
     }
index a36d6738cd712a93af62ab9b264546adfc07b480..3b53f97bee6b9a6f9c5dfdd6aab60b4de10d0b62 100644 (file)
@@ -4408,10 +4408,7 @@ static void free_stream(AVStream **pst)
 
     if (st->internal) {
         avcodec_free_context(&st->internal->avctx);
-        for (i = 0; i < st->internal->nb_bsfcs; i++) {
-            av_bsf_free(&st->internal->bsfcs[i]);
-            av_freep(&st->internal->bsfcs);
-        }
+        av_bsf_free(&st->internal->bsfc);
         av_freep(&st->internal->priv_pts);
         av_bsf_free(&st->internal->extract_extradata.bsf);
         av_packet_free(&st->internal->extract_extradata.pkt);
@@ -5572,7 +5569,8 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a
     int ret;
     const AVBitStreamFilter *bsf;
     AVBSFContext *bsfc;
-    AVCodecParameters *in_par;
+
+    av_assert0(!st->internal->bsfc);
 
     if (!(bsf = av_bsf_get_by_name(name))) {
         av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
@@ -5582,15 +5580,8 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a
     if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
         return ret;
 
-    if (st->internal->nb_bsfcs) {
-        in_par = st->internal->bsfcs[st->internal->nb_bsfcs - 1]->par_out;
-        bsfc->time_base_in = st->internal->bsfcs[st->internal->nb_bsfcs - 1]->time_base_out;
-    } else {
-        in_par = st->codecpar;
-        bsfc->time_base_in = st->time_base;
-    }
-
-    if ((ret = avcodec_parameters_copy(bsfc->par_in, in_par)) < 0) {
+    bsfc->time_base_in = st->time_base;
+    if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
         av_bsf_free(&bsfc);
         return ret;
     }
@@ -5613,10 +5604,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a
         return ret;
     }
 
-    if ((ret = av_dynarray_add_nofree(&st->internal->bsfcs, &st->internal->nb_bsfcs, bsfc))) {
-        av_bsf_free(&bsfc);
-        return ret;
-    }
+    st->internal->bsfc = bsfc;
 
     av_log(NULL, AV_LOG_VERBOSE,
            "Automatically inserted bitstream filter '%s'; args='%s'\n",