Partition, ...: use libfmt for logging

This commit is contained in:
Max Kellermann
2021-06-24 20:22:48 +02:00
parent 0185d58a2b
commit 6f539cfcd6
44 changed files with 320 additions and 296 deletions

View File

@@ -20,6 +20,8 @@
#include "Control.hxx"
#include "Filtered.hxx"
#include "Client.hxx"
#include "Domain.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "mixer/MixerControl.hxx"
#include "config/Block.hxx"
#include "Log.hxx"
@@ -286,9 +288,9 @@ AudioOutputControl::Open(std::unique_lock<Mutex> &lock,
try {
mixer_open(output->mixer);
} catch (...) {
FormatError(std::current_exception(),
"Failed to open mixer for '%s'",
GetName());
FmtError(output_domain,
"Failed to open mixer for '{}': {}",
GetName(), std::current_exception());
}
}

View File

@@ -20,12 +20,14 @@
#include "Filtered.hxx"
#include "Interface.hxx"
#include "Domain.hxx"
#include "Log.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "mixer/MixerInternal.hxx"
#include "mixer/plugins/SoftwareMixerPlugin.hxx"
#include "filter/plugins/ConvertFilterPlugin.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringBuffer.hxx"
#include "Log.hxx"
bool
FilteredAudioOutput::SupportsEnableDisable() const noexcept
@@ -91,10 +93,9 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
GetLogName()));
}
FormatDebug(output_domain,
"opened %s audio_format=%s",
GetLogName(),
ToString(out_audio_format).c_str());
FmtDebug(output_domain,
"opened {} audio_format={}",
GetLogName(), out_audio_format);
try {
ConfigureConvertFilter();
@@ -109,7 +110,7 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
DSD and fall back to PCM */
LogError(std::current_exception());
FormatError(output_domain, "Retrying without DSD");
LogError(output_domain, "Retrying without DSD");
desired_audio_format.format = SampleFormat::FLOAT;
OpenOutputAndConvert(desired_audio_format);
@@ -127,8 +128,9 @@ FilteredAudioOutput::CloseOutput(bool drain) noexcept
try {
Drain();
} catch (...) {
FormatError(std::current_exception(),
"Failed to drain %s", GetLogName());
FmtError(output_domain,
"Failed to drain {}: {}",
GetLogName(), std::current_exception());
}
} else
Cancel();
@@ -156,7 +158,7 @@ FilteredAudioOutput::Close(bool drain) noexcept
CloseOutput(drain);
CloseSoftwareMixer();
FormatDebug(output_domain, "closed %s", GetLogName());
FmtDebug(output_domain, "closed {}", GetLogName());
}
std::chrono::steady_clock::duration

View File

