mirror of
https://github.com/mpv-player/mpv
synced 2024-12-31 19:52:16 +00:00
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.)
This commit is contained in:
parent
60a617df31
commit
e721660e6d
@ -171,13 +171,11 @@ void af_fill_silence(void *dst, size_t bytes, int format)
|
||||
memset(dst, af_fmt_is_unsigned(format) ? 0x80 : 0, bytes);
|
||||
}
|
||||
|
||||
#define FMT_DIFF(type, a, b) (((a) & type) - ((b) & type))
|
||||
|
||||
// Returns a "score" that serves as heuristic how lossy or hard a conversion is.
|
||||
// If the formats are equal, 1024 is returned. If they are gravely incompatible
|
||||
// (like s16<->ac3), INT_MIN is returned. If there is implied loss of precision
|
||||
// (like s16->s8), a value <0 is returned.
|
||||
int af_format_conversion_score(int dst_format, int src_format)
|
||||
static int af_format_conversion_score(int dst_format, int src_format)
|
||||
{
|
||||
if (dst_format == AF_FORMAT_UNKNOWN || src_format == AF_FORMAT_UNKNOWN)
|
||||
return INT_MIN;
|
||||
|
@ -75,7 +75,6 @@ int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int sampler
|
||||
|
||||
void af_fill_silence(void *dst, size_t bytes, int format);
|
||||
|
||||
int af_format_conversion_score(int dst_format, int src_format);
|
||||
void af_get_best_sample_formats(int src_format, int out_formats[AF_FORMAT_COUNT]);
|
||||
|
||||
int af_format_sample_alignment(int format);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user