[FFmpeg-devel] [PATCH 09/19] binkaudio: eliminate packet_buffer.
Nicolas George
nicolas.george at normalesup.org
Sun Jul 29 15:57:27 CEST 2012
Instead of copying the whole packet, return the exact amount of bytes
used and rely on the caller to provide the rest of the packet.
Avoid a malloc and fix invalid timestamps warnings.
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavcodec/binkaudio.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index 591c6ab..2c9c3ad 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -63,7 +63,7 @@ typedef struct {
DECLARE_ALIGNED(16, int16_t, current)[BINK_BLOCK_MAX_SIZE / 16];
float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for float_to_int16_interleave
float *prev_ptr[MAX_CHANNELS]; ///< pointers to the overlap points in the coeffs array
- uint8_t *packet_buffer;
+ int packet_continuation;
union {
RDFTContext rdft;
DCTContext dct;
@@ -292,7 +292,6 @@ static av_cold int decode_end(AVCodecContext *avctx)
{
BinkAudioContext * s = avctx->priv_data;
av_freep(&s->bands);
- av_freep(&s->packet_buffer);
if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT)
ff_rdft_end(&s->trans.rdft);
else if (CONFIG_BINKAUDIO_DCT_DECODER)
@@ -313,10 +312,9 @@ static int decode_frame(AVCodecContext *avctx, void *data,
BinkAudioContext *s = avctx->priv_data;
int16_t *samples;
GetBitContext *gb = &s->gb;
- int ret, consumed = 0;
+ int ret, consumed;
- if (!get_bits_left(gb)) {
- uint8_t *buf;
+ /* TODO reindent */
/* handle end-of-stream */
if (!avpkt->size) {
*got_frame_ptr = 0;
@@ -326,17 +324,11 @@ static int decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
- buf = av_realloc(s->packet_buffer, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!buf)
- return AVERROR(ENOMEM);
- s->packet_buffer = buf;
- memcpy(s->packet_buffer, avpkt->data, avpkt->size);
- init_get_bits(gb, s->packet_buffer, avpkt->size * 8);
- consumed = avpkt->size;
+ init_get_bits(gb, avpkt->data, avpkt->size * 8);
/* skip reported size */
+ if (!s->packet_continuation)
skip_bits_long(gb, 32);
- }
/* get output buffer */
s->frame.nb_samples = s->block_size / avctx->channels;
@@ -352,12 +344,20 @@ static int decode_frame(AVCodecContext *avctx, void *data,
}
get_bits_align32(gb);
+ consumed = get_bits_count(gb) >> 3;
+ s->packet_continuation = consumed < avpkt->size;
*got_frame_ptr = 1;
*(AVFrame *)data = s->frame;
return consumed;
}
+static void flush(AVCodecContext *avctx)
+{
+ BinkAudioContext *s = avctx->priv_data;
+ s->packet_continuation = 0;
+}
+
AVCodec ff_binkaudio_rdft_decoder = {
.name = "binkaudio_rdft",
.type = AVMEDIA_TYPE_AUDIO,
@@ -366,6 +366,7 @@ AVCodec ff_binkaudio_rdft_decoder = {
.init = decode_init,
.close = decode_end,
.decode = decode_frame,
+ .flush = flush,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)")
};
@@ -378,6 +379,7 @@ AVCodec ff_binkaudio_dct_decoder = {
.init = decode_init,
.close = decode_end,
.decode = decode_frame,
+ .flush = flush,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)")
};
--
1.7.10.4
More information about the ffmpeg-devel
mailing list