Go to the documentation of this file.
121 memset(am->
prob[0], 0, (buf_size + 5) *
sizeof(*am->
prob[0]));
122 memset(am->
prob[1], 0, (buf_size + 5) *
sizeof(*am->
prob[1]));
155 if (
s->channels < 1 ||
s->channels > 2)
160 s->frame_samples = 131072 /
s->align;
161 s->last_nb_samples =
s->total_nb_samples %
s->frame_samples;
168 s->ch[0].qfactor =
s->ch[1].qfactor = qfactor < 0 ? 2 : qfactor;
169 s->ch[0].vrq = qfactor < 0 ? -qfactor : 0;
170 s->ch[1].vrq = qfactor < 0 ? -qfactor : 0;
172 s->ch[0].vrq =
av_clip(
s->ch[0].vrq, 1, 8);
173 s->ch[1].vrq =
av_clip(
s->ch[1].vrq, 1, 8);
188 x = (1 << (
bits >> 1)) + 3;
202 int sample_rate,
int bps)
206 memset(
c->buf0, 0,
sizeof(
c->buf0));
207 memset(
c->buf1, 0,
sizeof(
c->buf1));
209 c->filt_size = &
s->filt_size;
210 c->filt_bits = &
s->filt_bits;
212 c->bprob[0] =
s->bprob[0];
213 c->bprob[1] =
s->bprob[1];
215 c->srate_pad = ((
int64_t)sample_rate << 13) / 44100 & 0xFFFFFFFC
U;
219 c->bprob[0][
i] =
c->bprob[1][
i] = 1;
221 for (
int i = 0;
i < 11;
i++) {
250 ac->
high = 0xffffffff;
251 ac->
value = bytestream2_get_be32(&ac->
gb);
260 help = ac->
high / (unsigned)(freq2 + freq1);
265 if (
value - low >= add) {
266 ac->
low = low = add + low;
269 if ((low ^ (
high + low)) > 0xFFFFFF) {
272 ac->
high = (uint16_t)-(int16_t)low;
277 ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
279 low = ac->
low = ac->
low << 8;
286 if ((low ^ (add + low)) > 0xFFFFFF) {
289 ac->
high = (uint16_t)-(int16_t)low;
294 ac->
value = bytestream2_get_byteu(&ac->
gb) | (ac->
value << 8);
296 low = ac->
low = ac->
low << 8;
306 x =
c->bprob[0][idx];
307 if (x +
c->bprob[1][idx] > 4096) {
308 c->bprob[0][idx] = (x >> 1) + 1;
309 c->bprob[1][idx] = (
c->bprob[1][idx] >> 1) + 1;
328 new_high = ac->
high / freq;
347 if (((
high + low) ^ low) > 0xffffff) {
350 ac->
high = (uint16_t)-(int16_t)low;
356 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
357 low = ac->
low = ac->
low << 8;
373 }
while (val < am->buf_size);
390 if ((idx2 & idx) != idx2) {
392 prob_idx -=
prob[idx3];
394 }
while ((idx2 & idx) != idx3);
398 diff = ((prob_idx > 0) - prob_idx) >> 1;
412 unsigned freq, size2,
val, mul;
422 if (am->
total <= 1) {
430 freq = am->
prob[0][0];
431 for (
int j =
size; j > 0; j &= (j - 1) )
432 freq += am->
prob[0][j];
439 for (j = freq -
val; size2; size2 >>= 1) {
440 unsigned v = am->
prob[0][size2 + sum];
455 for (
int k =
val - 1; (
val & (
val - 1)) != k; k &= k - 1)
456 mul -= am->
prob[0][k];
510 if (((idx == 8) || (idx == 20)) && (0 <
bits))
525 dst->coeffs[idx++] = 0;
534 dst->coeffs[idx] = freq + 1 + ((
val - 1
U) <<
bits);
539 dst->coeffs[idx] = -
dst->coeffs[idx];
542 }
while (idx < dst->
size);
555 if (((
high + low) ^ low) > 0xffffff) {
558 ac->
high = (uint16_t)-(int16_t)low;
564 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
566 ac->
low = low = ac->
low << 8;
573 if (((
high + low) ^ low) > 0xffffff) {
576 ac->
high = (uint16_t)-(int16_t)low;
582 ac->
value = (ac->
value << 8) | bytestream2_get_byteu(&ac->
gb);
584 ac->
low = low = ac->
low << 8;
595 if (
ctx->zero[0] +
ctx->zero[1] > 4000
U) {
596 ctx->zero[0] = (
ctx->zero[0] >> 1) + 1;
597 ctx->zero[1] = (
ctx->zero[1] >> 1) + 1;
599 if (
ctx->sign[0] +
ctx->sign[1] > 4000
U) {
600 ctx->sign[0] = (
ctx->sign[0] >> 1) + 1;
601 ctx->sign[1] = (
ctx->sign[1] >> 1) + 1;
608 }
else if (sign < 0) {
623 int hbits =
bits / 2;
635 uint16_t *val4 =
ctx->val4;
638 if (val4[idx] +
ctx->val1[idx] > 2000
U) {
639 val4[idx] = (val4[idx] >> 1) + 1;
640 ctx->val1[idx] = (
ctx->val1[idx] >> 1) + 1;
651 }
while (idx <= ctx->
size);
680 unsigned rsize, idx = 3,
bits = 0, m = 0;
682 if (
ctx->qfactor == 0) {
700 for (
int x = 0; x <
size;) {
705 idx = (
ctx->pos_idx + idx) % 11;
709 for (
int y = 0; y < rsize; y++, off++) {
710 int midx,
shift = idx, *
src, sum = 16;
717 mdl64 = &
ctx->mdl64[3][idx];
718 }
else if (midx >= 7) {
719 mdl64 = &
ctx->mdl64[2][idx];
720 }
else if (midx >= 4) {
721 mdl64 = &
ctx->mdl64[1][idx];
723 mdl64 = &
ctx->mdl64[0][idx];
729 src = &
ctx->buf1[off + -1];
730 for (
int i = 0;
i <
filt.size &&
i < 15;
i++)
731 sum +=
filt.coeffs[
i] * (
unsigned)
src[-
i];
733 for (
int i = 15;
i <
filt.size;
i++)
734 sum +=
filt.coeffs[
i] * (
unsigned)
src[-
i];
736 if (
ctx->qfactor == 0) {
738 ctx->buf1[off] = sum +
val;
741 (((1
U <<
bits) - 1
U) &
ctx->buf1[off + -1]);
743 ctx->buf0[off] =
ctx->buf1[off] + (unsigned)
ctx->buf0[off + -1];
746 sum +=
ctx->buf0[off + -1] + (unsigned)
val;
751 ctx->buf1[off] = sum -
ctx->buf0[off + -1];
752 ctx->buf0[off] = sum;
753 m += (unsigned)
FFABS(
ctx->buf1[off]);
758 for (
unsigned i = (m << 6) / rsize;
i > 0;
i =
i >> 1)
760 sum -= (
ctx->vrq + 7);
773 int segment_size, offset2,
mode,
ret;
789 segment_size =
ctx->srate_pad;
796 offset2 = segment_size / 4 +
offset;
800 offset2 = segment_size / 4 + offset2;
805 offset2 = segment_size / 2 +
offset;
838 memmove(
c->buf0, &
c->buf0[
c->last_nb_decoded], 2560 *
sizeof(*
c->buf0));
839 memmove(
c->buf1, &
c->buf1[
c->last_nb_decoded], 2560 *
sizeof(*
c->buf1));
844 c->last_nb_decoded = nb_decoded;
850 int *got_frame_ptr,
AVPacket *avpkt)
859 for (
int ch = 0; ch <
s->channels; ch++) {
866 frame->nb_samples =
s->frame_samples;
870 if (
s->channels == 2 &&
s->correlated) {
871 int16_t *l16 = (int16_t *)
frame->extended_data[0];
872 int16_t *r16 = (int16_t *)
frame->extended_data[1];
873 uint8_t *l8 =
frame->extended_data[0];
874 uint8_t *r8 =
frame->extended_data[1];
876 for (
int n = 0; n <
frame->nb_samples;) {
879 frame->nb_samples = n;
882 if (ret < 0 || n + ret >
frame->nb_samples)
887 frame->nb_samples = n;
890 if (ret < 0 || n + ret >
frame->nb_samples)
895 for (
int i = 0;
i <
ret;
i++) {
896 int l =
s->ch[0].buf0[2560 +
i];
897 int r =
s->ch[1].buf0[2560 +
i];
899 l16[n +
i] = (l * 2 +
r + 1) >> 1;
900 r16[n +
i] = (l * 2 -
r + 1) >> 1;
904 for (
int i = 0;
i <
ret;
i++) {
905 int l =
s->ch[0].buf0[2560 +
i];
906 int r =
s->ch[1].buf0[2560 +
i];
908 l8[n +
i] = ((l * 2 +
r + 1) >> 1) + 0x7f;
909 r8[n +
i] = ((l * 2 -
r + 1) >> 1) + 0x7f;
919 for (
int n = 0; n <
frame->nb_samples;) {
920 for (
int ch = 0; ch <
s->channels; ch++) {
921 int16_t *m16 = (int16_t *)
frame->data[ch];
922 uint8_t *m8 =
frame->data[ch];
926 frame->nb_samples = n;
930 if (ret < 0 || n + ret >
frame->nb_samples)
935 for (
int i = 0;
i <
ret;
i++) {
936 int m =
s->ch[ch].buf0[2560 +
i];
942 for (
int i = 0;
i <
ret;
i++) {
943 int m =
s->ch[ch].buf0[2560 +
i];
945 m8[n +
i] = m + 0x7f;
957 if (
frame->nb_samples <
s->frame_samples &&
958 frame->nb_samples >
s->last_nb_samples)
959 frame->nb_samples =
s->last_nb_samples;
970 for (
int ch = 0; ch < 2; ch++) {
973 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 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.
int(* init)(AVBSFContext *ctx)
#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)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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 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)