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>
This commit is contained in:
Marton Balint 2020-04-18 10:49:54 +02:00
parent 499f43ae90
commit 1128aa8753
5 changed files with 15 additions and 32 deletions

View 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;
}

View 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

View 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) {

View 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;
}

View 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",