mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-24 11:49:48 +00:00
ffplay: try multiple sample rates if audio open fails
Should fix ticket #3509. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
e11697759d
commit
0c8d8c0c80
20
ffplay.c
20
ffplay.c
@ -2415,6 +2415,8 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
|
||||
SDL_AudioSpec wanted_spec, spec;
|
||||
const char *env;
|
||||
static const int next_nb_channels[] = {0, 0, 1, 6, 2, 6, 4, 6};
|
||||
static const int next_sample_rates[] = {0, 44100, 48000, 96000, 192000};
|
||||
int next_sample_rate_idx = FF_ARRAY_ELEMS(next_sample_rates) - 1;
|
||||
|
||||
env = SDL_getenv("SDL_AUDIO_CHANNELS");
|
||||
if (env) {
|
||||
@ -2425,24 +2427,32 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
|
||||
wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels);
|
||||
wanted_channel_layout &= ~AV_CH_LAYOUT_STEREO_DOWNMIX;
|
||||
}
|
||||
wanted_spec.channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
|
||||
wanted_nb_channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
|
||||
wanted_spec.channels = wanted_nb_channels;
|
||||
wanted_spec.freq = wanted_sample_rate;
|
||||
if (wanted_spec.freq <= 0 || wanted_spec.channels <= 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Invalid sample rate or channel count!\n");
|
||||
return -1;
|
||||
}
|
||||
while (next_sample_rate_idx && next_sample_rates[next_sample_rate_idx] >= wanted_spec.freq)
|
||||
next_sample_rate_idx--;
|
||||
wanted_spec.format = AUDIO_S16SYS;
|
||||
wanted_spec.silence = 0;
|
||||
wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
|
||||
wanted_spec.callback = sdl_audio_callback;
|
||||
wanted_spec.userdata = opaque;
|
||||
while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
|
||||
av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels): %s\n", wanted_spec.channels, SDL_GetError());
|
||||
av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels, %d Hz): %s\n",
|
||||
wanted_spec.channels, wanted_spec.freq, SDL_GetError());
|
||||
wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
|
||||
if (!wanted_spec.channels) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"No more channel combinations to try, audio open failed\n");
|
||||
return -1;
|
||||
wanted_spec.freq = next_sample_rates[next_sample_rate_idx--];
|
||||
wanted_spec.channels = wanted_nb_channels;
|
||||
if (!wanted_spec.freq) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"No more combinations to try, audio open failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
wanted_channel_layout = av_get_default_channel_layout(wanted_spec.channels);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user