FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
opusdec.c
Go to the documentation of this file.
1 /*
2  * Opus decoder
3  * Copyright (c) 2012 Andrew D'Addesio
4  * Copyright (c) 2013-2014 Mozilla Corporation
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * Opus decoder
26  * @author Andrew D'Addesio, Anton Khirnov
27  *
28  * Codec homepage: http://opus-codec.org/
29  * Specification: http://tools.ietf.org/html/rfc6716
30  * Ogg Opus specification: https://tools.ietf.org/html/draft-ietf-codec-oggopus-03
31  *
32  * Ogg-contained .opus files can be produced with opus-tools:
33  * http://git.xiph.org/?p=opus-tools.git
34  */
35 
36 #include <stdint.h>
37 
38 #include "libavutil/attributes.h"
39 #include "libavutil/audio_fifo.h"
41 #include "libavutil/opt.h"
42 
44 
45 #include "avcodec.h"
46 #include "get_bits.h"
47 #include "internal.h"
48 #include "mathops.h"
49 #include "opus.h"
50 #include "opustab.h"
51 #include "opus_celt.h"
52 
53 static const uint16_t silk_frame_duration_ms[16] = {
54  10, 20, 40, 60,
55  10, 20, 40, 60,
56  10, 20, 40, 60,
57  10, 20,
58  10, 20,
59 };
60 
61 /* number of samples of silence to feed to the resampler
62  * at the beginning */
63 static const int silk_resample_delay[] = {
64  4, 8, 11, 11, 11
65 };
66 
67 static int get_silk_samplerate(int config)
68 {
69  if (config < 4)
70  return 8000;
71  else if (config < 8)
72  return 12000;
73  return 16000;
74 }
75 
76 static void opus_fade(float *out,
77  const float *in1, const float *in2,
78  const float *window, int len)
79 {
80  int i;
81  for (i = 0; i < len; i++)
82  out[i] = in2[i] * window[i] + in1[i] * (1.0 - window[i]);
83 }
84 
85 static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
86 {
87  int celt_size = av_audio_fifo_size(s->celt_delay);
88  int ret, i;
89  ret = swr_convert(s->swr,
90  (uint8_t**)s->out, nb_samples,
91  NULL, 0);
92  if (ret < 0)
93  return ret;
94  else if (ret != nb_samples) {
95  av_log(s->avctx, AV_LOG_ERROR, "Wrong number of flushed samples: %d\n",
96  ret);
97  return AVERROR_BUG;
98  }
99 
100  if (celt_size) {
101  if (celt_size != nb_samples) {
102  av_log(s->avctx, AV_LOG_ERROR, "Wrong number of CELT delay samples.\n");
103  return AVERROR_BUG;
104  }
105  av_audio_fifo_read(s->celt_delay, (void**)s->celt_output, nb_samples);
106  for (i = 0; i < s->output_channels; i++) {
107  s->fdsp->vector_fmac_scalar(s->out[i],
108  s->celt_output[i], 1.0,
109  nb_samples);
110  }
111  }
112 
113  if (s->redundancy_idx) {
114  for (i = 0; i < s->output_channels; i++)
115  opus_fade(s->out[i], s->out[i],
116  s->redundancy_output[i] + 120 + s->redundancy_idx,
118  s->redundancy_idx = 0;
119  }
120 
121  s->out[0] += nb_samples;
122  s->out[1] += nb_samples;
123  s->out_size -= nb_samples * sizeof(float);
124 
125  return 0;
126 }
127 
129 {
130  static const float delay[16] = { 0.0 };
131  const uint8_t *delayptr[2] = { (uint8_t*)delay, (uint8_t*)delay };
132  int ret;
133 
134  av_opt_set_int(s->swr, "in_sample_rate", s->silk_samplerate, 0);
135  ret = swr_init(s->swr);
136  if (ret < 0) {
137  av_log(s->avctx, AV_LOG_ERROR, "Error opening the resampler.\n");
138  return ret;
139  }
140 
141  ret = swr_convert(s->swr,
142  NULL, 0,
143  delayptr, silk_resample_delay[s->packet.bandwidth]);
144  if (ret < 0) {
146  "Error feeding initial silence to the resampler.\n");
147  return ret;
148  }
149 
150  return 0;
151 }
152 
154 {
155  int ret;
156  enum OpusBandwidth bw = s->packet.bandwidth;
157 
158  if (s->packet.mode == OPUS_MODE_SILK &&
161 
162  ret = ff_opus_rc_dec_init(&s->redundancy_rc, data, size);
163  if (ret < 0)
164  goto fail;
165  ff_opus_rc_dec_raw_init(&s->redundancy_rc, data + size, size);
166 
169  s->packet.stereo + 1, 240,
171  if (ret < 0)
172  goto fail;
173 
174  return 0;
175 fail:
176  av_log(s->avctx, AV_LOG_ERROR, "Error decoding the redundancy frame.\n");
177  return ret;
178 }
179 
181 {
182  int samples = s->packet.frame_duration;
183  int redundancy = 0;
184  int redundancy_size, redundancy_pos;
185  int ret, i, consumed;
186  int delayed_samples = s->delayed_samples;
187 
188  ret = ff_opus_rc_dec_init(&s->rc, data, size);
189  if (ret < 0)
190  return ret;
191 
192  /* decode the silk frame */
193  if (s->packet.mode == OPUS_MODE_SILK || s->packet.mode == OPUS_MODE_HYBRID) {
194  if (!swr_is_initialized(s->swr)) {
195  ret = opus_init_resample(s);
196  if (ret < 0)
197  return ret;
198  }
199 
200  samples = ff_silk_decode_superframe(s->silk, &s->rc, s->silk_output,
202  s->packet.stereo + 1,
204  if (samples < 0) {
205  av_log(s->avctx, AV_LOG_ERROR, "Error decoding a SILK frame.\n");
206  return samples;
207  }
208  samples = swr_convert(s->swr,
209  (uint8_t**)s->out, s->packet.frame_duration,
210  (const uint8_t**)s->silk_output, samples);
211  if (samples < 0) {
212  av_log(s->avctx, AV_LOG_ERROR, "Error resampling SILK data.\n");
213  return samples;
214  }
215  av_assert2((samples & 7) == 0);
216  s->delayed_samples += s->packet.frame_duration - samples;
217  } else
218  ff_silk_flush(s->silk);
219 
220  // decode redundancy information
221  consumed = opus_rc_tell(&s->rc);
222  if (s->packet.mode == OPUS_MODE_HYBRID && consumed + 37 <= size * 8)
223  redundancy = ff_opus_rc_dec_log(&s->rc, 12);
224  else if (s->packet.mode == OPUS_MODE_SILK && consumed + 17 <= size * 8)
225  redundancy = 1;
226 
227  if (redundancy) {
228  redundancy_pos = ff_opus_rc_dec_log(&s->rc, 1);
229 
230  if (s->packet.mode == OPUS_MODE_HYBRID)
231  redundancy_size = ff_opus_rc_dec_uint(&s->rc, 256) + 2;
232  else
233  redundancy_size = size - (consumed + 7) / 8;
234  size -= redundancy_size;
235  if (size < 0) {
236  av_log(s->avctx, AV_LOG_ERROR, "Invalid redundancy frame size.\n");
237  return AVERROR_INVALIDDATA;
238  }
239 
240  if (redundancy_pos) {
241  ret = opus_decode_redundancy(s, data + size, redundancy_size);
242  if (ret < 0)
243  return ret;
244  ff_celt_flush(s->celt);
245  }
246  }
247 
248  /* decode the CELT frame */
249  if (s->packet.mode == OPUS_MODE_CELT || s->packet.mode == OPUS_MODE_HYBRID) {
250  float *out_tmp[2] = { s->out[0], s->out[1] };
251  float **dst = (s->packet.mode == OPUS_MODE_CELT) ?
252  out_tmp : s->celt_output;
253  int celt_output_samples = samples;
254  int delay_samples = av_audio_fifo_size(s->celt_delay);
255 
256  if (delay_samples) {
257  if (s->packet.mode == OPUS_MODE_HYBRID) {
258  av_audio_fifo_read(s->celt_delay, (void**)s->celt_output, delay_samples);
259 
260  for (i = 0; i < s->output_channels; i++) {
261  s->fdsp->vector_fmac_scalar(out_tmp[i], s->celt_output[i], 1.0,
262  delay_samples);
263  out_tmp[i] += delay_samples;
264  }
265  celt_output_samples -= delay_samples;
266  } else {
268  "Spurious CELT delay samples present.\n");
269  av_audio_fifo_drain(s->celt_delay, delay_samples);
271  return AVERROR_BUG;
272  }
273  }
274 
275  ff_opus_rc_dec_raw_init(&s->rc, data + size, size);
276 
277  ret = ff_celt_decode_frame(s->celt, &s->rc, dst,
278  s->packet.stereo + 1,
280  (s->packet.mode == OPUS_MODE_HYBRID) ? 17 : 0,
282  if (ret < 0)
283  return ret;
284 
285  if (s->packet.mode == OPUS_MODE_HYBRID) {
286  int celt_delay = s->packet.frame_duration - celt_output_samples;
287  void *delaybuf[2] = { s->celt_output[0] + celt_output_samples,
288  s->celt_output[1] + celt_output_samples };
289 
290  for (i = 0; i < s->output_channels; i++) {
291  s->fdsp->vector_fmac_scalar(out_tmp[i],
292  s->celt_output[i], 1.0,
293  celt_output_samples);
294  }
295 
296  ret = av_audio_fifo_write(s->celt_delay, delaybuf, celt_delay);
297  if (ret < 0)
298  return ret;
299  }
300  } else
301  ff_celt_flush(s->celt);
302 
303  if (s->redundancy_idx) {
304  for (i = 0; i < s->output_channels; i++)
305  opus_fade(s->out[i], s->out[i],
306  s->redundancy_output[i] + 120 + s->redundancy_idx,
308  s->redundancy_idx = 0;
309  }
310  if (redundancy) {
311  if (!redundancy_pos) {
312  ff_celt_flush(s->celt);
313  ret = opus_decode_redundancy(s, data + size, redundancy_size);
314  if (ret < 0)
315  return ret;
316 
317  for (i = 0; i < s->output_channels; i++) {
318  opus_fade(s->out[i] + samples - 120 + delayed_samples,
319  s->out[i] + samples - 120 + delayed_samples,
320  s->redundancy_output[i] + 120,
321  ff_celt_window2, 120 - delayed_samples);
322  if (delayed_samples)
323  s->redundancy_idx = 120 - delayed_samples;
324  }
325  } else {
326  for (i = 0; i < s->output_channels; i++) {
327  memcpy(s->out[i] + delayed_samples, s->redundancy_output[i], 120 * sizeof(float));
328  opus_fade(s->out[i] + 120 + delayed_samples,
329  s->redundancy_output[i] + 120,
330  s->out[i] + 120 + delayed_samples,
331  ff_celt_window2, 120);
332  }
333  }
334  }
335 
336  return samples;
337 }
338 
340  const uint8_t *buf, int buf_size,
341  float **out, int out_size,
342  int nb_samples)
343 {
344  int output_samples = 0;
345  int flush_needed = 0;
346  int i, j, ret;
347 
348  s->out[0] = out[0];
349  s->out[1] = out[1];
350  s->out_size = out_size;
351 
352  /* check if we need to flush the resampler */
353  if (swr_is_initialized(s->swr)) {
354  if (buf) {
355  int64_t cur_samplerate;
356  av_opt_get_int(s->swr, "in_sample_rate", 0, &cur_samplerate);
357  flush_needed = (s->packet.mode == OPUS_MODE_CELT) || (cur_samplerate != s->silk_samplerate);
358  } else {
359  flush_needed = !!s->delayed_samples;
360  }
361  }
362 
363  if (!buf && !flush_needed)
364  return 0;
365 
366  /* use dummy output buffers if the channel is not mapped to anything */
367  if (!s->out[0] ||
368  (s->output_channels == 2 && !s->out[1])) {
370  if (!s->out_dummy)
371  return AVERROR(ENOMEM);
372  if (!s->out[0])
373  s->out[0] = s->out_dummy;
374  if (!s->out[1])
375  s->out[1] = s->out_dummy;
376  }
377 
378  /* flush the resampler if necessary */
379  if (flush_needed) {
381  if (ret < 0) {
382  av_log(s->avctx, AV_LOG_ERROR, "Error flushing the resampler.\n");
383  return ret;
384  }
385  swr_close(s->swr);
386  output_samples += s->delayed_samples;
387  s->delayed_samples = 0;
388 
389  if (!buf)
390  goto finish;
391  }
392 
393  /* decode all the frames in the packet */
394  for (i = 0; i < s->packet.frame_count; i++) {
395  int size = s->packet.frame_size[i];
396  int samples = opus_decode_frame(s, buf + s->packet.frame_offset[i], size);
397 
398  if (samples < 0) {
399  av_log(s->avctx, AV_LOG_ERROR, "Error decoding an Opus frame.\n");
401  return samples;
402 
403  for (j = 0; j < s->output_channels; j++)
404  memset(s->out[j], 0, s->packet.frame_duration * sizeof(float));
405  samples = s->packet.frame_duration;
406  }
407  output_samples += samples;
408 
409  for (j = 0; j < s->output_channels; j++)
410  s->out[j] += samples;
411  s->out_size -= samples * sizeof(float);
412  }
413 
414 finish:
415  s->out[0] = s->out[1] = NULL;
416  s->out_size = 0;
417 
418  return output_samples;
419 }
420 
421 static int opus_decode_packet(AVCodecContext *avctx, void *data,
422  int *got_frame_ptr, AVPacket *avpkt)
423 {
424  OpusContext *c = avctx->priv_data;
425  AVFrame *frame = data;
426  const uint8_t *buf = avpkt->data;
427  int buf_size = avpkt->size;
428  int coded_samples = 0;
429  int decoded_samples = INT_MAX;
430  int delayed_samples = 0;
431  int i, ret;
432 
433  /* calculate the number of delayed samples */
434  for (i = 0; i < c->nb_streams; i++) {
435  OpusStreamContext *s = &c->streams[i];
436  s->out[0] =
437  s->out[1] = NULL;
438  delayed_samples = FFMAX(delayed_samples,
440  }
441 
442  /* decode the header of the first sub-packet to find out the sample count */
443  if (buf) {
444  OpusPacket *pkt = &c->streams[0].packet;
445  ret = ff_opus_parse_packet(pkt, buf, buf_size, c->nb_streams > 1);
446  if (ret < 0) {
447  av_log(avctx, AV_LOG_ERROR, "Error parsing the packet header.\n");
448  return ret;
449  }
450  coded_samples += pkt->frame_count * pkt->frame_duration;
452  }
453 
454  frame->nb_samples = coded_samples + delayed_samples;
455 
456  /* no input or buffered data => nothing to do */
457  if (!frame->nb_samples) {
458  *got_frame_ptr = 0;
459  return 0;
460  }
461 
462  /* setup the data buffers */
463  ret = ff_get_buffer(avctx, frame, 0);
464  if (ret < 0)
465  return ret;
466  frame->nb_samples = 0;
467 
468  memset(c->out, 0, c->nb_streams * 2 * sizeof(*c->out));
469  for (i = 0; i < avctx->channels; i++) {
470  ChannelMap *map = &c->channel_maps[i];
471  if (!map->copy)
472  c->out[2 * map->stream_idx + map->channel_idx] = (float*)frame->extended_data[i];
473  }
474 
475  /* read the data from the sync buffers */
476  for (i = 0; i < c->nb_streams; i++) {
477  float **out = c->out + 2 * i;
478  int sync_size = av_audio_fifo_size(c->sync_buffers[i]);
479 
480  float sync_dummy[32];
481  int out_dummy = (!out[0]) | ((!out[1]) << 1);
482 
483  if (!out[0])
484  out[0] = sync_dummy;
485  if (!out[1])
486  out[1] = sync_dummy;
487  if (out_dummy && sync_size > FF_ARRAY_ELEMS(sync_dummy))
488  return AVERROR_BUG;
489 
490  ret = av_audio_fifo_read(c->sync_buffers[i], (void**)out, sync_size);
491  if (ret < 0)
492  return ret;
493 
494  if (out_dummy & 1)
495  out[0] = NULL;
496  else
497  out[0] += ret;
498  if (out_dummy & 2)
499  out[1] = NULL;
500  else
501  out[1] += ret;
502 
503  c->out_size[i] = frame->linesize[0] - ret * sizeof(float);
504  }
505 
506  /* decode each sub-packet */
507  for (i = 0; i < c->nb_streams; i++) {
508  OpusStreamContext *s = &c->streams[i];
509 
510  if (i && buf) {
511  ret = ff_opus_parse_packet(&s->packet, buf, buf_size, i != c->nb_streams - 1);
512  if (ret < 0) {
513  av_log(avctx, AV_LOG_ERROR, "Error parsing the packet header.\n");
514  return ret;
515  }
516  if (coded_samples != s->packet.frame_count * s->packet.frame_duration) {
517  av_log(avctx, AV_LOG_ERROR,
518  "Mismatching coded sample count in substream %d.\n", i);
519  return AVERROR_INVALIDDATA;
520  }
521 
523  }
524 
525  ret = opus_decode_subpacket(&c->streams[i], buf, s->packet.data_size,
526  c->out + 2 * i, c->out_size[i], coded_samples);
527  if (ret < 0)
528  return ret;
529  c->decoded_samples[i] = ret;
530  decoded_samples = FFMIN(decoded_samples, ret);
531 
532  buf += s->packet.packet_size;
533  buf_size -= s->packet.packet_size;
534  }
535 
536  /* buffer the extra samples */
537  for (i = 0; i < c->nb_streams; i++) {
538  int buffer_samples = c->decoded_samples[i] - decoded_samples;
539  if (buffer_samples) {
540  float *buf[2] = { c->out[2 * i + 0] ? c->out[2 * i + 0] : (float*)frame->extended_data[0],
541  c->out[2 * i + 1] ? c->out[2 * i + 1] : (float*)frame->extended_data[0] };
542  buf[0] += decoded_samples;
543  buf[1] += decoded_samples;
544  ret = av_audio_fifo_write(c->sync_buffers[i], (void**)buf, buffer_samples);
545  if (ret < 0)
546  return ret;
547  }
548  }
549 
550  for (i = 0; i < avctx->channels; i++) {
551  ChannelMap *map = &c->channel_maps[i];
552 
553  /* handle copied channels */
554  if (map->copy) {
555  memcpy(frame->extended_data[i],
556  frame->extended_data[map->copy_idx],
557  frame->linesize[0]);
558  } else if (map->silence) {
559  memset(frame->extended_data[i], 0, frame->linesize[0]);
560  }
561 
562  if (c->gain_i && decoded_samples > 0) {
563  c->fdsp->vector_fmul_scalar((float*)frame->extended_data[i],
564  (float*)frame->extended_data[i],
565  c->gain, FFALIGN(decoded_samples, 8));
566  }
567  }
568 
569  frame->nb_samples = decoded_samples;
570  *got_frame_ptr = !!decoded_samples;
571 
572  return avpkt->size;
573 }
574 
576 {
577  OpusContext *c = ctx->priv_data;
578  int i;
579 
580  for (i = 0; i < c->nb_streams; i++) {
581  OpusStreamContext *s = &c->streams[i];
582 
583  memset(&s->packet, 0, sizeof(s->packet));
584  s->delayed_samples = 0;
585 
586  if (s->celt_delay)
588  swr_close(s->swr);
589 
591 
592  ff_silk_flush(s->silk);
593  ff_celt_flush(s->celt);
594  }
595 }
596 
598 {
599  OpusContext *c = avctx->priv_data;
600  int i;
601 
602  for (i = 0; i < c->nb_streams; i++) {
603  OpusStreamContext *s = &c->streams[i];
604 
605  ff_silk_free(&s->silk);
606  ff_celt_free(&s->celt);
607 
608  av_freep(&s->out_dummy);
610 
612  swr_free(&s->swr);
613  }
614 
615  av_freep(&c->streams);
616 
617  if (c->sync_buffers) {
618  for (i = 0; i < c->nb_streams; i++)
620  }
621  av_freep(&c->sync_buffers);
623  av_freep(&c->out);
624  av_freep(&c->out_size);
625 
626  c->nb_streams = 0;
627 
628  av_freep(&c->channel_maps);
629  av_freep(&c->fdsp);
630 
631  return 0;
632 }
633 
635 {
636  OpusContext *c = avctx->priv_data;
637  int ret, i, j;
638 
640  avctx->sample_rate = 48000;
641 
643  if (!c->fdsp)
644  return AVERROR(ENOMEM);
645 
646  /* find out the channel configuration */
647  ret = ff_opus_parse_extradata(avctx, c);
648  if (ret < 0) {
649  av_freep(&c->fdsp);
650  return ret;
651  }
652 
653  /* allocate and init each independent decoder */
654  c->streams = av_mallocz_array(c->nb_streams, sizeof(*c->streams));
655  c->out = av_mallocz_array(c->nb_streams, 2 * sizeof(*c->out));
656  c->out_size = av_mallocz_array(c->nb_streams, sizeof(*c->out_size));
659  if (!c->streams || !c->sync_buffers || !c->decoded_samples || !c->out || !c->out_size) {
660  c->nb_streams = 0;
661  ret = AVERROR(ENOMEM);
662  goto fail;
663  }
664 
665  for (i = 0; i < c->nb_streams; i++) {
666  OpusStreamContext *s = &c->streams[i];
667  uint64_t layout;
668 
669  s->output_channels = (i < c->nb_stereo_streams) ? 2 : 1;
670 
671  s->avctx = avctx;
672 
673  for (j = 0; j < s->output_channels; j++) {
674  s->silk_output[j] = s->silk_buf[j];
675  s->celt_output[j] = s->celt_buf[j];
676  s->redundancy_output[j] = s->redundancy_buf[j];
677  }
678 
679  s->fdsp = c->fdsp;
680 
681  s->swr =swr_alloc();
682  if (!s->swr)
683  goto fail;
684 
686  av_opt_set_int(s->swr, "in_sample_fmt", avctx->sample_fmt, 0);
687  av_opt_set_int(s->swr, "out_sample_fmt", avctx->sample_fmt, 0);
688  av_opt_set_int(s->swr, "in_channel_layout", layout, 0);
689  av_opt_set_int(s->swr, "out_channel_layout", layout, 0);
690  av_opt_set_int(s->swr, "out_sample_rate", avctx->sample_rate, 0);
691  av_opt_set_int(s->swr, "filter_size", 16, 0);
692 
693  ret = ff_silk_init(avctx, &s->silk, s->output_channels);
694  if (ret < 0)
695  goto fail;
696 
697  ret = ff_celt_init(avctx, &s->celt, s->output_channels);
698  if (ret < 0)
699  goto fail;
700 
702  s->output_channels, 1024);
703  if (!s->celt_delay) {
704  ret = AVERROR(ENOMEM);
705  goto fail;
706  }
707 
709  s->output_channels, 32);
710  if (!c->sync_buffers[i]) {
711  ret = AVERROR(ENOMEM);
712  goto fail;
713  }
714  }
715 
716  return 0;
717 fail:
718  opus_decode_close(avctx);
719  return ret;
720 }
721 
723  .name = "opus",
724  .long_name = NULL_IF_CONFIG_SMALL("Opus"),
725  .type = AVMEDIA_TYPE_AUDIO,
726  .id = AV_CODEC_ID_OPUS,
727  .priv_data_size = sizeof(OpusContext),
729  .close = opus_decode_close,
732  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
733 };
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, int self_delimiting)
Parse Opus packet info from raw packet data.
Definition: opus.c:89
static av_cold int opus_decode_close(AVCodecContext *avctx)
Definition: opusdec.c:597
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band)
Definition: opus_celt.c:783
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
av_cold void swr_close(SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
Definition: swresample.c:148
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVAudioFifo ** sync_buffers
Definition: opus.h:160
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
static const uint16_t silk_frame_duration_ms[16]
Definition: opusdec.c:53
int frame_count
frame count
Definition: opus.h:92
int nb_stereo_streams
Definition: opus.h:165
float redundancy_buf[2][960]
Definition: opus.h:115
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static FFServerConfig config
Definition: ffserver.c:193
int output_channels
Definition: opus.h:102
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
int delayed_samples
Definition: opus.h:129
float gain
Definition: opus.h:169
static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int size)
Definition: opusdec.c:153
int size
Definition: avcodec.h:1658
int out_size
Definition: movenc.c:55
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
Definition: opus_rc.c:114
static AVPacket pkt
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:3681
int16_t gain_i
Definition: opus.h:168
Macro definitions for various function/variable attributes.
const uint8_t ff_celt_band_end[]
Definition: opustab.c:27
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
Definition: float_dsp.h:54
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:1019
int * decoded_samples
Definition: opus.h:162
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
Definition: opusdec.c:85
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2502
uint8_t
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition: options.c:149
#define av_cold
Definition: attributes.h:82
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
AVOptions.
static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size)
Definition: opusdec.c:180
int copy
Definition: opus.h:144
SilkContext * silk
Definition: opus.h:106
static AVFrame * frame
static void finish(void)
Definition: movenc.c:344
uint8_t * data
Definition: avcodec.h:1657
bitstream reader API header.
static void opus_fade(float *out, const float *in1, const float *in2, const float *window, int len)
Definition: opusdec.c:76
ptrdiff_t size
Definition: opengl_enc.c:101
float * silk_output[2]
Definition: opus.h:111
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
static av_cold int opus_decode_init(AVCodecContext *avctx)
Definition: opusdec.c:634
AVFloatDSPContext * fdsp
Definition: opus.h:108
ChannelMap * channel_maps
Definition: opus.h:171
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels)
Definition: opus_celt.c:995
libswresample public header
int nb_streams
Definition: opus.h:164
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void ff_celt_flush(CeltFrame *f)
Definition: opus_celt.c:953
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:558
AVFloatDSPContext * fdsp
Definition: opus.h:167
const char * name
Name of the codec implementation.
Definition: avcodec.h:3688
#define FFMAX(a, b)
Definition: common.h:94
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
#define fail()
Definition: checkasm.h:89
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:469
static SDL_Window * window
Definition: ffplay.c:362
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
audio channel layout utility functions
float * out[2]
Definition: opus.h:119
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:3020
int frame_size[MAX_FRAMES]
frame sizes
Definition: opus.h:94
#define FFMIN(a, b)
Definition: common.h:96
int frame_duration
frame duration, in samples @ 48kHz
Definition: opus.h:95
float celt_buf[2][960]
Definition: opus.h:112
SwrContext * swr
Definition: opus.h:125
void ff_celt_free(CeltFrame **f)
Definition: opus_celt.c:980
AVFormatContext * ctx
Definition: movenc.c:48
int out_dummy_allocated_size
Definition: opus.h:123
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: float_dsp.h:69
float silk_buf[2][960]
Definition: opus.h:110
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:3031
#define FF_ARRAY_ELEMS(a)
int silence
Definition: opus.h:149
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:875
static int get_silk_samplerate(int config)
Definition: opusdec.c:67
CeltFrame * celt
Definition: opus.h:107
float * out_dummy
Definition: opus.h:122
Libavcodec external API header.
OpusPacket packet
Definition: opus.h:131
int sample_rate
samples per second
Definition: avcodec.h:2494
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
AVCodec ff_opus_decoder
Definition: opusdec.c:722
void ff_silk_flush(SilkContext *s)
Definition: opus_silk.c:843
main external API structure.
Definition: avcodec.h:1732
const float ff_celt_window2[120]
Definition: opustab.c:1115
int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels)
Definition: opus_silk.c:851
static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame...
Definition: opus_rc.h:61
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
Definition: swresample.c:137
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:953
void * buf
Definition: avisynth_c.h:690
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
int config
configuration: tells the audio mode, bandwidth, and frame duration
Definition: opus.h:90
void ff_silk_free(SilkContext **ps)
Definition: opus_silk.c:838
enum OpusMode mode
mode
Definition: opus.h:96
void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes)
Definition: opus_rc.c:352
int copy_idx
Definition: opus.h:146
const VDPAUPixFmtMap * map
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:119
int stereo
whether this packet is mono or stereo
Definition: opus.h:88
AVCodecContext * avctx
Definition: opus.h:101
float ** out
Definition: opus.h:156
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
Definition: swresample.c:706
int data_size
size of the useful data – packet size - padding
Definition: opus.h:86
int channel_idx
Definition: opus.h:139
int redundancy_idx
Definition: opus.h:133
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
static int opus_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: opusdec.c:421
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:201
static int opus_init_resample(OpusStreamContext *s)
Definition: opusdec.c:128
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf, int buf_size, float **out, int out_size, int nb_samples)
Definition: opusdec.c:339
float * celt_output[2]
Definition: opus.h:113
common internal api header.
OpusRangeCoder rc
Definition: opus.h:104
int stream_idx
Definition: opus.h:138
int * out_size
Definition: opus.h:157
OpusBandwidth
Definition: opus.h:70
static double c[64]
static const int silk_resample_delay[]
Definition: opusdec.c:63
int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, int duration_ms)
Decode the LP layer of one Opus frame (which may correspond to several SILK frames).
Definition: opus_silk.c:774
OpusStreamContext * streams
Definition: opus.h:153
int packet_size
packet size
Definition: opus.h:85
OpusRangeCoder redundancy_rc
Definition: opus.h:105
void * priv_data
Definition: avcodec.h:1774
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
Definition: opus_rc.c:338
Audio FIFO Buffer.
int len
int channels
number of audio channels
Definition: avcodec.h:2495
int frame_offset[MAX_FRAMES]
frame offsets
Definition: opus.h:93
enum OpusBandwidth bandwidth
bandwidth
Definition: opus.h:97
static av_cold void opus_decode_flush(AVCodecContext *ctx)
Definition: opusdec.c:575
float * redundancy_output[2]
Definition: opus.h:116
uint64_t layout
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
Definition: opus_rc.c:182
AVAudioFifo * celt_delay
Definition: opus.h:126
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
Definition: opus.c:290
FILE * out
Definition: movenc.c:54
#define av_freep(p)
int silk_samplerate
Definition: opus.h:127
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2257
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:234
#define AV_CH_LAYOUT_MONO
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
Definition: swresample.c:702
This structure stores compressed data.
Definition: avcodec.h:1634
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:244
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:994
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:152