39#define MAX_BLOCKSIZE 65535
41#define OUT_BUFFER_SIZE 16384
45#define WAVE_FORMAT_PCM 0x0001
47#define DEFAULT_BLOCK_SIZE 256
66#define V2LPCQOFFSET (1 << LPCQUANT)
83#define VERBATIM_CKSIZE_SIZE 5
84#define VERBATIM_BYTE_SIZE 8
85#define CANONICAL_HEADER_SIZE 44
133 for (chan = 0; chan <
s->channels; chan++) {
138 if (
s->blocksize + (uint64_t)
s->nwrap >= UINT_MAX /
sizeof(
int32_t)) {
140 "s->blocksize + s->nwrap too large\n");
150 sizeof(
s->decoded_base[0][0]))) < 0)
152 for (
i = 0;
i <
s->nwrap;
i++)
153 s->decoded_base[chan][
i] = 0;
154 s->decoded[chan] =
s->decoded_base[chan] +
s->nwrap;
165 if (
s->version != 0) {
177 if (
s->bitshift == 32) {
178 for (
i = 0;
i <
s->blocksize;
i++)
180 }
else if (
s->bitshift != 0) {
181 for (
i = 0;
i <
s->blocksize;
i++)
190 int nblock =
FFMAX(1,
s->nmean);
192 switch (
s->internal_ftype) {
206 for (chan = 0; chan <
s->channels; chan++)
207 for (
i = 0;
i < nblock;
i++)
208 s->offset[chan][
i] =
mean;
223 if (bytestream2_get_le32(&gb) !=
MKTAG(
'F',
'O',
'R',
'M')) {
230 tag = bytestream2_get_le32(&gb);
231 if (
tag !=
MKTAG(
'A',
'I',
'F',
'F') &&
237 while (bytestream2_get_le32(&gb) !=
MKTAG(
'C',
'O',
'M',
'M')) {
238 len = bytestream2_get_be32(&gb);
245 len = bytestream2_get_be32(&gb);
253 bps = bytestream2_get_be16(&gb);
256 s->swap =
tag ==
MKTAG(
'A',
'I',
'F',
'C');
258 if (
bps != 16 &&
bps != 8) {
263 exp = bytestream2_get_be16(&gb) - 16383 - 63;
264 val = bytestream2_get_be64(&gb);
284 uint16_t wave_format;
289 if (bytestream2_get_le32(&gb) !=
MKTAG(
'R',
'I',
'F',
'F')) {
296 if (bytestream2_get_le32(&gb) !=
MKTAG(
'W',
'A',
'V',
'E')) {
301 while (bytestream2_get_le32(&gb) !=
MKTAG(
'f',
'm',
't',
' ')) {
302 len = bytestream2_get_le32(&gb);
309 len = bytestream2_get_le32(&gb);
316 wave_format = bytestream2_get_le16(&gb);
318 switch (wave_format) {
330 bps = bytestream2_get_le16(&gb);
333 if (
bps != 16 &&
bps != 8) {
353 int residual_size,
int32_t coffset)
355 int pred_order, sum, qshift, init_sum,
i, j;
361 if ((
unsigned)pred_order >
s->nwrap) {
367 for (
i = 0;
i < pred_order;
i++)
386 for (
i = -pred_order;
i < 0;
i++)
387 s->decoded[
channel][
i] -= (
unsigned)coffset;
390 init_sum = pred_order ? (
command ==
FN_QLPC ?
s->lpcqoffset : 0) : coffset;
391 for (
i = 0;
i <
s->blocksize;
i++) {
393 for (j = 0; j < pred_order; j++)
394 sum += coeffs[j] * (
unsigned)
s->decoded[
channel][
i - j - 1];
396 (unsigned)(sum >> qshift);
401 for (
i = 0;
i <
s->blocksize;
i++)
402 s->decoded[
channel][
i] += (
unsigned)coffset;
433 if (
s->avctx->ch_layout.nb_channels !=
s->channels) {
435 s->avctx->ch_layout.nb_channels =
s->channels;
440 if (
s->version > 0) {
447 "invalid or unsupported block size: %d\n",
451 s->blocksize = blocksize;
454 if (maxnlpc > 1024U) {
459 if (
s->nmean > 32768U) {
478 if (
s->avctx->extradata_size > 0)
483 "missing verbatim section at beginning of stream\n");
495 for (
i = 0;
i <
s->header_size;
i++)
527 int *got_frame_ptr,
AVPacket *avpkt)
529 const uint8_t *buf = avpkt->
data;
530 int buf_size = avpkt->
size;
532 int i, input_buf_size = 0;
536 if (
s->max_framesize == 0) {
538 s->max_framesize = 8192;
542 s->max_framesize = 0;
546 memset(tmp_ptr, 0,
s->allocated_bitstream_size);
547 s->bitstream = tmp_ptr;
551 buf_size =
FFMIN(buf_size,
s->max_framesize -
s->bitstream_size);
552 input_buf_size = buf_size;
555 s->allocated_bitstream_size) {
556 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
558 s->bitstream_index = 0;
561 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size], buf,
563 buf = &
s->bitstream[
s->bitstream_index];
564 buf_size +=
s->bitstream_size;
565 s->bitstream_size = buf_size;
569 if (buf_size < s->max_framesize && avpkt->
data) {
571 return input_buf_size;
579 if (!
s->got_header) {
585 int max_framesize =
s->blocksize *
s->channels * 8;
587 unsigned old_allocated_bitstream_size =
s->allocated_bitstream_size;
594 s->bitstream = tmp_ptr;
595 if (
s->allocated_bitstream_size > old_allocated_bitstream_size)
596 memset(
s->bitstream + old_allocated_bitstream_size, 0,
s->allocated_bitstream_size - old_allocated_bitstream_size);
597 s->max_framesize =
FFMAX(
s->max_framesize, max_framesize);
604 if (
s->got_quit_command) {
610 while (
s->cur_chan <
s->channels) {
647 s->bitshift = bitshift;
652 if (blocksize >
s->blocksize) {
654 "Increasing block size");
659 "block size: %d\n", blocksize);
662 s->blocksize = blocksize;
666 s->got_quit_command = 1;
673 int residual_size = 0;
684 if (residual_size > 30U) {
694 int32_t sum = (
s->version < 2) ? 0 :
s->nmean / 2;
695 for (
i = 0;
i <
s->nmean;
i++)
697 coffset = sum /
s->nmean;
699 coffset =
s->bitshift == 0 ? coffset : coffset >>
s->bitshift - 1 >> 1;
704 for (
i = 0;
i <
s->blocksize;
i++)
708 residual_size, coffset)) < 0)
714 int64_t sum = (
s->version < 2) ? 0 :
s->blocksize / 2;
715 for (
i = 0;
i <
s->blocksize;
i++)
718 for (
i = 1;
i <
s->nmean;
i++)
722 s->offset[
channel][
s->nmean - 1] = sum /
s->blocksize;
724 s->offset[
channel][
s->nmean - 1] =
s->bitshift == 32 ? 0 : (sum /
s->blocksize) * (1LL <<
s->bitshift);
728 for (
i = -
s->nwrap;
i < 0;
i++)
737 if (
s->cur_chan ==
s->channels) {
739 int16_t *samples_s16;
743 frame->nb_samples =
s->blocksize;
747 for (chan = 0; chan <
s->channels; chan++) {
748 samples_u8 = ((uint8_t **)
frame->extended_data)[chan];
749 samples_s16 = ((int16_t **)
frame->extended_data)[chan];
750 for (
i = 0;
i <
s->blocksize;
i++) {
751 switch (
s->internal_ftype) {
761 if (
s->swap &&
s->internal_ftype !=
TYPE_U8)
762 s->bdsp.bswap16_buf(((uint16_t **)
frame->extended_data)[chan],
763 ((uint16_t **)
frame->extended_data)[chan],
772 if (
s->cur_chan <
s->channels)
780 s->bitstream_size = 0;
781 s->bitstream_index = 0;
784 if (
s->bitstream_size) {
785 s->bitstream_index +=
i;
786 s->bitstream_size -=
i;
787 return input_buf_size;
797 for (
i = 0;
i <
s->channels;
i++) {
static double val(void *priv, double ch)
const FFCodec ff_shorten_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)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_unused const uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
channel
Use these values when setting the channel map with ebur128_set_channel().
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_sr_golomb_shorten(GetBitContext *gb, int k)
read signed golomb rice code (shorten).
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#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.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
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
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define MKTAG(a, b, c, d)
Memory handling functions.
static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
static const uint8_t header[24]
static int decode_aiff_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
static int decode_subframe_lpc(ShortenContext *s, int command, int channel, int residual_size, int32_t coffset)
static av_cold int shorten_decode_init(AVCodecContext *avctx)
static int init_offset(ShortenContext *s)
#define VERBATIM_BYTE_SIZE
#define VERBATIM_CKSIZE_SIZE
static int read_header(ShortenContext *s)
static unsigned int get_uint(ShortenContext *s, int k)
static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static int allocate_buffers(ShortenContext *s)
static const int fixed_coeffs[][3]
#define CANONICAL_HEADER_SIZE
#define DEFAULT_BLOCK_SIZE
static const uint8_t is_audio_command[10]
indicates if the FN_* command is audio or non-audio
static void fix_bitshift(ShortenContext *s, int32_t *buffer)
static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
static av_cold int shorten_decode_close(AVCodecContext *avctx)
#define FF_ARRAY_ELEMS(a)
main external API structure.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int32_t * decoded[MAX_CHANNELS]
int32_t * offset[MAX_CHANNELS]
uint8_t header[OUT_BUFFER_SIZE]
int32_t * decoded_base[MAX_CHANNELS]
unsigned int allocated_bitstream_size
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
static float mean(const float *input, int size)