From 66bb2e02f95baed39eac2f3b1b11053d1e2a4c21 Mon Sep 17 00:00:00 2001 Message-Id: <66bb2e02f95baed39eac2f3b1b11053d1e2a4c21.1714794076.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 2 Dec 2007 18:10:08 +0000 Subject: [PATCH] record whether tracks are connected to speaker in a sane and working way Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/queue.h | 1 + server/play.c | 19 +++++++++++-------- server/server-queue.c | 4 ++-- server/speaker.c | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/queue.h b/lib/queue.h index 3ae4c26..ce43fc5 100644 --- a/lib/queue.h +++ b/lib/queue.h @@ -54,6 +54,7 @@ struct queue_entry { const struct plugin *pl; /* plugin that's playing this track */ void *data; /* player data */ long sofar; /* how much played so far */ + int prepared; /* true when connected to speaker */ /* For DISORDER_PLAYER_PAUSES only: */ time_t lastpaused, lastresumed; /* when last paused/resumed, or 0 */ long uptopause; /* how much played up to last pause */ diff --git a/server/play.c b/server/play.c index bd27474..7b70799 100644 --- a/server/play.c +++ b/server/play.c @@ -312,14 +312,16 @@ static int start(ev_source *ev, memset(&sm, 0, sizeof sm); D(("start %s %d", q->id, prepare_only)); - if(find_player_pid(q->id) > 0) { - if(prepare_only) return START_OK; - /* We have already prepared this track so we just need to tell the speaker - * process to start actually playing the queued up audio data */ - strcpy(sm.id, q->id); - sm.type = SM_PLAY; - speaker_send(speaker_fd, &sm); - D(("sent SM_PLAY for %s", sm.id)); + if(q->prepared) { + /* The track is alraedy prepared */ + if(!prepare_only) { + /* We want to run it, since it's prepared the answer is to tell the + * speaker to set it off */ + strcpy(sm.id, q->id); + sm.type = SM_PLAY; + speaker_send(speaker_fd, &sm); + D(("sent SM_PLAY for %s", sm.id)); + } return START_OK; } /* Find the player plugin. */ @@ -478,6 +480,7 @@ static int start(ev_source *ev, return START_SOFTFAIL; } store_player_pid(q->id, pid); + q->prepared = 1; if(lfd != -1) xclose(lfd); setpgid(pid, pid); diff --git a/server/server-queue.c b/server/server-queue.c index 2b0e89e..7126288 100644 --- a/server/server-queue.c +++ b/server/server-queue.c @@ -41,11 +41,11 @@ #include "disorder.h" /* the head of the queue is played next, so normally we add to the tail */ -struct queue_entry qhead = { &qhead, &qhead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +struct queue_entry qhead = { &qhead, &qhead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* the head of the recent list is the oldest thing, the tail the most recently * played */ -struct queue_entry phead = { &phead, &phead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +struct queue_entry phead = { &phead, &phead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static long pcount; diff --git a/server/speaker.c b/server/speaker.c index 55dde7e..fabdfc4 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -495,7 +495,7 @@ static void mainloop(void) { t = findtrack(id, 1/*create*/); write(fd, "", 1); /* write an ack */ if(t->fd != -1) { - error(0, "got a connection for a track that already has one"); + error(0, "%s: already got a connection", id); xclose(fd); } else { nonblock(fd); -- [mdw]