@@ -22,6 +22,7 @@
#include "Domain.hxx"
#include "OutputAPI.hxx"
#include "Defaults.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "pcm/AudioParser.hxx"
#include "mixer/MixerList.hxx"
#include "mixer/MixerType.hxx"
@@ -68,9 +69,9 @@ audio_output_detect()
if (plugin->test_default_device == nullptr)
continue;
FormatInfo(output_domain,
"Attempting to detect a %s audio device",
plugin->name);
FmtInfo(output_domain,
"Attempting to detect a {} audio device",
plugin->name);
if (ao_plugin_test_default_device(plugin))
return plugin;
}
@@ -188,9 +189,9 @@ FilteredAudioOutput::Configure(const ConfigBlock &block,
/* It's not really fatal - Part of the filter chain
has been set up already and even an empty one will
work (if only with unexpected behaviour) */
FormatError(std::current_exception(),
"Failed to initialize filter chain for '%s'",
name);
FmtError(output_domain,
"Failed to initialize filter chain for '{}': {}",
name, std::current_exception());
}
}
@@ -238,9 +239,9 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
*prepared_filter,
mixer_listener);
} catch (...) {
FormatError(std::current_exception(),
"Failed to initialize hardware mixer for '%s'",
name);
FmtError(output_domain,
"Failed to initialize hardware mixer for '{}': {}",
name, std::current_exception());
}
/* use the hardware mixer for replay gain? */
@@ -250,8 +251,8 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
replay_gain_filter_set_mixer(*prepared_replay_gain_filter,
mixer, 100);
else
FormatError(output_domain,
"No such mixer for output '%s'", name);
FmtError(output_domain,
"No such mixer for output '{}'", name);
} else if (!StringIsEqual(replay_gain_handler, "software") &&
prepared_replay_gain_filter != nullptr) {
throw std::runtime_error("Invalid \"replay_gain_handler\" value");
@@ -289,9 +290,9 @@ audio_output_new(EventLoop &normal_event_loop, EventLoop &rt_event_loop,
plugin = audio_output_detect();
FormatNotice(output_domain,
"Successfully detected a %s audio device",
plugin->name);
FmtNotice(output_domain,
"Successfully detected a {} audio device",
plugin->name);
}
/* use the real-time I/O thread only for the ALSA plugin;

View File

@@ -22,6 +22,8 @@
#include "Filtered.hxx"
#include "Client.hxx"
#include "Domain.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "thread/Util.hxx"
#include "thread/Slack.hxx"
#include "thread/Name.hxx"
@@ -166,10 +168,8 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
}
if (f != in_audio_format || f != output->out_audio_format)
FormatDebug(output_domain, "converting in=%s -> f=%s -> out=%s",
ToString(in_audio_format).c_str(),
ToString(f).c_str(),
ToString(output->out_audio_format).c_str());
FmtDebug(output_domain, "converting in={} -> f={} -> out={}",
in_audio_format, f, output->out_audio_format);
}
inline void
@@ -231,8 +231,9 @@ AudioOutputControl::FillSourceOrClose() noexcept
try {
return source.Fill(mutex);
} catch (...) {
FormatError(std::current_exception(),
"Failed to filter for %s", GetLogName());
FmtError(output_domain,
"Failed to filter for {}: {}",
GetLogName(), std::current_exception());
InternalCloseError(std::current_exception());
return false;
}
@@ -250,9 +251,9 @@ AudioOutputControl::PlayChunk(std::unique_lock<Mutex> &lock) noexcept
caught_interrupted = true;
return false;
} catch (...) {
FormatError(std::current_exception(),
"Failed to send tag to %s",
GetLogName());
FmtError(output_domain,
"Failed to send tag to {}: {}",
GetLogName(), std::current_exception());
}
}
@@ -277,8 +278,9 @@ AudioOutputControl::PlayChunk(std::unique_lock<Mutex> &lock) noexcept
caught_interrupted = true;
return false;
} catch (...) {
FormatError(std::current_exception(),
"Failed to play on %s", GetLogName());
FmtError(output_domain,
"Failed to play on {}",
GetLogName(), std::current_exception());
InternalCloseError(std::current_exception());
return false;
}
@@ -356,9 +358,9 @@ AudioOutputControl::InternalPause(std::unique_lock<Mutex> &lock) noexcept
success = output->IteratePause();
} catch (AudioOutputInterrupted) {
} catch (...) {
FormatError(std::current_exception(),
"Failed to pause %s",
GetLogName());
FmtError(output_domain,
"Failed to pause {}: {}",
GetLogName(), std::current_exception());
}
if (!success) {
@@ -416,8 +418,9 @@ AudioOutputControl::InternalDrain() noexcept
output->Drain();
} catch (...) {
FormatError(std::current_exception(),
"Failed to flush filter on %s", GetLogName());
FmtError(output_domain,
"Failed to flush filter on {}: {}",
GetLogName(), std::current_exception());
InternalCloseError(std::current_exception());
return;
}

View File

@@ -498,9 +498,9 @@ alsa_test_default_device()
int ret = snd_pcm_open(&handle, default_device,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (ret) {
FormatError(alsa_output_domain,
"Error opening default ALSA device: %s",
snd_strerror(-ret));
FmtError(alsa_output_domain,
"Error opening default ALSA device: {}",
snd_strerror(-ret));
return false;
} else
snd_pcm_close(handle);
@@ -548,13 +548,13 @@ AlsaOutput::Setup(AudioFormat &audio_format,
buffer_time, period_time,
audio_format, params);
FormatDebug(alsa_output_domain, "format=%s (%s)",
snd_pcm_format_name(hw_result.format),
snd_pcm_format_description(hw_result.format));
FmtDebug(alsa_output_domain, "format={} ({})",
snd_pcm_format_name(hw_result.format),
snd_pcm_format_description(hw_result.format));
FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u",
(unsigned)hw_result.buffer_size,
(unsigned)hw_result.period_size);
FmtDebug(alsa_output_domain, "buffer_size={} period_size={}",
hw_result.buffer_size,
hw_result.period_size);
AlsaSetupSw(pcm, hw_result.buffer_size - hw_result.period_size,
hw_result.period_size);
@@ -708,9 +708,9 @@ AlsaOutput::Open(AudioFormat &audio_format)
throw FormatRuntimeError("Failed to open ALSA device \"%s\": %s",
GetDevice(), snd_strerror(err));
FormatDebug(alsa_output_domain, "opened %s type=%s",
snd_pcm_name(pcm),
snd_pcm_type_name(snd_pcm_type(pcm)));
FmtDebug(alsa_output_domain, "opened {} type={}",
snd_pcm_name(pcm),
snd_pcm_type_name(snd_pcm_type(pcm)));
PcmExport::Params params;
params.alsa_channel_order = true;
@@ -734,7 +734,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
#ifdef ENABLE_DSD
if (params.dsd_mode == PcmExport::DsdMode::DOP)
FormatDebug(alsa_output_domain, "DoP (DSD over PCM) enabled");
LogDebug(alsa_output_domain, "DoP (DSD over PCM) enabled");
#endif
pcm_export->Open(audio_format.format,
@@ -775,13 +775,13 @@ inline int
AlsaOutput::Recover(int err) noexcept
{
if (err == -EPIPE) {
FormatDebug(alsa_output_domain,
"Underrun on ALSA device \"%s\"",
GetDevice());
FmtDebug(alsa_output_domain,
"Underrun on ALSA device \"{}\"",
GetDevice());
} else if (err == -ESTRPIPE) {
FormatDebug(alsa_output_domain,
"ALSA device \"%s\" was suspended",
GetDevice());
FmtDebug(alsa_output_domain,
"ALSA device \"{}\" was suspended",
GetDevice());
}
switch (snd_pcm_state(pcm)) {
@@ -1158,7 +1158,7 @@ try {
}
if (throttle_silence_log.CheckUpdate(std::chrono::seconds(5)))
FormatWarning(alsa_output_domain, "Decoder is too slow; playing silence to avoid xrun");
LogWarning(alsa_output_domain, "Decoder is too slow; playing silence to avoid xrun");
/* insert some silence if the buffer has not enough
data yet, to avoid ALSA xrun */

View File

@@ -60,8 +60,8 @@ sndio_test_default_device()
{
auto *hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
if (!hdl) {
FormatError(sndio_output_domain,
"Error opening default sndio device");
LogError(sndio_output_domain,
"Error opening default sndio device");
return false;
}

View File

@@ -391,12 +391,12 @@ SlesOutput::Cancel() noexcept
SLresult result = play.SetPlayState(SL_PLAYSTATE_PAUSED);
if (result != SL_RESULT_SUCCESS)
FormatError(sles_domain, "Play.SetPlayState(PAUSED) failed");
LogError(sles_domain, "Play.SetPlayState(PAUSED) failed");
result = queue.Clear();
if (result != SL_RESULT_SUCCESS)
FormatWarning(sles_domain,
"AndroidSimpleBufferQueue.Clear() failed");
LogWarning(sles_domain,
"AndroidSimpleBufferQueue.Clear() failed");
const std::lock_guard<Mutex> protect(mutex);
n_queued = 0;

View File

@@ -422,7 +422,7 @@ inline void
WasapiOutputThread::Work() noexcept
try {
SetThreadName("Wasapi Output Worker");
FormatDebug(wasapi_output_domain, "Working thread started");
LogDebug(wasapi_output_domain, "Working thread started");
COM com;
AtScopeExit(this) {
@@ -448,8 +448,8 @@ try {
Status current_state = status.load();
switch (current_state) {
case Status::FINISH:
FormatDebug(wasapi_output_domain,
"Working thread stopped");
LogDebug(wasapi_output_domain,
"Working thread stopped");
return;
case Status::PAUSE:
@@ -589,8 +589,8 @@ WasapiOutput::DoOpen(AudioFormat &audio_format)
if (device_format.Format.wBitsPerSample == 24) {
params.pack24 = true;
}
FormatDebug(wasapi_output_domain, "Packing data: shift8=%d pack24=%d",
int(params.shift8), int(params.pack24));
FmtDebug(wasapi_output_domain, "Packing data: shift8={} pack24={}",
params.shift8, params.pack24);
pcm_export.emplace();
pcm_export->Open(audio_format.format, audio_format.channels, params);
}
@@ -608,11 +608,11 @@ WasapiOutput::DoOpen(AudioFormat &audio_format)
FAILED(result)) {
throw MakeHResultError(result, "Unable to get device period");
}
FormatDebug(wasapi_output_domain,
"Default device period: %lu ns, Minimum device period: "
"%lu ns",
(unsigned long)ns(hundred_ns(default_device_period)).count(),
(unsigned long)ns(hundred_ns(min_device_period)).count());
FmtDebug(wasapi_output_domain,
"Default device period: {} ns, Minimum device period: "
"{} ns",
ns(hundred_ns(default_device_period)).count(),
ns(hundred_ns(min_device_period)).count());
REFERENCE_TIME buffer_duration;
if (Exclusive()) {
@@ -621,8 +621,8 @@ WasapiOutput::DoOpen(AudioFormat &audio_format)
const REFERENCE_TIME align = hundred_ns(ms(50)).count();
buffer_duration = (align / default_device_period) * default_device_period;
}
FormatDebug(wasapi_output_domain, "Buffer duration: %lu ns",
(unsigned long)ns(hundred_ns(buffer_duration)).count());
FmtDebug(wasapi_output_domain, "Buffer duration: {} ns",
ns(hundred_ns(buffer_duration)).count());
if (Exclusive()) {
if (HRESULT result = client->Initialize(
@@ -639,10 +639,9 @@ WasapiOutput::DoOpen(AudioFormat &audio_format)
std::ceil(double(buffer_size_in_frames *
hundred_ns(s(1)).count()) /
SampleRate());
FormatDebug(
wasapi_output_domain,
"Aligned buffer duration: %lu ns",
(unsigned long)ns(hundred_ns(buffer_duration)).count());
FmtDebug(wasapi_output_domain,
"Aligned buffer duration: {} ns",
ns(hundred_ns(buffer_duration)).count());
client.reset();
client = Activate<IAudioClient>(*device);
result = client->Initialize(
@@ -687,8 +686,7 @@ WasapiOutput::Close() noexcept
try {
thread->CheckException();
} catch (...) {
FormatError(std::current_exception(),
"exception while stopping");
LogError(wasapi_output_domain, "exception while stopping");
}
thread->Finish();
com_worker->Async([&]() {
@@ -1029,8 +1027,8 @@ WasapiOutput::EnumerateDevices(IMMDeviceEnumerator &enumerator)
if (name == nullptr)
continue;
FormatNotice(wasapi_output_domain,
"Device \"%u\" \"%s\"", i, name.c_str());
FmtNotice(wasapi_output_domain,
"Device \"{}\" \"{}\"", i, name);
}
}