archive/File, input/Plugin: return InputStreamPtr
This commit is contained in:
parent
49619fbd77
commit
7bce6329e3
@ -31,7 +31,7 @@ try {
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
InputStreamPtr is(archive.OpenStream(path_utf8, mutex, cond));
|
||||
auto is = archive.OpenStream(path_utf8, mutex, cond);
|
||||
if (!is)
|
||||
return false;
|
||||
|
||||
@ -47,7 +47,7 @@ try {
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
InputStreamPtr is(archive.OpenStream(path_utf8, mutex, cond));
|
||||
auto is = archive.OpenStream(path_utf8, mutex, cond);
|
||||
return is && tag_stream_scan(*is, builder);
|
||||
} catch (const std::exception &e) {
|
||||
return false;
|
||||
|
@ -20,10 +20,11 @@
|
||||
#ifndef MPD_ARCHIVE_FILE_HXX
|
||||
#define MPD_ARCHIVE_FILE_HXX
|
||||
|
||||
#include "input/Ptr.hxx"
|
||||
|
||||
class Mutex;
|
||||
class Cond;
|
||||
class ArchiveVisitor;
|
||||
class InputStream;
|
||||
|
||||
class ArchiveFile {
|
||||
public:
|
||||
@ -41,8 +42,8 @@ public:
|
||||
*
|
||||
* @param path the path within the archive
|
||||
*/
|
||||
virtual InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) = 0;
|
||||
virtual InputStreamPtr OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -53,8 +53,8 @@ public:
|
||||
visitor.VisitArchiveEntry(name.c_str());
|
||||
}
|
||||
|
||||
InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
InputStreamPtr OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
};
|
||||
|
||||
class Bzip2InputStream final : public InputStream {
|
||||
@ -127,11 +127,11 @@ Bzip2InputStream::~Bzip2InputStream()
|
||||
BZ2_bzDecompressEnd(&bzstream);
|
||||
}
|
||||
|
||||
InputStream *
|
||||
InputStreamPtr
|
||||
Bzip2ArchiveFile::OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
return new Bzip2InputStream(istream, path, mutex, cond);
|
||||
return std::make_unique<Bzip2InputStream>(istream, path, mutex, cond);
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
@ -74,8 +74,8 @@ public:
|
||||
|
||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||
|
||||
InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
InputStreamPtr OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
};
|
||||
|
||||
/* archive open && listing routine */
|
||||
@ -156,7 +156,7 @@ public:
|
||||
size_t Read(void *ptr, size_t size) override;
|
||||
};
|
||||
|
||||
InputStream *
|
||||
InputStreamPtr
|
||||
Iso9660ArchiveFile::OpenStream(const char *pathname,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -165,8 +165,8 @@ Iso9660ArchiveFile::OpenStream(const char *pathname,
|
||||
throw FormatRuntimeError("not found in the ISO file: %s",
|
||||
pathname);
|
||||
|
||||
return new Iso9660InputStream(iso, pathname, mutex, cond,
|
||||
statbuf);
|
||||
return std::make_unique<Iso9660InputStream>(iso, pathname, mutex, cond,
|
||||
statbuf);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -59,8 +59,8 @@ public:
|
||||
|
||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||
|
||||
InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
InputStreamPtr OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
};
|
||||
|
||||
/* archive open && listing routine */
|
||||
@ -116,7 +116,7 @@ public:
|
||||
void Seek(offset_type offset) override;
|
||||
};
|
||||
|
||||
InputStream *
|
||||
InputStreamPtr
|
||||
ZzipArchiveFile::OpenStream(const char *pathname,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -125,9 +125,9 @@ ZzipArchiveFile::OpenStream(const char *pathname,
|
||||
throw FormatRuntimeError("not found in the ZIP file: %s",
|
||||
pathname);
|
||||
|
||||
return new ZzipInputStream(dir, pathname,
|
||||
mutex, cond,
|
||||
_file);
|
||||
return std::make_unique<ZzipInputStream>(dir, pathname,
|
||||
mutex, cond,
|
||||
_file);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -20,6 +20,8 @@
|
||||
#ifndef MPD_INPUT_PLUGIN_HXX
|
||||
#define MPD_INPUT_PLUGIN_HXX
|
||||
|
||||
#include "Ptr.hxx"
|
||||
|
||||
struct ConfigBlock;
|
||||
class Mutex;
|
||||
class Cond;
|
||||
@ -48,8 +50,8 @@ struct InputPlugin {
|
||||
/**
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
InputStream *(*open)(const char *uri,
|
||||
Mutex &mutex, Cond &cond);
|
||||
InputStreamPtr (*open)(const char *uri,
|
||||
Mutex &mutex, Cond &cond);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -39,11 +39,9 @@ InputStream::Open(const char *url,
|
||||
}
|
||||
|
||||
input_plugins_for_each_enabled(plugin) {
|
||||
InputStream *is;
|
||||
|
||||
is = plugin->open(url, mutex, cond);
|
||||
auto is = plugin->open(url, mutex, cond);
|
||||
if (is != nullptr)
|
||||
return input_rewind_open(InputStreamPtr(is));
|
||||
return input_rewind_open(std::move(is));
|
||||
}
|
||||
|
||||
throw std::runtime_error("Unrecognized URI");
|
||||
|
@ -110,8 +110,8 @@ public:
|
||||
snd_pcm_close(capture_handle);
|
||||
}
|
||||
|
||||
static InputStream *Create(EventLoop &event_loop, const char *uri,
|
||||
Mutex &mutex, Cond &cond);
|
||||
static InputStreamPtr Create(EventLoop &event_loop, const char *uri,
|
||||
Mutex &mutex, Cond &cond);
|
||||
|
||||
protected:
|
||||
/* virtual methods from AsyncInputStream */
|
||||
@ -146,7 +146,7 @@ private:
|
||||
void DispatchSockets() noexcept override;
|
||||
};
|
||||
|
||||
inline InputStream *
|
||||
inline InputStreamPtr
|
||||
AlsaInputStream::Create(EventLoop &event_loop, const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -167,9 +167,9 @@ AlsaInputStream::Create(EventLoop &event_loop, const char *uri,
|
||||
snd_pcm_t *handle = OpenDevice(device, rate, format, channels);
|
||||
|
||||
int frame_size = snd_pcm_format_width(format) / 8 * channels;
|
||||
return new AlsaInputStream(event_loop,
|
||||
uri, mutex, cond,
|
||||
device, handle, frame_size);
|
||||
return std::make_unique<AlsaInputStream>(event_loop,
|
||||
uri, mutex, cond,
|
||||
device, handle, frame_size);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::duration
|
||||
@ -396,7 +396,7 @@ alsa_input_init(EventLoop &event_loop, const ConfigBlock &)
|
||||
alsa_input_event_loop = &event_loop;
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
alsa_input_open(const char *uri, Mutex &mutex, Cond &cond)
|
||||
{
|
||||
return AlsaInputStream::Create(*alsa_input_event_loop, uri,
|
||||
|
@ -66,10 +66,10 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond)
|
||||
delete file;
|
||||
};
|
||||
|
||||
return InputStreamPtr(file->OpenStream(filename, mutex, cond));
|
||||
return file->OpenStream(filename, mutex, cond);
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_archive_open(gcc_unused const char *filename,
|
||||
gcc_unused Mutex &mutex, gcc_unused Cond &cond)
|
||||
{
|
||||
|
@ -182,7 +182,7 @@ cdio_detect_device(void)
|
||||
return path;
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_cdio_open(const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -250,9 +250,10 @@ input_cdio_open(const char *uri,
|
||||
lsn_to = cdio_get_disc_last_lsn(cdio);
|
||||
}
|
||||
|
||||
return new CdioParanoiaInputStream(uri, mutex, cond,
|
||||
drv, cdio, reverse_endian,
|
||||
lsn_from, lsn_to);
|
||||
return std::make_unique<CdioParanoiaInputStream>(uri, mutex, cond,
|
||||
drv, cdio,
|
||||
reverse_endian,
|
||||
lsn_from, lsn_to);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -88,7 +88,7 @@ struct CurlInputStream final : public AsyncInputStream, CurlResponseHandler {
|
||||
CurlInputStream(const CurlInputStream &) = delete;
|
||||
CurlInputStream &operator=(const CurlInputStream &) = delete;
|
||||
|
||||
static InputStream *Open(const char *url, Mutex &mutex, Cond &cond);
|
||||
static InputStreamPtr Open(const char *url, Mutex &mutex, Cond &cond);
|
||||
|
||||
/**
|
||||
* Create and initialize a new #CurlRequest instance. After
|
||||
@ -435,7 +435,7 @@ CurlInputStream::DoSeek(offset_type new_offset)
|
||||
});
|
||||
}
|
||||
|
||||
inline InputStream *
|
||||
inline InputStreamPtr
|
||||
CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
|
||||
{
|
||||
auto c = std::make_unique<CurlInputStream>((*curl_init)->GetEventLoop(),
|
||||
@ -447,10 +447,10 @@ CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
|
||||
});
|
||||
|
||||
auto icy = c->icy;
|
||||
return new IcyInputStream(std::move(c), std::move(icy));
|
||||
return std::make_unique<IcyInputStream>(std::move(c), std::move(icy));
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_curl_open(const char *url, Mutex &mutex, Cond &cond)
|
||||
{
|
||||
if (strncmp(url, "http://", 7) != 0 &&
|
||||
|
@ -81,7 +81,7 @@ input_ffmpeg_init(EventLoop &, const ConfigBlock &)
|
||||
throw PluginUnavailable("No protocol");
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_ffmpeg_open(const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -98,7 +98,7 @@ input_ffmpeg_open(const char *uri,
|
||||
if (result != 0)
|
||||
throw MakeFfmpegError(result);
|
||||
|
||||
return new FfmpegInputStream(uri, mutex, cond, h);
|
||||
return std::make_unique<FfmpegInputStream>(uri, mutex, cond, h);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -70,12 +70,12 @@ OpenFileInputStream(Path path,
|
||||
POSIX_FADV_SEQUENTIAL);
|
||||
#endif
|
||||
|
||||
return InputStreamPtr(new FileInputStream(path.ToUTF8().c_str(),
|
||||
std::move(reader), info.GetSize(),
|
||||
mutex, cond));
|
||||
return std::make_unique<FileInputStream>(path.ToUTF8().c_str(),
|
||||
std::move(reader), info.GetSize(),
|
||||
mutex, cond);
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_file_open(gcc_unused const char *filename,
|
||||
gcc_unused Mutex &mutex, gcc_unused Cond &cond)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ MmsInputStream::Open()
|
||||
SetMimeType("audio/x-ms-wma");
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_mms_open(const char *url,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -76,7 +76,7 @@ input_mms_open(const char *url,
|
||||
!StringStartsWith(url, "mmsu://"))
|
||||
return nullptr;
|
||||
|
||||
auto m = new MmsInputStream(url, mutex, cond);
|
||||
auto m = std::make_unique<MmsInputStream>(url, mutex, cond);
|
||||
m->Start();
|
||||
return m;
|
||||
}
|
||||
|
@ -216,21 +216,15 @@ input_nfs_finish() noexcept
|
||||
nfs_finish();
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_nfs_open(const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
if (!StringStartsWith(uri, "nfs://"))
|
||||
return nullptr;
|
||||
|
||||
NfsInputStream *is = new NfsInputStream(uri, mutex, cond);
|
||||
try {
|
||||
is->Open();
|
||||
} catch (...) {
|
||||
delete is;
|
||||
throw;
|
||||
}
|
||||
|
||||
auto is = std::make_unique<NfsInputStream>(uri, mutex, cond);
|
||||
is->Open();
|
||||
return is;
|
||||
}
|
||||
|
||||
|
@ -147,5 +147,5 @@ input_rewind_open(InputStreamPtr is)
|
||||
/* seekable resources don't need this plugin */
|
||||
return is;
|
||||
|
||||
return InputStreamPtr(new RewindInputStream(std::move(is)));
|
||||
return std::make_unique<RewindInputStream>(std::move(is));
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ input_smbclient_init(EventLoop &, const ConfigBlock &)
|
||||
// TODO: evaluate ConfigBlock, call smbc_setOption*()
|
||||
}
|
||||
|
||||
static InputStream *
|
||||
static InputStreamPtr
|
||||
input_smbclient_open(const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
@ -119,7 +119,8 @@ input_smbclient_open(const char *uri,
|
||||
throw MakeErrno(e, "smbc_fstat() failed");
|
||||
}
|
||||
|
||||
return new SmbclientInputStream(uri, mutex, cond, ctx, fd, st);
|
||||
return std::make_unique<SmbclientInputStream>(uri, mutex, cond,
|
||||
ctx, fd, st);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
Loading…
Reference in New Issue
Block a user