Commit ff1acefb authored by Max Kellermann's avatar Max Kellermann

decoder: removed plugin method try_decode()

Instead of having a seprate try_decode() method, let the stream_decode() and file_decode() methods decide whether they are able to decode the song.
parent 10eea9d9
...@@ -193,12 +193,6 @@ ffmpeg_helper(struct input_stream *input, ...@@ -193,12 +193,6 @@ ffmpeg_helper(struct input_stream *input,
return ret; return ret;
} }
static bool
ffmpeg_try_decode(struct input_stream *input)
{
return ffmpeg_helper(input, NULL, NULL);
}
static enum decoder_command static enum decoder_command
ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
const AVPacket *packet, const AVPacket *packet,
...@@ -370,7 +364,6 @@ static const char *const ffmpeg_mime_types[] = { ...@@ -370,7 +364,6 @@ static const char *const ffmpeg_mime_types[] = {
const struct decoder_plugin ffmpeg_plugin = { const struct decoder_plugin ffmpeg_plugin = {
.name = "ffmpeg", .name = "ffmpeg",
.init = ffmpeg_init, .init = ffmpeg_init,
.try_decode = ffmpeg_try_decode,
.stream_decode = ffmpeg_decode, .stream_decode = ffmpeg_decode,
.tag_dup = ffmpeg_tag, .tag_dup = ffmpeg_tag,
.suffixes = ffmpeg_suffixes, .suffixes = ffmpeg_suffixes,
......
...@@ -434,13 +434,14 @@ out: ...@@ -434,13 +434,14 @@ out:
static bool static bool
oggflac_decode(struct decoder *decoder, struct input_stream *inStream) oggflac_decode(struct decoder *decoder, struct input_stream *inStream)
{ {
return flac_decode_internal(decoder, inStream, true); if (ogg_stream_type_detect(inStream) != FLAC)
} return false;
static bool /* rewind the stream, because ogg_stream_type_detect() has
oggflac_try_decode(struct input_stream *inStream) moved it */
{ input_stream_seek(inStream, 0, SEEK_SET);
return ogg_stream_type_detect(inStream) == FLAC;
return flac_decode_internal(decoder, inStream, true);
} }
static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL };
...@@ -457,7 +458,6 @@ const struct decoder_plugin oggflacPlugin = { ...@@ -457,7 +458,6 @@ const struct decoder_plugin oggflacPlugin = {
.name = "oggflac", .name = "oggflac",
.init = oggflac_init, .init = oggflac_init,
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
.try_decode = oggflac_try_decode,
.stream_decode = oggflac_decode, .stream_decode = oggflac_decode,
.tag_dup = oggflac_tag_dup, .tag_dup = oggflac_tag_dup,
.suffixes = oggflac_suffixes, .suffixes = oggflac_suffixes,
......
...@@ -214,6 +214,13 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -214,6 +214,13 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
const char *errorStr; const char *errorStr;
bool initialized = false; bool initialized = false;
if (ogg_stream_type_detect(inStream) != VORBIS)
return false;
/* rewind the stream, because ogg_stream_type_detect() has
moved it */
input_stream_seek(inStream, 0, SEEK_SET);
data.inStream = inStream; data.inStream = inStream;
data.decoder = decoder; data.decoder = decoder;
...@@ -351,12 +358,6 @@ static struct tag *oggvorbis_TagDup(const char *file) ...@@ -351,12 +358,6 @@ static struct tag *oggvorbis_TagDup(const char *file)
return ret; return ret;
} }
static bool
oggvorbis_try_decode(struct input_stream *inStream)
{
return ogg_stream_type_detect(inStream) == VORBIS;
}
static const char *const oggvorbis_Suffixes[] = { "ogg","oga", NULL }; static const char *const oggvorbis_Suffixes[] = { "ogg","oga", NULL };
static const char *const oggvorbis_MimeTypes[] = { static const char *const oggvorbis_MimeTypes[] = {
"application/ogg", "application/ogg",
...@@ -367,7 +368,6 @@ static const char *const oggvorbis_MimeTypes[] = { ...@@ -367,7 +368,6 @@ static const char *const oggvorbis_MimeTypes[] = {
const struct decoder_plugin oggvorbisPlugin = { const struct decoder_plugin oggvorbisPlugin = {
.name = "oggvorbis", .name = "oggvorbis",
.try_decode = oggvorbis_try_decode,
.stream_decode = oggvorbis_decode, .stream_decode = oggvorbis_decode,
.tag_dup = oggvorbis_TagDup, .tag_dup = oggvorbis_TagDup,
.suffixes = oggvorbis_Suffixes, .suffixes = oggvorbis_Suffixes,
......
...@@ -61,12 +61,6 @@ struct decoder_plugin { ...@@ -61,12 +61,6 @@ struct decoder_plugin {
void (*finish)(void); void (*finish)(void);
/** /**
* returns true if the input stream is decodable by the
* decoder plugin, false if not
*/
bool (*try_decode)(struct input_stream *);
/**
* this will be used to decode InputStreams, and is * this will be used to decode InputStreams, and is
* recommended for files and networked (HTTP) connections. * recommended for files and networked (HTTP) connections.
* *
......
...@@ -29,23 +29,6 @@ ...@@ -29,23 +29,6 @@
#include "ls.h" #include "ls.h"
static bool static bool
decoder_try_decode(const struct decoder_plugin *plugin,
struct input_stream *input_stream)
{
bool ret;
if (plugin->try_decode == NULL)
return true;
ret = plugin->try_decode(input_stream);
/* rewind the stream, so the next reader gets a fresh start */
input_stream_seek(input_stream, 0, SEEK_SET);
return ret;
}
static bool
decoder_stream_decode(const struct decoder_plugin *plugin, decoder_stream_decode(const struct decoder_plugin *plugin,
struct decoder *decoder, struct decoder *decoder,
struct input_stream *input_stream) struct input_stream *input_stream)
...@@ -172,8 +155,6 @@ static void decoder_run(void) ...@@ -172,8 +155,6 @@ static void decoder_run(void)
while ((plugin = decoder_plugin_from_mime_type(input_stream.mime, next++))) { while ((plugin = decoder_plugin_from_mime_type(input_stream.mime, next++))) {
if (plugin->stream_decode == NULL) if (plugin->stream_decode == NULL)
continue; continue;
if (!decoder_try_decode(plugin, &input_stream))
continue;
ret = decoder_stream_decode(plugin, &decoder, ret = decoder_stream_decode(plugin, &decoder,
&input_stream); &input_stream);
if (ret) if (ret)
...@@ -189,8 +170,6 @@ static void decoder_run(void) ...@@ -189,8 +170,6 @@ static void decoder_run(void)
while ((plugin = decoder_plugin_from_suffix(s, next++))) { while ((plugin = decoder_plugin_from_suffix(s, next++))) {
if (plugin->stream_decode == NULL) if (plugin->stream_decode == NULL)
continue; continue;
if (!decoder_try_decode(plugin, &input_stream))
continue;
ret = decoder_stream_decode(plugin, &decoder, ret = decoder_stream_decode(plugin, &decoder,
&input_stream); &input_stream);
if (ret) if (ret)
...@@ -215,9 +194,6 @@ static void decoder_run(void) ...@@ -215,9 +194,6 @@ static void decoder_run(void)
unsigned int next = 0; unsigned int next = 0;
const char *s = getSuffix(uri); const char *s = getSuffix(uri);
while ((plugin = decoder_plugin_from_suffix(s, next++))) { while ((plugin = decoder_plugin_from_suffix(s, next++))) {
if (!decoder_try_decode(plugin, &input_stream))
continue;
if (plugin->file_decode != NULL) { if (plugin->file_decode != NULL) {
input_stream_close(&input_stream); input_stream_close(&input_stream);
close_instream = false; close_instream = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment