Go to the documentation of this file.
37 #define MAX_CHANNELS 8
38 #define MAX_BLOCKSIZE 65535
40 #define OUT_BUFFER_SIZE 16384
44 #define WAVE_FORMAT_PCM 0x0001
46 #define DEFAULT_BLOCK_SIZE 256
52 #define BITSHIFTSIZE 2
65 #define V2LPCQOFFSET (1 << LPCQUANT)
73 #define FN_BLOCKSIZE 5
82 #define VERBATIM_CKSIZE_SIZE 5
83 #define VERBATIM_BYTE_SIZE 8
84 #define CANONICAL_HEADER_SIZE 44
132 for (chan = 0; chan <
s->channels; chan++) {
137 if (
s->blocksize + (uint64_t)
s->nwrap >= UINT_MAX /
sizeof(
int32_t)) {
139 "s->blocksize + s->nwrap too large\n");
149 sizeof(
s->decoded_base[0][0]))) < 0)
151 for (
i = 0;
i <
s->nwrap;
i++)
152 s->decoded_base[chan][
i] = 0;
153 s->decoded[chan] =
s->decoded_base[chan] +
s->nwrap;
164 if (
s->version != 0) {
176 if (
s->bitshift == 32) {
177 for (
i = 0;
i <
s->blocksize;
i++)
179 }
else if (
s->bitshift != 0) {
180 for (
i = 0;
i <
s->blocksize;
i++)
189 int nblock =
FFMAX(1,
s->nmean);
191 switch (
s->internal_ftype) {
205 for (chan = 0; chan <
s->channels; chan++)
206 for (
i = 0;
i < nblock;
i++)
207 s->offset[chan][
i] =
mean;
222 if (bytestream2_get_le32(&gb) !=
MKTAG(
'F',
'O',
'R',
'M')) {
229 tag = bytestream2_get_le32(&gb);
230 if (
tag !=
MKTAG(
'A',
'I',
'F',
'F') &&
236 while (bytestream2_get_le32(&gb) !=
MKTAG(
'C',
'O',
'M',
'M')) {
237 len = bytestream2_get_be32(&gb);
244 len = bytestream2_get_be32(&gb);
252 bps = bytestream2_get_be16(&gb);
255 s->swap =
tag ==
MKTAG(
'A',
'I',
'F',
'C');
257 if (
bps != 16 &&
bps != 8) {
262 exp = bytestream2_get_be16(&gb) - 16383 - 63;
263 val = bytestream2_get_be64(&gb);
264 if (exp < -63 || exp > 63) {
283 uint16_t wave_format;
288 if (bytestream2_get_le32(&gb) !=
MKTAG(
'R',
'I',
'F',
'F')) {
295 if (bytestream2_get_le32(&gb) !=
MKTAG(
'W',
'A',
'V',
'E')) {
300 while (bytestream2_get_le32(&gb) !=
MKTAG(
'f',
'm',
't',
' ')) {
301 len = bytestream2_get_le32(&gb);
308 len = bytestream2_get_le32(&gb);
315 wave_format = bytestream2_get_le16(&gb);
317 switch (wave_format) {
329 bps = bytestream2_get_le16(&gb);
332 if (
bps != 16 &&
bps != 8) {
352 int residual_size,
int32_t coffset)
354 int pred_order, sum, qshift, init_sum,
i, j;
360 if ((
unsigned)pred_order >
s->nwrap) {
366 for (
i = 0;
i < pred_order;
i++)
385 for (
i = -pred_order;
i < 0;
i++)
386 s->decoded[
channel][
i] -= (
unsigned)coffset;
389 init_sum = pred_order ? (
command ==
FN_QLPC ?
s->lpcqoffset : 0) : coffset;
390 for (
i = 0;
i <
s->blocksize;
i++) {
392 for (j = 0; j < pred_order; j++)
393 sum += coeffs[j] * (
unsigned)
s->decoded[
channel][
i - j - 1];
395 (unsigned)(sum >> qshift);
400 for (
i = 0;
i <
s->blocksize;
i++)
401 s->decoded[
channel][
i] += (
unsigned)coffset;
432 if (
s->avctx->ch_layout.nb_channels !=
s->channels) {
434 s->avctx->ch_layout.nb_channels =
s->channels;
439 if (
s->version > 0) {
446 "invalid or unsupported block size: %d\n",
450 s->blocksize = blocksize;
453 if (maxnlpc > 1024
U) {
458 if (
s->nmean > 32768
U) {
477 if (
s->avctx->extradata_size > 0)
482 "missing verbatim section at beginning of stream\n");
494 for (
i = 0;
i <
s->header_size;
i++)
526 int *got_frame_ptr,
AVPacket *avpkt)
528 const uint8_t *buf = avpkt->
data;
529 int buf_size = avpkt->
size;
531 int i, input_buf_size = 0;
535 if (
s->max_framesize == 0) {
537 s->max_framesize = 8192;
541 s->max_framesize = 0;
545 memset(tmp_ptr, 0,
s->allocated_bitstream_size);
546 s->bitstream = tmp_ptr;
550 buf_size =
FFMIN(buf_size,
s->max_framesize -
s->bitstream_size);
551 input_buf_size = buf_size;
554 s->allocated_bitstream_size) {
555 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
557 s->bitstream_index = 0;
560 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size], buf,
562 buf = &
s->bitstream[
s->bitstream_index];
563 buf_size +=
s->bitstream_size;
564 s->bitstream_size = buf_size;
568 if (buf_size < s->max_framesize && avpkt->
data) {
570 return input_buf_size;
578 if (!
s->got_header) {
587 max_framesize =
FFMAX(
s->max_framesize,
s->blocksize *
s->channels * 8);
594 s->bitstream = tmp_ptr;
595 s->max_framesize = max_framesize;
602 if (
s->got_quit_command) {
608 while (
s->cur_chan <
s->channels) {
645 s->bitshift = bitshift;
650 if (blocksize >
s->blocksize) {
652 "Increasing block size");
657 "block size: %d\n", blocksize);
660 s->blocksize = blocksize;
664 s->got_quit_command = 1;
671 int residual_size = 0;
682 if (residual_size > 30
U) {
692 int32_t sum = (
s->version < 2) ? 0 :
s->nmean / 2;
695 coffset = sum /
s->nmean;
697 coffset =
s->bitshift == 0 ? coffset : coffset >>
s->bitshift - 1 >> 1;
702 for (
i = 0;
i <
s->blocksize;
i++)
706 residual_size, coffset)) < 0)
712 int64_t sum = (
s->version < 2) ? 0 :
s->blocksize / 2;
713 for (
i = 0;
i <
s->blocksize;
i++)
720 s->offset[
channel][
s->nmean - 1] = sum /
s->blocksize;
722 s->offset[
channel][
s->nmean - 1] =
s->bitshift == 32 ? 0 : (sum /
s->blocksize) * (1LL <<
s->bitshift);
726 for (
i = -
s->nwrap;
i < 0;
i++)
735 if (
s->cur_chan ==
s->channels) {
737 int16_t *samples_s16;
745 for (chan = 0; chan <
s->channels; chan++) {
748 for (
i = 0;
i <
s->blocksize;
i++) {
749 switch (
s->internal_ftype) {
759 if (
s->swap &&
s->internal_ftype !=
TYPE_U8)
770 if (
s->cur_chan <
s->channels)
778 s->bitstream_size = 0;
779 s->bitstream_index = 0;
782 if (
s->bitstream_size) {
783 s->bitstream_index +=
i;
784 s->bitstream_size -=
i;
785 return input_buf_size;
795 for (
i = 0;
i <
s->channels;
i++) {
818 AV_CODEC_CAP_SUBFRAMES |
static int get_bits_left(GetBitContext *gb)
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_cold int shorten_decode_init(AVCodecContext *avctx)
int sample_rate
samples per second
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_count(const GetBitContext *s)
static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static const uint8_t is_audio_command[10]
indicates if the FN_* command is audio or non-audio
This structure describes decoded (raw) audio or video data.
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
static int init_offset(ShortenContext *s)
int32_t * offset[MAX_CHANNELS]
uint8_t header[OUT_BUFFER_SIZE]
static void skip_bits(GetBitContext *s, int n)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
static const int fixed_coeffs[][3]
static double val(void *priv, double ch)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
#define FF_CODEC_DECODE_CB(func)
static int allocate_buffers(ShortenContext *s)
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define VERBATIM_BYTE_SIZE
static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
#define CODEC_LONG_NAME(str)
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
const FFCodec ff_shorten_decoder
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.
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.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
int32_t * decoded[MAX_CHANNELS]
#define CANONICAL_HEADER_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static int decode_aiff_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const uint8_t header[24]
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
#define AV_LOG_INFO
Standard information.
static void fix_bitshift(ShortenContext *s, int32_t *buffer)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int32_t * decoded_base[MAX_CHANNELS]
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
const char * name
Name of the codec implementation.
static int get_sr_golomb_shorten(GetBitContext *gb, int k)
read signed golomb rice code (shorten).
static av_cold int shorten_decode_close(AVCodecContext *avctx)
unsigned int allocated_bitstream_size
#define AV_INPUT_BUFFER_PADDING_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static int decode_subframe_lpc(ShortenContext *s, int command, int channel, int residual_size, int32_t coffset)
main external API structure.
#define DEFAULT_BLOCK_SIZE
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static float mean(const float *input, int size)
static int read_header(ShortenContext *s)
This structure stores compressed data.
static unsigned int get_uint(ShortenContext *s, int k)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define VERBATIM_CKSIZE_SIZE
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const av_unused uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
#define MKTAG(a, b, c, d)