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;
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 - 1
U) <<
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] > 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);
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++) {
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++)
#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
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
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.
static av_cold void close(AVCodecParserContext *s)
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.
static AVFormatContext * ctx
#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
#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
#define i(width, name, range_min, range_max)
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
#define xf(width, name, var, range_min, range_max, subs,...)
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)
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
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)
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)