65 unsigned int consumed;
72 uint32_t audio_sample;
76 uint32_t levels[2][8];
96 frame->blocks = 4 * ((
data[1] >> 4) & 0x03) + 4;
99 frame->allocation = (
data[1] >> 1) & 0x01;
100 frame->subbands =
data[1] & 0x01 ? 8 : 4;
114 crc_header[0] =
data[1];
115 crc_header[1] =
data[2];
119 if (
len * 8 < consumed +
frame->subbands)
123 for (sb = 0; sb <
frame->subbands - 1; sb++)
124 frame->joint |= ((
data[4] >> (7 - sb)) & 0x01) << sb;
125 if (
frame->subbands == 4)
126 crc_header[crc_pos / 8] =
data[4] & 0xf0;
128 crc_header[crc_pos / 8] =
data[4];
130 consumed +=
frame->subbands;
131 crc_pos +=
frame->subbands;
138 for (sb = 0; sb <
frame->subbands; sb++) {
140 frame->scale_factor[ch][sb] =
141 (
data[consumed >> 3] >> (4 - (consumed & 0x7))) & 0x0F;
142 crc_header[crc_pos >> 3] |=
143 frame->scale_factor[ch][sb] << (4 - (crc_pos & 0x7));
156 for (sb = 0; sb <
frame->subbands; sb++)
157 levels[ch][sb] = (1 <<
bits[ch][sb]) - 1;
162 for (sb = 0; sb <
frame->subbands; sb++) {
165 if (levels[ch][sb] == 0) {
175 if (consumed >
len * 8)
178 if ((
data[consumed >> 3] >> (7 - (consumed & 0x7))) & 0x01)
179 audio_sample |= 1 << (
bits[ch][sb] -
bit - 1);
185 (((((uint64_t) audio_sample << 1) | 1) <<
shift) /
186 levels[ch][sb]) - (1 <<
shift);
193 for (sb = 0; sb <
frame->subbands; sb++) {
194 if (
frame->joint & (0x01 << sb)) {
206 if ((consumed & 0x7) != 0)
207 consumed += 8 - (consumed & 0x7);
209 return consumed >> 3;
220 for (
i = 0;
i < 8;
i++) {
225 memcpy(v + 80, v, 9 *
sizeof(*v));
237 for (idx = 0,
i = 0;
i < 4;
i++, idx += 5) {
263 for (
i = 0;
i < 16;
i++) {
268 memcpy(v + 160, v, 9 *
sizeof(*v));
284 for (idx = 0,
i = 0;
i < 8;
i++, idx += 5) {
307 switch (
frame->subbands) {
331 memset(sbc->
dsp.
V, 0,
sizeof(sbc->
dsp.
V));
332 for (ch = 0; ch < 2; ch++)
339 void *
data,
int *got_frame_ptr,
344 int ret, frame_length;
350 if (frame_length <= 0)
380 .supported_samplerates = (
const int[]) { 16000, 32000, 44100, 48000, 0 },
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#define bit(string, value)
static const uint16_t channel_layouts[7]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame, size_t len)
static void sbc_synthesize_four(struct sbc_decoder_state *state, struct sbc_frame *frame, int ch, int blk, AVFrame *output_frame)
static void sbc_synthesize_audio(struct sbc_decoder_state *state, struct sbc_frame *frame, AVFrame *output_frame)
static void sbc_synthesize_eight(struct sbc_decoder_state *state, struct sbc_frame *frame, int ch, int blk, AVFrame *output_frame)
static int sbc_decode_init(AVCodecContext *avctx)
static int sbc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ff_sbc_crc8(const AVCRC *ctx, const uint8_t *data, size_t len)
void ff_sbc_calculate_bits(const struct sbc_frame *frame, int(*bits)[8])
SBC common definitions for the encoder and decoder.
#define SBCDEC_FIXED_EXTRA_BITS
const int32_t ff_synmatrix4[8][4]
const int32_t ff_sbc_proto_8_80m1[]
const int32_t ff_sbc_proto_4_40m0[]
const int32_t ff_synmatrix8[16][8]
const int32_t ff_sbc_proto_8_80m0[]
const int32_t ff_sbc_proto_4_40m1[]
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
Describe the class of an AVClass context structure.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int channels
number of audio channels
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int channels
number of audio channels, only used for audio.
This structure stores compressed data.
struct sbc_decoder_state dsp
static const uint8_t offset[127][2]