InputLegacy: move functions to the input_stream class

This commit is contained in:
Max Kellermann
2013-09-05 00:06:31 +02:00
parent 52ffdb0a55
commit 7d0269d2ce
47 changed files with 461 additions and 608 deletions

View File

@@ -21,7 +21,7 @@
#include "TagSave.hxx"
#include "Song.hxx"
#include "Directory.hxx"
#include "InputLegacy.hxx"
#include "InputStream.hxx"
#include "conf.h"
#include "DecoderAPI.hxx"
#include "DecoderList.hxx"
@@ -86,7 +86,7 @@ decoder_read(gcc_unused struct decoder *decoder,
void *buffer, size_t length)
{
Error error;
return input_stream_lock_read(is, buffer, length, error);
return is->LockRead(buffer, length, error);
}
void
@@ -190,22 +190,22 @@ int main(int argc, char **argv)
if (playlist == NULL) {
/* open the stream and wait until it becomes ready */
is = input_stream_open(uri, mutex, cond, error);
is = input_stream::Open(uri, mutex, cond, error);
if (is == NULL) {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
else
g_printerr("input_stream_open() failed\n");
g_printerr("input_stream::Open() failed\n");
return 2;
}
input_stream_lock_wait_ready(is);
is->LockWaitReady();
/* open the playlist */
playlist = playlist_list_open_stream(is, uri);
if (playlist == NULL) {
input_stream_close(is);
is->Close();
g_printerr("Failed to open playlist\n");
return 2;
}
@@ -237,7 +237,7 @@ int main(int argc, char **argv)
playlist_plugin_close(playlist);
if (is != NULL)
input_stream_close(is);
is->Close();
decoder_plugin_deinit_all();
playlist_list_global_finish();

View File

@@ -59,34 +59,35 @@ dump_input_stream(struct input_stream *is)
{
Error error;
input_stream_lock(is);
is->Lock();
/* wait until the stream becomes ready */
input_stream_wait_ready(is);
is->WaitReady();
if (!input_stream_check(is, error)) {
if (!is->Check(error)) {
g_warning("%s", error.GetMessage());
input_stream_unlock(is);
is->Unlock();
return EXIT_FAILURE;
}
/* read data and tags from the stream */
input_stream_unlock(is);
is->Unlock();
{
TextInputStream tis(is);
dump_text_file(tis);
}
input_stream_lock(is);
if (!input_stream_check(is, error)) {
is->Lock();
if (!is->Check(error)) {
g_warning("%s", error.GetMessage());
input_stream_unlock(is);
is->Unlock();
return EXIT_FAILURE;
}
input_stream_unlock(is);
is->Unlock();
return 0;
}
@@ -131,15 +132,15 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
is = input_stream_open(argv[1], mutex, cond, error);
is = input_stream::Open(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(is);
input_stream_close(is);
is->Close();
} else {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
else
g_printerr("input_stream_open() failed\n");
g_printerr("input_stream::Open() failed\n");
ret = 2;
}

View File

@@ -72,7 +72,7 @@ decoder_read(gcc_unused struct decoder *decoder,
void *buffer, size_t length)
{
Error error;
return input_stream_lock_read(is, buffer, length, error);
return is->LockRead(buffer, length, error);
}
void
@@ -185,9 +185,8 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
struct input_stream *is =
input_stream_open(path, mutex, cond, error);
input_stream *is = input_stream::Open(path, mutex, cond,
error);
if (is == NULL) {
g_printerr("Failed to open %s: %s\n",
path, error.GetMessage());
@@ -196,9 +195,9 @@ int main(int argc, char **argv)
mutex.lock();
input_stream_wait_ready(is);
is->WaitReady();
if (!input_stream_check(is, error)) {
if (!is->Check(error)) {
mutex.unlock();
g_printerr("Failed to read %s: %s\n",
@@ -210,7 +209,7 @@ int main(int argc, char **argv)
success = decoder_plugin_scan_stream(plugin, is,
&print_handler, NULL);
input_stream_close(is);
is->Close();
}
decoder_plugin_deinit_all();

View File

@@ -22,7 +22,7 @@
#include "DecoderList.hxx"
#include "DecoderAPI.hxx"
#include "InputInit.hxx"
#include "InputLegacy.hxx"
#include "InputStream.hxx"
#include "AudioFormat.hxx"
#include "util/Error.hxx"
#include "stdbin.h"
@@ -92,8 +92,7 @@ decoder_read(gcc_unused struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
Error error;
return input_stream_lock_read(is, buffer, length, error);
return is->LockRead(buffer, length, IgnoreError());
}
void
@@ -189,20 +188,20 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
struct input_stream *is =
input_stream_open(decoder.uri, mutex, cond, error);
input_stream *is =
input_stream::Open(decoder.uri, mutex, cond, error);
if (is == NULL) {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
else
g_printerr("input_stream_open() failed\n");
g_printerr("input_stream::Open() failed\n");
return 1;
}
decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
input_stream_close(is);
is->Close();
} else {
g_printerr("Decoder plugin is not usable\n");
return 1;

View File

@@ -22,7 +22,6 @@
#include "stdbin.h"
#include "Tag.hxx"
#include "conf.h"
#include "InputLegacy.hxx"
#include "InputStream.hxx"
#include "InputInit.hxx"
#include "IOThread.hxx"
@@ -55,15 +54,15 @@ dump_input_stream(struct input_stream *is)
size_t num_read;
ssize_t num_written;
input_stream_lock(is);
is->Lock();
/* wait until the stream becomes ready */
input_stream_wait_ready(is);
is->WaitReady();
if (!input_stream_check(is, error)) {
if (!is->Check(error)) {
g_warning("%s", error.GetMessage());
input_stream_unlock(is);
is->Unlock();
return EXIT_FAILURE;
}
@@ -74,16 +73,15 @@ dump_input_stream(struct input_stream *is)
/* read data and tags from the stream */
while (!input_stream_eof(is)) {
Tag *tag = input_stream_tag(is);
while (!is->IsEOF()) {
Tag *tag = is->ReadTag();
if (tag != NULL) {
g_printerr("Received a tag:\n");
tag_save(stderr, *tag);
delete tag;
}
num_read = input_stream_read(is, buffer, sizeof(buffer),
error);
num_read = is->Read(buffer, sizeof(buffer), error);
if (num_read == 0) {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
@@ -96,13 +94,13 @@ dump_input_stream(struct input_stream *is)
break;
}
if (!input_stream_check(is, error)) {
if (!is->Check(error)) {
g_warning("%s", error.GetMessage());
input_stream_unlock(is);
is->Unlock();
return EXIT_FAILURE;
}
input_stream_unlock(is);
is->Unlock();
return 0;
}
@@ -147,15 +145,15 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
is = input_stream_open(argv[1], mutex, cond, error);
is = input_stream::Open(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(is);
input_stream_close(is);
is->Close();
} else {
if (error.IsDefined())
g_warning("%s", error.GetMessage());
else
g_printerr("input_stream_open() failed\n");
g_printerr("input_stream::Open() failed\n");
ret = 2;
}