debug: multilevel debug functions

This commit is contained in:
James Laird
2013-04-03 21:54:45 +11:00
parent 6090b490ed
commit 0f7b32ab6d
6 changed files with 25 additions and 22 deletions
+6 -2
View File
@@ -1,4 +1,8 @@
- makefile
- documentation
- PKGBUILD, initscript, systemd, launchd plist
- tidy debug printing
- alsa
- pipe
- avahi
- volume
- supervisor?
- pico mdns?
+2 -3
View File
@@ -56,10 +56,9 @@ void warn(char *format, ...) {
va_end(args);
}
void debug(char *format, ...) {
if (!debuglev)
void debug(int level, char *format, ...) {
if (level > debuglev)
return;
fprintf(stderr, "DEBUG: ");
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
+1 -1
View File
@@ -29,7 +29,7 @@ typedef struct {
extern int debuglev;
void die(char *format, ...);
void warn(char *format, ...);
void debug(char *format, ...);
void debug(int level, char *format, ...);
uint8_t *base64_dec(char *input, int *outlen);
char *base64_enc(uint8_t *input, int length);
+4 -4
View File
@@ -218,7 +218,7 @@ void player_put_packet(seq_t seqno, uint8_t *data, int len) {
pthread_mutex_lock(&ab_mutex);
if (ab_buffering && buf_fill >= config.buffer_start_fill) {
debug("buffering over. starting play\n");
debug(1, "buffering over. starting play\n");
ab_buffering = 0;
pthread_cond_signal(&ab_buffer_ready);
}
@@ -318,7 +318,7 @@ static void bf_est_update(short fill) {
bf_est_drift = biquad_filt(&bf_drift_lpf, CONTROL_B*(adj_error + err_deriv) + bf_est_drift);
debug("bf %d err %f drift %f desiring %f ed %f estd %f\n",
debug(3, "bf %d err %f drift %f desiring %f ed %f estd %f\n",
fill, bf_est_err, bf_est_drift, desired_fill, err_deriv, err_deriv + adj_error);
bf_playback_rate = 1.0 + adj_error + bf_est_drift;
@@ -401,12 +401,12 @@ static int stuff_buffer(double playback_rate, short *inptr, short *outptr) {
};
if (stuff) {
if (stuff==1) {
debug("+++++++++\n");
debug(2, "+++++++++\n");
// interpolate one sample
*outptr++ = dithered_vol(((long)inptr[-2] + (long)inptr[0]) >> 1);
*outptr++ = dithered_vol(((long)inptr[-1] + (long)inptr[1]) >> 1);
} else if (stuff==-1) {
debug("---------\n");
debug(2, "---------\n");
inptr++;
inptr++;
}
+5 -5
View File
@@ -72,15 +72,15 @@ static void *rtp_receiver(void *arg) {
continue;
}
if (type == 0x56 && seqno == 0) {
debug("resend-related request packet received, ignoring.\n");
debug(2, "resend-related request packet received, ignoring.\n");
continue;
}
debug("Unknown RTP packet of type 0x%02X length %d seqno %d\n", type, nread, seqno);
debug(1, "Unknown RTP packet of type 0x%02X length %d seqno %d\n", type, nread, seqno);
}
warn("Unknown RTP packet of type 0x%02X length %d\n", type, nread);
}
debug("RTP thread interrupted. terminating.\n");
debug(1, "RTP thread interrupted. terminating.\n");
close(sock);
return NULL;
@@ -128,7 +128,7 @@ int rtp_setup(SOCKADDR *remote, int cport, int tport) {
if (running)
die("rtp_setup called with active stream!\n");
debug("rtp_setup: cport=%d tport=%d\n", cport, tport);
debug(1, "rtp_setup: cport=%d tport=%d\n", cport, tport);
// we do our own timing and ignore the timing port.
// an audio perfectionist may wish to learn the protocol.
@@ -147,7 +147,7 @@ int rtp_setup(SOCKADDR *remote, int cport, int tport) {
int sport = bind_port(remote);
debug("rtp listening on port %d\n", sport);
debug(1, "rtp listening on port %d\n", sport);
please_shutdown = 0;
pthread_create(&rtp_thread, NULL, &rtp_receiver, NULL);
+7 -7
View File
@@ -61,7 +61,7 @@ static inline int rtsp_playing(void) {
static void rtsp_take_player(void) {
if (pthread_mutex_trylock(&playing_mutex)) {
debug("shutting down playing thread\n");
debug(1, "shutting down playing thread\n");
// XXX minor race condition between please_shutdown and signal delivery
please_shutdown = 1;
pthread_kill(playing_thread, SIGUSR1);
@@ -161,7 +161,7 @@ static int msg_handle_line(rtsp_message **pmsg, char *line) {
*pmsg = msg;
char *sp, *p;
debug("received request: %s\n", line);
debug(1, "received request: %s\n", line);
p = strtok_r(line, " ", &sp);
if (!p)
@@ -191,7 +191,7 @@ static int msg_handle_line(rtsp_message **pmsg, char *line) {
*p = 0;
p += 2;
msg_add_header(msg, line, p);
debug(" %s: %s\n", line, p);
debug(2, " %s: %s\n", line, p);
return -1;
} else {
char *cl = msg_get_header(msg, "Content-Length");
@@ -219,12 +219,12 @@ static rtsp_message * rtsp_read_request(int fd) {
while (msg_size < 0) {
if (please_shutdown) {
debug("RTSP shutdown requested\n");
debug(1, "RTSP shutdown requested\n");
goto shutdown;
}
nread = read(fd, buf+inbuf, buflen - inbuf);
if (!nread) {
debug("RTSP connection closed\n");
debug(1, "RTSP connection closed\n");
goto shutdown;
}
if (nread < 0) {
@@ -291,10 +291,10 @@ static void msg_write_response(int fd, rtsp_message *resp) {
"RTSP/1.0 %d %s\r\n", resp->respcode,
resp->respcode==200 ? "OK" : "Error");
write(fd, rbuf, nrbuf);
debug("sending response: %s", rbuf);
debug(1, "sending response: %s", rbuf);
int i;
for (i=0; i<resp->nheaders; i++) {
debug(" %s: %s\n", resp->name[i], resp->value[i]);
debug(2, " %s: %s\n", resp->name[i], resp->value[i]);
write(fd, resp->name[i], strlen(resp->name[i]));
write(fd, ": ", 2);
write(fd, resp->value[i], strlen(resp->value[i]));