Update SDL to 2.0.7

This commit is contained in:
Alex Szpakowski
2017-10-28 22:36:09 -03:00
parent 7d27167be2
commit 4a2fd6d703
1400 changed files with 52242 additions and 127752 deletions
+53 -41
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -26,7 +26,6 @@
#include <sys/types.h>
#include <signal.h> /* For kill() */
#include <errno.h>
#include <string.h>
#include "SDL_assert.h"
@@ -310,12 +309,14 @@ swizzle_alsa_channels(_THIS, void *buffer, Uint32 bufferlen)
/* !!! FIXME: update this for 7.1 if needed, later. */
}
#ifdef SND_CHMAP_API_VERSION
/* Some devices have the right channel map, no swizzling necessary */
static void
no_swizzle(_THIS, void *buffer, Uint32 bufferlen)
{
return;
}
#endif /* SND_CHMAP_API_VERSION */
static void
@@ -329,20 +330,7 @@ ALSA_PlayDevice(_THIS)
this->hidden->swizzle_func(this, this->hidden->mixbuf, frames_left);
while ( frames_left > 0 && SDL_AtomicGet(&this->enabled) ) {
int status;
/* This wait is a work-around for a hang when USB devices are
unplugged. Normally it should not result in any waiting,
but in the case of a USB unplug, it serves as a way to
join the playback thread after the timeout occurs */
status = ALSA_snd_pcm_wait(this->hidden->pcm_handle, 1000);
if (status == 0) {
/*fprintf(stderr, "ALSA timeout waiting for available buffer space\n");*/
SDL_OpenedAudioDeviceDisconnected(this);
return;
}
status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
int status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
sample_buf, frames_left);
if (status < 0) {
@@ -362,6 +350,13 @@ ALSA_PlayDevice(_THIS)
}
continue;
}
else if (status == 0) {
/* No frames were written (no available space in pcm device).
Allow other threads to catch up. */
Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
SDL_Delay(delay);
}
sample_buf += status * frame_size;
frames_left -= status;
}
@@ -381,23 +376,22 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
this->spec.channels;
const int total_frames = buflen / frame_size;
snd_pcm_uframes_t frames_left = total_frames;
snd_pcm_uframes_t wait_time = frame_size / 2;
SDL_assert((buflen % frame_size) == 0);
while ( frames_left > 0 && SDL_AtomicGet(&this->enabled) ) {
/* !!! FIXME: This works, but needs more testing before going live */
/* ALSA_snd_pcm_wait(this->hidden->pcm_handle, -1); */
int status = ALSA_snd_pcm_readi(this->hidden->pcm_handle,
int status;
status = ALSA_snd_pcm_readi(this->hidden->pcm_handle,
sample_buf, frames_left);
if (status < 0) {
if (status == -EAGAIN) {
ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
status = 0;
}
else if (status < 0) {
/*printf("ALSA: capture error %d\n", status);*/
if (status == -EAGAIN) {
/* Apparently snd_pcm_recover() doesn't handle this case -
does it assume snd_pcm_wait() above? */
SDL_Delay(1);
continue;
}
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
if (status < 0) {
/* Hmm, not much we can do - abort */
@@ -743,8 +737,9 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
}
/* Switch to blocking mode for playback */
ALSA_snd_pcm_nonblock(pcm_handle, 0);
if (!iscapture) {
ALSA_snd_pcm_nonblock(pcm_handle, 0);
}
/* We're ready to rock and roll. :-) */
return 0;
@@ -761,18 +756,28 @@ static void
add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSeen)
{
ALSA_Device *dev = SDL_malloc(sizeof (ALSA_Device));
char *desc = ALSA_snd_device_name_get_hint(hint, "DESC");
char *desc;
char *handle = NULL;
char *ptr;
if (!desc) {
SDL_free(dev);
return;
} else if (!dev) {
free(desc);
if (!dev) {
return;
}
/* Not all alsa devices are enumerable via snd_device_name_get_hint
(i.e. bluetooth devices). Therefore if hint is passed in to this
function as NULL, assume name contains desc.
Make sure not to free the storage associated with desc in this case */
if (hint) {
desc = ALSA_snd_device_name_get_hint(hint, "DESC");
if (!desc) {
SDL_free(dev);
return;
}
} else {
desc = (char *) name;
}
SDL_assert(name != NULL);
/* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
@@ -786,14 +791,16 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
handle = SDL_strdup(name);
if (!handle) {
free(desc);
if (hint) {
free(desc);
}
SDL_free(dev);
return;
}
SDL_AddAudioDevice(iscapture, desc, handle);
free(desc);
if (hint)
free(desc);
dev->name = handle;
dev->iscapture = iscapture;
dev->next = *pSeen;
@@ -813,12 +820,15 @@ ALSA_HotplugThread(void *arg)
ALSA_Device *dev;
Uint32 ticks;
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
while (!SDL_AtomicGet(&ALSA_hotplug_shutdown)) {
void **hints = NULL;
ALSA_Device *unseen;
ALSA_Device *seen;
ALSA_Device *prev;
if (ALSA_snd_device_name_hint(-1, "pcm", &hints) != -1) {
ALSA_Device *unseen = devices;
ALSA_Device *seen = NULL;
ALSA_Device *prev;
int i, j;
const char *match = NULL;
int bestmatch = 0xFFFF;
@@ -828,6 +838,8 @@ ALSA_HotplugThread(void *arg)
"hw:", "sysdefault:", "default:", NULL
};
unseen = devices;
seen = NULL;
/* Apparently there are several different ways that ALSA lists
actual hardware. It could be prefixed with "hw:" or "default:"
or "sysdefault:" and maybe others. Go through the list and see
@@ -922,7 +934,7 @@ ALSA_HotplugThread(void *arg)
/* report anything still in unseen as removed. */
for (dev = unseen; dev; dev = next) {
/*printf("ALSA: removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
/*printf("ALSA: removing usb %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
next = dev->next;
SDL_RemoveAudioDevice(dev->iscapture, dev->name);
SDL_free(dev->name);
+4 -4
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -20,8 +20,8 @@
*/
#include "../../SDL_internal.h"
#ifndef _SDL_ALSA_audio_h
#define _SDL_ALSA_audio_h
#ifndef SDL_ALSA_audio_h_
#define SDL_ALSA_audio_h_
#include <alsa/asoundlib.h>
@@ -43,6 +43,6 @@ struct SDL_PrivateAudioData
void (*swizzle_func)(_THIS, void *buffer, Uint32 bufferlen);
};
#endif /* _SDL_ALSA_audio_h */
#endif /* SDL_ALSA_audio_h_ */
/* vi: set ts=4 sw=4 expandtab: */