Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2014-05-10 16:32:43 +0400
committerMarton Balint <cus@passwd.hu>2014-05-17 15:18:29 +0400
commit0c8d8c0c80671fd592697fee5ca7e645c26d2da9 (patch)
tree1225e84d3949f0f2de2bee7b5e6216da9dd52ca7 /ffplay.c
parente11697759d06900195136df2be035d0d052316a1 (diff)
ffplay: try multiple sample rates if audio open fails
Should fix ticket #3509. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'ffplay.c')
-rw-r--r--ffplay.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/ffplay.c b/ffplay.c
index df7e870119..fbf7d56126 100644
--- a/ffplay.c
+++ b/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);
}