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;
160 memset(buf, 0, entries *
sizeof(*buf));
165 for (
i = 0;
i < entries;
i++)
169 while (n_zeros < entries) {
170 int steplet =
step >> 8;
179 bits[x ].bit = dominant;
180 bits[x++].count = steplet;
186 if (
step > INT32_MAX*8LL/9 + 1)
189 }
else if (steplet > 0) {
194 if (actual_run > 0) {
195 bits[x ].bit = dominant;
196 bits[x++].count = actual_run;
199 bits[x ].bit = !dominant;
203 n_zeros += actual_run;
212 dominant = !dominant;
219 for (
i = 0; n_zeros < entries;
i++) {
223 if (
pos >= entries) {
225 level += passes << low_bits;
227 if (
bits[x].
bit &&
bits[x].count > entries - n_zeros)
228 passes =
bits[x].count / (entries - n_zeros);
236 buf[
pos] += passes << low_bits;
241 bits[x].count -= passes;
242 x +=
bits[x].count == 0;
248 for (
i = 0;
i < entries;
i++) {
259 return (
a >>
b) + (
a < 0);
264 return a + (1 <<
b - 1) >>
b;
267 #define LATTICE_SHIFT 10
268 #define SAMPLE_SHIFT 4
269 #define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
274 int *k_ptr = &(k[order-2]),
275 *state_ptr = &(
state[order-2]);
277 for (
i = order-2;
i >= 0;
i--, k_ptr--, state_ptr--) {
278 unsigned k_value = *k_ptr, state_value = *state_ptr;
294 for (
int i = order - 2;
i >= 0;
i--) {
297 for (
int j = 0, p =
i + 1; p < order; j++, p++) {
312 int quant, n, buf_size, input_buf_size;
315 if ((!
pkt->
size && !
s->bitstream_size) ||
s->nb_samples == 0) {
320 buf_size =
FFMIN(
pkt->
size,
s->max_framesize -
s->bitstream_size);
321 input_buf_size = buf_size;
323 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
324 s->bitstream_index = 0;
327 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->
data, buf_size);
328 buf = &
s->bitstream[
s->bitstream_index];
329 buf_size +=
s->bitstream_size;
330 s->bitstream_size = buf_size;
331 if (buf_size < s->max_framesize &&
pkt->
data) {
333 return input_buf_size;
347 for (
int i = 0;
i <
s->n_taps;
i++)
348 s->k[
i] *=
s->quant[
i];
353 const int down_sampling =
s->down_sampling;
355 int *
state =
s->state[ch];
363 for (
int j = 0; j <
s->down_sampling - 1; j++) {
373 for (
int i = 0;
i <
s->n_taps;
i++)
379 s->samples[1][
i] +=
shift(
s->samples[0][
i], 1);
380 s->samples[0][
i] -=
s->samples[1][
i];
406 s->bitstream_size = 0;
407 s->bitstream_index = 0;
413 if (
s->bitstream_size) {
414 s->bitstream_index += n;
415 s->bitstream_size -= n;
416 return input_buf_size;
432 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
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t ** extended_data
pointers to the data planes/channels.
#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)
#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)