diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavcodec/alac.c | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavcodec/alac.c')
| -rw-r--r-- | ffmpeg/libavcodec/alac.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/ffmpeg/libavcodec/alac.c b/ffmpeg/libavcodec/alac.c index 0018b9a..3f37f61 100644 --- a/ffmpeg/libavcodec/alac.c +++ b/ffmpeg/libavcodec/alac.c @@ -50,6 +50,7 @@ #include "get_bits.h" #include "bytestream.h" #include "internal.h" +#include "thread.h" #include "unary.h" #include "mathops.h" #include "alac_data.h" @@ -287,9 +288,10 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, return AVERROR_INVALIDDATA; } if (!alac->nb_samples) { + ThreadFrame tframe = { .f = frame }; /* get output buffer */ frame->nb_samples = output_samples; - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0) return ret; } else if (output_samples != alac->nb_samples) { av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %u != %d\n", @@ -318,6 +320,9 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index, rice_history_mult[ch] = get_bits(&alac->gb, 3); lpc_order[ch] = get_bits(&alac->gb, 5); + if (lpc_order[ch] >= alac->max_samples_per_frame) + return AVERROR_INVALIDDATA; + /* read the predictor table */ for (i = lpc_order[ch] - 1; i >= 0; i--) lpc_coefs[ch][i] = get_sbits(&alac->gb, 16); @@ -443,7 +448,8 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, int channels; int ch, ret, got_end; - init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8); + if ((ret = init_get_bits8(&alac->gb, avpkt->data, avpkt->size)) < 0) + return ret; got_end = 0; alac->nb_samples = 0; @@ -460,9 +466,8 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, } channels = (element == TYPE_CPE) ? 2 : 1; - if ( ch + channels > alac->channels - || ff_alac_channel_layout_offsets[alac->channels - 1][ch] + channels > alac->channels - ) { + if (ch + channels > alac->channels || + ff_alac_channel_layout_offsets[alac->channels - 1][ch] + channels > alac->channels) { av_log(avctx, AV_LOG_ERROR, "invalid element channel count\n"); return AVERROR_INVALIDDATA; } @@ -508,11 +513,7 @@ static av_cold int alac_decode_close(AVCodecContext *avctx) static int allocate_buffers(ALACContext *alac) { int ch; - int buf_size; - - if (alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) - goto buf_alloc_fail; - buf_size = alac->max_samples_per_frame * sizeof(int32_t); + int buf_size = alac->max_samples_per_frame * sizeof(int32_t); for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) { FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch], @@ -543,7 +544,8 @@ static int alac_set_info(ALACContext *alac) bytestream2_skipu(&gb, 12); // size:4, alac:4, version:4 alac->max_samples_per_frame = bytestream2_get_be32u(&gb); - if (!alac->max_samples_per_frame || alac->max_samples_per_frame > INT_MAX) { + if (!alac->max_samples_per_frame || + alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) { av_log(alac->avctx, AV_LOG_ERROR, "max samples per frame invalid: %u\n", alac->max_samples_per_frame); return AVERROR_INVALIDDATA; @@ -615,14 +617,22 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) return 0; } +static int init_thread_copy(AVCodecContext *avctx) +{ + ALACContext *alac = avctx->priv_data; + alac->avctx = avctx; + return allocate_buffers(alac); +} + AVCodec ff_alac_decoder = { .name = "alac", + .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_ALAC, .priv_data_size = sizeof(ALACContext), .init = alac_decode_init, .close = alac_decode_close, .decode = alac_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), + .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy), + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, }; |
