FFmpeg
sbcdec.c
Go to the documentation of this file.
1 /*
2  * Bluetooth low-complexity, subband codec (SBC)
3  *
4  * Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
5  * Copyright (C) 2012-2013 Intel Corporation
6  * Copyright (C) 2008-2010 Nokia Corporation
7  * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
8  * Copyright (C) 2004-2005 Henryk Ploetz <henryk@ploetzli.ch>
9  * Copyright (C) 2005-2008 Brad Midgley <bmidgley@xmission.com>
10  *
11  * This file is part of FFmpeg.
12  *
13  * FFmpeg is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * FFmpeg is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with FFmpeg; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  */
27 
28 /**
29  * @file
30  * SBC decoder implementation
31  */
32 
33 #include <stdbool.h>
34 #include "avcodec.h"
35 #include "internal.h"
36 #include "libavutil/intreadwrite.h"
37 #include "sbc.h"
38 #include "sbcdec_data.h"
39 
41  int32_t V[2][170];
42  int offset[2][16];
43 };
44 
45 typedef struct SBCDecContext {
46  AVClass *class;
50 
51 /*
52  * Unpacks a SBC frame at the beginning of the stream in data,
53  * which has at most len bytes into frame.
54  * Returns the length in bytes of the packed frame, or a negative
55  * value on error. The error codes are:
56  *
57  * -1 Data stream too short
58  * -2 Sync byte incorrect
59  * -3 CRC8 incorrect
60  * -4 Bitpool value out of bounds
61  */
62 static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame,
63  size_t len)
64 {
65  unsigned int consumed;
66  /* Will copy the parts of the header that are relevant to crc
67  * calculation here */
68  uint8_t crc_header[11] = { 0 };
69  int crc_pos;
70  int32_t temp;
71 
72  uint32_t audio_sample;
73  int ch, sb, blk, bit; /* channel, subband, block and bit standard
74  counters */
75  int bits[2][8]; /* bits distribution */
76  uint32_t levels[2][8]; /* levels derived from that */
77 
78  if (len < 4)
79  return -1;
80 
81  if (data[0] == MSBC_SYNCWORD) {
82  if (data[1] != 0)
83  return -2;
84  if (data[2] != 0)
85  return -2;
86 
87  frame->frequency = SBC_FREQ_16000;
88  frame->blocks = MSBC_BLOCKS;
89  frame->allocation = LOUDNESS;
90  frame->mode = MONO;
91  frame->channels = 1;
92  frame->subbands = 8;
93  frame->bitpool = 26;
94  } else if (data[0] == SBC_SYNCWORD) {
95  frame->frequency = (data[1] >> 6) & 0x03;
96  frame->blocks = 4 * ((data[1] >> 4) & 0x03) + 4;
97  frame->mode = (data[1] >> 2) & 0x03;
98  frame->channels = frame->mode == MONO ? 1 : 2;
99  frame->allocation = (data[1] >> 1) & 0x01;
100  frame->subbands = data[1] & 0x01 ? 8 : 4;
101  frame->bitpool = data[2];
102 
103  if ((frame->mode == MONO || frame->mode == DUAL_CHANNEL) &&
104  frame->bitpool > 16 * frame->subbands)
105  return -4;
106 
107  if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
108  frame->bitpool > 32 * frame->subbands)
109  return -4;
110  } else
111  return -2;
112 
113  consumed = 32;
114  crc_header[0] = data[1];
115  crc_header[1] = data[2];
116  crc_pos = 16;
117 
118  if (frame->mode == JOINT_STEREO) {
119  if (len * 8 < consumed + frame->subbands)
120  return -1;
121 
122  frame->joint = 0x00;
123  for (sb = 0; sb < frame->subbands - 1; sb++)
124  frame->joint |= ((data[4] >> (7 - sb)) & 0x01) << sb;
125  if (frame->subbands == 4)
126  crc_header[crc_pos / 8] = data[4] & 0xf0;
127  else
128  crc_header[crc_pos / 8] = data[4];
129 
130  consumed += frame->subbands;
131  crc_pos += frame->subbands;
132  }
133 
134  if (len * 8 < consumed + (4 * frame->subbands * frame->channels))
135  return -1;
136 
137  for (ch = 0; ch < frame->channels; ch++) {
138  for (sb = 0; sb < frame->subbands; sb++) {
139  /* FIXME assert(consumed % 4 == 0); */
140  frame->scale_factor[ch][sb] =
141  (data[consumed >> 3] >> (4 - (consumed & 0x7))) & 0x0F;
142  crc_header[crc_pos >> 3] |=
143  frame->scale_factor[ch][sb] << (4 - (crc_pos & 0x7));
144 
145  consumed += 4;
146  crc_pos += 4;
147  }
148  }
149 
150  if (data[3] != ff_sbc_crc8(frame->crc_ctx, crc_header, crc_pos))
151  return -3;
152 
154 
155  for (ch = 0; ch < frame->channels; ch++) {
156  for (sb = 0; sb < frame->subbands; sb++)
157  levels[ch][sb] = (1 << bits[ch][sb]) - 1;
158  }
159 
160  for (blk = 0; blk < frame->blocks; blk++) {
161  for (ch = 0; ch < frame->channels; ch++) {
162  for (sb = 0; sb < frame->subbands; sb++) {
163  uint32_t shift;
164 
165  if (levels[ch][sb] == 0) {
166  frame->sb_sample[blk][ch][sb] = 0;
167  continue;
168  }
169 
170  shift = frame->scale_factor[ch][sb] +
172 
173  audio_sample = 0;
174  for (bit = 0; bit < bits[ch][sb]; bit++) {
175  if (consumed > len * 8)
176  return -1;
177 
178  if ((data[consumed >> 3] >> (7 - (consumed & 0x7))) & 0x01)
179  audio_sample |= 1 << (bits[ch][sb] - bit - 1);
180 
181  consumed++;
182  }
183 
184  frame->sb_sample[blk][ch][sb] = (int32_t)
185  (((((uint64_t) audio_sample << 1) | 1) << shift) /
186  levels[ch][sb]) - (1 << shift);
187  }
188  }
189  }
190 
191  if (frame->mode == JOINT_STEREO) {
192  for (blk = 0; blk < frame->blocks; blk++) {
193  for (sb = 0; sb < frame->subbands; sb++) {
194  if (frame->joint & (0x01 << sb)) {
195  temp = frame->sb_sample[blk][0][sb] +
196  frame->sb_sample[blk][1][sb];
197  frame->sb_sample[blk][1][sb] =
198  frame->sb_sample[blk][0][sb] -
199  frame->sb_sample[blk][1][sb];
200  frame->sb_sample[blk][0][sb] = temp;
201  }
202  }
203  }
204  }
205 
206  if ((consumed & 0x7) != 0)
207  consumed += 8 - (consumed & 0x7);
208 
209  return consumed >> 3;
210 }
211 
212 static inline void sbc_synthesize_four(struct sbc_decoder_state *state,
213  struct sbc_frame *frame,
214  int ch, int blk, AVFrame *output_frame)
215 {
216  int i, k, idx;
217  int32_t *v = state->V[ch];
218  int *offset = state->offset[ch];
219 
220  for (i = 0; i < 8; i++) {
221  /* Shifting */
222  offset[i]--;
223  if (offset[i] < 0) {
224  offset[i] = 79;
225  memcpy(v + 80, v, 9 * sizeof(*v));
226  }
227 
228  /* Distribute the new matrix value to the shifted position */
229  v[offset[i]] =
230  (int)( (unsigned)ff_synmatrix4[i][0] * frame->sb_sample[blk][ch][0] +
231  (unsigned)ff_synmatrix4[i][1] * frame->sb_sample[blk][ch][1] +
232  (unsigned)ff_synmatrix4[i][2] * frame->sb_sample[blk][ch][2] +
233  (unsigned)ff_synmatrix4[i][3] * frame->sb_sample[blk][ch][3] ) >> 15;
234  }
235 
236  /* Compute the samples */
237  for (idx = 0, i = 0; i < 4; i++, idx += 5) {
238  k = (i + 4) & 0xf;
239 
240  /* Store in output, Q0 */
241  AV_WN16A(&output_frame->data[ch][blk * 8 + i * 2], av_clip_int16(
242  (int)( (unsigned)v[offset[i] + 0] * ff_sbc_proto_4_40m0[idx + 0] +
243  (unsigned)v[offset[k] + 1] * ff_sbc_proto_4_40m1[idx + 0] +
244  (unsigned)v[offset[i] + 2] * ff_sbc_proto_4_40m0[idx + 1] +
245  (unsigned)v[offset[k] + 3] * ff_sbc_proto_4_40m1[idx + 1] +
246  (unsigned)v[offset[i] + 4] * ff_sbc_proto_4_40m0[idx + 2] +
247  (unsigned)v[offset[k] + 5] * ff_sbc_proto_4_40m1[idx + 2] +
248  (unsigned)v[offset[i] + 6] * ff_sbc_proto_4_40m0[idx + 3] +
249  (unsigned)v[offset[k] + 7] * ff_sbc_proto_4_40m1[idx + 3] +
250  (unsigned)v[offset[i] + 8] * ff_sbc_proto_4_40m0[idx + 4] +
251  (unsigned)v[offset[k] + 9] * ff_sbc_proto_4_40m1[idx + 4] ) >> 15));
252  }
253 }
254 
255 static inline void sbc_synthesize_eight(struct sbc_decoder_state *state,
256  struct sbc_frame *frame,
257  int ch, int blk, AVFrame *output_frame)
258 {
259  int i, k, idx;
260  int32_t *v = state->V[ch];
261  int *offset = state->offset[ch];
262 
263  for (i = 0; i < 16; i++) {
264  /* Shifting */
265  offset[i]--;
266  if (offset[i] < 0) {
267  offset[i] = 159;
268  memcpy(v + 160, v, 9 * sizeof(*v));
269  }
270 
271  /* Distribute the new matrix value to the shifted position */
272  v[offset[i]] =
273  (int)( (unsigned)ff_synmatrix8[i][0] * frame->sb_sample[blk][ch][0] +
274  (unsigned)ff_synmatrix8[i][1] * frame->sb_sample[blk][ch][1] +
275  (unsigned)ff_synmatrix8[i][2] * frame->sb_sample[blk][ch][2] +
276  (unsigned)ff_synmatrix8[i][3] * frame->sb_sample[blk][ch][3] +
277  (unsigned)ff_synmatrix8[i][4] * frame->sb_sample[blk][ch][4] +
278  (unsigned)ff_synmatrix8[i][5] * frame->sb_sample[blk][ch][5] +
279  (unsigned)ff_synmatrix8[i][6] * frame->sb_sample[blk][ch][6] +
280  (unsigned)ff_synmatrix8[i][7] * frame->sb_sample[blk][ch][7] ) >> 15;
281  }
282 
283  /* Compute the samples */
284  for (idx = 0, i = 0; i < 8; i++, idx += 5) {
285  k = (i + 8) & 0xf;
286 
287  /* Store in output, Q0 */
288  AV_WN16A(&output_frame->data[ch][blk * 16 + i * 2], av_clip_int16(
289  (int)( (unsigned)v[offset[i] + 0] * ff_sbc_proto_8_80m0[idx + 0] +
290  (unsigned)v[offset[k] + 1] * ff_sbc_proto_8_80m1[idx + 0] +
291  (unsigned)v[offset[i] + 2] * ff_sbc_proto_8_80m0[idx + 1] +
292  (unsigned)v[offset[k] + 3] * ff_sbc_proto_8_80m1[idx + 1] +
293  (unsigned)v[offset[i] + 4] * ff_sbc_proto_8_80m0[idx + 2] +
294  (unsigned)v[offset[k] + 5] * ff_sbc_proto_8_80m1[idx + 2] +
295  (unsigned)v[offset[i] + 6] * ff_sbc_proto_8_80m0[idx + 3] +
296  (unsigned)v[offset[k] + 7] * ff_sbc_proto_8_80m1[idx + 3] +
297  (unsigned)v[offset[i] + 8] * ff_sbc_proto_8_80m0[idx + 4] +
298  (unsigned)v[offset[k] + 9] * ff_sbc_proto_8_80m1[idx + 4] ) >> 15));
299  }
300 }
301 
304 {
305  int ch, blk;
306 
307  switch (frame->subbands) {
308  case 4:
309  for (ch = 0; ch < frame->channels; ch++)
310  for (blk = 0; blk < frame->blocks; blk++)
312  break;
313 
314  case 8:
315  for (ch = 0; ch < frame->channels; ch++)
316  for (blk = 0; blk < frame->blocks; blk++)
318  break;
319  }
320 }
321 
322 static int sbc_decode_init(AVCodecContext *avctx)
323 {
324  SBCDecContext *sbc = avctx->priv_data;
325  int i, ch;
326 
328 
329  memset(sbc->dsp.V, 0, sizeof(sbc->dsp.V));
330  for (ch = 0; ch < 2; ch++)
331  for (i = 0; i < FF_ARRAY_ELEMS(sbc->dsp.offset[0]); i++)
332  sbc->dsp.offset[ch][i] = (10 * i + 10);
333  return 0;
334 }
335 
337  void *data, int *got_frame_ptr,
338  AVPacket *avpkt)
339 {
340  SBCDecContext *sbc = avctx->priv_data;
341  AVFrame *frame = data;
342  int ret, frame_length;
343 
344  if (!sbc)
345  return AVERROR(EIO);
346 
347  frame_length = sbc_unpack_frame(avpkt->data, &sbc->frame, avpkt->size);
348  if (frame_length <= 0)
349  return frame_length;
350 
351  avctx->channels =
352  frame->channels = sbc->frame.channels;
353  frame->format = AV_SAMPLE_FMT_S16P;
354  frame->nb_samples = sbc->frame.blocks * sbc->frame.subbands;
355  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
356  return ret;
357 
358  sbc_synthesize_audio(&sbc->dsp, &sbc->frame, frame);
359 
360  *got_frame_ptr = 1;
361 
362  return frame_length;
363 }
364 
366  .name = "sbc",
367  .long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband codec)"),
368  .type = AVMEDIA_TYPE_AUDIO,
369  .id = AV_CODEC_ID_SBC,
370  .priv_data_size = sizeof(SBCDecContext),
373  .capabilities = AV_CODEC_CAP_DR1,
374  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
375  .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
377  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
379  .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
380 };
AVCodec
AVCodec.
Definition: avcodec.h:3481
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
SBCDecContext::frame
struct sbc_frame frame
Definition: sbcdec.c:47
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVERROR
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
AV_CRC_8_EBU
@ AV_CRC_8_EBU
Definition: crc.h:57
MSBC_SYNCWORD
#define MSBC_SYNCWORD
Definition: sbc.h:69
JOINT_STEREO
#define JOINT_STEREO
Definition: atrac3.c:55
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
ch
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 &&1) 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
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
internal.h
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
sbc_decode_init
static int sbc_decode_init(AVCodecContext *avctx)
Definition: sbcdec.c:322
data
const char data[16]
Definition: mxf.c:91
sbc_frame::subbands
uint8_t subbands
Definition: sbc.h:96
SBCDEC_FIXED_EXTRA_BITS
#define SBCDEC_FIXED_EXTRA_BITS
Definition: sbc.h:72
STEREO
#define STEREO
Definition: cook.c:61
sbc_synthesize_eight
static void sbc_synthesize_eight(struct sbc_decoder_state *state, struct sbc_frame *frame, int ch, int blk, AVFrame *output_frame)
Definition: sbcdec.c:255
MSBC_BLOCKS
#define MSBC_BLOCKS
Definition: sbc.h:39
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
sbc_decoder_state::offset
int offset[2][16]
Definition: sbcdec.c:42
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
ff_sbc_proto_4_40m1
const int32_t ff_sbc_proto_4_40m1[]
Definition: sbcdec_data.c:49
AV_CODEC_ID_SBC
@ AV_CODEC_ID_SBC
Definition: avcodec.h:652
state
static struct @313 state
sbc_decoder_state::V
int32_t V[2][170]
Definition: sbcdec.c:41
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
intreadwrite.h
sbc_unpack_frame
static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame, size_t len)
Definition: sbcdec.c:62
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
bits
uint8_t bits
Definition: vp3data.h:202
ff_synmatrix8
const int32_t ff_synmatrix8[16][8]
Definition: sbcdec_data.c:94
ff_synmatrix4
const int32_t ff_synmatrix4[8][4]
Definition: sbcdec_data.c:83
AV_WN16A
#define AV_WN16A(p, v)
Definition: intreadwrite.h:534
SBC_SYNCWORD
#define SBC_SYNCWORD
Definition: sbc.h:68
blk
#define blk(i)
Definition: sha.c:185
ff_sbc_decoder
AVCodec ff_sbc_decoder
Definition: sbcdec.c:365
SBCDecContext
Definition: sbcdec.c:45
int32_t
int32_t
Definition: audio_convert.c:194
SBCDecContext::dsp
struct sbc_decoder_state dsp
Definition: sbcdec.c:48
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
sbc_decode_frame
static int sbc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: sbcdec.c:336
ff_sbc_proto_8_80m1
const int32_t ff_sbc_proto_8_80m1[]
Definition: sbcdec_data.c:70
SBC_ALIGN
#define SBC_ALIGN
Definition: sbc.h:78
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1965
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
AVPacket::size
int size
Definition: avcodec.h:1478
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
sbc_frame::channels
uint8_t channels
Definition: sbc.h:91
sbc_synthesize_audio
static void sbc_synthesize_audio(struct sbc_decoder_state *state, struct sbc_frame *frame, AVFrame *output_frame)
Definition: sbcdec.c:302
ff_sbc_proto_4_40m0
const int32_t ff_sbc_proto_4_40m0[]
Definition: sbcdec_data.c:41
sbcdec_data.h
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
output_frame
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition: h264dec.c:837
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
sbc.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:2226
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:112
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
sbc_frame
Definition: sbc.h:82
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:668
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: avcodec.h:3488
len
int len
Definition: vorbis_enc_data.h:452
ff_sbc_crc8
uint8_t ff_sbc_crc8(const AVCRC *ctx, const uint8_t *data, size_t len)
Definition: sbc.c:55
avcodec.h
sbc_frame::crc_ctx
const AVCRC * crc_ctx
Definition: sbc.h:112
MONO
#define MONO
Definition: cook.c:60
SBC_FREQ_16000
#define SBC_FREQ_16000
Definition: sbc.h:42
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
LOUDNESS
#define LOUDNESS(energy)
Definition: f_ebur128.c:478
sbc_synthesize_four
static void sbc_synthesize_four(struct sbc_decoder_state *state, struct sbc_frame *frame, int ch, int blk, AVFrame *output_frame)
Definition: sbcdec.c:212
sbc_frame::blocks
uint8_t blocks
Definition: sbc.h:84
temp
else temp
Definition: vf_mcdeint.c:256
ff_sbc_calculate_bits
void ff_sbc_calculate_bits(const struct sbc_frame *frame, int(*bits)[8])
Definition: sbc.c:79
shift
static int shift(int a, int b)
Definition: sonic.c:82
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:1592
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:113
ff_sbc_proto_8_80m0
const int32_t ff_sbc_proto_8_80m0[]
Definition: sbcdec_data.c:57
sbc_decoder_state
Definition: sbcdec.c:40
int
int
Definition: ffmpeg_filter.c:191