pcm: use GLib logging

This commit is contained in:
Max Kellermann 2008-12-29 17:28:49 +01:00
parent f4ce43b958
commit e0fe4eb722
4 changed files with 76 additions and 67 deletions

View File

@ -18,10 +18,14 @@
#include "pcm_channels.h" #include "pcm_channels.h"
#include "utils.h" #include "utils.h"
#include "log.h"
#include <glib.h>
#include <assert.h> #include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static void static void
pcm_convert_channels_16_1_to_2(int16_t *dest, const int16_t *src, pcm_convert_channels_16_1_to_2(int16_t *dest, const int16_t *src,
unsigned num_frames) unsigned num_frames)
@ -93,8 +97,8 @@ pcm_convert_channels_16(int8_t dest_channels,
pcm_convert_channels_16_n_to_2(buf, src_channels, src, pcm_convert_channels_16_n_to_2(buf, src_channels, src,
num_frames); num_frames);
else { else {
ERROR("conversion %u->%u channels is not supported\n", g_warning("conversion %u->%u channels is not supported",
src_channels, dest_channels); src_channels, dest_channels);
return NULL; return NULL;
} }
@ -172,8 +176,8 @@ pcm_convert_channels_24(int8_t dest_channels,
pcm_convert_channels_24_n_to_2(buf, src_channels, src, pcm_convert_channels_24_n_to_2(buf, src_channels, src,
num_frames); num_frames);
else { else {
ERROR("conversion %u->%u channels is not supported\n", g_warning("conversion %u->%u channels is not supported",
src_channels, dest_channels); src_channels, dest_channels);
return NULL; return NULL;
} }

View File

@ -19,13 +19,17 @@
#include "pcm_resample.h" #include "pcm_resample.h"
#include "conf.h" #include "conf.h"
#include "log.h"
#include "utils.h" #include "utils.h"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static int pcm_resample_get_converter(void) static int pcm_resample_get_converter(void)
{ {
const char *conf = getConfigParamValue(CONF_SAMPLERATE_CONVERTER); const char *conf = getConfigParamValue(CONF_SAMPLERATE_CONVERTER);
@ -54,10 +58,10 @@ static int pcm_resample_get_converter(void)
goto out; goto out;
} }
ERROR("unknown samplerate converter \"%s\"\n", conf); g_warning("unknown samplerate converter \"%s\"", conf);
out: out:
DEBUG("selecting samplerate converter \"%s\"\n", g_debug("selecting samplerate converter \"%s\"",
src_get_name(convalgo)); src_get_name(convalgo));
return convalgo; return convalgo;
} }
@ -89,15 +93,15 @@ pcm_resample_set(struct pcm_resample_state *state,
state->state = src_new(convalgo, channels, &error); state->state = src_new(convalgo, channels, &error);
if (!state->state) { if (!state->state) {
ERROR("cannot create new libsamplerate state: %s\n", g_warning("cannot create new libsamplerate state: %s",
src_strerror(error)); src_strerror(error));
state->error = true; state->error = true;
return; return;
} }
data->src_ratio = (double)dest_rate / (double)src_rate; data->src_ratio = (double)dest_rate / (double)src_rate;
DEBUG("setting samplerate conversion ratio to %.2lf\n", g_debug("setting samplerate conversion ratio to %.2lf",
data->src_ratio); data->src_ratio);
src_set_ratio(state->state, data->src_ratio); src_set_ratio(state->state, data->src_ratio);
} }
@ -142,8 +146,8 @@ pcm_resample_16(uint8_t channels,
error = src_process(state->state, data); error = src_process(state->state, data);
if (error) { if (error) {
ERROR("error processing samples with libsamplerate: %s\n", g_warning("error processing samples with libsamplerate: %s",
src_strerror(error)); src_strerror(error));
state->error = true; state->error = true;
return 0; return 0;
} }
@ -215,8 +219,8 @@ pcm_resample_24(uint8_t channels,
error = src_process(state->state, data); error = src_process(state->state, data);
if (error) { if (error) {
ERROR("error processing samples with libsamplerate: %s\n", g_warning("error processing samples with libsamplerate: %s",
src_strerror(error)); src_strerror(error));
state->error = true; state->error = true;
return 0; return 0;
} }

View File

@ -18,7 +18,6 @@
#include "pcm_utils.h" #include "pcm_utils.h"
#include "pcm_channels.h" #include "pcm_channels.h"
#include "log.h"
#include "utils.h" #include "utils.h"
#include "conf.h" #include "conf.h"
#include "audio_format.h" #include "audio_format.h"
@ -28,6 +27,9 @@
#include <math.h> #include <math.h>
#include <glib.h> #include <glib.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static inline int static inline int
pcm_dither(void) pcm_dither(void)
{ {
@ -118,8 +120,8 @@ void pcm_volume(char *buffer, int bufferSize,
break; break;
default: default:
FATAL("%u bits not supported by pcm_volume!\n", g_error("%u bits not supported by pcm_volume!\n",
format->bits); format->bits);
} }
} }
@ -193,7 +195,7 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t size,
break; break;
default: default:
FATAL("%u bits not supported by pcm_add!\n", format->bits); g_error("%u bits not supported by pcm_add!\n", format->bits);
} }
} }
@ -278,7 +280,7 @@ pcm_convert_to_16(struct pcm_convert_state *convert,
return buf; return buf;
} }
ERROR("only 8 or 16 bits are supported for conversion!\n"); g_warning("only 8 or 16 bits are supported for conversion!\n");
return NULL; return NULL;
} }
@ -340,7 +342,7 @@ pcm_convert_to_24(uint8_t bits, const void *src,
return src; return src;
} }
ERROR("only 8 or 24 bits are supported for conversion!\n"); g_warning("only 8 or 24 bits are supported for conversion!\n");
return NULL; return NULL;
} }
@ -442,7 +444,7 @@ size_t pcm_convert(const struct audio_format *inFormat,
convState); convState);
default: default:
FATAL("cannot convert to %u bit\n", outFormat->bits); g_error("cannot convert to %u bit\n", outFormat->bits);
} }
} }

