| 257 | } |
| 258 | |
| 259 | static av_cold int libopus_encode_init(AVCodecContext *avctx) |
| 260 | { |
| 261 | LibopusEncContext *opus = avctx->priv_data; |
| 262 | OpusMSEncoder *enc; |
| 263 | uint8_t libopus_channel_mapping[255]; |
| 264 | int ret = OPUS_OK; |
| 265 | int channels = avctx->ch_layout.nb_channels; |
| 266 | int av_ret; |
| 267 | int coupled_stream_count, header_size, frame_size; |
| 268 | int mapping_family; |
| 269 | |
| 270 | frame_size = opus->opts.frame_duration * 48000 / 1000; |
| 271 | switch (frame_size) { |
| 272 | case 120: |
| 273 | case 240: |
| 274 | if (opus->opts.application != OPUS_APPLICATION_RESTRICTED_LOWDELAY) |
| 275 | av_log(avctx, AV_LOG_WARNING, |
| 276 | "LPC mode cannot be used with a frame duration of less " |
| 277 | "than 10ms. Enabling restricted low-delay mode.\n" |
| 278 | "Use a longer frame duration if this is not what you want.\n"); |
| 279 | /* Frame sizes less than 10 ms can only use MDCT mode, so switching to |
| 280 | * RESTRICTED_LOWDELAY avoids an unnecessary extra 2.5ms lookahead. */ |
| 281 | opus->opts.application = OPUS_APPLICATION_RESTRICTED_LOWDELAY; |
| 282 | case 480: |
| 283 | case 960: |
| 284 | case 1920: |
| 285 | case 2880: |
| 286 | #ifdef OPUS_FRAMESIZE_120_MS |
| 287 | case 3840: |
| 288 | case 4800: |
| 289 | case 5760: |
| 290 | #endif |
| 291 | opus->opts.packet_size = |
| 292 | avctx->frame_size = frame_size * avctx->sample_rate / 48000; |
| 293 | break; |
| 294 | default: |
| 295 | av_log(avctx, AV_LOG_ERROR, "Invalid frame duration: %g.\n" |
| 296 | "Frame duration must be exactly one of: 2.5, 5, 10, 20, 40" |
| 297 | #ifdef OPUS_FRAMESIZE_120_MS |
| 298 | ", 60, 80, 100 or 120.\n", |
| 299 | #else |
| 300 | " or 60.\n", |
| 301 | #endif |
| 302 | opus->opts.frame_duration); |
| 303 | return AVERROR(EINVAL); |
| 304 | } |
| 305 | |
| 306 | if (avctx->compression_level < 0 || avctx->compression_level > 10) { |
| 307 | av_log(avctx, AV_LOG_WARNING, |
| 308 | "Compression level must be in the range 0 to 10. " |
| 309 | "Defaulting to 10.\n"); |
| 310 | opus->opts.complexity = 10; |
| 311 | } else { |
| 312 | opus->opts.complexity = avctx->compression_level; |
| 313 | } |
| 314 | |
| 315 | if (avctx->cutoff) { |
| 316 | switch (avctx->cutoff) { |
nothing calls this directly
no test coverage detected