diff --git a/lib/amr.c b/lib/amr.c index 138b37506..fab1381ae 100644 --- a/lib/amr.c +++ b/lib/amr.c @@ -3,18 +3,6 @@ #include "bitstr.h" -static int codeclib_set_av_opt_intstr(encoder_t *enc, const char *opt, str *val) { - int i = val ? str_to_i(val, -1) : -1; - if (i == -1) { - ilog(LOG_WARN, "Failed to parse '" STR_FORMAT "' as integer value for ffmpeg option '%s'", - STR_FMT0(val), opt); - return -1; - } - return codeclib_set_av_opt_int(enc, opt, i); -} - - - static const unsigned int amr_bitrates[AMR_FT_TYPES] = { 4750, // 0 5150, // 1 @@ -155,12 +143,8 @@ static void amr_set_enc_codec_options(str *key, str *value, void *data) { ; // not an encoder option else if (!str_cmp(key, "mode-change-interval")) ; // not an encoder option - else { - // our string might not be null terminated - char *s = g_strdup_printf(STR_FORMAT, STR_FMT(key)); - codeclib_set_av_opt_intstr(enc, s, value); - g_free(s); - } + else + codeclib_set_av_opt_intstr(enc, key, value); } static void amr_set_enc_options(encoder_t *enc, const str *codec_opts) { amr_set_encdec_options(&enc->codec_options, enc->def); diff --git a/lib/avc.c b/lib/avc.c index bdc4a2bc6..da352db60 100644 --- a/lib/avc.c +++ b/lib/avc.c @@ -316,6 +316,18 @@ int codeclib_set_av_opt_int(encoder_t *enc, const char *opt, int64_t val) { } +int codeclib_set_av_opt_intstr(encoder_t *enc, const str *opt, const str *val) { + g_autoptr(char) s = g_strdup_printf(STR_FORMAT, STR_FMT(opt)); + int i = val ? str_to_i(val, -1) : -1; + if (i == -1) { + ilog(LOG_WARN, "Failed to parse '" STR_FORMAT "' as integer value for ffmpeg option '%s'", + STR_FMT0(val), s); + return -1; + } + return codeclib_set_av_opt_int(enc, s, i); +} + + codec_def_t *codec_def_make_generic_av(enum AVCodecID id) { { RWLOCK_R(&generic_ffmpeg_codecs_lock); diff --git a/lib/codecmod.h b/lib/codecmod.h index eb09fe3ea..1cf20f950 100644 --- a/lib/codecmod.h +++ b/lib/codecmod.h @@ -27,6 +27,7 @@ int avc_encoder_input(encoder_t *enc, AVFrame **frame); void avc_encoder_close(encoder_t *enc); int codeclib_set_av_opt_int(encoder_t *enc, const char *opt, int64_t val); +int codeclib_set_av_opt_intstr(encoder_t *enc, const str *opt, const str *val); void codeclib_key_value_parse(const str *instr, void (*cb)(str *key, str *value, void *data), void *data);