lib/icuConverter, ...: use FmtBuffer() and FmtErrno()
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "lib/alsa/NonBlock.hxx"
|
#include "lib/alsa/NonBlock.hxx"
|
||||||
#include "lib/alsa/Error.hxx"
|
#include "lib/alsa/Error.hxx"
|
||||||
#include "lib/alsa/Format.hxx"
|
#include "lib/alsa/Format.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "../AsyncInputStream.hxx"
|
#include "../AsyncInputStream.hxx"
|
||||||
#include "event/Call.hxx"
|
#include "event/Call.hxx"
|
||||||
#include "config/Block.hxx"
|
#include "config/Block.hxx"
|
||||||
@@ -420,8 +421,8 @@ AlsaInputStream::OpenDevice(const SourceSpec &spec)
|
|||||||
SND_PCM_STREAM_CAPTURE,
|
SND_PCM_STREAM_CAPTURE,
|
||||||
SND_PCM_NONBLOCK | global_config.mode)) < 0)
|
SND_PCM_NONBLOCK | global_config.mode)) < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("Failed to open device {}",
|
FmtBuffer<256>("Failed to open device {}",
|
||||||
spec.GetDeviceName()).c_str());
|
spec.GetDeviceName()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigureCapture(spec.GetAudioFormat());
|
ConfigureCapture(spec.GetAudioFormat());
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "Error.hxx"
|
#include "Error.hxx"
|
||||||
#include "Format.hxx"
|
#include "Format.hxx"
|
||||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "util/ByteOrder.hxx"
|
#include "util/ByteOrder.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
@@ -198,16 +199,16 @@ SetupHw(snd_pcm_t *pcm,
|
|||||||
audio_format.format, params);
|
audio_format.format, params);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("Failed to configure format {}",
|
FmtBuffer<256>("Failed to configure format {}",
|
||||||
audio_format.format).c_str());
|
audio_format.format));
|
||||||
|
|
||||||
unsigned int channels = audio_format.channels;
|
unsigned int channels = audio_format.channels;
|
||||||
err = snd_pcm_hw_params_set_channels_near(pcm, hwparams,
|
err = snd_pcm_hw_params_set_channels_near(pcm, hwparams,
|
||||||
&channels);
|
&channels);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("Failed to configure {} channels",
|
FmtBuffer<256>("Failed to configure {} channels",
|
||||||
audio_format.channels).c_str());
|
audio_format.channels));
|
||||||
|
|
||||||
audio_format.channels = (int8_t)channels;
|
audio_format.channels = (int8_t)channels;
|
||||||
|
|
||||||
@@ -219,8 +220,8 @@ SetupHw(snd_pcm_t *pcm,
|
|||||||
&output_sample_rate, nullptr);
|
&output_sample_rate, nullptr);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("Failed to configure sample rate {} Hz",
|
FmtBuffer<256>("Failed to configure sample rate {} Hz",
|
||||||
requested_sample_rate).c_str());
|
requested_sample_rate));
|
||||||
|
|
||||||
if (output_sample_rate == 0)
|
if (output_sample_rate == 0)
|
||||||
throw FormatRuntimeError("Failed to configure sample rate %u Hz",
|
throw FormatRuntimeError("Failed to configure sample rate %u Hz",
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Converter.hxx"
|
#include "Converter.hxx"
|
||||||
#include "util/AllocatedString.hxx"
|
#include "util/AllocatedString.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
#include "util/AllocatedArray.hxx"
|
#include "util/AllocatedArray.hxx"
|
||||||
#include <unicode/ucnv.h>
|
#include <unicode/ucnv.h>
|
||||||
#elif defined(HAVE_ICONV)
|
#elif defined(HAVE_ICONV)
|
||||||
#include "system/Error.hxx"
|
#include "lib/fmt/SystemError.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ICU
|
#ifdef HAVE_ICU
|
||||||
@@ -54,8 +55,8 @@ IcuConverter::Create(const char *charset)
|
|||||||
UErrorCode code = U_ZERO_ERROR;
|
UErrorCode code = U_ZERO_ERROR;
|
||||||
UConverter *converter = ucnv_open(charset, &code);
|
UConverter *converter = ucnv_open(charset, &code);
|
||||||
if (converter == nullptr)
|
if (converter == nullptr)
|
||||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to initialize charset '{}': {}"),
|
throw std::runtime_error(FmtBuffer<256>(FMT_STRING("Failed to initialize charset '{}': {}"),
|
||||||
charset, u_errorName(code)));
|
charset, u_errorName(code)));
|
||||||
|
|
||||||
return std::unique_ptr<IcuConverter>(new IcuConverter(converter));
|
return std::unique_ptr<IcuConverter>(new IcuConverter(converter));
|
||||||
#elif defined(HAVE_ICONV)
|
#elif defined(HAVE_ICONV)
|
||||||
@@ -67,8 +68,8 @@ IcuConverter::Create(const char *charset)
|
|||||||
iconv_close(to);
|
iconv_close(to);
|
||||||
if (from != (iconv_t)-1)
|
if (from != (iconv_t)-1)
|
||||||
iconv_close(from);
|
iconv_close(from);
|
||||||
throw MakeErrno(e, fmt::format(FMT_STRING("Failed to initialize charset '{}'"),
|
throw FmtErrno(e, FMT_STRING("Failed to initialize charset '{}'"),
|
||||||
charset).c_str());
|
charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::unique_ptr<IcuConverter>(new IcuConverter(to, from));
|
return std::unique_ptr<IcuConverter>(new IcuConverter(to, from));
|
||||||
@@ -119,8 +120,8 @@ IcuConverter::ToUTF8(std::string_view s) const
|
|||||||
&source, source + s.size(),
|
&source, source + s.size(),
|
||||||
nullptr, true, &code);
|
nullptr, true, &code);
|
||||||
if (code != U_ZERO_ERROR)
|
if (code != U_ZERO_ERROR)
|
||||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to convert to Unicode: {}"),
|
throw std::runtime_error(FmtBuffer<256>(FMT_STRING("Failed to convert to Unicode: {}"),
|
||||||
u_errorName(code)));
|
u_errorName(code)));
|
||||||
|
|
||||||
const size_t target_length = target - buffer;
|
const size_t target_length = target - buffer;
|
||||||
return UCharToUTF8({buffer, target_length});
|
return UCharToUTF8({buffer, target_length});
|
||||||
@@ -149,8 +150,8 @@ IcuConverter::FromUTF8(std::string_view s) const
|
|||||||
nullptr, true, &code);
|
nullptr, true, &code);
|
||||||
|
|
||||||
if (code != U_ZERO_ERROR)
|
if (code != U_ZERO_ERROR)
|
||||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to convert from Unicode: {}"),
|
throw std::runtime_error(FmtBuffer<256>(FMT_STRING("Failed to convert from Unicode: {}"),
|
||||||
u_errorName(code)));
|
u_errorName(code)));
|
||||||
|
|
||||||
return {{buffer, size_t(target - buffer)}};
|
return {{buffer, size_t(target - buffer)}};
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "plugins/NullMixerPlugin.hxx"
|
#include "plugins/NullMixerPlugin.hxx"
|
||||||
#include "plugins/SoftwareMixerPlugin.hxx"
|
#include "plugins/SoftwareMixerPlugin.hxx"
|
||||||
#include "lib/fmt/ExceptionFormatter.hxx"
|
#include "lib/fmt/ExceptionFormatter.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "pcm/Volume.hxx"
|
#include "pcm/Volume.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@@ -105,8 +106,8 @@ output_mixer_set_volume(AudioOutputControl &ao, unsigned volume)
|
|||||||
FmtError(mixer_domain,
|
FmtError(mixer_domain,
|
||||||
"Failed to set mixer for '{}': {}",
|
"Failed to set mixer for '{}': {}",
|
||||||
ao.GetName(), std::current_exception());
|
ao.GetName(), std::current_exception());
|
||||||
std::throw_with_nested(std::runtime_error(fmt::format("Failed to set mixer for '{}'",
|
std::throw_with_nested(std::runtime_error(FmtBuffer<256>("Failed to set mixer for '{}'",
|
||||||
ao.GetName())));
|
ao.GetName())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "AlsaMixerPlugin.hxx"
|
#include "AlsaMixerPlugin.hxx"
|
||||||
#include "lib/alsa/NonBlock.hxx"
|
#include "lib/alsa/NonBlock.hxx"
|
||||||
#include "lib/alsa/Error.hxx"
|
#include "lib/alsa/Error.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "mixer/Mixer.hxx"
|
#include "mixer/Mixer.hxx"
|
||||||
#include "mixer/Listener.hxx"
|
#include "mixer/Listener.hxx"
|
||||||
#include "output/OutputAPI.hxx"
|
#include "output/OutputAPI.hxx"
|
||||||
@@ -267,8 +268,8 @@ AlsaMixer::Setup()
|
|||||||
|
|
||||||
if ((err = snd_mixer_attach(handle, device)) < 0)
|
if ((err = snd_mixer_attach(handle, device)) < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("failed to attach to {}",
|
FmtBuffer<256>("failed to attach to {}",
|
||||||
device).c_str());
|
device));
|
||||||
|
|
||||||
if ((err = snd_mixer_selem_register(handle, nullptr, nullptr)) < 0)
|
if ((err = snd_mixer_selem_register(handle, nullptr, nullptr)) < 0)
|
||||||
throw Alsa::MakeError(err, "snd_mixer_selem_register() failed");
|
throw Alsa::MakeError(err, "snd_mixer_selem_register() failed");
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "lib/alsa/NonBlock.hxx"
|
#include "lib/alsa/NonBlock.hxx"
|
||||||
#include "lib/alsa/PeriodBuffer.hxx"
|
#include "lib/alsa/PeriodBuffer.hxx"
|
||||||
#include "lib/alsa/Version.hxx"
|
#include "lib/alsa/Version.hxx"
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
#include "../OutputAPI.hxx"
|
#include "../OutputAPI.hxx"
|
||||||
#include "../Error.hxx"
|
#include "../Error.hxx"
|
||||||
#include "mixer/plugins/AlsaMixerPlugin.hxx"
|
#include "mixer/plugins/AlsaMixerPlugin.hxx"
|
||||||
@@ -807,8 +808,8 @@ AlsaOutput::Open(AudioFormat &audio_format)
|
|||||||
SND_PCM_STREAM_PLAYBACK, mode);
|
SND_PCM_STREAM_PLAYBACK, mode);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
throw Alsa::MakeError(err,
|
throw Alsa::MakeError(err,
|
||||||
fmt::format("Failed to open ALSA device \"{}\"",
|
FmtBuffer<256>("Failed to open ALSA device \"{}\"",
|
||||||
GetDevice()).c_str());
|
GetDevice()));
|
||||||
|
|
||||||
const char *pcm_name = snd_pcm_name(pcm);
|
const char *pcm_name = snd_pcm_name(pcm);
|
||||||
if (pcm_name == nullptr)
|
if (pcm_name == nullptr)
|
||||||
|
Reference in New Issue
Block a user