1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

ffplay: try more channel count combinations for SDL_OpenAudio

This should fix ticket 1384.

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint 2012-06-02 01:26:17 +02:00
parent 7821264c26
commit 0dad529201

View File

@ -2246,6 +2246,7 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
{ {
SDL_AudioSpec wanted_spec, spec; SDL_AudioSpec wanted_spec, spec;
const char *env; const char *env;
const int next_nb_channels[] = {0, 0, 1, 6, 2, 6, 4, 6};
env = SDL_getenv("SDL_AUDIO_CHANNELS"); env = SDL_getenv("SDL_AUDIO_CHANNELS");
if (env) { if (env) {
@ -2255,12 +2256,6 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
if (!wanted_channel_layout || wanted_nb_channels != av_get_channel_layout_nb_channels(wanted_channel_layout)) { if (!wanted_channel_layout || wanted_nb_channels != av_get_channel_layout_nb_channels(wanted_channel_layout)) {
wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels); wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels);
wanted_channel_layout &= ~AV_CH_LAYOUT_STEREO_DOWNMIX; wanted_channel_layout &= ~AV_CH_LAYOUT_STEREO_DOWNMIX;
wanted_nb_channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
/* SDL only supports 1, 2, 4 or 6 channels at the moment, so we have to make sure not to request anything else. */
while (wanted_nb_channels > 0 && (wanted_nb_channels == 3 || wanted_nb_channels == 5 || wanted_nb_channels > (SDL_VERSION_ATLEAST(1, 2, 8) ? 6 : 2))) {
wanted_nb_channels--;
wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels);
}
} }
wanted_spec.channels = av_get_channel_layout_nb_channels(wanted_channel_layout); wanted_spec.channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
wanted_spec.freq = wanted_sample_rate; wanted_spec.freq = wanted_sample_rate;
@ -2273,10 +2268,15 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
wanted_spec.callback = sdl_audio_callback; wanted_spec.callback = sdl_audio_callback;
wanted_spec.userdata = opaque; wanted_spec.userdata = opaque;
if (SDL_OpenAudio(&wanted_spec, &spec) < 0) { while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); fprintf(stderr, "SDL_OpenAudio (%d channels): %s\n", wanted_spec.channels, SDL_GetError());
wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
if (!wanted_spec.channels) {
fprintf(stderr, "No more channel combinations to try, audio open failed\n");
return -1; return -1;
} }
wanted_channel_layout = av_get_default_channel_layout(wanted_spec.channels);
}
if (spec.format != AUDIO_S16SYS) { if (spec.format != AUDIO_S16SYS) {
fprintf(stderr, "SDL advised audio format %d is not supported!\n", spec.format); fprintf(stderr, "SDL advised audio format %d is not supported!\n", spec.format);
return -1; return -1;