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].qfactor =
s->ch[1].qfactor = qfactor < 0 ? 2 : qfactor;
168 s->ch[0].vrq = qfactor < 0 ? -qfactor : 0;
169 s->ch[1].vrq = qfactor < 0 ? -qfactor : 0;
171 s->ch[0].vrq =
av_clip(
s->ch[0].vrq, 1, 8);
172 s->ch[1].vrq =
av_clip(
s->ch[1].vrq, 1, 8);
187 x = (1 << (
bits >> 1)) + 3;
205 memset(
c->buf0, 0,
sizeof(
c->buf0));
206 memset(
c->buf1, 0,
sizeof(
c->buf1));
208 c->filt_size = &
s->filt_size;
209 c->filt_bits = &
s->filt_bits;
211 c->bprob[0] =
s->bprob[0];
212 c->bprob[1] =
s->bprob[1];
214 c->srate_pad = ((int64_t)
sample_rate << 13) / 44100 & 0xFFFFFFFC
U;
218 c->bprob[0][
i] =
c->bprob[1][
i] = 1;
220 for (
int i = 0;
i < 11;
i++) {
249 ac->
high = 0xffffffff;
250 ac->
value = bytestream2_get_be32(&ac->
gb);
259 help = ac->
high / (unsigned)(freq2 + freq1);
264 if (
value - low >= add) {
265 ac->
low = low = add + low;
268 if ((low ^ (high + low)) > 0xFFFFFF) {
271 ac->
high = (uint16_t)-(int16_t)low;
276 ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
278 low = ac->
low = ac->
low << 8;
285 if ((low ^ (add + low)) > 0xFFFFFF) {
288 ac->
high = (uint16_t)-(int16_t)low;
293 ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
295 low = ac->
low = ac->
low << 8;
305 x =
c->bprob[0][idx];
306 if (x +
c->bprob[1][idx] > 4096) {
307 c->bprob[0][idx] = (x >> 1) + 1;
308 c->bprob[1][idx] = (
c->bprob[1][idx] >> 1) + 1;
327 new_high = ac->
high / freq;
346 if (((high + low) ^ low) > 0xffffff) {
349 ac->
high = (uint16_t)-(int16_t)low;
355 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
356 low = ac->
low = ac->
low << 8;
372 }
while (val < am->buf_size);
389 if ((idx2 & idx) != idx2) {
391 prob_idx -=
prob[idx3];
393 }
while ((idx2 & idx) != idx3);
397 diff = ((prob_idx > 0) - prob_idx) >> 1;
411 unsigned freq, size2,
val, mul;
421 if (am->
total <= 1) {
429 freq = am->
prob[0][0];
430 for (
int j =
size; j > 0; j &= (j - 1) )
431 freq += am->
prob[0][j];
438 for (j = freq -
val; size2; size2 >>= 1) {
439 unsigned v = am->
prob[0][size2 + sum];
454 for (
int k =
val - 1; (
val & (
val - 1)) != k; k &= k - 1)
455 mul -= am->
prob[0][k];
466 for (dst[0] = 0; dst[0] <
size; dst[0]++) {
467 if (!am->
prob[1][dst[0]])
475 for (dst[0] = 0; dst[0] <
size & freq <
val; dst[0]++) {
476 if (!am->
prob[1][dst[0]])
480 if (am->
prob[1][dst[0]]) {
486 am->
prob[1][dst[0]]++;
509 if (((idx == 8) || (idx == 20)) && (0 <
bits))
541 }
while (idx < dst->
size);
552 if (ac->
value - low < high) {
554 if (((high + low) ^ low) > 0xffffff) {
557 ac->
high = (uint16_t)-(int16_t)low;
563 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
565 ac->
low = low = ac->
low << 8;
570 ac->
low = low = low + high;
572 if (((high + low) ^ low) > 0xffffff) {
575 ac->
high = (uint16_t)-(int16_t)low;
581 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
583 ac->
low = low = ac->
low << 8;
594 if (
ctx->zero[0] +
ctx->zero[1] > 4000
U) {
595 ctx->zero[0] = (
ctx->zero[0] >> 1) + 1;
596 ctx->zero[1] = (
ctx->zero[1] >> 1) + 1;
598 if (
ctx->sign[0] +
ctx->sign[1] > 4000
U) {
599 ctx->sign[0] = (
ctx->sign[0] >> 1) + 1;
600 ctx->sign[1] = (
ctx->sign[1] >> 1) + 1;
607 }
else if (sign < 0) {
622 int hbits =
bits / 2;
634 uint16_t *val4 =
ctx->val4;
637 if (val4[idx] +
ctx->val1[idx] > 2000
U) {
638 val4[idx] = (val4[idx] >> 1) + 1;
639 ctx->val1[idx] = (
ctx->val1[idx] >> 1) + 1;
650 }
while (idx <= ctx->
size);
653 dst[0] =
val + 1 + (idx <<
ctx->bits);
665 dst[0] =
val + 1 + (idx <<
ctx->bits);
679 unsigned rsize, idx = 3,
bits = 0, m = 0;
681 if (
ctx->qfactor == 0) {
699 for (
int x = 0; x <
size;) {
704 idx = (
ctx->pos_idx + idx) % 11;
708 for (
int y = 0; y < rsize; y++, off++) {
709 int midx,
shift = idx, *
src, sum = 16;
716 mdl64 = &
ctx->mdl64[3][idx];
717 }
else if (midx >= 7) {
718 mdl64 = &
ctx->mdl64[2][idx];
719 }
else if (midx >= 4) {
720 mdl64 = &
ctx->mdl64[1][idx];
722 mdl64 = &
ctx->mdl64[0][idx];
728 src = &
ctx->buf1[off + -1];
729 for (
int i = 0;
i <
filt.size &&
i < 15;
i++)
730 sum +=
filt.coeffs[
i] * (
unsigned)
src[-
i];
732 for (
int i = 15;
i <
filt.size;
i++)
733 sum +=
filt.coeffs[
i] * (
unsigned)
src[-
i];
735 if (
ctx->qfactor == 0) {
737 ctx->buf1[off] = sum +
val;
740 (((1
U <<
bits) - 1
U) &
ctx->buf1[off + -1]);
742 ctx->buf0[off] =
ctx->buf1[off] + (unsigned)
ctx->buf0[off + -1];
745 sum +=
ctx->buf0[off + -1] + (unsigned)
val;
750 ctx->buf1[off] = sum -
ctx->buf0[off + -1];
751 ctx->buf0[off] = sum;
752 m += (unsigned)
FFABS(
ctx->buf1[off]);
757 for (
unsigned i = (m << 6) / rsize;
i > 0;
i =
i >> 1)
759 sum -= (
ctx->vrq + 7);
772 int segment_size, offset2,
mode,
ret;
788 segment_size =
ctx->srate_pad;
795 offset2 = segment_size / 4 +
offset;
799 offset2 = segment_size / 4 + offset2;
804 offset2 = segment_size / 2 +
offset;
837 memmove(
c->buf0, &
c->buf0[
c->last_nb_decoded], 2560 *
sizeof(*
c->buf0));
838 memmove(
c->buf1, &
c->buf1[
c->last_nb_decoded], 2560 *
sizeof(*
c->buf1));
843 c->last_nb_decoded = nb_decoded;
849 int *got_frame_ptr,
AVPacket *avpkt)
858 for (
int ch = 0; ch <
s->channels; ch++) {
869 if (
s->channels == 2 &&
s->correlated) {
894 for (
int i = 0;
i <
ret;
i++) {
895 int l =
s->ch[0].buf0[2560 +
i];
896 int r =
s->ch[1].buf0[2560 +
i];
898 l16[n +
i] = (l * 2 +
r + 1) >> 1;
899 r16[n +
i] = (l * 2 -
r + 1) >> 1;
903 for (
int i = 0;
i <
ret;
i++) {
904 int l =
s->ch[0].buf0[2560 +
i];
905 int r =
s->ch[1].buf0[2560 +
i];
907 l8[n +
i] = ((l * 2 +
r + 1) >> 1) + 0x7f;
908 r8[n +
i] = ((l * 2 -
r + 1) >> 1) + 0x7f;
919 for (
int ch = 0; ch <
s->channels; ch++) {
920 int16_t *m16 = (int16_t *)
frame->
data[ch];
934 for (
int i = 0;
i <
ret;
i++) {
935 int m =
s->ch[ch].buf0[2560 +
i];
941 for (
int i = 0;
i <
ret;
i++) {
942 int m =
s->ch[ch].buf0[2560 +
i];
944 m8[n +
i] = m + 0x7f;
969 for (
int ch = 0; ch < 2; ch++) {
972 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.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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)
#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 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)
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.
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)
uint8_t ** extended_data
pointers to the data planes/channels.
#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]
#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 const uint8_t vrq_qfactors[8]
static int ac_get_freq(ACoder *ac, unsigned freq, int *result)
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)