Add new optioons --statistics to print out the, um, statistics, and remove them from debug level 1.

This commit is contained in:
Mike Brady
2014-11-21 17:39:27 +00:00
parent 6db9ccf020
commit 705a0be1e4
7 changed files with 42 additions and 6 deletions
+10
View File
@@ -120,6 +120,16 @@ void debug(int level, char *format, ...) {
daemon_log(LOG_DEBUG,"%s", s);
}
void inform(char *format, ...) {
char s[1024];
s[0]=0;
va_list args;
va_start(args, format);
vsprintf(s,format,args);
va_end(args);
daemon_log(LOG_INFO,"%s", s);
}
#ifdef HAVE_LIBPOLARSSL
char *base64_enc(uint8_t *input, int length) {
char *buf = NULL;
+2
View File
@@ -55,6 +55,7 @@ typedef struct {
uint32_t iTunesLatency; // supplied with --iTunesLatency option
uint32_t AirPlayLatency; //supplied with --AirPlayLatency option
int daemonise;
int statistics_requested;
char *cmd_start, *cmd_stop;
int cmd_blocking;
enum stuffing_type packet_stuffing;
@@ -72,6 +73,7 @@ void set_requested_connection_state_to_output(int v);
int debuglev;
void die(char *format, ...);
void warn(char *format, ...);
void inform(char *format, ...);
void debug(int level, char *format, ...);
uint8_t *base64_dec(char *input, int *outlen);
+4 -1
View File
@@ -2,7 +2,7 @@
.SH NAME
shairport-sync \- Synchronised Audio Player for iTunes / AirPlay
.SH SYNOPSIS
\fBshairport-sync [-dvw]\fB [-a \fB\fIname\fB]\fB [-A \fB\fIlatency\fB]\fB [-B \fB\fIcommand\fB]\fB [-E \fB\fIcommand\fB]\fB [-i \fB\fIlatency\fB]\fB [-m \fB\fIbackend\fB]\fB [-o \fB\fIbackend\fB]\fB [-r \fB\fIthreshold\fB]\fB [-S \fB\fImode\fB]\fB [-t \fB\fItimeout\fB]\fB [-- \fB\fIaudio_backend_options\fB]\fB
\fBshairport-sync [-dvw]\fB [-a \fB\fIname\fB]\fB [-A \fB\fIlatency\fB]\fB [-B \fB\fIcommand\fB]\fB [-E \fB\fIcommand\fB]\fB [-i \fB\fIlatency\fB]\fB [-m \fB\fIbackend\fB]\fB [-o \fB\fIbackend\fB]\fB [-r \fB\fIthreshold\fB]\fB [--statistics\fB [-S \fB\fImode\fB]\fB [-t \fB\fItimeout\fB]\fB [-- \fB\fIaudio_backend_options\fB]\fB
shairport-sync -D\fB
@@ -73,6 +73,9 @@ Reconnect the shairport-sync daemon to the output device and exit. It may take a
\fB-r \f1\fIthreshold\f1\fB | --resync=\f1\fIthreshold\f1
Resynchronise if timings differ by more than \fIthreshold\f1 frames. If the output timing differs from the source timing by more than the threshold, output will be muted and a full resynchronisation will occur. The default threshold is 2,205 frames, i.e. 50 milliseconds. Specify \fB0\f1 to disable resynchronisation.
.TP
\fB--statistics=\f1
Print some statistics in the standard output, or in the logfile if in daemon mode.
.TP
\fB-S \f1\fImode\f1\fB | --stuffing=\f1\fImode\f1
Stuff the audio stream using the \fImode\f1. "Stuffing" refers to the process of adding or removing frames of audio to or from the stream sent to the output device to keep it exactly in synchrony with the player. The default mode, \fBbasic\f1, is normally almost completely inaudible. The alternative mode, \fBsoxr\f1, is even less obtrusive but requires much more processing power. For this mode, support for libsoxr, the SoX Resampler Library, must be selected when shairport-sync is compiled.
.TP
+8
View File
@@ -43,6 +43,7 @@
<opt>[-m </opt><arg>backend</arg><opt>]</opt>
<opt>[-o </opt><arg>backend</arg><opt>]</opt>
<opt>[-r </opt><arg>threshold</arg><opt>]</opt>
<opt>[--statistics</opt>
<opt>[-S </opt><arg>mode</arg><opt>]</opt>
<opt>[-t </opt><arg>timeout</arg><opt>]</opt>
<opt>[-- </opt><arg>audio_backend_options</arg><opt>]</opt>
@@ -217,6 +218,13 @@
</p></optdesc>
</option>
<option>
<p><opt>--statistics=</opt></p>
<optdesc><p>
Print some statistics in the standard output, or in the logfile if in daemon mode.
</p></optdesc>
</option>
<option>
<p><opt>-S </opt><arg>mode</arg><opt> | --stuffing=</opt><arg>mode</arg></p>
<optdesc><p>
+8
View File
@@ -15,6 +15,7 @@
<b>[-m </b><em>backend</em><b>]</b>
<b>[-o </b><em>backend</em><b>]</b>
<b>[-r </b><em>threshold</em><b>]</b>
<b>[--statistics</b>
<b>[-S </b><em>mode</em><b>]</b>
<b>[-t </b><em>timeout</em><b>]</b>
<b>[-- </b><em>audio_backend_options</em><b>]</b>
@@ -203,6 +204,13 @@
<p><b>--statistics=</b></p>
<p>
Print some statistics in the standard output, or in the logfile if in daemon mode.
</p>
<p><b>-S </b><em>mode</em><b> | --stuffing=</b><em>mode</em></p>
<p>
Stuff the audio stream using the <em>mode</em>. &quot;Stuffing&quot; refers to the
+3 -1
View File
@@ -37,6 +37,7 @@
#include <math.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <sys/syslog.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -998,7 +999,8 @@ static void *player_thread_func(void *arg) {
double moving_average_insertions_plus_deletions = (1.0*tsum_of_insertions_and_deletions)/number_of_statistics;
double moving_average_drift = (1.0*tsum_of_drifts)/number_of_statistics;
// if ((play_number/print_interval)%20==0)
debug(1,"Sync error: %.1f (frames); net correction: %.1f (ppm); corrections: %.1f (ppm); missing packets %llu; late packets %llu; too late packets %llu; resend requests %llu; min DAC queue size %lli, min and max buffer occupancy %u and %u.", moving_average_sync_error, moving_average_correction*1000000/352, moving_average_insertions_plus_deletions*1000000/352,missing_packets,late_packets,too_late_packets,resend_requests,minimum_dac_queue_size,minimum_buffer_occupancy,maximum_buffer_occupancy);
if (config.statistics_requested)
inform("Sync error: %.1f (frames); net correction: %.1f (ppm); corrections: %.1f (ppm); missing packets %llu; late packets %llu; too late packets %llu; resend requests %llu; min DAC queue size %lli, min and max buffer occupancy %u and %u.", moving_average_sync_error, moving_average_correction*1000000/352, moving_average_insertions_plus_deletions*1000000/352,missing_packets,late_packets,too_late_packets,resend_requests,minimum_dac_queue_size,minimum_buffer_occupancy,maximum_buffer_occupancy);
minimum_dac_queue_size=1000000; // hack reset
maximum_buffer_occupancy = 0; // can't be less than this
minimum_buffer_occupancy = BUFFER_FRAMES; // can't be more than this
+7 -4
View File
@@ -74,9 +74,9 @@ void shairport_shutdown() {
static void sig_ignore(int foo, siginfo_t *bar, void *baz) {
}
static void sig_shutdown(int foo, siginfo_t *bar, void *baz) {
daemon_log(LOG_NOTICE, "Shutdown requested...");
debug(1, "shutdown requested...");
shairport_shutdown();
daemon_log(LOG_NOTICE, "Exit...");
daemon_log(LOG_NOTICE, "exit...");
daemon_retval_send(255);
daemon_pid_file_remove();
exit(0);
@@ -177,7 +177,7 @@ void usage(char *progname) {
printf(" shairport tries them all until one works.\n");
printf(" -r, --resync=THRESHOLD resync if error exceeds this number of frames. Set to 0 to stop resyncing.\n");
printf(" -t, --timeout=SECONDS go back to idle mode from play mode after a break in communications of this many seconds (default 120). Set to 0 never to exit play mode.\n");
printf(" --statistics print some interesting statistics -- output to the logfile if running as a daemon.\n");
printf("\n");
mdns_ls_backends();
printf("\n");
@@ -190,6 +190,7 @@ int parse_options(int argc, char **argv) {
char *stuffing = NULL; /* used for picking up the stuffing option */
poptContext optCon; /* context for parsing command-line options */
struct poptOption optionsTable[] = {
{ "statistics", 0, POPT_ARG_NONE, &config.statistics_requested, 0, NULL},
{ "version", 'V', POPT_ARG_NONE, NULL, 0, NULL},
{ "verbose", 'v', POPT_ARG_NONE, NULL, 'v', NULL },
{ "daemon", 'd', POPT_ARG_NONE, &config.daemonise, 0, NULL },
@@ -247,6 +248,7 @@ int parse_options(int argc, char **argv) {
}
/* Print out options */
debug(2,"statistics_requester status is %d.",config.statistics_requested);
debug(2,"daemon status is %d.",config.daemonise);
debug(2,"rtsp listening port is %d.",config.port);
debug(2,"Shairport Sync player name is \"%s\".",config.apname);
@@ -332,6 +334,7 @@ int main(int argc, char **argv) {
memset(&config, 0, sizeof(config));
// set defaults
config.statistics_requested - 0; // don't print stats in the log
config.latency = 99400; // iTunes
config.userSuppliedLatency = 0; // zero means none supplied
config.iTunesLatency = 99400; // this seems to work pretty well for iTunes -- two left-ear headphones, one from the iMac jack, one from an NSLU2 running a cheap "3D Sound" USB Soundcard
@@ -495,7 +498,7 @@ int main(int argc, char **argv) {
}
config.output->init(argc-audio_arg, argv+audio_arg);
daemon_log(LOG_NOTICE, "Successful startup.");
daemon_log(LOG_NOTICE, "startup");
uint8_t ap_md5[16];