[FFmpeg-devel] [PATCH 3/3] avcodec/audiotoolboxdec: switch to the new generic filtering mechanism
James Almer
jamrial at gmail.com
Thu May 25 19:31:05 EEST 2017
Signed-off-by: James Almer <jamrial at gmail.com>
---
Again, untested.
libavcodec/audiotoolboxdec.c | 73 ++++++++++++--------------------------------
1 file changed, 20 insertions(+), 53 deletions(-)
diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
index c30817778f..97514368bf 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -43,7 +43,6 @@ typedef struct ATDecodeContext {
AudioStreamPacketDescription pkt_desc;
AVPacket in_pkt;
AVPacket new_in_pkt;
- AVBSFContext *bsf;
char *decoded_data;
int channel_map[64];
@@ -478,42 +477,15 @@ static int ffat_decode(AVCodecContext *avctx, void *data,
ATDecodeContext *at = avctx->priv_data;
AVFrame *frame = data;
int pkt_size = avpkt->size;
- AVPacket filtered_packet = {0};
OSStatus ret;
AudioBufferList out_buffers;
- if (avctx->codec_id == AV_CODEC_ID_AAC && avpkt->size > 2 &&
- (AV_RB16(avpkt->data) & 0xfff0) == 0xfff0) {
- AVPacket filter_pkt = {0};
- if (!at->bsf) {
- const AVBitStreamFilter *bsf = av_bsf_get_by_name("aac_adtstoasc");
- if(!bsf)
- return AVERROR_BSF_NOT_FOUND;
- if ((ret = av_bsf_alloc(bsf, &at->bsf)))
- return ret;
- if (((ret = avcodec_parameters_from_context(at->bsf->par_in, avctx)) < 0) ||
- ((ret = av_bsf_init(at->bsf)) < 0)) {
- av_bsf_free(&at->bsf);
- return ret;
- }
- }
-
- if ((ret = av_packet_ref(&filter_pkt, avpkt)) < 0)
- return ret;
-
- if ((ret = av_bsf_send_packet(at->bsf, &filter_pkt)) < 0) {
- av_packet_unref(&filter_pkt);
- return ret;
- }
-
- if ((ret = av_bsf_receive_packet(at->bsf, &filtered_packet)) < 0)
- return ret;
-
+ if (avctx->codec_id == AV_CODEC_ID_AAC) {
if (!at->extradata_size) {
uint8_t *side_data;
int side_data_size = 0;
- side_data = av_packet_get_side_data(&filtered_packet, AV_PKT_DATA_NEW_EXTRADATA,
+ side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
&side_data_size);
if (side_data_size) {
at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
@@ -523,13 +495,10 @@ static int ffat_decode(AVCodecContext *avctx, void *data,
memcpy(at->extradata, side_data, side_data_size);
}
}
-
- avpkt = &filtered_packet;
}
if (!at->converter) {
if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
- av_packet_unref(&filtered_packet);
return ret;
}
}
@@ -548,9 +517,7 @@ static int ffat_decode(AVCodecContext *avctx, void *data,
av_packet_unref(&at->new_in_pkt);
if (avpkt->size) {
- if (filtered_packet.data) {
- at->new_in_pkt = filtered_packet;
- } else if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
+ if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
return ret;
}
} else {
@@ -601,7 +568,6 @@ static av_cold int ffat_close_decoder(AVCodecContext *avctx)
ATDecodeContext *at = avctx->priv_data;
if (at->converter)
AudioConverterDispose(at->converter);
- av_bsf_free(&at->bsf);
av_packet_unref(&at->new_in_pkt);
av_packet_unref(&at->in_pkt);
av_free(at->decoded_data);
@@ -615,7 +581,7 @@ static av_cold int ffat_close_decoder(AVCodecContext *avctx)
.version = LIBAVUTIL_VERSION_INT, \
};
-#define FFAT_DEC(NAME, ID) \
+#define FFAT_DEC(NAME, ID, bsf_name) \
FFAT_DEC_CLASS(NAME) \
AVCodec ff_##NAME##_at_decoder = { \
.name = #NAME "_at", \
@@ -628,22 +594,23 @@ static av_cold int ffat_close_decoder(AVCodecContext *avctx)
.decode = ffat_decode, \
.flush = ffat_decode_flush, \
.priv_class = &ffat_##NAME##_dec_class, \
+ .bsfs = bsf_name, \
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, \
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
};
-FFAT_DEC(aac, AV_CODEC_ID_AAC)
-FFAT_DEC(ac3, AV_CODEC_ID_AC3)
-FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT)
-FFAT_DEC(alac, AV_CODEC_ID_ALAC)
-FFAT_DEC(amr_nb, AV_CODEC_ID_AMR_NB)
-FFAT_DEC(eac3, AV_CODEC_ID_EAC3)
-FFAT_DEC(gsm_ms, AV_CODEC_ID_GSM_MS)
-FFAT_DEC(ilbc, AV_CODEC_ID_ILBC)
-FFAT_DEC(mp1, AV_CODEC_ID_MP1)
-FFAT_DEC(mp2, AV_CODEC_ID_MP2)
-FFAT_DEC(mp3, AV_CODEC_ID_MP3)
-FFAT_DEC(pcm_alaw, AV_CODEC_ID_PCM_ALAW)
-FFAT_DEC(pcm_mulaw, AV_CODEC_ID_PCM_MULAW)
-FFAT_DEC(qdmc, AV_CODEC_ID_QDMC)
-FFAT_DEC(qdm2, AV_CODEC_ID_QDM2)
+FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
+FFAT_DEC(ac3, AV_CODEC_ID_AC3, NULL)
+FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT, NULL)
+FFAT_DEC(alac, AV_CODEC_ID_ALAC, NULL)
+FFAT_DEC(amr_nb, AV_CODEC_ID_AMR_NB, NULL)
+FFAT_DEC(eac3, AV_CODEC_ID_EAC3, NULL)
+FFAT_DEC(gsm_ms, AV_CODEC_ID_GSM_MS, NULL)
+FFAT_DEC(ilbc, AV_CODEC_ID_ILBC, NULL)
+FFAT_DEC(mp1, AV_CODEC_ID_MP1, NULL)
+FFAT_DEC(mp2, AV_CODEC_ID_MP2, NULL)
+FFAT_DEC(mp3, AV_CODEC_ID_MP3, NULL)
+FFAT_DEC(pcm_alaw, AV_CODEC_ID_PCM_ALAW, NULL)
+FFAT_DEC(pcm_mulaw, AV_CODEC_ID_PCM_MULAW, NULL)
+FFAT_DEC(qdmc, AV_CODEC_ID_QDMC, NULL)
+FFAT_DEC(qdm2, AV_CODEC_ID_QDM2, NULL)
--
2.12.1
More information about the ffmpeg-devel
mailing list