Go to the documentation of this file.
  120     memset(am->
prob[0], 0, (buf_size + 5) * 
sizeof(*am->
prob[0]));
 
  121     memset(am->
prob[1], 0, (buf_size + 5) * 
sizeof(*am->
prob[1]));
 
  154     if (
s->channels < 1 || 
s->channels > 2)
 
  159     s->frame_samples = 131072 / 
s->align;
 
  160     s->last_nb_samples = 
s->total_nb_samples % 
s->frame_samples;
 
  167     s->ch[0].cmode = 
s->ch[1].cmode = cmode < 0 ? 2 : cmode;
 
  168     s->ch[0].cmode2 = cmode < 0 ? 
FFABS(cmode) : 0;
 
  169     s->ch[1].cmode2 = cmode < 0 ? 
FFABS(cmode) : 0;
 
  183     x = (1 << (
bits >> 1)) + 3;
 
  201     memset(
c->buf0, 0, 
sizeof(
c->buf0));
 
  202     memset(
c->buf1, 0, 
sizeof(
c->buf1));
 
  204     c->filt_size = &
s->filt_size;
 
  205     c->filt_bits = &
s->filt_bits;
 
  207     c->bprob[0] = 
s->bprob[0];
 
  208     c->bprob[1] = 
s->bprob[1];
 
  210     c->srate_pad = (
sample_rate << 13) / 44100 & 0xFFFFFFFCU;
 
  214         c->bprob[0][
i] = 
c->bprob[1][
i] = 1;
 
  216     for (
int i = 0; 
i < 11; 
i++) {
 
  245     ac->
high = 0xffffffff;
 
  246     ac->
value = bytestream2_get_be32(&ac->
gb);
 
  255     help = ac->
high / (unsigned)(freq2 + freq1);
 
  261         ac->
low = low = 
add + low;
 
  264             if ((low ^ (high + low)) > 0xFFFFFF) {
 
  267                 ac->
high = (uint16_t)-(int16_t)low;
 
  272             ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
 
  274             low = ac->
low = ac->
low << 8;
 
  281         if ((low ^ (
add + low)) > 0xFFFFFF) {
 
  284             ac->
high = (uint16_t)-(int16_t)low;
 
  289         ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
 
  291         low = ac->
low = ac->
low << 8;
 
  301     x = 
c->bprob[0][idx];
 
  302     if (x + 
c->bprob[1][idx] > 4096) {
 
  303         c->bprob[0][idx] = (x >> 1) + 1;
 
  304         c->bprob[1][idx] = (
c->bprob[1][idx] >> 1) + 1;
 
  323     new_high = ac->
high / freq;
 
  342         if (((high + low) ^ low) > 0xffffff) {
 
  345             ac->
high = (uint16_t)-(int16_t)low;
 
  351         ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
 
  352         low = ac->
low = ac->
low << 8;
 
  368         } 
while (val < am->buf_size);
 
  385                 if ((idx2 & idx) != idx2) {
 
  387                         prob_idx -= 
prob[idx3];
 
  389                     } 
while ((idx2 & idx) != idx3);
 
  393             diff = ((prob_idx > 0) - prob_idx) >> 1;
 
  407     unsigned freq, size2, 
val, 
mul;
 
  417         if (am->
total <= 1) {
 
  425             freq = am->
prob[0][0];
 
  426             for (
int j = 
size; j > 0; j &= (j - 1) )
 
  427                 freq += am->
prob[0][j];
 
  434             for (j = freq - 
val; size2; size2 >>= 1) {
 
  435                 unsigned v = am->
prob[0][size2 + sum];
 
  450             for (
int k = 
val - 1; (
val & (
val - 1)) != k; k &= k - 1)
 
  462         for (dst[0] = 0; dst[0] < 
size; dst[0]++) {
 
  463             if (!am->
prob[1][dst[0]])
 
  471         for (dst[0] = 0; dst[0] < 
size & freq < 
val; dst[0]++) {
 
  472             if (!am->
prob[1][dst[0]])
 
  476     if (am->
prob[1][dst[0]]) {
 
  482     am->
prob[1][dst[0]]++;
 
  505         if (((idx == 8) || (idx == 20)) && (0 < 
bits))
 
  537     } 
while (idx < dst->
size);
 
  548     if (ac->
value - low < high) {
 
  550             if (((high + low) ^ low) > 0xffffff) {
 
  553                 ac->
high = (uint16_t)-(int16_t)low;
 
  559             ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
 
  561             ac->
low = low = ac->
low << 8;
 
  566     ac->
low = low = low + high;
 
  568         if (((high + low) ^ low) > 0xffffff) {
 
  571             ac->
high = (uint16_t)-(int16_t)low;
 
  577         ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
 
  579         ac->
low = low = ac->
low << 8;
 
  590     if (
ctx->zero[0] + 
ctx->zero[1] > 4000
U) {
 
  591         ctx->zero[0] = (
ctx->zero[0] >> 1) + 1;
 
  592         ctx->zero[1] = (
ctx->zero[1] >> 1) + 1;
 
  594     if (
ctx->sign[0] + 
ctx->sign[1] > 4000
U) {
 
  595         ctx->sign[0] = (
ctx->sign[0] >> 1) + 1;
 
  596         ctx->sign[1] = (
ctx->sign[1] >> 1) + 1;
 
  603     } 
else if (sign < 0) {
 
  618             int hbits = 
bits / 2;
 
  630             uint16_t *val4 = 
ctx->val4;
 
  633             if (val4[idx] + 
ctx->val1[idx] > 2000
U) {
 
  634                 val4[idx] = (val4[idx] >> 1) + 1;
 
  635                 ctx->val1[idx] = (
ctx->val1[idx] >> 1) + 1;
 
  646         } 
while (idx <= ctx->
size);
 
  649             dst[0] = 
val + 1 + (idx << 
ctx->bits);
 
  661     dst[0] = 
val + 1 + (idx << 
ctx->bits);
 
  668 static const uint8_t 
tab[16] = {
 
  669     0, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
 
  677     unsigned idx = 3, 
bits = 0;
 
  679     if (
ctx->cmode == 0) {
 
  697     for (
int x = 0; x < 
size;) {
 
  701         idx = (
ctx->pos_idx + idx) % 11;
 
  705             int midx, 
shift = idx, *
src, sum = 16;
 
  712                 mdl64 = &
ctx->mdl64[3][idx];
 
  713             } 
else if (midx >= 7) {
 
  714                 mdl64 = &
ctx->mdl64[2][idx];
 
  715             } 
else if (midx >= 4) {
 
  716                 mdl64 = &
ctx->mdl64[1][idx];
 
  718                 mdl64 = &
ctx->mdl64[0][idx];
 
  724             src = &
ctx->buf1[off + -1];
 
  725             for (
int i = 0; 
i < 
filt.size && 
i < 15; 
i++)
 
  726                 sum += 
filt.coeffs[
i] * (
unsigned)
src[-
i];
 
  728             for (
int i = 15; 
i < 
filt.size; 
i++)
 
  729                 sum += 
filt.coeffs[
i] * (
unsigned)
src[-
i];
 
  731             if (
ctx->cmode == 0) {
 
  733                     ctx->buf1[off] = sum + 
val;
 
  736                         (((1
U << 
bits) - 1
U) & 
ctx->buf1[off + -1]);
 
  738                 ctx->buf0[off] = 
ctx->buf1[off] + 
ctx->buf0[off + -1];
 
  741                 sum += 
ctx->buf0[off + -1] + 
val;
 
  746                 ctx->buf1[off] = sum - 
ctx->buf0[off + -1];
 
  747                 ctx->buf0[off] = sum;
 
  751         if (
ctx->cmode2 != 0) {
 
  753             for (
int i = (m << 6) / 
split; 
i > 0; 
i = 
i >> 1)
 
  755             sum = sum - (
ctx->cmode2 + 7);
 
  768     int segment_size, offset2, 
mode, 
ret;
 
  784         segment_size = 
ctx->srate_pad;
 
  791                 offset2 = segment_size / 4 + 
offset;
 
  795                 offset2 = segment_size / 4 + offset2;
 
  800                 offset2 = segment_size / 2 + 
offset;
 
  833     memmove(
c->buf0, &
c->buf0[
c->last_nb_decoded], 2560 * 
sizeof(*
c->buf0));
 
  834     memmove(
c->buf1, &
c->buf1[
c->last_nb_decoded], 2560 * 
sizeof(*
c->buf1));
 
  839     c->last_nb_decoded = nb_decoded;
 
  845                             int *got_frame_ptr, 
AVPacket *avpkt)
 
  854     for (
int ch = 0; ch < 
s->channels; ch++) {
 
  861     frame->nb_samples = 
s->frame_samples;
 
  865     if (
s->channels == 2 && 
s->correlated) {
 
  866         int16_t *l16 = (int16_t *)
frame->extended_data[0];
 
  867         int16_t *r16 = (int16_t *)
frame->extended_data[1];
 
  868         uint8_t *l8 = 
frame->extended_data[0];
 
  869         uint8_t *r8 = 
frame->extended_data[1];
 
  871         for (
int n = 0; n < 
frame->nb_samples;) {
 
  874                 frame->nb_samples = n;
 
  877             if (ret < 0 || n + ret > 
frame->nb_samples)
 
  882                 frame->nb_samples = n;
 
  885             if (ret < 0 || n + ret > 
frame->nb_samples)
 
  890                 for (
int i = 0; 
i < 
ret; 
i++) {
 
  891                     int l = 
s->ch[0].buf0[2560 + 
i];
 
  892                     int r = 
s->ch[1].buf0[2560 + 
i];
 
  894                     l16[n + 
i] = (l * 2 + 
r + 1) >> 1;
 
  895                     r16[n + 
i] = (l * 2 - 
r + 1) >> 1;
 
  899                 for (
int i = 0; 
i < 
ret; 
i++) {
 
  900                     int l = 
s->ch[0].buf0[2560 + 
i];
 
  901                     int r = 
s->ch[1].buf0[2560 + 
i];
 
  903                     l8[n + 
i] = ((l * 2 + 
r + 1) >> 1) + 0x7f;
 
  904                     r8[n + 
i] = ((l * 2 - 
r + 1) >> 1) + 0x7f;
 
  914         for (
int n = 0; n < 
frame->nb_samples;) {
 
  915             for (
int ch = 0; ch < 
s->channels; ch++) {
 
  916                 int16_t *m16 = (int16_t *)
frame->data[ch];
 
  917                 uint8_t *m8 = 
frame->data[ch];
 
  921                     frame->nb_samples = n;
 
  925                 if (ret < 0 || n + ret > 
frame->nb_samples)
 
  930                     for (
int i = 0; 
i < 
ret; 
i++) {
 
  931                         int m = 
s->ch[ch].buf0[2560 + 
i];
 
  937                     for (
int i = 0; 
i < 
ret; 
i++) {
 
  938                         int m = 
s->ch[ch].buf0[2560 + 
i];
 
  940                         m8[n + 
i] = m + 0x7f;
 
  961     for (
int ch = 0; ch < 2; ch++) {
 
  964         for (
int i = 0; 
i < 11; 
i++)
 
  
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
int32_t buf1[131072+2560]
int sample_rate
samples per second
static int ac_update(ACoder *ac, int freq, int mul)
This structure describes decoded (raw) audio or video data.
static void adaptive_model_free(AdaptiveModel *am)
int nb_channels
Number of channels in this layout.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
static int decode_filt_coeffs(RKAContext *s, ChContext *ctx, ACoder *ac, FiltCoeffs *dst)
uint32_t total_nb_samples
static double val(void *priv, double ch)
#define FF_ARRAY_ELEMS(a)
static int decode_filter(RKAContext *s, ChContext *ctx, ACoder *ac, int off, unsigned size)
#define FF_CODEC_DECODE_CB(func)
int(* init)(AVBSFContext *ctx)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define CODEC_LONG_NAME(str)
static float mul(float src0, float src1)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int ac_dec_bit(ACoder *ac)
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static void update_ch_subobj(AdaptiveModel *am)
static void init_acoder(ACoder *ac)
int32_t buf0[131072+2560]
static int adaptive_model_init(AdaptiveModel *am, int buf_size)
static void amdl_update_prob(AdaptiveModel *am, int val, int diff)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
static const uint8_t tab[16]
static int decode_bool(ACoder *ac, ChContext *c, int idx)
AdaptiveModel * filt_size
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.
const FFCodec ff_rka_decoder
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
static int shift(int a, int b)
enum AVSampleFormat sample_fmt
audio sample format
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static char * split(char *message, char delim)
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
static int ac_decode_bool(ACoder *ac, int freq1, int freq2)
AdaptiveModel * filt_bits
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
static void model64_init(Model64 *m, unsigned bits)
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int amdl_decode_int(AdaptiveModel *am, ACoder *ac, unsigned *dst, unsigned size)
static int chctx_init(RKAContext *s, ChContext *c, int sample_rate, int bps)
#define av_malloc_array(a, b)
#define xf(width, name, var, range_min, range_max, subs,...)
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.
AdaptiveModel nb_segments
static const int8_t filt[NUMTAPS *2]
AdaptiveModel coeff_bits[11]
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 prob(name, subs,...)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
main external API structure.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
static int ac_get_freq(ACoder *ac, unsigned freq, int *result)
static float add(float src0, float src1)
static int rka_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static int mdl64_decode(ACoder *ac, Model64 *ctx, int *dst)
static av_cold int rka_decode_init(AVCodecContext *avctx)
static av_cold int rka_decode_close(AVCodecContext *avctx)
This structure stores compressed data.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int decode_ch_samples(AVCodecContext *avctx, ChContext *c)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int decode_samples(AVCodecContext *avctx, ACoder *ac, ChContext *ctx, int offset)