View File

@ -18,7 +18,6 @@
#include "zeroconf.h" #include "zeroconf.h"
#include "conf.h" #include "conf.h"
#include "log.h"
#include "listen.h" #include "listen.h"
#include "ioops.h" #include "ioops.h"
#include "utils.h" #include "utils.h"
@ -206,13 +205,13 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
char *n; char *n;
assert(g); assert(g);
DEBUG("Avahi: Service group changed to state %d\n", state); g_debug("Avahi: Service group changed to state %d", state);
switch (state) { switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED: case AVAHI_ENTRY_GROUP_ESTABLISHED:
/* The entry group has been established successfully */ /* The entry group has been established successfully */
LOG("Avahi: Service '%s' successfully established.\n", g_message("Avahi: Service '%s' successfully established.",
avahiName); avahiName);
break; break;
case AVAHI_ENTRY_GROUP_COLLISION: case AVAHI_ENTRY_GROUP_COLLISION:
@ -221,26 +220,26 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
avahi_free(avahiName); avahi_free(avahiName);
avahiName = n; avahiName = n;
LOG("Avahi: Service name collision, renaming service to '%s'\n", g_message("Avahi: Service name collision, renaming service to '%s'",
avahiName); avahiName);
/* And recreate the services */ /* And recreate the services */
avahiRegisterService(avahi_entry_group_get_client(g)); avahiRegisterService(avahi_entry_group_get_client(g));
break; break;
case AVAHI_ENTRY_GROUP_FAILURE: case AVAHI_ENTRY_GROUP_FAILURE:
ERROR("Avahi: Entry group failure: %s\n", g_warning("Avahi: Entry group failure: %s",
avahi_strerror(avahi_client_errno avahi_strerror(avahi_client_errno
(avahi_entry_group_get_client(g)))); (avahi_entry_group_get_client(g))));
/* Some kind of failure happened while we were registering our services */ /* Some kind of failure happened while we were registering our services */
avahiRunning = 0; avahiRunning = 0;
break; break;
case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_UNCOMMITED:
DEBUG("Avahi: Service group is UNCOMMITED\n"); g_debug("Avahi: Service group is UNCOMMITED");
break; break;
case AVAHI_ENTRY_GROUP_REGISTERING: case AVAHI_ENTRY_GROUP_REGISTERING:
DEBUG("Avahi: Service group is REGISTERING\n"); g_debug("Avahi: Service group is REGISTERING");
} }
} }
@ -249,15 +248,15 @@ static void avahiRegisterService(AvahiClient * c)
{ {
int ret; int ret;
assert(c); assert(c);
DEBUG("Avahi: Registering service %s/%s\n", SERVICE_TYPE, avahiName); g_debug("Avahi: Registering service %s/%s", SERVICE_TYPE, avahiName);
/* If this is the first time we're called, /* If this is the first time we're called,
* let's create a new entry group */ * let's create a new entry group */
if (!avahiGroup) { if (!avahiGroup) {
avahiGroup = avahi_entry_group_new(c, avahiGroupCallback, NULL); avahiGroup = avahi_entry_group_new(c, avahiGroupCallback, NULL);
if (!avahiGroup) { if (!avahiGroup) {
ERROR("Avahi: Failed to create avahi EntryGroup: %s\n", g_warning("Avahi: Failed to create avahi EntryGroup: %s",
avahi_strerror(avahi_client_errno(c))); avahi_strerror(avahi_client_errno(c)));
goto fail; goto fail;
} }
} }
@ -271,16 +270,16 @@ static void avahiRegisterService(AvahiClient * c)
0, avahiName, SERVICE_TYPE, NULL, 0, avahiName, SERVICE_TYPE, NULL,
NULL, boundPort, NULL); NULL, boundPort, NULL);
if (ret < 0) { if (ret < 0) {
ERROR("Avahi: Failed to add service %s: %s\n", SERVICE_TYPE, g_warning("Avahi: Failed to add service %s: %s", SERVICE_TYPE,
avahi_strerror(ret)); avahi_strerror(ret));
goto fail; goto fail;
} }
/* Tell the server to register the service group */ /* Tell the server to register the service group */
ret = avahi_entry_group_commit(avahiGroup); ret = avahi_entry_group_commit(avahiGroup);
if (ret < 0) { if (ret < 0) {
ERROR("Avahi: Failed to commit service group: %s\n", g_warning("Avahi: Failed to commit service group: %s",
avahi_strerror(ret)); avahi_strerror(ret));
goto fail; goto fail;
} }
return; return;
@ -297,11 +296,11 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
assert(c); assert(c);
/* Called whenever the client or server state changes */ /* Called whenever the client or server state changes */
DEBUG("Avahi: Client changed to state %d\n", state); g_debug("Avahi: Client changed to state %d", state);
switch (state) { switch (state) {
case AVAHI_CLIENT_S_RUNNING: case AVAHI_CLIENT_S_RUNNING:
DEBUG("Avahi: Client is RUNNING\n"); g_debug("Avahi: Client is RUNNING");
/* The server has startup successfully and registered its host /* The server has startup successfully and registered its host
* name on the network, so it's time to create our services */ * name on the network, so it's time to create our services */
@ -312,8 +311,8 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
case AVAHI_CLIENT_FAILURE: case AVAHI_CLIENT_FAILURE:
reason = avahi_client_errno(c); reason = avahi_client_errno(c);
if (reason == AVAHI_ERR_DISCONNECTED) { if (reason == AVAHI_ERR_DISCONNECTED) {
LOG("Avahi: Client Disconnected, " g_message("Avahi: Client Disconnected, "
"will reconnect shortly\n"); "will reconnect shortly");
if (avahiGroup) { if (avahiGroup) {
avahi_entry_group_free(avahiGroup); avahi_entry_group_free(avahiGroup);
avahiGroup = NULL; avahiGroup = NULL;
@ -326,43 +325,43 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
avahiClientCallback, NULL, avahiClientCallback, NULL,
&reason); &reason);
if (!avahiClient) { if (!avahiClient) {
ERROR("Avahi: Could not reconnect: %s\n", g_warning("Avahi: Could not reconnect: %s",
avahi_strerror(reason)); avahi_strerror(reason));
avahiRunning = 0; avahiRunning = 0;
} }
} else { } else {
ERROR("Avahi: Client failure: %s (terminal)\n", g_warning("Avahi: Client failure: %s (terminal)",
avahi_strerror(reason)); avahi_strerror(reason));
avahiRunning = 0; avahiRunning = 0;
} }
break; break;
case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_COLLISION:
DEBUG("Avahi: Client is COLLISION\n"); g_debug("Avahi: Client is COLLISION");
/* Let's drop our registered services. When the server is back /* Let's drop our registered services. When the server is back
* in AVAHI_SERVER_RUNNING state we will register them * in AVAHI_SERVER_RUNNING state we will register them
* again with the new host name. */ * again with the new host name. */
if (avahiGroup) { if (avahiGroup) {
DEBUG("Avahi: Resetting group\n"); g_debug("Avahi: Resetting group");
avahi_entry_group_reset(avahiGroup); avahi_entry_group_reset(avahiGroup);
} }
case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_REGISTERING:
DEBUG("Avahi: Client is REGISTERING\n"); g_debug("Avahi: Client is REGISTERING");
/* The server records are now being established. This /* The server records are now being established. This
* might be caused by a host name change. We need to wait * might be caused by a host name change. We need to wait
* for our own records to register until the host name is * for our own records to register until the host name is
* properly esatblished. */ * properly esatblished. */
if (avahiGroup) { if (avahiGroup) {
DEBUG("Avahi: Resetting group\n"); g_debug("Avahi: Resetting group");
avahi_entry_group_reset(avahiGroup); avahi_entry_group_reset(avahiGroup);
} }
break; break;
case AVAHI_CLIENT_CONNECTING: case AVAHI_CLIENT_CONNECTING:
DEBUG("Avahi: Client is CONNECTING\n"); g_debug("Avahi: Client is CONNECTING");
} }
} }
@ -383,7 +382,7 @@ static int avahiFdset(fd_set * rfds, fd_set * wfds, fd_set * efds)
FD_SET(w->fd, efds); FD_SET(w->fd, efds);
} }
if (w->requestedEvent & AVAHI_WATCH_HUP) { if (w->requestedEvent & AVAHI_WATCH_HUP) {
ERROR("Avahi: No support for HUP events! (ignoring)\n"); g_warning("Avahi: No support for HUP events! (ignoring)");
} }
if (w->fd > maxfd) if (w->fd > maxfd)
@ -447,14 +446,14 @@ static int avahiFdconsume(int fdCount, fd_set * rfds, fd_set * wfds,
static void init_avahi(const char *serviceName) static void init_avahi(const char *serviceName)
{ {
int error; int error;
DEBUG("Avahi: Initializing interface\n"); g_debug("Avahi: Initializing interface");
if (avahi_is_valid_service_name(serviceName)) { if (avahi_is_valid_service_name(serviceName)) {
avahiName = avahi_strdup(serviceName); avahiName = avahi_strdup(serviceName);
} else { } else {
ERROR("Invalid zeroconf_name \"%s\", defaulting to " g_warning("Invalid zeroconf_name \"%s\", defaulting to "
"\"%s\" instead.\n", "\"%s\" instead.",
serviceName, SERVICE_NAME); serviceName, SERVICE_NAME);
avahiName = avahi_strdup(SERVICE_NAME); avahiName = avahi_strdup(SERVICE_NAME);
} }
@ -473,8 +472,8 @@ static void init_avahi(const char *serviceName)
avahiClientCallback, NULL, &error); avahiClientCallback, NULL, &error);
if (!avahiClient) { if (!avahiClient) {
ERROR("Avahi: Failed to create client: %s\n", g_warning("Avahi: Failed to create client: %s",
avahi_strerror(error)); avahi_strerror(error));
goto fail; goto fail;
} }
@ -535,13 +534,13 @@ static void dnsRegisterCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
void *context) void *context)
{ {
if (errorCode != kDNSServiceErr_NoError) { if (errorCode != kDNSServiceErr_NoError) {
ERROR("Failed to register zeroconf service.\n"); g_warning("Failed to register zeroconf service.");
DNSServiceRefDeallocate(dnsReference); DNSServiceRefDeallocate(dnsReference);
dnsReference = NULL; dnsReference = NULL;
deregisterIO(&zeroConfIo); deregisterIO(&zeroConfIo);
} else { } else {
DEBUG("Registered zeroconf service with name '%s'\n", name); g_debug("Registered zeroconf service with name '%s'", name);
} }
} }
@ -556,7 +555,7 @@ static void init_zeroconf_osx(const char *serviceName)
NULL); NULL);
if (error != kDNSServiceErr_NoError) { if (error != kDNSServiceErr_NoError) {
ERROR("Failed to register zeroconf service.\n"); g_warning("Failed to register zeroconf service.");
if (dnsReference) { if (dnsReference) {
DNSServiceRefDeallocate(dnsReference); DNSServiceRefDeallocate(dnsReference);
@ -603,7 +602,7 @@ void finishZeroconf(void)
return; return;
#ifdef HAVE_AVAHI #ifdef HAVE_AVAHI
DEBUG("Avahi: Shutting down interface\n"); g_debug("Avahi: Shutting down interface");
deregisterIO(&zeroConfIo); deregisterIO(&zeroConfIo);
if (avahiGroup) { if (avahiGroup) {
@ -625,7 +624,7 @@ void finishZeroconf(void)
if (dnsReference != NULL) { if (dnsReference != NULL) {
DNSServiceRefDeallocate(dnsReference); DNSServiceRefDeallocate(dnsReference);
dnsReference = NULL; dnsReference = NULL;
DEBUG("Deregistered Zeroconf service.\n"); g_debug("Deregistered Zeroconf service.");
} }
#endif #endif
} }