FFmpeg  4.1.5
dstdec.c
Go to the documentation of this file.
1 /*
2  * Direct Stream Transfer (DST) decoder
3  * Copyright (c) 2014 Peter Ross <pross@xvid.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Direct Stream Transfer (DST) decoder
25  * ISO/IEC 14496-3 Part 3 Subpart 10: Technical description of lossless coding of oversampled audio
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/intreadwrite.h"
30 #include "internal.h"
31 #include "get_bits.h"
32 #include "avcodec.h"
33 #include "golomb.h"
34 #include "mathops.h"
35 #include "dsd.h"
36 
37 #define DST_MAX_CHANNELS 6
38 #define DST_MAX_ELEMENTS (2 * DST_MAX_CHANNELS)
39 
40 #define DSD_FS44(sample_rate) (sample_rate * 8LL / 44100)
41 
42 #define DST_SAMPLES_PER_FRAME(sample_rate) (588 * DSD_FS44(sample_rate))
43 
44 static const int8_t fsets_code_pred_coeff[3][3] = {
45  { -8 },
46  { -16, 8 },
47  { -9, -5, 6 },
48 };
49 
50 static const int8_t probs_code_pred_coeff[3][3] = {
51  { -8 },
52  { -16, 8 },
53  { -24, 24, -8 },
54 };
55 
56 typedef struct ArithCoder {
57  unsigned int a;
58  unsigned int c;
59 } ArithCoder;
60 
61 typedef struct Table {
62  unsigned int elements;
63  unsigned int length[DST_MAX_ELEMENTS];
65 } Table;
66 
67 typedef struct DSTContext {
68  AVClass *class;
69 
72  Table fsets, probs;
74  DECLARE_ALIGNED(16, int16_t, filter)[DST_MAX_ELEMENTS][16][256];
76 } DSTContext;
77 
79 {
80  DSTContext *s = avctx->priv_data;
81  int i;
82 
83  if (avctx->channels > DST_MAX_CHANNELS) {
84  avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
85  return AVERROR_PATCHWELCOME;
86  }
87 
89 
90  for (i = 0; i < avctx->channels; i++)
91  memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
92 
94 
95  return 0;
96 }
97 
98 static int read_map(GetBitContext *gb, Table *t, unsigned int map[DST_MAX_CHANNELS], int channels)
99 {
100  int ch;
101  t->elements = 1;
102  map[0] = 0;
103  if (!get_bits1(gb)) {
104  for (ch = 1; ch < channels; ch++) {
105  int bits = av_log2(t->elements) + 1;
106  map[ch] = get_bits(gb, bits);
107  if (map[ch] == t->elements) {
108  t->elements++;
109  if (t->elements >= DST_MAX_ELEMENTS)
110  return AVERROR_INVALIDDATA;
111  } else if (map[ch] > t->elements) {
112  return AVERROR_INVALIDDATA;
113  }
114  }
115  } else {
116  memset(map, 0, sizeof(*map) * DST_MAX_CHANNELS);
117  }
118  return 0;
119 }
120 
122 {
123  int v = get_ur_golomb_jpegls(gb, k, get_bits_left(gb), 0);
124  if (v && get_bits1(gb))
125  v = -v;
126  return v;
127 }
128 
129 static void read_uncoded_coeff(GetBitContext *gb, int *dst, unsigned int elements,
130  int coeff_bits, int is_signed, int offset)
131 {
132  int i;
133 
134  for (i = 0; i < elements; i++) {
135  dst[i] = (is_signed ? get_sbits(gb, coeff_bits) : get_bits(gb, coeff_bits)) + offset;
136  }
137 }
138 
139 static int read_table(GetBitContext *gb, Table *t, const int8_t code_pred_coeff[3][3],
140  int length_bits, int coeff_bits, int is_signed, int offset)
141 {
142  unsigned int i, j, k;
143  for (i = 0; i < t->elements; i++) {
144  t->length[i] = get_bits(gb, length_bits) + 1;
145  if (!get_bits1(gb)) {
146  read_uncoded_coeff(gb, t->coeff[i], t->length[i], coeff_bits, is_signed, offset);
147  } else {
148  int method = get_bits(gb, 2), lsb_size;
149  if (method == 3)
150  return AVERROR_INVALIDDATA;
151 
152  read_uncoded_coeff(gb, t->coeff[i], method + 1, coeff_bits, is_signed, offset);
153 
154  lsb_size = get_bits(gb, 3);
155  for (j = method + 1; j < t->length[i]; j++) {
156  int c, x = 0;
157  for (k = 0; k < method + 1; k++)
158  x += code_pred_coeff[method][k] * t->coeff[i][j - k - 1];
159  c = get_sr_golomb_dst(gb, lsb_size);
160  if (x >= 0)
161  c -= (x + 4) / 8;
162  else
163  c += (-x + 3) / 8;
164  if (!is_signed) {
165  if (c < offset || c >= offset + (1<<coeff_bits))
166  return AVERROR_INVALIDDATA;
167  }
168  t->coeff[i][j] = c;
169  }
170  }
171  }
172  return 0;
173 }
174 
175 static void ac_init(ArithCoder *ac, GetBitContext *gb)
176 {
177  ac->a = 4095;
178  ac->c = get_bits(gb, 12);
179 }
180 
181 static av_always_inline void ac_get(ArithCoder *ac, GetBitContext *gb, int p, int *e)
182 {
183  unsigned int k = (ac->a >> 8) | ((ac->a >> 7) & 1);
184  unsigned int q = k * p;
185  unsigned int a_q = ac->a - q;
186 
187  *e = ac->c < a_q;
188  if (*e) {
189  ac->a = a_q;
190  } else {
191  ac->a = q;
192  ac->c -= a_q;
193  }
194 
195  if (ac->a < 2048) {
196  int n = 11 - av_log2(ac->a);
197  ac->a <<= n;
198  ac->c = (ac->c << n) | get_bits(gb, n);
199  }
200 }
201 
203 {
204  return (ff_reverse[c & 127] >> 1) + 1;
205 }
206 
207 static void build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
208 {
209  int i, j, k, l;
210 
211  for (i = 0; i < fsets->elements; i++) {
212  int length = fsets->length[i];
213 
214  for (j = 0; j < 16; j++) {
215  int total = av_clip(length - j * 8, 0, 8);
216 
217  for (k = 0; k < 256; k++) {
218  int v = 0;
219 
220  for (l = 0; l < total; l++)
221  v += (((k >> l) & 1) * 2 - 1) * fsets->coeff[i][j * 8 + l];
222  table[i][j][k] = v;
223  }
224  }
225  }
226 }
227 
228 static int decode_frame(AVCodecContext *avctx, void *data,
229  int *got_frame_ptr, AVPacket *avpkt)
230 {
231  unsigned samples_per_frame = DST_SAMPLES_PER_FRAME(avctx->sample_rate);
232  unsigned map_ch_to_felem[DST_MAX_CHANNELS];
233  unsigned map_ch_to_pelem[DST_MAX_CHANNELS];
234  unsigned i, ch, same_map, dst_x_bit;
235  unsigned half_prob[DST_MAX_CHANNELS];
236  const int channels = avctx->channels;
237  DSTContext *s = avctx->priv_data;
238  GetBitContext *gb = &s->gb;
239  ArithCoder *ac = &s->ac;
240  AVFrame *frame = data;
241  uint8_t *dsd;
242  float *pcm;
243  int ret;
244 
245  if (avpkt->size <= 1)
246  return AVERROR_INVALIDDATA;
247 
248  frame->nb_samples = samples_per_frame / 8;
249  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
250  return ret;
251  dsd = frame->data[0];
252  pcm = (float *)frame->data[0];
253 
254  if ((ret = init_get_bits8(gb, avpkt->data, avpkt->size)) < 0)
255  return ret;
256 
257  if (!get_bits1(gb)) {
258  skip_bits1(gb);
259  if (get_bits(gb, 6))
260  return AVERROR_INVALIDDATA;
261  memcpy(frame->data[0], avpkt->data + 1, FFMIN(avpkt->size - 1, frame->nb_samples * avctx->channels));
262  goto dsd;
263  }
264 
265  /* Segmentation (10.4, 10.5, 10.6) */
266 
267  if (!get_bits1(gb)) {
268  avpriv_request_sample(avctx, "Not Same Segmentation");
269  return AVERROR_PATCHWELCOME;
270  }
271 
272  if (!get_bits1(gb)) {
273  avpriv_request_sample(avctx, "Not Same Segmentation For All Channels");
274  return AVERROR_PATCHWELCOME;
275  }
276 
277  if (!get_bits1(gb)) {
278  avpriv_request_sample(avctx, "Not End Of Channel Segmentation");
279  return AVERROR_PATCHWELCOME;
280  }
281 
282  /* Mapping (10.7, 10.8, 10.9) */
283 
284  same_map = get_bits1(gb);
285 
286  if ((ret = read_map(gb, &s->fsets, map_ch_to_felem, avctx->channels)) < 0)
287  return ret;
288 
289  if (same_map) {
290  s->probs.elements = s->fsets.elements;
291  memcpy(map_ch_to_pelem, map_ch_to_felem, sizeof(map_ch_to_felem));
292  } else {
293  avpriv_request_sample(avctx, "Not Same Mapping");
294  if ((ret = read_map(gb, &s->probs, map_ch_to_pelem, avctx->channels)) < 0)
295  return ret;
296  }
297 
298  /* Half Probability (10.10) */
299 
300  for (ch = 0; ch < avctx->channels; ch++)
301  half_prob[ch] = get_bits1(gb);
302 
303  /* Filter Coef Sets (10.12) */
304 
305  ret = read_table(gb, &s->fsets, fsets_code_pred_coeff, 7, 9, 1, 0);
306  if (ret < 0)
307  return ret;
308 
309  /* Probability Tables (10.13) */
310 
311  ret = read_table(gb, &s->probs, probs_code_pred_coeff, 6, 7, 0, 1);
312  if (ret < 0)
313  return ret;
314 
315  /* Arithmetic Coded Data (10.11) */
316 
317  if (get_bits1(gb))
318  return AVERROR_INVALIDDATA;
319  ac_init(ac, gb);
320 
321  build_filter(s->filter, &s->fsets);
322 
323  memset(s->status, 0xAA, sizeof(s->status));
324  memset(dsd, 0, frame->nb_samples * 4 * avctx->channels);
325 
326  ac_get(ac, gb, prob_dst_x_bit(s->fsets.coeff[0][0]), &dst_x_bit);
327 
328  for (i = 0; i < samples_per_frame; i++) {
329  for (ch = 0; ch < channels; ch++) {
330  const unsigned felem = map_ch_to_felem[ch];
331  int16_t (*filter)[256] = s->filter[felem];
332  uint8_t *status = s->status[ch];
333  int prob, residual, v;
334 
335 #define F(x) filter[(x)][status[(x)]]
336  const int16_t predict = F( 0) + F( 1) + F( 2) + F( 3) +
337  F( 4) + F( 5) + F( 6) + F( 7) +
338  F( 8) + F( 9) + F(10) + F(11) +
339  F(12) + F(13) + F(14) + F(15);
340 #undef F
341 
342  if (!half_prob[ch] || i >= s->fsets.length[felem]) {
343  unsigned pelem = map_ch_to_pelem[ch];
344  unsigned index = FFABS(predict) >> 3;
345  prob = s->probs.coeff[pelem][FFMIN(index, s->probs.length[pelem] - 1)];
346  } else {
347  prob = 128;
348  }
349 
350  ac_get(ac, gb, prob, &residual);
351  v = ((predict >> 15) ^ residual) & 1;
352  dsd[((i >> 3) * channels + ch) << 2] |= v << (7 - (i & 0x7 ));
353 
354  AV_WN64A(status + 8, (AV_RN64A(status + 8) << 1) | ((AV_RN64A(status) >> 63) & 1));
355  AV_WN64A(status, (AV_RN64A(status) << 1) | v);
356  }
357  }
358 
359 dsd:
360  for (i = 0; i < avctx->channels; i++) {
361  ff_dsd2pcm_translate(&s->dsdctx[i], frame->nb_samples, 0,
362  frame->data[0] + i * 4,
363  avctx->channels * 4, pcm + i, avctx->channels);
364  }
365 
366  *got_frame_ptr = 1;
367 
368  return avpkt->size;
369 }
370 
372  .name = "dst",
373  .long_name = NULL_IF_CONFIG_SMALL("DST (Digital Stream Transfer)"),
374  .type = AVMEDIA_TYPE_AUDIO,
375  .id = AV_CODEC_ID_DST,
376  .priv_data_size = sizeof(DSTContext),
377  .init = decode_init,
378  .decode = decode_frame,
379  .capabilities = AV_CODEC_CAP_DR1,
380  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
382 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static av_always_inline int get_sr_golomb_dst(GetBitContext *gb, unsigned int k)
Definition: dstdec.c:121
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:381
Definition: dstdec.c:61
unsigned int a
Definition: dstdec.c:57
#define DST_MAX_ELEMENTS
Definition: dstdec.c:38
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
const uint8_t ff_reverse[256]
Definition: reverse.c:23
#define avpriv_request_sample(...)
#define DST_MAX_CHANNELS
Definition: dstdec.c:37
channels
Definition: aptx.c:30
int size
Definition: avcodec.h:1446
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
Table fsets
Definition: dstdec.c:72
static int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len)
read unsigned golomb rice code (jpegls).
Definition: golomb.h:428
av_cold void ff_init_dsd_data(void)
Definition: dsd.c:46
static int read_map(GetBitContext *gb, Table *t, unsigned int map[DST_MAX_CHANNELS], int channels)
Definition: dstdec.c:98
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec.c:174
AVCodec.
Definition: avcodec.h:3424
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:361
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: dstdec.c:228
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:153
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2197
uint8_t
#define av_cold
Definition: attributes.h:82
static const int8_t fsets_code_pred_coeff[3][3]
Definition: dstdec.c:44
static void ac_init(ArithCoder *ac, GetBitContext *gb)
Definition: dstdec.c:175
static AVFrame * frame
const char data[16]
Definition: mxf.c:91
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
uint8_t * data
Definition: avcodec.h:1445
Table probs
Definition: dstdec.c:72
bitstream reader API header.
static const uint16_t table[]
Definition: prosumer.c:206
#define prob(name, subs,...)
Definition: cbs_vp9.c:374
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:814
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
static void read_uncoded_coeff(GetBitContext *gb, int *dst, unsigned int elements, int coeff_bits, int is_signed, int offset)
Definition: dstdec.c:129
int16_t filter[DST_MAX_ELEMENTS][16][256]
Definition: dstdec.c:74
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3431
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
uint64_t residual
Definition: dirac_vlc.h:29
static av_cold int decode_init(AVCodecContext *avctx)
Definition: dstdec.c:78
static const int8_t probs_code_pred_coeff[3][3]
Definition: dstdec.c:50
#define FFMIN(a, b)
Definition: common.h:96
static const ElemCat * elements[ELEMENT_COUNT]
Definition: signature.h:566
ArithCoder ac
Definition: dstdec.c:71
Per-channel buffer.
Definition: dsd.h:42
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
void ff_dsd2pcm_translate(DSDContext *s, size_t samples, int lsbf, const unsigned char *src, ptrdiff_t src_stride, float *dst, ptrdiff_t dst_stride)
Definition: dsd.c:55
int n
Definition: avisynth_c.h:684
unsigned int length[DST_MAX_ELEMENTS]
Definition: dstdec.c:63
AVCodec ff_dst_decoder
Definition: dstdec.c:371
#define AV_WN64A(p, v)
Definition: intreadwrite.h:542
if(ret< 0)
Definition: vf_mcdeint.c:279
#define av_log2
Definition: intmath.h:83
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
unsigned int c
Definition: dstdec.c:58
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int sample_rate
samples per second
Definition: avcodec.h:2189
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:650
static uint8_t prob_dst_x_bit(int c)
Definition: dstdec.c:202
int coeff[DST_MAX_ELEMENTS][128]
Definition: dstdec.c:64
static av_always_inline void ac_get(ArithCoder *ac, GetBitContext *gb, int p, int *e)
Definition: dstdec.c:181
main external API structure.
Definition: avcodec.h:1533
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1918
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:487
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:523
Describe the class of an AVClass context structure.
Definition: log.h:67
int index
Definition: gxfenc.c:89
const VDPAUPixFmtMap * map
unsigned char buf[FIFOSIZE]
Definition: dsd.h:43
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
unsigned int elements
Definition: dstdec.c:62
common internal api header.
static void build_filter(int16_t table[DST_MAX_ELEMENTS][16][256], const Table *fsets)
Definition: dstdec.c:207
uint8_t status[DST_MAX_CHANNELS][16]
Definition: dstdec.c:73
#define DST_SAMPLES_PER_FRAME(sample_rate)
Definition: dstdec.c:42
DSDContext dsdctx[DST_MAX_CHANNELS]
Definition: dstdec.c:75
void * priv_data
Definition: avcodec.h:1560
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)
Definition: dstdec.c:139
int channels
number of audio channels
Definition: avcodec.h:2190
#define F(x)
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define av_always_inline
Definition: attributes.h:39
const char int length
Definition: avisynth_c.h:768
GetBitContext * gb
Definition: mss12.h:53
#define AV_RN64A(p)
Definition: intreadwrite.h:530
exp golomb vlc stuff
This structure stores compressed data.
Definition: avcodec.h:1422
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:292
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:968
GetBitContext gb
Definition: dstdec.c:70