diff options
author | wm4 <wm4@nowhere> | 2015-09-10 23:38:42 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-09-10 23:38:42 +0200 |
commit | e721660e6dd9b8785896dfd81519baa22ea6b2fb (patch) | |
tree | 3661739007350213cfd9f15d24a93fd725e8485e /audio/out | |
parent | 60a617df311fc6e56feced64143d912eb7b7099b (diff) |
ao_lavc: use new sample format determination code
This is just a refactor, which makes it use the previously introduced
function, and allows us to make af_format_conversion_score() private.
(We drop 2 unlikely warning messages too... who cares.)
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao_lavc.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index eedc9c6a6b..a89324e9b0 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -58,33 +58,28 @@ struct priv { bool shutdown; }; -static void select_format(struct ao *ao, AVCodec *codec) +static bool supports_format(AVCodec *codec, int format) { - int best_score = INT_MIN; - int best_format = 0; - - // Check the encoder's list of supported formats. for (const enum AVSampleFormat *sampleformat = codec->sample_fmts; sampleformat && *sampleformat != AV_SAMPLE_FMT_NONE; ++sampleformat) { - int fmt = af_from_avformat(*sampleformat); - if (!fmt) { - MP_WARN(ao, "unsupported lavc format %s\n", - av_get_sample_fmt_name(*sampleformat)); - continue; - } - int score = af_format_conversion_score(fmt, ao->format); - if (score > best_score) { - best_score = score; - best_format = fmt; - } + if (format && af_from_avformat(*sampleformat) == format) + return true; } + return false; +} - if (best_format) { - ao->format = best_format; - } else { - MP_ERR(ao, "sample format not found\n"); // shouldn't happen +static void select_format(struct ao *ao, AVCodec *codec) +{ + int formats[AF_FORMAT_COUNT]; + af_get_best_sample_formats(ao->format, formats); + + for (int n = 0; n < AF_FORMAT_COUNT; n++) { + if (supports_format(codec, formats[n])) { + ao->format = formats[n]; + break; + } } } |