Log: new logging library API
Prepare to migrate away from GLib. Currently, we're still using GLib as a backend.
This commit is contained in:
@@ -25,15 +25,13 @@
|
||||
#include "util/Manual.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "alsa"
|
||||
|
||||
#define ALSA_PCM_NEW_HW_PARAMS_API
|
||||
#define ALSA_PCM_NEW_SW_PARAMS_API
|
||||
|
||||
@@ -216,8 +214,9 @@ alsa_test_default_device(void)
|
||||
int ret = snd_pcm_open(&handle, default_device,
|
||||
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
|
||||
if (ret) {
|
||||
g_message("Error opening default ALSA device: %s\n",
|
||||
snd_strerror(-ret));
|
||||
FormatError(alsa_output_domain,
|
||||
"Error opening default ALSA device: %s",
|
||||
snd_strerror(-ret));
|
||||
return false;
|
||||
} else
|
||||
snd_pcm_close(handle);
|
||||
@@ -413,9 +412,11 @@ configure_hw:
|
||||
err = snd_pcm_hw_params_set_access(ad->pcm, hwparams,
|
||||
SND_PCM_ACCESS_MMAP_INTERLEAVED);
|
||||
if (err < 0) {
|
||||
g_warning("Cannot set mmap'ed mode on ALSA device \"%s\": %s\n",
|
||||
alsa_device(ad), snd_strerror(-err));
|
||||
g_warning("Falling back to direct write mode\n");
|
||||
FormatWarning(alsa_output_domain,
|
||||
"Cannot set mmap'ed mode on ALSA device \"%s\": %s",
|
||||
alsa_device(ad), snd_strerror(-err));
|
||||
LogWarning(alsa_output_domain,
|
||||
"Falling back to direct write mode");
|
||||
ad->use_mmap = false;
|
||||
} else
|
||||
ad->writei = snd_pcm_mmap_writei;
|
||||
@@ -443,8 +444,9 @@ configure_hw:
|
||||
|
||||
snd_pcm_format_t format;
|
||||
if (snd_pcm_hw_params_get_format(hwparams, &format) == 0)
|
||||
g_debug("format=%s (%s)", snd_pcm_format_name(format),
|
||||
snd_pcm_format_description(format));
|
||||
FormatDebug(alsa_output_domain,
|
||||
"format=%s (%s)", snd_pcm_format_name(format),
|
||||
snd_pcm_format_description(format));
|
||||
|
||||
err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams,
|
||||
&channels);
|
||||
@@ -473,9 +475,9 @@ configure_hw:
|
||||
unsigned buffer_time_min, buffer_time_max;
|
||||
snd_pcm_hw_params_get_buffer_time_min(hwparams, &buffer_time_min, 0);
|
||||
snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time_max, 0);
|
||||
g_debug("buffer: size=%u..%u time=%u..%u",
|
||||
(unsigned)buffer_size_min, (unsigned)buffer_size_max,
|
||||
buffer_time_min, buffer_time_max);
|
||||
FormatDebug(alsa_output_domain, "buffer: size=%u..%u time=%u..%u",
|
||||
(unsigned)buffer_size_min, (unsigned)buffer_size_max,
|
||||
buffer_time_min, buffer_time_max);
|
||||
|
||||
snd_pcm_uframes_t period_size_min, period_size_max;
|
||||
snd_pcm_hw_params_get_period_size_min(hwparams, &period_size_min, 0);
|
||||
@@ -483,9 +485,9 @@ configure_hw:
|
||||
unsigned period_time_min, period_time_max;
|
||||
snd_pcm_hw_params_get_period_time_min(hwparams, &period_time_min, 0);
|
||||
snd_pcm_hw_params_get_period_time_max(hwparams, &period_time_max, 0);
|
||||
g_debug("period: size=%u..%u time=%u..%u",
|
||||
(unsigned)period_size_min, (unsigned)period_size_max,
|
||||
period_time_min, period_time_max);
|
||||
FormatDebug(alsa_output_domain, "period: size=%u..%u time=%u..%u",
|
||||
(unsigned)period_size_min, (unsigned)period_size_max,
|
||||
period_time_min, period_time_max);
|
||||
|
||||
if (ad->buffer_time > 0) {
|
||||
buffer_time = ad->buffer_time;
|
||||
@@ -504,8 +506,9 @@ configure_hw:
|
||||
if (period_time_ro == 0 && buffer_time >= 10000) {
|
||||
period_time_ro = period_time = buffer_time / 4;
|
||||
|
||||
g_debug("default period_time = buffer_time/4 = %u/4 = %u",
|
||||
buffer_time, period_time);
|
||||
FormatDebug(alsa_output_domain,
|
||||
"default period_time = buffer_time/4 = %u/4 = %u",
|
||||
buffer_time, period_time);
|
||||
}
|
||||
|
||||
if (period_time_ro > 0) {
|
||||
@@ -525,7 +528,8 @@ configure_hw:
|
||||
} else if (err < 0)
|
||||
goto error;
|
||||
if (retry != MPD_ALSA_RETRY_NR)
|
||||
g_debug("ALSA period_time set to %d\n", period_time);
|
||||
FormatDebug(alsa_output_domain,
|
||||
"ALSA period_time set to %d", period_time);
|
||||
|
||||
snd_pcm_uframes_t alsa_buffer_size;
|
||||
cmd = "snd_pcm_hw_params_get_buffer_size";
|
||||
@@ -567,8 +571,8 @@ configure_hw:
|
||||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
g_debug("buffer_size=%u period_size=%u",
|
||||
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
|
||||
FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u",
|
||||
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
|
||||
|
||||
if (alsa_period_size == 0)
|
||||
/* this works around a SIGFPE bug that occurred when
|
||||
@@ -673,8 +677,9 @@ alsa_open(struct audio_output *ao, AudioFormat &audio_format, Error &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
g_debug("opened %s type=%s", snd_pcm_name(ad->pcm),
|
||||
snd_pcm_type_name(snd_pcm_type(ad->pcm)));
|
||||
FormatDebug(alsa_output_domain, "opened %s type=%s",
|
||||
snd_pcm_name(ad->pcm),
|
||||
snd_pcm_type_name(snd_pcm_type(ad->pcm)));
|
||||
|
||||
if (!alsa_setup_or_dsd(ad, audio_format, error)) {
|
||||
snd_pcm_close(ad->pcm);
|
||||
@@ -700,9 +705,12 @@ static int
|
||||
alsa_recover(AlsaOutput *ad, int err)
|
||||
{
|
||||
if (err == -EPIPE) {
|
||||
g_debug("Underrun on ALSA device \"%s\"\n", alsa_device(ad));
|
||||
FormatDebug(alsa_output_domain,
|
||||
"Underrun on ALSA device \"%s\"", alsa_device(ad));
|
||||
} else if (err == -ESTRPIPE) {
|
||||
g_debug("ALSA device \"%s\" was suspended\n", alsa_device(ad));
|
||||
FormatDebug(alsa_output_domain,
|
||||
"ALSA device \"%s\" was suspended",
|
||||
alsa_device(ad));
|
||||
}
|
||||
|
||||
switch (snd_pcm_state(ad->pcm)) {
|
||||
|
Reference in New Issue
Block a user