Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
cadc67ea
Commit
cadc67ea
authored
Feb 21, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input: wrap InputStream in std::unique_ptr
parent
054e9eca
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
108 additions
and
104 deletions
+108
-104
TagFile.cxx
src/TagFile.cxx
+1
-5
TagStream.cxx
src/TagStream.cxx
+3
-8
Bzip2ArchivePlugin.cxx
src/archive/plugins/Bzip2ArchivePlugin.cxx
+5
-9
DecoderAPI.cxx
src/decoder/DecoderAPI.cxx
+3
-4
DecoderAPI.hxx
src/decoder/DecoderAPI.hxx
+2
-1
WavpackDecoderPlugin.cxx
src/decoder/plugins/WavpackDecoderPlugin.cxx
+2
-2
InputStream.hxx
src/input/InputStream.hxx
+7
-7
LocalOpen.cxx
src/input/LocalOpen.cxx
+3
-3
LocalOpen.hxx
src/input/LocalOpen.hxx
+2
-2
Open.cxx
src/input/Open.cxx
+6
-8
Ptr.hxx
src/input/Ptr.hxx
+29
-0
PlaylistStream.cxx
src/playlist/PlaylistStream.cxx
+5
-9
SoundCloudPlaylistPlugin.cxx
src/playlist/plugins/SoundCloudPlaylistPlugin.cxx
+2
-4
FakeDecoderAPI.cxx
test/FakeDecoderAPI.cxx
+1
-1
dump_playlist.cxx
test/dump_playlist.cxx
+3
-4
dump_text_file.cxx
test/dump_text_file.cxx
+14
-13
read_tags.cxx
test/read_tags.cxx
+4
-5
run_decoder.cxx
test/run_decoder.cxx
+3
-6
run_input.cxx
test/run_input.cxx
+13
-13
No files found.
src/TagFile.cxx
View file @
cadc67ea
...
...
@@ -39,7 +39,7 @@ class TagFileScan {
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
;
InputStream
Ptr
is
;
public
:
TagFileScan
(
Path
_path_fs
,
const
char
*
_suffix
,
...
...
@@ -48,10 +48,6 @@ public:
handler
(
_handler
),
handler_ctx
(
_handler_ctx
)
,
is
(
nullptr
)
{}
~
TagFileScan
()
{
delete
is
;
}
bool
ScanFile
(
const
DecoderPlugin
&
plugin
)
{
return
plugin
.
ScanFile
(
path_fs
,
handler
,
handler_ctx
);
}
...
...
src/TagStream.cxx
View file @
cadc67ea
...
...
@@ -68,12 +68,7 @@ tag_stream_scan(const char *uri, const tag_handler &handler, void *ctx)
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
OpenReady
(
uri
,
mutex
,
cond
,
IgnoreError
());
if
(
is
==
nullptr
)
return
false
;
bool
success
=
tag_stream_scan
(
*
is
,
handler
,
ctx
);
delete
is
;
return
success
;
auto
is
=
InputStream
::
OpenReady
(
uri
,
mutex
,
cond
,
IgnoreError
());
return
is
&&
tag_stream_scan
(
*
is
,
handler
,
ctx
);
}
src/archive/plugins/Bzip2ArchivePlugin.cxx
View file @
cadc67ea
...
...
@@ -49,22 +49,18 @@ public:
RefCount
ref
;
std
::
string
name
;
InputStream
*
const
istream
;
const
InputStreamPtr
istream
;
Bzip2ArchiveFile
(
Path
path
,
InputStream
*
_is
)
Bzip2ArchiveFile
(
Path
path
,
InputStream
Ptr
&&
_is
)
:
ArchiveFile
(
bz2_archive_plugin
),
name
(
path
.
GetBase
().
c_str
()),
istream
(
_is
)
{
istream
(
std
::
move
(
_is
)
)
{
// remove .bz2 suffix
const
size_t
len
=
name
.
length
();
if
(
len
>
4
)
name
.
erase
(
len
-
4
);
}
~
Bzip2ArchiveFile
()
{
delete
istream
;
}
void
Ref
()
{
ref
.
Increment
();
}
...
...
@@ -141,11 +137,11 @@ bz2_open(Path pathname, Error &error)
{
static
Mutex
mutex
;
static
Cond
cond
;
InputStream
*
is
=
OpenLocalInputStream
(
pathname
,
mutex
,
cond
,
error
);
auto
is
=
OpenLocalInputStream
(
pathname
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
return
nullptr
;
return
new
Bzip2ArchiveFile
(
pathname
,
is
);
return
new
Bzip2ArchiveFile
(
pathname
,
std
::
move
(
is
)
);
}
/* single archive handling */
...
...
src/decoder/DecoderAPI.cxx
View file @
cadc67ea
...
...
@@ -256,7 +256,7 @@ void decoder_seek_error(Decoder & decoder)
decoder_command_finished
(
decoder
);
}
InputStream
*
InputStream
Ptr
decoder_open_uri
(
Decoder
&
decoder
,
const
char
*
uri
,
Error
&
error
)
{
assert
(
decoder
.
dc
.
state
==
DecoderState
::
START
||
...
...
@@ -266,8 +266,8 @@ decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
Mutex
&
mutex
=
dc
.
mutex
;
Cond
&
cond
=
dc
.
cond
;
InputStream
*
is
=
InputStream
::
Open
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
auto
is
=
InputStream
::
Open
(
uri
,
mutex
,
cond
,
error
);
if
(
!
is
)
return
nullptr
;
mutex
.
lock
();
...
...
@@ -280,7 +280,6 @@ decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
if
(
dc
.
command
==
DecoderCommand
::
STOP
)
{
mutex
.
unlock
();
delete
is
;
return
nullptr
;
}
...
...
src/decoder/DecoderAPI.hxx
View file @
cadc67ea
...
...
@@ -30,6 +30,7 @@
// IWYU pragma: begin_exports
#include "check.h"
#include "input/Ptr.hxx"
#include "DecoderCommand.hxx"
#include "DecoderPlugin.hxx"
#include "ReplayGainInfo.hxx"
...
...
@@ -116,7 +117,7 @@ decoder_seek_error(Decoder &decoder);
* cancelled by DecoderCommand::STOP (returns nullptr without setting
* #Error).
*/
InputStream
*
InputStream
Ptr
decoder_open_uri
(
Decoder
&
decoder
,
const
char
*
uri
,
Error
&
error
);
/**
...
...
src/decoder/plugins/WavpackDecoderPlugin.cxx
View file @
cadc67ea
...
...
@@ -486,13 +486,13 @@ wavpack_open_wvc(Decoder &decoder, const char *uri)
char
*
wvc_url
=
xstrcatdup
(
uri
,
"c"
);
InputStream
*
is_wvc
=
decoder_open_uri
(
decoder
,
uri
,
IgnoreError
());
auto
is_wvc
=
decoder_open_uri
(
decoder
,
uri
,
IgnoreError
());
free
(
wvc_url
);
if
(
is_wvc
==
nullptr
)
return
nullptr
;
return
new
WavpackInput
(
decoder
,
*
is_wvc
);
return
new
WavpackInput
(
decoder
,
*
is_wvc
.
release
()
);
}
/*
...
...
src/input/InputStream.hxx
View file @
cadc67ea
...
...
@@ -22,6 +22,7 @@
#include "check.h"
#include "Offset.hxx"
#include "Ptr.hxx"
#include "thread/Mutex.hxx"
#include "Compiler.h"
...
...
@@ -123,18 +124,17 @@ public:
* @return an #InputStream object on success, nullptr on error
*/
gcc_nonnull_all
gcc_malloc
static
InputStream
*
Open
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
static
InputStreamPtr
Open
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
/**
* Just like Open(), but waits for the stream to become ready.
* It is a wrapper for Open(), WaitReady() and Check().
*/
gcc_
malloc
gcc_
nonnull_all
static
InputStream
*
OpenReady
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
gcc_nonnull_all
static
InputStream
Ptr
OpenReady
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
/**
* The absolute URI which was used to open this stream.
...
...
src/input/LocalOpen.cxx
View file @
cadc67ea
...
...
@@ -35,19 +35,19 @@
#include <errno.h>
#endif
InputStream
*
InputStream
Ptr
OpenLocalInputStream
(
Path
path
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
{
assert
(
!
error
.
IsDefined
());
InputStream
*
is
=
OpenFileInputStream
(
path
,
mutex
,
cond
,
error
);
InputStream
Ptr
is
(
OpenFileInputStream
(
path
,
mutex
,
cond
,
error
)
);
#ifdef ENABLE_ARCHIVE
if
(
is
==
nullptr
&&
error
.
IsDomain
(
errno_domain
)
&&
error
.
GetCode
()
==
ENOTDIR
)
{
/* ENOTDIR means this may be a path inside an archive
file */
Error
error2
;
is
=
OpenArchiveInputStream
(
path
,
mutex
,
cond
,
error2
);
is
.
reset
(
OpenArchiveInputStream
(
path
,
mutex
,
cond
,
error2
)
);
if
(
is
==
nullptr
&&
error2
.
IsDefined
())
error
=
std
::
move
(
error2
);
}
...
...
src/input/LocalOpen.hxx
View file @
cadc67ea
...
...
@@ -21,8 +21,8 @@
#define MPD_INPUT_LOCAL_OPEN_HXX
#include "check.h"
#include "Ptr.hxx"
class
InputStream
;
class
Path
;
class
Mutex
;
class
Cond
;
...
...
@@ -32,7 +32,7 @@ class Error;
* Open a "local" file. This is a wrapper for the input plugins
* "file" and "archive".
*/
InputStream
*
InputStream
Ptr
OpenLocalInputStream
(
Path
path
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
#endif
src/input/Open.cxx
View file @
cadc67ea
...
...
@@ -30,7 +30,7 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
InputStream
*
InputStream
Ptr
InputStream
::
Open
(
const
char
*
url
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
...
...
@@ -51,7 +51,7 @@ InputStream::Open(const char *url,
if
(
is
!=
nullptr
)
{
is
=
input_rewind_open
(
is
);
return
is
;
return
InputStreamPtr
(
is
)
;
}
else
if
(
error
.
IsDefined
())
return
nullptr
;
}
...
...
@@ -60,12 +60,12 @@ InputStream::Open(const char *url,
return
nullptr
;
}
InputStream
*
InputStream
Ptr
InputStream
::
OpenReady
(
const
char
*
uri
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
{
InputStream
*
is
=
Open
(
uri
,
mutex
,
cond
,
error
);
auto
is
=
Open
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
return
nullptr
;
...
...
@@ -74,10 +74,8 @@ InputStream::OpenReady(const char *uri,
bool
success
=
is
->
Check
(
error
);
mutex
.
unlock
();
if
(
!
success
)
{
delete
is
;
is
=
nullptr
;
}
if
(
!
success
)
is
.
reset
();
return
is
;
}
src/input/Ptr.hxx
0 → 100644
View file @
cadc67ea
/*
* Copyright (C) 2003-2015 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_INPUT_STREAM_PTR_HXX
#define MPD_INPUT_STREAM_PTR_HXX
#include <memory>
class
InputStream
;
typedef
std
::
unique_ptr
<
InputStream
>
InputStreamPtr
;
#endif
src/playlist/PlaylistStream.cxx
View file @
cadc67ea
...
...
@@ -44,7 +44,7 @@ try {
return
nullptr
;
Error
error
;
InputStream
*
is
=
OpenLocalInputStream
(
path
,
mutex
,
cond
,
error
);
auto
is
=
OpenLocalInputStream
(
path
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
{
LogError
(
error
);
return
nullptr
;
...
...
@@ -53,9 +53,7 @@ try {
auto
playlist
=
playlist_list_open_stream_suffix
(
*
is
,
suffix_utf8
.
c_str
());
if
(
playlist
!=
nullptr
)
playlist
=
new
CloseSongEnumerator
(
playlist
,
is
);
else
delete
is
;
playlist
=
new
CloseSongEnumerator
(
playlist
,
is
.
release
());
return
playlist
;
}
catch
(
const
std
::
runtime_error
&
e
)
{
...
...
@@ -91,7 +89,7 @@ try {
return
playlist
;
Error
error
;
InputStream
*
is
=
InputStream
::
OpenReady
(
uri
,
mutex
,
cond
,
error
);
auto
is
=
InputStream
::
OpenReady
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
nullptr
)
{
if
(
error
.
IsDefined
())
FormatError
(
error
,
"Failed to open %s"
,
uri
);
...
...
@@ -100,12 +98,10 @@ try {
}
playlist
=
playlist_list_open_stream
(
*
is
,
uri
);
if
(
playlist
==
nullptr
)
{
delete
is
;
if
(
playlist
==
nullptr
)
return
nullptr
;
}
return
new
CloseSongEnumerator
(
playlist
,
is
);
return
new
CloseSongEnumerator
(
playlist
,
is
.
release
()
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
LogError
(
e
);
return
nullptr
;
...
...
src/playlist/plugins/SoundCloudPlaylistPlugin.cxx
View file @
cadc67ea
...
...
@@ -234,8 +234,8 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
Mutex
&
mutex
,
Cond
&
cond
)
{
Error
error
;
InputStream
*
input_stream
=
InputStream
::
OpenReady
(
url
,
mutex
,
cond
,
error
);
auto
input_stream
=
InputStream
::
OpenReady
(
url
,
mutex
,
cond
,
error
);
if
(
input_stream
==
nullptr
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
...
...
@@ -260,7 +260,6 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
done
=
true
;
}
else
{
mutex
.
unlock
();
delete
input_stream
;
return
-
1
;
}
}
...
...
@@ -279,7 +278,6 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
}
mutex
.
unlock
();
delete
input_stream
;
return
0
;
}
...
...
test/FakeDecoderAPI.cxx
View file @
cadc67ea
...
...
@@ -72,7 +72,7 @@ decoder_seek_error(gcc_unused Decoder &decoder)
{
}
InputStream
*
InputStream
Ptr
decoder_open_uri
(
Decoder
&
decoder
,
const
char
*
uri
,
Error
&
error
)
{
return
InputStream
::
OpenReady
(
uri
,
decoder
.
mutex
,
decoder
.
cond
,
error
);
...
...
test/dump_playlist.cxx
View file @
cadc67ea
...
...
@@ -50,7 +50,6 @@ tag_save(FILE *file, const Tag &tag)
int
main
(
int
argc
,
char
**
argv
)
try
{
const
char
*
uri
;
InputStream
*
is
=
NULL
;
if
(
argc
!=
3
)
{
fprintf
(
stderr
,
"Usage: dump_playlist CONFIG URI
\n
"
);
...
...
@@ -82,12 +81,13 @@ try {
Mutex
mutex
;
Cond
cond
;
InputStreamPtr
is
;
auto
playlist
=
playlist_list_open_uri
(
uri
,
mutex
,
cond
);
if
(
playlist
==
NULL
)
{
/* open the stream and wait until it becomes ready */
is
=
InputStream
::
OpenReady
(
uri
,
mutex
,
cond
,
error
);
if
(
is
==
NULL
)
{
if
(
!
is
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
...
...
@@ -100,7 +100,6 @@ try {
playlist
=
playlist_list_open_stream
(
*
is
,
uri
);
if
(
playlist
==
NULL
)
{
delete
is
;
fprintf
(
stderr
,
"Failed to open playlist
\n
"
);
return
2
;
}
...
...
@@ -132,7 +131,7 @@ try {
/* deinitialize everything */
delete
playlist
;
delete
is
;
is
.
reset
()
;
decoder_plugin_deinit_all
();
playlist_list_global_finish
();
...
...
test/dump_text_file.cxx
View file @
cadc67ea
...
...
@@ -92,19 +92,20 @@ int main(int argc, char **argv)
/* open the stream and dump it */
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
,
error
);
if
(
is
!=
NULL
)
{
ret
=
dump_input_stream
(
*
is
);
delete
is
;
}
else
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
fprintf
(
stderr
,
"input_stream::Open() failed
\n
"
);
ret
=
EXIT_FAILURE
;
{
Mutex
mutex
;
Cond
cond
;
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
,
error
);
if
(
is
)
{
ret
=
dump_input_stream
(
*
is
);
}
else
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
fprintf
(
stderr
,
"input_stream::Open() failed
\n
"
);
ret
=
EXIT_FAILURE
;
}
}
/* deinitialize everything */
...
...
test/read_tags.cxx
View file @
cadc67ea
...
...
@@ -107,16 +107,15 @@ int main(int argc, char **argv)
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
OpenReady
(
path
.
c_str
(),
mutex
,
cond
,
error
);
if
(
is
==
NULL
)
{
auto
is
=
InputStream
::
OpenReady
(
path
.
c_str
(),
mutex
,
cond
,
error
);
if
(
!
is
)
{
FormatError
(
error
,
"Failed to open %s"
,
path
.
c_str
());
return
EXIT_FAILURE
;
}
success
=
plugin
->
ScanStream
(
*
is
,
print_handler
,
nullptr
);
delete
is
;
}
decoder_plugin_deinit_all
();
...
...
test/run_decoder.cxx
View file @
cadc67ea
...
...
@@ -64,10 +64,9 @@ int main(int argc, char **argv)
if
(
plugin
->
file_decode
!=
nullptr
)
{
plugin
->
FileDecode
(
decoder
,
Path
::
FromFS
(
uri
));
}
else
if
(
plugin
->
stream_decode
!=
nullptr
)
{
InputStream
*
is
=
InputStream
::
OpenReady
(
uri
,
decoder
.
mutex
,
decoder
.
cond
,
error
);
if
(
is
==
NULL
)
{
auto
is
=
InputStream
::
OpenReady
(
uri
,
decoder
.
mutex
,
decoder
.
cond
,
error
);
if
(
!
is
)
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
...
...
@@ -77,8 +76,6 @@ int main(int argc, char **argv)
}
plugin
->
StreamDecode
(
decoder
,
*
is
);
delete
is
;
}
else
{
fprintf
(
stderr
,
"Decoder plugin is not usable
\n
"
);
return
EXIT_FAILURE
;
...
...
test/run_input.cxx
View file @
cadc67ea
...
...
@@ -118,20 +118,20 @@ int main(int argc, char **argv)
/* open the stream and dump it */
Mutex
mutex
;
Cond
cond
;
InputStream
*
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
,
error
);
int
ret
;
if
(
is
!=
NULL
)
{
ret
=
dump_input_stream
(
is
);
delete
is
;
}
else
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
fprintf
(
stderr
,
"input_stream::Open() failed
\n
"
);
ret
=
EXIT_FAILURE
;
{
Mutex
mutex
;
Cond
cond
;
auto
is
=
InputStream
::
OpenReady
(
argv
[
1
],
mutex
,
cond
,
error
);
if
(
is
)
{
ret
=
dump_input_stream
(
is
.
get
());
}
else
{
if
(
error
.
IsDefined
())
LogError
(
error
);
else
fprintf
(
stderr
,
"input_stream::Open() failed
\n
"
);
ret
=
EXIT_FAILURE
;
}
}
/* deinitialize everything */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment