41#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
45#define DST_MAX_CHANNELS 6
46#define DST_MAX_ELEMENTS (2 * DST_MAX_CHANNELS)
48#define DSD_FS44(sample_rate) (sample_rate * 8LL / 44100)
50#define DST_SAMPLES_PER_FRAME(sample_rate) (588 * DSD_FS44(sample_rate))
83#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
86 unsigned scratch_size;
109#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
119#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
160 int coeff_bits,
int is_signed,
int offset)
170 int length_bits,
int coeff_bits,
int is_signed,
int offset)
172 unsigned int i, j, k;
178 int method =
get_bits(gb, 2), lsb_size;
185 for (j = method + 1; j < t->
length[
i]; j++) {
187 for (k = 0; k < method + 1; k++)
188 x += code_pred_coeff[method][k] * (
unsigned)t->
coeff[
i][j - k - 1];
213 unsigned int k = (ac->
a >> 8) | ((ac->
a >> 7) & 1);
214 unsigned int q = k * p;
215 unsigned int a_q = ac->
a - q;
244 for (j = 0; j < 16; j++) {
245 int total =
av_clip(length - j * 8, 0, 8);
247 for (k = 0; k < 256; k++) {
250 for (l = 0; l < total; l++)
251 v += (((k >> l) & 1) * 2 - 1) * fsets->
coeff[
i][j * 8 + l];
262 int *got_frame_ptr,
AVPacket *avpkt)
267 unsigned i, ch, same_map, dst_x_bit;
276 if (avpkt->
size <= 1)
279 frame->nb_samples = samples_per_frame / 8;
282 dsd =
frame->data[0];
284#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
302 unsigned n =
FFMIN(avpkt->
size - 1, total);
307 memcpy(dsd, avpkt->
data + 1, n);
308 memset(dsd + n, 0x69, total - n);
337 s->probs.elements =
s->fsets.elements;
338 memcpy(map_ch_to_pelem, map_ch_to_felem,
sizeof(map_ch_to_felem));
372 memset(
s->status, 0xAA,
sizeof(
s->status));
377 for (
i = 0;
i < samples_per_frame;
i++) {
379 const unsigned felem = map_ch_to_felem[ch];
380 int16_t (*
filter)[256] =
s->filter[felem];
381 uint8_t *status =
s->status[ch];
382 int prob, residual, v;
384#define F(x) filter[(x)][status[(x)]]
385 const int16_t
predict =
F( 0) +
F( 1) +
F( 2) +
F( 3) +
386 F( 4) +
F( 5) +
F( 6) +
F( 7) +
387 F( 8) +
F( 9) +
F(10) +
F(11) +
388 F(12) +
F(13) +
F(14) +
F(15);
391 if (!half_prob[ch] ||
i >=
s->fsets.length[felem]) {
392 unsigned pelem = map_ch_to_pelem[ch];
400 v = ((
predict >> 15) ^ residual) & 1;
401 dsd[(
i >> 3) *
channels + ch] |= v << (7 - (
i & 0x7 ));
409#if CONFIG_SWRESAMPLE && FF_API_DSD_PCM
412 (
const uint8_t *
const []){ s->scratch },
414 if (ret !=
frame->nb_samples)
static av_always_inline void predict(PredictorState *ps, int *coef, int output_enable)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_dst_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define prob(name, subs,...)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#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 ff_dsd_to_pcm_init(struct AVCodecContext *avctx, struct SwrContext **swrp)
(Re)create a libswresample context converting AV_SAMPLE_FMT_DSD to avctx->sample_fmt at the same samp...
static void ac_init(ArithCoder *ac, GetBitContext *gb)
static av_always_inline void ac_get(ArithCoder *ac, GetBitContext *gb, int p, int *e)
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static uint8_t prob_dst_x_bit(int c)
static av_cold int decode_close(AVCodecContext *avctx)
static const int8_t fsets_code_pred_coeff[3][3]
static av_cold int decode_init(AVCodecContext *avctx)
static int build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
static void read_uncoded_coeff(GetBitContext *gb, int *dst, unsigned int elements, int coeff_bits, int is_signed, int offset)
static av_always_inline int get_sr_golomb_dst(GetBitContext *gb, unsigned int k)
static int read_table(GetBitContext *gb, Table *t, const int8_t code_pred_coeff[3][3], int length_bits, int coeff_bits, int is_signed, int offset)
static const int8_t probs_code_pred_coeff[3][3]
#define DST_SAMPLES_PER_FRAME(sample_rate)
static int read_map(GetBitContext *gb, Table *t, unsigned int map[DST_MAX_CHANNELS], int channels)
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
bitstream reader API header.
static int get_sbits(GetBitContext *s, int n)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len)
read unsigned golomb rice code (jpegls).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_SAMPLE_FMT_DSD
DSD (Direct Stream Digital) bitstream, interleaved.
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
const VDPAUPixFmtMap * map
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static av_cold int decode_close(AVCodecContext *avctx)
const uint8_t ff_reverse[256]
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const uint16_t table[]
static const ElemCat * elements[ELEMENT_COUNT]
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
enum AVSampleFormat request_sample_fmt
desired sample format
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
uint8_t status[DST_MAX_CHANNELS][16]
int16_t filter[DST_MAX_ELEMENTS][16][256]
The libswresample context.
int coeff[DST_MAX_ELEMENTS][128]
unsigned int length[DST_MAX_ELEMENTS]
libswresample public header
#define avpriv_request_sample(...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)