avformat: only allow a single bitstream filter when muxing

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>
pull/336/head
Marton Balint 5 years ago
parent 499f43ae90
commit 1128aa8753
  1. 6
      libavformat/dashenc.c
  2. 5
      libavformat/internal.h
  3. 6
      libavformat/mux.c
  4. 6
      libavformat/segment.c
  5. 24
      libavformat/utils.c

@ -2325,10 +2325,8 @@ static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt
if (ret == 1) { if (ret == 1) {
AVStream *st = s->streams[avpkt->stream_index]; AVStream *st = s->streams[avpkt->stream_index];
AVStream *ost = oc->streams[0]; AVStream *ost = oc->streams[0];
st->internal->bsfcs = ost->internal->bsfcs; st->internal->bsfc = ost->internal->bsfc;
st->internal->nb_bsfcs = ost->internal->nb_bsfcs; ost->internal->bsfc = NULL;
ost->internal->bsfcs = NULL;
ost->internal->nb_bsfcs = 0;
} }
return ret; return ret;
} }

@ -152,12 +152,11 @@ struct AVStreamInternal {
int reorder; int reorder;
/** /**
* bitstream filters to run on stream * bitstream filter to run on stream
* - encoding: Set by muxer using ff_stream_add_bitstream_filter * - encoding: Set by muxer using ff_stream_add_bitstream_filter
* - decoding: unused * - decoding: unused
*/ */
AVBSFContext **bsfcs; AVBSFContext *bsfc;
int nb_bsfcs;
/** /**
* Whether or not check_bitstream should still be run on each packet * Whether or not check_bitstream should still be run on each packet

@ -811,7 +811,7 @@ static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt)
static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) { static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
int i, ret; int ret;
if (!(s->flags & AVFMT_FLAG_AUTO_BSF)) if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
return 1; 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++) { if (st->internal->bsfc) {
AVBSFContext *ctx = st->internal->bsfcs[i]; AVBSFContext *ctx = st->internal->bsfc;
// TODO: when any bitstream filter requires flushing at EOF, we'll need to // TODO: when any bitstream filter requires flushing at EOF, we'll need to
// flush each stream's BSF chain on write_trailer. // flush each stream's BSF chain on write_trailer.
if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) { if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {

@ -1034,10 +1034,8 @@ static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
if (ret == 1) { if (ret == 1) {
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
AVStream *ost = oc->streams[pkt->stream_index]; AVStream *ost = oc->streams[pkt->stream_index];
st->internal->bsfcs = ost->internal->bsfcs; st->internal->bsfc = ost->internal->bsfc;
st->internal->nb_bsfcs = ost->internal->nb_bsfcs; ost->internal->bsfc = NULL;
ost->internal->bsfcs = NULL;
ost->internal->nb_bsfcs = 0;
} }
return ret; return ret;
} }

@ -4408,10 +4408,7 @@ static void free_stream(AVStream **pst)
if (st->internal) { if (st->internal) {
avcodec_free_context(&st->internal->avctx); avcodec_free_context(&st->internal->avctx);
for (i = 0; i < st->internal->nb_bsfcs; i++) { av_bsf_free(&st->internal->bsfc);
av_bsf_free(&st->internal->bsfcs[i]);
av_freep(&st->internal->bsfcs);
}
av_freep(&st->internal->priv_pts); av_freep(&st->internal->priv_pts);
av_bsf_free(&st->internal->extract_extradata.bsf); av_bsf_free(&st->internal->extract_extradata.bsf);
av_packet_free(&st->internal->extract_extradata.pkt); 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; int ret;
const AVBitStreamFilter *bsf; const AVBitStreamFilter *bsf;
AVBSFContext *bsfc; AVBSFContext *bsfc;
AVCodecParameters *in_par;
av_assert0(!st->internal->bsfc);
if (!(bsf = av_bsf_get_by_name(name))) { if (!(bsf = av_bsf_get_by_name(name))) {
av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", 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) if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
return ret; return ret;
if (st->internal->nb_bsfcs) { bsfc->time_base_in = st->time_base;
in_par = st->internal->bsfcs[st->internal->nb_bsfcs - 1]->par_out; if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
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) {
av_bsf_free(&bsfc); av_bsf_free(&bsfc);
return ret; return ret;
} }
@ -5613,10 +5604,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a
return ret; return ret;
} }
if ((ret = av_dynarray_add_nofree(&st->internal->bsfcs, &st->internal->nb_bsfcs, bsfc))) { st->internal->bsfc = bsfc;
av_bsf_free(&bsfc);
return ret;
}
av_log(NULL, AV_LOG_VERBOSE, av_log(NULL, AV_LOG_VERBOSE,
"Automatically inserted bitstream filter '%s'; args='%s'\n", "Automatically inserted bitstream filter '%s'; args='%s'\n",

Loading…
Cancel
Save