2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2012 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"
26 #define SPEAKER "disorder-speaker"
28 /** @brief The current playing track or NULL */
29 struct queue_entry
*playing
;
31 /** @brief Set when paused */
34 static void finished(ev_source
*ev
);
35 static int start_child(struct queue_entry
*q
,
36 const struct pbgc_params
*params
,
37 void attribute((unused
)) *bgdata
);
38 static int prepare_child(struct queue_entry
*q
,
39 const struct pbgc_params
*params
,
40 void attribute((unused
)) *bgdata
);
41 static void ensure_next_scratch(ev_source
*ev
);
43 /** @brief File descriptor of our end of the socket to the speaker */
44 static int speaker_fd
= -1;
46 /** @brief Set when shutting down */
47 static int shutting_down
;
49 /* Speaker ------------------------------------------------------------------ */
51 /** @brief Called when speaker process terminates
53 * Currently kills of DisOrder completely. A future version could terminate
54 * the speaker when nothing was going on, or recover from failures, though any
55 * tracks with decoders already started would need to have them restarted.
57 static int speaker_terminated(ev_source
attribute((unused
)) *ev
,
58 pid_t
attribute((unused
)) pid
,
59 int attribute((unused
)) status
,
60 const struct rusage
attribute((unused
)) *rusage
,
61 void attribute((unused
)) *u
) {
62 disorder_fatal(0, "speaker subprocess %s", wstat(status
));
65 /** @brief Called when we get a message from the speaker process */
66 static int speaker_readable(ev_source
*ev
, int fd
,
67 void attribute((unused
)) *u
) {
68 struct speaker_message sm
;
69 int ret
= speaker_recv(fd
, &sm
);
71 if(ret
< 0) return 0; /* EAGAIN */
73 ev_fd_cancel(ev
, ev_read
, fd
);
78 /* track ID is paused, DATA seconds played */
79 D(("SM_PAUSED %s %ld", sm
.u
.id
, sm
.data
));
80 playing
->sofar
= sm
.data
;
82 case SM_FINISHED
: /* scratched the playing track */
83 case SM_STILLBORN
: /* scratched too early */
84 case SM_UNKNOWN
: /* scratched WAY too early */
85 if(playing
&& !strcmp(sm
.u
.id
, playing
->id
)) {
86 if((playing
->state
== playing_unplayed
87 || playing
->state
== playing_started
)
88 && sm
.type
== SM_FINISHED
)
89 playing
->state
= playing_ok
;
94 /* track ID is playing, DATA seconds played */
95 D(("SM_PLAYING %s %ld", sm
.u
.id
, sm
.data
));
96 playing
->sofar
= sm
.data
;
99 /* track ID is now prepared */
100 struct queue_entry
*q
;
101 for(q
= qhead
.next
; q
!= &qhead
&& strcmp(q
->id
, sm
.u
.id
); q
= q
->next
)
103 if(q
&& q
->preparing
) {
106 /* We might be waiting to play the now-prepared track */
112 disorder_error(0, "unknown speaker message type %d", sm
.type
);
117 /** @brief Initialize the speaker process */
118 void speaker_setup(ev_source
*ev
) {
121 struct speaker_message sm
;
123 if(socketpair(PF_UNIX
, SOCK_DGRAM
, 0, sp
) < 0)
124 disorder_fatal(errno
, "error calling socketpair");
125 if(!(pid
= xfork())) {
127 ev_signal_atfork(ev
);
132 signal(SIGPIPE
, SIG_DFL
);
134 execlp("valgrind", "valgrind", SPEAKER
, "--config", configfile
,
135 debugging ?
"--debug" : "--no-debug",
136 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
139 execlp(SPEAKER
, SPEAKER
, "--config", configfile
,
140 debugging ?
"--debug" : "--no-debug",
141 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
144 disorder_fatal(errno
, "error invoking %s", SPEAKER
);
146 ev_child(ev
, pid
, 0, speaker_terminated
, 0);
150 /* Wait for the speaker to be ready */
151 speaker_recv(speaker_fd
, &sm
);
152 nonblock(speaker_fd
);
153 if(ev_fd(ev
, ev_read
, speaker_fd
, speaker_readable
, 0, "speaker read") < 0)
154 disorder_fatal(0, "error registering speaker socket fd");
157 /** @brief Tell the speaker to reload its configuration */
158 void speaker_reload(void) {
159 struct speaker_message sm
;
161 memset(&sm
, 0, sizeof sm
);
163 speaker_send(speaker_fd
, &sm
);
166 /* Track termination -------------------------------------------------------- */
168 /** @brief Called when the currently playing track finishes playing
169 * @param ev Event loop or NULL
171 * There are three places this is called from:
173 * 1) speaker_readable(), when the speaker tells us the playing track finished.
174 * (Technically the speaker lies a little to arrange for gapless play.)
176 * 2) player_finished(), when the player for a non-raw track (i.e. one that
177 * does not use the speaker) finishes.
179 * 3) quitting(), after signalling the decoder or player but possible before it
180 * has actually terminated. In this case @p ev is NULL, inhibiting any further
181 * attempt to play anything.
183 static void finished(ev_source
*ev
) {
184 D(("finished playing=%p", (void *)playing
));
187 if(playing
->state
!= playing_scratched
)
188 notify_not_scratched(playing
->track
, playing
->submitter
);
189 switch(playing
->state
) {
191 eventlog("completed", playing
->track
, (char *)0);
193 case playing_scratched
:
194 eventlog("scratched", playing
->track
, playing
->scratched
, (char *)0);
197 eventlog("failed", playing
->track
, wstat(playing
->wstat
), (char *)0);
202 queue_played(playing
);
205 /* Try to play something else */
210 /** @brief Called when a player or decoder process terminates
212 * This is called when a decoder process terminates (which might actually be
213 * some time before the speaker reports it as finished) or when a non-raw
214 * (i.e. non-speaker) player terminates. In the latter case it's imaginable
215 * that the OS has buffered the last few samples.
217 * NB. The finished track might NOT be in the queue (yet) - it might be a
218 * pre-chosen scratch.
220 static int player_finished(ev_source
*ev
,
223 const struct rusage
attribute((unused
)) *rusage
,
225 struct queue_entry
*q
= u
;
227 D(("player_finished pid=%lu status=%#x",
228 (unsigned long)pid
, (unsigned)status
));
229 /* Record that this PID is dead. If we killed the track we might know this
230 * already, but also it might have exited or crashed. Either way we don't
231 * want to end up signalling it. */
234 case playing_unplayed
:
236 /* If this was a pre-prepared track then either it failed or we
237 * deliberately stopped it: it might have been removed from the queue, or
238 * moved down the queue, or the speaker might be on a break. So we leave
239 * it state alone for future use.
243 /* We actually started playing this track. */
245 /* Don't override 'scratched' with 'failed'. */
246 if(q
->state
!= playing_scratched
)
247 q
->state
= playing_failed
;
249 q
->state
= playing_ok
;
252 /* Report the status unless we killed it */
254 if(!(q
->killed
&& WIFSIGNALED(status
) && WTERMSIG(status
) == q
->killed
))
255 disorder_error(0, "player for %s %s", q
->track
, wstat(status
));
257 /* Clean up any prefork calls */
258 if(q
->type
& DISORDER_PLAYER_PREFORK
)
259 play_cleanup(q
->pl
, q
->data
);
261 /* If this actually was the current track, and does not use the speaker
262 * process, then it must have finished. For raw-output players we will get a
263 * separate notification from the speaker process. */
265 && (q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
270 /* Track initiation --------------------------------------------------------- */
272 /** @brief Find the player for @p q */
273 static const struct stringlist
*find_player(const struct queue_entry
*q
) {
276 for(n
= 0; n
< config
->player
.n
; ++n
)
277 if(fnmatch(config
->player
.s
[n
].s
[0], q
->track
, 0) == 0)
279 if(n
>= config
->player
.n
)
282 return &config
->player
.s
[n
];
285 /** @brief Start to play @p q
286 * @param ev Event loop
287 * @param q Track to play/prepare
288 * @return @ref START_OK, @ref START_HARDFAIL or @ref START_SOFTFAIL
290 * This makes @p actually start playing. It calls prepare() if necessary and
291 * either sends an @ref SM_PLAY command or invokes the player itself in a
294 * It's up to the caller to set @ref playing and @c playing->state (this might
295 * be changed in the future).
297 static int start(ev_source
*ev
,
298 struct queue_entry
*q
) {
299 const struct stringlist
*player
;
302 D(("start %s", q
->id
));
303 /* Find the player plugin. */
304 if(!(player
= find_player(q
)))
305 return START_HARDFAIL
; /* No player */
306 if(!(q
->pl
= open_plugin(player
->s
[1], 0)))
307 return START_HARDFAIL
;
308 q
->type
= play_get_type(q
->pl
);
309 /* Special handling for raw-format players */
310 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) == DISORDER_PLAYER_RAW
) {
311 /* Make sure that the track is prepared */
312 if((rc
= prepare(ev
, q
)))
314 /* Now we're sure it's prepared, start it playing */
315 /* TODO actually it might not be fully prepared yet - it's all happening in
316 * a subprocess. See speaker.c for further discussion. */
317 struct speaker_message sm
[1];
318 memset(sm
, 0, sizeof sm
);
319 strcpy(sm
->u
.id
, q
->id
);
321 speaker_send(speaker_fd
, sm
);
322 D(("sent SM_PLAY for %s", sm
->u
.id
));
323 /* Our caller will set playing and playing->state = playing_started */
326 rc
= play_background(ev
, player
, q
, start_child
, NULL
);
328 ev_child(ev
, q
->pid
, 0, player_finished
, q
);
329 /* Our caller will set playing and playing->state = playing_started */
334 /** @brief Child-process half of start()
335 * @return Process exit code
337 * Called in subprocess to execute non-raw-format players (via plugin).
339 static int start_child(struct queue_entry
*q
,
340 const struct pbgc_params
*params
,
341 void attribute((unused
)) *bgdata
) {
344 params
->argv
, params
->argc
,
350 /** @brief Prepare a track for later play
351 * @return @ref START_OK, @ref START_HARDFAIL or @ref START_SOFTFAIL
353 * This can be called either when we want to play the track or slightly before
354 * so that some samples are decoded and available in a buffer.
356 * Only applies to raw-format (i.e. speaker-using) players; everything else
359 int prepare(ev_source
*ev
,
360 struct queue_entry
*q
) {
361 const struct stringlist
*player
;
363 /* If there's a decoder (or player!) going we do nothing */
366 /* If the track is already prepared, do nothing */
367 if(q
->prepared
|| q
->preparing
)
369 /* Find the player plugin */
370 if(!(player
= find_player(q
)))
371 return START_HARDFAIL
; /* No player */
372 q
->pl
= open_plugin(player
->s
[1], 0);
373 q
->type
= play_get_type(q
->pl
);
374 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
375 return START_OK
; /* Not a raw player */
376 int rc
= play_background(ev
, player
, q
, prepare_child
, NULL
);
378 ev_child(ev
, q
->pid
, 0, player_finished
, q
);
380 /* Actually the track is still "in flight" */
386 /** @brief Child-process half of prepare()
387 * @return Process exit code
389 * Called in subprocess to execute the decoder for a raw-format player.
391 * @todo We currently run the normalizer from here in a double-fork. This is
392 * unsatisfactory for many reasons: we can't prevent it outliving the main
393 * server and we don't adequately report its exit status.
395 static int prepare_child(struct queue_entry
*q
,
396 const struct pbgc_params
*params
,
397 void attribute((unused
)) *bgdata
) {
398 /* np will be the pipe to disorder-normalize */
400 if(socketpair(PF_UNIX
, SOCK_STREAM
, 0, np
) < 0)
401 disorder_fatal(errno
, "error calling socketpair");
402 /* Beware of the Leopard! On OS X 10.5.x, the order of the shutdown
403 * calls here DOES MATTER. If you do the SHUT_WR first then the SHUT_RD
404 * fails with "Socket is not connected". I think this is a bug but
405 * provided implementors either don't care about the order or all agree
406 * about the order, choosing the reliable order is an adequate
408 xshutdown(np
[1], SHUT_RD
); /* decoder writes to np[1] */
409 xshutdown(np
[0], SHUT_WR
); /* normalize reads from np[0] */
412 /* Start disorder-normalize. We double-fork so that nothing has to wait
413 * for disorder-normalize. */
415 if(!(npid
= xfork())) {
416 /* Grandchild of disorderd */
418 /* Great-grandchild of disorderd */
419 /* Connect to the speaker process */
420 struct sockaddr_un addr
;
421 memset(&addr
, 0, sizeof addr
);
422 addr
.sun_family
= AF_UNIX
;
423 snprintf(addr
.sun_path
, sizeof addr
.sun_path
,
424 "%s/private/speaker", config
->home
);
425 int sfd
= xsocket(PF_UNIX
, SOCK_STREAM
, 0);
426 if(connect(sfd
, (const struct sockaddr
*)&addr
, sizeof addr
) < 0)
427 disorder_fatal(errno
, "connecting to %s", addr
.sun_path
);
428 /* Send the ID, with a NATIVE-ENDIAN 32 bit length */
429 uint32_t l
= strlen(q
->id
);
430 if(write(sfd
, &l
, sizeof l
) < 0
431 || write(sfd
, q
->id
, l
) < 0)
432 disorder_fatal(errno
, "writing to %s", addr
.sun_path
);
434 if (read(sfd
, &l
, 1) < 0)
435 disorder_fatal(errno
, "reading ack from %s", addr
.sun_path
);
442 /* TODO stderr shouldn't be redirected for disorder-normalize
443 * (but it should be for play_track() */
444 execlp("disorder-normalize", "disorder-normalize",
445 log_default
== &log_syslog ?
"--syslog" : "--no-syslog",
446 "--config", configfile
,
448 disorder_fatal(errno
, "executing disorder-normalize");
449 /* End of the great-grandchild of disorderd */
451 /* Back in the grandchild of disorderd */
453 /* End of the grandchild of disorderd */
455 /* Back in the child of disorderd */
456 /* Wait for the grandchild of disordered to finish */
458 while(waitpid(npid
, &n
, 0) < 0 && errno
== EINTR
)
460 /* Pass the file descriptor to the driver in an environment
463 snprintf(buffer
, sizeof buffer
, "DISORDER_RAW_FD=%d", np
[1]);
464 if(putenv(buffer
) < 0)
465 disorder_fatal(errno
, "error calling putenv");
466 /* Close all the FDs we don't need */
468 /* Start the decoder itself */
470 params
->argv
, params
->argc
,
476 /** @brief Kill a player
477 * @param q Queue entry corresponding to player
479 static void kill_player(struct queue_entry
*q
) {
481 kill(-q
->pid
, config
->signal
);
482 q
->killed
= config
->signal
;
485 /** @brief Abandon a queue entry
487 * Called from c_remove() (but NOT when scratching a track). Only does
488 * anything to raw-format tracks. Terminates the background decoder and tells
489 * the speaker process to cancel the track.
491 void abandon(ev_source
attribute((unused
)) *ev
,
492 struct queue_entry
*q
) {
493 struct speaker_message sm
;
496 return; /* Not prepared. */
497 if((q
->type
& DISORDER_PLAYER_TYPEMASK
) != DISORDER_PLAYER_RAW
)
498 return; /* Not a raw player. */
499 /* Terminate the player. */
501 /* Cancel the track. */
502 memset(&sm
, 0, sizeof sm
);
504 strcpy(sm
.u
.id
, q
->id
);
505 speaker_send(speaker_fd
, &sm
);
508 /* Random tracks ------------------------------------------------------------ */
510 /** @brief Called with a new random track
511 * @param ev Event loop
512 * @param track Track name
514 static void chosen_random_track(ev_source
*ev
,
516 struct queue_entry
*q
;
520 /* Add the track to the queue */
521 q
= queue_add(track
, 0, WHERE_END
, NULL
, origin_random
);
522 D(("picked %p (%s) at random", (void *)q
, q
->track
));
524 /* Maybe a track can now be played */
528 /** @brief Maybe add a randomly chosen track
529 * @param ev Event loop
531 * Picking can take some time so the track will only be added after this
532 * function has returned.
534 void add_random_track(ev_source
*ev
) {
535 struct queue_entry
*q
;
538 /* If random play is not enabled then do nothing. */
539 if(shutting_down
|| !random_is_enabled())
541 /* Count how big the queue is */
542 for(q
= qhead
.next
; q
!= &qhead
; q
= q
->next
)
544 /* If it's smaller than the desired size then add a track */
545 if(qlen
< config
->queue_pad
)
546 trackdb_request_random(ev
, chosen_random_track
);
549 /* Track initiation (part 2) ------------------------------------------------ */
551 /** @brief Attempt to play something
553 * This is called from numerous locations - whenever it might conceivably have
554 * become possible to play something.
556 void play(ev_source
*ev
) {
557 struct queue_entry
*q
;
558 int random_enabled
= random_is_enabled();
560 D(("play playing=%p", (void *)playing
));
561 /* If we're shutting down, or there's something playing, or playing is not
562 * enabled, give up now */
563 if(shutting_down
|| playing
|| !playing_is_enabled()) return;
564 /* See if there's anything to play */
565 if(qhead
.next
== &qhead
) {
566 /* Queue is empty. We could just wait around since there are periodic
567 * attempts to add a random track anyway. However they are rarer than
568 * attempts to force a track so we initiate one now. */
569 add_random_track(ev
);
570 /* chosen_random_track() will call play() when a new random track has been
571 * added to the queue. */
574 /* There must be at least one track in the queue. */
576 /* If random play is disabled but the track is a non-adopted random one
577 * then don't play it. play() will be called again when random play is
579 if(!random_enabled
&& q
->origin
== origin_random
)
581 D(("taken %p (%s) from queue", (void *)q
, q
->track
));
582 /* Try to start playing. */
583 switch(start(ev
, q
)) {
585 if(q
== qhead
.next
) {
586 queue_remove(q
, 0); /* Abandon this track. */
590 /* Oh well, try the next one */
594 /* We'll try the same track again shortly. */
597 /* Remove from the queue */
598 if(q
== qhead
.next
) {
602 /* It's become the playing track */
604 xtime(&playing
->played
);
605 playing
->state
= playing_started
;
606 notify_play(playing
->track
, playing
->submitter
);
607 eventlog("playing", playing
->track
,
608 playing
->submitter ? playing
->submitter
: (const char *)0,
610 /* Maybe add a random track. */
611 add_random_track(ev
);
612 /* If there is another track in the queue prepare it now. This could
613 * potentially be a just-added random track. */
614 if(qhead
.next
!= &qhead
)
615 prepare(ev
, qhead
.next
);
616 /* Make sure there is a prepared scratch */
617 ensure_next_scratch(ev
);
622 /* Miscelleneous ------------------------------------------------------------ */
624 int flag_enabled(const char *s
) {
625 return !s
|| !strcmp(s
, "yes");
628 /** @brief Return true if play is enabled */
629 int playing_is_enabled(void) {
630 return flag_enabled(trackdb_get_global("playing"));
633 /** @brief Enable play */
634 void enable_playing(const char *who
, ev_source
*ev
) {
635 trackdb_set_global("playing", "yes", who
);
636 /* Add a random track if necessary. */
637 add_random_track(ev
);
641 /** @brief Disable play */
642 void disable_playing(const char *who
, ev_source
attribute((unused
)) *ev
) {
643 trackdb_set_global("playing", "no", who
);
646 /** @brief Return true if random play is enabled */
647 int random_is_enabled(void) {
648 return flag_enabled(trackdb_get_global("random-play"));
651 /** @brief Enable random play */
652 void enable_random(const char *who
, ev_source
*ev
) {
653 trackdb_set_global("random-play", "yes", who
);
654 add_random_track(ev
);
658 /** @brief Disable random play */
659 void disable_random(const char *who
, ev_source
attribute((unused
)) *ev
) {
660 trackdb_set_global("random-play", "no", who
);
663 /* Scratching --------------------------------------------------------------- */
665 /** @brief Track to play next time something is scratched */
666 static struct queue_entry
*next_scratch
;
668 /** @brief Ensure there isa prepared scratch */
669 static void ensure_next_scratch(ev_source
*ev
) {
670 if(next_scratch
) /* There's one already */
672 if(!config
->scratch
.n
) /* There are no scratches */
674 int r
= rand() * (double)config
->scratch
.n
/ (RAND_MAX
+ 1.0);
675 next_scratch
= queue_add(config
->scratch
.s
[r
], NULL
,
676 WHERE_NOWHERE
, NULL
, origin_scratch
);
678 prepare(ev
, next_scratch
);
681 /** @brief Scratch a track
682 * @param who User responsible (or NULL)
683 * @param id Track ID (or NULL for current)
685 void scratch(const char *who
, const char *id
) {
686 struct speaker_message sm
;
688 D(("scratch playing=%p state=%d id=%s playing->id=%s",
690 playing ? playing
->state
: 0,
692 playing ? playing
->id
: "(none)"));
693 /* There must be a playing track; it must be in a scratchable state; if a
694 * specific ID was mentioned it must be that track. */
696 && (playing
->state
== playing_started
697 || playing
->state
== playing_paused
)
699 || !strcmp(id
, playing
->id
))) {
700 /* Update state (for the benefit of the 'recent' list) */
701 playing
->state
= playing_scratched
;
702 playing
->scratched
= who ?
xstrdup(who
) : 0;
703 /* Find the player and kill the whole process group */
704 if(playing
->pid
>= 0)
705 kill_player(playing
);
706 /* Tell the speaker, if we think it'll care */
707 if((playing
->type
& DISORDER_PLAYER_TYPEMASK
) == DISORDER_PLAYER_RAW
) {
708 memset(&sm
, 0, sizeof sm
);
710 strcpy(sm
.u
.id
, playing
->id
);
711 speaker_send(speaker_fd
, &sm
);
712 D(("sending SM_CANCEL for %s", playing
->id
));
714 /* If playing is enabled then add a scratch to the queue. Having a scratch
715 * appear in the queue when further play is disabled is weird and
716 * contradicts implicit assumptions made elsewhere, so we try to avoid
718 if(playing_is_enabled()) {
719 /* Try to make sure there is a scratch */
720 ensure_next_scratch(NULL
);
721 /* Insert it at the head of the queue */
723 next_scratch
->submitter
= who
;
724 queue_insert_entry(&qhead
, next_scratch
);
725 eventlog_raw("queue", queue_marshall(next_scratch
), (const char *)0);
729 notify_scratch(playing
->track
, playing
->submitter
, who
,
730 xtime(0) - playing
->played
);
734 /* Server termination ------------------------------------------------------- */
736 /** @brief Called from quit() to tear down everything belonging to this file */
737 void quitting(ev_source
*ev
) {
738 struct queue_entry
*q
;
740 /* Don't start anything new */
742 /* Shut down the current player */
744 kill_player(playing
);
745 playing
->state
= playing_quitting
;
748 /* Zap any background decoders that are going */
749 for(q
= qhead
.next
; q
!= &qhead
; q
= q
->next
)
751 /* Don't need the speaker any more */
752 ev_fd_cancel(ev
, ev_read
, speaker_fd
);
756 /* Pause and resume --------------------------------------------------------- */
758 /** @brief Pause the playing track */
759 int pause_playing(const char *who
) {
760 struct speaker_message sm
;
763 /* Can't pause if already paused or if nothing playing. */
764 if(!playing
|| paused
) return 0;
765 switch(playing
->type
& DISORDER_PLAYER_TYPEMASK
) {
766 case DISORDER_PLAYER_STANDALONE
:
767 if(!(playing
->type
& DISORDER_PLAYER_PAUSES
)) {
769 disorder_error(0, "cannot pause because player is not powerful enough");
772 if(play_pause(playing
->pl
, &played
, playing
->data
)) {
773 disorder_error(0, "player indicates it cannot pause");
776 xtime(&playing
->lastpaused
);
777 playing
->uptopause
= played
;
778 playing
->lastresumed
= 0;
780 case DISORDER_PLAYER_RAW
:
781 memset(&sm
, 0, sizeof sm
);
783 speaker_send(speaker_fd
, &sm
);
787 disorder_info("paused by %s", who
);
788 notify_pause(playing
->track
, who
);
790 if(playing
->state
== playing_started
)
791 playing
->state
= playing_paused
;
792 eventlog("state", "pause", (char *)0);
796 /** @brief Resume playing after a pause */
797 void resume_playing(const char *who
) {
798 struct speaker_message sm
;
803 switch(playing
->type
& DISORDER_PLAYER_TYPEMASK
) {
804 case DISORDER_PLAYER_STANDALONE
:
805 if(!(playing
->type
& DISORDER_PLAYER_PAUSES
)) {
807 /* Shouldn't happen */
810 play_resume(playing
->pl
, playing
->data
);
811 xtime(&playing
->lastresumed
);
813 case DISORDER_PLAYER_RAW
:
814 memset(&sm
, 0, sizeof sm
);
816 speaker_send(speaker_fd
, &sm
);
819 if(who
) disorder_info("resumed by %s", who
);
820 notify_resume(playing
->track
, who
);
821 if(playing
->state
== playing_paused
)
822 playing
->state
= playing_started
;
823 eventlog("state", "resume", (char *)0);
826 /** @brief Request an RTP stream */
827 void rtp_request(const struct sockaddr_storage
*sa
) {
828 struct speaker_message sm
;
829 memset(&sm
, 0, sizeof sm
);
830 sm
.type
= SM_RTP_REQUEST
;
832 speaker_send(speaker_fd
, &sm
);
835 /** @brief Cancel an RTP stream */
836 void rtp_request_cancel(const struct sockaddr_storage
*sa
) {
837 struct speaker_message sm
;
838 memset(&sm
, 0, sizeof sm
);
839 sm
.type
= SM_RTP_CANCEL
;
841 speaker_send(speaker_fd
, &sm
);