MT#65420 reorder enc/dec option setting

Call the function first, then set codec options

Change-Id: I2371f3f5f0aaec3b4498d60e74ab8fbbcdb5c990
pull/2169/head
Richard Fuchs 3 weeks ago
parent 2ab27737ff
commit bc20cb5fa7

@ -153,7 +153,7 @@ static void amr_set_enc_options(encoder_t *enc, const str *codec_opts) {
// if a mode-set was given, pick the highest supported bitrate
if (enc->format_options.amr.mode_set) {
int max_bitrate = enc->avc.avcctx->bit_rate;
int max_bitrate = enc->bitrate;
int use_bitrate = 0;
for (int i = 0; i < AMR_FT_TYPES; i++) {
if (!(enc->format_options.amr.mode_set & (1 << i)))
@ -173,7 +173,7 @@ static void amr_set_enc_options(encoder_t *enc, const str *codec_opts) {
else {
ilog(LOG_DEBUG, "Using %i as initial %s bitrate based on mode-set",
use_bitrate, enc->def->rtpname);
enc->avc.avcctx->bit_rate = use_bitrate;
enc->bitrate = use_bitrate;
}
}
}

@ -35,13 +35,14 @@ const char *avc_decoder_init(decoder_t *dec, const str *extra_opts) {
dec->avc.avcctx = avcodec_alloc_context3(codec);
if (!dec->avc.avcctx)
return "failed to alloc codec context";
SET_CHANNELS(dec->avc.avcctx, dec->in_format.channels);
DEF_CH_LAYOUT(&dec->avc.avcctx->CH_LAYOUT, dec->in_format.channels);
dec->avc.avcctx->sample_rate = dec->in_format.clockrate;
if (dec->def->set_dec_options)
dec->def->set_dec_options(dec, extra_opts);
SET_CHANNELS(dec->avc.avcctx, dec->in_format.channels);
DEF_CH_LAYOUT(&dec->avc.avcctx->CH_LAYOUT, dec->in_format.channels);
dec->avc.avcctx->sample_rate = dec->in_format.clockrate;
int i = avcodec_open2(dec->avc.avcctx, codec, NULL);
if (i) {
ilog(LOG_ERR | LOG_FLAG_LIMIT, "Error returned from libav: %s", av_error(i));
@ -202,6 +203,9 @@ const char *avc_encoder_init(encoder_t *enc, const str *extra_opts) {
ilogs(internals, LOG_DEBUG, "using output sample format %s for codec %s",
av_get_sample_fmt_name(enc->actual_format.format), enc->avc.codec->name);
if (enc->def->set_enc_options)
enc->def->set_enc_options(enc, extra_opts);
SET_CHANNELS(enc->avc.avcctx, enc->actual_format.channels);
DEF_CH_LAYOUT(&enc->avc.avcctx->CH_LAYOUT, enc->actual_format.channels);
enc->avc.avcctx->sample_rate = enc->actual_format.clockrate;
@ -209,9 +213,6 @@ const char *avc_encoder_init(encoder_t *enc, const str *extra_opts) {
enc->avc.avcctx->time_base = (AVRational){1,enc->actual_format.clockrate};
enc->avc.avcctx->bit_rate = enc->bitrate;
if (enc->def->set_enc_options)
enc->def->set_enc_options(enc, extra_opts);
int i = avcodec_open2(enc->avc.avcctx, enc->avc.codec, NULL);
if (i) {
ilog(LOG_ERR | LOG_FLAG_LIMIT, "Error returned from libav: %s", av_error(i));

Loading…
Cancel
Save