summaryrefslogtreecommitdiff
path: root/libavcodec/tta.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2013-06-03 15:49:25 +0000
committerPaul B Mahol <onemda@gmail.com>2013-06-05 22:35:32 +0000
commit495db0e3b097924d38e297132cb15c9efe1b3e43 (patch)
tree8d59a8e4587f2487ecde06ba65a49ff7d1316920 /libavcodec/tta.c
parent9300de0409d52272387a9b9d84143dba212291f4 (diff)
downloadffmpeg-495db0e3b097924d38e297132cb15c9efe1b3e43.tar.gz
ttadec: frame multi-threading support
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavcodec/tta.c')
-rw-r--r--libavcodec/tta.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 8b90d7f918..ae16f49509 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -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,
};