if (dbus_service_is_running())
shairport_sync_set_disable_standby(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE);
#endif
- config.keep_dac_busy = 0;
+ config.keep_dac_busy = 0;
}
}
}
int do_close() {
- debug(2,"alsa: do_close()");
+ debug(2, "alsa: do_close()");
if (alsa_backend_state == abm_disconnected)
debug(1, "alsa: do_close() -- closing the output device when it is already "
"disconnected");
else
selected_interface = AVAHI_IF_UNSPEC;
if (ap2_text_record_string_list) {
- ret = avahi_entry_group_add_service_strlst(group, selected_interface, AVAHI_PROTO_UNSPEC, 0,
+ ret = avahi_entry_group_add_service_strlst(group, selected_interface, AVAHI_PROTO_UNSPEC, 0,
ap2_service_name, config.regtype2, NULL, NULL,
port, ap2_text_record_string_list);
- if (ret == AVAHI_ERR_COLLISION) {
- die("Error: AirPlay 2 name \"%s\" is already in use.", ap2_service_name);
- }
-
+ if (ret == AVAHI_ERR_COLLISION) {
+ die("Error: AirPlay 2 name \"%s\" is already in use.", ap2_service_name);
+ }
}
if ((ret == 0) && (text_record_string_list)) {
ret = avahi_entry_group_add_service_strlst(group, selected_interface, AVAHI_PROTO_UNSPEC, 0,
service_name, config.regtype, NULL, NULL, port,
text_record_string_list);
- if (ret == AVAHI_ERR_COLLISION) {
- die("Error: AirPlay 1 name \"%s\" is already in use.", service_name);
- }
+ if (ret == AVAHI_ERR_COLLISION) {
+ die("Error: AirPlay 1 name \"%s\" is already in use.", service_name);
+ }
}
if (ret == 0) {
ret = avahi_entry_group_commit(group);
void mqtt_publish(char *topic, char *data_in, uint32_t length_in) {
char *data = data_in;
uint32_t length = length_in;
-
+
if ((length == 0) && (config.mqtt_empty_payload_substitute != NULL)) {
length = strlen(config.mqtt_empty_payload_substitute);
data = config.mqtt_empty_payload_substitute;
}
-
+
char fulltopic[strlen(config.mqtt_topic) + strlen(topic) + 3];
snprintf(fulltopic, strlen(config.mqtt_topic) + strlen(topic) + 2, "%s/%s", config.mqtt_topic,
topic);
debug(2, "[MQTT]: publishing under %s", fulltopic);
-
+
int rc;
if ((rc = mosquitto_publish(global_mosq, NULL, fulltopic, length, data, 0, 0)) !=
MOSQ_ERR_SUCCESS) {
// (In future version of NQPTP the SMI interface may also be deleted at this point.)
// SMI interfaces are not currently deleted or garbage collected.
-
#include <inttypes.h>
#include <pthread.h>
int32_t minimum_buffer_occupancy = INT32_MAX;
int32_t maximum_buffer_occupancy = INT32_MIN;
-#ifdef CONFIG_AIRPLAY_2
+#ifdef CONFIG_AIRPLAY_2
conn->ap2_audio_buffer_minimum_size = -1;
#endif
statistics_item("min DAC queue", "%*" PRIu64 "", 13, minimum_dac_queue_size);
statistics_item("min buffers", "%*" PRIu32 "", 11, minimum_buffer_occupancy);
statistics_item("max buffers", "%*" PRIu32 "", 11, maximum_buffer_occupancy);
-#ifdef CONFIG_AIRPLAY_2
- if ( conn->ap2_audio_buffer_minimum_size > 10 * 1024)
- statistics_item("min buffer size", "%*" PRIu32 "k", 14, conn->ap2_audio_buffer_minimum_size/1024);
+#ifdef CONFIG_AIRPLAY_2
+ if (conn->ap2_audio_buffer_minimum_size > 10 * 1024)
+ statistics_item("min buffer size", "%*" PRIu32 "k", 14,
+ conn->ap2_audio_buffer_minimum_size / 1024);
else
- statistics_item("min buffer size", "%*" PRIu32 "", 15, conn->ap2_audio_buffer_minimum_size);
+ statistics_item("min buffer size", "%*" PRIu32 "", 15,
+ conn->ap2_audio_buffer_minimum_size);
#endif
statistics_item("nominal fps", "%*.2f", 11, conn->remote_frame_rate);
statistics_item("received fps", "%*.2f", 12, conn->input_frame_rate);
minimum_dac_queue_size = UINT64_MAX; // hack reset
maximum_buffer_occupancy = INT32_MIN; // can't be less than this
minimum_buffer_occupancy = INT32_MAX; // can't be more than this
-#ifdef CONFIG_AIRPLAY_2
+#ifdef CONFIG_AIRPLAY_2
conn->ap2_audio_buffer_minimum_size = -1;
#endif
at_least_one_frame_seen = 0;
debug(3, "ptp_shm_interface_open is NULL");
if (mapped_addr == MAP_FAILED)
debug(3, "ptp_shm_interface_open is MAP_FAILED");
-
+
if (strcmp(config.nqptp_shared_memory_interface_name, "") != 0) {
response = 0;
int shared_memory_file_descriptor =
void check64conversion(const char *prompt, const uint8_t *source, uint64_t value) {
char converted_value[128];
- sprintf(converted_value,"%" PRIx64 "", value);
-
+ sprintf(converted_value, "%" PRIx64 "", value);
+
char obf[32];
char *obfp = obf;
int obfc;
int suppress_zeroes = 1;
- for (obfc=0;obfc<8;obfc++) {
- if ((suppress_zeroes == 0) || (source[obfc] != 0)){
+ for (obfc = 0; obfc < 8; obfc++) {
+ if ((suppress_zeroes == 0) || (source[obfc] != 0)) {
if (suppress_zeroes != 0) {
if (source[obfc] < 0x10) {
snprintf(obfp, 3, "%1x", source[obfc]);
- obfp+=1;
+ obfp += 1;
} else {
- snprintf(obfp, 3, "%02x", source[obfc]);
- obfp+=2;
+ snprintf(obfp, 3, "%02x", source[obfc]);
+ obfp += 2;
}
} else {
snprintf(obfp, 3, "%02x", source[obfc]);
- obfp+=2;
+ obfp += 2;
}
suppress_zeroes = 0;
}
};
- *obfp=0;
- if (strcmp(converted_value,obf) != 0) {
- debug(1,"%s check64conversion error converting \"%s\" to %" PRIx64 ".", prompt, obf, value);
+ *obfp = 0;
+ if (strcmp(converted_value, obf) != 0) {
+ debug(1, "%s check64conversion error converting \"%s\" to %" PRIx64 ".", prompt, obf, value);
}
}
void check32conversion(const char *prompt, const uint8_t *source, uint32_t value) {
char converted_value[128];
- sprintf(converted_value,"%" PRIx32 "", value);
-
+ sprintf(converted_value, "%" PRIx32 "", value);
+
char obf[32];
char *obfp = obf;
int obfc;
int suppress_zeroes = 1;
- for (obfc=0;obfc<4;obfc++) {
- if ((suppress_zeroes == 0) || (source[obfc] != 0)){
+ for (obfc = 0; obfc < 4; obfc++) {
+ if ((suppress_zeroes == 0) || (source[obfc] != 0)) {
if (suppress_zeroes != 0) {
if (source[obfc] < 0x10) {
snprintf(obfp, 3, "%1x", source[obfc]);
- obfp+=1;
+ obfp += 1;
} else {
- snprintf(obfp, 3, "%02x", source[obfc]);
- obfp+=2;
+ snprintf(obfp, 3, "%02x", source[obfc]);
+ obfp += 2;
}
} else {
snprintf(obfp, 3, "%02x", source[obfc]);
- obfp+=2;
+ obfp += 2;
}
suppress_zeroes = 0;
}
};
- *obfp=0;
- if (strcmp(converted_value,obf) != 0) {
- debug(1,"%s check32conversion error converting \"%s\" to %" PRIx32 ".", prompt, obf, value);
+ *obfp = 0;
+ if (strcmp(converted_value, obf) != 0) {
+ debug(1, "%s check32conversion error converting \"%s\" to %" PRIx32 ".", prompt, obf, value);
}
}
// add in the audio_backend_latency_offset;
int32_t notified_latency = frame_2 - frame_1;
if (notified_latency != 77175)
- debug(1,"Notified latency is %d frames.", notified_latency);
+ debug(1, "Notified latency is %d frames.", notified_latency);
int32_t added_latency =
(int32_t)(config.audio_backend_latency_offset * conn->input_rate);
// the actual latency is the notified latency plus the fixed latency + the added latency
if (net_latency <= 0) {
if (conn->latency_warning_issued == 0) {
- warn("The stream latency (%f seconds) it too short to accommodate an offset of %f seconds and a backend buffer of %f seconds.", ((notified_latency + 11035) * 1.0)/conn->input_rate, config.audio_backend_latency_offset, config.audio_backend_buffer_desired_length);
- warn("(FYI the stream latency needed would be %f seconds.)", config.audio_backend_buffer_desired_length - config.audio_backend_latency_offset);
+ warn("The stream latency (%f seconds) it too short to accommodate an offset of %f "
+ "seconds and a backend buffer of %f seconds.",
+ ((notified_latency + 11035) * 1.0) / conn->input_rate,
+ config.audio_backend_latency_offset,
+ config.audio_backend_buffer_desired_length);
+ warn("(FYI the stream latency needed would be %f seconds.)",
+ config.audio_backend_buffer_desired_length -
+ config.audio_backend_latency_offset);
conn->latency_warning_issued = 1;
}
conn->latency = notified_latency + 11035;
pthread_exit(NULL);
}
-ssize_t buffered_read(buffered_tcp_desc *descriptor, void *buf, size_t count, size_t *bytes_remaining) {
+ssize_t buffered_read(buffered_tcp_desc *descriptor, void *buf, size_t count,
+ size_t *bytes_remaining) {
ssize_t response = -1;
if (pthread_mutex_lock(&descriptor->mutex) != 0)
debug(1, "problem with mutex");
debug(2, "buffered_read: waiting for %u bytes (okay at start of a track).", count);
else
debug(1, "buffered_read: waiting for %u bytes.", count);
- }
+ }
while ((descriptor->buffer_occupancy == 0) && (descriptor->error_code == 0)) {
if (pthread_cond_wait(&descriptor->not_empty_cv, &descriptor->mutex))
debug(1, "Error waiting for buffered read");
if (nread < 0) {
char errorstring[1024];
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
- debug(1, "error in buffered_tcp_reader %d: \"%s\". Could not recv a packet.", errno, errorstring);
+ debug(1, "error in buffered_tcp_reader %d: \"%s\". Could not recv a packet.", errno,
+ errorstring);
descriptor->error_code = errno;
} else if (nread == 0) {
descriptor->closed = 1;
// this will read a block of the size specified to the buffer
// and will return either with the block or on error
-ssize_t lread_sized_block(buffered_tcp_desc *descriptor, void *buf, size_t count, size_t *bytes_remaining) {
+ssize_t lread_sized_block(buffered_tcp_desc *descriptor, void *buf, size_t count,
+ size_t *bytes_remaining) {
ssize_t response, nread;
size_t inbuf = 0; // bytes already in the buffer
int keep_trying = 1;
uint16_t data_len;
// here we read from the buffer that our thread has been reading
size_t bytes_remaining_in_buffer;
- nread = lread_sized_block(buffered_audio, &data_len, sizeof(data_len), &bytes_remaining_in_buffer);
- if ((conn->ap2_audio_buffer_minimum_size < 0) || (bytes_remaining_in_buffer < (size_t)conn->ap2_audio_buffer_minimum_size))
+ nread = lread_sized_block(buffered_audio, &data_len, sizeof(data_len),
+ &bytes_remaining_in_buffer);
+ if ((conn->ap2_audio_buffer_minimum_size < 0) ||
+ (bytes_remaining_in_buffer < (size_t)conn->ap2_audio_buffer_minimum_size))
conn->ap2_audio_buffer_minimum_size = bytes_remaining_in_buffer;
if (nread < 0) {
char errorstring[1024];
data_len = ntohs(data_len);
// debug(1,"buffered audio packet of size %u detected.", data_len - 2);
nread = lread_sized_block(buffered_audio, packet, data_len - 2, &bytes_remaining_in_buffer);
- if ((conn->ap2_audio_buffer_minimum_size < 0) || (bytes_remaining_in_buffer < (size_t)conn->ap2_audio_buffer_minimum_size))
+ if ((conn->ap2_audio_buffer_minimum_size < 0) ||
+ (bytes_remaining_in_buffer < (size_t)conn->ap2_audio_buffer_minimum_size))
conn->ap2_audio_buffer_minimum_size = bytes_remaining_in_buffer;
// debug(1, "buffered audio packet of size %u received.", nread);
if (nread < 0) {
int64_t local_lead_time = 0;
int64_t requested_lead_time_ns = (int64_t)(requested_lead_time * 1000000000);
// requested_lead_time_ns = (int64_t)(-300000000);
- // debug(1,"requested_lead_time_ns is actually %f milliseconds.", requested_lead_time_ns * 1E-6);
+ // debug(1,"requested_lead_time_ns is actually %f milliseconds.", requested_lead_time_ns *
+ // 1E-6);
int outdated = 0;
if (have_time_information == 0) {
local_lead_time = local_should_be_time - get_absolute_time_in_ns();
- // debug(1,"local_lead_time is actually %f milliseconds.", local_lead_time * 1E-6);
+ // debug(1,"local_lead_time is actually %f milliseconds.", local_lead_time * 1E-6);
outdated = (local_lead_time < requested_lead_time_ns);
// if (outdated != 0)
// debug(1,"Frame is outdated %d if lead_time %" PRId64 " is less than requested lead time
uint32_t anchorRTPTime = rtpTime;
int32_t added_latency = (int32_t)(config.audio_backend_latency_offset * conn->input_rate);
- // debug(1,"anchorRTPTime: %" PRIu32 ", added latency: %" PRId32 ".", anchorRTPTime, added_latency);
+ // debug(1,"anchorRTPTime: %" PRIu32 ", added latency: %" PRId32 ".", anchorRTPTime,
+ // added_latency);
set_ptp_anchor_info(conn, conn->networkTimeTimelineID, anchorRTPTime - added_latency,
anchorTimeNanoseconds);
}
resp->respcode = 500;
}
-void handle_post(rtsp_conn_info *conn,
- rtsp_message *req,
+void handle_post(rtsp_conn_info *conn, rtsp_message *req,
__attribute((unused)) rtsp_message *resp) {
debug(1, "Connection %d: POST %s Content-Length %d", conn->connection_number, req->path,
req->contentlength);
}
}
-void handle_audio_mode(rtsp_conn_info *conn,
- rtsp_message *req,
- __attribute__((unused)) rtsp_message *resp) {
+void handle_audio_mode(rtsp_conn_info *conn, rtsp_message *req,
+ __attribute__((unused)) rtsp_message *resp) {
debug(2, "Connection %d: POST %s Content-Length %d", conn->connection_number, req->path,
req->contentlength);
debug_log_rtsp_message(2, NULL, req);
}
-
void handle_post(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
resp->respcode = 200;
if (strcmp(req->path, "/pair-setup") == 0) {
// if it's a full service PTP stream, we get groupUUID, groupContainsGroupLeader and
// timingPeerList
if (conn->airplay_stream_category == ptp_stream) {
- if (ptp_shm_interface_open() != 0) // it should be open already, but just in case it isn't...
+ if (ptp_shm_interface_open() !=
+ 0) // it should be open already, but just in case it isn't...
die("Can not access the NQPTP service. Has it stopped running?");
- ptp_send_control_message_string("T"); // remove all previous history
+ ptp_send_control_message_string("T"); // remove all previous history
debug_log_rtsp_message(2, "SETUP \"PTP\" message", req);
plist_t groupUUID = plist_dict_get_item(messagePlist, "groupUUID");
if (groupUUID) {
pthread_cleanup_push(msg_cleanup_function, (void *)&resp);
resp->respcode = 501; // Not Implemented
int dl = debug_level;
- if ((strcmp(req->method, "OPTIONS") ==
- 0) || (strcmp(req->method, "POST") ==
- 0)) // the options message is very common, so don't log it until level 3
+ if ((strcmp(req->method, "OPTIONS") == 0) ||
+ (strcmp(req->method, "POST") ==
+ 0)) // the options message is very common, so don't log it until level 3
dl = 3;
- debug(dl,
- "Connection %d: Received an RTSP Packet of type \"%s\":", conn->connection_number,
+ debug(dl, "Connection %d: Received an RTSP Packet of type \"%s\":", conn->connection_number,
req->method),
- debug_print_msg_headers(dl, req);
+ debug_print_msg_headers(dl, req);
apple_challenge(conn->fd, req, resp);
hdr = msg_get_header(req, "CSeq");
if (hdr)
#include "config.h"
#ifdef CONFIG_AIRPLAY_2
+#include "ptp-utilities.h"
#include <gcrypt.h>
#include <sodium.h>
#include <uuid/uuid.h>
-#include "ptp-utilities.h"
#endif
#ifdef CONFIG_MBEDTLS
"support. Change the \"general/interpolation\" setting in the configuration file.");
#endif
else
- die("Invalid interpolation option choice \"%s\". It should be \"auto\", \"basic\" or \"soxr\"", str);
+ die("Invalid interpolation option choice \"%s\". It should be \"auto\", \"basic\" or "
+ "\"soxr\"",
+ str);
}
#ifdef CONFIG_SOXR
config.debugger_show_file_and_line = 1;
else
die("Invalid diagnostics log_show_file_and_line option choice \"%s\". It should be "
- "\"yes\" or \"no\"", str);
+ "\"yes\" or \"no\"",
+ str);
}
/* Get the show elapsed time in debug messages setting. */
config.debugger_show_elapsed_time = 1;
else
die("Invalid diagnostics log_show_time_since_startup option choice \"%s\". It should be "
- "\"yes\" or \"no\"", str);
+ "\"yes\" or \"no\"",
+ str);
}
/* Get the show relative time in debug messages setting. */
config.debugger_show_relative_time = 1;
else
die("Invalid diagnostics log_show_time_since_last_message option choice \"%s\". It "
- "should be \"yes\" or \"no\"", str);
+ "should be \"yes\" or \"no\"",
+ str);
}
/* Get the statistics setting. */
config.statistics_requested = 1;
else
die("Invalid diagnostics statistics option choice \"%s\". It should be \"yes\" or "
- "\"no\"", str);
+ "\"no\"",
+ str);
}
/* Get the disable_resend_requests setting. */
else
die("Invalid diagnostic disable_resend_requests option choice \"%s\". It should be "
"\"yes\" "
- "or \"no\"", str);
+ "or \"no\"",
+ str);
}
/* Get the drop packets setting. */
else if (strcasecmp(str, "yes") == 0)
config.ignore_volume_control = 1;
else
- die("Invalid ignore_volume_control option choice \"%s\". It should be \"yes\" or \"no\"", str);
+ die("Invalid ignore_volume_control option choice \"%s\". It should be \"yes\" or \"no\"",
+ str);
}
/* Get the optional volume_max_db setting. */
config.playback_mode = ST_right_only;
else
die("Invalid playback_mode choice \"%s\". It should be \"stereo\" (default), \"mono\", "
- "\"reverse stereo\", \"both left\", \"both right\"", str);
+ "\"reverse stereo\", \"both left\", \"both right\"",
+ str);
}
/* Get the volume control profile setting -- "standard" or "flat" */
config.volume_control_profile = VCP_flat;
else
die("Invalid volume_control_profile choice \"%s\". It should be \"standard\" (default) "
- "or \"flat\"", str);
+ "or \"flat\"",
+ str);
}
config_set_lookup_bool(config.cfg, "general.volume_control_combined_hardware_priority",
inform("Support for the Apple ALAC decoder has not been compiled into this version of "
"Shairport Sync. The default decoder will be used.");
} else
- die("Invalid alac_decoder option choice \"%s\". It should be \"hammerton\" or \"apple\"", str);
+ die("Invalid alac_decoder option choice \"%s\". It should be \"hammerton\" or \"apple\"",
+ str);
}
/* Get the resend control settings. */
config.get_coverart = 1;
else
die("Invalid metadata include_cover_art option choice \"%s\". It should be \"yes\" or "
- "\"no\"", str);
+ "\"no\"",
+ str);
}
if (config_lookup_string(config.cfg, "metadata.pipe_name", &str)) {
config.retain_coverart = 1;
else
die("Invalid metadata \"retain_cover_art\" option choice \"%s\". It should be \"yes\" or "
- "\"no\"", str);
+ "\"no\"",
+ str);
}
#endif
config.cmd_blocking = 1;
else
warn("Invalid \"wait_for_completion\" option choice \"%s\". It should be "
- "\"yes\" or \"no\". It is set to \"no\".", str);
+ "\"yes\" or \"no\". It is set to \"no\".",
+ str);
}
if (config_lookup_string(config.cfg, "sessioncontrol.before_play_begins_returns_output",
else
die("Invalid \"before_play_begins_returns_output\" option choice \"%s\". It "
"should be "
- "\"yes\" or \"no\"", str);
+ "\"yes\" or \"no\"",
+ str);
}
if (config_lookup_string(config.cfg, "sessioncontrol.allow_session_interruption", &str)) {
else
die("Invalid \"allow_interruption\" option choice \"%s\". It should be "
"\"yes\" "
- "or \"no\"", str);
+ "or \"no\"",
+ str);
}
if (config_lookup_int(config.cfg, "sessioncontrol.session_timeout", &value)) {
config.dbus_service_bus_type = DBT_session;
else
die("Invalid dbus_service_bus option choice \"%s\". It should be \"system\" (default) or "
- "\"session\"", str);
+ "\"session\"",
+ str);
}
#endif
config.mpris_service_bus_type = DBT_session;
else
die("Invalid mpris_service_bus option choice \"%s\". It should be \"system\" (default) or "
- "\"session\"", str);
+ "\"session\"",
+ str);
}
#endif
do {
ptp_send_control_message_string("T"); // get nqptp to create the named shm interface
usleep(ptp_wait_interval_us);
- ptp_check_times++;
+ ptp_check_times++;
} while ((ptp_shm_interface_open() != 0) && (ptp_check_times < (2000000 / ptp_wait_interval_us)));
-
+
if (ptp_shm_interface_open() != 0) {
die("Can't access NQPTP! Is it installed and running?");
} else {
if (ptp_check_times == 1)
- debug(1,"NQPTP is online.");
+ debug(1, "NQPTP is online.");
else
- debug(1,"NQPTP is online after %u microseconds.",ptp_check_times * ptp_wait_interval_us);
+ debug(1, "NQPTP is online after %u microseconds.", ptp_check_times * ptp_wait_interval_us);
}
#endif