Lines Matching refs:avctx

88 static void libopus_write_header(AVCodecContext *avctx, int stream_count,
93 uint8_t *p = avctx->extradata;
94 int channels = avctx->ch_layout.nb_channels;
99 bytestream_put_le16(&p, avctx->initial_padding * 48000 / avctx->sample_rate); /* Lookahead samples at 48kHz */
100 bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
112 static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
117 if (avctx->global_quality) {
118 av_log(avctx, AV_LOG_ERROR,
124 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->bit_rate));
126 av_log(avctx, AV_LOG_ERROR,
134 av_log(avctx, AV_LOG_WARNING,
139 av_log(avctx, AV_LOG_WARNING,
145 av_log(avctx, AV_LOG_WARNING,
151 av_log(avctx, AV_LOG_WARNING,
158 av_log(avctx, AV_LOG_WARNING,
162 if (avctx->cutoff) {
166 av_log(avctx, AV_LOG_WARNING,
174 av_log(avctx, AV_LOG_WARNING,
181 static int libopus_check_max_channels(AVCodecContext *avctx,
183 if (avctx->ch_layout.nb_channels > max_channels) {
184 av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n",
185 avctx->ch_layout.nb_channels);
192 static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) {
193 av_assert2(avctx->ch_layout.nb_channels < FF_ARRAY_ELEMS(ff_vorbis_ch_layouts));
195 if (avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
196 av_log(avctx, AV_LOG_WARNING,
198 "channel layout for %d channels.\n", avctx->ch_layout.nb_channels);
199 } else if (av_channel_layout_compare(&avctx->ch_layout, &ff_vorbis_ch_layouts[avctx->ch_layout.nb_channels - 1])) {
202 av_channel_layout_describe(&avctx->ch_layout, name, sizeof(name));
203 av_log(avctx, AV_LOG_ERROR,
214 AVCodecContext *avctx,
223 ret = libopus_check_max_channels(avctx, 8);
225 ret = libopus_check_vorbis_layout(avctx, mapping_family);
231 ret = libopus_check_max_channels(avctx, 2);
233 ret = libopus_check_vorbis_layout(avctx, mapping_family);
238 ret = libopus_check_max_channels(avctx, 8);
240 ret = libopus_check_vorbis_layout(avctx, mapping_family);
241 channel_map = ff_vorbis_channel_layout_offsets[avctx->ch_layout.nb_channels - 1];
245 ret = libopus_check_max_channels(avctx, 254);
248 av_log(avctx, AV_LOG_WARNING,
258 static av_cold int libopus_encode_init(AVCodecContext *avctx)
260 LibopusEncContext *opus = avctx->priv_data;
264 int channels = avctx->ch_layout.nb_channels;
274 av_log(avctx, AV_LOG_WARNING,
291 avctx->frame_size = frame_size * avctx->sample_rate / 48000;
294 av_log(avctx, AV_LOG_ERROR, "Invalid frame duration: %g.\n"
305 if (avctx->compression_level < 0 || avctx->compression_level > 10) {
306 av_log(avctx, AV_LOG_WARNING,
311 opus->opts.complexity = avctx->compression_level;
314 if (avctx->cutoff) {
315 switch (avctx->cutoff) {
332 av_log(avctx, AV_LOG_WARNING,
335 avctx->cutoff);
336 avctx->cutoff = 0;
341 av_ret = libopus_validate_layout_and_get_channel_map(avctx, opus->opts.mapping_family,
360 avctx->sample_rate, channels, opus->stream_count,
370 avctx->sample_rate, channels, mapping_family,
376 av_log(avctx, AV_LOG_ERROR,
381 if (!avctx->bit_rate) {
383 avctx->bit_rate = 64000 * opus->stream_count +
385 av_log(avctx, AV_LOG_WARNING,
386 "No bit rate set. Defaulting to %"PRId64" bps.\n", avctx->bit_rate);
389 if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * channels) {
390 av_log(avctx, AV_LOG_ERROR, "The bit rate %"PRId64" bps is unsupported. "
391 "Please choose a value between 500 and %d.\n", avctx->bit_rate,
397 ret = libopus_configure_encoder(avctx, enc, &opus->opts);
405 avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
406 if (!avctx->extradata) {
407 av_log(avctx, AV_LOG_ERROR, "Failed to allocate extradata.\n");
411 avctx->extradata_size = header_size;
414 av_get_bytes_per_sample(avctx->sample_fmt));
416 av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
421 ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
423 av_log(avctx, AV_LOG_WARNING,
427 libopus_write_header(avctx, opus->stream_count, coupled_stream_count,
430 ff_af_queue_init(avctx, &opus->afq);
455 static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
458 LibopusEncContext *opus = avctx->priv_data;
459 const int bytes_per_sample = av_get_bytes_per_sample(avctx->sample_fmt);
460 const int channels = avctx->ch_layout.nb_channels;
490 if ((ret = ff_alloc_packet(avctx, avpkt, (1275 * 6 + 7) * opus->stream_count)) < 0)
493 if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT)
503 av_log(avctx, AV_LOG_ERROR,
535 static av_cold int libopus_encode_close(AVCodecContext *avctx)
537 LibopusEncContext *opus = avctx->priv_data;