summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/out/ao_sdl.c')
-rw-r--r--audio/out/ao_sdl.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c
index 7cfb1ae1e2..ee95e77d44 100644
--- a/audio/out/ao_sdl.c
+++ b/audio/out/ao_sdl.c
@@ -42,8 +42,8 @@ struct priv
bool unpause;
bool paused;
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0;
- unsigned int callback_time1;
+ int64_t callback_time0;
+ int64_t callback_time1;
#endif
};
@@ -56,7 +56,7 @@ static void audio_callback(void *userdata, Uint8 *stream, int len)
#ifdef ESTIMATE_DELAY
priv->callback_time1 = priv->callback_time0;
- priv->callback_time0 = GetTimer();
+ priv->callback_time0 = mp_time_us();
#endif
while (len > 0 && !priv->paused) {
@@ -160,32 +160,38 @@ static int init(struct ao *ao, char *params)
return -1;
}
+ struct mp_chmap_sel sel = {0};
+ mp_chmap_sel_add_waveext_def(&sel);
+ if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) {
+ uninit(ao, true);
+ return -1;
+ }
+
SDL_AudioSpec desired, obtained;
- int bytes = 0;
switch (ao->format) {
- case AF_FORMAT_U8: desired.format = AUDIO_U8; bytes = 1; break;
- case AF_FORMAT_S8: desired.format = AUDIO_S8; bytes = 1; break;
- case AF_FORMAT_U16_LE: desired.format = AUDIO_U16LSB; bytes = 2; break;
- case AF_FORMAT_U16_BE: desired.format = AUDIO_U16MSB; bytes = 2; break;
+ case AF_FORMAT_U8: desired.format = AUDIO_U8; break;
+ case AF_FORMAT_S8: desired.format = AUDIO_S8; break;
+ case AF_FORMAT_U16_LE: desired.format = AUDIO_U16LSB; break;
+ case AF_FORMAT_U16_BE: desired.format = AUDIO_U16MSB; break;
default:
- case AF_FORMAT_S16_LE: desired.format = AUDIO_S16LSB; bytes = 2; break;
- case AF_FORMAT_S16_BE: desired.format = AUDIO_S16MSB; bytes = 2; break;
+ case AF_FORMAT_S16_LE: desired.format = AUDIO_S16LSB; break;
+ case AF_FORMAT_S16_BE: desired.format = AUDIO_S16MSB; break;
#ifdef AUDIO_S32LSB
- case AF_FORMAT_S32_LE: desired.format = AUDIO_S32LSB; bytes = 4; break;
+ case AF_FORMAT_S32_LE: desired.format = AUDIO_S32LSB; break;
#endif
#ifdef AUDIO_S32MSB
- case AF_FORMAT_S32_BE: desired.format = AUDIO_S32MSB; bytes = 4; break;
+ case AF_FORMAT_S32_BE: desired.format = AUDIO_S32MSB; break;
#endif
#ifdef AUDIO_F32LSB
- case AF_FORMAT_FLOAT_LE: desired.format = AUDIO_F32LSB; bytes = 4; break;
+ case AF_FORMAT_FLOAT_LE: desired.format = AUDIO_F32LSB; break;
#endif
#ifdef AUDIO_F32MSB
- case AF_FORMAT_FLOAT_BE: desired.format = AUDIO_F32MSB; bytes = 4; break;
+ case AF_FORMAT_FLOAT_BE: desired.format = AUDIO_F32MSB; break;
#endif
}
desired.freq = ao->samplerate;
- desired.channels = ao->channels;
+ desired.channels = ao->channels.num;
desired.samples = FFMIN(32768, ceil_power_of_two(ao->samplerate * buflen));
desired.callback = audio_callback;
desired.userdata = ao;
@@ -210,23 +216,23 @@ static int init(struct ao *ao, char *params)
(int) obtained.format, (int) obtained.samples);
switch (obtained.format) {
- case AUDIO_U8: ao->format = AF_FORMAT_U8; bytes = 1; break;
- case AUDIO_S8: ao->format = AF_FORMAT_S8; bytes = 1; break;
- case AUDIO_S16LSB: ao->format = AF_FORMAT_S16_LE; bytes = 2; break;
- case AUDIO_S16MSB: ao->format = AF_FORMAT_S16_BE; bytes = 2; break;
- case AUDIO_U16LSB: ao->format = AF_FORMAT_U16_LE; bytes = 2; break;
- case AUDIO_U16MSB: ao->format = AF_FORMAT_U16_BE; bytes = 2; break;
+ case AUDIO_U8: ao->format = AF_FORMAT_U8; break;
+ case AUDIO_S8: ao->format = AF_FORMAT_S8; break;
+ case AUDIO_S16LSB: ao->format = AF_FORMAT_S16_LE; break;
+ case AUDIO_S16MSB: ao->format = AF_FORMAT_S16_BE; break;
+ case AUDIO_U16LSB: ao->format = AF_FORMAT_U16_LE; break;
+ case AUDIO_U16MSB: ao->format = AF_FORMAT_U16_BE; break;
#ifdef AUDIO_S32LSB
- case AUDIO_S32LSB: ao->format = AF_FORMAT_S32_LE; bytes = 4; break;
+ case AUDIO_S32LSB: ao->format = AF_FORMAT_S32_LE; break;
#endif
#ifdef AUDIO_S32MSB
- case AUDIO_S32MSB: ao->format = AF_FORMAT_S32_BE; bytes = 4; break;
+ case AUDIO_S32MSB: ao->format = AF_FORMAT_S32_BE; break;
#endif
#ifdef AUDIO_F32LSB
- case AUDIO_F32LSB: ao->format = AF_FORMAT_FLOAT_LE; bytes = 4; break;
+ case AUDIO_F32LSB: ao->format = AF_FORMAT_FLOAT_LE; break;
#endif
#ifdef AUDIO_F32MSB
- case AUDIO_F32MSB: ao->format = AF_FORMAT_FLOAT_BE; bytes = 4; break;
+ case AUDIO_F32MSB: ao->format = AF_FORMAT_FLOAT_BE; break;
#endif
default:
if (!ao->probing)
@@ -236,12 +242,13 @@ static int init(struct ao *ao, char *params)
return -1;
}
+ if (!ao_chmap_sel_get_def(ao, &sel, &ao->channels, obtained.channels)) {
+ uninit(ao, true);
+ return -1;
+ }
+
ao->samplerate = obtained.freq;
- ao->channels = obtained.channels;
- ao->bps = ao->channels * ao->samplerate * bytes;
- ao->buffersize = obtained.size * bufcnt;
- ao->outburst = obtained.size;
- priv->buffer = av_fifo_alloc(ao->buffersize);
+ priv->buffer = av_fifo_alloc(obtained.size * bufcnt);
priv->buffer_mutex = SDL_CreateMutex();
if (!priv->buffer_mutex) {
mp_msg(MSGT_AO, MSGL_ERR, "[sdl] SDL_CreateMutex failed\n");
@@ -257,7 +264,7 @@ static int init(struct ao *ao, char *params)
priv->unpause = 1;
priv->paused = 1;
- priv->callback_time0 = priv->callback_time1 = GetTimer();
+ priv->callback_time0 = priv->callback_time1 = mp_time_us();
return 1;
}
@@ -329,8 +336,8 @@ static float get_delay(struct ao *ao)
SDL_LockMutex(priv->buffer_mutex);
int sz = av_fifo_size(priv->buffer);
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0 = priv->callback_time0;
- unsigned int callback_time1 = priv->callback_time1;
+ int64_t callback_time0 = priv->callback_time0;
+ int64_t callback_time1 = priv->callback_time1;
#endif
SDL_UnlockMutex(priv->buffer_mutex);
@@ -340,16 +347,16 @@ static float get_delay(struct ao *ao)
#ifdef ESTIMATE_DELAY
// delay component: outstanding audio living in SDL
- unsigned int current_time = GetTimer();
+ int64_t current_time = mp_time_us();
// interval between callbacks
- unsigned int callback_interval = callback_time0 - callback_time1;
- unsigned int elapsed_interval = current_time - callback_time0;
+ int64_t callback_interval = callback_time0 - callback_time1;
+ int64_t elapsed_interval = current_time - callback_time0;
if (elapsed_interval > callback_interval)
elapsed_interval = callback_interval;
// delay subcomponent: remaining audio from the currently played buffer
- unsigned int buffer_interval = callback_interval - elapsed_interval;
+ int64_t buffer_interval = callback_interval - elapsed_interval;
// delay subcomponent: remaining audio from the next played buffer, as
// provided by the callback
@@ -362,7 +369,6 @@ static float get_delay(struct ao *ao)
}
const struct ao_driver audio_out_sdl = {
- .is_new = true,
.info = &(const struct ao_info) {
"SDL Audio",
"sdl",