Clean up ALSA plug a bit.

This commit is contained in:
Themaister 2012-04-25 19:49:11 +02:00
parent dbfd847a60
commit 6b6e1556f6
3 changed files with 15 additions and 12 deletions

View File

@ -119,21 +119,20 @@ error:
return NULL; return NULL;
} }
static ssize_t alsa_write(void *data, const void *buf, size_t size) static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
{ {
alsa_t *alsa = (alsa_t*)data; alsa_t *alsa = (alsa_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
snd_pcm_sframes_t frames;
snd_pcm_sframes_t written = 0; snd_pcm_sframes_t written = 0;
int rc; snd_pcm_sframes_t size = snd_pcm_bytes_to_frames(alsa->pcm, size_);
size = snd_pcm_bytes_to_frames(alsa->pcm, size); // Frames to write
while (written < (snd_pcm_sframes_t)size) while (size)
{ {
if (!alsa->nonblock) if (!alsa->nonblock)
{ {
rc = snd_pcm_wait(alsa->pcm, -1); int rc = snd_pcm_wait(alsa->pcm, -1);
if (rc == -EPIPE || rc == -ESTRPIPE) if (rc == -EPIPE || rc == -ESTRPIPE || rc == -EINTR)
{ {
if (snd_pcm_recover(alsa->pcm, rc, 1) < 0) if (snd_pcm_recover(alsa->pcm, rc, 1) < 0)
return -1; return -1;
@ -141,24 +140,26 @@ static ssize_t alsa_write(void *data, const void *buf, size_t size)
} }
} }
frames = snd_pcm_writei(alsa->pcm, (const char*)buf + written * 2 * (alsa->has_float ? sizeof(float) : sizeof(int16_t)), size - written); snd_pcm_sframes_t frames = snd_pcm_writei(alsa->pcm, buf, size);
if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE) if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE)
{ {
if (snd_pcm_recover(alsa->pcm, frames, 1) < 0) if (snd_pcm_recover(alsa->pcm, frames, 1) < 0)
return -1; return -1;
return 0; break;
} }
else if (frames == -EAGAIN && alsa->nonblock) else if (frames == -EAGAIN && alsa->nonblock)
return 0; break;
else if (frames < 0) else if (frames < 0)
return -1; return -1;
written += frames; written += frames;
buf += (frames << 1) * (alsa->has_float ? sizeof(float) : sizeof(int16_t));
size -= frames;
} }
return snd_pcm_frames_to_bytes(alsa->pcm, size); return written;
} }
static bool alsa_stop(void *data) static bool alsa_stop(void *data)
@ -180,6 +181,7 @@ static bool alsa_start(void *data)
static void alsa_free(void *data) static void alsa_free(void *data)
{ {
alsa_t *alsa = (alsa_t*)data; alsa_t *alsa = (alsa_t*)data;
if (alsa) if (alsa)
{ {
if (alsa->pcm) if (alsa->pcm)

View File

@ -113,6 +113,7 @@ static ssize_t oss_write(void *data, const void *buf, size_t size)
{ {
if ((fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN) if ((fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN)
return 0; return 0;
return -1; return -1;
} }

View File

@ -474,7 +474,7 @@ extern struct console_settings g_console;
#ifndef RARCH_LOG #ifndef RARCH_LOG
#define RARCH_LOG(...) do { \ #define RARCH_LOG(...) do { \
if (g_extern.verbose) \ if (g_extern.verbose) \
fprintf(stderr, "SSNES: " __VA_ARGS__); \ fprintf(stderr, "RetroArch: " __VA_ARGS__); \
fflush(stderr); \ fflush(stderr); \
} while (0) } while (0)
#endif #endif