Add runtime enumeration of supported schemas.

Fix src/ls.cxx to only print unique schemas.
Refactor src/ls.cxx to use src/input/InputPlugin functionality.

Add dynamic enumeration support to curl plugin.
This commit is contained in:
Eugene Gorodinsky
2019-04-17 21:47:55 +03:00
committed by Eugene Gorodinsky
parent 38d0f02e83
commit 4e2a551f30
12 changed files with 137 additions and 32 deletions

View File

@@ -486,4 +486,5 @@ const struct InputPlugin input_plugin_alsa = {
alsa_input_init,
nullptr,
alsa_input_open,
nullptr
};

View File

@@ -357,4 +357,5 @@ const InputPlugin input_plugin_cdio_paranoia = {
input_cdio_init,
nullptr,
input_cdio_open,
nullptr
};

View File

@@ -471,16 +471,25 @@ input_curl_open(const char *url, Mutex &mutex)
return CurlInputStream::Open(url, {}, mutex);
}
static constexpr const char *curl_prefixes[] = {
"http://",
"https://",
nullptr
};
static std::set<std::string>
input_curl_protocols() {
std::set<std::string> protocols;
auto version_info = curl_version_info(CURLVERSION_FIRST);
for (auto proto_ptr = version_info->protocols; *proto_ptr != nullptr; proto_ptr++) {
if (protocol_is_whitelisted(*proto_ptr)) {
std::string schema(*proto_ptr);
schema.append("://");
protocols.emplace(schema);
}
}
return protocols;
}
const struct InputPlugin input_plugin_curl = {
"curl",
curl_prefixes,
nullptr,
input_curl_init,
input_curl_finish,
input_curl_open,
input_curl_protocols
};

View File

@@ -25,8 +25,13 @@
#include "lib/ffmpeg/Init.hxx"
#include "lib/ffmpeg/Error.hxx"
#include "../InputStream.hxx"
#include "../InputPlugin.hxx"
#include "PluginUnavailable.hxx"
#include "util/StringAPI.hxx"
#include "../InputPlugin.hxx"
#include <iostream>
#include <exception>
#include <typeinfo>
#include <stdexcept>
class FfmpegInputStream final : public InputStream {
Ffmpeg::IOContext io;
@@ -71,6 +76,22 @@ input_ffmpeg_init(EventLoop &, const ConfigBlock &)
throw PluginUnavailable("No protocol");
}
static std::set<std::string>
input_ffmpeg_protocols() {
void *opaque = nullptr;
const char* protocol;
std::set<std::string> protocols;
while ((protocol = avio_enum_protocols(&opaque, 0))) {
if (protocol_is_whitelisted(protocol)) {
std::string schema(protocol);
schema.append("://");
protocols.emplace(schema);
}
}
return protocols;
}
static InputStreamPtr
input_ffmpeg_open(const char *uri,
Mutex &mutex)
@@ -111,20 +132,11 @@ FfmpegInputStream::Seek(offset_type new_offset)
offset = result;
}
static constexpr const char *ffmpeg_prefixes[] = {
"gopher://",
"rtp://",
"rtsp://",
"rtmp://",
"rtmpt://",
"rtmps://",
nullptr
};
const InputPlugin input_plugin_ffmpeg = {
"ffmpeg",
ffmpeg_prefixes,
nullptr,
input_ffmpeg_init,
nullptr,
input_ffmpeg_open,
input_ffmpeg_protocols
};

View File

@@ -110,4 +110,5 @@ const InputPlugin input_plugin_mms = {
nullptr,
nullptr,
input_mms_open,
nullptr
};

View File

@@ -232,4 +232,5 @@ const InputPlugin input_plugin_nfs = {
input_nfs_init,
input_nfs_finish,
input_nfs_open,
nullptr
};

View File

@@ -219,5 +219,6 @@ const InputPlugin qobuz_input_plugin = {
InitQobuzInput,
FinishQobuzInput,
OpenQobuzInput,
nullptr,
ScanQobuzTags,
};

View File

@@ -162,4 +162,5 @@ const InputPlugin input_plugin_smbclient = {
input_smbclient_init,
nullptr,
input_smbclient_open,
nullptr
};

View File

@@ -249,5 +249,6 @@ const InputPlugin tidal_input_plugin = {
InitTidalInput,
FinishTidalInput,
OpenTidalInput,
nullptr,
ScanTidalTags,
};