aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-27 23:05:56 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-27 23:05:56 +0000
commit5622edbc98f55852bc079a50690137232fbd82a1 (patch)
treed95028bf2c2231a3229c33ac92c05551251fd339
parent8b19235b6113d869fba1239ac4d1406d6d7310b8 (diff)
downloadmpd-5622edbc98f55852bc079a50690137232fbd82a1.tar.gz
mpd-5622edbc98f55852bc079a50690137232fbd82a1.tar.xz
mpd-5622edbc98f55852bc079a50690137232fbd82a1.zip
cleanup audio code some
git-svn-id: https://svn.musicpd.org/mpd/trunk@108 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/audio.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/audio.c b/src/audio.c
index f014235df..d1f8d863c 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -131,11 +131,12 @@ int isCurrentAudioFormat(AudioFormat * audioFormat) {
int initAudio(AudioFormat * audioFormat) {
ao_sample_format format;
- if(!isCurrentAudioFormat(audioFormat)) {
- finishAudio();
- }
-
if(!audio_device) {
+ if(!isCurrentAudioFormat(audioFormat)) {
+ finishAudio();
+ return 0;
+ }
+
format.bits = audioFormat->bits;
format.rate = audioFormat->sampleRate;
format.byte_format = AO_FMT_NATIVE;
@@ -145,16 +146,11 @@ int initAudio(AudioFormat * audioFormat) {
audio_format.channels = format.channels;
blockSignals();
-
audio_device = ao_open_live(audio_ao_driver_id, &format,
audio_ao_options);
-
- if(audio_device==NULL) {
- unblockSignals();
- audioError();
- return -1;
- }
unblockSignals();
+
+ if(audio_device==NULL) return -1;
}
return 0;
@@ -163,13 +159,18 @@ int initAudio(AudioFormat * audioFormat) {
void playAudio(char * playChunk, int size) {
int send;
-
- assert(audio_device!=NULL);
+ if(audio_device==NULL) return 0;
+
while(size>0) {
send = audio_write_size>size?size:audio_write_size;
- ao_play(audio_device,playChunk,send);
+ if(!ao_play(audio_device,playChunk,send)) {
+ audioError();
+ ERROR("closing audio device due to write error\n");
+ finishAudio();
+ return;
+ }
playChunk+=send;
size-=send;