FFmpeg: libavcodec/tta.c Source File
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
31
36
37 #define BITSTREAM_READER_LE
45
46 #define FORMAT_SIMPLE 1
47 #define FORMAT_ENCRYPTED 2
48
53
57
59
65
70 0,
74 };
75
77 {
78 uint32_t crc, CRC;
79
81 crc =
av_crc(
s->crc_table, 0xFFFFFFFFU, buf, buf_size);
82 if (CRC != (crc ^ 0xFFFFFFFFU)) {
85 }
86
87 return 0;
88 }
89
91 {
92 uint64_t crc = UINT64_MAX, poly = 0x42F0E1EBA9EA3693
U;
95
97 crc ^= (uint64_t)*
pass++ << 56;
98 for (
i = 0;
i < 8;
i++)
99 crc = (crc << 1) ^ (poly & (((int64_t) crc) >> 63));
100 }
101
102 return crc ^ UINT64_MAX;
103 }
104
106 {
108
111 sizeof(*
s->decode_buffer) *
s->channels);
112 if (!
s->decode_buffer)
114 } else
115 s->decode_buffer =
NULL;
119
120 return 0;
121 }
122
124 {
127 int total_frames;
129
131
132 // 22 bytes for a TTA1 header
135
140
142 /* signature */
144
149 }
152 av_log(avctx,
AV_LOG_ERROR,
"Missing password for encrypted stream. Please use the -password option\n");
154 }
156 }
157
159
161 if (
s->channels > 1 &&
s->channels < 9) {
163 }
167 }
168
174
175 if (
s->channels == 0 ||
s->channels > 16) {
181 }
182
185 case 2:
187 break;
188 case 3:
190 break;
191 //case 4: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break;
192 default:
195 }
196
197 // prevent overflow
201 }
203
204 s->last_frame_length =
s->data_length %
s->frame_length;
205 total_frames =
s->data_length /
s->frame_length +
206 (
s->last_frame_length ? 1 : 0);
207
212 s->data_length,
s->frame_length,
s->last_frame_length, total_frames);
213
214 if(
s->frame_length >= UINT_MAX / (
s->channels *
sizeof(
int32_t))){
217 }
218 } else {
221 }
222
224
226 }
227
229 int *got_frame_ptr,
AVPacket *avpkt)
230 {
231 const uint8_t *buf = avpkt->
data;
232 int buf_size = avpkt->
size;
236 int cur_chan = 0, framelen =
s->frame_length;
237 uint32_t *p;
238
240 if (buf_size < 4 ||
243 }
244
247
248 /* get output buffer */
249 frame->nb_samples = framelen;
252
253 // decode directly to output buffer for 24-bit sample format
256
257 // init per channel states
258 for (
i = 0;
i <
s->channels;
i++) {
260 s->ch_ctx[
i].predictor = 0;
264 for (
i = 0;
i < 8;
i++)
266 }
268 }
269
271 for (p =
s->decode_buffer; (
int32_t*)p < s->decode_buffer + (framelen *
s->channels); p++) {
274 TTARice *rice = &
s->ch_ctx[cur_chan].rice;
275 uint32_t unary, depth, k;
277
279
280 if (unary == 0) {
281 depth = 0;
283 } else {
284 depth = 1;
286 unary--;
287 }
288
292 }
293
294 if (k) {
298 }
300 } else
302
303 // FIXME: copy paste from original
304 switch (depth) {
305 case 1:
312 default:
318 }
319
320 // extract coded value
322
323 // run hybrid filter
326
327 // fixed order prediction
328 #define PRED(x, k) (int32_t)((((uint64_t)(x) << (k)) - (x)) >> (k))
331 case 2:
334 }
336
337 // flip channels
338 if (cur_chan < (
s->channels-1))
339 cur_chan++;
340 else {
341 // decorrelate in case of multiple channels
342 if (
s->channels > 1) {
344 for (*p += *
r / 2;
r > (
int32_t*)p -
s->channels;
r--)
346 }
347 cur_chan = 0;
349 // check for last frame
351 frame->nb_samples = framelen =
s->last_frame_length;
352 break;
353 }
354 }
355 }
356
361 }
363
364 // convert to output buffer
366 case 1: {
368 p =
s->decode_buffer;
369 for (
i = 0;
i < framelen *
s->channels;
i++)
371 break;
372 }
373 case 2: {
375 p =
s->decode_buffer;
376 for (
i = 0;
i < framelen *
s->channels;
i++)
378 break;
379 }
380 case 3: {
381 // shift samples for 24-bit sample format
383
384 for (
i = 0;
i < framelen *
s->channels;
i++)
386 // reset decode buffer
387 s->decode_buffer =
NULL;
388 break;
389 }
390 }
391
392 *got_frame_ptr = 1;
393
394 return buf_size;
396 // reset decode buffer
398 s->decode_buffer =
NULL;
400 }
401
404
407 s->decode_buffer =
NULL;
409
410 return 0;
411 }
412
413 #define OFFSET(x) offsetof(TTAContext, x)
414 #define DEC (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
418 };
419
425 };
426
439 };
static void error(const char *err)
static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_bits_left(GetBitContext *gb)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int sample_rate
samples per second
static uint64_t tta_check_crc64(uint8_t *pass)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
void ff_tta_filter_init(TTAFilter *c, int32_t shift)
This structure describes decoded (raw) audio or video data.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
enum AVChannelOrder order
Channel order used in this layout.
void ff_tta_rice_init(TTARice *c, uint32_t k0, uint32_t k1)
int nb_channels
Number of channels in this layout.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
static const AVClass tta_decoder_class
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames. The frames must then be freed with ff_thread_release_buffer(). Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
#define AV_CH_LAYOUT_STEREO
av_cold void ff_ttadsp_init(TTADSPContext *c)
#define AV_CH_LAYOUT_QUAD
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_CH_LOW_FREQUENCY
#define FF_CODEC_DECODE_CB(func)
static av_cold int tta_decode_init(AVCodecContext *avctx)
static const int64_t tta_channel_layouts[7]
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
int(* init)(AVBSFContext *ctx)
static int allocate_buffers(AVCodecContext *avctx)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define CODEC_LONG_NAME(str)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const char * av_default_item_name(void *ptr)
Return the context name.
const FFCodec ff_tta_decoder
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
enum AVSampleFormat sample_fmt
audio sample format
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
#define AV_CH_LAYOUT_5POINT1_BACK
static void predictor(uint8_t *src, ptrdiff_t size)
const uint32_t ff_tta_shift_1[]
static int tta_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
const uint32_t *const ff_tta_shift_16
const uint8_t ff_tta_filter_configs[]
#define av_malloc_array(a, b)
#define AV_CH_BACK_CENTER
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
#define AV_CH_LAYOUT_7POINT1_WIDE
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
void * av_calloc(size_t nmemb, size_t size)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static const uint8_t * align_get_bits(GetBitContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static av_cold int tta_decode_close(AVCodecContext *avctx)
main external API structure.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
static av_const int sign_extend(int val, unsigned bits)
Filter the word "frame" indicates either a video frame or a group of audio samples
This structure stores compressed data.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const AVOption options[]
@ AV_SAMPLE_FMT_S32
signed 32 bits
Generated on Tue Feb 28 2023 21:33:39 for FFmpeg by
doxygen
1.8.17