Commit a094e7f1 authored by James Almer's avatar James Almer

avcodec/aac_adtstoasc: move the reference in the bsf internal buffer

There's no need to allocate a new packet for it.
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 0f3d1c69
...@@ -36,27 +36,26 @@ typedef struct AACBSFContext { ...@@ -36,27 +36,26 @@ typedef struct AACBSFContext {
* This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4 * This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
* ADTS header and removes the ADTS header. * ADTS header and removes the ADTS header.
*/ */
static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt)
{ {
AACBSFContext *ctx = bsfc->priv_data; AACBSFContext *ctx = bsfc->priv_data;
GetBitContext gb; GetBitContext gb;
PutBitContext pb; PutBitContext pb;
AACADTSHeaderInfo hdr; AACADTSHeaderInfo hdr;
AVPacket *in;
int ret; int ret;
ret = ff_bsf_get_packet(bsfc, &in); ret = ff_bsf_get_packet_ref(bsfc, pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (bsfc->par_in->extradata && in->size >= 2 && (AV_RB16(in->data) >> 4) != 0xfff) if (bsfc->par_in->extradata && pkt->size >= 2 && (AV_RB16(pkt->data) >> 4) != 0xfff)
goto finish; return 0;
if (in->size < AV_AAC_ADTS_HEADER_SIZE) if (pkt->size < AV_AAC_ADTS_HEADER_SIZE)
goto packet_too_small; goto packet_too_small;
init_get_bits(&gb, in->data, AV_AAC_ADTS_HEADER_SIZE * 8); init_get_bits(&gb, pkt->data, AV_AAC_ADTS_HEADER_SIZE * 8);
if (ff_adts_header_parse(&gb, &hdr) < 0) { if (ff_adts_header_parse(&gb, &hdr) < 0) {
av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
...@@ -71,10 +70,10 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) ...@@ -71,10 +70,10 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
goto fail; goto fail;
} }
in->size -= AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent; pkt->size -= AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
if (in->size <= 0) if (pkt->size <= 0)
goto packet_too_small; goto packet_too_small;
in->data += AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent; pkt->data += AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
if (!ctx->first_frame_done) { if (!ctx->first_frame_done) {
int pce_size = 0; int pce_size = 0;
...@@ -82,7 +81,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) ...@@ -82,7 +81,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
uint8_t *extradata; uint8_t *extradata;
if (!hdr.chan_config) { if (!hdr.chan_config) {
init_get_bits(&gb, in->data, in->size * 8); init_get_bits(&gb, pkt->data, pkt->size * 8);
if (get_bits(&gb, 3) != 5) { if (get_bits(&gb, 3) != 5) {
avpriv_report_missing_feature(bsfc, avpriv_report_missing_feature(bsfc,
"PCE-based channel configuration " "PCE-based channel configuration "
...@@ -94,11 +93,11 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) ...@@ -94,11 +93,11 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
init_put_bits(&pb, pce_data, MAX_PCE_SIZE); init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
pce_size = ff_copy_pce_data(&pb, &gb) / 8; pce_size = ff_copy_pce_data(&pb, &gb) / 8;
flush_put_bits(&pb); flush_put_bits(&pb);
in->size -= get_bits_count(&gb)/8; pkt->size -= get_bits_count(&gb)/8;
in->data += get_bits_count(&gb)/8; pkt->data += get_bits_count(&gb)/8;
} }
extradata = av_packet_new_side_data(in, AV_PKT_DATA_NEW_EXTRADATA, extradata = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
2 + pce_size); 2 + pce_size);
if (!extradata) { if (!extradata) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
...@@ -120,17 +119,13 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) ...@@ -120,17 +119,13 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
ctx->first_frame_done = 1; ctx->first_frame_done = 1;
} }
finish:
av_packet_move_ref(out, in);
av_packet_free(&in);
return 0; return 0;
packet_too_small: packet_too_small:
av_log(bsfc, AV_LOG_ERROR, "Input packet too small\n"); av_log(bsfc, AV_LOG_ERROR, "Input packet too small\n");
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
fail: fail:
av_packet_free(&in); av_packet_unref(pkt);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment