tak.h
Go to the documentation of this file.
1 /*
2  * TAK decoder/demuxer common code
3  * Copyright (c) 2012 Paul B Mahol
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  * TAK (Tom's lossless Audio Kompressor) decoder/demuxer common functions
25  */
26 
27 #ifndef AVCODEC_TAK_H
28 #define AVCODEC_TAK_H
29 
30 #include <stdint.h>
31 
32 #define BITSTREAM_READER_LE
33 #include "get_bits.h"
34 #include "avcodec.h"
35 
36 #define TAK_FORMAT_DATA_TYPE_BITS 3
37 #define TAK_FORMAT_SAMPLE_RATE_BITS 18
38 #define TAK_FORMAT_BPS_BITS 5
39 #define TAK_FORMAT_CHANNEL_BITS 4
40 #define TAK_FORMAT_VALID_BITS 5
41 #define TAK_FORMAT_CH_LAYOUT_BITS 6
42 #define TAK_SIZE_FRAME_DURATION_BITS 4
43 #define TAK_SIZE_SAMPLES_NUM_BITS 35
44 #define TAK_LAST_FRAME_POS_BITS 40
45 #define TAK_LAST_FRAME_SIZE_BITS 24
46 #define TAK_ENCODER_CODEC_BITS 6
47 #define TAK_ENCODER_PROFILE_BITS 4
48 #define TAK_ENCODER_VERSION_BITS 24
49 #define TAK_SAMPLE_RATE_MIN 6000
50 #define TAK_CHANNELS_MIN 1
51 #define TAK_BPS_MIN 8
52 #define TAK_FRAME_HEADER_FLAGS_BITS 3
53 #define TAK_FRAME_HEADER_SYNC_ID 0xA0FF
54 #define TAK_FRAME_HEADER_SYNC_ID_BITS 16
55 #define TAK_FRAME_HEADER_SAMPLE_COUNT_BITS 14
56 #define TAK_FRAME_HEADER_NO_BITS 21
57 #define TAK_FRAME_DURATION_QUANT_SHIFT 5
58 #define TAK_CRC24_BITS 24
59 
60 
61 #define TAK_FRAME_FLAG_IS_LAST 0x1
62 #define TAK_FRAME_FLAG_HAS_INFO 0x2
63 #define TAK_FRAME_FLAG_HAS_METADATA 0x4
64 
65 #define TAK_MAX_CHANNELS (1 << TAK_FORMAT_CHANNEL_BITS)
66 
67 #define TAK_MIN_FRAME_HEADER_BITS (TAK_FRAME_HEADER_SYNC_ID_BITS + \
68  TAK_FRAME_HEADER_FLAGS_BITS + \
69  TAK_FRAME_HEADER_NO_BITS + \
70  TAK_CRC24_BITS)
71 
72 #define TAK_MIN_FRAME_HEADER_LAST_BITS (TAK_MIN_FRAME_HEADER_BITS + 2 + \
73  TAK_FRAME_HEADER_SAMPLE_COUNT_BITS)
74 
75 #define TAK_ENCODER_BITS (TAK_ENCODER_CODEC_BITS + \
76  TAK_ENCODER_PROFILE_BITS)
77 
78 #define TAK_SIZE_BITS (TAK_SIZE_SAMPLES_NUM_BITS + \
79  TAK_SIZE_FRAME_DURATION_BITS)
80 
81 #define TAK_FORMAT_BITS (TAK_FORMAT_DATA_TYPE_BITS + \
82  TAK_FORMAT_SAMPLE_RATE_BITS + \
83  TAK_FORMAT_BPS_BITS + \
84  TAK_FORMAT_CHANNEL_BITS + 1 + \
85  TAK_FORMAT_VALID_BITS + 1 + \
86  TAK_FORMAT_CH_LAYOUT_BITS * \
87  TAK_MAX_CHANNELS)
88 
89 #define TAK_STREAMINFO_BITS (TAK_ENCODER_BITS + \
90  TAK_SIZE_BITS + \
91  TAK_FORMAT_BITS)
92 
93 #define TAK_MAX_FRAME_HEADER_BITS (TAK_MIN_FRAME_HEADER_LAST_BITS + \
94  TAK_STREAMINFO_BITS + 31)
95 
96 #define TAK_STREAMINFO_BYTES ((TAK_STREAMINFO_BITS + 7) / 8)
97 #define TAK_MAX_FRAME_HEADER_BYTES ((TAK_MAX_FRAME_HEADER_BITS + 7) / 8)
98 #define TAK_MIN_FRAME_HEADER_BYTES ((TAK_MIN_FRAME_HEADER_BITS + 7) / 8)
99 
103 };
104 
114 };
115 
127 };
128 
129 typedef struct TAKStreamInfo {
130  int flags;
134  int channels;
135  int bps;
139  uint64_t ch_layout;
140  int64_t samples;
141 } TAKStreamInfo;
142 
143 void ff_tak_init_crc(void);
144 
145 int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
146 
147 /**
148  * Parse the Streaminfo metadata block.
149  * @param[in] gb pointer to GetBitContext
150  * @param[out] s storage for parsed information
151  */
153 
154 /**
155  * Validate and decode a frame header.
156  * @param avctx AVCodecContext to use as av_log() context
157  * @param[in] gb GetBitContext from which to read frame header
158  * @param[out] s frame information
159  * @param log_level_offset log level offset, can be used to silence
160  * error messages.
161  * @return non-zero on error, 0 if OK
162  */
164  TAKStreamInfo *s, int log_level_offset);
165 #endif /* AVCODEC_TAK_H */
const char * s
Definition: avisynth_c.h:668
int channels
Definition: tak.h:134
uint64_t ch_layout
Definition: tak.h:139
TAKMetaDataType
Definition: tak.h:105
void ff_tak_init_crc(void)
Definition: tak.c:84
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, TAKStreamInfo *s, int log_level_offset)
Validate and decode a frame header.
Definition: tak.c:143
uint8_t
int flags
Definition: tak.h:130
bitstream reader API header.
int data_type
Definition: tak.h:132
int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
Definition: tak.c:92
int last_frame_samples
Definition: tak.h:138
external API header
int bps
Definition: tak.h:135
int64_t samples
Definition: tak.h:140
TAKCodecType
Definition: tak.h:100
main external API structure.
enum TAKCodecType codec
Definition: tak.h:131
void * buf
Definition: avisynth_c.h:594
struct TAKStreamInfo TAKStreamInfo
int frame_samples
Definition: tak.h:137
int sample_rate
Definition: tak.h:133
int frame_num
Definition: tak.h:136
TAKFrameSizeType
Definition: tak.h:116
void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
Parse the Streaminfo metadata block.
Definition: tak.c:108