Go to the documentation of this file.
26 #define BITSTREAM_READER_LE
67 s->bitstream_size = 0;
90 s->nb_samples = UINT64_MAX;
94 if (!
s->n_taps ||
s->n_taps > 2048)
98 if (!
s->down_sampling)
102 if (!
s->samples_per_packet)
105 if (
s->down_sampling *
s->samples_per_packet <
s->n_taps)
116 s->input_samples =
av_calloc(
s->samples_per_packet,
sizeof(*
s->input_samples));
117 if (!
s->input_samples)
120 s->samples[0] =
av_calloc(
s->samples_per_packet *
s->down_sampling,
sizeof(*
s->samples[0]));
121 s->samples[1] =
av_calloc(
s->samples_per_packet *
s->down_sampling,
sizeof(*
s->samples[0]));
122 if (!
s->samples[0] || !
s->samples[1])
125 s->bits =
av_calloc(
s->max_framesize * 8,
sizeof(*
s->bits));
129 for (
int i = 0;
i < 512;
i++) {
130 s->quant[
i] = sqrt(
i + 1);
154 int i, low_bits = 0, x = 0, max_x;
155 int n_zeros = 0,
step = 256, dominant = 0;
159 memset(buf, 0, entries *
sizeof(*buf));
164 for (
i = 0;
i < entries;
i++)
168 while (n_zeros < entries) {
169 int steplet =
step >> 8;
178 bits[x ].bit = dominant;
179 bits[x++].count = steplet;
185 if (
step > INT32_MAX*8LL/9 + 1)
188 }
else if (steplet > 0) {
193 if (actual_run > 0) {
194 bits[x ].bit = dominant;
195 bits[x++].count = actual_run;
198 bits[x ].bit = !dominant;
202 n_zeros += actual_run;
211 dominant = !dominant;
218 for (
i = 0; n_zeros < entries;
i++) {
219 if (
pos >= entries) {
221 level += 1 << low_bits;
232 buf[
pos] += 1 << low_bits;
237 x +=
bits[x].count == 0;
243 for (
i = 0;
i < entries;
i++) {
254 return (
a >>
b) + (
a < 0);
259 return a + (1 <<
b - 1) >>
b;
262 #define LATTICE_SHIFT 10
263 #define SAMPLE_SHIFT 4
264 #define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
269 int *k_ptr = &(k[order-2]),
270 *state_ptr = &(
state[order-2]);
272 for (
i = order-2;
i >= 0;
i--, k_ptr--, state_ptr--) {
273 unsigned k_value = *k_ptr, state_value = *state_ptr;
289 for (
int i = order - 2;
i >= 0;
i--) {
292 for (
int j = 0, p =
i + 1; p < order; j++, p++) {
307 int quant, n, buf_size, input_buf_size;
310 if ((!
pkt->
size && !
s->bitstream_size) ||
s->nb_samples == 0) {
315 buf_size =
FFMIN(
pkt->
size,
s->max_framesize -
s->bitstream_size);
316 input_buf_size = buf_size;
318 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
319 s->bitstream_index = 0;
322 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->
data, buf_size);
323 buf = &
s->bitstream[
s->bitstream_index];
324 buf_size +=
s->bitstream_size;
325 s->bitstream_size = buf_size;
326 if (buf_size < s->max_framesize &&
pkt->
data) {
328 return input_buf_size;
331 frame->nb_samples =
FFMIN(
s->samples_per_packet *
s->down_sampling,
s->nb_samples);
342 for (
int i = 0;
i <
s->n_taps;
i++)
343 s->k[
i] *=
s->quant[
i];
348 const int down_sampling =
s->down_sampling;
350 int *
state =
s->state[ch];
358 for (
int j = 0; j <
s->down_sampling - 1; j++) {
368 for (
int i = 0;
i <
s->n_taps;
i++)
373 for (
int i = 0;
i <
frame->nb_samples;
i++) {
374 s->samples[1][
i] +=
shift(
s->samples[0][
i], 1);
375 s->samples[0][
i] -=
s->samples[1][
i];
382 for (
int i = 0;
i <
frame->nb_samples;
i++)
388 int16_t *osamples = (int16_t *)
frame->extended_data[ch];
394 s->nb_samples -=
frame->nb_samples;
401 s->bitstream_size = 0;
402 s->bitstream_index = 0;
408 if (
s->bitstream_size) {
409 s->bitstream_index += n;
410 s->bitstream_size -= n;
411 return input_buf_size;
static void error(const char *err)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int get_bits_left(GetBitContext *gb)
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 int get_bits_count(const GetBitContext *s)
static int shift_down(int a, int b)
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
static unsigned read_uint_max(BonkContext *s, uint32_t max)
int nb_channels
Number of channels in this layout.
#define bit(string, value)
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
static int predictor_calc_error(int *k, int *state, int order, int error)
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
static int bonk_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *pkt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define FF_CODEC_DECODE_CB(func)
int(* init)(AVBSFContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_cold int bonk_init(AVCodecContext *avctx)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
#define CODEC_LONG_NAME(str)
static unsigned int get_bits1(GetBitContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static int shift(int a, int b)
enum AVSampleFormat sample_fmt
audio sample format
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
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVSampleFormat
Audio sample formats.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
const char * name
Name of the codec implementation.
void * av_calloc(size_t nmemb, size_t size)
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
#define AV_INPUT_BUFFER_PADDING_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
const FFCodec ff_bonk_decoder
main external API structure.
static int intlist_read(BonkContext *s, int *buf, int entries, int base_2_part)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Filter the word “frame” indicates either a video frame or a group of audio samples
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
This structure stores compressed data.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold int bonk_close(AVCodecContext *avctx)
static uint32_t samples_per_packet(const AVCodecParameters *par)
static void predictor_init_state(int *k, unsigned *state, int order)