Merge branch 'v0.23.x'

This commit is contained in:
Max Kellermann
2023-06-02 14:36:02 +02:00
11 changed files with 59 additions and 15 deletions

View File

@@ -8,6 +8,7 @@
#include "lib/xiph/FlacMetadataChain.hxx"
#include "OggCodec.hxx"
#include "input/InputStream.hxx"
#include "input/LocalOpen.hxx"
#include "fs/Path.hxx"
#include "fs/NarrowPath.hxx"
#include "Log.hxx"
@@ -54,13 +55,30 @@ static bool
flac_scan_file(Path path_fs, TagHandler &handler) noexcept
{
FlacMetadataChain chain;
if (!chain.Read(NarrowPath(path_fs))) {
const bool succeed = [&chain, &path_fs]() noexcept {
// read by NarrowPath
if (chain.Read(NarrowPath(path_fs))) {
return true;
}
if (std::is_same_v<Path::value_type, char> ||
chain.GetStatus() != FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE) {
return false;
}
// read by InputStream
Mutex mutex;
auto is = OpenLocalInputStream(path_fs, mutex);
if (is && chain.Read(*is)) {
return true;
}
return false;
}();
if (!succeed) {
FmtDebug(flac_domain,
"Failed to read FLAC tags: {}",
chain.GetStatusString());
return false;
}
chain.Scan(handler);
return true;
}

View File

@@ -546,7 +546,21 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) noexcept
mad_bit_skip(ptr, 16);
lame->peak = MAD_F(mad_bit_read(ptr, 32) << 5); /* peak */
/* The lame peak value is a float multiplied by 2^23 and stored as an
* unsigned integer (it is always positive). MAD's fixed-point format uses
* 28 bits for the fractional part, so shift the 23 bit fraction up before
* converting to a float.
*/
unsigned long peak_int = mad_bit_read(ptr, 32);
#define LAME_PEAK_FRACBITS 23
#if MAD_F_FRACBITS > LAME_PEAK_FRACBITS
peak_int <<= (MAD_F_FRACBITS - LAME_PEAK_FRACBITS);
#elif LAME_PEAK_FRACBITS > MAD_F_FRACBITS
peak_int >>= (LAME_PEAK_FRACBITS - MAD_F_FRACBITS);
#endif
lame->peak = mad_f_todouble(peak_int); /* peak */
FmtDebug(mad_domain, "LAME peak found: {}", lame->peak);
lame->track_gain = 0;

View File

@@ -1007,7 +1007,7 @@ WasapiOutput::EnumerateDevices(IMMDeviceEnumerator &enumerator)
continue;
FmtNotice(wasapi_output_domain,
"Device \"{}\" \"{}\"", i, name);
"Device \"{}\" \"{}\"", i, name.c_str());
}
}

View File

@@ -114,7 +114,7 @@ public:
void set_value(const T &value) {
std::unique_lock<CriticalSection> lock(mutex);
if (!std::holds_alternative<std::monostate>(&result)) {
if (!std::holds_alternative<std::monostate>(result)) {
throw WinFutureError(WinFutureErrc::promise_already_satisfied);
}
result.template emplace<T>(value);

View File

@@ -40,17 +40,17 @@ public:
using R = std::invoke_result_t<std::decay_t<Function>>;
auto promise = std::make_shared<Promise<R>>();
auto future = promise->get_future();
Push([function = std::forward<Function>(function),
promise = std::move(promise)]() mutable {
Push([func = std::forward<Function>(function),
prom = std::move(promise)]() mutable {
try {
if constexpr (std::is_void_v<R>) {
std::invoke(std::forward<Function>(function));
promise->set_value();
std::invoke(std::forward<Function>(func));
prom->set_value();
} else {
promise->set_value(std::invoke(std::forward<Function>(function)));
prom->set_value(std::invoke(std::forward<Function>(func)));
}
} catch (...) {
promise->set_exception(std::current_exception());
prom->set_exception(std::current_exception());
}
});
return future;