Merge branch 'master' of git://git.musicpd.org/dk/mpd
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.la
|
*.la
|
||||||
*.lo
|
*.lo
|
||||||
*.o
|
*.o
|
||||||
|
*.exe
|
||||||
.deps
|
.deps
|
||||||
.dirstamp
|
.dirstamp
|
||||||
Makefile
|
Makefile
|
||||||
@@ -31,7 +32,6 @@ ltmain.sh
|
|||||||
missing
|
missing
|
||||||
mkinstalldirs
|
mkinstalldirs
|
||||||
mpd
|
mpd
|
||||||
mpd.exe
|
|
||||||
mpd.service
|
mpd.service
|
||||||
stamp-h1
|
stamp-h1
|
||||||
tags
|
tags
|
||||||
|
30
Makefile.am
30
Makefile.am
@@ -70,7 +70,7 @@ mpd_headers = \
|
|||||||
src/gcc.h \
|
src/gcc.h \
|
||||||
src/decoder/pcm_decoder_plugin.h \
|
src/decoder/pcm_decoder_plugin.h \
|
||||||
src/input_stream.h \
|
src/input_stream.h \
|
||||||
src/text_input_stream.h \
|
src/TextInputStream.hxx \
|
||||||
src/ls.h \
|
src/ls.h \
|
||||||
src/mixer_plugin.h \
|
src/mixer_plugin.h \
|
||||||
src/daemon.h \
|
src/daemon.h \
|
||||||
@@ -94,7 +94,7 @@ mpd_headers = \
|
|||||||
src/tag_ape.h \
|
src/tag_ape.h \
|
||||||
src/tag_id3.h \
|
src/tag_id3.h \
|
||||||
src/tag_rva2.h \
|
src/tag_rva2.h \
|
||||||
src/timer.h \
|
src/Timer.hxx \
|
||||||
src/mpd_error.h
|
src/mpd_error.h
|
||||||
|
|
||||||
src_mpd_SOURCES = \
|
src_mpd_SOURCES = \
|
||||||
@@ -238,12 +238,12 @@ src_mpd_SOURCES = \
|
|||||||
src/tag_handler.c src/tag_handler.h \
|
src/tag_handler.c src/tag_handler.h \
|
||||||
src/TagFile.cxx src/TagFile.hxx \
|
src/TagFile.cxx src/TagFile.hxx \
|
||||||
src/TextFile.cxx src/TextFile.hxx \
|
src/TextFile.cxx src/TextFile.hxx \
|
||||||
src/text_input_stream.c \
|
src/TextInputStream.cxx \
|
||||||
src/Volume.cxx src/Volume.hxx \
|
src/Volume.cxx src/Volume.hxx \
|
||||||
src/SongFilter.cxx src/SongFilter.hxx \
|
src/SongFilter.cxx src/SongFilter.hxx \
|
||||||
src/SongPointer.hxx \
|
src/SongPointer.hxx \
|
||||||
src/PlaylistFile.cxx src/PlaylistFile.hxx \
|
src/PlaylistFile.cxx src/PlaylistFile.hxx \
|
||||||
src/timer.c
|
src/Timer.cxx
|
||||||
|
|
||||||
#
|
#
|
||||||
# Windows resource file
|
# Windows resource file
|
||||||
@@ -555,13 +555,13 @@ endif
|
|||||||
|
|
||||||
if HAVE_FLAC
|
if HAVE_FLAC
|
||||||
libdecoder_plugins_a_SOURCES += \
|
libdecoder_plugins_a_SOURCES += \
|
||||||
src/decoder/FLACInput.cxx src/decoder/FLACInput.hxx \
|
src/decoder/FlacInput.cxx src/decoder/FlacInput.hxx \
|
||||||
src/decoder/FLACIOHandle.cxx src/decoder/FLACIOHandle.hxx \
|
src/decoder/FlacIOHandle.cxx src/decoder/FlacIOHandle.hxx \
|
||||||
src/decoder/FLACMetaData.cxx src/decoder/FLACMetaData.hxx \
|
src/decoder/FlacMetadata.cxx src/decoder/FlacMetadata.hxx \
|
||||||
src/decoder/FLAC_PCM.cxx src/decoder/FLAC_PCM.hxx \
|
src/decoder/FlacPcm.cxx src/decoder/FlacPcm.hxx \
|
||||||
src/decoder/FLACCommon.cxx src/decoder/FLACCommon.hxx \
|
src/decoder/FlacCommon.cxx src/decoder/FlacCommon.hxx \
|
||||||
src/decoder/FLACDecoderPlugin.cxx \
|
src/decoder/FlacDecoderPlugin.cxx \
|
||||||
src/decoder/FLACDecoderPlugin.h
|
src/decoder/FlacDecoderPlugin.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if HAVE_AUDIOFILE
|
if HAVE_AUDIOFILE
|
||||||
@@ -1108,7 +1108,7 @@ test_dump_text_file_SOURCES = test/dump_text_file.cxx \
|
|||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
||||||
src/text_input_stream.c \
|
src/TextInputStream.cxx \
|
||||||
src/fd_util.c
|
src/fd_util.c
|
||||||
|
|
||||||
test_dump_playlist_LDADD = \
|
test_dump_playlist_LDADD = \
|
||||||
@@ -1130,14 +1130,14 @@ test_dump_playlist_SOURCES = test/dump_playlist.cxx \
|
|||||||
src/Song.cxx src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
src/Song.cxx src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
||||||
src/tag_handler.c src/TagFile.cxx \
|
src/tag_handler.c src/TagFile.cxx \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/text_input_stream.c \
|
src/TextInputStream.cxx \
|
||||||
src/cue/CueParser.cxx src/cue/CueParser.hxx \
|
src/cue/CueParser.cxx src/cue/CueParser.hxx \
|
||||||
src/fd_util.c
|
src/fd_util.c
|
||||||
|
|
||||||
if HAVE_FLAC
|
if HAVE_FLAC
|
||||||
test_dump_playlist_SOURCES += \
|
test_dump_playlist_SOURCES += \
|
||||||
src/ReplayGainInfo.cxx \
|
src/ReplayGainInfo.cxx \
|
||||||
src/decoder/FLACMetaData.cxx
|
src/decoder/FlacMetadata.cxx
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test_run_decoder_LDADD = \
|
test_run_decoder_LDADD = \
|
||||||
@@ -1299,7 +1299,7 @@ test_run_output_SOURCES = test/run_output.cxx \
|
|||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/audio_format.c \
|
src/audio_format.c \
|
||||||
src/AudioParser.cxx \
|
src/AudioParser.cxx \
|
||||||
src/timer.c src/clock.c \
|
src/Timer.cxx src/clock.c \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
||||||
src/Page.cxx \
|
src/Page.cxx \
|
||||||
src/SocketUtil.cxx \
|
src/SocketUtil.cxx \
|
||||||
|
@@ -17,10 +17,13 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "ClientFile.hxx"
|
#include "ClientFile.hxx"
|
||||||
#include "Client.hxx"
|
#include "Client.hxx"
|
||||||
#include "ack.h"
|
#include "ack.h"
|
||||||
#include "io_error.h"
|
#include "io_error.h"
|
||||||
|
#include "fs/Path.hxx"
|
||||||
|
#include "fs/FileSystem.hxx"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -28,7 +31,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool
|
bool
|
||||||
client_allow_file(const Client *client, const char *path_fs,
|
client_allow_file(const Client *client, const Path &path_fs,
|
||||||
GError **error_r)
|
GError **error_r)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -53,7 +56,7 @@ client_allow_file(const Client *client, const char *path_fs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(path_fs, &st) < 0) {
|
if (!StatFile(path_fs, st)) {
|
||||||
set_error_errno(error_r);
|
set_error_errno(error_r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this client allowed to use the specified local file?
|
* Is this client allowed to use the specified local file?
|
||||||
@@ -37,7 +38,7 @@ class Client;
|
|||||||
* @return true if access is allowed
|
* @return true if access is allowed
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
client_allow_file(const Client *client, const char *path_fs,
|
client_allow_file(const Client *client, const Path &path_fs,
|
||||||
GError **error_r);
|
GError **error_r);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
#include "decoder/pcm_decoder_plugin.h"
|
#include "decoder/pcm_decoder_plugin.h"
|
||||||
#include "decoder/dsdiff_decoder_plugin.h"
|
#include "decoder/dsdiff_decoder_plugin.h"
|
||||||
#include "decoder/dsf_decoder_plugin.h"
|
#include "decoder/dsf_decoder_plugin.h"
|
||||||
#include "decoder/FLACDecoderPlugin.h"
|
#include "decoder/FlacDecoderPlugin.h"
|
||||||
#include "decoder/OpusDecoderPlugin.h"
|
#include "decoder/OpusDecoderPlugin.h"
|
||||||
#include "decoder/VorbisDecoderPlugin.h"
|
#include "decoder/VorbisDecoderPlugin.h"
|
||||||
#include "decoder/AdPlugDecoderPlugin.h"
|
#include "decoder/AdPlugDecoderPlugin.h"
|
||||||
|
@@ -63,14 +63,14 @@ ExcludeList::LoadFile(const Path &path_fs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExcludeList::Check(const char *name_fs) const
|
ExcludeList::Check(const Path &name_fs) const
|
||||||
{
|
{
|
||||||
assert(name_fs != NULL);
|
assert(!name_fs.IsNull());
|
||||||
|
|
||||||
/* XXX include full path name in check */
|
/* XXX include full path name in check */
|
||||||
|
|
||||||
for (const auto &i : patterns)
|
for (const auto &i : patterns)
|
||||||
if (i.Check(name_fs))
|
if (i.Check(name_fs.c_str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -73,7 +73,7 @@ public:
|
|||||||
* Checks whether one of the patterns in the .mpdignore file matches
|
* Checks whether one of the patterns in the .mpdignore file matches
|
||||||
* the specified file name.
|
* the specified file name.
|
||||||
*/
|
*/
|
||||||
bool Check(const char *name_fs) const;
|
bool Check(const Path &name_fs) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ check_directory(const char *path_utf8, const Path &path_fs)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
const DirectoryReader reader(path_fs);
|
const DirectoryReader reader(path_fs);
|
||||||
if (reader.Failed() && errno == EACCES)
|
if (reader.HasFailed() && errno == EACCES)
|
||||||
g_warning("No permission to read directory: %s", path_utf8);
|
g_warning("No permission to read directory: %s", path_utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "ls.hxx"
|
#include "ls.hxx"
|
||||||
#include "Volume.hxx"
|
#include "Volume.hxx"
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
|
#include "fs/Path.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
@@ -117,9 +118,16 @@ handle_lsinfo(Client *client, int argc, char *argv[])
|
|||||||
if (strncmp(uri, "file:///", 8) == 0) {
|
if (strncmp(uri, "file:///", 8) == 0) {
|
||||||
/* print information about an arbitrary local file */
|
/* print information about an arbitrary local file */
|
||||||
const char *path_utf8 = uri + 7;
|
const char *path_utf8 = uri + 7;
|
||||||
|
const Path path_fs = Path::FromUTF8(path_utf8);
|
||||||
|
|
||||||
|
if (path_fs.IsNull()) {
|
||||||
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
|
"unsupported file name");
|
||||||
|
return COMMAND_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
if (!client_allow_file(client, path_utf8, &error))
|
if (!client_allow_file(client, path_fs, &error))
|
||||||
return print_error(client, error);
|
return print_error(client, error);
|
||||||
|
|
||||||
struct song *song = song_file_load(path_utf8, NULL);
|
struct song *song = song_file_load(path_utf8, NULL);
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/FileSystem.hxx"
|
#include "fs/FileSystem.hxx"
|
||||||
|
#include "fs/DirectoryReader.hxx"
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -77,7 +78,7 @@ spl_valid_name(const char *name_utf8)
|
|||||||
strchr(name_utf8, '\r') == NULL;
|
strchr(name_utf8, '\r') == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const Path &
|
||||||
spl_map(GError **error_r)
|
spl_map(GError **error_r)
|
||||||
{
|
{
|
||||||
const Path &path_fs = map_spl_path();
|
const Path &path_fs = map_spl_path();
|
||||||
@@ -85,8 +86,7 @@ spl_map(GError **error_r)
|
|||||||
g_set_error_literal(error_r, playlist_quark(),
|
g_set_error_literal(error_r, playlist_quark(),
|
||||||
PLAYLIST_RESULT_DISABLED,
|
PLAYLIST_RESULT_DISABLED,
|
||||||
"Stored playlists are disabled");
|
"Stored playlists are disabled");
|
||||||
|
return path_fs;
|
||||||
return path_fs.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -105,8 +105,7 @@ spl_check_name(const char *name_utf8, GError **error_r)
|
|||||||
static Path
|
static Path
|
||||||
spl_map_to_fs(const char *name_utf8, GError **error_r)
|
spl_map_to_fs(const char *name_utf8, GError **error_r)
|
||||||
{
|
{
|
||||||
if (spl_map(error_r) == NULL ||
|
if (spl_map(error_r).IsNull() || !spl_check_name(name_utf8, error_r))
|
||||||
!spl_check_name(name_utf8, error_r))
|
|
||||||
return Path::Null();
|
return Path::Null();
|
||||||
|
|
||||||
Path path_fs = map_spl_utf8_to_fs(name_utf8);
|
Path path_fs = map_spl_utf8_to_fs(name_utf8);
|
||||||
@@ -139,25 +138,24 @@ playlist_errno(GError **error_r)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
LoadPlaylistFileInfo(PlaylistInfo &info,
|
LoadPlaylistFileInfo(PlaylistInfo &info,
|
||||||
const char *parent_path_fs, const char *name_fs)
|
const Path &parent_path_fs, const Path &name_fs)
|
||||||
{
|
{
|
||||||
size_t name_length = strlen(name_fs);
|
const char *name_fs_str = name_fs.c_str();
|
||||||
|
size_t name_length = strlen(name_fs_str);
|
||||||
|
|
||||||
if (name_length < sizeof(PLAYLIST_FILE_SUFFIX) ||
|
if (name_length < sizeof(PLAYLIST_FILE_SUFFIX) ||
|
||||||
memchr(name_fs, '\n', name_length) != NULL)
|
memchr(name_fs_str, '\n', name_length) != NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!g_str_has_suffix(name_fs, PLAYLIST_FILE_SUFFIX))
|
if (!g_str_has_suffix(name_fs_str, PLAYLIST_FILE_SUFFIX))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char *path_fs = g_build_filename(parent_path_fs, name_fs, NULL);
|
Path path_fs = Path::Build(parent_path_fs, name_fs);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int ret = stat(path_fs, &st);
|
if (!StatFile(path_fs, st) || !S_ISREG(st.st_mode))
|
||||||
g_free(path_fs);
|
|
||||||
if (ret < 0 || !S_ISREG(st.st_mode))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char *name = g_strndup(name_fs,
|
char *name = g_strndup(name_fs_str,
|
||||||
name_length + 1 - sizeof(PLAYLIST_FILE_SUFFIX));
|
name_length + 1 - sizeof(PLAYLIST_FILE_SUFFIX));
|
||||||
std::string name_utf8 = Path::ToUTF8(name);
|
std::string name_utf8 = Path::ToUTF8(name);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
@@ -174,24 +172,23 @@ ListPlaylistFiles(GError **error_r)
|
|||||||
{
|
{
|
||||||
PlaylistVector list;
|
PlaylistVector list;
|
||||||
|
|
||||||
const char *parent_path_fs = spl_map(error_r);
|
const Path &parent_path_fs = spl_map(error_r);
|
||||||
if (parent_path_fs == NULL)
|
if (parent_path_fs.IsNull())
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
DIR *dir = opendir(parent_path_fs);
|
DirectoryReader reader(parent_path_fs);
|
||||||
if (dir == NULL) {
|
if (reader.HasFailed()) {
|
||||||
set_error_errno(error_r);
|
set_error_errno(error_r);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaylistInfo info;
|
PlaylistInfo info;
|
||||||
struct dirent *ent;
|
while (reader.ReadEntry()) {
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
const Path entry = reader.GetEntry();
|
||||||
if (LoadPlaylistFileInfo(info, parent_path_fs, ent->d_name))
|
if (LoadPlaylistFileInfo(info, parent_path_fs, entry))
|
||||||
list.push_back(std::move(info));
|
list.push_back(std::move(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +198,7 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
|
|||||||
{
|
{
|
||||||
assert(utf8path != NULL);
|
assert(utf8path != NULL);
|
||||||
|
|
||||||
if (spl_map(error_r) == NULL)
|
if (spl_map(error_r).IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
||||||
@@ -226,7 +223,7 @@ LoadPlaylistFile(const char *utf8path, GError **error_r)
|
|||||||
{
|
{
|
||||||
PlaylistFileContents contents;
|
PlaylistFileContents contents;
|
||||||
|
|
||||||
if (spl_map(error_r) == NULL)
|
if (spl_map(error_r).IsNull())
|
||||||
return contents;
|
return contents;
|
||||||
|
|
||||||
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
||||||
@@ -302,7 +299,7 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest,
|
|||||||
bool
|
bool
|
||||||
spl_clear(const char *utf8path, GError **error_r)
|
spl_clear(const char *utf8path, GError **error_r)
|
||||||
{
|
{
|
||||||
if (spl_map(error_r) == NULL)
|
if (spl_map(error_r).IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
||||||
@@ -365,7 +362,7 @@ spl_remove_index(const char *utf8path, unsigned pos, GError **error_r)
|
|||||||
bool
|
bool
|
||||||
spl_append_song(const char *utf8path, struct song *song, GError **error_r)
|
spl_append_song(const char *utf8path, struct song *song, GError **error_r)
|
||||||
{
|
{
|
||||||
if (spl_map(error_r) == NULL)
|
if (spl_map(error_r).IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
const Path path_fs = spl_map_to_fs(utf8path, error_r);
|
||||||
@@ -454,7 +451,7 @@ spl_rename_internal(const Path &from_path_fs, const Path &to_path_fs,
|
|||||||
bool
|
bool
|
||||||
spl_rename(const char *utf8from, const char *utf8to, GError **error_r)
|
spl_rename(const char *utf8from, const char *utf8to, GError **error_r)
|
||||||
{
|
{
|
||||||
if (spl_map(error_r) == NULL)
|
if (spl_map(error_r).IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Path from_path_fs = spl_map_to_fs(utf8from, error_r);
|
Path from_path_fs = spl_map_to_fs(utf8from, error_r);
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "protocol/Result.hxx"
|
#include "protocol/Result.hxx"
|
||||||
#include "ls.hxx"
|
#include "ls.hxx"
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
|
#include "fs/Path.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -42,13 +43,20 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|||||||
enum playlist_result result;
|
enum playlist_result result;
|
||||||
|
|
||||||
if (strncmp(uri, "file:///", 8) == 0) {
|
if (strncmp(uri, "file:///", 8) == 0) {
|
||||||
const char *path = uri + 7;
|
const char *path_utf8 = uri + 7;
|
||||||
|
const Path path_fs = Path::FromUTF8(path_utf8);
|
||||||
|
|
||||||
|
if (path_fs.IsNull()) {
|
||||||
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
|
"unsupported file name");
|
||||||
|
return COMMAND_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
if (!client_allow_file(client, path, &error))
|
if (!client_allow_file(client, path_fs, &error))
|
||||||
return print_error(client, error);
|
return print_error(client, error);
|
||||||
|
|
||||||
result = client->partition.AppendFile(path);
|
result = client->partition.AppendFile(path_utf8);
|
||||||
return print_playlist_result(client, result);
|
return print_playlist_result(client, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,13 +86,20 @@ handle_addid(Client *client, int argc, char *argv[])
|
|||||||
enum playlist_result result;
|
enum playlist_result result;
|
||||||
|
|
||||||
if (strncmp(uri, "file:///", 8) == 0) {
|
if (strncmp(uri, "file:///", 8) == 0) {
|
||||||
const char *path = uri + 7;
|
const char *path_utf8 = uri + 7;
|
||||||
|
const Path path_fs = Path::FromUTF8(path_utf8);
|
||||||
|
|
||||||
|
if (path_fs.IsNull()) {
|
||||||
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
|
"unsupported file name");
|
||||||
|
return COMMAND_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
if (!client_allow_file(client, path, &error))
|
if (!client_allow_file(client, path_fs, &error))
|
||||||
return print_error(client, error);
|
return print_error(client, error);
|
||||||
|
|
||||||
result = client->partition.AppendFile(path, &added_id);
|
result = client->partition.AppendFile(path_utf8, &added_id);
|
||||||
} else {
|
} else {
|
||||||
if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) {
|
if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) {
|
||||||
command_error(client, ACK_ERROR_NO_EXIST,
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "text_input_stream.h"
|
#include "TextInputStream.hxx"
|
||||||
#include "input_stream.h"
|
#include "input_stream.h"
|
||||||
#include "util/fifo_buffer.h"
|
#include "util/fifo_buffer.h"
|
||||||
|
|
||||||
@@ -27,85 +27,66 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct text_input_stream {
|
TextInputStream::TextInputStream(struct input_stream *_is)
|
||||||
struct input_stream *is;
|
: is(_is),
|
||||||
|
buffer(fifo_buffer_new(4096))
|
||||||
struct fifo_buffer *buffer;
|
|
||||||
|
|
||||||
char *line;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct text_input_stream *
|
|
||||||
text_input_stream_new(struct input_stream *is)
|
|
||||||
{
|
{
|
||||||
struct text_input_stream *tis = g_new(struct text_input_stream, 1);
|
|
||||||
|
|
||||||
tis->is = is;
|
|
||||||
tis->buffer = fifo_buffer_new(4096);
|
|
||||||
tis->line = NULL;
|
|
||||||
|
|
||||||
return tis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
TextInputStream::~TextInputStream()
|
||||||
text_input_stream_free(struct text_input_stream *tis)
|
|
||||||
{
|
{
|
||||||
fifo_buffer_free(tis->buffer);
|
fifo_buffer_free(buffer);
|
||||||
g_free(tis->line);
|
|
||||||
g_free(tis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
bool TextInputStream::ReadLine(std::string &line)
|
||||||
text_input_stream_read(struct text_input_stream *tis)
|
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = nullptr;
|
||||||
void *dest;
|
void *dest;
|
||||||
const char *src, *p;
|
const char *src, *p;
|
||||||
size_t length, nbytes;
|
size_t length, nbytes;
|
||||||
|
|
||||||
g_free(tis->line);
|
|
||||||
tis->line = NULL;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
dest = fifo_buffer_write(tis->buffer, &length);
|
dest = fifo_buffer_write(buffer, &length);
|
||||||
if (dest != NULL && length >= 2) {
|
if (dest != nullptr && length >= 2) {
|
||||||
/* reserve one byte for the null terminator if
|
/* reserve one byte for the null terminator if
|
||||||
the last line is not terminated by a
|
the last line is not terminated by a
|
||||||
newline character */
|
newline character */
|
||||||
--length;
|
--length;
|
||||||
|
|
||||||
nbytes = input_stream_lock_read(tis->is, dest, length,
|
nbytes = input_stream_lock_read(is, dest, length,
|
||||||
&error);
|
&error);
|
||||||
if (nbytes > 0)
|
if (nbytes > 0)
|
||||||
fifo_buffer_append(tis->buffer, nbytes);
|
fifo_buffer_append(buffer, nbytes);
|
||||||
else if (error != NULL) {
|
else if (error != nullptr) {
|
||||||
g_warning("%s", error->message);
|
g_warning("%s", error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
nbytes = 0;
|
nbytes = 0;
|
||||||
|
|
||||||
src = fifo_buffer_read(tis->buffer, &length);
|
auto src_p = fifo_buffer_read(buffer, &length);
|
||||||
if (src == NULL)
|
src = reinterpret_cast<const char *>(src_p);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
p = memchr(src, '\n', length);
|
if (src == nullptr)
|
||||||
if (p == NULL && nbytes == 0) {
|
return false;
|
||||||
|
|
||||||
|
p = reinterpret_cast<const char*>(memchr(src, '\n', length));
|
||||||
|
if (p == nullptr && nbytes == 0) {
|
||||||
/* end of file (or line too long): terminate
|
/* end of file (or line too long): terminate
|
||||||
the current line */
|
the current line */
|
||||||
dest = fifo_buffer_write(tis->buffer, &nbytes);
|
dest = fifo_buffer_write(buffer, &nbytes);
|
||||||
assert(dest != NULL);
|
assert(dest != nullptr);
|
||||||
*(char *)dest = '\n';
|
*(char *)dest = '\n';
|
||||||
fifo_buffer_append(tis->buffer, 1);
|
fifo_buffer_append(buffer, 1);
|
||||||
}
|
}
|
||||||
} while (p == NULL);
|
} while (p == nullptr);
|
||||||
|
|
||||||
length = p - src + 1;
|
length = p - src + 1;
|
||||||
while (p > src && g_ascii_isspace(p[-1]))
|
while (p > src && g_ascii_isspace(p[-1]))
|
||||||
--p;
|
--p;
|
||||||
|
|
||||||
tis->line = g_strndup(src, p - src);
|
line = std::string(src, p - src);
|
||||||
fifo_buffer_consume(tis->buffer, length);
|
fifo_buffer_consume(buffer, length);
|
||||||
return tis->line;
|
return true;
|
||||||
}
|
}
|
59
src/TextInputStream.hxx
Normal file
59
src/TextInputStream.hxx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPD_TEXT_INPUT_STREAM_HXX
|
||||||
|
#define MPD_TEXT_INPUT_STREAM_HXX
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct input_stream;
|
||||||
|
struct fifo_buffer;
|
||||||
|
|
||||||
|
class TextInputStream {
|
||||||
|
struct input_stream *is;
|
||||||
|
struct fifo_buffer *buffer;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Wraps an existing #input_stream object into a #TextInputStream,
|
||||||
|
* to read its contents as text lines.
|
||||||
|
*
|
||||||
|
* @param _is an open #input_stream object
|
||||||
|
*/
|
||||||
|
explicit TextInputStream(struct input_stream *_is);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the #TextInputStream object. Does not close or free the
|
||||||
|
* underlying #input_stream.
|
||||||
|
*/
|
||||||
|
~TextInputStream();
|
||||||
|
|
||||||
|
TextInputStream(const TextInputStream &) = delete;
|
||||||
|
TextInputStream& operator=(const TextInputStream &) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the next line from the stream with newline character stripped.
|
||||||
|
*
|
||||||
|
* @param line a string to put result to
|
||||||
|
* @return true if line is read successfully, false on end of file
|
||||||
|
* or error
|
||||||
|
*/
|
||||||
|
bool ReadLine(std::string &line);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "timer.h"
|
#include "Timer.hxx"
|
||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
|
||||||
@@ -28,46 +28,37 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct timer *timer_new(const struct audio_format *af)
|
Timer::Timer(const struct audio_format &af)
|
||||||
|
: time(0),
|
||||||
|
started(false),
|
||||||
|
rate(af.sample_rate * audio_format_frame_size(&af))
|
||||||
{
|
{
|
||||||
struct timer *timer = g_new(struct timer, 1);
|
|
||||||
timer->time = 0; // us
|
|
||||||
timer->started = 0; // false
|
|
||||||
timer->rate = af->sample_rate * audio_format_frame_size(af); // samples per second
|
|
||||||
|
|
||||||
return timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_free(struct timer *timer)
|
void Timer::Start()
|
||||||
{
|
{
|
||||||
g_free(timer);
|
time = monotonic_clock_us();
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_start(struct timer *timer)
|
void Timer::Reset()
|
||||||
{
|
{
|
||||||
timer->time = monotonic_clock_us();
|
time = 0;
|
||||||
timer->started = 1;
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_reset(struct timer *timer)
|
void Timer::Add(int size)
|
||||||
{
|
{
|
||||||
timer->time = 0;
|
assert(started);
|
||||||
timer->started = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer_add(struct timer *timer, int size)
|
|
||||||
{
|
|
||||||
assert(timer->started);
|
|
||||||
|
|
||||||
// (size samples) / (rate samples per second) = duration seconds
|
// (size samples) / (rate samples per second) = duration seconds
|
||||||
// duration seconds * 1000000 = duration us
|
// duration seconds * 1000000 = duration us
|
||||||
timer->time += ((uint64_t)size * 1000000) / timer->rate;
|
time += ((uint64_t)size * 1000000) / rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned Timer::GetDelay() const
|
||||||
timer_delay(const struct timer *timer)
|
|
||||||
{
|
{
|
||||||
int64_t delay = (int64_t)(timer->time - monotonic_clock_us()) / 1000;
|
int64_t delay = (int64_t)(time - monotonic_clock_us()) / 1000;
|
||||||
if (delay < 0)
|
if (delay < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -77,13 +68,13 @@ timer_delay(const struct timer *timer)
|
|||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_sync(struct timer *timer)
|
void Timer::Synchronize() const
|
||||||
{
|
{
|
||||||
int64_t sleep_duration;
|
int64_t sleep_duration;
|
||||||
|
|
||||||
assert(timer->started);
|
assert(started);
|
||||||
|
|
||||||
sleep_duration = timer->time - monotonic_clock_us();
|
sleep_duration = time - monotonic_clock_us();
|
||||||
if (sleep_duration > 0)
|
if (sleep_duration > 0)
|
||||||
g_usleep(sleep_duration);
|
g_usleep(sleep_duration);
|
||||||
}
|
}
|
@@ -17,43 +17,33 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_TIMER_H
|
#ifndef MPD_TIMER_HXX
|
||||||
#define MPD_TIMER_H
|
#define MPD_TIMER_HXX
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct audio_format;
|
struct audio_format;
|
||||||
|
|
||||||
struct timer {
|
class Timer {
|
||||||
uint64_t time;
|
uint64_t time;
|
||||||
int started;
|
bool started;
|
||||||
int rate;
|
const int rate;
|
||||||
|
public:
|
||||||
|
explicit Timer(const struct audio_format& af);
|
||||||
|
|
||||||
|
bool IsStarted() const { return started; }
|
||||||
|
|
||||||
|
void Start();
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
void Add(int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of milliseconds to sleep to get back to sync.
|
||||||
|
*/
|
||||||
|
unsigned GetDelay() const;
|
||||||
|
|
||||||
|
void Synchronize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct timer *timer_new(const struct audio_format *af);
|
|
||||||
|
|
||||||
void timer_free(struct timer *timer);
|
|
||||||
|
|
||||||
void timer_start(struct timer *timer);
|
|
||||||
|
|
||||||
void timer_reset(struct timer *timer);
|
|
||||||
|
|
||||||
void timer_add(struct timer *timer, int size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of milliseconds to sleep to get back to sync.
|
|
||||||
*/
|
|
||||||
unsigned
|
|
||||||
timer_delay(const struct timer *timer);
|
|
||||||
|
|
||||||
void timer_sync(struct timer *timer);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -34,6 +34,7 @@
|
|||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/FileSystem.hxx"
|
#include "fs/FileSystem.hxx"
|
||||||
|
#include "fs/DirectoryReader.hxx"
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@@ -102,7 +103,7 @@ remove_excluded_from_directory(Directory *directory,
|
|||||||
directory_for_each_child_safe(child, n, directory) {
|
directory_for_each_child_safe(child, n, directory) {
|
||||||
const Path name_fs = Path::FromUTF8(child->GetName());
|
const Path name_fs = Path::FromUTF8(child->GetName());
|
||||||
|
|
||||||
if (name_fs.IsNull() || exclude_list.Check(name_fs.c_str())) {
|
if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
|
||||||
delete_directory(child);
|
delete_directory(child);
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
@@ -113,7 +114,7 @@ remove_excluded_from_directory(Directory *directory,
|
|||||||
assert(song->parent == directory);
|
assert(song->parent == directory);
|
||||||
|
|
||||||
const Path name_fs = Path::FromUTF8(song->uri);
|
const Path name_fs = Path::FromUTF8(song->uri);
|
||||||
if (name_fs.IsNull() || exclude_list.Check(name_fs.c_str())) {
|
if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
|
||||||
delete_song(directory, song);
|
delete_song(directory, song);
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
@@ -261,8 +262,9 @@ update_directory_child(Directory *directory,
|
|||||||
|
|
||||||
/* we don't look at "." / ".." nor files with newlines in their name */
|
/* we don't look at "." / ".." nor files with newlines in their name */
|
||||||
G_GNUC_PURE
|
G_GNUC_PURE
|
||||||
static bool skip_path(const char *path)
|
static bool skip_path(const Path &path_fs)
|
||||||
{
|
{
|
||||||
|
const char *path = path_fs.c_str();
|
||||||
return (path[0] == '.' && path[1] == 0) ||
|
return (path[0] == '.' && path[1] == 0) ||
|
||||||
(path[0] == '.' && path[1] == '.' && path[2] == 0) ||
|
(path[0] == '.' && path[1] == '.' && path[2] == 0) ||
|
||||||
strchr(path, '\n') != NULL;
|
strchr(path, '\n') != NULL;
|
||||||
@@ -277,20 +279,11 @@ skip_symlink(const Directory *directory, const char *utf8_name)
|
|||||||
if (path_fs.IsNull())
|
if (path_fs.IsNull())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
char buffer[MPD_PATH_MAX];
|
const Path target = ReadLink(path_fs);
|
||||||
ssize_t length = readlink(path_fs.c_str(), buffer, sizeof(buffer));
|
if (target.IsNull())
|
||||||
if (length < 0)
|
|
||||||
/* don't skip if this is not a symlink */
|
/* don't skip if this is not a symlink */
|
||||||
return errno != EINVAL;
|
return errno != EINVAL;
|
||||||
|
|
||||||
if ((size_t)length >= sizeof(buffer))
|
|
||||||
/* skip symlinks when the buffer is too small for the
|
|
||||||
link target */
|
|
||||||
return true;
|
|
||||||
|
|
||||||
/* null-terminate the buffer, because readlink() will not */
|
|
||||||
buffer[length] = 0;
|
|
||||||
|
|
||||||
if (!follow_inside_symlinks && !follow_outside_symlinks) {
|
if (!follow_inside_symlinks && !follow_outside_symlinks) {
|
||||||
/* ignore all symlinks */
|
/* ignore all symlinks */
|
||||||
return true;
|
return true;
|
||||||
@@ -299,16 +292,18 @@ skip_symlink(const Directory *directory, const char *utf8_name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_path_is_absolute(buffer)) {
|
const char *target_str = target.c_str();
|
||||||
|
|
||||||
|
if (g_path_is_absolute(target_str)) {
|
||||||
/* if the symlink points to an absolute path, see if
|
/* if the symlink points to an absolute path, see if
|
||||||
that path is inside the music directory */
|
that path is inside the music directory */
|
||||||
const char *relative = map_to_relative_path(buffer);
|
const char *relative = map_to_relative_path(target_str);
|
||||||
return relative > buffer
|
return relative > target_str
|
||||||
? !follow_inside_symlinks
|
? !follow_inside_symlinks
|
||||||
: !follow_outside_symlinks;
|
: !follow_outside_symlinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *p = buffer;
|
const char *p = target_str;
|
||||||
while (*p == '.') {
|
while (*p == '.') {
|
||||||
if (p[1] == '.' && G_IS_DIR_SEPARATOR(p[2])) {
|
if (p[1] == '.' && G_IS_DIR_SEPARATOR(p[2])) {
|
||||||
/* "../" moves to parent directory */
|
/* "../" moves to parent directory */
|
||||||
@@ -352,10 +347,12 @@ update_directory(Directory *directory, const struct stat *st)
|
|||||||
if (path_fs.IsNull())
|
if (path_fs.IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DIR *dir = opendir(path_fs.c_str());
|
DirectoryReader reader(path_fs);
|
||||||
if (!dir) {
|
if (reader.HasFailed()) {
|
||||||
|
int error = errno;
|
||||||
|
const auto path_utf8 = path_fs.ToUTF8();
|
||||||
g_warning("Failed to open directory %s: %s",
|
g_warning("Failed to open directory %s: %s",
|
||||||
path_fs.c_str(), g_strerror(errno));
|
path_utf8.c_str(), g_strerror(error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,15 +364,16 @@ update_directory(Directory *directory, const struct stat *st)
|
|||||||
|
|
||||||
purge_deleted_from_directory(directory);
|
purge_deleted_from_directory(directory);
|
||||||
|
|
||||||
struct dirent *ent;
|
while (reader.ReadEntry()) {
|
||||||
while ((ent = readdir(dir))) {
|
|
||||||
std::string utf8;
|
std::string utf8;
|
||||||
struct stat st2;
|
struct stat st2;
|
||||||
|
|
||||||
if (skip_path(ent->d_name) || exclude_list.Check(ent->d_name))
|
const Path entry = reader.GetEntry();
|
||||||
|
|
||||||
|
if (skip_path(entry) || exclude_list.Check(entry))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
utf8 = Path::ToUTF8(ent->d_name);
|
utf8 = entry.ToUTF8();
|
||||||
if (utf8.empty())
|
if (utf8.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -390,8 +388,6 @@ update_directory(Directory *directory, const struct stat *st)
|
|||||||
modified |= delete_name_in(directory, utf8.c_str());
|
modified |= delete_name_in(directory, utf8.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
directory->mtime = st->st_mtime;
|
directory->mtime = st->st_mtime;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of a monotonic clock in milliseconds.
|
* Returns the value of a monotonic clock in milliseconds.
|
||||||
*/
|
*/
|
||||||
@@ -38,4 +42,8 @@ gcc_pure
|
|||||||
uint64_t
|
uint64_t
|
||||||
monotonic_clock_us(void);
|
monotonic_clock_us(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -22,9 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FLACCommon.hxx"
|
#include "FlacCommon.hxx"
|
||||||
#include "FLACMetaData.hxx"
|
#include "FlacMetadata.hxx"
|
||||||
#include "FLAC_PCM.hxx"
|
#include "FlacPcm.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "audio_check.h"
|
#include "audio_check.h"
|
||||||
@@ -36,7 +36,7 @@ extern "C" {
|
|||||||
|
|
||||||
flac_data::flac_data(struct decoder *_decoder,
|
flac_data::flac_data(struct decoder *_decoder,
|
||||||
struct input_stream *_input_stream)
|
struct input_stream *_input_stream)
|
||||||
:FLACInput(_input_stream, _decoder),
|
:FlacInput(_input_stream, _decoder),
|
||||||
initialized(false), unsupported(false),
|
initialized(false), unsupported(false),
|
||||||
total_frames(0), first_frame(0), next_frame(0), position(0),
|
total_frames(0), first_frame(0), next_frame(0), position(0),
|
||||||
decoder(_decoder), input_stream(_input_stream),
|
decoder(_decoder), input_stream(_input_stream),
|
@@ -24,7 +24,7 @@
|
|||||||
#ifndef MPD_FLAC_COMMON_HXX
|
#ifndef MPD_FLAC_COMMON_HXX
|
||||||
#define MPD_FLAC_COMMON_HXX
|
#define MPD_FLAC_COMMON_HXX
|
||||||
|
|
||||||
#include "FLACInput.hxx"
|
#include "FlacInput.hxx"
|
||||||
#include "decoder_api.h"
|
#include "decoder_api.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -37,7 +37,7 @@ extern "C" {
|
|||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#define G_LOG_DOMAIN "flac"
|
#define G_LOG_DOMAIN "flac"
|
||||||
|
|
||||||
struct flac_data : public FLACInput {
|
struct flac_data : public FlacInput {
|
||||||
struct pcm_buffer buffer;
|
struct pcm_buffer buffer;
|
||||||
|
|
||||||
/**
|
/**
|
@@ -18,9 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h" /* must be first for large file support */
|
#include "config.h" /* must be first for large file support */
|
||||||
#include "FLACDecoderPlugin.h"
|
#include "FlacDecoderPlugin.h"
|
||||||
#include "FLACCommon.hxx"
|
#include "FlacCommon.hxx"
|
||||||
#include "FLACMetaData.hxx"
|
#include "FlacMetadata.hxx"
|
||||||
#include "OggCodec.hxx"
|
#include "OggCodec.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@@ -87,7 +87,7 @@ static bool
|
|||||||
flac_scan_file(const char *file,
|
flac_scan_file(const char *file,
|
||||||
const struct tag_handler *handler, void *handler_ctx)
|
const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
FLACMetadataChain chain;
|
FlacMetadataChain chain;
|
||||||
if (!chain.Read(file)) {
|
if (!chain.Read(file)) {
|
||||||
g_debug("Failed to read FLAC tags: %s",
|
g_debug("Failed to read FLAC tags: %s",
|
||||||
chain.GetStatusString());
|
chain.GetStatusString());
|
||||||
@@ -102,7 +102,7 @@ static bool
|
|||||||
flac_scan_stream(struct input_stream *is,
|
flac_scan_stream(struct input_stream *is,
|
||||||
const struct tag_handler *handler, void *handler_ctx)
|
const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
FLACMetadataChain chain;
|
FlacMetadataChain chain;
|
||||||
if (!chain.Read(is)) {
|
if (!chain.Read(is)) {
|
||||||
g_debug("Failed to read FLAC tags: %s",
|
g_debug("Failed to read FLAC tags: %s",
|
||||||
chain.GetStatusString());
|
chain.GetStatusString());
|
||||||
@@ -214,14 +214,14 @@ static FLAC__StreamDecoderInitStatus
|
|||||||
stream_init_oggflac(FLAC__StreamDecoder *flac_dec, struct flac_data *data)
|
stream_init_oggflac(FLAC__StreamDecoder *flac_dec, struct flac_data *data)
|
||||||
{
|
{
|
||||||
return FLAC__stream_decoder_init_ogg_stream(flac_dec,
|
return FLAC__stream_decoder_init_ogg_stream(flac_dec,
|
||||||
FLACInput::Read,
|
FlacInput::Read,
|
||||||
FLACInput::Seek,
|
FlacInput::Seek,
|
||||||
FLACInput::Tell,
|
FlacInput::Tell,
|
||||||
FLACInput::Length,
|
FlacInput::Length,
|
||||||
FLACInput::Eof,
|
FlacInput::Eof,
|
||||||
flac_write_cb,
|
flac_write_cb,
|
||||||
flacMetadata,
|
flacMetadata,
|
||||||
FLACInput::Error,
|
FlacInput::Error,
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,14 +229,14 @@ static FLAC__StreamDecoderInitStatus
|
|||||||
stream_init_flac(FLAC__StreamDecoder *flac_dec, struct flac_data *data)
|
stream_init_flac(FLAC__StreamDecoder *flac_dec, struct flac_data *data)
|
||||||
{
|
{
|
||||||
return FLAC__stream_decoder_init_stream(flac_dec,
|
return FLAC__stream_decoder_init_stream(flac_dec,
|
||||||
FLACInput::Read,
|
FlacInput::Read,
|
||||||
FLACInput::Seek,
|
FlacInput::Seek,
|
||||||
FLACInput::Tell,
|
FlacInput::Tell,
|
||||||
FLACInput::Length,
|
FlacInput::Length,
|
||||||
FLACInput::Eof,
|
FlacInput::Eof,
|
||||||
flac_write_cb,
|
flac_write_cb,
|
||||||
flacMetadata,
|
flacMetadata,
|
||||||
FLACInput::Error,
|
FlacInput::Error,
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ static bool
|
|||||||
oggflac_scan_file(const char *file,
|
oggflac_scan_file(const char *file,
|
||||||
const struct tag_handler *handler, void *handler_ctx)
|
const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
FLACMetadataChain chain;
|
FlacMetadataChain chain;
|
||||||
if (!chain.ReadOgg(file)) {
|
if (!chain.ReadOgg(file)) {
|
||||||
g_debug("Failed to read OggFLAC tags: %s",
|
g_debug("Failed to read OggFLAC tags: %s",
|
||||||
chain.GetStatusString());
|
chain.GetStatusString());
|
||||||
@@ -313,7 +313,7 @@ static bool
|
|||||||
oggflac_scan_stream(struct input_stream *is,
|
oggflac_scan_stream(struct input_stream *is,
|
||||||
const struct tag_handler *handler, void *handler_ctx)
|
const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
FLACMetadataChain chain;
|
FlacMetadataChain chain;
|
||||||
if (!chain.ReadOgg(is)) {
|
if (!chain.ReadOgg(is)) {
|
||||||
g_debug("Failed to read OggFLAC tags: %s",
|
g_debug("Failed to read OggFLAC tags: %s",
|
||||||
chain.GetStatusString());
|
chain.GetStatusString());
|
@@ -18,14 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FLACIOHandle.hxx"
|
#include "FlacIOHandle.hxx"
|
||||||
#include "io_error.h"
|
#include "io_error.h"
|
||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
FLACIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
|
FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
|
||||||
{
|
{
|
||||||
input_stream *is = (input_stream *)handle;
|
input_stream *is = (input_stream *)handle;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ FLACIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
FLACIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
|
FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
|
||||||
{
|
{
|
||||||
input_stream *is = (input_stream *)handle;
|
input_stream *is = (input_stream *)handle;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ FLACIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static FLAC__int64
|
static FLAC__int64
|
||||||
FLACIOTell(FLAC__IOHandle handle)
|
FlacIOTell(FLAC__IOHandle handle)
|
||||||
{
|
{
|
||||||
input_stream *is = (input_stream *)handle;
|
input_stream *is = (input_stream *)handle;
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ FLACIOTell(FLAC__IOHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
FLACIOEof(FLAC__IOHandle handle)
|
FlacIOEof(FLAC__IOHandle handle)
|
||||||
{
|
{
|
||||||
input_stream *is = (input_stream *)handle;
|
input_stream *is = (input_stream *)handle;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ FLACIOEof(FLAC__IOHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
FLACIOClose(gcc_unused FLAC__IOHandle handle)
|
FlacIOClose(gcc_unused FLAC__IOHandle handle)
|
||||||
{
|
{
|
||||||
/* no-op because the libFLAC caller is repsonsible for closing
|
/* no-op because the libFLAC caller is repsonsible for closing
|
||||||
the #input_stream */
|
the #input_stream */
|
||||||
@@ -96,19 +96,19 @@ FLACIOClose(gcc_unused FLAC__IOHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FLAC__IOCallbacks flac_io_callbacks = {
|
const FLAC__IOCallbacks flac_io_callbacks = {
|
||||||
FLACIORead,
|
FlacIORead,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
FLACIOEof,
|
FlacIOEof,
|
||||||
FLACIOClose,
|
FlacIOClose,
|
||||||
};
|
};
|
||||||
|
|
||||||
const FLAC__IOCallbacks flac_io_callbacks_seekable = {
|
const FLAC__IOCallbacks flac_io_callbacks_seekable = {
|
||||||
FLACIORead,
|
FlacIORead,
|
||||||
nullptr,
|
nullptr,
|
||||||
FLACIOSeek,
|
FlacIOSeek,
|
||||||
FLACIOTell,
|
FlacIOTell,
|
||||||
FLACIOEof,
|
FlacIOEof,
|
||||||
FLACIOClose,
|
FlacIOClose,
|
||||||
};
|
};
|
@@ -29,13 +29,13 @@ extern const FLAC__IOCallbacks flac_io_callbacks;
|
|||||||
extern const FLAC__IOCallbacks flac_io_callbacks_seekable;
|
extern const FLAC__IOCallbacks flac_io_callbacks_seekable;
|
||||||
|
|
||||||
static inline FLAC__IOHandle
|
static inline FLAC__IOHandle
|
||||||
ToFLACIOHandle(input_stream *is)
|
ToFlacIOHandle(input_stream *is)
|
||||||
{
|
{
|
||||||
return (FLAC__IOHandle)is;
|
return (FLAC__IOHandle)is;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const FLAC__IOCallbacks &
|
static inline const FLAC__IOCallbacks &
|
||||||
GetFLACIOCallbacks(const input_stream *is)
|
GetFlacIOCallbacks(const input_stream *is)
|
||||||
{
|
{
|
||||||
return is->seekable
|
return is->seekable
|
||||||
? flac_io_callbacks_seekable
|
? flac_io_callbacks_seekable
|
@@ -18,13 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FLACInput.hxx"
|
#include "FlacInput.hxx"
|
||||||
#include "decoder_api.h"
|
#include "decoder_api.h"
|
||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
#include "InputStream.hxx"
|
#include "InputStream.hxx"
|
||||||
|
|
||||||
FLAC__StreamDecoderReadStatus
|
FLAC__StreamDecoderReadStatus
|
||||||
FLACInput::Read(FLAC__byte buffer[], size_t *bytes)
|
FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
|
||||||
{
|
{
|
||||||
size_t r = decoder_read(decoder, input_stream, (void *)buffer, *bytes);
|
size_t r = decoder_read(decoder, input_stream, (void *)buffer, *bytes);
|
||||||
*bytes = r;
|
*bytes = r;
|
||||||
@@ -42,7 +42,7 @@ FLACInput::Read(FLAC__byte buffer[], size_t *bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderSeekStatus
|
FLAC__StreamDecoderSeekStatus
|
||||||
FLACInput::Seek(FLAC__uint64 absolute_byte_offset)
|
FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
|
||||||
{
|
{
|
||||||
if (!input_stream->seekable)
|
if (!input_stream->seekable)
|
||||||
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
|
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
|
||||||
@@ -56,7 +56,7 @@ FLACInput::Seek(FLAC__uint64 absolute_byte_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderTellStatus
|
FLAC__StreamDecoderTellStatus
|
||||||
FLACInput::Tell(FLAC__uint64 *absolute_byte_offset)
|
FlacInput::Tell(FLAC__uint64 *absolute_byte_offset)
|
||||||
{
|
{
|
||||||
if (!input_stream->seekable)
|
if (!input_stream->seekable)
|
||||||
return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
|
return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
|
||||||
@@ -66,7 +66,7 @@ FLACInput::Tell(FLAC__uint64 *absolute_byte_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderLengthStatus
|
FLAC__StreamDecoderLengthStatus
|
||||||
FLACInput::Length(FLAC__uint64 *stream_length)
|
FlacInput::Length(FLAC__uint64 *stream_length)
|
||||||
{
|
{
|
||||||
if (input_stream->size < 0)
|
if (input_stream->size < 0)
|
||||||
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
|
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
|
||||||
@@ -76,7 +76,7 @@ FLACInput::Length(FLAC__uint64 *stream_length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLAC__bool
|
FLAC__bool
|
||||||
FLACInput::Eof()
|
FlacInput::Eof()
|
||||||
{
|
{
|
||||||
return (decoder != nullptr &&
|
return (decoder != nullptr &&
|
||||||
decoder_get_command(decoder) != DECODE_COMMAND_NONE &&
|
decoder_get_command(decoder) != DECODE_COMMAND_NONE &&
|
||||||
@@ -85,7 +85,7 @@ FLACInput::Eof()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FLACInput::Error(FLAC__StreamDecoderErrorStatus status)
|
FlacInput::Error(FLAC__StreamDecoderErrorStatus status)
|
||||||
{
|
{
|
||||||
if (decoder == nullptr ||
|
if (decoder == nullptr ||
|
||||||
decoder_get_command(decoder) != DECODE_COMMAND_STOP)
|
decoder_get_command(decoder) != DECODE_COMMAND_STOP)
|
||||||
@@ -93,56 +93,56 @@ FLACInput::Error(FLAC__StreamDecoderErrorStatus status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderReadStatus
|
FLAC__StreamDecoderReadStatus
|
||||||
FLACInput::Read(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
FlacInput::Read(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
||||||
FLAC__byte buffer[], size_t *bytes,
|
FLAC__byte buffer[], size_t *bytes,
|
||||||
void *client_data)
|
void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
return i->Read(buffer, bytes);
|
return i->Read(buffer, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderSeekStatus
|
FLAC__StreamDecoderSeekStatus
|
||||||
FLACInput::Seek(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
FlacInput::Seek(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
||||||
FLAC__uint64 absolute_byte_offset, void *client_data)
|
FLAC__uint64 absolute_byte_offset, void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
return i->Seek(absolute_byte_offset);
|
return i->Seek(absolute_byte_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderTellStatus
|
FLAC__StreamDecoderTellStatus
|
||||||
FLACInput::Tell(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
FlacInput::Tell(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
||||||
FLAC__uint64 *absolute_byte_offset, void *client_data)
|
FLAC__uint64 *absolute_byte_offset, void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
return i->Tell(absolute_byte_offset);
|
return i->Tell(absolute_byte_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAC__StreamDecoderLengthStatus
|
FLAC__StreamDecoderLengthStatus
|
||||||
FLACInput::Length(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
FlacInput::Length(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
||||||
FLAC__uint64 *stream_length, void *client_data)
|
FLAC__uint64 *stream_length, void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
return i->Length(stream_length);
|
return i->Length(stream_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLAC__bool
|
FLAC__bool
|
||||||
FLACInput::Eof(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
FlacInput::Eof(gcc_unused const FLAC__StreamDecoder *flac_decoder,
|
||||||
void *client_data)
|
void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
return i->Eof();
|
return i->Eof();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FLACInput::Error(gcc_unused const FLAC__StreamDecoder *decoder,
|
FlacInput::Error(gcc_unused const FLAC__StreamDecoder *decoder,
|
||||||
FLAC__StreamDecoderErrorStatus status, void *client_data)
|
FLAC__StreamDecoderErrorStatus status, void *client_data)
|
||||||
{
|
{
|
||||||
FLACInput *i = (FLACInput *)client_data;
|
FlacInput *i = (FlacInput *)client_data;
|
||||||
|
|
||||||
i->Error(status);
|
i->Error(status);
|
||||||
}
|
}
|
@@ -26,13 +26,13 @@
|
|||||||
* This class wraps an #input_stream in libFLAC stream decoder
|
* This class wraps an #input_stream in libFLAC stream decoder
|
||||||
* callbacks.
|
* callbacks.
|
||||||
*/
|
*/
|
||||||
class FLACInput {
|
class FlacInput {
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
|
|
||||||
struct input_stream *input_stream;
|
struct input_stream *input_stream;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FLACInput(struct input_stream *_input_stream,
|
FlacInput(struct input_stream *_input_stream,
|
||||||
struct decoder *_decoder=nullptr)
|
struct decoder *_decoder=nullptr)
|
||||||
:decoder(_decoder), input_stream(_input_stream) {}
|
:decoder(_decoder), input_stream(_input_stream) {}
|
||||||
|
|
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FLACMetaData.hxx"
|
#include "FlacMetadata.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "XiphTags.h"
|
#include "XiphTags.h"
|
||||||
@@ -239,7 +239,7 @@ flac_vorbis_comments_to_tag(struct tag *tag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FLACMetadataChain::Scan(const struct tag_handler *handler, void *handler_ctx)
|
FlacMetadataChain::Scan(const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
FLACMetadataIterator iterator(*this);
|
FLACMetadataIterator iterator(*this);
|
||||||
|
|
@@ -21,19 +21,19 @@
|
|||||||
#define MPD_FLAC_METADATA_H
|
#define MPD_FLAC_METADATA_H
|
||||||
|
|
||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
#include "FLACIOHandle.hxx"
|
#include "FlacIOHandle.hxx"
|
||||||
|
|
||||||
#include <FLAC/metadata.h>
|
#include <FLAC/metadata.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
class FLACMetadataChain {
|
class FlacMetadataChain {
|
||||||
FLAC__Metadata_Chain *chain;
|
FLAC__Metadata_Chain *chain;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FLACMetadataChain():chain(::FLAC__metadata_chain_new()) {}
|
FlacMetadataChain():chain(::FLAC__metadata_chain_new()) {}
|
||||||
|
|
||||||
~FLACMetadataChain() {
|
~FlacMetadataChain() {
|
||||||
::FLAC__metadata_chain_delete(chain);
|
::FLAC__metadata_chain_delete(chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Read(input_stream *is) {
|
bool Read(input_stream *is) {
|
||||||
return Read(::ToFLACIOHandle(is), ::GetFLACIOCallbacks(is));
|
return Read(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadOgg(const char *path) {
|
bool ReadOgg(const char *path) {
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ReadOgg(input_stream *is) {
|
bool ReadOgg(input_stream *is) {
|
||||||
return ReadOgg(::ToFLACIOHandle(is), ::GetFLACIOCallbacks(is));
|
return ReadOgg(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
@@ -88,7 +88,7 @@ class FLACMetadataIterator {
|
|||||||
public:
|
public:
|
||||||
FLACMetadataIterator():iterator(::FLAC__metadata_iterator_new()) {}
|
FLACMetadataIterator():iterator(::FLAC__metadata_iterator_new()) {}
|
||||||
|
|
||||||
FLACMetadataIterator(FLACMetadataChain &chain)
|
FLACMetadataIterator(FlacMetadataChain &chain)
|
||||||
:iterator(::FLAC__metadata_iterator_new()) {
|
:iterator(::FLAC__metadata_iterator_new()) {
|
||||||
::FLAC__metadata_iterator_init(iterator,
|
::FLAC__metadata_iterator_init(iterator,
|
||||||
(FLAC__Metadata_Chain *)chain);
|
(FLAC__Metadata_Chain *)chain);
|
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FLAC_PCM.hxx"
|
#include "FlacPcm.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
@@ -47,14 +47,14 @@ public:
|
|||||||
* Destroys this instance.
|
* Destroys this instance.
|
||||||
*/
|
*/
|
||||||
~DirectoryReader() {
|
~DirectoryReader() {
|
||||||
if (!Failed())
|
if (!HasFailed())
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if directory failed to open.
|
* Checks if directory failed to open.
|
||||||
*/
|
*/
|
||||||
bool Failed() const {
|
bool HasFailed() const {
|
||||||
return dirp == nullptr;
|
return dirp == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
* Checks if directory entry is available.
|
* Checks if directory entry is available.
|
||||||
*/
|
*/
|
||||||
bool HasEntry() const {
|
bool HasEntry() const {
|
||||||
assert(!Failed());
|
assert(!HasFailed());
|
||||||
return ent != nullptr;
|
return ent != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
* Reads next directory entry.
|
* Reads next directory entry.
|
||||||
*/
|
*/
|
||||||
bool ReadEntry() {
|
bool ReadEntry() {
|
||||||
assert(!Failed());
|
assert(!HasFailed());
|
||||||
ent = readdir(dirp);
|
ent = readdir(dirp);
|
||||||
return HasEntry();
|
return HasEntry();
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FifoOutputPlugin.hxx"
|
#include "FifoOutputPlugin.hxx"
|
||||||
#include "output_api.h"
|
#include "output_api.h"
|
||||||
#include "timer.h"
|
#include "Timer.hxx"
|
||||||
#include "fd_util.h"
|
#include "fd_util.h"
|
||||||
#include "open.h"
|
#include "open.h"
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ struct FifoOutput {
|
|||||||
int input;
|
int input;
|
||||||
int output;
|
int output;
|
||||||
bool created;
|
bool created;
|
||||||
struct timer *timer;
|
Timer *timer;
|
||||||
|
|
||||||
FifoOutput()
|
FifoOutput()
|
||||||
:path(nullptr), input(-1), output(-1), created(false) {}
|
:path(nullptr), input(-1), output(-1), created(false) {}
|
||||||
@@ -232,7 +232,7 @@ fifo_output_open(struct audio_output *ao, struct audio_format *audio_format,
|
|||||||
{
|
{
|
||||||
FifoOutput *fd = (FifoOutput *)ao;
|
FifoOutput *fd = (FifoOutput *)ao;
|
||||||
|
|
||||||
fd->timer = timer_new(audio_format);
|
fd->timer = new Timer(*audio_format);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ fifo_output_close(struct audio_output *ao)
|
|||||||
{
|
{
|
||||||
FifoOutput *fd = (FifoOutput *)ao;
|
FifoOutput *fd = (FifoOutput *)ao;
|
||||||
|
|
||||||
timer_free(fd->timer);
|
delete fd->timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -252,7 +252,7 @@ fifo_output_cancel(struct audio_output *ao)
|
|||||||
char buf[FIFO_BUFFER_SIZE];
|
char buf[FIFO_BUFFER_SIZE];
|
||||||
int bytes = 1;
|
int bytes = 1;
|
||||||
|
|
||||||
timer_reset(fd->timer);
|
fd->timer->Reset();
|
||||||
|
|
||||||
while (bytes > 0 && errno != EINTR)
|
while (bytes > 0 && errno != EINTR)
|
||||||
bytes = read(fd->input, buf, FIFO_BUFFER_SIZE);
|
bytes = read(fd->input, buf, FIFO_BUFFER_SIZE);
|
||||||
@@ -268,8 +268,8 @@ fifo_output_delay(struct audio_output *ao)
|
|||||||
{
|
{
|
||||||
FifoOutput *fd = (FifoOutput *)ao;
|
FifoOutput *fd = (FifoOutput *)ao;
|
||||||
|
|
||||||
return fd->timer->started
|
return fd->timer->IsStarted()
|
||||||
? timer_delay(fd->timer)
|
? fd->timer->GetDelay()
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,9 +280,9 @@ fifo_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
|||||||
FifoOutput *fd = (FifoOutput *)ao;
|
FifoOutput *fd = (FifoOutput *)ao;
|
||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
|
|
||||||
if (!fd->timer->started)
|
if (!fd->timer->IsStarted())
|
||||||
timer_start(fd->timer);
|
fd->timer->Start();
|
||||||
timer_add(fd->timer, size);
|
fd->timer->Add(size);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
bytes = write(fd->output, chunk, size);
|
bytes = write(fd->output, chunk, size);
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#define MPD_OUTPUT_HTTPD_INTERNAL_H
|
#define MPD_OUTPUT_HTTPD_INTERNAL_H
|
||||||
|
|
||||||
#include "OutputInternal.hxx"
|
#include "OutputInternal.hxx"
|
||||||
#include "timer.h"
|
#include "Timer.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "event/ServerSocket.hxx"
|
#include "event/ServerSocket.hxx"
|
||||||
|
|
||||||
@@ -72,10 +72,10 @@ struct HttpdOutput final : private ServerSocket {
|
|||||||
mutable Mutex mutex;
|
mutable Mutex mutex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A #timer object to synchronize this output with the
|
* A #Timer object to synchronize this output with the
|
||||||
* wallclock.
|
* wallclock.
|
||||||
*/
|
*/
|
||||||
struct timer *timer;
|
Timer *timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The header page, which is sent to every client on connect.
|
* The header page, which is sent to every client on connect.
|
||||||
|
@@ -320,7 +320,7 @@ HttpdOutput::Open(struct audio_format *audio_format, GError **error_r)
|
|||||||
/* initialize other attributes */
|
/* initialize other attributes */
|
||||||
|
|
||||||
clients_cnt = 0;
|
clients_cnt = 0;
|
||||||
timer = timer_new(audio_format);
|
timer = new Timer(*audio_format);
|
||||||
|
|
||||||
open = true;
|
open = true;
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ HttpdOutput::Close()
|
|||||||
|
|
||||||
open = false;
|
open = false;
|
||||||
|
|
||||||
timer_free(timer);
|
delete timer;
|
||||||
|
|
||||||
clients.clear();
|
clients.clear();
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ httpd_output_delay(struct audio_output *ao)
|
|||||||
then httpd_output_pause() will not do anything, it
|
then httpd_output_pause() will not do anything, it
|
||||||
will not fill the buffer and it will not update the
|
will not fill the buffer and it will not update the
|
||||||
timer; therefore, we reset the timer here */
|
timer; therefore, we reset the timer here */
|
||||||
timer_reset(httpd->timer);
|
httpd->timer->Reset();
|
||||||
|
|
||||||
/* some arbitrary delay that is long enough to avoid
|
/* some arbitrary delay that is long enough to avoid
|
||||||
consuming too much CPU, and short enough to notice
|
consuming too much CPU, and short enough to notice
|
||||||
@@ -406,8 +406,8 @@ httpd_output_delay(struct audio_output *ao)
|
|||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpd->timer->started
|
return httpd->timer->IsStarted()
|
||||||
? timer_delay(httpd->timer)
|
? httpd->timer->GetDelay()
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,9 +463,9 @@ httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!httpd->timer->started)
|
if (!httpd->timer->IsStarted())
|
||||||
timer_start(httpd->timer);
|
httpd->timer->Start();
|
||||||
timer_add(httpd->timer, size);
|
httpd->timer->Add(size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "NullOutputPlugin.hxx"
|
#include "NullOutputPlugin.hxx"
|
||||||
#include "output_api.h"
|
#include "output_api.h"
|
||||||
#include "timer.h"
|
#include "Timer.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ struct NullOutput {
|
|||||||
|
|
||||||
bool sync;
|
bool sync;
|
||||||
|
|
||||||
struct timer *timer;
|
Timer *timer;
|
||||||
|
|
||||||
bool Initialize(const config_param *param, GError **error_r) {
|
bool Initialize(const config_param *param, GError **error_r) {
|
||||||
return ao_base_init(&base, &null_output_plugin, param,
|
return ao_base_init(&base, &null_output_plugin, param,
|
||||||
@@ -72,7 +72,7 @@ null_open(struct audio_output *ao, struct audio_format *audio_format,
|
|||||||
NullOutput *nd = (NullOutput *)ao;
|
NullOutput *nd = (NullOutput *)ao;
|
||||||
|
|
||||||
if (nd->sync)
|
if (nd->sync)
|
||||||
nd->timer = timer_new(audio_format);
|
nd->timer = new Timer(*audio_format);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ null_close(struct audio_output *ao)
|
|||||||
NullOutput *nd = (NullOutput *)ao;
|
NullOutput *nd = (NullOutput *)ao;
|
||||||
|
|
||||||
if (nd->sync)
|
if (nd->sync)
|
||||||
timer_free(nd->timer);
|
delete nd->timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
@@ -91,8 +91,8 @@ null_delay(struct audio_output *ao)
|
|||||||
{
|
{
|
||||||
NullOutput *nd = (NullOutput *)ao;
|
NullOutput *nd = (NullOutput *)ao;
|
||||||
|
|
||||||
return nd->sync && nd->timer->started
|
return nd->sync && nd->timer->IsStarted()
|
||||||
? timer_delay(nd->timer)
|
? nd->timer->GetDelay()
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +101,14 @@ null_play(struct audio_output *ao, gcc_unused const void *chunk, size_t size,
|
|||||||
gcc_unused GError **error)
|
gcc_unused GError **error)
|
||||||
{
|
{
|
||||||
NullOutput *nd = (NullOutput *)ao;
|
NullOutput *nd = (NullOutput *)ao;
|
||||||
struct timer *timer = nd->timer;
|
Timer *timer = nd->timer;
|
||||||
|
|
||||||
if (!nd->sync)
|
if (!nd->sync)
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
if (!timer->started)
|
if (!timer->IsStarted())
|
||||||
timer_start(timer);
|
timer->Start();
|
||||||
timer_add(timer, size);
|
timer->Add(size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ null_cancel(struct audio_output *ao)
|
|||||||
if (!nd->sync)
|
if (!nd->sync)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
timer_reset(nd->timer);
|
nd->timer->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct audio_output_plugin null_output_plugin = {
|
const struct audio_output_plugin null_output_plugin = {
|
||||||
|
@@ -24,10 +24,7 @@
|
|||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "input_stream.h"
|
#include "input_stream.h"
|
||||||
#include "cue/CueParser.hxx"
|
#include "cue/CueParser.hxx"
|
||||||
|
#include "TextInputStream.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "text_input_stream.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -40,16 +37,15 @@ struct CuePlaylist {
|
|||||||
struct playlist_provider base;
|
struct playlist_provider base;
|
||||||
|
|
||||||
struct input_stream *is;
|
struct input_stream *is;
|
||||||
struct text_input_stream *tis;
|
TextInputStream tis;
|
||||||
CueParser parser;
|
CueParser parser;
|
||||||
|
|
||||||
CuePlaylist(struct input_stream *_is)
|
CuePlaylist(struct input_stream *_is)
|
||||||
:is(_is), tis(text_input_stream_new(is)) {
|
:is(_is), tis(is) {
|
||||||
playlist_provider_init(&base, &cue_playlist_plugin);
|
playlist_provider_init(&base, &cue_playlist_plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
~CuePlaylist() {
|
~CuePlaylist() {
|
||||||
text_input_stream_free(tis);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,9 +72,9 @@ cue_playlist_read(struct playlist_provider *_playlist)
|
|||||||
if (song != NULL)
|
if (song != NULL)
|
||||||
return song;
|
return song;
|
||||||
|
|
||||||
const char *line;
|
std::string line;
|
||||||
while ((line = text_input_stream_read(playlist->tis)) != NULL) {
|
while (playlist->tis.ReadLine(line)) {
|
||||||
playlist->parser.Feed(line);
|
playlist->parser.Feed(line.c_str());
|
||||||
song = playlist->parser.Get();
|
song = playlist->parser.Get();
|
||||||
if (song != NULL)
|
if (song != NULL)
|
||||||
return song;
|
return song;
|
||||||
|
@@ -23,10 +23,7 @@
|
|||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "util/StringUtil.hxx"
|
#include "util/StringUtil.hxx"
|
||||||
|
#include "TextInputStream.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "text_input_stream.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@@ -36,20 +33,21 @@ extern "C" {
|
|||||||
struct ExtM3uPlaylist {
|
struct ExtM3uPlaylist {
|
||||||
struct playlist_provider base;
|
struct playlist_provider base;
|
||||||
|
|
||||||
struct text_input_stream *tis;
|
TextInputStream *tis;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct playlist_provider *
|
static struct playlist_provider *
|
||||||
extm3u_open_stream(struct input_stream *is)
|
extm3u_open_stream(struct input_stream *is)
|
||||||
{
|
{
|
||||||
ExtM3uPlaylist *playlist = g_new(ExtM3uPlaylist, 1);
|
ExtM3uPlaylist *playlist = g_new(ExtM3uPlaylist, 1);
|
||||||
playlist->tis = text_input_stream_new(is);
|
playlist->tis = new TextInputStream(is);
|
||||||
|
|
||||||
const char *line = text_input_stream_read(playlist->tis);
|
std::string line;
|
||||||
if (line == NULL || strcmp(line, "#EXTM3U") != 0) {
|
if (!playlist->tis->ReadLine(line)
|
||||||
|
|| strcmp(line.c_str(), "#EXTM3U") != 0) {
|
||||||
/* no EXTM3U header: fall back to the plain m3u
|
/* no EXTM3U header: fall back to the plain m3u
|
||||||
plugin */
|
plugin */
|
||||||
text_input_stream_free(playlist->tis);
|
delete playlist->tis;
|
||||||
g_free(playlist);
|
g_free(playlist);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -63,7 +61,7 @@ extm3u_close(struct playlist_provider *_playlist)
|
|||||||
{
|
{
|
||||||
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
||||||
|
|
||||||
text_input_stream_free(playlist->tis);
|
delete playlist->tis;
|
||||||
g_free(playlist);
|
g_free(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,29 +110,31 @@ extm3u_read(struct playlist_provider *_playlist)
|
|||||||
{
|
{
|
||||||
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
||||||
struct tag *tag = NULL;
|
struct tag *tag = NULL;
|
||||||
const char *line;
|
std::string line;
|
||||||
|
const char *line_s;
|
||||||
struct song *song;
|
struct song *song;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
line = text_input_stream_read(playlist->tis);
|
if (!playlist->tis->ReadLine(line)) {
|
||||||
if (line == NULL) {
|
|
||||||
if (tag != NULL)
|
if (tag != NULL)
|
||||||
tag_free(tag);
|
tag_free(tag);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
line_s = line.c_str();
|
||||||
|
|
||||||
if (g_str_has_prefix(line, "#EXTINF:")) {
|
if (g_str_has_prefix(line_s, "#EXTINF:")) {
|
||||||
if (tag != NULL)
|
if (tag != NULL)
|
||||||
tag_free(tag);
|
tag_free(tag);
|
||||||
tag = extm3u_parse_tag(line + 8);
|
tag = extm3u_parse_tag(line_s + 8);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*line != 0 && g_ascii_isspace(*line))
|
while (*line_s != 0 && g_ascii_isspace(*line_s))
|
||||||
++line;
|
++line_s;
|
||||||
} while (line[0] == '#' || *line == 0);
|
} while (line_s[0] == '#' || *line_s == 0);
|
||||||
|
|
||||||
song = song_remote_new(line);
|
song = song_remote_new(line_s);
|
||||||
song->tag = tag;
|
song->tag = tag;
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
@@ -21,17 +21,14 @@
|
|||||||
#include "M3uPlaylistPlugin.hxx"
|
#include "M3uPlaylistPlugin.hxx"
|
||||||
#include "PlaylistPlugin.hxx"
|
#include "PlaylistPlugin.hxx"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
#include "TextInputStream.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "text_input_stream.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
struct M3uPlaylist {
|
struct M3uPlaylist {
|
||||||
struct playlist_provider base;
|
struct playlist_provider base;
|
||||||
|
|
||||||
struct text_input_stream *tis;
|
TextInputStream *tis;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct playlist_provider *
|
static struct playlist_provider *
|
||||||
@@ -40,7 +37,7 @@ m3u_open_stream(struct input_stream *is)
|
|||||||
M3uPlaylist *playlist = g_new(M3uPlaylist, 1);
|
M3uPlaylist *playlist = g_new(M3uPlaylist, 1);
|
||||||
|
|
||||||
playlist_provider_init(&playlist->base, &m3u_playlist_plugin);
|
playlist_provider_init(&playlist->base, &m3u_playlist_plugin);
|
||||||
playlist->tis = text_input_stream_new(is);
|
playlist->tis = new TextInputStream(is);
|
||||||
|
|
||||||
return &playlist->base;
|
return &playlist->base;
|
||||||
}
|
}
|
||||||
@@ -50,7 +47,7 @@ m3u_close(struct playlist_provider *_playlist)
|
|||||||
{
|
{
|
||||||
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
||||||
|
|
||||||
text_input_stream_free(playlist->tis);
|
delete playlist->tis;
|
||||||
g_free(playlist);
|
g_free(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,18 +55,20 @@ static struct song *
|
|||||||
m3u_read(struct playlist_provider *_playlist)
|
m3u_read(struct playlist_provider *_playlist)
|
||||||
{
|
{
|
||||||
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
||||||
const char *line;
|
std::string line;
|
||||||
|
const char *line_s;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
line = text_input_stream_read(playlist->tis);
|
if (!playlist->tis->ReadLine(line))
|
||||||
if (line == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (*line != 0 && g_ascii_isspace(*line))
|
line_s = line.c_str();
|
||||||
++line;
|
|
||||||
} while (line[0] == '#' || *line == 0);
|
|
||||||
|
|
||||||
return song_remote_new(line);
|
while (*line_s != 0 && g_ascii_isspace(*line_s))
|
||||||
|
++line_s;
|
||||||
|
} while (line_s[0] == '#' || *line_s == 0);
|
||||||
|
|
||||||
|
return song_remote_new(line_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *const m3u_suffixes[] = {
|
static const char *const m3u_suffixes[] = {
|
||||||
|
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MPD_TEXT_INPUT_STREAM_H
|
|
||||||
#define MPD_TEXT_INPUT_STREAM_H
|
|
||||||
|
|
||||||
struct input_stream;
|
|
||||||
struct text_input_stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps an existing #input_stream object into a #text_input_stream,
|
|
||||||
* to read its contents as text lines.
|
|
||||||
*
|
|
||||||
* @param is an open #input_stream object
|
|
||||||
* @return the new #text_input_stream object
|
|
||||||
*/
|
|
||||||
struct text_input_stream *
|
|
||||||
text_input_stream_new(struct input_stream *is);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees the #text_input_stream object. Does not close or free the
|
|
||||||
* underlying #input_stream.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
text_input_stream_free(struct text_input_stream *tis);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the next line from the stream.
|
|
||||||
*
|
|
||||||
* @return a line (newline character stripped), or NULL on end of file
|
|
||||||
* or error
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
text_input_stream_read(struct text_input_stream *tis);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -23,10 +23,7 @@
|
|||||||
#include "InputStream.hxx"
|
#include "InputStream.hxx"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "stdbin.h"
|
#include "stdbin.h"
|
||||||
|
#include "TextInputStream.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "text_input_stream.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
#include "ArchiveList.hxx"
|
#include "ArchiveList.hxx"
|
||||||
@@ -49,11 +46,11 @@ my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_text_file(struct text_input_stream *is)
|
dump_text_file(TextInputStream &is)
|
||||||
{
|
{
|
||||||
const char *line;
|
std::string line;
|
||||||
while ((line = text_input_stream_read(is)) != NULL)
|
while (is.ReadLine(line))
|
||||||
printf("'%s'\n", line);
|
printf("'%s'\n", line.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -77,11 +74,10 @@ dump_input_stream(struct input_stream *is)
|
|||||||
/* read data and tags from the stream */
|
/* read data and tags from the stream */
|
||||||
|
|
||||||
input_stream_unlock(is);
|
input_stream_unlock(is);
|
||||||
|
{
|
||||||
struct text_input_stream *tis = text_input_stream_new(is);
|
TextInputStream tis(is);
|
||||||
dump_text_file(tis);
|
dump_text_file(tis);
|
||||||
text_input_stream_free(tis);
|
}
|
||||||
|
|
||||||
input_stream_lock(is);
|
input_stream_lock(is);
|
||||||
|
|
||||||
if (!input_stream_check(is, &error)) {
|
if (!input_stream_check(is, &error)) {
|
||||||
|
Reference in New Issue
Block a user