summaryrefslogtreecommitdiffstats
path: root/libavcodec/cllc.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-08-26 12:59:38 +0200
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-08-27 19:00:47 +0200
commit237f53ce85262cd86f158d884e3f84194e574aa6 (patch)
treebc34d7f6d7fff24d6f39fc4d094efb00c4b79641 /libavcodec/cllc.c
parent5cc5d9d5f7ea2231490d11cf2a28350ebb3f06ab (diff)
downloadffmpeg-streaming-237f53ce85262cd86f158d884e3f84194e574aa6.zip
ffmpeg-streaming-237f53ce85262cd86f158d884e3f84194e574aa6.tar.gz
cllc: simplify/fix swapped data buffer allocation.
Using the malloc variant avoids pointless memcpy on size increase and simplifies handling allocation failure. Also change code to ensure that allocation, bswap and bitstream reader all use the same size, even when the packet size is odd for example. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavcodec/cllc.c')
-rw-r--r--libavcodec/cllc.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
index 7625852..9cb8dfa 100644
--- a/libavcodec/cllc.c
+++ b/libavcodec/cllc.c
@@ -272,8 +272,8 @@ static int cllc_decode_frame(AVCodecContext *avctx, void *data,
CLLCContext *ctx = avctx->priv_data;
AVFrame *pic = avctx->coded_frame;
uint8_t *src = avpkt->data;
- uint8_t *swapped_buf_new;
uint32_t info_tag, info_offset;
+ int data_size;
GetBitContext gb;
int coding_type, ret;
@@ -282,16 +282,6 @@ static int cllc_decode_frame(AVCodecContext *avctx, void *data,
pic->reference = 0;
- /* Make sure our bswap16'd buffer is big enough */
- swapped_buf_new = av_fast_realloc(ctx->swapped_buf,
- &ctx->swapped_buf_size, avpkt->size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- if (!swapped_buf_new) {
- av_log(avctx, AV_LOG_ERROR, "Could not realloc swapped buffer.\n");
- return AVERROR(ENOMEM);
- }
- ctx->swapped_buf = swapped_buf_new;
-
/* Skip the INFO header if present */
info_offset = 0;
info_tag = AV_RL32(src);
@@ -310,15 +300,21 @@ static int cllc_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_DEBUG, "Skipping INFO chunk.\n");
}
+ data_size = (avpkt->size - info_offset) & ~1;
+
+ /* Make sure our bswap16'd buffer is big enough */
+ av_fast_padded_malloc(&ctx->swapped_buf,
+ &ctx->swapped_buf_size, data_size);
+ if (!ctx->swapped_buf) {
+ av_log(avctx, AV_LOG_ERROR, "Could not allocate swapped buffer.\n");
+ return AVERROR(ENOMEM);
+ }
+
/* bswap16 the buffer since CLLC's bitreader works in 16-bit words */
ctx->dsp.bswap16_buf((uint16_t *) ctx->swapped_buf, (uint16_t *) src,
- (avpkt->size - info_offset) / 2);
-
- /* Initialize padding to 0 */
- memset(ctx->swapped_buf + avpkt->size - info_offset,
- 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ data_size / 2);
- init_get_bits(&gb, ctx->swapped_buf, (avpkt->size - info_offset) * 8);
+ init_get_bits(&gb, ctx->swapped_buf, data_size * 8);
/*
* Read in coding type. The types are as follows:
OpenPOWER on IntegriCloud