MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / libopus_encode_init

Function libopus_encode_init

libavcodec/libopusenc.c:259–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259static 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) {

Callers

nothing calls this directly

Calls 9

av_logFunction · 0.85
ff_opus_error_to_averrorFunction · 0.85
av_callocFunction · 0.85
av_get_bytes_per_sampleFunction · 0.85
libopus_write_headerFunction · 0.85
ff_af_queue_initFunction · 0.85
av_mallocFunction · 0.50

Tested by

no test coverage detected