Skip to content

Commit 037bdc6

Browse files
committed
Merge commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab'
* commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab': lavc: add a new bitstream filtering API Left to do: - Merge conflcts in: - libavcodec/h264_mp4toannexb_bsf.c - libavcodec/hevc_mp4toannexb_bsf.c - Convert: - dca_core - mp3_header_decompress - mpeg4_unpack_bframes - vp9_superframe
2 parents 8e26bdd + 33d1898 commit 037bdc6

21 files changed

+1385
-348
lines changed

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,6 @@ ENCODER_LIST=$(find_things encoder ENC libavcodec/allcodecs.c)
32043204
DECODER_LIST=$(find_things decoder DEC libavcodec/allcodecs.c)
32053205
HWACCEL_LIST=$(find_things hwaccel HWACCEL libavcodec/allcodecs.c)
32063206
PARSER_LIST=$(find_things parser PARSER libavcodec/allcodecs.c)
3207-
BSF_LIST=$(find_things bsf BSF libavcodec/allcodecs.c)
32083207
MUXER_LIST=$(find_things muxer _MUX libavformat/allformats.c)
32093208
DEMUXER_LIST=$(find_things demuxer DEMUX libavformat/allformats.c)
32103209
OUTDEV_LIST=$(find_things outdev OUTDEV libavdevice/alldevices.c)
@@ -3218,6 +3217,7 @@ find_things_extern(){
32183217
sed -n "s/^[^#]*extern.*$pattern *ff_\([^ ]*\)_$thing;/\1_$thing/p" "$file"
32193218
}
32203219

3220+
BSF_LIST=$(find_things_extern bsf AVBitStreamFilter libavcodec/bitstream_filters.c)
32213221
PROTOCOL_LIST=$(find_things_extern protocol URLProtocol libavformat/protocols.c)
32223222

32233223
ALL_COMPONENTS="

doc/APIchanges

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ libavutil: 2015-08-28
1515

1616
API changes, most recent first:
1717

18+
2016-xx-xx - xxxxxxx - lavc 57.15.0 - avcodec.h
19+
Add a new bitstream filtering API working with AVPackets.
20+
Deprecate the old bistream filtering API.
21+
1822
2016-xx-xx - xxxxxxx - lavfi 6.42.0 - avfilter.h
1923
Add AVFilterContext.hw_device_ctx.
2024

libavcodec/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ OBJS = allcodecs.o \
2626
avpicture.o \
2727
bitstream.o \
2828
bitstream_filter.o \
29+
bitstream_filters.o \
30+
bsf.o \
2931
codec_desc.o \
3032
d3d11va.o \
3133
dirac.o \

libavcodec/aac_adtstoasc_bsf.c

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "avcodec.h"
2323
#include "aacadtsdec.h"
24+
#include "bsf.h"
2425
#include "put_bits.h"
2526
#include "get_bits.h"
2627
#include "mpeg4audio.h"
@@ -34,68 +35,76 @@ typedef struct AACBSFContext {
3435
* This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
3536
* ADTS header and removes the ADTS header.
3637
*/
37-
static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
38-
AVCodecContext *avctx, const char *args,
39-
uint8_t **poutbuf, int *poutbuf_size,
40-
const uint8_t *buf, int buf_size,
41-
int keyframe)
38+
static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
4239
{
40+
AACBSFContext *ctx = bsfc->priv_data;
41+
4342
GetBitContext gb;
4443
PutBitContext pb;
4544
AACADTSHeaderInfo hdr;
45+
AVPacket *in;
46+
int ret;
4647

47-
AACBSFContext *ctx = bsfc->priv_data;
48+
ret = ff_bsf_get_packet(bsfc, &in);
49+
if (ret < 0)
50+
return ret;
4851

49-
init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8);
52+
if (in->size < AAC_ADTS_HEADER_SIZE)
53+
goto packet_too_small;
5054

51-
*poutbuf = (uint8_t*) buf;
52-
*poutbuf_size = buf_size;
55+
init_get_bits(&gb, in->data, AAC_ADTS_HEADER_SIZE * 8);
5356

54-
if (avctx->extradata)
55-
if (show_bits(&gb, 12) != 0xfff)
56-
return 0;
57+
if (bsfc->par_in->extradata && show_bits(&gb, 12) != 0xfff)
58+
goto finish;
5759

5860
if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
59-
av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
60-
return AVERROR_INVALIDDATA;
61+
av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
62+
ret = AVERROR_INVALIDDATA;
63+
goto fail;
6164
}
6265

6366
if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
64-
avpriv_report_missing_feature(avctx,
67+
avpriv_report_missing_feature(bsfc,
6568
"Multiple RDBs per frame with CRC");
66-
return AVERROR_PATCHWELCOME;
69+
ret = AVERROR_PATCHWELCOME;
70+
goto fail;
6771
}
6872

69-
buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
70-
buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
73+
in->size -= AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
74+
if (in->size <= 0)
75+
goto packet_too_small;
76+
in->data += AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
7177

