]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Format
authorMike Brady <mikebrady@eircom.net>
Thu, 27 Dec 2018 14:04:31 +0000 (14:04 +0000)
committerMike Brady <mikebrady@eircom.net>
Thu, 27 Dec 2018 14:04:31 +0000 (14:04 +0000)
audio_alsa.c
dacp.c
rtsp.c

index f3c27d35e326a586a71c9bc50bacb785bdca6af7..764a4381856d0eedfe30ab93aa6e44e563652fb3 100644 (file)
@@ -802,7 +802,7 @@ static int init(int argc, char **argv) {
     // Get the optional "Keep DAC Busy setting"
     int kdb;
     if (config_set_lookup_bool(config.cfg, "alsa.disable_standby_mode", &kdb)) {
-       config.keep_dac_busy = kdb;
+      config.keep_dac_busy = kdb;
     }
     debug(1, "alsa: disable_standby_mode is %s.", config.keep_dac_busy ? "on" : "off");
   }
@@ -956,9 +956,10 @@ static int init(int argc, char **argv) {
     if (ret == 0)
       actual_close_alsa_device();
     else
-      die("audio_alsa error %d opening the alsa device. Incorrect settings or device already busy?",ret);
+      die("audio_alsa error %d opening the alsa device. Incorrect settings or device already busy?",
+          ret);
   }
-       most_recent_write_time = 0; // could be used by the alsa_buffer_monitor_thread_code
+  most_recent_write_time = 0; // could be used by the alsa_buffer_monitor_thread_code
   pthread_create(&alsa_buffer_monitor_thread, NULL, &alsa_buffer_monitor_thread_code, NULL);
 
   return response;
@@ -969,10 +970,10 @@ static void deinit(void) {
   pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
   // debug(2,"audio_alsa deinit called.");
   stop();
-       debug(1, "Cancel buffer monitor thread.");
-       pthread_cancel(alsa_buffer_monitor_thread);
-       debug(1, "Join buffer monitor thread.");
-       pthread_join(alsa_buffer_monitor_thread, NULL);
+  debug(1, "Cancel buffer monitor thread.");
+  pthread_cancel(alsa_buffer_monitor_thread);
+  debug(1, "Join buffer monitor thread.");
+  pthread_join(alsa_buffer_monitor_thread, NULL);
   pthread_setcancelstate(oldState, NULL);
 }
 
