Browse code

ffplay: try more channel count combinations for SDL_OpenAudio

This should fix ticket 1384.

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2012/06/02 08:26:17
Showing 1 changed files
... ...
@@ -2246,6 +2246,7 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
2246 2246
 {
2247 2247
     SDL_AudioSpec wanted_spec, spec;
2248 2248
     const char *env;
2249
+    const int next_nb_channels[] = {0, 0, 1, 6, 2, 6, 4, 6};
2249 2250
 
2250 2251
     env = SDL_getenv("SDL_AUDIO_CHANNELS");
2251 2252
     if (env) {
... ...
@@ -2255,12 +2256,6 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
2255 2255
     if (!wanted_channel_layout || wanted_nb_channels != av_get_channel_layout_nb_channels(wanted_channel_layout)) {
2256 2256
         wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels);
2257 2257
         wanted_channel_layout &= ~AV_CH_LAYOUT_STEREO_DOWNMIX;
2258
-        wanted_nb_channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
2259
-        /* SDL only supports 1, 2, 4 or 6 channels at the moment, so we have to make sure not to request anything else. */
2260
-        while (wanted_nb_channels > 0 && (wanted_nb_channels == 3 || wanted_nb_channels == 5 || wanted_nb_channels > (SDL_VERSION_ATLEAST(1, 2, 8) ? 6 : 2))) {
2261
-            wanted_nb_channels--;
2262
-            wanted_channel_layout = av_get_default_channel_layout(wanted_nb_channels);
2263
-        }
2264 2258
     }
2265 2259
     wanted_spec.channels = av_get_channel_layout_nb_channels(wanted_channel_layout);
2266 2260
     wanted_spec.freq = wanted_sample_rate;
... ...
@@ -2273,9 +2268,14 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
2273 2273
     wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
2274 2274
     wanted_spec.callback = sdl_audio_callback;
2275 2275
     wanted_spec.userdata = opaque;
2276
-    if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
2277
-        fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
2278
-        return -1;
2276
+    while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
2277
+        fprintf(stderr, "SDL_OpenAudio (%d channels): %s\n", wanted_spec.channels, SDL_GetError());
2278
+        wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
2279
+        if (!wanted_spec.channels) {
2280
+            fprintf(stderr, "No more channel combinations to try, audio open failed\n");
2281
+            return -1;
2282
+        }
2283
+        wanted_channel_layout = av_get_default_channel_layout(wanted_spec.channels);
2279 2284
     }
2280 2285
     if (spec.format != AUDIO_S16SYS) {
2281 2286
         fprintf(stderr, "SDL advised audio format %d is not supported!\n", spec.format);