InputStream: add constructor/destructor
Eliminate input_stream_init() and input_stream_deinit().
This commit is contained in:
parent
e565cd4404
commit
dcf55c7e32
@ -21,37 +21,6 @@
|
|||||||
#include "InputInternal.hxx"
|
#include "InputInternal.hxx"
|
||||||
#include "InputStream.hxx"
|
#include "InputStream.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
void
|
|
||||||
input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
|
|
||||||
const char *uri, Mutex &mutex, Cond &cond)
|
|
||||||
{
|
|
||||||
assert(is != NULL);
|
|
||||||
assert(plugin != NULL);
|
|
||||||
assert(uri != NULL);
|
|
||||||
|
|
||||||
is->plugin = plugin;
|
|
||||||
is->uri = g_strdup(uri);
|
|
||||||
is->mutex = &mutex;
|
|
||||||
is->cond = &cond;
|
|
||||||
is->ready = false;
|
|
||||||
is->seekable = false;
|
|
||||||
is->size = -1;
|
|
||||||
is->offset = 0;
|
|
||||||
is->mime = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
input_stream_deinit(struct input_stream *is)
|
|
||||||
{
|
|
||||||
assert(is != NULL);
|
|
||||||
assert(is->plugin != NULL);
|
|
||||||
|
|
||||||
g_free(is->uri);
|
|
||||||
g_free(is->mime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
input_stream_signal_client(struct input_stream *is)
|
input_stream_signal_client(struct input_stream *is)
|
||||||
{
|
{
|
||||||
|
@ -21,18 +21,8 @@
|
|||||||
#define MPD_INPUT_INTERNAL_HXX
|
#define MPD_INPUT_INTERNAL_HXX
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "thread/Mutex.hxx"
|
|
||||||
#include "thread/Cond.hxx"
|
|
||||||
|
|
||||||
struct input_stream;
|
struct input_stream;
|
||||||
struct input_plugin;
|
|
||||||
|
|
||||||
void
|
|
||||||
input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
|
|
||||||
const char *uri, Mutex &mutex, Cond &cond);
|
|
||||||
|
|
||||||
void
|
|
||||||
input_stream_deinit(struct input_stream *is);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
input_stream_signal_client(struct input_stream *is);
|
input_stream_signal_client(struct input_stream *is);
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
struct input_stream {
|
struct input_stream {
|
||||||
/**
|
/**
|
||||||
* the plugin which implements this input stream
|
* the plugin which implements this input stream
|
||||||
@ -85,6 +87,21 @@ struct input_stream {
|
|||||||
* the MIME content type of the resource, or NULL if unknown
|
* the MIME content type of the resource, or NULL if unknown
|
||||||
*/
|
*/
|
||||||
char *mime;
|
char *mime;
|
||||||
|
|
||||||
|
input_stream(const input_plugin &_plugin,
|
||||||
|
const char *_uri, Mutex &_mutex, Cond &_cond)
|
||||||
|
:plugin(&_plugin), uri(g_strdup(_uri)),
|
||||||
|
mutex(&_mutex), cond(&_cond),
|
||||||
|
ready(false), seekable(false),
|
||||||
|
size(-1), offset(0),
|
||||||
|
mime(nullptr) {
|
||||||
|
assert(_uri != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
~input_stream() {
|
||||||
|
g_free(uri);
|
||||||
|
g_free(mime);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
gcc_nonnull(1)
|
gcc_nonnull(1)
|
||||||
|
@ -184,16 +184,15 @@ bz2_close(struct archive_file *file)
|
|||||||
|
|
||||||
Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri,
|
Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri,
|
||||||
Mutex &mutex, Cond &cond)
|
Mutex &mutex, Cond &cond)
|
||||||
:archive(&_context), eof(false)
|
:base(bz2_inputplugin, uri, mutex, cond),
|
||||||
|
archive(&_context), eof(false)
|
||||||
{
|
{
|
||||||
input_stream_init(&base, &bz2_inputplugin, uri, mutex, cond);
|
|
||||||
refcount_inc(&archive->ref);
|
refcount_inc(&archive->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bzip2InputStream::~Bzip2InputStream()
|
Bzip2InputStream::~Bzip2InputStream()
|
||||||
{
|
{
|
||||||
bz2_close(&archive->base);
|
bz2_close(&archive->base);
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct input_stream *
|
static struct input_stream *
|
||||||
|
@ -178,10 +178,9 @@ struct Iso9660InputStream {
|
|||||||
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri,
|
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri,
|
||||||
Mutex &mutex, Cond &cond,
|
Mutex &mutex, Cond &cond,
|
||||||
iso9660_stat_t *_statbuf)
|
iso9660_stat_t *_statbuf)
|
||||||
:archive(&_archive), statbuf(_statbuf),
|
:base(iso9660_input_plugin, uri, mutex, cond),
|
||||||
|
archive(&_archive), statbuf(_statbuf),
|
||||||
max_blocks(CEILING(statbuf->size, ISO_BLOCKSIZE)) {
|
max_blocks(CEILING(statbuf->size, ISO_BLOCKSIZE)) {
|
||||||
input_stream_init(&base, &iso9660_input_plugin, uri,
|
|
||||||
mutex, cond);
|
|
||||||
|
|
||||||
base.ready = true;
|
base.ready = true;
|
||||||
base.size = statbuf->size;
|
base.size = statbuf->size;
|
||||||
@ -192,7 +191,6 @@ struct Iso9660InputStream {
|
|||||||
~Iso9660InputStream() {
|
~Iso9660InputStream() {
|
||||||
free(statbuf);
|
free(statbuf);
|
||||||
archive->Unref();
|
archive->Unref();
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,10 +142,8 @@ struct ZzipInputStream {
|
|||||||
ZzipInputStream(ZzipArchiveFile &_archive, const char *uri,
|
ZzipInputStream(ZzipArchiveFile &_archive, const char *uri,
|
||||||
Mutex &mutex, Cond &cond,
|
Mutex &mutex, Cond &cond,
|
||||||
ZZIP_FILE *_file)
|
ZZIP_FILE *_file)
|
||||||
:archive(&_archive), file(_file) {
|
:base(zzip_input_plugin, uri, mutex, cond),
|
||||||
input_stream_init(&base, &zzip_input_plugin, uri,
|
archive(&_archive), file(_file) {
|
||||||
mutex, cond);
|
|
||||||
|
|
||||||
base.ready = true;
|
base.ready = true;
|
||||||
//we are seekable (but its not recommendent to do so)
|
//we are seekable (but its not recommendent to do so)
|
||||||
base.seekable = true;
|
base.seekable = true;
|
||||||
@ -160,7 +158,6 @@ struct ZzipInputStream {
|
|||||||
~ZzipInputStream() {
|
~ZzipInputStream() {
|
||||||
zzip_file_close(file);
|
zzip_file_close(file);
|
||||||
archive->Unref();
|
archive->Unref();
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,11 +56,10 @@ struct CdioParanoiaInputStream {
|
|||||||
|
|
||||||
CdioParanoiaInputStream(const char *uri, Mutex &mutex, Cond &cond,
|
CdioParanoiaInputStream(const char *uri, Mutex &mutex, Cond &cond,
|
||||||
int _trackno)
|
int _trackno)
|
||||||
:drv(nullptr), cdio(nullptr), para(nullptr),
|
:base(input_plugin_cdio_paranoia, uri, mutex, cond),
|
||||||
|
drv(nullptr), cdio(nullptr), para(nullptr),
|
||||||
trackno(_trackno)
|
trackno(_trackno)
|
||||||
{
|
{
|
||||||
input_stream_init(&base, &input_plugin_cdio_paranoia, uri,
|
|
||||||
mutex, cond);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~CdioParanoiaInputStream() {
|
~CdioParanoiaInputStream() {
|
||||||
@ -70,8 +69,6 @@ struct CdioParanoiaInputStream {
|
|||||||
cdio_cddap_close_no_free_cdio(drv);
|
cdio_cddap_close_no_free_cdio(drv);
|
||||||
if (cdio != nullptr)
|
if (cdio != nullptr)
|
||||||
cdio_destroy(cdio);
|
cdio_destroy(cdio);
|
||||||
|
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,12 +166,12 @@ struct input_curl {
|
|||||||
GError *postponed_error;
|
GError *postponed_error;
|
||||||
|
|
||||||
input_curl(const char *url, Mutex &mutex, Cond &cond)
|
input_curl(const char *url, Mutex &mutex, Cond &cond)
|
||||||
:range(nullptr), request_headers(nullptr),
|
:base(input_plugin_curl, url, mutex, cond),
|
||||||
|
range(nullptr), request_headers(nullptr),
|
||||||
paused(false),
|
paused(false),
|
||||||
meta_name(nullptr),
|
meta_name(nullptr),
|
||||||
tag(nullptr),
|
tag(nullptr),
|
||||||
postponed_error(nullptr) {
|
postponed_error(nullptr) {
|
||||||
input_stream_init(&base, &input_plugin_curl, url, mutex, cond);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~input_curl();
|
~input_curl();
|
||||||
@ -705,8 +705,6 @@ input_curl::~input_curl()
|
|||||||
|
|
||||||
if (postponed_error != NULL)
|
if (postponed_error != NULL)
|
||||||
g_error_free(postponed_error);
|
g_error_free(postponed_error);
|
||||||
|
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -51,11 +51,10 @@ struct DespotifyInputStream {
|
|||||||
Mutex &mutex, Cond &cond,
|
Mutex &mutex, Cond &cond,
|
||||||
despotify_session *_session,
|
despotify_session *_session,
|
||||||
ds_track *_track)
|
ds_track *_track)
|
||||||
:session(_session), track(_track),
|
:base(input_plugin_despotify, uri, mutex, cond),
|
||||||
|
session(_session), track(_track),
|
||||||
tag(mpd_despotify_tag_from_track(track)),
|
tag(mpd_despotify_tag_from_track(track)),
|
||||||
len_available(0), eof(false) {
|
len_available(0), eof(false) {
|
||||||
input_stream_init(&base, &input_plugin_despotify, uri,
|
|
||||||
mutex, cond);
|
|
||||||
|
|
||||||
memset(&pcm, 0, sizeof(pcm));
|
memset(&pcm, 0, sizeof(pcm));
|
||||||
|
|
||||||
@ -69,7 +68,6 @@ struct DespotifyInputStream {
|
|||||||
tag_free(tag);
|
tag_free(tag);
|
||||||
|
|
||||||
despotify_free_track(track);
|
despotify_free_track(track);
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,10 +44,8 @@ struct FfmpegInputStream {
|
|||||||
|
|
||||||
FfmpegInputStream(const char *uri, Mutex &mutex, Cond &cond,
|
FfmpegInputStream(const char *uri, Mutex &mutex, Cond &cond,
|
||||||
AVIOContext *_h)
|
AVIOContext *_h)
|
||||||
:h(_h), eof(false) {
|
:base(input_plugin_ffmpeg, uri, mutex, cond),
|
||||||
input_stream_init(&base, &input_plugin_ffmpeg,
|
h(_h), eof(false) {
|
||||||
uri, mutex, cond);
|
|
||||||
|
|
||||||
base.ready = true;
|
base.ready = true;
|
||||||
base.seekable = (h->seekable & AVIO_SEEKABLE_NORMAL) != 0;
|
base.seekable = (h->seekable & AVIO_SEEKABLE_NORMAL) != 0;
|
||||||
base.size = avio_size(h);
|
base.size = avio_size(h);
|
||||||
@ -61,7 +59,6 @@ struct FfmpegInputStream {
|
|||||||
|
|
||||||
~FfmpegInputStream() {
|
~FfmpegInputStream() {
|
||||||
avio_close(h);
|
avio_close(h);
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,10 +42,8 @@ struct FileInputStream {
|
|||||||
|
|
||||||
FileInputStream(const char *path, int _fd, off_t size,
|
FileInputStream(const char *path, int _fd, off_t size,
|
||||||
Mutex &mutex, Cond &cond)
|
Mutex &mutex, Cond &cond)
|
||||||
:fd(_fd) {
|
:base(input_plugin_file, path, mutex, cond),
|
||||||
input_stream_init(&base, &input_plugin_file, path,
|
fd(_fd) {
|
||||||
mutex, cond);
|
|
||||||
|
|
||||||
base.size = size;
|
base.size = size;
|
||||||
base.seekable = true;
|
base.seekable = true;
|
||||||
base.ready = true;
|
base.ready = true;
|
||||||
@ -53,7 +51,6 @@ struct FileInputStream {
|
|||||||
|
|
||||||
~FileInputStream() {
|
~FileInputStream() {
|
||||||
close(fd);
|
close(fd);
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,9 +42,8 @@ struct MmsInputStream {
|
|||||||
MmsInputStream(const char *uri,
|
MmsInputStream(const char *uri,
|
||||||
Mutex &mutex, Cond &cond,
|
Mutex &mutex, Cond &cond,
|
||||||
mmsx_t *_mms)
|
mmsx_t *_mms)
|
||||||
:mms(_mms), eof(false) {
|
:base(input_plugin_mms, uri, mutex, cond),
|
||||||
input_stream_init(&base, &input_plugin_mms, uri, mutex, cond);
|
mms(_mms), eof(false) {
|
||||||
|
|
||||||
/* XX is this correct? at least this selects the ffmpeg
|
/* XX is this correct? at least this selects the ffmpeg
|
||||||
decoder, which seems to work fine*/
|
decoder, which seems to work fine*/
|
||||||
base.mime = g_strdup("audio/x-ms-wma");
|
base.mime = g_strdup("audio/x-ms-wma");
|
||||||
@ -54,7 +53,6 @@ struct MmsInputStream {
|
|||||||
|
|
||||||
~MmsInputStream() {
|
~MmsInputStream() {
|
||||||
mmsx_close(mms);
|
mmsx_close(mms);
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,15 +61,13 @@ struct RewindInputStream {
|
|||||||
char buffer[64 * 1024];
|
char buffer[64 * 1024];
|
||||||
|
|
||||||
RewindInputStream(input_stream *_input)
|
RewindInputStream(input_stream *_input)
|
||||||
:input(_input), tail(0) {
|
:base(rewind_input_plugin, _input->uri,
|
||||||
input_stream_init(&base, &rewind_input_plugin, input->uri,
|
*_input->mutex, *_input->cond),
|
||||||
*input->mutex, *input->cond);
|
input(_input), tail(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~RewindInputStream() {
|
~RewindInputStream() {
|
||||||
input_stream_close(input);
|
input_stream_close(input);
|
||||||
|
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,14 +278,12 @@ input_soup_queue(gpointer data)
|
|||||||
|
|
||||||
SoupInputStream::SoupInputStream(const char *uri,
|
SoupInputStream::SoupInputStream(const char *uri,
|
||||||
Mutex &mutex, Cond &cond)
|
Mutex &mutex, Cond &cond)
|
||||||
:buffers(g_queue_new()),
|
:base(input_plugin_soup, uri, mutex, cond),
|
||||||
|
buffers(g_queue_new()),
|
||||||
current_consumed(0), total_buffered(0),
|
current_consumed(0), total_buffered(0),
|
||||||
alive(false), pause(false), eof(false), completed(false),
|
alive(false), pause(false), eof(false), completed(false),
|
||||||
postponed_error(nullptr)
|
postponed_error(nullptr)
|
||||||
{
|
{
|
||||||
input_stream_init(&base, &input_plugin_soup, uri,
|
|
||||||
mutex, cond);
|
|
||||||
|
|
||||||
#if GCC_CHECK_VERSION(4,6)
|
#if GCC_CHECK_VERSION(4,6)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
/* the libsoup macro SOUP_METHOD_GET discards the "const"
|
/* the libsoup macro SOUP_METHOD_GET discards the "const"
|
||||||
@ -365,8 +363,6 @@ SoupInputStream::~SoupInputStream()
|
|||||||
|
|
||||||
if (postponed_error != NULL)
|
if (postponed_error != NULL)
|
||||||
g_error_free(postponed_error);
|
g_error_free(postponed_error);
|
||||||
|
|
||||||
input_stream_deinit(&base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user