@@ -1136,7 +1137,7 @@ int get_rate_information(uint64_t *elapsed_time, uint64_t *frames_played) {
 }
 
 int untimed_play(void *buf, int samples) {
-       
+
   // debug(3,"audio_alsa play called.");
   int oldState;
   pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
@@ -1284,11 +1285,12 @@ static void flush(void) {
 }
 
 static int play(void *buf, int samples) {
-  uint64_t time_now = get_absolute_time_in_fp(); // this is to regulate access by the silence filler thread
+  uint64_t time_now =
+      get_absolute_time_in_fp(); // this is to regulate access by the silence filler thread
   uint64_t sample_duration = ((uint64_t)samples) << 32;
   sample_duration = sample_duration / desired_sample_rate;
-       most_recent_write_time = time_now + sample_duration;
-       return untimed_play(buf,samples);
+  most_recent_write_time = time_now + sample_duration;
+  return untimed_play(buf, samples);
 }
 
 static void stop(void) {
@@ -1457,12 +1459,13 @@ void *alsa_buffer_monitor_thread_code(void *arg) {
   // (if no source transformation is happening), Shairport Sync
   // will deliver fill-in silences and the audio material without adding dither.
   // So don't insert dither into the silences sent to keep the DAC busy.
-  
+
   // Also, if the ignore_volume_setting is set, the audio is sent through unaltered,
   // so, in that circumstance, don't add dither either.
 
   int use_dither = 0;
-  if ((hardware_mixer == 0) && (config.ignore_volume_control == 0) && (config.airplay_volume != 0.0))
+  if ((hardware_mixer == 0) && (config.ignore_volume_control == 0) &&
+      (config.airplay_volume != 0.0))
     use_dither = 1;
 
   debug(1, "alsa: dither will %sbe added to inter-session silence.", use_dither ? "" : "not ");
@@ -1483,28 +1486,32 @@ void *alsa_buffer_monitor_thread_code(void *arg) {
     long buffer_size;
     int reply;
     while (1) {
-       if (config.keep_dac_busy != 0) {
-               uint64_t present_time = get_absolute_time_in_fp();
-  
-               if ((most_recent_write_time == 0) || ((present_time > most_recent_write_time) && ((present_time - most_recent_write_time) > (sleep_time_in_fp)))) {
-                                       reply = delay(&buffer_size);
-                                       if (reply != 0)
-                                               buffer_size = 0;
-                                       if (buffer_size < frames_of_silence) {
-                                               if ((hardware_mixer == 0) && (config.ignore_volume_control == 0) && (config.airplay_volume != 0.0))
-                                                       use_dither = 1;
-                                               else
-                                                       use_dither = 0;
-                                               dither_random_number_store = generate_zero_frames(
-                                                               silence, frames_of_silence, config.output_format, use_dither, // i.e. with dither
-                                                               dither_random_number_store);
-                                               //debug(1,"Play %d frames of silence with most_recent_write_time of %" PRIx64 ".", frames_of_silence,most_recent_write_time);
-                                               untimed_play(silence, frames_of_silence);
-                                       }
-                               }
-      }   
+      if (config.keep_dac_busy != 0) {
+        uint64_t present_time = get_absolute_time_in_fp();
+
+        if ((most_recent_write_time == 0) ||
+            ((present_time > most_recent_write_time) &&
+             ((present_time - most_recent_write_time) > (sleep_time_in_fp)))) {
+          reply = delay(&buffer_size);
+          if (reply != 0)
+            buffer_size = 0;
+          if (buffer_size < frames_of_silence) {
+            if ((hardware_mixer == 0) && (config.ignore_volume_control == 0) &&
+                (config.airplay_volume != 0.0))
+              use_dither = 1;
+            else
+              use_dither = 0;
+            dither_random_number_store = generate_zero_frames(
+                silence, frames_of_silence, config.output_format, use_dither, // i.e. with dither
+                dither_random_number_store);
+            // debug(1,"Play %d frames of silence with most_recent_write_time of %" PRIx64 ".",
+            // frames_of_silence,most_recent_write_time);
+            untimed_play(silence, frames_of_silence);
+          }
+        }
+      }
       usleep(sleep_time_ms * 1000); // has a cancellation point in it
-//      pthread_testcancel();
+                                    //      pthread_testcancel();
     }
   }
   pthread_cleanup_pop(1);
diff --git a/dacp.c b/dacp.c
index 827cb70401053741cd645b284bfe47e4e1cb5c21..8f93f7dfadce6cd6585394722e309d8a768d4e18 100644 (file)
--- a/dacp.c
+++ b/dacp.c
@@ -211,7 +211,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
       } else {
         pthread_cleanup_push(connect_cleanup, (void *)&sockfd);
         // debug(2, "dacp_send_command: open socket %d.",sockfd);
-        
+
         struct timeval tv;
         tv.tv_sec = 2;
         tv.tv_usec = 0;
@@ -259,7 +259,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
               int ndata = recv(sockfd, buffer, sizeof(buffer), 0);
               // debug(3, "Received %d bytes: \"%s\".", ndata, buffer);
               if (ndata <= 0) {
-                //debug(1, "dacp_send_command -- error receiving response for command \"%s\".",
+                // debug(1, "dacp_send_command -- error receiving response for command \"%s\".",
                 //      command);
                 free(response.body);
                 response.body = NULL;
@@ -300,7 +300,8 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
       // debug(1,"Sent command\"%s\" with a response body of size %d.",command,response.size);
       // debug(1,"dacp_conversation_lock released.");
     } else {
-      debug(3, "dacp_send_command: could not acquire a lock on the dacp transmit/receive section when attempting to "
+      debug(3, "dacp_send_command: could not acquire a lock on the dacp transmit/receive section "
+               "when attempting to "
                "send the command \"%s\". Possible timeout?",
             command);
       response.code = 494; // This client is already busy
@@ -908,7 +909,7 @@ int dacp_get_client_volume(int32_t *result) {
     }
     // debug(1, "Overall Volume is %d.", overall_volume);
   }
-  
+
   if (server_reply) {
     // debug(1, "Freeing response memory.");
     free(server_reply);
diff --git a/rtsp.c b/rtsp.c
index 84e0660718d74ddd2c2b596caf649823c1c64384..bf0ad37005635cf363d0ac0670fd26b75c21af70 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -558,7 +558,7 @@ fail:
 enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_message **the_packet) {
   enum rtsp_read_request_response reply = rtsp_read_request_response_ok;
   ssize_t buflen = 4096;
-  char *buf = malloc(buflen + 1); //add a NUL at the end
+  char *buf = malloc(buflen + 1); // add a NUL at the end
 
   rtsp_message *msg = NULL;
 
@@ -622,7 +622,7 @@ do {
   }
 
   if (msg_size > buflen) {
-    buf = realloc(buf, msg_size+1);
+    buf = realloc(buf, msg_size + 1);
     if (!buf) {
       warn("too much content");
       reply = rtsp_read_request_response_error;
@@ -692,7 +692,7 @@ do {
 
   msg->contentlength = inbuf;
   msg->content = buf;
-  char *jp = inbuf+buf;
+  char *jp = inbuf + buf;
   *jp = '\0';
   *the_packet = msg;
   return reply;
@@ -1002,8 +1002,8 @@ static void handle_ignore(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
 */
 
 void handle_set_parameter_parameter(rtsp_conn_info *conn, rtsp_message *req,
-                                    __attribute__((unused)) rtsp_message *resp) {                                  
-                                    
+                                    __attribute__((unused)) rtsp_message *resp) {
+
   char *cp = req->content;
   int cp_left = req->contentlength;
   /*
@@ -1014,12 +1014,13 @@ void handle_set_parameter_parameter(rtsp_conn_info *conn, rtsp_message *req,
     snprintf((char *)buf + 2 * i, 3, "%02x", cp[i]);
   debug(1, "handle_set_parameter_parameter: \"%s\".",buf);
   */
-  
+
   char *next;
   while (cp_left && cp) {
     next = nextline(cp, cp_left);
     // note: "next" will return NULL if there is no \r or \n or \r\n at the end of this
-    // but we are always guaranteed that if cp is not null, it will be pointing to something NUL-terminated
+    // but we are always guaranteed that if cp is not null, it will be pointing to something
+    // NUL-terminated
 
     if (next)
       cp_left -= (next - cp);
@@ -1032,7 +1033,7 @@ void handle_set_parameter_parameter(rtsp_conn_info *conn, rtsp_message *req,
       player_volume(volume, conn);
     } else
 #ifdef CONFIG_METADATA
-    if (!strncmp(cp, "progress: ", strlen("progress: "))) {
+        if (!strncmp(cp, "progress: ", strlen("progress: "))) {
       char *progress = cp + strlen("volume: ");
       // debug(2, "progress: \"%s\"\n",progress); // rtpstampstart/rtpstampnow/rtpstampend 44100 per
       // second