Go to the documentation of this file.
26 #define BITSTREAM_READER_LE
66 s->bitstream_size = 0;
89 s->nb_samples = UINT64_MAX;
93 if (!
s->n_taps ||
s->n_taps > 2048)
97 if (!
s->down_sampling)
101 if (!
s->samples_per_packet)
104 if (
s->down_sampling *
s->samples_per_packet <
s->n_taps)
115 s->input_samples =
av_calloc(
s->samples_per_packet,
sizeof(*
s->input_samples));
116 if (!
s->input_samples)
119 s->samples[0] =
av_calloc(
s->samples_per_packet *
s->down_sampling,
sizeof(*
s->samples[0]));
120 s->samples[1] =
av_calloc(
s->samples_per_packet *
s->down_sampling,
sizeof(*
s->samples[0]));
121 if (!
s->samples[0] || !
s->samples[1])
124 s->bits =
av_calloc(
s->max_framesize * 8,
sizeof(*
s->bits));
128 for (
int i = 0;
i < 512;
i++) {
129 s->quant[
i] = sqrt(
i + 1);
153 int i, low_bits = 0, x = 0, max_x;
154 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++) {
222 if (
pos >= entries) {
224 level += passes << low_bits;
226 if (
bits[x].
bit &&
bits[x].count > entries - n_zeros)
227 passes =
bits[x].count / (entries - n_zeros);
235 buf[
pos] += passes << low_bits;
240 bits[x].count -= passes;
241 x +=
bits[x].count == 0;
247 for (
i = 0;
i < entries;
i++) {
258 return (
a >>
b) + (
a < 0);
263 return a + (1 <<
b - 1) >>
b;
266 #define LATTICE_SHIFT 10
267 #define SAMPLE_SHIFT 4
268 #define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
273 int *k_ptr = &(k[order-2]),
274 *state_ptr = &(
state[order-2]);
276 for (
i = order-2;
i >= 0;
i--, k_ptr--, state_ptr--) {
277 unsigned k_value = *k_ptr, state_value = *state_ptr;
293 for (
int i = order - 2;
i >= 0;
i--) {
296 for (
int j = 0, p =
i + 1; p < order; j++, p++) {
311 int quant, n, buf_size, input_buf_size;
314 if ((!
pkt->
size && !
s->bitstream_size) ||
s->nb_samples == 0) {
319 buf_size =
FFMIN(
pkt->
size,
s->max_framesize -
s->bitstream_size);
320 input_buf_size = buf_size;
322 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
323 s->bitstream_index = 0;
326 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->
data, buf_size);
327 buf = &
s->bitstream[
s->bitstream_index];
328 buf_size +=
s->bitstream_size;
329 s->bitstream_size = buf_size;
330 if (buf_size < s->max_framesize &&
pkt->
data) {
332 return input_buf_size;
335 frame->nb_samples =
FFMIN(
s->samples_per_packet *
s->down_sampling,
s->nb_samples);
346 for (
int i = 0;
i <
s->n_taps;
i++)
347 s->k[
i] *=
s->quant[
i];
352 const int down_sampling =
s->down_sampling;
354 int *
state =
s->state[ch];
362 for (
int j = 0; j <
s->down_sampling - 1; j++) {
372 for (
int i = 0;
i <
s->n_taps;
i++)
377 for (
int i = 0;
i <
frame->nb_samples;
i++) {
378 s->samples[1][
i] +=
shift(
s->samples[0][
i], 1);
379 s->samples[0][
i] -=
s->samples[1][
i];
386 for (
int i = 0;
i <
frame->nb_samples;
i++)
392 int16_t *osamples = (int16_t *)
frame->extended_data[ch];
398 s->nb_samples -=
frame->nb_samples;
405 s->bitstream_size = 0;
406 s->bitstream_index = 0;
412 if (
s->bitstream_size) {
413 s->bitstream_index += n;
414 s->bitstream_size -= n;
415 return input_buf_size;
431 AV_CODEC_CAP_SUBFRAMES |
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 const uint8_t quant[64]
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)
#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.
int(* init)(AVBSFContext *ctx)
#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.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
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
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)