From f7813a5324be39d13ab536c245d15dfc602a7849 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 29 Dec 2013 12:19:38 +0000 Subject: basic type mechanism working --- ffmpeg/libavcodec/takdec.c | 68 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'ffmpeg/libavcodec/takdec.c') diff --git a/ffmpeg/libavcodec/takdec.c b/ffmpeg/libavcodec/takdec.c index 43382f1..fcbe10a 100644 --- a/ffmpeg/libavcodec/takdec.c +++ b/ffmpeg/libavcodec/takdec.c @@ -28,6 +28,7 @@ #include "libavutil/internal.h" #include "libavutil/samplefmt.h" #include "tak.h" +#include "thread.h" #include "avcodec.h" #include "dsputil.h" #include "internal.h" @@ -170,7 +171,6 @@ static av_cold int tak_decode_init(AVCodecContext *avctx) { TAKDecContext *s = avctx->priv_data; - ff_tak_init_crc(); ff_dsputil_init(&s->dsp, avctx); s->avctx = avctx; @@ -468,27 +468,14 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded, for (i = 0; i < tmp; i++) { int v = 1 << (filter_quant - 1); - if (!(filter_order & 15)) { + if (filter_order & -16) v += s->dsp.scalarproduct_int16(&s->residues[i], s->filter, - filter_order); - } else if (filter_order & 4) { - for (j = 0; j < filter_order; j += 4) { - v += s->residues[i + j + 3] * s->filter[j + 3] + - s->residues[i + j + 2] * s->filter[j + 2] + - s->residues[i + j + 1] * s->filter[j + 1] + - s->residues[i + j ] * s->filter[j ]; - } - } else { - for (j = 0; j < filter_order; j += 8) { - v += s->residues[i + j + 7] * s->filter[j + 7] + - s->residues[i + j + 6] * s->filter[j + 6] + - s->residues[i + j + 5] * s->filter[j + 5] + - s->residues[i + j + 4] * s->filter[j + 4] + - s->residues[i + j + 3] * s->filter[j + 3] + - s->residues[i + j + 2] * s->filter[j + 2] + - s->residues[i + j + 1] * s->filter[j + 1] + - s->residues[i + j ] * s->filter[j ]; - } + filter_order & -16); + for (j = filter_order & -16; j < filter_order; j += 4) { + v += s->residues[i + j + 3] * s->filter[j + 3] + + s->residues[i + j + 2] * s->filter[j + 2] + + s->residues[i + j + 1] * s->filter[j + 1] + + s->residues[i + j ] * s->filter[j ]; } v = (av_clip(v >> filter_quant, -8192, 8191) << dshift) - *decoded; *decoded++ = v; @@ -686,6 +673,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, { TAKDecContext *s = avctx->priv_data; AVFrame *frame = data; + ThreadFrame tframe = { .f = data }; GetBitContext *gb = &s->gb; int chan, i, ret, hsize; @@ -698,11 +686,12 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, if ((ret = ff_tak_decode_frame_header(avctx, gb, &s->ti, 0)) < 0) return ret; - if (avctx->err_recognition & AV_EF_CRCCHECK) { + if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_COMPLIANT)) { hsize = get_bits_count(gb) / 8; if (ff_tak_check_crc(pkt->data, hsize)) { av_log(avctx, AV_LOG_ERROR, "CRC error\n"); - return AVERROR_INVALIDDATA; + if (avctx->err_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; } } @@ -749,8 +738,9 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, : s->ti.frame_samples; frame->nb_samples = s->nb_samples; - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0) return ret; + ff_thread_finish_setup(avctx); if (avctx->bits_per_raw_sample <= 16) { int buf_size = av_samples_get_buffer_size(NULL, avctx->channels, @@ -872,11 +862,12 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, else if (get_bits_left(gb) > 0) av_log(avctx, AV_LOG_DEBUG, "underread\n"); - if (avctx->err_recognition & AV_EF_CRCCHECK) { + if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT)) { if (ff_tak_check_crc(pkt->data + hsize, get_bits_count(gb) / 8 - hsize)) { av_log(avctx, AV_LOG_ERROR, "CRC error\n"); - return AVERROR_INVALIDDATA; + if (avctx->err_recognition & AV_EF_EXPLODE) + return AVERROR_INVALIDDATA; } } @@ -912,6 +903,25 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data, return pkt->size; } +static int init_thread_copy(AVCodecContext *avctx) +{ + TAKDecContext *s = avctx->priv_data; + s->avctx = avctx; + return 0; +} + +static int update_thread_context(AVCodecContext *dst, + const AVCodecContext *src) +{ + TAKDecContext *tsrc = src->priv_data; + TAKDecContext *tdst = dst->priv_data; + + if (dst == src) + return 0; + memcpy(&tdst->ti, &tsrc->ti, sizeof(TAKStreamInfo)); + return 0; +} + static av_cold int tak_decode_close(AVCodecContext *avctx) { TAKDecContext *s = avctx->priv_data; @@ -923,14 +933,16 @@ static av_cold int tak_decode_close(AVCodecContext *avctx) AVCodec ff_tak_decoder = { .name = "tak", + .long_name = NULL_IF_CONFIG_SMALL("TAK (Tom's lossless Audio Kompressor)"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_TAK, .priv_data_size = sizeof(TAKDecContext), .init = tak_decode_init, .close = tak_decode_close, .decode = tak_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("TAK (Tom's lossless Audio Kompressor)"), + .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy), + .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context), + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32P, -- cgit v1.2.3