2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2009 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file server/play.c
19 * @brief Playing tracks
21 * This file is rather badly organized. Sorry. It's better than it was...
24 #include "disorder-server.h"
27 #define SPEAKER "disorder-speaker"
29 /** @brief The current playing track or NULL */
30 struct queue_entry
*playing
;
32 /** @brief Set when paused */
35 static void finished(ev_source
*ev
);
36 static int start_child(struct queue_entry
*q
,
37 const struct pbgc_params
*params
,
38 void attribute((unused
)) *bgdata
);
39 static int prepare_child(struct queue_entry
*q
,
40 const struct pbgc_params
*params
,
41 void attribute((unused
)) *bgdata
);
42 static void ensure_next_scratch(ev_source
*ev
);
44 /** @brief File descriptor of our end of the socket to the speaker */
45 static int speaker_fd
= -1;
47 /** @brief Set when shutting down */
48 static int shutting_down
;
50 /* Speaker ------------------------------------------------------------------ */
52 /** @brief Called when speaker process terminates
54 * Currently kills of DisOrder completely. A future version could terminate
55 * the speaker when nothing was going on, or recover from failures, though any
56 * tracks with decoders already started would need to have them restarted.
58 static int speaker_terminated(ev_source
attribute((unused
)) *ev
,
59 pid_t
attribute((unused
)) pid
,
60 int attribute((unused
)) status
,
61 const struct rusage
attribute((unused
)) *rusage
,
62 void attribute((unused
)) *u
) {
63 disorder_fatal(0, "speaker subprocess %s", wstat(status
));
66 /** @brief Called when we get a message from the speaker process */
67 static int speaker_readable(ev_source
*ev
, int fd
,
68 void attribute((unused
)) *u
) {
69 struct speaker_message sm
;
70 int ret
= speaker_recv(fd
, &sm
);
72 if(ret
< 0) return 0; /* EAGAIN */
74 ev_fd_cancel(ev
, ev_read
, fd
);
79 /* track ID is paused, DATA seconds played */
80 D(("SM_PAUSED %s %ld", sm
.id
, sm
.data
));
81 playing
->sofar
= sm
.data
;
83 case SM_FINISHED
: /* scratched the playing track */
84 case SM_STILLBORN
: /* scratched too early */
85 case SM_UNKNOWN
: /* scratched WAY too early */
86 if(playing
&& !strcmp(sm
.id
, playing
->id
)) {
87 if((playing
->state
== playing_unplayed
88 || playing
->state
== playing_started
)
89 && sm
.type
== SM_FINISHED
)
90 playing
->state
= playing_ok
;
95 /* track ID is playing, DATA seconds played */
96 D(("SM_PLAYING %s %ld", sm
.id
, sm
.data
));
97 playing
->sofar
= sm
.data
;
100 /* track ID is now prepared */
101 struct queue_entry
*q
;
102 for(q
= qhead
.next
; q
!= &qhead
&& strcmp(q
->id
, sm
.id
); q
= q
->next
)
104 if(q
&& q
->preparing
) {
107 /* We might be waiting to play the now-prepared track */
113 disorder_error(0, "unknown speaker message type %d", sm
.type
);
118 /** @brief Initialize the speaker process */
119 void speaker_setup(ev_source
*ev
) {
122 struct speaker_message sm
;
124 if(socketpair(PF_UNIX
, SOCK_DGRAM
, 0, sp
) < 0)
125 disorder_fatal(errno
, "error calling socketpair");
126 if(!(pid
= xfork())) {
128 ev_signal_atfork(ev
);
133 signal(SIGPIPE
, SIG_DFL
);
135 execlp("valgrind", "valgrind", SPEAKER
, "--config", configfile
,
136 debugging ?
"--debug" : "--no-debug",
137 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
140 execlp(SPEAKER
, SPEAKER
, "--config", configfile
,
141 debugging ?
"--debug" : "--no-debug",
142 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
145 disorder_fatal(errno
, "error invoking %s", SPEAKER
);
147 ev_child(ev
, pid
, 0, speaker_terminated
, 0);
151 /* Wait for the speaker to be ready */
152 speaker_recv(speaker_fd
, &sm
);
153 nonblock(speaker_fd
);
154 if(ev_fd(ev
, ev_read
, speaker_fd
, speaker_readable
, 0, "speaker read") < 0)
155 disorder_fatal(0, "error registering speaker socket fd");
158 /** @brief Tell the speaker to reload its configuration */
159 void speaker_reload(void) {
160 struct speaker_message sm
;
162 memset(&sm
, 0, sizeof sm
);
164 speaker_send(speaker_fd
, &sm
);
167 /* Track termination -------------------------------------------------------- */
169 /** @brief Called when the currently playing track finishes playing
170 * @param ev Event loop or NULL
172 * There are three places this is called from:
174 * 1) speaker_readable(), when the speaker tells us the playing track finished.
175 * (Technically the speaker lies a little to arrange for gapless play.)
177 * 2) player_finished(), when the player for a non-raw track (i.e. one that
178 * does not use the speaker) finishes.
180 * 3) quitting(), after signalling the decoder or player but possible before it
181 * has actually terminated. In this case @p ev is NULL, inhibiting any further
182 * attempt to play anything.
184 static void finished(ev_source
*ev
) {
185 D(("finished playing=%p", (void *)playing
));
188 if(playing
->state
!= playing_scratched
)
189 notify_not_scratched(playing
->track
, playing
->submitter
);
190 switch(playing
->state
) {
192 eventlog("completed", playing
->track
, (char *)0);
194 case playing_scratched
:
195 eventlog("scratched", playing
->track
, playing
->scratched
, (char *)0);
198 eventlog("failed", playing
->track
, wstat(playing
->wstat
), (char *)0);
203 queue_played(playing
);
206 /* Try to play something else */
211 /** @brief Called when a player or decoder process terminates
213 * This is called when a decoder process terminates (which might actually be
214 * some time before the speaker reports it as finished) or when a non-raw
215 * (i.e. non-speaker) player terminates. In the latter case it's imaginable
216 * that the OS has buffered the last few samples.
218 * NB. The finished track might NOT be in the queue (yet) - it might be a
219 * pre-chosen scratch.
221 static int player_finished(ev_source
*ev
,
224 const struct rusage
attribute((unused
)) *rusage
,
226 struct queue_entry
*q
= u
;
228 D(("player_finished pid=%lu status=%#x",
229 (unsigned long)pid
, (unsigned)status
));
230 /* Record that this PID is dead. If we killed the track we might know this
231 * already, but also it might have exited or crashed. Either way we don't
232 * want to end up signalling it. */
235 case playing_unplayed
:
237 /* If this was a pre-prepared track then either it failed or we
238 * deliberately stopped it: it might have been removed from the queue, or
239 * moved down the queue, or the speaker might be on a break. So we leave
240 * it state alone for future use.
244 /* We actually started playing this track. */
246 /* Don't override 'scratched' with 'failed'. */
247 if(q
->state
!= playing_scratched
)
248 q
->state
= playing_failed
;
250 q
->state
= playing_ok
;
253 /* Regardless we always report and record the status and do cleanup for
256 disorder_error(0, "player for %s %s", q
->track
, wstat(status
));
257 if(q
->type
& DISORDER_PLAYER_PREFORK
)
258 play_cleanup(q
->pl
, q
->data
);
260 /* If this actually was the current track, and does not use the speaker
261 * process, then it must have finished. For raw-output players we will get a
262 * separate notification from the speaker process. */
264 && (q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
269 /* Track initiation --------------------------------------------------------- */
271 /** @brief Find the player for @p q */
272 static const struct stringlist
*find_player(const struct queue_entry
*q
) {
275 for(n
= 0; n
< config
->player
.n
; ++n
)
276 if(fnmatch(config
->player
.s
[n
].s
[0], q
->track
, 0) == 0)
278 if(n
>= config
->player
.n
)
281 return &config
->player
.s
[n
];
284 /** @brief Start to play @p q
285 * @param ev Event loop
286 * @param q Track to play/prepare
287 * @return @ref START_OK, @ref START_HARDFAIL or @ref START_SOFTFAIL
289 * This makes @p actually start playing. It calls prepare() if necessary and
290 * either sends an @ref SM_PLAY command or invokes the player itself in a
293 * It's up to the caller to set @ref playing and @c playing->state (this might
294 * be changed in the future).
296 static int start(ev_source
*ev
,
297 struct queue_entry
*q
) {
298 const struct stringlist
*player
;
301 D(("start %s", q
->id
));
302 /* Find the player plugin. */
303 if(!(player
= find_player(q
)))
304 return START_HARDFAIL
; /* No player */
305 if(!(q
->pl
= open_plugin(player
->s
[1], 0)))
306 return START_HARDFAIL
;
307 q
->type
= play_get_type(q
->pl
);
308 /* Special handling for raw-format players */
309 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) == DISORDER_PLAYER_RAW
) {
310 /* Make sure that the track is prepared */
311 if((rc
= prepare(ev
, q
)))
313 /* Now we're sure it's prepared, start it playing */
314 /* TODO actually it might not be fully prepared yet - it's all happening in
315 * a subprocess. See speaker.c for further discussion. */
316 struct speaker_message sm
[1];
317 memset(sm
, 0, sizeof sm
);
318 strcpy(sm
->id
, q
->id
);
320 speaker_send(speaker_fd
, sm
);
321 D(("sent SM_PLAY for %s", sm
->id
));
322 /* Our caller will set playing and playing->state = playing_started */
325 rc
= play_background(ev
, player
, q
, start_child
, NULL
);
327 ev_child(ev
, q
->pid
, 0, player_finished
, q
);
328 /* Our caller will set playing and playing->state = playing_started */
333 /** @brief Child-process half of start()
334 * @return Process exit code
336 * Called in subprocess to execute non-raw-format players (via plugin).
338 static int start_child(struct queue_entry
*q
,
339 const struct pbgc_params
*params
,
340 void attribute((unused
)) *bgdata
) {
345 params
->argv
, params
->argc
,
351 /** @brief Prepare a track for later play
352 * @return @ref START_OK, @ref START_HARDFAIL or @ref START_SOFTFAIL
354 * This can be called either when we want to play the track or slightly before
355 * so that some samples are decoded and available in a buffer.
357 * Only applies to raw-format (i.e. speaker-using) players; everything else
360 int prepare(ev_source
*ev
,
361 struct queue_entry
*q
) {
362 const struct stringlist
*player
;
364 /* If there's a decoder (or player!) going we do nothing */
367 /* If the track is already prepared, do nothing */
368 if(q
->prepared
|| q
->preparing
)
370 /* Find the player plugin */
371 if(!(player
= find_player(q
)))
372 return START_HARDFAIL
; /* No player */
373 q
->pl
= open_plugin(player
->s
[1], 0);
374 q
->type
= play_get_type(q
->pl
);
375 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
376 return START_OK
; /* Not a raw player */
377 int rc
= play_background(ev
, player
, q
, prepare_child
, NULL
);
379 ev_child(ev
, q
->pid
, 0, player_finished
, q
);
381 /* Actually the track is still "in flight" */
387 /** @brief Child-process half of prepare()
388 * @return Process exit code
390 * Called in subprocess to execute the decoder for a raw-format player.
392 * @todo We currently run the normalizer from here in a double-fork. This is
393 * unsatisfactory for many reasons: we can't prevent it outliving the main
394 * server and we don't adequately report its exit status.
396 static int prepare_child(struct queue_entry
*q
,
397 const struct pbgc_params
*params
,
398 void attribute((unused
)) *bgdata
) {
399 /* np will be the pipe to disorder-normalize */
401 if(socketpair(PF_UNIX
, SOCK_STREAM
, 0, np
) < 0)
402 disorder_fatal(errno
, "error calling socketpair");
403 /* Beware of the Leopard! On OS X 10.5.x, the order of the shutdown
404 * calls here DOES MATTER. If you do the SHUT_WR first then the SHUT_RD
405 * fails with "Socket is not connected". I think this is a bug but
406 * provided implementors either don't care about the order or all agree
407 * about the order, choosing the reliable order is an adequate
409 xshutdown(np
[1], SHUT_RD
); /* decoder writes to np[1] */
410 xshutdown(np
[0], SHUT_WR
); /* normalize reads from np[0] */
413 /* Start disorder-normalize. We double-fork so that nothing has to wait
414 * for disorder-normalize. */
416 if(!(npid
= xfork())) {
417 /* Grandchild of disorderd */
419 /* Great-grandchild of disorderd */
420 /* Connect to the speaker process */
421 struct sockaddr_un addr
;
422 memset(&addr
, 0, sizeof addr
);
423 addr
.sun_family
= AF_UNIX
;
424 snprintf(addr
.sun_path
, sizeof addr
.sun_path
,
425 "%s/speaker/socket", config
->home
);
426 int sfd
= xsocket(PF_UNIX
, SOCK_STREAM
, 0);
427 if(connect(sfd
, (const struct sockaddr
*)&addr
, sizeof addr
) < 0)
428 disorder_fatal(errno
, "connecting to %s", addr
.sun_path
);
429 /* Send the ID, with a NATIVE-ENDIAN 32 bit length */
430 uint32_t l
= strlen(q
->id
);
431 if(write(sfd
, &l
, sizeof l
) < 0
432 || write(sfd
, q
->id
, l
) < 0)
433 disorder_fatal(errno
, "writing to %s", addr
.sun_path
);
435 if (read(sfd
, &l
, 1) < 0)
436 disorder_fatal(errno
, "reading ack from %s", addr
.sun_path
);
443 /* TODO stderr shouldn't be redirected for disorder-normalize
444 * (but it should be for play_track() */
445 execlp("disorder-normalize", "disorder-normalize",
446 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
447 "--config", configfile
,
449 disorder_fatal(errno
, "executing disorder-normalize");
450 /* End of the great-grandchild of disorderd */
452 /* Back in the grandchild of disorderd */
454 /* End of the grandchild of disorderd */
456 /* Back in the child of disorderd */
457 /* Wait for the grandchild of disordered to finish */
459 while(waitpid(npid
, &n
, 0) < 0 && errno
== EINTR
)
461 /* Pass the file descriptor to the driver in an environment
464 snprintf(buffer
, sizeof buffer
, "DISORDER_RAW_FD=%d", np
[1]);
465 if(putenv(buffer
) < 0)
466 disorder_fatal(errno
, "error calling putenv");
467 /* Close all the FDs we don't need */
469 /* Start the decoder itself */
471 params
->argv
, params
->argc
,
477 /** @brief Abandon a queue entry
479 * Called from c_remove() (but NOT when scratching a track). Only does
480 * anything to raw-format tracks. Terminates the background decoder and tells
481 * the speaker process to cancel the track.
483 void abandon(ev_source
attribute((unused
)) *ev
,
484 struct queue_entry
*q
) {
485 struct speaker_message sm
;
488 return; /* Not prepared. */
489 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
490 return; /* Not a raw player. */
491 /* Terminate the player. */
492 kill(-q
->pid
, config
->signal
);
493 /* Cancel the track. */
494 memset(&sm
, 0, sizeof sm
);
496 strcpy(sm
.id
, q
->id
);
497 speaker_send(speaker_fd
, &sm
);
500 /* Random tracks ------------------------------------------------------------ */
502 /** @brief Called with a new random track
503 * @param ev Event loop
504 * @param track Track name
506 static void chosen_random_track(ev_source
*ev
,
508 struct queue_entry
*q
;
512 /* Add the track to the queue */
513 q
= queue_add(track
, 0, WHERE_END
, NULL
, origin_random
);
514 D(("picked %p (%s) at random", (void *)q
, q
->track
));
516 /* Maybe a track can now be played */
520 /** @brief Maybe add a randomly chosen track
521 * @param ev Event loop
523 * Picking can take some time so the track will only be added after this
524 * function has returned.
526 void add_random_track(ev_source
*ev
) {
527 struct queue_entry
*q
;
530 /* If random play is not enabled then do nothing. */
531 if(shutting_down
|| !random_is_enabled())
533 /* Count how big the queue is */
534 for(q
= qhead
.next
; q
!= &qhead
; q
= q
->next
)
536 /* If it's smaller than the desired size then add a track */
537 if(qlen
< config
->queue_pad
)
538 trackdb_request_random(ev
, chosen_random_track
);
541 /* Track initiation (part 2) ------------------------------------------------ */
543 /** @brief Attempt to play something
545 * This is called from numerous locations - whenever it might conceivably have
546 * become possible to play something.
548 void play(ev_source
*ev
) {
549 struct queue_entry
*q
;
550 int random_enabled
= random_is_enabled();
552 D(("play playing=%p", (void *)playing
));
553 /* If we're shutting down, or there's something playing, or playing is not
554 * enabled, give up now */
555 if(shutting_down
|| playing
|| !playing_is_enabled()) return;
556 /* See if there's anything to play */
557 if(qhead
.next
== &qhead
) {
558 /* Queue is empty. We could just wait around since there are periodic
559 * attempts to add a random track anyway. However they are rarer than
560 * attempts to force a track so we initiate one now. */
561 add_random_track(ev
);
562 /* chosen_random_track() will call play() when a new random track has been
563 * added to the queue. */
566 /* There must be at least one track in the queue. */
568 /* If random play is disabled but the track is a non-adopted random one
569 * then don't play it. play() will be called again when random play is
571 if(!random_enabled
&& q
->origin
== origin_random
)
573 D(("taken %p (%s) from queue", (void *)q
, q
->track
));
574 /* Try to start playing. */
575 switch(start(ev
, q
)) {
577 if(q
== qhead
.next
) {
578 queue_remove(q
, 0); /* Abandon this track. */
582 /* Oh well, try the next one */
586 /* We'll try the same track again shortly. */
589 /* Remove from the queue */
590 if(q
== qhead
.next
) {
594 /* It's become the playing track */
596 xtime(&playing
->played
);
597 playing
->state
= playing_started
;
598 notify_play(playing
->track
, playing
->submitter
);
599 eventlog("playing", playing
->track
,
600 playing
->submitter ? playing
->submitter
: (const char *)0,
602 /* Maybe add a random track. */
603 add_random_track(ev
);
604 /* If there is another track in the queue prepare it now. This could
605 * potentially be a just-added random track. */
606 if(qhead
.next
!= &qhead
)
607 prepare(ev
, qhead
.next
);
608 /* Make sure there is a prepared scratch */
609 ensure_next_scratch(ev
);
614 /* Miscelleneous ------------------------------------------------------------ */
616 int flag_enabled(const char *s
) {
617 return !s
|| !strcmp(s
, "yes");
620 /** @brief Return true if play is enabled */
621 int playing_is_enabled(void) {
622 return flag_enabled(trackdb_get_global("playing"));
625 /** @brief Enable play */
626 void enable_playing(const char *who
, ev_source
*ev
) {
627 trackdb_set_global("playing", "yes", who
);
628 /* Add a random track if necessary. */
629 add_random_track(ev
);
633 /** @brief Disable play */
634 void disable_playing(const char *who
, ev_source
attribute((unused
)) *ev
) {
635 trackdb_set_global("playing", "no", who
);
638 /** @brief Return true if random play is enabled */
639 int random_is_enabled(void) {
640 return flag_enabled(trackdb_get_global("random-play"));
643 /** @brief Enable random play */
644 void enable_random(const char *who
, ev_source
*ev
) {
645 trackdb_set_global("random-play", "yes", who
);
646 add_random_track(ev
);
650 /** @brief Disable random play */
651 void disable_random(const char *who
, ev_source
attribute((unused
)) *ev
) {
652 trackdb_set_global("random-play", "no", who
);
655 /* Scratching --------------------------------------------------------------- */
657 /** @brief Track to play next time something is scratched */
658 static struct queue_entry
*next_scratch
;
660 /** @brief Ensure there isa prepared scratch */
661 static void ensure_next_scratch(ev_source
*ev
) {
662 if(next_scratch
) /* There's one already */
664 if(!config
->scratch
.n
) /* There are no scratches */
666 int r
= rand() * (double)config
->scratch
.n
/ (RAND_MAX
+ 1.0);
667 next_scratch
= queue_add(config
->scratch
.s
[r
], NULL
,
668 WHERE_NOWHERE
, NULL
, origin_scratch
);
670 prepare(ev
, next_scratch
);
673 /** @brief Scratch a track
674 * @param who User responsible (or NULL)
675 * @param id Track ID (or NULL for current)
677 void scratch(const char *who
, const char *id
) {
678 struct speaker_message sm
;
680 D(("scratch playing=%p state=%d id=%s playing->id=%s",
682 playing ? playing
->state
: 0,
684 playing ? playing
->id
: "(none)"));
685 /* There must be a playing track; it must be in a scratchable state; if a
686 * specific ID was mentioned it must be that track. */
688 && (playing
->state
== playing_started
689 || playing
->state
== playing_paused
)
691 || !strcmp(id
, playing
->id
))) {
692 /* Update state (for the benefit of the 'recent' list) */
693 playing
->state
= playing_scratched
;
694 playing
->scratched
= who ?
xstrdup(who
) : 0;
695 /* Find the player and kill the whole process group */
696 if(playing
->pid
>= 0) {
697 D(("kill -%d -%lu", config
->signal
, (unsigned long)playing
->pid
));
698 kill(-playing
->pid
, config
->signal
);
700 /* Tell the speaker, if we think it'll care */
701 if((playing
->type
& DISORDER_PLAYER_TYPEMASK
) == DISORDER_PLAYER_RAW
) {
702 memset(&sm
, 0, sizeof sm
);
704 strcpy(sm
.id
, playing
->id
);
705 speaker_send(speaker_fd
, &sm
);
706 D(("sending SM_CANCEL for %s", playing
->id
));
708 /* If playing is enabled then add a scratch to the queue. Having a scratch
709 * appear in the queue when further play is disabled is weird and
710 * contradicts implicit assumptions made elsewhere, so we try to avoid
712 if(playing_is_enabled()) {
713 /* Try to make sure there is a scratch */
714 ensure_next_scratch(NULL
);
715 /* Insert it at the head of the queue */
717 next_scratch
->submitter
= who
;
718 queue_insert_entry(&qhead
, next_scratch
);
719 eventlog_raw("queue", queue_marshall(next_scratch
), (const char *)0);
723 notify_scratch(playing
->track
, playing
->submitter
, who
,
724 xtime(0) - playing
->played
);
728 /* Server termination ------------------------------------------------------- */
730 /** @brief Called from quit() to tear down everything belonging to this file */
731 void quitting(ev_source
*ev
) {
732 struct queue_entry
*q
;
734 /* Don't start anything new */
736 /* Shut down the current player */
738 if(playing
->pid
>= 0)
739 kill(-playing
->pid
, config
->signal
);
740 playing
->state
= playing_quitting
;
743 /* Zap any background decoders that are going */
744 for(q
= qhead
.next
; q
!= &qhead
; q
= q
->next
)
746 D(("kill -%d %lu", config
->signal
, (unsigned long)q
->pid
));
747 kill(-q
->pid
, config
->signal
);
749 /* Don't need the speaker any more */
750 ev_fd_cancel(ev
, ev_read
, speaker_fd
);
754 /* Pause and resume --------------------------------------------------------- */
756 /** @brief Pause the playing track */
757 int pause_playing(const char *who
) {
758 struct speaker_message sm
;
761 /* Can't pause if already paused or if nothing playing. */
762 if(!playing
|| paused
) return 0;
763 switch(playing
->type
& DISORDER_PLAYER_TYPEMASK
) {
764 case DISORDER_PLAYER_STANDALONE
:
765 if(!(playing
->type
& DISORDER_PLAYER_PAUSES
)) {
767 disorder_error(0, "cannot pause because player is not powerful enough");
770 if(play_pause(playing
->pl
, &played
, playing
->data
)) {
771 disorder_error(0, "player indicates it cannot pause");
774 xtime(&playing
->lastpaused
);
775 playing
->uptopause
= played
;
776 playing
->lastresumed
= 0;
778 case DISORDER_PLAYER_RAW
:
779 memset(&sm
, 0, sizeof sm
);
781 speaker_send(speaker_fd
, &sm
);
785 disorder_info("paused by %s", who
);
786 notify_pause(playing
->track
, who
);
788 if(playing
->state
== playing_started
)
789 playing
->state
= playing_paused
;
790 eventlog("state", "pause", (char *)0);
794 /** @brief Resume playing after a pause */
795 void resume_playing(const char *who
) {
796 struct speaker_message sm
;
801 switch(playing
->type
& DISORDER_PLAYER_TYPEMASK
) {
802 case DISORDER_PLAYER_STANDALONE
:
803 if(!(playing
->type
& DISORDER_PLAYER_PAUSES
)) {
805 /* Shouldn't happen */
808 play_resume(playing
->pl
, playing
->data
);
809 xtime(&playing
->lastresumed
);
811 case DISORDER_PLAYER_RAW
:
812 memset(&sm
, 0, sizeof sm
);
814 speaker_send(speaker_fd
, &sm
);
817 if(who
) disorder_info("resumed by %s", who
);
818 notify_resume(playing
->track
, who
);
819 if(playing
->state
== playing_paused
)
820 playing
->state
= playing_started
;
821 eventlog("state", "resume", (char *)0);