1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00

audio: fix annyoing af_get_best_sample_formats() definition

The af_get_best_sample_formats() function had an argument of
int[AF_FORMAT_COUNT], which is slightly incorrect, because it's 0
terminated and should in theory have AF_FORMAT_COUNT+1 entries. It won't
actually write this many formats (since some formats are fundamentally
incompatible), but it still feels annoying and incorrect. So fix it, and
require that callers pass an AF_FORMAT_COUNT+1 array.

Note that the array size has no meaning in C function arguments (just
another issue with C static arrays being weird and stupid), so get rid
of it completely.

Not changing the af_lavcac3enc use, since that is rewritten in another
branch anyway.
This commit is contained in:
wm4 2018-01-24 00:02:13 +01:00 committed by Kevin Mitchell
parent 3dd5621cec
commit d36ff64b29
8 changed files with 10 additions and 9 deletions

View File

@ -209,10 +209,11 @@ static int cmp_entry(const void *a, const void *b)
// and the list is terminated with 0 (AF_FORMAT_UNKNOWN).
// Keep in mind that this also returns formats with flipped interleaving
// (e.g. for s16, it returns [s16, s16p, ...]).
void af_get_best_sample_formats(int src_format, int out_formats[AF_FORMAT_COUNT])
// out_formats must be an int[AF_FORMAT_COUNT + 1] array.
void af_get_best_sample_formats(int src_format, int *out_formats)
{
int num = 0;
struct entry e[AF_FORMAT_COUNT];
struct entry e[AF_FORMAT_COUNT + 1];
for (int fmt = 1; fmt < AF_FORMAT_COUNT; fmt++) {
int score = af_format_conversion_score(fmt, src_format);
if (score > INT_MIN)

View File

@ -69,7 +69,7 @@ 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);
void af_get_best_sample_formats(int src_format, int out_formats[AF_FORMAT_COUNT]);
void af_get_best_sample_formats(int src_format, int *out_formats);
int af_select_best_samplerate(int src_sampelrate, const int *available);
int af_format_sample_alignment(int format);

View File

@ -704,7 +704,7 @@ static int init_device(struct ao *ao, int mode)
dump_hw_params(ao, MSGL_DEBUG, "HW params after access:\n", alsa_hwparams);
bool found_format = false;
int try_formats[AF_FORMAT_COUNT];
int try_formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(ao->format, try_formats);
for (int n = 0; try_formats[n] && !found_format; n++) {
int mp_format = try_formats[n];

View File

@ -72,7 +72,7 @@ static bool supports_format(AVCodec *codec, int format)
static void select_format(struct ao *ao, AVCodec *codec)
{
int formats[AF_FORMAT_COUNT];
int formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(ao->format, formats);
for (int n = 0; formats[n]; n++) {

View File

@ -197,7 +197,7 @@ static int init(struct ao *ao)
ao->samplerate = freq;
p->al_format = AL_FALSE;
int try_formats[AF_FORMAT_COUNT];
int try_formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(ao->format, try_formats);
for (int n = 0; try_formats[n]; n++) {
p->al_format = get_al_format(try_formats[n]);

View File

@ -136,7 +136,7 @@ static int init(struct ao *ao)
pcm.formatType = SL_DATAFORMAT_PCM;
pcm.numChannels = 2;
int compatible_formats[AF_FORMAT_COUNT];
int compatible_formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(ao->format, compatible_formats);
pcm.bitsPerSample = 0;
for (int i = 0; compatible_formats[i] && !pcm.bitsPerSample; ++i)

View File

@ -315,7 +315,7 @@ static int reopen_device(struct ao *ao, bool allow_format_changes)
}
}
int try_formats[AF_FORMAT_COUNT];
int try_formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(format, try_formats);
for (int n = 0; try_formats[n]; n++) {
format = try_formats[n];

View File

@ -97,7 +97,7 @@ static const struct wasapi_sample_fmt wasapi_formats[] = {
static void wasapi_get_best_sample_formats(
int src_format, struct wasapi_sample_fmt *out_formats)
{
int mp_formats[AF_FORMAT_COUNT];
int mp_formats[AF_FORMAT_COUNT + 1];
af_get_best_sample_formats(src_format, mp_formats);
for (int n = 0; mp_formats[n]; n++) {
for (int i = 0; wasapi_formats[i].mp_format; i++) {