// 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");
}
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;
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);
}
}
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
}
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) {
// (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 ");
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);
} 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;
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;
// 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
}
// debug(1, "Overall Volume is %d.", overall_volume);
}
-
+
if (server_reply) {
// debug(1, "Freeing response memory.");
free(server_reply);
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;
}
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;
msg->contentlength = inbuf;
msg->content = buf;
- char *jp = inbuf+buf;
+ char *jp = inbuf + buf;
*jp = '\0';
*the_packet = msg;
return reply;
*/
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;
/*
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);
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