58 switch (
frame->subbands) {
60 for (ch = 0; ch <
frame->channels; ch++) {
61 x = &
s->X[ch][
s->position - 4 *
62 s->increment +
frame->blocks * 4];
64 blk +=
s->increment) {
70 x -= 4 *
s->increment;
73 return frame->blocks * 4;
76 for (ch = 0; ch <
frame->channels; ch++) {
77 x = &
s->X[ch][
s->position - 8 *
78 s->increment +
frame->blocks * 8];
80 blk +=
s->increment) {
86 x -= 8 *
s->increment;
89 return frame->blocks * 8;
106 uint8_t crc_header[11] = { 0 };
109 uint32_t audio_sample;
113 uint32_t levels[2][8];
114 uint32_t sb_sample_delta[2][8];
123 avpkt->
data[1] = (
frame->frequency & 0x03) << 6;
124 avpkt->
data[1] |= (((
frame->blocks >> 2) - 1) & 0x03) << 4;
125 avpkt->
data[1] |= (
frame->mode & 0x03) << 2;
126 avpkt->
data[1] |= (
frame->allocation & 0x01) << 1;
127 avpkt->
data[1] |= ((
frame->subbands == 8) & 0x01) << 0;
133 crc_header[0] = avpkt->
data[1];
134 crc_header[1] = avpkt->
data[2];
141 crc_header[crc_pos >> 3] = joint;
142 crc_pos +=
frame->subbands;
145 for (ch = 0; ch <
frame->channels; ch++) {
146 for (sb = 0; sb <
frame->subbands; sb++) {
148 crc_header[crc_pos >> 3] <<= 4;
149 crc_header[crc_pos >> 3] |=
frame->scale_factor[ch][sb] & 0x0F;
156 crc_header[crc_pos >> 3] <<= 8 - (crc_pos % 8);
162 for (ch = 0; ch <
frame->channels; ch++) {
163 for (sb = 0; sb <
frame->subbands; sb++) {
164 levels[ch][sb] = ((1 <<
bits[ch][sb]) - 1) <<
165 (32 - (
frame->scale_factor[ch][sb] +
167 sb_sample_delta[ch][sb] = (uint32_t) 1 <<
168 (
frame->scale_factor[ch][sb] +
174 for (ch = 0; ch <
frame->channels; ch++) {
175 for (sb = 0; sb <
frame->subbands; sb++) {
177 if (
bits[ch][sb] == 0)
180 audio_sample = ((uint64_t) levels[ch][sb] *
181 (sb_sample_delta[ch][sb] +
182 frame->sb_sample_f[
blk][ch][sb])) >> 32;
246 / (1000000 *
frame->subbands)) - 10, 4, 16) & ~3;
275 sbc->
dsp.increment = sbc->
msbc ? 1 : 4;
282 const AVFrame *av_frame,
int *got_packet_ptr)
290 int frame_length = 4 + (4 *
frame->subbands *
frame->channels) / 8
291 + ((
frame->blocks *
frame->bitpool * (1 + dual)
302 if (
frame->subbands == 8)
303 sbc->
dsp.position = sbc->
dsp.sbc_enc_process_input_8s(
304 sbc->
dsp.position, av_frame->
data[0], sbc->
dsp.X,
307 sbc->
dsp.position = sbc->
dsp.sbc_enc_process_input_4s(
308 sbc->
dsp.position, av_frame->
data[0], sbc->
dsp.X,
314 j = sbc->
dsp.sbc_calc_scalefactors_j(
frame->sb_sample_f,
319 sbc->
dsp.sbc_calc_scalefactors(
frame->sb_sample_f,
330#define OFFSET(x) offsetof(SBCEncContext, x)
331#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
333 {
"sbc_delay",
"set maximum algorithmic latency",
335 {
"msbc",
"use mSBC mode (wideband speech mono SBC)",
342 .class_name =
"sbc encoder",
const FFCodec ff_sbc_encoder
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define CODEC_SAMPLERATES_ARRAY(array)
#define CODEC_CH_LAYOUTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
#define AV_PROFILE_SBC_MSBC
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static const uint8_t bits[8]
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
av_cold void ff_sbcdsp_init(SBCDSPContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
const AVProfile ff_sbc_profiles[]
#define FF_AVCTX_PROFILE_OPTION(name, description, type, value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
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 SBC_MODE_JOINT_STEREO
#define SBC_MODE_DUAL_CHANNEL
SBC basic "building bricks".
#define SBC_X_BUFFER_SIZE
static size_t sbc_pack_frame(AVPacket *avpkt, struct sbc_frame *frame, int joint, int msbc)
static int sbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *av_frame, int *got_packet_ptr)
static av_cold int sbc_encode_init(AVCodecContext *avctx)
static const AVClass sbc_class
static int sbc_analyze_audio(SBCDSPContext *s, struct sbc_frame *frame)
static const int sbc_samplerates[]
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
int global_quality
Global quality for codecs which cannot change it per frame.
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.