7278
if (!ctx->first_frame_done) {
7379
int pce_size = 0;
7480
uint8_t pce_data[MAX_PCE_SIZE];
81+
uint8_t *extradata;
82+
7583
if (!hdr.chan_config) {
76-
init_get_bits(&gb, buf, buf_size * 8);
84+
init_get_bits(&gb, in->data, in->size * 8);
7785
if (get_bits(&gb, 3) != 5) {
78-
avpriv_report_missing_feature(avctx,
86+
avpriv_report_missing_feature(bsfc,
7987
"PCE-based channel configuration "
8088
"without PCE as first syntax "
8189
"element");
82-
return AVERROR_PATCHWELCOME;
90+
ret = AVERROR_PATCHWELCOME;
91+
goto fail;
8392
}
8493
init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
8594
pce_size = avpriv_copy_pce_data(&pb, &gb)/8;
8695
flush_put_bits(&pb);
87-
buf_size -= get_bits_count(&gb)/8;
88-
buf += get_bits_count(&gb)/8;
96+
in->size -= get_bits_count(&gb)/8;
97+
in->data += get_bits_count(&gb)/8;
8998
}
90-
av_free(avctx->extradata);
91-
avctx->extradata_size = 2 + pce_size;
92-
avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
93-
if (!avctx->extradata) {
94-
avctx->extradata_size = 0;
95-
return AVERROR(ENOMEM);
99+
100+
extradata = av_packet_new_side_data(in, AV_PKT_DATA_NEW_EXTRADATA,
101+
2 + pce_size);
102+
if (!extradata) {
103+
ret = AVERROR(ENOMEM);
104+
goto fail;
96105
}
97106

98-
init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
107+
init_put_bits(&pb, extradata, 2 + pce_size);
99108
put_bits(&pb, 5, hdr.object_type);
100109
put_bits(&pb, 4, hdr.sampling_index);
101110
put_bits(&pb, 4, hdr.chan_config);
@@ -104,20 +113,42 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
104113
put_bits(&pb, 1, 0); //is not extension
105114
flush_put_bits(&pb);
106115
if (pce_size) {
107-
memcpy(avctx->extradata + 2, pce_data, pce_size);
116+
memcpy(extradata + 2, pce_data, pce_size);
108117
}
109118

110119
ctx->first_frame_done = 1;
111120
}
112121

113-
*poutbuf = (uint8_t*) buf;
114-
*poutbuf_size = buf_size;
122+
finish:
123+
av_packet_move_ref(out, in);
124+
av_packet_free(&in);
115125

116126
return 0;
127+
128+
packet_too_small:
129+
av_log(bsfc, AV_LOG_ERROR, "Input packet too small\n");
130+
ret = AVERROR_INVALIDDATA;
131+
fail:
132+
av_packet_free(&in);
133+
return ret;
117134
}
118135

119-
AVBitStreamFilter ff_aac_adtstoasc_bsf = {
136+
static int aac_adtstoasc_init(AVBSFContext *ctx)
137+
{
138+
av_freep(&ctx->par_out->extradata);
139+
ctx->par_out->extradata_size = 0;
140+
141+
return 0;
142+
}
143+
144+
static const enum AVCodecID codec_ids[] = {
145+
AV_CODEC_ID_AAC, AV_CODEC_ID_NONE,
146+
};
147+
148+
const AVBitStreamFilter ff_aac_adtstoasc_bsf = {
120149
.name = "aac_adtstoasc",
121150
.priv_data_size = sizeof(AACBSFContext),
151+
.init = aac_adtstoasc_init,
122152
.filter = aac_adtstoasc_filter,
153+
.codec_ids = codec_ids,
123154
};

libavcodec/allcodecs.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
av_register_codec_parser(&ff_##x##_parser); \
5959
}
6060

61-
#define REGISTER_BSF(X, x) \
62-
{ \
63-
extern AVBitStreamFilter ff_##x##_bsf; \
64-
if (CONFIG_##X##_BSF) \
65-
av_register_bitstream_filter(&ff_##x##_bsf); \
66-
}
67-
6861
void avcodec_register_all(void)
6962
{
7063
static int initialized;
@@ -667,22 +660,4 @@ void avcodec_register_all(void)
667660
REGISTER_PARSER(VP3, vp3);
668661
REGISTER_PARSER(VP8, vp8);
669662
REGISTER_PARSER(VP9, vp9);
670-
671-
/* bitstream filters */
672-
REGISTER_BSF(AAC_ADTSTOASC, aac_adtstoasc);
673-
REGISTER_BSF(CHOMP, chomp);
674-
REGISTER_BSF(DUMP_EXTRADATA, dump_extradata);
675-
REGISTER_BSF(DCA_CORE, dca_core);
676-
REGISTER_BSF(H264_MP4TOANNEXB, h264_mp4toannexb);
677-
REGISTER_BSF(HEVC_MP4TOANNEXB, hevc_mp4toannexb);
678-
REGISTER_BSF(IMX_DUMP_HEADER, imx_dump_header);
679-
REGISTER_BSF(MJPEG2JPEG, mjpeg2jpeg);
680-
REGISTER_BSF(MJPEGA_DUMP_HEADER, mjpega_dump_header);
681-
REGISTER_BSF(MP3_HEADER_DECOMPRESS, mp3_header_decompress);
682-
REGISTER_BSF(MPEG4_UNPACK_BFRAMES, mpeg4_unpack_bframes);
683-
REGISTER_BSF(MOV2TEXTSUB, mov2textsub);
684-
REGISTER_BSF(NOISE, noise);
685-
REGISTER_BSF(REMOVE_EXTRADATA, remove_extradata);
686-
REGISTER_BSF(TEXT2MOVSUB, text2movsub);
687-
REGISTER_BSF(VP9_SUPERFRAME, vp9_superframe);
688663
}

0 commit comments

Comments
 (0)