int notified_buffer_empty = 0; // diagnostic only
debug_mutex_lock(&conn->ab_mutex, 30000, 1);
-
-
+
int wait;
long dac_delay = 0; // long because alsa returns a long
-
- pthread_cleanup_push(buffer_get_frame_cleanup_handler, (void *)conn); // undo what's been done so far
+
+ pthread_cleanup_push(buffer_get_frame_cleanup_handler,
+ (void *)conn); // undo what's been done so far
do {
// get the time
local_time_now = get_absolute_time_in_fp(); // type okay
if (conn->flush_requested == 1) {
if (config.output->flush)
config.output->flush(); // no cancellation points
- ab_resync(conn); // no cancellation points
+ ab_resync(conn); // no cancellation points
conn->first_packet_timestamp = 0;
conn->first_packet_time_to_play = 0;
conn->time_since_play_started = 0;
time_of_wakeup.tv_sec = sec;
time_of_wakeup.tv_nsec = nsec;
// pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex, &time_of_wakeup);
- int rc = pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex, &time_of_wakeup); // this is a pthread cancellation point
+ int rc = pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex,
+ &time_of_wakeup); // this is a pthread cancellation point
if (rc != 0)
debug(3, "pthread_cond_timedwait returned error code %d.", rc);
#endif
} while (wait);
// seq_t read = conn->ab_read;
- if (!curframe->ready) {
- // debug(1, "Supplying a silent frame for frame %u", read);
- conn->missing_packets++;
- curframe->timestamp = 0; // indicate a silent frame should be substituted
- }
- curframe->ready = 0;
- curframe->resend_level = 0;
- conn->ab_read = SUCCESSOR(conn->ab_read);
-
- pthread_cleanup_pop(1);
- return curframe;
+ if (!curframe->ready) {
+ // debug(1, "Supplying a silent frame for frame %u", read);
+ conn->missing_packets++;
+ curframe->timestamp = 0; // indicate a silent frame should be substituted
+ }
+ curframe->ready = 0;
+ curframe->resend_level = 0;
+ conn->ab_read = SUCCESSOR(conn->ab_read);
+
+ pthread_cleanup_pop(1);
+ return curframe;
}
static inline short shortmean(short a, short b) {
#ifdef HAVE_DACP_CLIENT
- relinquish_dacp_server_information(conn); // say it doesn't belong to this conversation thread any more...
+ relinquish_dacp_server_information(
+ conn); // say it doesn't belong to this conversation thread any more...
#else
// stop watching for DACP port number stuff
if (conn->outbuf) {
free(conn->outbuf);
conn->outbuf = NULL;
- }
+ }
if (conn->sbuf) {
free(conn->sbuf);
conn->sbuf = NULL;
- }
+ }
if (conn->tbuf) {
free(conn->tbuf);
conn->tbuf = NULL;
// if ((input_rate!=config.output_rate) || (input_bit_depth!=output_bit_depth)) {
// debug(1,"Define tbuf of length
// %d.",output_bytes_per_frame*(max_frames_per_packet*output_sample_ratio+max_frame_size_change));
- conn->tbuf = malloc(sizeof(int32_t) * 2 * (conn->max_frames_per_packet * conn->output_sample_ratio +
- conn->max_frame_size_change));
+ conn->tbuf =
+ malloc(sizeof(int32_t) * 2 * (conn->max_frames_per_packet * conn->output_sample_ratio +
+ conn->max_frame_size_change));
if (conn->tbuf == NULL)
die("Failed to allocate memory for the transition buffer.");
// initialise this, because soxr stuffing might be chosen later
- conn->sbuf = malloc(sizeof(int32_t) * 2 * (conn->max_frames_per_packet * conn->output_sample_ratio +
- conn->max_frame_size_change));
+ conn->sbuf =
+ malloc(sizeof(int32_t) * 2 * (conn->max_frames_per_packet * conn->output_sample_ratio +
+ conn->max_frame_size_change));
if (conn->sbuf == NULL)
die("Failed to allocate memory for the sbuf buffer.");
if (conn->dapo_private_storage)
debug(1, "DACP monitor already initialised?");
else
- // this does not have pthread cancellation points in it (assuming avahi doesn't)
+ // this does not have pthread cancellation points in it (assuming avahi doesn't)
conn->dapo_private_storage = mdns_dacp_monitor(conn->dacp_id); // ??
#endif
debug(3, "Set initial volume to %f.", config.airplay_volume);
player_volume(config.airplay_volume, conn); // ??
int64_t frames_to_drop = 0;
-
- // create and start the timing, control and audio receiver threads
+
+ // create and start the timing, control and audio receiver threads
pthread_create(&conn->rtp_audio_thread, NULL, &rtp_audio_receiver, (void *)conn);
pthread_create(&conn->rtp_control_thread, NULL, &rtp_control_receiver, (void *)conn);
pthread_create(&conn->rtp_timing_thread, NULL, &rtp_timing_receiver, (void *)conn);
-
+
pthread_cleanup_push(player_thread_cleanup_handler, arg); // undo what's been done so far
// debug(1, "Play begin");
case ST_soxr:
#ifdef HAVE_LIBSOXR
// if (amount_to_stuff) debug(1,"Soxr stuff...");
- play_samples = stuff_buffer_soxr_32((int32_t *)conn->tbuf, (int32_t *)conn->sbuf, inbuflength,
- config.output_format, conn->outbuf, amount_to_stuff,
- enable_dither, conn);
+ play_samples = stuff_buffer_soxr_32((int32_t *)conn->tbuf, (int32_t *)conn->sbuf,
+ inbuflength, config.output_format, conn->outbuf,
+ amount_to_stuff, enable_dither, conn);
#endif
break;
}
} else {
// if there is no delay procedure, or it's not working or not allowed, there can be no
// synchronising
- play_samples = stuff_buffer_basic_32((int32_t *)conn->tbuf, inbuflength, config.output_format,
- conn->outbuf, 0, enable_dither, conn);
+ play_samples =
+ stuff_buffer_basic_32((int32_t *)conn->tbuf, inbuflength, config.output_format,
+ conn->outbuf, 0, enable_dither, conn);
if (conn->outbuf == NULL)
debug(1, "NULL outbuf to play -- skipping it.");
else
if (at_least_one_frame_seen) {
if ((config.output->delay)) {
if (config.no_sync == 0) {
- inform(
- "|%*.1f," /* Sync error in milliseconds */
- "%*.1f," /* net correction in ppm */
- "%*.1f," /* corrections in ppm */
- "%*d," /* total packets */
- "%*llu," /* missing packets */
- "%*llu," /* late packets */
- "%*llu," /* too late packets */
- "%*llu," /* resend requests */
- "%*lli," /* min DAC queue size */
- "%*d," /* min buffer occupancy */
- "%*d", /* max buffer occupancy */
- 10,
- 1000 * moving_average_sync_error / config.output_rate,
- 10, moving_average_correction * 1000000 / (352 * conn->output_sample_ratio),
- 10, moving_average_insertions_plus_deletions * 1000000 /
- (352 * conn->output_sample_ratio),
- 12, play_number, 7, conn->missing_packets, 7, conn->late_packets, 7,
- conn->too_late_packets, 7, conn->resend_requests, 7, minimum_dac_queue_size,
- 5, minimum_buffer_occupancy, 5, maximum_buffer_occupancy);
- } else {
inform("|%*.1f," /* Sync error in milliseconds */
+ "%*.1f," /* net correction in ppm */
+ "%*.1f," /* corrections in ppm */
"%*d," /* total packets */
"%*llu," /* missing packets */
"%*llu," /* late packets */
"%*d," /* min buffer occupancy */
"%*d", /* max buffer occupancy */
10,
- 1000 * moving_average_sync_error / config.output_rate,
+ 1000 * moving_average_sync_error / config.output_rate, 10,
+ moving_average_correction * 1000000 / (352 * conn->output_sample_ratio),
+ 10, moving_average_insertions_plus_deletions * 1000000 /
+ (352 * conn->output_sample_ratio),
12, play_number, 7, conn->missing_packets, 7, conn->late_packets, 7,
conn->too_late_packets, 7, conn->resend_requests, 7,
minimum_dac_queue_size, 5, minimum_buffer_occupancy, 5,
maximum_buffer_occupancy);
+ } else {
+ inform("|%*.1f," /* Sync error in milliseconds */
+ "%*d," /* total packets */
+ "%*llu," /* missing packets */
+ "%*llu," /* late packets */
+ "%*llu," /* too late packets */
+ "%*llu," /* resend requests */
+ "%*lli," /* min DAC queue size */
+ "%*d," /* min buffer occupancy */
+ "%*d", /* max buffer occupancy */
+ 10,
+ 1000 * moving_average_sync_error / config.output_rate, 12, play_number, 7,
+ conn->missing_packets, 7, conn->late_packets, 7, conn->too_late_packets, 7,
+ conn->resend_requests, 7, minimum_dac_queue_size, 5,
+ minimum_buffer_occupancy, 5, maximum_buffer_occupancy);
}
} else {
inform("|%*.1f," /* Sync error in milliseconds */
"%*d," /* min buffer occupancy */
"%*d", /* max buffer occupancy */
10,
- 1000 * moving_average_sync_error / config.output_rate,
- 12, play_number, 7, conn->missing_packets, 7, conn->late_packets, 7,
- conn->too_late_packets, 7, conn->resend_requests, 5,
- minimum_buffer_occupancy, 5, maximum_buffer_occupancy);
+ 1000 * moving_average_sync_error / config.output_rate, 12, play_number, 7,
+ conn->missing_packets, 7, conn->late_packets, 7, conn->too_late_packets, 7,
+ conn->resend_requests, 5, minimum_buffer_occupancy, 5,
+ maximum_buffer_occupancy);
}
} else {
inform("No frames received in the last sampling interval.");
}
}
}
-
- debug(1,"This should never be called.");
-
-/* all done in the cleanup...
-
- debug(3, "Connection %d: player thread main loop exit.", conn->connection_number);
-
- if (config.statistics_requested) {
- int rawSeconds = (int)difftime(time(NULL), conn->playstart);
- int elapsedHours = rawSeconds / 3600;
- int elapsedMin = (rawSeconds / 60) % 60;
- int elapsedSec = rawSeconds % 60;
- inform("Playback Stopped. Total playing time %02d:%02d:%02d.", elapsedHours, elapsedMin,
- elapsedSec);
- }
-
-#ifdef HAVE_DACP_CLIENT
- relinquish_dacp_server_information(conn); // say it doesn't belong to this conversation thread any more...
+ debug(1, "This should never be called.");
-#else
- // stop watching for DACP port number stuff
- // this is only used for compatability, if dacp stuff isn't enabled.
- if (conn->dapo_private_storage) {
- mdns_dacp_dont_monitor(conn->dapo_private_storage);
- conn->dapo_private_storage = NULL;
- } else {
- debug(2, "DACP Monitor already stopped");
- }
-#endif
+ /* all done in the cleanup...
- debug(2, "Cancelling timing, control and audio threads...");
- debug(2, "Cancel timing thread.");
- pthread_cancel(rtp_timing_thread);
- debug(2, "Join timing thread.");
- pthread_join(rtp_timing_thread, NULL);
- debug(2, "Timing thread terminated.");
- debug(2, "Cancel control thread.");
- pthread_cancel(rtp_control_thread);
- debug(2, "Join control thread.");
- pthread_join(rtp_control_thread, NULL);
- debug(2, "Control thread terminated.");
- debug(2, "Cancel audio thread.");
- pthread_cancel(rtp_audio_thread);
- debug(2, "Join audio thread.");
- pthread_join(rtp_audio_thread, NULL);
- debug(2, "Audio thread terminated.");
- clear_reference_timestamp(conn);
- conn->rtp_running = 0;
+ debug(3, "Connection %d: player thread main loop exit.", conn->connection_number);
- debug(3, "Connection %d: stopping output device.", conn->connection_number);
+ if (config.statistics_requested) {
+ int rawSeconds = (int)difftime(time(NULL), conn->playstart);
+ int elapsedHours = rawSeconds / 3600;
+ int elapsedMin = (rawSeconds / 60) % 60;
+ int elapsedSec = rawSeconds % 60;
+ inform("Playback Stopped. Total playing time %02d:%02d:%02d.", elapsedHours, elapsedMin,
+ elapsedSec);
+ }
- if (config.output->stop)
- config.output->stop();
+ #ifdef HAVE_DACP_CLIENT
- debug(2, "Freeing audio buffers and decoders.");
+ relinquish_dacp_server_information(conn); // say it doesn't belong to this conversation thread
+ any more...
- free_audio_buffers(conn);
- terminate_decoders(conn);
- debug(2, "Connection %d: player thread terminated.", conn->connection_number);
- if (outbuf)
- free(outbuf);
- if (tbuf)
- free(tbuf);
- if (sbuf)
- free(sbuf);
- */
+ #else
+ // stop watching for DACP port number stuff
+ // this is only used for compatability, if dacp stuff isn't enabled.
+ if (conn->dapo_private_storage) {
+ mdns_dacp_dont_monitor(conn->dapo_private_storage);
+ conn->dapo_private_storage = NULL;
+ } else {
+ debug(2, "DACP Monitor already stopped");
+ }
+ #endif
+
+ debug(2, "Cancelling timing, control and audio threads...");
+ debug(2, "Cancel timing thread.");
+ pthread_cancel(rtp_timing_thread);
+ debug(2, "Join timing thread.");
+ pthread_join(rtp_timing_thread, NULL);
+ debug(2, "Timing thread terminated.");
+ debug(2, "Cancel control thread.");
+ pthread_cancel(rtp_control_thread);
+ debug(2, "Join control thread.");
+ pthread_join(rtp_control_thread, NULL);
+ debug(2, "Control thread terminated.");
+ debug(2, "Cancel audio thread.");
+ pthread_cancel(rtp_audio_thread);
+ debug(2, "Join audio thread.");
+ pthread_join(rtp_audio_thread, NULL);
+ debug(2, "Audio thread terminated.");
+ clear_reference_timestamp(conn);
+ conn->rtp_running = 0;
+
+ debug(3, "Connection %d: stopping output device.", conn->connection_number);
+
+ if (config.output->stop)
+ config.output->stop();
+
+ debug(2, "Freeing audio buffers and decoders.");
+
+ free_audio_buffers(conn);
+ terminate_decoders(conn);
+ debug(2, "Connection %d: player thread terminated.", conn->connection_number);
+ if (outbuf)
+ free(outbuf);
+ if (tbuf)
+ free(tbuf);
+ if (sbuf)
+ free(sbuf);
+ */
pthread_cleanup_pop(1);
pthread_exit(NULL);
}
// takes the volume as specified by the airplay protocol
void player_volume_without_notification(double airplay_volume, rtsp_conn_info *conn) {
- // no cancellation points here if we assume that the mute call to the back end has no cancellation points
+ // no cancellation points here if we assume that the mute call to the back end has no cancellation
+ // points
// The volume ranges -144.0 (mute) or -30 -- 0. See
// http://git.zx2c4.com/Airtunes2/about/#setting-volume
if (config.ignore_volume_control == 1)
scaled_attenuation = max_db;
else if (config.volume_control_profile == VCP_standard)
- scaled_attenuation = vol2attn(airplay_volume, max_db, min_db); // no cancellation points
+ scaled_attenuation = vol2attn(airplay_volume, max_db, min_db); // no cancellation points
else if (config.volume_control_profile == VCP_flat)
- scaled_attenuation = flat_vol2attn(airplay_volume, max_db, min_db); // no cancellation points
+ scaled_attenuation = flat_vol2attn(airplay_volume, max_db, min_db); // no cancellation points
else
debug(1, "Unrecognised volume control profile");
// %f",software_attenuation,temp_fix_volume,airplay_volume);
conn->fix_volume = temp_fix_volume;
- memory_barrier(); // no cancellation points
+ memory_barrier(); // no cancellation points
if (config.loudness)
loudness_set_volume(software_attenuation / 100);