| 154 | } |
| 155 | |
| 156 | av_cold int swr_init(struct SwrContext *s){ |
| 157 | int ret; |
| 158 | char l1[1024], l2[1024]; |
| 159 | |
| 160 | clear_context(s); |
| 161 | |
| 162 | if((unsigned) s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){ |
| 163 | av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt); |
| 164 | return AVERROR(EINVAL); |
| 165 | } |
| 166 | if((unsigned) s->out_sample_fmt >= AV_SAMPLE_FMT_NB){ |
| 167 | av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt); |
| 168 | return AVERROR(EINVAL); |
| 169 | } |
| 170 | |
| 171 | if(s-> in_sample_rate <= 0){ |
| 172 | av_log(s, AV_LOG_ERROR, "Requested input sample rate %d is invalid\n", s->in_sample_rate); |
| 173 | return AVERROR(EINVAL); |
| 174 | } |
| 175 | if(s->out_sample_rate <= 0){ |
| 176 | av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate); |
| 177 | return AVERROR(EINVAL); |
| 178 | } |
| 179 | |
| 180 | s->out.ch_count = s-> user_out_chlayout.nb_channels; |
| 181 | s-> in.ch_count = s-> user_in_chlayout.nb_channels; |
| 182 | |
| 183 | if (swri_check_chlayout(s, &s->user_in_chlayout , "input") || |
| 184 | swri_check_chlayout(s, &s->user_out_chlayout, "output")) |
| 185 | return AVERROR(EINVAL); |
| 186 | |
| 187 | ret = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); |
| 188 | ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); |
| 189 | ret |= av_channel_layout_copy(&s->used_ch_layout, &s->user_used_chlayout); |
| 190 | if (ret < 0) |
| 191 | return ret; |
| 192 | |
| 193 | s->int_sample_fmt= s->user_int_sample_fmt; |
| 194 | |
| 195 | s->dither.method = s->user_dither_method; |
| 196 | |
| 197 | switch(s->engine){ |
| 198 | #if CONFIG_LIBSOXR |
| 199 | case SWR_ENGINE_SOXR: s->resampler = &swri_soxr_resampler; break; |
| 200 | #endif |
| 201 | case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break; |
| 202 | default: |
| 203 | av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n"); |
| 204 | return AVERROR(EINVAL); |
| 205 | } |
| 206 | |
| 207 | if (!av_channel_layout_check(&s->used_ch_layout)) |
| 208 | av_channel_layout_default(&s->used_ch_layout, s->in.ch_count); |
| 209 | |
| 210 | if (s->used_ch_layout.nb_channels != s->in_ch_layout.nb_channels) |
| 211 | av_channel_layout_uninit(&s->in_ch_layout); |
| 212 | |
| 213 | if (s->used_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) |