| 679 | } |
| 680 | |
| 681 | static av_cold int opus_decode_init(AVCodecContext *avctx) |
| 682 | { |
| 683 | OpusContext *c = avctx->priv_data; |
| 684 | int ret; |
| 685 | |
| 686 | avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; |
| 687 | avctx->sample_rate = 48000; |
| 688 | |
| 689 | c->fdsp = avpriv_float_dsp_alloc(0); |
| 690 | if (!c->fdsp) |
| 691 | return AVERROR(ENOMEM); |
| 692 | |
| 693 | /* find out the channel configuration */ |
| 694 | ret = ff_opus_parse_extradata(avctx, &c->p); |
| 695 | if (ret < 0) |
| 696 | return ret; |
| 697 | if (c->p.gain_i) |
| 698 | c->gain = ff_exp10(c->p.gain_i / (20.0 * 256)); |
| 699 | |
| 700 | /* allocate and init each independent decoder */ |
| 701 | c->streams = av_calloc(c->p.nb_streams, sizeof(*c->streams)); |
| 702 | if (!c->streams) { |
| 703 | c->p.nb_streams = 0; |
| 704 | return AVERROR(ENOMEM); |
| 705 | } |
| 706 | |
| 707 | for (int i = 0; i < c->p.nb_streams; i++) { |
| 708 | OpusStreamContext *s = &c->streams[i]; |
| 709 | AVChannelLayout layout; |
| 710 | |
| 711 | s->output_channels = (i < c->p.nb_stereo_streams) ? 2 : 1; |
| 712 | |
| 713 | s->avctx = avctx; |
| 714 | |
| 715 | for (int j = 0; j < s->output_channels; j++) { |
| 716 | s->silk_output[j] = s->silk_buf[j]; |
| 717 | s->celt_output[j] = s->celt_buf[j]; |
| 718 | s->redundancy_output[j] = s->redundancy_buf[j]; |
| 719 | } |
| 720 | |
| 721 | s->fdsp = c->fdsp; |
| 722 | |
| 723 | s->swr =swr_alloc(); |
| 724 | if (!s->swr) |
| 725 | return AVERROR(ENOMEM); |
| 726 | |
| 727 | layout = (s->output_channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO : |
| 728 | (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; |
| 729 | av_opt_set_int(s->swr, "in_sample_fmt", avctx->sample_fmt, 0); |
| 730 | av_opt_set_int(s->swr, "out_sample_fmt", avctx->sample_fmt, 0); |
| 731 | av_opt_set_chlayout(s->swr, "in_chlayout", &layout, 0); |
| 732 | av_opt_set_chlayout(s->swr, "out_chlayout", &layout, 0); |
| 733 | av_opt_set_int(s->swr, "out_sample_rate", avctx->sample_rate, 0); |
| 734 | av_opt_set_int(s->swr, "filter_size", 16, 0); |
| 735 | |
| 736 | ret = ff_silk_init(avctx, &s->silk, s->output_channels); |
| 737 | if (ret < 0) |
| 738 | return ret; |
nothing calls this directly
no test coverage detected