summaryrefslogtreecommitdiff
path: root/ffmpeg/libavcodec/sonic.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffmpeg/libavcodec/sonic.c')
-rw-r--r--ffmpeg/libavcodec/sonic.c337
1 files changed, 216 insertions, 121 deletions
diff --git a/ffmpeg/libavcodec/sonic.c b/ffmpeg/libavcodec/sonic.c
index fe9f01f..a5e573a 100644
--- a/ffmpeg/libavcodec/sonic.c
+++ b/ffmpeg/libavcodec/sonic.c
@@ -22,6 +22,8 @@
#include "get_bits.h"
#include "golomb.h"
#include "internal.h"
+#include "rangecoder.h"
+
/**
* @file
@@ -45,7 +47,8 @@
#define RIGHT_SIDE 2
typedef struct SonicContext {
- AVFrame frame;
+ int version;
+ int minor_version;
int lossless, decorrelation;
int num_taps, downsampling;
@@ -76,14 +79,6 @@ typedef struct SonicContext {
#define BASE_QUANT 0.6
#define RATE_VARIATION 3.0
-static inline int divide(int a, int b)
-{
- if (a < 0)
- return -( (-a + b/2)/b );
- else
- return (a + b/2)/b;
-}
-
static inline int shift(int a,int b)
{
return (a+(1<<(b-1))) >> b;
@@ -91,10 +86,97 @@ static inline int shift(int a,int b)
static inline int shift_down(int a,int b)
{
- return (a>>b)+((a<0)?1:0);
+ return (a>>b)+(a<0);
+}
+
+static av_always_inline av_flatten void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2]){
+ int i;
+
+#define put_rac(C,S,B) \
+do{\
+ if(rc_stat){\
+ rc_stat[*(S)][B]++;\
+ rc_stat2[(S)-state][B]++;\
+ }\
+ put_rac(C,S,B);\
+}while(0)
+
+ if(v){
+ const int a= FFABS(v);
+ const int e= av_log2(a);
+ put_rac(c, state+0, 0);
+ if(e<=9){
+ for(i=0; i<e; i++){
+ put_rac(c, state+1+i, 1); //1..10
+ }
+ put_rac(c, state+1+i, 0);
+
+ for(i=e-1; i>=0; i--){
+ put_rac(c, state+22+i, (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + e, v < 0); //11..21
+ }else{
+ for(i=0; i<e; i++){
+ put_rac(c, state+1+FFMIN(i,9), 1); //1..10
+ }
+ put_rac(c, state+1+9, 0);
+
+ for(i=e-1; i>=0; i--){
+ put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31
+ }
+
+ if(is_signed)
+ put_rac(c, state+11 + 10, v < 0); //11..21
+ }
+ }else{
+ put_rac(c, state+0, 1);
+ }
+#undef put_rac
+}
+
+static inline av_flatten int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
+ if(get_rac(c, state+0))
+ return 0;
+ else{
+ int i, e, a;
+ e= 0;
+ while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
+ e++;
+ }
+
+ a= 1;
+ for(i=e-1; i>=0; i--){
+ a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
+ }
+
+ e= -(is_signed && get_rac(c, state+11 + FFMIN(e, 10))); //11..21
+ return (a^e)-e;
+ }
}
#if 1
+static inline int intlist_write(RangeCoder *c, uint8_t *state, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ put_symbol(c, state, buf[i], 1, NULL, NULL);
+
+ return 1;
+}
+
+static inline int intlist_read(RangeCoder *c, uint8_t *state, int *buf, int entries, int base_2_part)
+{
+ int i;
+
+ for (i = 0; i < entries; i++)
+ buf[i] = get_symbol(c, state, 1);
+
+ return 1;
+}
+#elif 1
static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
{
int i;
@@ -173,9 +255,9 @@ static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_pa
int step = 256, pos = 0, dominant = 0, any = 0;
int *copy, *bits;
- copy = av_mallocz(4* entries);
+ copy = av_calloc(entries, sizeof(*copy));
if (!copy)
- return -1;
+ return AVERROR(ENOMEM);
if (base_2_part)
{
@@ -199,11 +281,11 @@ static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_pa
max = abs(copy[i]);
}
- bits = av_mallocz(4* entries*max);
+ bits = av_calloc(entries*max, sizeof(*bits));
if (!bits)
{
-// av_free(copy);
- return -1;
+ av_free(copy);
+ return AVERROR(ENOMEM);
}
for (i = 0; i <= max; i++)
@@ -258,8 +340,8 @@ static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_pa
if (buf[i])
put_bits(pb, 1, buf[i] < 0);
-// av_free(bits);
-// av_free(copy);
+ av_free(bits);
+ av_free(copy);
return 0;
}
@@ -269,10 +351,10 @@ static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_par
int i, low_bits = 0, x = 0;
int n_zeros = 0, step = 256, dominant = 0;
int pos = 0, level = 0;
- int *bits = av_mallocz(4* entries);
+ int *bits = av_calloc(entries, sizeof(*bits));
if (!bits)
- return -1;
+ return AVERROR(ENOMEM);
if (base_2_part)
{
@@ -350,7 +432,7 @@ static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_par
pos++;
}
-// av_free(bits);
+ av_free(bits);
// read signs
for (i = 0; i < entries; i++)
@@ -419,7 +501,7 @@ static void modified_levinson_durbin(int *window, int window_entries,
int *out, int out_entries, int channels, int *tap_quant)
{
int i;
- int *state = av_mallocz(4* window_entries);
+ int *state = av_calloc(window_entries, sizeof(*state));
memcpy(state, window, 4* window_entries);
@@ -428,18 +510,21 @@ static void modified_levinson_durbin(int *window, int window_entries,
int step = (i+1)*channels, k, j;
double xx = 0.0, xy = 0.0;
#if 1
- int *x_ptr = &(window[step]), *state_ptr = &(state[0]);
+ int *x_ptr = &(window[step]);
+ int *state_ptr = &(state[0]);
j = window_entries - step;
- for (;j>=0;j--,x_ptr++,state_ptr++)
+ for (;j>0;j--,x_ptr++,state_ptr++)
{
- double x_value = *x_ptr, state_value = *state_ptr;
+ double x_value = *x_ptr;
+ double state_value = *state_ptr;
xx += state_value*state_value;
xy += x_value*state_value;
}
#else
for (j = 0; j <= (window_entries - step); j++);
{
- double stepval = window[step+j], stateval = window[j];
+ double stepval = window[step+j];
+ double stateval = window[j];
// xx += (double)window[j]*(double)window[j];
// xy += (double)window[step+j]*(double)window[j];
xx += stateval*stateval;
@@ -463,16 +548,18 @@ static void modified_levinson_durbin(int *window, int window_entries,
x_ptr = &(window[step]);
state_ptr = &(state[0]);
j = window_entries - step;
- for (;j>=0;j--,x_ptr++,state_ptr++)
+ for (;j>0;j--,x_ptr++,state_ptr++)
{
- int x_value = *x_ptr, state_value = *state_ptr;
+ int x_value = *x_ptr;
+ int state_value = *state_ptr;
*x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
*state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
}
#else
for (j=0; j <= (window_entries - step); j++)
{
- int stepval = window[step+j], stateval=state[j];
+ int stepval = window[step+j];
+ int stateval=state[j];
window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
state[j] += shift_down(k * stepval, LATTICE_SHIFT);
}
@@ -496,23 +583,27 @@ static inline int code_samplerate(int samplerate)
case 16000: return 7;
case 8000: return 8;
}
- return -1;
+ return AVERROR(EINVAL);
}
static av_cold int sonic_encode_init(AVCodecContext *avctx)
{
SonicContext *s = avctx->priv_data;
PutBitContext pb;
- int i, version = 0;
+ int i;
+
+ s->version = 2;
if (avctx->channels > MAX_CHANNELS)
{
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
- return -1; /* only stereo or mono for now */
+ return AVERROR(EINVAL); /* only stereo or mono for now */
}
if (avctx->channels == 2)
s->decorrelation = MID_SIDE;
+ else
+ s->decorrelation = 3;
if (avctx->codec->id == AV_CODEC_ID_SONIC_LS)
{
@@ -529,55 +620,57 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
}
// max tap 2048
- if ((s->num_taps < 32) || (s->num_taps > 1024) ||
- ((s->num_taps>>5)<<5 != s->num_taps))
- {
+ if (s->num_taps < 32 || s->num_taps > 1024 || s->num_taps % 32) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
// generate taps
- s->tap_quant = av_mallocz(4* s->num_taps);
+ s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
for (i = 0; i < s->num_taps; i++)
- s->tap_quant[i] = (int)(sqrt(i+1));
+ s->tap_quant[i] = ff_sqrt(i+1);
s->channels = avctx->channels;
s->samplerate = avctx->sample_rate;
- s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
+ s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
s->frame_size = s->channels*s->block_align*s->downsampling;
s->tail_size = s->num_taps*s->channels;
- s->tail = av_mallocz(4 * s->tail_size);
+ s->tail = av_calloc(s->tail_size, sizeof(*s->tail));
if (!s->tail)
- return -1;
+ return AVERROR(ENOMEM);
- s->predictor_k = av_mallocz(4 * s->num_taps);
+ s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k) );
if (!s->predictor_k)
- return -1;
+ return AVERROR(ENOMEM);
for (i = 0; i < s->channels; i++)
{
- s->coded_samples[i] = av_mallocz(4* s->block_align);
+ s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
if (!s->coded_samples[i])
- return -1;
+ return AVERROR(ENOMEM);
}
- s->int_samples = av_mallocz(4* s->frame_size);
+ s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
s->window_size = ((2*s->tail_size)+s->frame_size);
- s->window = av_mallocz(4* s->window_size);
+ s->window = av_calloc(s->window_size, sizeof(*s->window));
if (!s->window)
- return -1;
+ return AVERROR(ENOMEM);
avctx->extradata = av_mallocz(16);
if (!avctx->extradata)
- return -1;
+ return AVERROR(ENOMEM);
init_put_bits(&pb, avctx->extradata, 16*8);
- put_bits(&pb, 2, version); // version
- if (version == 1)
+ put_bits(&pb, 2, s->version); // version
+ if (s->version >= 1)
{
+ if (s->version >= 2) {
+ put_bits(&pb, 8, s->version);
+ put_bits(&pb, 8, s->minor_version);
+ }
put_bits(&pb, 2, s->channels);
put_bits(&pb, 4, code_samplerate(s->samplerate));
}
@@ -592,13 +685,9 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
flush_put_bits(&pb);
avctx->extradata_size = put_bits_count(&pb)/8;
- av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
- version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d.%d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ s->version, s->minor_version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
- avctx->coded_frame = avcodec_alloc_frame();
- if (!avctx->coded_frame)
- return AVERROR(ENOMEM);
- avctx->coded_frame->key_frame = 1;
avctx->frame_size = s->block_align*s->downsampling;
return 0;
@@ -609,16 +698,14 @@ static av_cold int sonic_encode_close(AVCodecContext *avctx)
SonicContext *s = avctx->priv_data;
int i;
- av_freep(&avctx->coded_frame);
-
for (i = 0; i < s->channels; i++)
- av_free(s->coded_samples[i]);
+ av_freep(&s->coded_samples[i]);
- av_free(s->predictor_k);
- av_free(s->tail);
- av_free(s->tap_quant);
- av_free(s->window);
- av_free(s->int_samples);
+ av_freep(&s->predictor_k);
+ av_freep(&s->tail);
+ av_freep(&s->tap_quant);
+ av_freep(&s->window);
+ av_freep(&s->int_samples);
return 0;
}
@@ -627,15 +714,18 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
SonicContext *s = avctx->priv_data;
- PutBitContext pb;
+ RangeCoder c;
int i, j, ch, quant = 0, x = 0;
int ret;
const short *samples = (const int16_t*)frame->data[0];
+ uint8_t state[32];
if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
return ret;
- init_put_bits(&pb, avpkt->data, avpkt->size);
+ ff_init_range_encoder(&c, avpkt->data, avpkt->size);
+ ff_build_rac_states(&c, 0.05*(1LL<<32), 256-8);
+ memset(state, 128, sizeof(state));
// short -> internal
for (i = 0; i < s->frame_size; i++)
@@ -681,8 +771,8 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
// generate taps
modified_levinson_durbin(s->window, s->window_size,
s->predictor_k, s->num_taps, s->channels, s->tap_quant);
- if (intlist_write(&pb, s->predictor_k, s->num_taps, 0) < 0)
- return -1;
+ if ((ret = intlist_write(&c, state, s->predictor_k, s->num_taps, 0)) < 0)
+ return ret;
for (ch = 0; ch < s->channels; ch++)
{
@@ -711,7 +801,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
energy2 = sqrt(energy2/(s->channels*s->block_align));
- energy1 = sqrt(2.0)*energy1/(s->channels*s->block_align);
+ energy1 = M_SQRT2*energy1/(s->channels*s->block_align);
// increase bitrate when samples are like a gaussian distribution
// reduce bitrate when samples are like a two-tailed exponential distribution
@@ -722,12 +812,9 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
// av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
- if (quant < 1)
- quant = 1;
- if (quant > 65534)
- quant = 65534;
+ quant = av_clip(quant, 1, 65534);
- set_ue_golomb(&pb, quant);
+ put_symbol(&c, state, quant, 0, NULL, NULL);
quant *= SAMPLE_FACTOR;
}
@@ -737,18 +824,18 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
{
if (!s->lossless)
for (i = 0; i < s->block_align; i++)
- s->coded_samples[ch][i] = divide(s->coded_samples[ch][i], quant);
+ s->coded_samples[ch][i] = ROUNDED_DIV(s->coded_samples[ch][i], quant);
- if (intlist_write(&pb, s->coded_samples[ch], s->block_align, 1) < 0)
- return -1;
+ if ((ret = intlist_write(&c, state, s->coded_samples[ch], s->block_align, 1)) < 0)
+ return ret;
}
// av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
- flush_put_bits(&pb);
- avpkt->size = (put_bits_count(&pb)+7)/8;
+ avpkt->size = ff_rac_terminate(&c);
*got_packet_ptr = 1;
return 0;
+
}
#endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
@@ -760,30 +847,31 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
{
SonicContext *s = avctx->priv_data;
GetBitContext gb;
- int i, version;
+ int i;
s->channels = avctx->channels;
s->samplerate = avctx->sample_rate;
- avcodec_get_frame_defaults(&s->frame);
- avctx->coded_frame = &s->frame;
-
if (!avctx->extradata)
{
av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
- init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
+ init_get_bits8(&gb, avctx->extradata, avctx->extradata_size);
- version = get_bits(&gb, 2);
- if (version > 1)
+ s->version = get_bits(&gb, 2);
+ if (s->version >= 2) {
+ s->version = get_bits(&gb, 8);
+ s->minor_version = get_bits(&gb, 8);
+ }
+ if (s->version != 2)
{
av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
- if (version == 1)
+ if (s->version >= 1)
{
s->channels = get_bits(&gb, 2);
s->samplerate = samplerate_table[get_bits(&gb, 4)];
@@ -794,13 +882,17 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
if (s->channels > MAX_CHANNELS)
{
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->lossless = get_bits1(&gb);
if (!s->lossless)
skip_bits(&gb, 3); // XXX FIXME
s->decorrelation = get_bits(&gb, 2);
+ if (s->decorrelation != 3 && s->channels != 2) {
+ av_log(avctx, AV_LOG_ERROR, "invalid decorrelation %d\n", s->decorrelation);
+ return AVERROR_INVALIDDATA;
+ }
s->downsampling = get_bits(&gb, 2);
if (!s->downsampling) {
@@ -812,34 +904,34 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
if (get_bits1(&gb)) // XXX FIXME
av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
- s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
+ s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
s->frame_size = s->channels*s->block_align*s->downsampling;
// avctx->frame_size = s->block_align;
- av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
- version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
+ av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d.%d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
+ s->version, s->minor_version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
// generate taps
- s->tap_quant = av_mallocz(4* s->num_taps);
+ s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
for (i = 0; i < s->num_taps; i++)
- s->tap_quant[i] = (int)(sqrt(i+1));
+ s->tap_quant[i] = ff_sqrt(i+1);
- s->predictor_k = av_mallocz(4* s->num_taps);
+ s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k));
for (i = 0; i < s->channels; i++)
{
- s->predictor_state[i] = av_mallocz(4* s->num_taps);
+ s->predictor_state[i] = av_calloc(s->num_taps, sizeof(**s->predictor_state));
if (!s->predictor_state[i])
- return -1;
+ return AVERROR(ENOMEM);
}
for (i = 0; i < s->channels; i++)
{
- s->coded_samples[i] = av_mallocz(4* s->block_align);
+ s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
if (!s->coded_samples[i])
- return -1;
+ return AVERROR(ENOMEM);
}
- s->int_samples = av_mallocz(4* s->frame_size);
+ s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
@@ -850,14 +942,14 @@ static av_cold int sonic_decode_close(AVCodecContext *avctx)
SonicContext *s = avctx->priv_data;
int i;
- av_free(s->int_samples);
- av_free(s->tap_quant);
- av_free(s->predictor_k);
+ av_freep(&s->int_samples);
+ av_freep(&s->tap_quant);
+ av_freep(&s->predictor_k);
for (i = 0; i < s->channels; i++)
{
- av_free(s->predictor_state[i]);
- av_free(s->coded_samples[i]);
+ av_freep(&s->predictor_state[i]);
+ av_freep(&s->coded_samples[i]);
}
return 0;
@@ -870,22 +962,26 @@ static int sonic_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
SonicContext *s = avctx->priv_data;
- GetBitContext gb;
+ RangeCoder c;
+ uint8_t state[32];
int i, quant, ch, j, ret;
int16_t *samples;
+ AVFrame *frame = data;
if (buf_size == 0) return 0;
- s->frame.nb_samples = s->frame_size;
- if ((ret = ff_get_buffer(avctx, &s->frame, 0)) < 0)
+ frame->nb_samples = s->frame_size / avctx->channels;
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- samples = (int16_t *)s->frame.data[0];
+ samples = (int16_t *)frame->data[0];
// av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
- init_get_bits(&gb, buf, buf_size*8);
+ memset(state, 128, sizeof(state));
+ ff_init_range_decoder(&c, buf, buf_size);
+ ff_build_rac_states(&c, 0.05*(1LL<<32), 256-8);
- intlist_read(&gb, s->predictor_k, s->num_taps, 0);
+ intlist_read(&c, state, s->predictor_k, s->num_taps, 0);
// dequantize
for (i = 0; i < s->num_taps; i++)
@@ -894,7 +990,7 @@ static int sonic_decode_frame(AVCodecContext *avctx,
if (s->lossless)
quant = 1;
else
- quant = get_ue_golomb(&gb) * SAMPLE_FACTOR;
+ quant = get_symbol(&c, state, 0) * SAMPLE_FACTOR;
// av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
@@ -904,7 +1000,7 @@ static int sonic_decode_frame(AVCodecContext *avctx,
predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
- intlist_read(&gb, s->coded_samples[ch], s->block_align, 1);
+ intlist_read(&c, state, s->coded_samples[ch], s->block_align, 1);
for (i = 0; i < s->block_align; i++)
{
@@ -949,16 +1045,14 @@ static int sonic_decode_frame(AVCodecContext *avctx,
for (i = 0; i < s->frame_size; i++)
samples[i] = av_clip_int16(s->int_samples[i]);
- align_get_bits(&gb);
-
*got_frame_ptr = 1;
- *(AVFrame*)data = s->frame;
- return (get_bits_count(&gb)+7)/8;
+ return buf_size;
}
AVCodec ff_sonic_decoder = {
.name = "sonic",
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_SONIC,
.priv_data_size = sizeof(SonicContext),
@@ -966,34 +1060,35 @@ AVCodec ff_sonic_decoder = {
.close = sonic_decode_close,
.decode = sonic_decode_frame,
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_EXPERIMENTAL,
- .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
};
#endif /* CONFIG_SONIC_DECODER */
#if CONFIG_SONIC_ENCODER
AVCodec ff_sonic_encoder = {
.name = "sonic",
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_SONIC,
.priv_data_size = sizeof(SonicContext),
.init = sonic_encode_init,
.encode2 = sonic_encode_frame,
+ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
.capabilities = CODEC_CAP_EXPERIMENTAL,
.close = sonic_encode_close,
- .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
};
#endif
#if CONFIG_SONIC_LS_ENCODER
AVCodec ff_sonic_ls_encoder = {
.name = "sonicls",
+ .long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_SONIC_LS,
.priv_data_size = sizeof(SonicContext),
.init = sonic_encode_init,
.encode2 = sonic_encode_frame,
+ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
.capabilities = CODEC_CAP_EXPERIMENTAL,
.close = sonic_encode_close,
- .long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
};
#endif