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 & 0xFFFFFFFCU;
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;
334 *result = (ac->
value - ac->
low) / new_high;
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;
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;
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];
509 if (((idx == 8) || (idx == 20)) && (0 <
bits))
524 dst->coeffs[idx++] = 0;
533 dst->coeffs[idx] = freq + 1 + ((
val - 1U) <<
bits);
538 dst->coeffs[idx] = -
dst->coeffs[idx];
541 }
while (idx < dst->
size);
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;
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] > 4000U) {
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] > 4000U) {
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] > 2000U) {
638 val4[idx] = (val4[idx] >> 1) + 1;
639 ctx->val1[idx] = (
ctx->val1[idx] >> 1) + 1;
650 }
while (idx <= ctx->
size);
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 (((1U <<
bits) - 1U) &
ctx->buf1[off + -1]);
742 ctx->buf0[off] =
ctx->buf1[off] + (unsigned)
ctx->buf0[off + -1];
744 val *= 1U <<
ctx->qfactor;
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++) {
865 frame->nb_samples =
s->frame_samples;
869 if (
s->channels == 2 &&
s->correlated) {
870 int16_t *l16 = (int16_t *)
frame->extended_data[0];
871 int16_t *r16 = (int16_t *)
frame->extended_data[1];
872 uint8_t *l8 =
frame->extended_data[0];
873 uint8_t *r8 =
frame->extended_data[1];
875 for (
int n = 0; n <
frame->nb_samples;) {
878 frame->nb_samples = n;
881 if (ret < 0 || n + ret >
frame->nb_samples)
886 frame->nb_samples = n;
889 if (ret < 0 || n + ret >
frame->nb_samples)
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;
918 for (
int n = 0; n <
frame->nb_samples;) {
919 for (
int ch = 0; ch <
s->channels; ch++) {
920 int16_t *m16 = (int16_t *)
frame->data[ch];
921 uint8_t *m8 =
frame->data[ch];
925 frame->nb_samples = n;
929 if (ret < 0 || n + ret >
frame->nb_samples)
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;
956 if (
frame->nb_samples <
s->frame_samples &&
957 frame->nb_samples >
s->last_nb_samples)
958 frame->nb_samples =
s->last_nb_samples;
969 for (
int ch = 0; ch < 2; ch++) {
972 for (
int i = 0;
i < 11;
i++)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static char * split(char *message, char delim)
static const int8_t filt[NUMTAPS *2]
const FFCodec ff_rka_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
#define prob(name, subs,...)
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
static int shift(int a, int b)
static int ac_get_freq(ACoder *ac, unsigned freq, int *result)
static int decode_ch_samples(AVCodecContext *avctx, ChContext *c)
static int ac_update(ACoder *ac, int freq, int mul)
static int decode_bool(ACoder *ac, ChContext *c, int idx)
static void adaptive_model_free(AdaptiveModel *am)
static int decode_filter(RKAContext *s, ChContext *ctx, ACoder *ac, int off, unsigned size)
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)
static int mdl64_decode(ACoder *ac, Model64 *ctx, int *dst)
static int ac_decode_bool(ACoder *ac, int freq1, int freq2)
static int decode_filt_coeffs(RKAContext *s, ChContext *ctx, ACoder *ac, FiltCoeffs *dst)
static int ac_dec_bit(ACoder *ac)
static int adaptive_model_init(AdaptiveModel *am, int buf_size)
static av_cold int rka_decode_init(AVCodecContext *avctx)
static void amdl_update_prob(AdaptiveModel *am, int val, int diff)
static void model64_init(Model64 *m, unsigned bits)
static void update_ch_subobj(AdaptiveModel *am)
static const uint8_t vrq_qfactors[8]
static void init_acoder(ACoder *ac)
static int decode_samples(AVCodecContext *avctx, ACoder *ac, ChContext *ctx, int offset)
static av_cold int rka_decode_close(AVCodecContext *avctx)
static int rka_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int32_t buf0[131072+2560]
int32_t buf1[131072+2560]
AdaptiveModel coeff_bits[11]
AdaptiveModel * filt_size
AdaptiveModel nb_segments
AdaptiveModel * filt_bits
uint32_t total_nb_samples
#define av_malloc_array(a, b)
static AVFormatContext * ctx
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)