]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
handle volume control requests in AP2 correctly. Don't reset timing peer lists when...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 15 May 2021 11:18:37 +0000 (12:18 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 15 May 2021 11:18:37 +0000 (12:18 +0100)
player.c
player.h
rtsp.c

index 7c308b9a67e4c489c6fb8e3d4e0b903860b22679..efa40c6331e295c805aa1819fcdcb3b32dc091ec 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1974,10 +1974,13 @@ void *player_thread_func(void *arg) {
 #endif
 
   pthread_setcancelstate(oldState, NULL);
-
+  
+  double initial_volume = config.airplay_volume; // default
+  if (conn->initial_airplay_volume_set) // if we have been given an initial volume
+    initial_volume = conn->initial_airplay_volume;
   // set the default volume to whatever it was before, as stored in the config airplay_volume
-  debug(2, "Set initial volume to %f.", config.airplay_volume);
-  player_volume(config.airplay_volume, conn); // will contain a cancellation point if asked to wait
+  debug(2, "Set initial volume to %f.", initial_volume);
+  player_volume(initial_volume, conn); // will contain a cancellation point if asked to wait
 
   debug(2, "Play begin");
   while (1) {
index eb210ae57a67e0c93b741aafab76b0d0f84053f0..cc4dda2cd29ff8b837e58d756b8b19aadc527dcd 100644 (file)
--- a/player.h
+++ b/player.h
@@ -205,7 +205,11 @@ typedef struct {
   // mutexes and condition variables
   pthread_cond_t flowcontrol;
   pthread_mutex_t ab_mutex, flush_mutex, volume_control_mutex;
+
   int fix_volume;
+  double initial_airplay_volume;
+  int initial_airplay_volume_set;
+  
   uint32_t timestamp_epoch, last_timestamp,
       maximum_timestamp_interval; // timestamp_epoch of zero means not initialised, could start at 2
                                   // or 1.
diff --git a/rtsp.c b/rtsp.c
index c670455b462d3a33010b30af491c51a0318b1d14..2828adec8aea04f395a93378fb60d145811d0d21 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -3,7 +3,7 @@
  * Copyright (c) James Laird 2013
 
  * Modifications associated with audio synchronization, mutithreading and
- * metadata handling copyright (c) Mike Brady 2014-2020
+ * metadata handling copyright (c) Mike Brady 2014-2021
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person
@@ -1411,7 +1411,7 @@ void handle_setrateanchori(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
         }
       } else {
         player_full_flush(conn);
-        ptp_send_control_message_string("T"); // ensure an obsolete clock isn't picked up later.
+        // ptp_send_control_message_string("T"); // ensure an obsolete clock isn't picked up later.
       }
     }
     pthread_cleanup_pop(1); // plist_free the messagePlist;
@@ -2281,8 +2281,16 @@ void handle_set_parameter_parameter(rtsp_conn_info *conn, rtsp_message *req,
 
     if (!strncmp(cp, "volume: ", strlen("volume: "))) {
       float volume = atof(cp + strlen("volume: "));
-      // debug(2, "AirPlay request to set volume to: %f.", volume);
-      player_volume(volume, conn);
+      debug(2, "Connection %d: request to set AirPlay Volume to: %f.", conn->connection_number, volume);
+      // if we are playing, go ahead and change the volume
+      if (try_to_hold_play_lock(conn) == 0) {
+        player_volume(volume, conn);
+        release_hold_on_play_lock(conn);
+      } else {
+        // otherwise use the volume as the initial setting for when/if the player starts
+        conn->initial_airplay_volume = volume;
+        conn->initial_airplay_volume_set = 1;
+      }
     } else
 #ifdef CONFIG_METADATA
         if (!strncmp(cp, "progress: ", strlen("progress: "))) {
@@ -2294,7 +2302,7 @@ void handle_set_parameter_parameter(rtsp_conn_info *conn, rtsp_message *req,
     } else
 #endif
     {
-      debug(1, "unrecognised parameter: \"%s\" (%d)\n", cp, strlen(cp));
+      debug(1, "Connection %d, unrecognised parameter: \"%s\" (%d)\n", conn->connection_number, cp, strlen(cp));
     }
     cp = next;
   }
@@ -3015,7 +3023,7 @@ static void handle_get_parameter(__attribute__((unused)) rtsp_conn_info *conn, r
 
   if ((req->content) && (req->contentlength == strlen("volume\r\n")) &&
       strstr(req->content, "volume") == req->content) {
-    // debug(1,"Current volume sought");
+    debug(2,"Connection %d: Current volume (%.6f) requested", conn->connection_number, config.airplay_volume);
     char *p = malloc(128); // will be automatically deallocated with the response is deleted
     if (p) {
       resp->content = p;
@@ -3110,10 +3118,11 @@ static void handle_set_parameter(rtsp_conn_info *conn, rtsp_message *req, rtsp_m
       // debug(2, "received parameters in SET_PARAMETER request.");
       handle_set_parameter_parameter(conn, req, resp); // this could be volume or progress
     } else {
-      debug(1, "received unknown Content-Type \"%s\" in SET_PARAMETER request.", ct);
+      debug(1, "Connection %d: received unknown Content-Type \"%s\" in SET_PARAMETER request.", conn->connection_number, ct);
+      debug_print_msg_headers(1,req);
     }
   } else {
-    debug(1, "missing Content-Type header in SET_PARAMETER request.");
+    debug(1, "Connection %d: missing Content-Type header in SET_PARAMETER request.", conn->connection_number);
   }
   resp->respcode = 200;
 }