static av_cold int libopus_decode_init(AVCodecContext *avc)
{
    struct libopus_context *opus = avc->priv_data;
    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
    uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
    avc->sample_rate    = 48000;
    avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
                          AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
    avc->channel_layout = avc->channels > 8 ? 0 :
                          ff_vorbis_channel_layouts[avc->channels - 1];
    if (avc->extradata_size >= OPUS_HEAD_SIZE) {
        gain_db     = sign_extend(AV_RL16(avc->extradata + 16), 16);
        channel_map = AV_RL8 (avc->extradata + 18);
    if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
        nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
        nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
        if (nb_streams + nb_coupled != avc->channels)
            av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
        mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
    } else {
        if (avc->channels > 2 || channel_map) {
            av_log(avc, AV_LOG_ERROR,
                   "No channel mapping for %d channels.\n", avc->channels);
            return AVERROR(EINVAL);
        nb_streams = 1;
        nb_coupled = avc->channels > 1;
        mapping    = mapping_arr;
    if (avc->channels > 2 && avc->channels <= 8) {
        const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
        int ch;
        /* Remap channels from Vorbis order to libav order */
        for (ch = 0; ch < avc->channels; ch++)
            mapping_arr[ch] = mapping[vorbis_offset[ch]];
        mapping = mapping_arr;
    opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
                                                nb_streams, nb_coupled,
                                                mapping, &ret);
    if (!opus->dec) {
        av_log(avc, AV_LOG_ERROR, "Unable to create decoder: %s\n",
               opus_strerror(ret));
        return ff_opus_error_to_averror(ret);
    ret = opus_multistream_decoder_ctl(opus->dec, OPUS_SET_GAIN(gain_db));
    if (ret != OPUS_OK)
        av_log(avc, AV_LOG_WARNING, "Failed to set gain: %s\n",
               opus_strerror(ret));
    avc->delay = 3840;  /* Decoder delay (in samples) at 48kHz */
    return 0;
static av_cold int libopus_decode_init(AVCodecContext *avc)
{
    struct libopus_context *opus = avc->priv_data;
    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
    uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
    avc->sample_rate    = 48000;
    avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
                          AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
    avc->channel_layout = avc->channels > 8 ? 0 :
                          ff_vorbis_channel_layouts[avc->channels - 1];
    if (avc->extradata_size >= OPUS_HEAD_SIZE) {
        gain_db     = sign_extend(AV_RL16(avc->extradata + 16), 16);
        channel_map = AV_RL8 (avc->extradata + 18);
    if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
        nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
        nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
        if (nb_streams + nb_coupled != avc->channels)
            av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
        mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
    } else {
        if (avc->channels > 2 || channel_map) {
            av_log(avc, AV_LOG_ERROR,
                   "No channel mapping for %d channels.\n", avc->channels);
            return AVERROR(EINVAL);
        nb_streams = 1;
        nb_coupled = avc->channels > 1;
        mapping    = mapping_arr;
    if (avc->channels > 2 && avc->channels <= 8) {
        const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
        int ch;
        
        for (ch = 0; ch < avc->channels; ch++)
            mapping_arr[ch] = mapping[vorbis_offset[ch]];
        mapping = mapping_arr;
    opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
                                                nb_streams, nb_coupled,
                                                mapping, &ret);
    if (!opus->dec) {
        av_log(avc, AV_LOG_ERROR, "Unable to create decoder: %s\n",
               opus_strerror(ret));
        return ff_opus_error_to_averror(ret);
    ret = opus_multistream_decoder_ctl(opus->dec, OPUS_SET_GAIN(gain_db));
    if (ret != OPUS_OK)
        av_log(avc, AV_LOG_WARNING, "Failed to set gain: %s\n",
               opus_strerror(ret));
    avc->delay = 3840;  
    return 0;
static av_cold int FUNC_0(AVCodecContext *avc)
{
    struct libopus_context *VAR_0 = avc->priv_data;
    int VAR_1, VAR_2 = 0, VAR_3 = 0, VAR_4, VAR_5;
    uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
    avc->sample_rate    = 48000;
    avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
                          AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
    avc->channel_layout = avc->channels > 8 ? 0 :
                          ff_vorbis_channel_layouts[avc->channels - 1];
    if (avc->extradata_size >= OPUS_HEAD_SIZE) {
        VAR_3     = sign_extend(AV_RL16(avc->extradata + 16), 16);
        VAR_2 = AV_RL8 (avc->extradata + 18);
    if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
        VAR_4 = avc->extradata[OPUS_HEAD_SIZE + 0];
        VAR_5 = avc->extradata[OPUS_HEAD_SIZE + 1];
        if (VAR_4 + VAR_5 != avc->channels)
            av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
        mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
    } else {
        if (avc->channels > 2 || VAR_2) {
            av_log(avc, AV_LOG_ERROR,
                   "No channel mapping for %d channels.\n", avc->channels);
            return AVERROR(EINVAL);
        VAR_4 = 1;
        VAR_5 = avc->channels > 1;
        mapping    = mapping_arr;
    if (avc->channels > 2 && avc->channels <= 8) {
        const uint8_t *VAR_6 = ff_vorbis_channel_layout_offsets[avc->channels - 1];
        int VAR_7;
        
        for (VAR_7 = 0; VAR_7 < avc->channels; VAR_7++)
            mapping_arr[VAR_7] = mapping[VAR_6[VAR_7]];
        mapping = mapping_arr;
    VAR_0->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
                                                VAR_4, VAR_5,
                                                mapping, &VAR_1);
    if (!VAR_0->dec) {
        av_log(avc, AV_LOG_ERROR, "Unable to create decoder: %s\n",
               opus_strerror(VAR_1));
        return ff_opus_error_to_averror(VAR_1);
    VAR_1 = opus_multistream_decoder_ctl(VAR_0->dec, OPUS_SET_GAIN(VAR_3));
    if (VAR_1 != OPUS_OK)
        av_log(avc, AV_LOG_WARNING, "Failed to set gain: %s\n",
               opus_strerror(VAR_1));
    avc->delay = 3840;  
    return 0;
static av_cold int FUNC_0(AVCodecContext *avc)
{ struct libopus_context *VAR_0 = avc->priv_data; int VAR_1, VAR_2 = 0, VAR_3 = 0, VAR_4, VAR_5; uint8_t mapping_arr[8] = { 0, 1 }, *mapping; avc->sample_rate    = 48000; avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16; avc->channel_layout = avc->channels > 8 ? 0 :
ff_vorbis_channel_layouts[avc->channels - 1]; if (avc->extradata_size >= OPUS_HEAD_SIZE) { VAR_3     = sign_extend(AV_RL16(avc->extradata + 16), 16); VAR_2 = AV_RL8 (avc->extradata + 18); if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) { VAR_4 = avc->extradata[OPUS_HEAD_SIZE + 0]; VAR_5 = avc->extradata[OPUS_HEAD_SIZE + 1]; if (VAR_4 + VAR_5 != avc->channels)
av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n"); mapping = avc->extradata + OPUS_HEAD_SIZE + 2; } else { if (avc->channels > 2 || VAR_2) { av_log(avc, AV_LOG_ERROR,
"No channel mapping for %d channels.\n", avc->channels); return AVERROR(EINVAL); VAR_4 = 1; VAR_5 = avc->channels > 1; mapping    = mapping_arr; if (avc->channels > 2 && avc->channels <= 8) { const uint8_t *VAR_6 = ff_vorbis_channel_layout_offsets[avc->channels - 1]; int VAR_7; for (VAR_7 = 0; VAR_7 < avc->channels; VAR_7++) mapping_arr[VAR_7] = mapping[VAR_6[VAR_7]]; mapping = mapping_arr; VAR_0->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
VAR_4, VAR_5,
mapping, &VAR_1); if (!VAR_0->dec) { av_log(avc, AV_LOG_ERROR, "Unable to create decoder: %s\n",
opus_strerror(VAR_1)); return ff_opus_error_to_averror(VAR_1); VAR_1 = opus_multistream_decoder_ctl(VAR_0->dec, OPUS_SET_GAIN(VAR_3)); if (VAR_1 != OPUS_OK)
av_log(avc, AV_LOG_WARNING, "Failed to set gain: %s\n",
opus_strerror(VAR_1)); avc->delay = 3840; return 0;