chiark / gitweb /
speaker: new comments to add/remove RTP recipients
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 10 Nov 2013 13:58:33 +0000 (13:58 +0000)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sun, 10 Nov 2013 14:04:18 +0000 (14:04 +0000)
lib/speaker-protocol.h
server/play.c
server/speaker.c

index 200e4b5..cd6a192 100644 (file)
@@ -26,6 +26,7 @@
 #define SPEAKER_PROTOCOL_H
 
 #include "byte-order.h"
+#include <netinet/in.h>
 
 /** @brief A message from the main server to the speaker, or vica versa */
 struct speaker_message {
@@ -37,6 +38,8 @@ struct speaker_message {
    * - @ref SM_RESUME
    * - @ref SM_CANCEL
    * - @ref SM_RELOAD
+   * - @ref SM_RTP_REQUEST
+   * - @ref SM_RTP_CANCEL
    *
    * Messages from the speaker:
    * - @ref SM_PAUSED
@@ -53,6 +56,9 @@ struct speaker_message {
   union {
     /** @brief Track ID (including 0 terminator) */
     char id[24];                          /* ID including terminator */
+
+    /** @brief An IP address (for @ref SM_RTP_REQUEST and @ref SM_RTP_CANCEL) */
+    struct sockaddr_storage address;
   } u;
 };
 
@@ -76,6 +82,12 @@ struct speaker_message {
 /** @brief Reload configuration */
 #define SM_RELOAD 5
 
+/** @brief Reload configuration */
+#define SM_RTP_REQUEST 6
+
+/** @brief Reload configuration */
+#define SM_RTP_CANCEL 7
+
 /* messages from the speaker */
 /** @brief Paused track @c id, @c data seconds in
  *
index e15cda1..a5d318c 100644 (file)
@@ -823,6 +823,24 @@ void resume_playing(const char *who) {
   eventlog("state", "resume", (char *)0);
 }
 
+/** @brief Request an RTP stream */
+void rtp_request(const struct sockaddr_storage *sa) {
+  struct speaker_message sm;
+  memset(&sm, 0, sizeof sm);
+  sm.type = SM_RTP_REQUEST;
+  sm.u.address = *sa;
+  speaker_send(speaker_fd, &sm);
+}
+
+/** @brief Cancel an RTP stream */
+void rtp_request_cancel(const struct sockaddr_storage *sa) {
+  struct speaker_message sm;
+  memset(&sm, 0, sizeof sm);
+  sm.type = SM_RTP_CANCEL;
+  sm.u.address = *sa;
+  speaker_send(speaker_fd, &sm);
+}
+
 /*
 Local Variables:
 c-basic-offset:2
index e470759..a55b074 100644 (file)
@@ -660,6 +660,15 @@ static void mainloop(void) {
             disorder_error(0, "cannot read configuration");
           disorder_info("reloaded configuration");
          break;
+        case SM_RTP_REQUEST:
+          /* TODO the error behavior here is really unhelpful */
+          if(rtp_add_recipient(&sm.u.address))
+            disorder_error(0, "unacceptable RTP destination");
+          break;
+        case SM_RTP_CANCEL:
+          if(rtp_remove_recipient(&sm.u.address))
+            disorder_error(0, "unacceptable RTP destination for removal");
+          break;
        default:
          disorder_error(0, "unknown message type %d", sm.type);
         }