FFmpeg  2.1.1
tta.c
Go to the documentation of this file.
1 /*
2  * TTA (The Lossless True Audio) decoder
3  * Copyright (c) 2006 Alex Beregszaszi
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * TTA (The Lossless True Audio) decoder
25  * @see http://www.true-audio.com/
26  * @see http://tta.corecodec.org/
27  * @author Alex Beregszaszi
28  */
29 
30 #define BITSTREAM_READER_LE
31 #include <limits.h>
32 #include "ttadata.h"
33 #include "avcodec.h"
34 #include "get_bits.h"
35 #include "thread.h"
36 #include "unary.h"
37 #include "internal.h"
38 #include "libavutil/crc.h"
39 #include "libavutil/intreadwrite.h"
40 #include "libavutil/opt.h"
41 
42 #define FORMAT_SIMPLE 1
43 #define FORMAT_ENCRYPTED 2
44 
45 typedef struct TTAContext {
46  AVClass *class;
48  const AVCRC *crc_table;
49 
51  unsigned data_length;
53 
55 
59 } TTAContext;
60 
61 static inline void ttafilter_process(TTAFilter *c, int32_t *in)
62 {
63  register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
64 
65  if (c->error < 0) {
66  qm[0] -= dx[0]; qm[1] -= dx[1]; qm[2] -= dx[2]; qm[3] -= dx[3];
67  qm[4] -= dx[4]; qm[5] -= dx[5]; qm[6] -= dx[6]; qm[7] -= dx[7];
68  } else if (c->error > 0) {
69  qm[0] += dx[0]; qm[1] += dx[1]; qm[2] += dx[2]; qm[3] += dx[3];
70  qm[4] += dx[4]; qm[5] += dx[5]; qm[6] += dx[6]; qm[7] += dx[7];
71  }
72 
73  sum += dl[0] * qm[0] + dl[1] * qm[1] + dl[2] * qm[2] + dl[3] * qm[3] +
74  dl[4] * qm[4] + dl[5] * qm[5] + dl[6] * qm[6] + dl[7] * qm[7];
75 
76  dx[0] = dx[1]; dx[1] = dx[2]; dx[2] = dx[3]; dx[3] = dx[4];
77  dl[0] = dl[1]; dl[1] = dl[2]; dl[2] = dl[3]; dl[3] = dl[4];
78 
79  dx[4] = ((dl[4] >> 30) | 1);
80  dx[5] = ((dl[5] >> 30) | 2) & ~1;
81  dx[6] = ((dl[6] >> 30) | 2) & ~1;
82  dx[7] = ((dl[7] >> 30) | 4) & ~3;
83 
84  c->error = *in;
85  *in += (sum >> c->shift);
86 
87  dl[4] = -dl[5]; dl[5] = -dl[6];
88  dl[6] = *in - dl[7]; dl[7] = *in;
89  dl[5] += dl[6]; dl[4] += dl[5];
90 }
91 
92 static const int64_t tta_channel_layouts[7] = {
96  0,
98  AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER,
100 };
101 
102 static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
103 {
104  uint32_t crc, CRC;
105 
106  CRC = AV_RL32(buf + buf_size);
107  crc = av_crc(s->crc_table, 0xFFFFFFFFU, buf, buf_size);
108  if (CRC != (crc ^ 0xFFFFFFFFU)) {
109  av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
110  return AVERROR_INVALIDDATA;
111  }
112 
113  return 0;
114 }
115 
116 static uint64_t tta_check_crc64(uint8_t *pass)
117 {
118  uint64_t crc = UINT64_MAX, poly = 0x42F0E1EBA9EA3693U;
119  uint8_t *end = pass + strlen(pass);
120  int i;
121 
122  while (pass < end) {
123  crc ^= (uint64_t)*pass++ << 56;
124  for (i = 0; i < 8; i++)
125  crc = (crc << 1) ^ (poly & (((int64_t) crc) >> 63));
126  }
127 
128  return crc ^ UINT64_MAX;
129 }
130 
132 {
133  TTAContext *s = avctx->priv_data;
134 
135  if (s->bps < 3) {
137  if (!s->decode_buffer)
138  return AVERROR(ENOMEM);
139  } else
140  s->decode_buffer = NULL;
141  s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx));
142  if (!s->ch_ctx) {
143  av_freep(&s->decode_buffer);
144  return AVERROR(ENOMEM);
145  }
146 
147  return 0;
148 }
149 
151 {
152  TTAContext *s = avctx->priv_data;
153  GetBitContext gb;
154  int total_frames;
155 
156  s->avctx = avctx;
157 
158  // 30bytes includes TTA1 header
159  if (avctx->extradata_size < 22)
160  return AVERROR_INVALIDDATA;
161 
163  init_get_bits8(&gb, avctx->extradata, avctx->extradata_size);
164  if (show_bits_long(&gb, 32) == AV_RL32("TTA1")) {
165  /* signature */
166  skip_bits_long(&gb, 32);
167 
168  s->format = get_bits(&gb, 16);
169  if (s->format > 2) {
170  av_log(avctx, AV_LOG_ERROR, "Invalid format\n");
171  return AVERROR_INVALIDDATA;
172  }
173  if (s->format == FORMAT_ENCRYPTED) {
174  if (!s->pass) {
175  av_log(avctx, AV_LOG_ERROR, "Missing password for encrypted stream. Please use the -password option\n");
176  return AVERROR(EINVAL);
177  }
179  }
180  avctx->channels = s->channels = get_bits(&gb, 16);
181  if (s->channels > 1 && s->channels < 9)
183  avctx->bits_per_raw_sample = get_bits(&gb, 16);
184  s->bps = (avctx->bits_per_raw_sample + 7) / 8;
185  avctx->sample_rate = get_bits_long(&gb, 32);
186  s->data_length = get_bits_long(&gb, 32);
187  skip_bits_long(&gb, 32); // CRC32 of header
188 
189  if (s->channels == 0) {
190  av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
191  return AVERROR_INVALIDDATA;
192  } else if (avctx->sample_rate == 0) {
193  av_log(avctx, AV_LOG_ERROR, "Invalid samplerate\n");
194  return AVERROR_INVALIDDATA;
195  }
196 
197  switch(s->bps) {
198  case 1: avctx->sample_fmt = AV_SAMPLE_FMT_U8; break;
199  case 2:
200  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
201  break;
202  case 3:
203  avctx->sample_fmt = AV_SAMPLE_FMT_S32;
204  break;
205  //case 4: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break;
206  default:
207  av_log(avctx, AV_LOG_ERROR, "Invalid/unsupported sample format.\n");
208  return AVERROR_INVALIDDATA;
209  }
210 
211  // prevent overflow
212  if (avctx->sample_rate > 0x7FFFFFu) {
213  av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
214  return AVERROR(EINVAL);
215  }
216  s->frame_length = 256 * avctx->sample_rate / 245;
217 
219  total_frames = s->data_length / s->frame_length +
220  (s->last_frame_length ? 1 : 0);
221 
222  av_log(avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n",
223  s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
224  avctx->block_align);
225  av_log(avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
226  s->data_length, s->frame_length, s->last_frame_length, total_frames);
227 
228  if(s->frame_length >= UINT_MAX / (s->channels * sizeof(int32_t))){
229  av_log(avctx, AV_LOG_ERROR, "frame_length too large\n");
230  return AVERROR_INVALIDDATA;
231  }
232  } else {
233  av_log(avctx, AV_LOG_ERROR, "Wrong extradata present\n");
234  return AVERROR_INVALIDDATA;
235  }
236 
237  return allocate_buffers(avctx);
238 }
239 
240 static int tta_decode_frame(AVCodecContext *avctx, void *data,
241  int *got_frame_ptr, AVPacket *avpkt)
242 {
243  AVFrame *frame = data;
244  ThreadFrame tframe = { .f = data };
245  const uint8_t *buf = avpkt->data;
246  int buf_size = avpkt->size;
247  TTAContext *s = avctx->priv_data;
248  GetBitContext gb;
249  int i, ret;
250  int cur_chan = 0, framelen = s->frame_length;
251  int32_t *p;
252 
253  if (avctx->err_recognition & AV_EF_CRCCHECK) {
254  if (buf_size < 4 || tta_check_crc(s, buf, buf_size - 4))
255  return AVERROR_INVALIDDATA;
256  }
257 
258  if ((ret = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)
259  return ret;
260 
261  /* get output buffer */
262  frame->nb_samples = framelen;
263  if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0)
264  return ret;
265 
266  // decode directly to output buffer for 24-bit sample format
267  if (s->bps == 3)
268  s->decode_buffer = (int32_t *)frame->data[0];
269 
270  // init per channel states
271  for (i = 0; i < s->channels; i++) {
272  TTAFilter *filter = &s->ch_ctx[i].filter;
273  s->ch_ctx[i].predictor = 0;
275  if (s->format == FORMAT_ENCRYPTED) {
276  int i;
277  for (i = 0; i < 8; i++)
278  filter->qm[i] = sign_extend(s->crc_pass[i], 8);
279  }
280  ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10);
281  }
282 
283  i = 0;
284  for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) {
285  int32_t *predictor = &s->ch_ctx[cur_chan].predictor;
286  TTAFilter *filter = &s->ch_ctx[cur_chan].filter;
287  TTARice *rice = &s->ch_ctx[cur_chan].rice;
288  uint32_t unary, depth, k;
289  int32_t value;
290 
291  unary = get_unary(&gb, 0, get_bits_left(&gb));
292 
293  if (unary == 0) {
294  depth = 0;
295  k = rice->k0;
296  } else {
297  depth = 1;
298  k = rice->k1;
299  unary--;
300  }
301 
302  if (get_bits_left(&gb) < k) {
303  ret = AVERROR_INVALIDDATA;
304  goto error;
305  }
306 
307  if (k) {
308  if (k > MIN_CACHE_BITS) {
309  ret = AVERROR_INVALIDDATA;
310  goto error;
311  }
312  value = (unary << k) + get_bits(&gb, k);
313  } else
314  value = unary;
315 
316  // FIXME: copy paste from original
317  switch (depth) {
318  case 1:
319  rice->sum1 += value - (rice->sum1 >> 4);
320  if (rice->k1 > 0 && rice->sum1 < ff_tta_shift_16[rice->k1])
321  rice->k1--;
322  else if(rice->sum1 > ff_tta_shift_16[rice->k1 + 1])
323  rice->k1++;
324  value += ff_tta_shift_1[rice->k0];
325  default:
326  rice->sum0 += value - (rice->sum0 >> 4);
327  if (rice->k0 > 0 && rice->sum0 < ff_tta_shift_16[rice->k0])
328  rice->k0--;
329  else if(rice->sum0 > ff_tta_shift_16[rice->k0 + 1])
330  rice->k0++;
331  }
332 
333  // extract coded value
334  *p = 1 + ((value >> 1) ^ ((value & 1) - 1));
335 
336  // run hybrid filter
337  ttafilter_process(filter, p);
338 
339  // fixed order prediction
340 #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k)
341  switch (s->bps) {
342  case 1: *p += PRED(*predictor, 4); break;
343  case 2:
344  case 3: *p += PRED(*predictor, 5); break;
345  case 4: *p += *predictor; break;
346  }
347  *predictor = *p;
348 
349  // flip channels
350  if (cur_chan < (s->channels-1))
351  cur_chan++;
352  else {
353  // decorrelate in case of multiple channels
354  if (s->channels > 1) {
355  int32_t *r = p - 1;
356  for (*p += *r / 2; r > p - s->channels; r--)
357  *r = *(r + 1) - *r;
358  }
359  cur_chan = 0;
360  i++;
361  // check for last frame
362  if (i == s->last_frame_length && get_bits_left(&gb) / 8 == 4) {
363  frame->nb_samples = framelen = s->last_frame_length;
364  break;
365  }
366  }
367  }
368 
369  align_get_bits(&gb);
370  if (get_bits_left(&gb) < 32) {
371  ret = AVERROR_INVALIDDATA;
372  goto error;
373  }
374  skip_bits_long(&gb, 32); // frame crc
375 
376  // convert to output buffer
377  switch (s->bps) {
378  case 1: {
379  uint8_t *samples = (uint8_t *)frame->data[0];
380  for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
381  *samples++ = *p + 0x80;
382  break;
383  }
384  case 2: {
385  int16_t *samples = (int16_t *)frame->data[0];
386  for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++)
387  *samples++ = *p;
388  break;
389  }
390  case 3: {
391  // shift samples for 24-bit sample format
392  int32_t *samples = (int32_t *)frame->data[0];
393  for (i = 0; i < framelen * s->channels; i++)
394  *samples++ <<= 8;
395  // reset decode buffer
396  s->decode_buffer = NULL;
397  break;
398  }
399  }
400 
401  *got_frame_ptr = 1;
402 
403  return buf_size;
404 error:
405  // reset decode buffer
406  if (s->bps == 3)
407  s->decode_buffer = NULL;
408  return ret;
409 }
410 
412 {
413  TTAContext *s = avctx->priv_data;
414  s->avctx = avctx;
415  return allocate_buffers(avctx);
416 }
417 
419  TTAContext *s = avctx->priv_data;
420 
421  if (s->bps < 3)
423  s->decode_buffer = NULL;
424  av_freep(&s->ch_ctx);
425 
426  return 0;
427 }
428 
429 #define OFFSET(x) offsetof(TTAContext, x)
430 #define DEC (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
431 static const AVOption options[] = {
432  { "password", "Set decoding password", OFFSET(pass), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, DEC },
433  { NULL },
434 };
435 
436 static const AVClass tta_decoder_class = {
437  .class_name = "TTA Decoder",
438  .item_name = av_default_item_name,
439  .option = options,
440  .version = LIBAVUTIL_VERSION_INT,
441 };
442 
444  .name = "tta",
445  .long_name = NULL_IF_CONFIG_SMALL("TTA (True Audio)"),
446  .type = AVMEDIA_TYPE_AUDIO,
447  .id = AV_CODEC_ID_TTA,
448  .priv_data_size = sizeof(TTAContext),
453  .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
454  .priv_class = &tta_decoder_class,
455 };
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:378
static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
Definition: tta.c:102
uint32_t poly
Definition: crc.c:261
const char * s
Definition: avisynth_c.h:668
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:306
AVOption.
Definition: opt.h:253
TTAChannel * ch_ctx
Definition: tta.c:58
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:255
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:411
AVFrame * f
Definition: thread.h:36
#define LIBAVUTIL_VERSION_INT
Definition: avcodec.h:820
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:212
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int tta_decode_init(AVCodecContext *avctx)
Definition: tta.c:150
static int tta_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: tta.c:240
void ff_tta_rice_init(TTARice *c, uint32_t k0, uint32_t k1)
Definition: ttadata.c:40
int size
Definition: avcodec.h:1064
int32_t predictor
Definition: ttadata.h:39
#define pass
Definition: fft.c:511
Definition: tta.c:45
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int format
Definition: tta.c:50
int bps
Definition: tta.c:50
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2570
#define AV_CH_LAYOUT_STEREO
static const int64_t tta_channel_layouts[7]
Definition: tta.c:92
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1910
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1254
unsigned 8 bits
Definition: samplefmt.h:51
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
int32_t error
Definition: ttadata.h:28
int32_t round
Definition: ttadata.h:28
static av_cold int tta_decode_close(AVCodecContext *avctx)
Definition: tta.c:418
const char * av_default_item_name(void *ctx)
Return the context name.
Definition: log.c:145
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1881
uint8_t
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
Multithreading support functions.
static uint64_t tta_check_crc64(uint8_t *pass)
Definition: tta.c:116
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
#define AV_CH_LOW_FREQUENCY
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:742
const char data[16]
Definition: mxf.c:68
signed 32 bits
Definition: samplefmt.h:53
int32_t qm[MAX_ORDER]
Definition: ttadata.h:29
bitstream reader API header.
int32_t shift
Definition: ttadata.h:28
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2563
uint8_t crc_pass[8]
Definition: tta.c:56
const OptionDef options[]
Definition: ffserver.c:4682
signed 16 bits
Definition: samplefmt.h:52
static AVFrame * frame
Definition: demuxing.c:51
static void predictor(uint8_t *src, int size)
Definition: exr.c:192
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:583
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int allocate_buffers(AVCodecContext *avctx)
Definition: tta.c:131
AVCodec ff_tta_decoder
Definition: tta.c:443
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define AV_WL64(p, darg)
Definition: intreadwrite.h:328
const char * r
Definition: vf_curves.c:103
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
#define AV_CH_LAYOUT_QUAD
Libavcodec external API header.
#define OFFSET(x)
Definition: tta.c:429
const AVCRC * crc_table
Definition: tta.c:48
int depth
Definition: v4l.c:61
uint32_t sum1
Definition: ttadata.h:35
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:190
unsigned data_length
Definition: tta.c:51
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:312
const uint32_t ff_tta_shift_1[]
Definition: ttadata.c:23
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2476
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread.c:1021
ret
Definition: avfilter.c:961
const uint32_t *const ff_tta_shift_16
Definition: ttadata.c:36
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
int32_t
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) av_pure
Calculate the CRC of a block.
Definition: crc.c:320
static void ttafilter_process(TTAFilter *c, int32_t *in)
Definition: tta.c:61
#define AV_CH_LAYOUT_5POINT1_BACK
uint32_t k1
Definition: ttadata.h:35
AVCodecContext * avctx
Definition: tta.c:47
static const AVClass tta_decoder_class
Definition: tta.c:436
int sample_rate
samples per second
Definition: avcodec.h:1873
const uint8_t ff_tta_filter_configs[]
Definition: ttadata.c:38
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:436
main external API structure.
Definition: avcodec.h:1146
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:538
int32_t dx[MAX_ORDER]
Definition: ttadata.h:30
void * buf
Definition: avisynth_c.h:594
int extradata_size
Definition: avcodec.h:1255
double value
Definition: eval.c:83
Describe the class of an AVClass context structure.
Definition: log.h:50
#define DEC
Definition: tta.c:430
uint8_t * data
Definition: avcodec.h:1063
uint8_t * pass
Definition: tta.c:57
int frame_length
Definition: tta.c:52
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:332
int last_frame_length
Definition: tta.c:52
#define MIN_CACHE_BITS
Definition: get_bits.h:123
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:123
void * priv_data
Definition: avcodec.h:1182
#define AV_CH_BACK_CENTER
#define AV_CH_LAYOUT_7POINT1_WIDE
uint32_t k0
Definition: ttadata.h:35
#define PRED(x, k)
int channels
Definition: tta.c:50
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:811
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:33
static double c[64]
int32_t * decode_buffer
Definition: tta.c:54
TTAFilter filter
Definition: ttadata.h:40
#define AVERROR_INVALIDDATA
#define AV_RL32(x)
Definition: intreadwrite.h:275
int channels
number of audio channels
Definition: avcodec.h:1874
int32_t dl[MAX_ORDER]
Definition: ttadata.h:31
#define FORMAT_ENCRYPTED
Definition: tta.c:43
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:444
#define AVERROR(e)
#define AV_EF_CRCCHECK
verify embedded CRCs
Definition: avcodec.h:2477
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
TTARice rice
Definition: ttadata.h:41
void ff_tta_filter_init(TTAFilter *c, int32_t shift)
Definition: ttadata.c:48
This structure stores compressed data.
Definition: avcodec.h:1040
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:150
uint32_t AVCRC
Definition: crc.h:34
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
for(j=16;j >0;--j)
uint32_t sum0
Definition: ttadata.h:35
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241