Go to the documentation of this file.
35 int i, flags1, flags2, block_align;
43 "too many channels: got %i, need %i or fewer\n",
56 "bitrate too low: got %"PRId64
", need 24000 or higher\n",
82 s->use_exp_vlc = flags2 & 0x0001;
83 s->use_bit_reservoir = flags2 & 0x0002;
84 s->use_variable_block_len = flags2 & 0x0004;
92 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
98 block_align = avctx->
bit_rate * (int64_t)
s->frame_len /
110 float **audio = (
float **)
frame->extended_data;
112 int window_index =
s->frame_len_bits -
s->block_len_bits;
115 const float *
win =
s->windows[window_index];
116 int window_len = 1 <<
s->block_len_bits;
117 float n = 2.0 * 32768.0 / window_len;
120 memcpy(
s->output,
s->frame_out[ch], window_len *
sizeof(*
s->output));
121 s->fdsp->vector_fmul_scalar(
s->frame_out[ch], audio[ch], n,
len);
122 s->fdsp->vector_fmul_reverse(&
s->output[window_len],
s->frame_out[ch],
124 s->fdsp->vector_fmul(
s->frame_out[ch],
s->frame_out[ch],
win,
len);
125 mdct->mdct_calc(mdct,
s->coefs[ch],
s->output);
140 float v, *q, max_scale, *q_end;
142 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
143 q =
s->exponents[ch];
144 q_end = q +
s->block_len;
148 v =
ff_exp10(*exp_param++ *(1.0 / 16.0));
149 max_scale =
FFMAX(max_scale, v);
155 s->max_exponent[ch] = max_scale;
164 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
165 q =
s->exponents[ch];
166 q_end = q +
s->block_len;
167 if (
s->version == 1) {
168 last_exp = *exp_param++;
169 av_assert0(last_exp - 10 >= 0 && last_exp - 10 < 32);
175 int exp = *exp_param++;
176 int code =
exp - last_exp + 60;
201 if (
s->use_variable_block_len) {
205 s->next_block_len_bits =
s->frame_len_bits;
206 s->prev_block_len_bits =
s->frame_len_bits;
207 s->block_len_bits =
s->frame_len_bits;
210 s->block_len = 1 <<
s->block_len_bits;
212 bsize =
s->frame_len_bits -
s->block_len_bits;
215 v =
s->coefs_end[bsize] -
s->coefs_start;
216 for (ch = 0; ch <
s->avctx->channels; ch++)
219 int n4 =
s->block_len / 2;
220 mdct_norm = 1.0 / (float) n4;
222 mdct_norm *= sqrt(n4);
225 if (
s->avctx->channels == 2)
228 for (ch = 0; ch <
s->avctx->channels; ch++) {
230 s->channel_coded[ch] = 1;
231 if (
s->channel_coded[ch])
235 for (ch = 0; ch <
s->avctx->channels; ch++) {
236 if (
s->channel_coded[ch]) {
238 float *coefs, *exponents,
mult;
241 coefs1 =
s->coefs1[ch];
242 exponents =
s->exponents[ch];
245 coefs = src_coefs[ch];
246 if (
s->use_noise_coding && 0) {
249 coefs +=
s->coefs_start;
251 for (
i = 0;
i < n;
i++) {
252 double t = *coefs++ / (exponents[
i] *
mult);
253 if (t < -32768 || t > 32767)
263 for (ch = 0; ch <
s->avctx->channels; ch++) {
264 int a =
s->channel_coded[ch];
272 for (v = total_gain - 1; v >= 127; v -= 127)
278 if (
s->use_noise_coding) {
279 for (ch = 0; ch <
s->avctx->channels; ch++) {
280 if (
s->channel_coded[ch]) {
282 n =
s->exponent_high_sizes[bsize];
283 for (
i = 0;
i < n;
i++) {
284 put_bits(&
s->pb, 1,
s->high_band_coded[ch][
i] = 0);
286 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
293 if (
s->block_len_bits !=
s->frame_len_bits)
297 for (ch = 0; ch <
s->avctx->channels; ch++) {
298 if (
s->channel_coded[ch]) {
299 if (
s->use_exp_vlc) {
310 for (ch = 0; ch <
s->avctx->channels; ch++) {
311 if (
s->channel_coded[ch]) {
314 tindex = (ch == 1 &&
s->ms_stereo);
315 ptr = &
s->coefs1[ch][0];
319 for (; ptr < eptr; ptr++) {
324 if (abs_level <= s->
coef_vlcs[tindex]->max_level)
325 if (run < s->
coef_vlcs[tindex]->levels[abs_level - 1])
326 code =
run +
s->int_table[tindex][abs_level - 1];
330 s->coef_vlcs[tindex]->huffcodes[
code]);
333 if (1 << coef_nb_bits <= abs_level)
336 put_bits(&
s->pb, coef_nb_bits, abs_level);
346 put_bits(&
s->pb,
s->coef_vlcs[tindex]->huffbits[1],
347 s->coef_vlcs[tindex]->huffcodes[1]);
349 if (
s->version == 1 &&
s->avctx->channels >= 2)
356 uint8_t *buf,
int buf_size,
int total_gain)
360 if (
s->use_bit_reservoir)
376 s->block_len_bits =
s->frame_len_bits;
377 s->block_len = 1 <<
s->block_len_bits;
388 for (
i = 0;
i <
s->block_len;
i++) {
389 a =
s->coefs[0][
i] * 0.5;
390 b =
s->coefs[1][
i] * 0.5;
391 s->coefs[0][
i] =
a +
b;
392 s->coefs[1][
i] =
a -
b;
400 for (
i = 64;
i;
i >>= 1) {
407 while(total_gain <= 128 && error > 0)
410 av_log(avctx,
AV_LOG_ERROR,
"Invalid input data or requested bitrate too low, cannot encode\n");
431 #if CONFIG_WMAV1_ENCODER
446 #if CONFIG_WMAV2_ENCODER
static void error(const char *err)
int frame_size
Number of samples per channel in an audio frame.
@ AV_SAMPLE_FMT_FLTP
float, planar
static int nb_coefs(int length, int level, uint64_t sn)
#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 av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static const CoefVLCTable coef_vlcs[6]
int sample_rate
samples per second
static enum AVSampleFormat sample_fmts[]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
const AVCodec ff_wmav1_encoder
static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame)
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int put_bytes_count(const PutBitContext *s, int round_up)
static void init_exp(WMACodecContext *s, int ch, const int *exp_param)
static float win(SuperEqualizerContext *s, float n, int N)
const struct AVCodec * codec
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
static int encode_block(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], int total_gain)
int initial_padding
Audio only.
static av_cold int encode_init(AVCodecContext *avctx)
static int16_t mult(Float11 *f1, Float11 *f2)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_wma_total_gain_to_bits(int total_gain)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int parse_exponents(DBEContext *s, DBEChannel *c)
int64_t bit_rate
the average bitrate
static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define MAX_CODED_SUPERFRAME_SIZE
int ff_wma_end(AVCodecContext *avctx)
const uint8_t ff_aac_scalefactor_bits[121]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const AVCodec ff_wmav2_encoder
#define AV_NOPTS_VALUE
Undefined timestamp value.
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int fixed_exp(int x)
int channels
number of audio channels
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static int put_bits_count(PutBitContext *s)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVSampleFormat
Audio sample formats.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
static int encode_frame(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], uint8_t *buf, int buf_size, int total_gain)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
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
main external API structure.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
This structure stores compressed data.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
const uint32_t ff_aac_scalefactor_code[121]