input/file,mms: convert to C++
This commit is contained in:
parent
e01615fd1e
commit
5cffe693b0
@ -79,10 +79,8 @@ mpd_headers = \
|
||||
src/decoder/pcm_decoder_plugin.h \
|
||||
src/input_plugin.h \
|
||||
src/input_stream.h \
|
||||
src/input/file_input_plugin.h \
|
||||
src/input/ffmpeg_input_plugin.h \
|
||||
src/input/rewind_input_plugin.h \
|
||||
src/input/mms_input_plugin.h \
|
||||
src/input/despotify_input_plugin.h \
|
||||
src/input/cdio_paranoia_input_plugin.h \
|
||||
src/despotify_utils.h \
|
||||
@ -714,7 +712,7 @@ libinput_a_SOURCES = \
|
||||
src/InputStream.cxx \
|
||||
src/input_internal.c src/input_internal.h \
|
||||
src/input/rewind_input_plugin.c \
|
||||
src/input/file_input_plugin.c
|
||||
src/input/FileInputPlugin.cxx src/input/FileInputPlugin.hxx
|
||||
|
||||
libinput_a_CPPFLAGS = $(AM_CPPFLAGS) \
|
||||
$(CURL_CFLAGS) \
|
||||
@ -753,7 +751,8 @@ libinput_a_SOURCES += src/input/ffmpeg_input_plugin.c
|
||||
endif
|
||||
|
||||
if ENABLE_MMS
|
||||
libinput_a_SOURCES += src/input/mms_input_plugin.c
|
||||
libinput_a_SOURCES += \
|
||||
src/input/MmsInputPlugin.cxx src/input/MmsInputPlugin.hxx
|
||||
endif
|
||||
|
||||
if ENABLE_DESPOTIFY
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "InputRegistry.hxx"
|
||||
#include "input/file_input_plugin.h"
|
||||
#include "input/FileInputPlugin.hxx"
|
||||
|
||||
#ifdef ENABLE_ARCHIVE
|
||||
#include "input/archive_input_plugin.h"
|
||||
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MMS
|
||||
#include "input/mms_input_plugin.h"
|
||||
#include "input/MmsInputPlugin.hxx"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CDIO_PARANOIA
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h" /* must be first for large file support */
|
||||
#include "input/file_input_plugin.h"
|
||||
#include "FileInputPlugin.hxx"
|
||||
#include "input_internal.h"
|
||||
#include "input_plugin.h"
|
||||
#include "fd_util.h"
|
||||
@ -34,10 +34,26 @@
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "input_file"
|
||||
|
||||
struct file_input_stream {
|
||||
struct FileInputStream {
|
||||
struct input_stream base;
|
||||
|
||||
int fd;
|
||||
|
||||
FileInputStream(const char *path, int _fd, off_t size,
|
||||
GMutex *mutex, GCond *cond)
|
||||
:fd(_fd) {
|
||||
input_stream_init(&base, &input_plugin_file, path,
|
||||
mutex, cond);
|
||||
|
||||
base.size = size;
|
||||
base.seekable = true;
|
||||
base.ready = true;
|
||||
}
|
||||
|
||||
~FileInputStream() {
|
||||
close(fd);
|
||||
input_stream_deinit(&base);
|
||||
}
|
||||
};
|
||||
|
||||
static struct input_stream *
|
||||
@ -47,10 +63,9 @@ input_file_open(const char *filename,
|
||||
{
|
||||
int fd, ret;
|
||||
struct stat st;
|
||||
struct file_input_stream *fis;
|
||||
|
||||
if (!g_path_is_absolute(filename))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);
|
||||
if (fd < 0) {
|
||||
@ -58,7 +73,7 @@ input_file_open(const char *filename,
|
||||
g_set_error(error_r, errno_quark(), errno,
|
||||
"Failed to open \"%s\": %s",
|
||||
filename, g_strerror(errno));
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ret = fstat(fd, &st);
|
||||
@ -67,30 +82,22 @@ input_file_open(const char *filename,
|
||||
"Failed to stat \"%s\": %s",
|
||||
filename, g_strerror(errno));
|
||||
close(fd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!S_ISREG(st.st_mode)) {
|
||||
g_set_error(error_r, errno_quark(), 0,
|
||||
"Not a regular file: %s", filename);
|
||||
close(fd);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef POSIX_FADV_SEQUENTIAL
|
||||
posix_fadvise(fd, (off_t)0, st.st_size, POSIX_FADV_SEQUENTIAL);
|
||||
#endif
|
||||
|
||||
fis = g_new(struct file_input_stream, 1);
|
||||
input_stream_init(&fis->base, &input_plugin_file, filename,
|
||||
mutex, cond);
|
||||
|
||||
fis->base.size = st.st_size;
|
||||
fis->base.seekable = true;
|
||||
fis->base.ready = true;
|
||||
|
||||
fis->fd = fd;
|
||||
|
||||
FileInputStream *fis = new FileInputStream(filename, fd, st.st_size,
|
||||
mutex, cond);
|
||||
return &fis->base;
|
||||
}
|
||||
|
||||
@ -98,7 +105,7 @@ static bool
|
||||
input_file_seek(struct input_stream *is, goffset offset, int whence,
|
||||
GError **error_r)
|
||||
{
|
||||
struct file_input_stream *fis = (struct file_input_stream *)is;
|
||||
FileInputStream *fis = (FileInputStream *)is;
|
||||
|
||||
offset = (goffset)lseek(fis->fd, (off_t)offset, whence);
|
||||
if (offset < 0) {
|
||||
@ -115,7 +122,7 @@ static size_t
|
||||
input_file_read(struct input_stream *is, void *ptr, size_t size,
|
||||
GError **error_r)
|
||||
{
|
||||
struct file_input_stream *fis = (struct file_input_stream *)is;
|
||||
FileInputStream *fis = (FileInputStream *)is;
|
||||
ssize_t nbytes;
|
||||
|
||||
nbytes = read(fis->fd, ptr, size);
|
||||
@ -132,11 +139,9 @@ input_file_read(struct input_stream *is, void *ptr, size_t size,
|
||||
static void
|
||||
input_file_close(struct input_stream *is)
|
||||
{
|
||||
struct file_input_stream *fis = (struct file_input_stream *)is;
|
||||
FileInputStream *fis = (FileInputStream *)is;
|
||||
|
||||
close(fis->fd);
|
||||
input_stream_deinit(&fis->base);
|
||||
g_free(fis);
|
||||
delete fis;
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -146,10 +151,16 @@ input_file_eof(struct input_stream *is)
|
||||
}
|
||||
|
||||
const struct input_plugin input_plugin_file = {
|
||||
.name = "file",
|
||||
.open = input_file_open,
|
||||
.close = input_file_close,
|
||||
.read = input_file_read,
|
||||
.eof = input_file_eof,
|
||||
.seek = input_file_seek,
|
||||
"file",
|
||||
nullptr,
|
||||
nullptr,
|
||||
input_file_open,
|
||||
input_file_close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
input_file_read,
|
||||
input_file_eof,
|
||||
input_file_seek,
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -17,8 +17,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_INPUT_FILE_H
|
||||
#define MPD_INPUT_FILE_H
|
||||
#ifndef MPD_INPUT_FILE_HXX
|
||||
#define MPD_INPUT_FILE_HXX
|
||||
|
||||
extern const struct input_plugin input_plugin_file;
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "input/mms_input_plugin.h"
|
||||
#include "MmsInputPlugin.hxx"
|
||||
#include "input_internal.h"
|
||||
#include "input_plugin.h"
|
||||
|
||||
@ -31,12 +31,30 @@
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "input_mms"
|
||||
|
||||
struct input_mms {
|
||||
struct MmsInputStream {
|
||||
struct input_stream base;
|
||||
|
||||
mmsx_t *mms;
|
||||
|
||||
bool eof;
|
||||
|
||||
MmsInputStream(const char *uri,
|
||||
GMutex *mutex, GCond *cond,
|
||||
mmsx_t *_mms)
|
||||
:mms(_mms), eof(false) {
|
||||
input_stream_init(&base, &input_plugin_mms, uri, mutex, cond);
|
||||
|
||||
/* XX is this correct? at least this selects the ffmpeg
|
||||
decoder, which seems to work fine*/
|
||||
base.mime = g_strdup("audio/x-ms-wma");
|
||||
|
||||
base.ready = true;
|
||||
}
|
||||
|
||||
~MmsInputStream() {
|
||||
mmsx_close(mms);
|
||||
input_stream_deinit(&base);
|
||||
}
|
||||
};
|
||||
|
||||
static inline GQuark
|
||||
@ -50,33 +68,19 @@ input_mms_open(const char *url,
|
||||
GMutex *mutex, GCond *cond,
|
||||
GError **error_r)
|
||||
{
|
||||
struct input_mms *m;
|
||||
|
||||
if (!g_str_has_prefix(url, "mms://") &&
|
||||
!g_str_has_prefix(url, "mmsh://") &&
|
||||
!g_str_has_prefix(url, "mmst://") &&
|
||||
!g_str_has_prefix(url, "mmsu://"))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
m = g_new(struct input_mms, 1);
|
||||
input_stream_init(&m->base, &input_plugin_mms, url,
|
||||
mutex, cond);
|
||||
|
||||
m->mms = mmsx_connect(NULL, NULL, url, 128 * 1024);
|
||||
if (m->mms == NULL) {
|
||||
g_free(m);
|
||||
const auto mms = mmsx_connect(nullptr, nullptr, url, 128 * 1024);
|
||||
if (mms == nullptr) {
|
||||
g_set_error(error_r, mms_quark(), 0, "mmsx_connect() failed");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m->eof = false;
|
||||
|
||||
/* XX is this correct? at least this selects the ffmpeg
|
||||
decoder, which seems to work fine*/
|
||||
m->base.mime = g_strdup("audio/x-ms-wma");
|
||||
|
||||
m->base.ready = true;
|
||||
|
||||
auto m = new MmsInputStream(url, mutex, cond, mms);
|
||||
return &m->base;
|
||||
}
|
||||
|
||||
@ -84,10 +88,10 @@ static size_t
|
||||
input_mms_read(struct input_stream *is, void *ptr, size_t size,
|
||||
GError **error_r)
|
||||
{
|
||||
struct input_mms *m = (struct input_mms *)is;
|
||||
MmsInputStream *m = (MmsInputStream *)is;
|
||||
int ret;
|
||||
|
||||
ret = mmsx_read(NULL, m->mms, ptr, size);
|
||||
ret = mmsx_read(nullptr, m->mms, (char *)ptr, size);
|
||||
if (ret <= 0) {
|
||||
if (ret < 0) {
|
||||
g_set_error(error_r, mms_quark(), errno,
|
||||
@ -107,17 +111,15 @@ input_mms_read(struct input_stream *is, void *ptr, size_t size,
|
||||
static void
|
||||
input_mms_close(struct input_stream *is)
|
||||
{
|
||||
struct input_mms *m = (struct input_mms *)is;
|
||||
MmsInputStream *m = (MmsInputStream *)is;
|
||||
|
||||
mmsx_close(m->mms);
|
||||
input_stream_deinit(&m->base);
|
||||
g_free(m);
|
||||
delete m;
|
||||
}
|
||||
|
||||
static bool
|
||||
input_mms_eof(struct input_stream *is)
|
||||
{
|
||||
struct input_mms *m = (struct input_mms *)is;
|
||||
MmsInputStream *m = (MmsInputStream *)is;
|
||||
|
||||
return m->eof;
|
||||
}
|
||||
@ -131,10 +133,16 @@ input_mms_seek(G_GNUC_UNUSED struct input_stream *is,
|
||||
}
|
||||
|
||||
const struct input_plugin input_plugin_mms = {
|
||||
.name = "mms",
|
||||
.open = input_mms_open,
|
||||
.close = input_mms_close,
|
||||
.read = input_mms_read,
|
||||
.eof = input_mms_eof,
|
||||
.seek = input_mms_seek,
|
||||
"mms",
|
||||
nullptr,
|
||||
nullptr,
|
||||
input_mms_open,
|
||||
input_mms_close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
input_mms_read,
|
||||
input_mms_eof,
|
||||
input_mms_seek,
|
||||
};
|
Loading…
Reference in New Issue
Block a user