FFmpeg
libavcodec
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
#include "
avcodec.h
"
33
#include "
get_bits.h
"
34
35
#define TAK_FORMAT_DATA_TYPE_BITS 3
36
#define TAK_FORMAT_SAMPLE_RATE_BITS 18
37
#define TAK_FORMAT_BPS_BITS 5
38
#define TAK_FORMAT_CHANNEL_BITS 4
39
#define TAK_FORMAT_VALID_BITS 5
40
#define TAK_FORMAT_CH_LAYOUT_BITS 6
41
#define TAK_SIZE_FRAME_DURATION_BITS 4
42
#define TAK_SIZE_SAMPLES_NUM_BITS 35
43
#define TAK_LAST_FRAME_POS_BITS 40
44
#define TAK_LAST_FRAME_SIZE_BITS 24
45
#define TAK_ENCODER_CODEC_BITS 6
46
#define TAK_ENCODER_PROFILE_BITS 4
47
#define TAK_SAMPLE_RATE_MIN 6000
48
#define TAK_CHANNELS_MIN 1
49
#define TAK_BPS_MIN 8
50
#define TAK_FRAME_HEADER_FLAGS_BITS 3
51
#define TAK_FRAME_HEADER_SYNC_ID 0xA0FF
52
#define TAK_FRAME_HEADER_SYNC_ID_BITS 16
53
#define TAK_FRAME_HEADER_SAMPLE_COUNT_BITS 14
54
#define TAK_FRAME_HEADER_NO_BITS 21
55
#define TAK_FRAME_DURATION_QUANT_SHIFT 5
56
#define TAK_CRC24_BITS 24
57
58
59
#define TAK_FRAME_FLAG_IS_LAST 0x1
60
#define TAK_FRAME_FLAG_HAS_INFO 0x2
61
#define TAK_FRAME_FLAG_HAS_METADATA 0x4
62
63
#define TAK_MAX_CHANNELS (1 << TAK_FORMAT_CHANNEL_BITS)
64
65
#define TAK_MIN_FRAME_HEADER_BITS (TAK_FRAME_HEADER_SYNC_ID_BITS + \
66
TAK_FRAME_HEADER_FLAGS_BITS + \
67
TAK_FRAME_HEADER_NO_BITS + \
68
TAK_CRC24_BITS)
69
70
#define TAK_MIN_FRAME_HEADER_LAST_BITS (TAK_MIN_FRAME_HEADER_BITS + 2 + \
71
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS)
72
73
#define TAK_ENCODER_BITS (TAK_ENCODER_CODEC_BITS + \
74
TAK_ENCODER_PROFILE_BITS)
75
76
#define TAK_SIZE_BITS (TAK_SIZE_SAMPLES_NUM_BITS + \
77
TAK_SIZE_FRAME_DURATION_BITS)
78
79
#define TAK_FORMAT_BITS (TAK_FORMAT_DATA_TYPE_BITS + \
80
TAK_FORMAT_SAMPLE_RATE_BITS + \
81
TAK_FORMAT_BPS_BITS + \
82
TAK_FORMAT_CHANNEL_BITS + 1 + \
83
TAK_FORMAT_VALID_BITS + 1 + \
84
TAK_FORMAT_CH_LAYOUT_BITS * \
85
TAK_MAX_CHANNELS)
86
87
#define TAK_STREAMINFO_BITS (TAK_ENCODER_BITS + \
88
TAK_SIZE_BITS + \
89
TAK_FORMAT_BITS)
90
91
#define TAK_MAX_FRAME_HEADER_BITS (TAK_MIN_FRAME_HEADER_LAST_BITS + \
92
TAK_STREAMINFO_BITS + 31)
93
94
#define TAK_STREAMINFO_BYTES ((TAK_STREAMINFO_BITS + 7) / 8)
95
#define TAK_MAX_FRAME_HEADER_BYTES ((TAK_MAX_FRAME_HEADER_BITS + 7) / 8)
96
#define TAK_MIN_FRAME_HEADER_BYTES ((TAK_MIN_FRAME_HEADER_BITS + 7) / 8)
97
98
enum
TAKCodecType
{
99
TAK_CODEC_MONO_STEREO
= 2,
100
TAK_CODEC_MULTICHANNEL
= 4,
101
};
102
103
enum
TAKMetaDataType
{
104
TAK_METADATA_END
= 0,
105
TAK_METADATA_STREAMINFO
,
106
TAK_METADATA_SEEKTABLE
,
107
TAK_METADATA_SIMPLE_WAVE_DATA
,
108
TAK_METADATA_ENCODER
,
109
TAK_METADATA_PADDING
,
110
TAK_METADATA_MD5
,
111
TAK_METADATA_LAST_FRAME
,
112
};
113
114
enum
TAKFrameSizeType
{
115
TAK_FST_94ms
= 0,
116
TAK_FST_125ms
,
117
TAK_FST_188ms
,
118
TAK_FST_250ms
,
119
TAK_FST_4096
,
120
TAK_FST_8192
,
121
TAK_FST_16384
,
122
TAK_FST_512
,
123
TAK_FST_1024
,
124
TAK_FST_2048
,
125
};
126
127
typedef
struct
TAKStreamInfo
{
128
int
flags
;
129
enum
TAKCodecType
codec
;
130
int
data_type
;
131
int
sample_rate
;
132
int
channels
;
133
int
bps
;
134
int
frame_num
;
135
int
frame_samples
;
136
int
last_frame_samples
;
137
uint64_t
ch_layout
;
138
int64_t
samples
;
139
}
TAKStreamInfo
;
140
141
int
ff_tak_check_crc
(
const
uint8_t *buf,
unsigned
int
buf_size);
142
143
/**
144
* Parse the Streaminfo metadata block.
145
* @param[out] s storage for parsed information
146
* @param[in] buf input buffer
147
* @param[in] size size of input buffer in bytes
148
* @return non-zero on error, 0 if OK
149
*/
150
int
avpriv_tak_parse_streaminfo
(
TAKStreamInfo
*
s
,
const
uint8_t *buf,
int
size
);
151
152
void
ff_tak_parse_streaminfo
(
TAKStreamInfo
*
s
,
GetBitContext
*gb);
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
*/
163
int
ff_tak_decode_frame_header
(
AVCodecContext
*avctx,
GetBitContext
*gb,
164
TAKStreamInfo
*
s
,
int
log_level_offset);
165
#endif
/* AVCODEC_TAK_H */
TAKCodecType
TAKCodecType
Definition:
tak.h:98
TAK_METADATA_PADDING
@ TAK_METADATA_PADDING
Definition:
tak.h:109
TAKStreamInfo::data_type
int data_type
Definition:
tak.h:130
TAKStreamInfo::flags
int flags
Definition:
tak.h:128
TAKStreamInfo::last_frame_samples
int last_frame_samples
Definition:
tak.h:136
ff_tak_check_crc
int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
Definition:
tak.c:79
TAK_FST_4096
@ TAK_FST_4096
Definition:
tak.h:119
TAKStreamInfo::channels
int channels
Definition:
tak.h:132
TAK_METADATA_ENCODER
@ TAK_METADATA_ENCODER
Definition:
tak.h:108
GetBitContext
Definition:
get_bits.h:107
TAK_METADATA_SEEKTABLE
@ TAK_METADATA_SEEKTABLE
Definition:
tak.h:106
TAK_FST_94ms
@ TAK_FST_94ms
Definition:
tak.h:115
TAK_METADATA_SIMPLE_WAVE_DATA
@ TAK_METADATA_SIMPLE_WAVE_DATA
Definition:
tak.h:107
s
#define s(width, name)
Definition:
cbs_vp9.c:256
TAK_METADATA_END
@ TAK_METADATA_END
Definition:
tak.h:104
get_bits.h
TAK_CODEC_MONO_STEREO
@ TAK_CODEC_MONO_STEREO
Definition:
tak.h:99
TAKStreamInfo::samples
int64_t samples
Definition:
tak.h:138
TAKStreamInfo::ch_layout
uint64_t ch_layout
Definition:
tak.h:137
ff_tak_parse_streaminfo
void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)
Definition:
tak.c:95
TAK_FST_16384
@ TAK_FST_16384
Definition:
tak.h:121
TAKStreamInfo::frame_samples
int frame_samples
Definition:
tak.h:135
TAKStreamInfo::frame_num
int frame_num
Definition:
tak.h:134
ff_tak_decode_frame_header
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
TAK_FST_250ms
@ TAK_FST_250ms
Definition:
tak.h:118
TAK_METADATA_LAST_FRAME
@ TAK_METADATA_LAST_FRAME
Definition:
tak.h:111
TAK_FST_512
@ TAK_FST_512
Definition:
tak.h:122
size
int size
Definition:
twinvq_data.h:10344
TAK_METADATA_MD5
@ TAK_METADATA_MD5
Definition:
tak.h:110
TAKStreamInfo::bps
int bps
Definition:
tak.h:133
TAKStreamInfo::codec
enum TAKCodecType codec
Definition:
tak.h:129
avpriv_tak_parse_streaminfo
int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size)
Parse the Streaminfo metadata block.
Definition:
tak.c:130
TAK_METADATA_STREAMINFO
@ TAK_METADATA_STREAMINFO
Definition:
tak.h:105
avcodec.h
TAKMetaDataType
TAKMetaDataType
Definition:
tak.h:103
TAK_FST_8192
@ TAK_FST_8192
Definition:
tak.h:120
TAK_FST_1024
@ TAK_FST_1024
Definition:
tak.h:123
AVCodecContext
main external API structure.
Definition:
avcodec.h:426
TAK_FST_188ms
@ TAK_FST_188ms
Definition:
tak.h:117
TAKStreamInfo::sample_rate
int sample_rate
Definition:
tak.h:131
TAKStreamInfo
Definition:
tak.h:127
TAK_FST_2048
@ TAK_FST_2048
Definition:
tak.h:124
TAKFrameSizeType
TAKFrameSizeType
Definition:
tak.h:114
TAK_FST_125ms
@ TAK_FST_125ms
Definition:
tak.h:116
TAK_CODEC_MULTICHANNEL
@ TAK_CODEC_MULTICHANNEL
Definition:
tak.h:100
Generated on Tue Feb 28 2023 21:33:38 for FFmpeg by
1.8.17