decoder/plugin: add method protocols()

Similar to commit 4e2a551f30 but for
decoder plugins.  This is tailored for the FFmpeg decoder plugin which
implements some protocols (e.g. RTSP) as demuxer plugin.
This commit is contained in:
Max Kellermann
2020-09-21 13:01:51 +02:00
parent d3c257d97d
commit 85849c9396
6 changed files with 126 additions and 2 deletions

View File

@@ -46,6 +46,42 @@
static constexpr Domain decoder_thread_domain("decoder_thread");
/**
* Decode a URI with the given decoder plugin.
*
* Caller holds DecoderControl::mutex.
*/
static bool
DecoderUriDecode(const DecoderPlugin &plugin,
DecoderBridge &bridge, const char *uri)
{
assert(plugin.uri_decode != nullptr);
assert(bridge.stream_tag == nullptr);
assert(bridge.decoder_tag == nullptr);
assert(uri != nullptr);
assert(bridge.dc.state == DecoderState::START);
FormatDebug(decoder_thread_domain, "probing plugin %s", plugin.name);
if (bridge.dc.command == DecoderCommand::STOP)
throw StopDecoder();
{
const ScopeUnlock unlock(bridge.dc.mutex);
FormatThreadName("decoder:%s", plugin.name);
plugin.UriDecode(bridge, uri);
SetThreadName("decoder");
}
assert(bridge.dc.state == DecoderState::START ||
bridge.dc.state == DecoderState::DECODE);
return bridge.dc.state != DecoderState::START;
}
/**
* Decode a stream with the given decoder plugin.
*
@@ -236,6 +272,24 @@ MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is)
LoadReplayGain(bridge, is);
}
/**
* Try decoding a URI.
*
* DecoderControl::mutex is not be locked by caller.
*/
static bool
TryUriDecode(DecoderBridge &bridge, const char *uri)
{
return decoder_plugins_try([&bridge, uri](const DecoderPlugin &plugin){
if (!plugin.SupportsUri(uri))
return false;
std::unique_lock<Mutex> lock(bridge.dc.mutex);
bridge.Reset();
return DecoderUriDecode(plugin, bridge, uri);
});
}
/**
* Try decoding a stream.
*
@@ -244,6 +298,9 @@ MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is)
static bool
decoder_run_stream(DecoderBridge &bridge, const char *uri)
{
if (TryUriDecode(bridge, uri))
return true;
DecoderControl &dc = bridge.dc;
auto input_stream = bridge.OpenUri(uri);