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