Commit 495db0e3 authored by Paul B Mahol's avatar Paul B Mahol

ttadec: frame multi-threading support

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 9300de04
......@@ -32,6 +32,7 @@
#include "ttadata.h"
#include "avcodec.h"
#include "get_bits.h"
#include "thread.h"
#include "unary.h"
#include "internal.h"
#include "libavutil/crc.h"
......@@ -127,6 +128,25 @@ static uint64_t tta_check_crc64(uint8_t *pass)
return crc ^ UINT64_MAX;
}
static int allocate_buffers(AVCodecContext *avctx)
{
TTAContext *s = avctx->priv_data;
if (s->bps < 3) {
s->decode_buffer = av_mallocz(sizeof(int32_t)*s->frame_length*s->channels);
if (!s->decode_buffer)
return AVERROR(ENOMEM);
} else
s->decode_buffer = NULL;
s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx));
if (!s->ch_ctx) {
av_freep(&s->decode_buffer);
return AVERROR(ENOMEM);
}
return 0;
}
static av_cold int tta_decode_init(AVCodecContext * avctx)
{
TTAContext *s = avctx->priv_data;
......@@ -209,30 +229,19 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
av_log(avctx, AV_LOG_ERROR, "frame_length too large\n");
return AVERROR_INVALIDDATA;
}
if (s->bps < 3) {
s->decode_buffer = av_mallocz(sizeof(int32_t)*s->frame_length*s->channels);
if (!s->decode_buffer)
return AVERROR(ENOMEM);
} else
s->decode_buffer = NULL;
s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx));
if (!s->ch_ctx) {
av_freep(&s->decode_buffer);
return AVERROR(ENOMEM);
}
} else {
av_log(avctx, AV_LOG_ERROR, "Wrong extradata present\n");
return AVERROR_INVALIDDATA;
}
return 0;
return allocate_buffers(avctx);
}
static int tta_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
AVFrame *frame = data;
ThreadFrame tframe = { .f = data };
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
TTAContext *s = avctx->priv_data;
......@@ -251,7 +260,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
/* get output buffer */
frame->nb_samples = framelen;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0)
return ret;
// decode directly to output buffer for 24-bit sample format
......@@ -399,6 +408,11 @@ error:
return ret;
}
static int init_thread_copy(AVCodecContext *avctx)
{
return allocate_buffers(avctx);
}
static av_cold int tta_decode_close(AVCodecContext *avctx) {
TTAContext *s = avctx->priv_data;
......@@ -432,7 +446,8 @@ AVCodec ff_tta_decoder = {
.init = tta_decode_init,
.close = tta_decode_close,
.decode = tta_decode_frame,
.capabilities = CODEC_CAP_DR1,
.init_thread_copy = init_thread_copy,
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name = NULL_IF_CONFIG_SMALL("TTA (True Audio)"),
.priv_class = &tta_decoder_class,
};
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