decoder/wavpack: add WavpackOpen() wrappers which throw exception
This commit is contained in:
parent
3759f29852
commit
f40816e063
@ -24,11 +24,10 @@
|
|||||||
#include "CheckAudioFormat.hxx"
|
#include "CheckAudioFormat.hxx"
|
||||||
#include "tag/TagHandler.hxx"
|
#include "tag/TagHandler.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "util/Domain.hxx"
|
|
||||||
#include "util/Macros.hxx"
|
#include "util/Macros.hxx"
|
||||||
#include "util/Alloc.hxx"
|
#include "util/Alloc.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "Log.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
|
||||||
#include <wavpack/wavpack.h>
|
#include <wavpack/wavpack.h>
|
||||||
|
|
||||||
@ -39,8 +38,6 @@
|
|||||||
|
|
||||||
#define ERRORLEN 80
|
#define ERRORLEN 80
|
||||||
|
|
||||||
static constexpr Domain wavpack_domain("wavpack");
|
|
||||||
|
|
||||||
#ifdef OPEN_DSD_AS_PCM
|
#ifdef OPEN_DSD_AS_PCM
|
||||||
/* libWavPack supports DSD since version 5 */
|
/* libWavPack supports DSD since version 5 */
|
||||||
#ifdef ENABLE_DSD
|
#ifdef ENABLE_DSD
|
||||||
@ -53,6 +50,33 @@ static constexpr int OPEN_DSD_FLAG = OPEN_DSD_AS_PCM;
|
|||||||
static constexpr int OPEN_DSD_FLAG = 0;
|
static constexpr int OPEN_DSD_FLAG = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static WavpackContext *
|
||||||
|
WavpackOpenInput(Path path, int flags, int norm_offset)
|
||||||
|
{
|
||||||
|
char error[ERRORLEN];
|
||||||
|
auto *wpc = WavpackOpenFileInput(path.c_str(), error,
|
||||||
|
flags, norm_offset);
|
||||||
|
if (wpc == nullptr)
|
||||||
|
throw FormatRuntimeError("failed to open WavPack file \"%s\": %s",
|
||||||
|
path.c_str(), error);
|
||||||
|
|
||||||
|
return wpc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WavpackContext *
|
||||||
|
WavpackOpenInput(WavpackStreamReader *reader, void *wv_id, void *wvc_id,
|
||||||
|
int flags, int norm_offset)
|
||||||
|
{
|
||||||
|
char error[ERRORLEN];
|
||||||
|
auto *wpc = WavpackOpenFileInputEx(reader, wv_id, wvc_id, error,
|
||||||
|
flags, norm_offset);
|
||||||
|
if (wpc == nullptr)
|
||||||
|
throw FormatRuntimeError("failed to open WavPack stream: %s",
|
||||||
|
error);
|
||||||
|
|
||||||
|
return wpc;
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static SignedSongTime
|
static SignedSongTime
|
||||||
GetDuration(WavpackContext *wpc)
|
GetDuration(WavpackContext *wpc)
|
||||||
@ -428,17 +452,8 @@ wavpack_streamdecode(DecoderClient &client, InputStream &is)
|
|||||||
|
|
||||||
WavpackInput isp(client, is);
|
WavpackInput isp(client, is);
|
||||||
|
|
||||||
char error[ERRORLEN];
|
auto *wpc = WavpackOpenInput(&mpd_is_reader, &isp, wvc.get(),
|
||||||
WavpackContext *wpc =
|
open_flags, 0);
|
||||||
WavpackOpenFileInputEx(&mpd_is_reader, &isp, wvc.get(),
|
|
||||||
error, open_flags, 0);
|
|
||||||
|
|
||||||
if (wpc == nullptr) {
|
|
||||||
FormatError(wavpack_domain,
|
|
||||||
"failed to open WavPack stream: %s", error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtScopeExit(wpc) {
|
AtScopeExit(wpc) {
|
||||||
WavpackCloseFile(wpc);
|
WavpackCloseFile(wpc);
|
||||||
};
|
};
|
||||||
@ -452,17 +467,9 @@ wavpack_streamdecode(DecoderClient &client, InputStream &is)
|
|||||||
static void
|
static void
|
||||||
wavpack_filedecode(DecoderClient &client, Path path_fs)
|
wavpack_filedecode(DecoderClient &client, Path path_fs)
|
||||||
{
|
{
|
||||||
char error[ERRORLEN];
|
auto *wpc = WavpackOpenInput(path_fs,
|
||||||
WavpackContext *wpc = WavpackOpenFileInput(path_fs.c_str(), error,
|
OPEN_DSD_FLAG | OPEN_NORMALIZE | OPEN_WVC,
|
||||||
OPEN_DSD_FLAG | OPEN_NORMALIZE | OPEN_WVC,
|
0);
|
||||||
0);
|
|
||||||
if (wpc == nullptr) {
|
|
||||||
FormatWarning(wavpack_domain,
|
|
||||||
"failed to open WavPack file \"%s\": %s",
|
|
||||||
path_fs.c_str(), error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtScopeExit(wpc) {
|
AtScopeExit(wpc) {
|
||||||
WavpackCloseFile(wpc);
|
WavpackCloseFile(wpc);
|
||||||
};
|
};
|
||||||
@ -477,16 +484,7 @@ static bool
|
|||||||
wavpack_scan_file(Path path_fs,
|
wavpack_scan_file(Path path_fs,
|
||||||
const TagHandler &handler, void *handler_ctx)
|
const TagHandler &handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
char error[ERRORLEN];
|
auto *wpc = WavpackOpenInput(path_fs, OPEN_DSD_FLAG, 0);
|
||||||
WavpackContext *wpc = WavpackOpenFileInput(path_fs.c_str(), error,
|
|
||||||
OPEN_DSD_FLAG, 0);
|
|
||||||
if (wpc == nullptr) {
|
|
||||||
FormatError(wavpack_domain,
|
|
||||||
"failed to open WavPack file \"%s\": %s",
|
|
||||||
path_fs.c_str(), error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtScopeExit(wpc) {
|
AtScopeExit(wpc) {
|
||||||
WavpackCloseFile(wpc);
|
WavpackCloseFile(wpc);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user