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
49619fbd
Commit
49619fbd
authored
Dec 26, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/Proxy: use InputStreamPtr
parent
fb9a2c54
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
59 deletions
+50
-59
IcyInputStream.cxx
src/input/IcyInputStream.cxx
+2
-2
IcyInputStream.hxx
src/input/IcyInputStream.hxx
+1
-1
Open.cxx
src/input/Open.cxx
+2
-5
ProxyInputStream.cxx
src/input/ProxyInputStream.cxx
+19
-19
ProxyInputStream.hxx
src/input/ProxyInputStream.hxx
+3
-2
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+7
-12
RewindInputPlugin.cxx
src/input/plugins/RewindInputPlugin.cxx
+11
-12
RewindInputPlugin.hxx
src/input/plugins/RewindInputPlugin.hxx
+3
-4
test_rewind.cxx
test/test_rewind.cxx
+2
-2
No files found.
src/input/IcyInputStream.cxx
View file @
49619fbd
...
...
@@ -22,9 +22,9 @@
#include "IcyMetaDataParser.hxx"
#include "tag/Tag.hxx"
IcyInputStream
::
IcyInputStream
(
InputStream
*
_input
,
IcyInputStream
::
IcyInputStream
(
InputStream
Ptr
_input
,
std
::
shared_ptr
<
IcyMetaDataParser
>
_parser
)
noexcept
:
ProxyInputStream
(
_input
),
parser
(
std
::
move
(
_parser
))
:
ProxyInputStream
(
std
::
move
(
_input
)
),
parser
(
std
::
move
(
_parser
))
{
}
...
...
src/input/IcyInputStream.hxx
View file @
49619fbd
...
...
@@ -53,7 +53,7 @@ public:
* needs to feed parameters (e.g. from the "icy-metaint"
* header) into it
*/
IcyInputStream
(
InputStream
*
_input
,
IcyInputStream
(
InputStream
Ptr
_input
,
std
::
shared_ptr
<
IcyMetaDataParser
>
_parser
)
noexcept
;
virtual
~
IcyInputStream
()
noexcept
;
...
...
src/input/Open.cxx
View file @
49619fbd
...
...
@@ -42,11 +42,8 @@ InputStream::Open(const char *url,
InputStream
*
is
;
is
=
plugin
->
open
(
url
,
mutex
,
cond
);
if
(
is
!=
nullptr
)
{
is
=
input_rewind_open
(
is
);
return
InputStreamPtr
(
is
);
}
if
(
is
!=
nullptr
)
return
input_rewind_open
(
InputStreamPtr
(
is
));
}
throw
std
::
runtime_error
(
"Unrecognized URI"
);
...
...
src/input/ProxyInputStream.cxx
View file @
49619fbd
...
...
@@ -21,77 +21,77 @@
#include "ProxyInputStream.hxx"
#include "tag/Tag.hxx"
ProxyInputStream
::
ProxyInputStream
(
InputStream
*
_input
)
noexcept
ProxyInputStream
::
ProxyInputStream
(
InputStream
Ptr
_input
)
noexcept
:
InputStream
(
_input
->
GetURI
(),
_input
->
mutex
,
_input
->
cond
),
input
(
*
_input
)
{}
ProxyInputStream
::~
ProxyInputStream
()
noexcept
input
(
std
::
move
(
_input
))
{
delete
&
input
;
assert
(
input
)
;
}
ProxyInputStream
::~
ProxyInputStream
()
noexcept
=
default
;
void
ProxyInputStream
::
CopyAttributes
()
{
if
(
input
.
IsReady
())
{
if
(
input
->
IsReady
())
{
if
(
!
IsReady
())
{
if
(
input
.
HasMimeType
())
SetMimeType
(
input
.
GetMimeType
());
if
(
input
->
HasMimeType
())
SetMimeType
(
input
->
GetMimeType
());
size
=
input
.
KnownSize
()
?
input
.
GetSize
()
size
=
input
->
KnownSize
()
?
input
->
GetSize
()
:
UNKNOWN_SIZE
;
seekable
=
input
.
IsSeekable
();
seekable
=
input
->
IsSeekable
();
SetReady
();
}
offset
=
input
.
GetOffset
();
offset
=
input
->
GetOffset
();
}
}
void
ProxyInputStream
::
Check
()
{
input
.
Check
();
input
->
Check
();
}
void
ProxyInputStream
::
Update
()
noexcept
{
input
.
Update
();
input
->
Update
();
CopyAttributes
();
}
void
ProxyInputStream
::
Seek
(
offset_type
new_offset
)
{
input
.
Seek
(
new_offset
);
input
->
Seek
(
new_offset
);
CopyAttributes
();
}
bool
ProxyInputStream
::
IsEOF
()
noexcept
{
return
input
.
IsEOF
();
return
input
->
IsEOF
();
}
std
::
unique_ptr
<
Tag
>
ProxyInputStream
::
ReadTag
()
{
return
input
.
ReadTag
();
return
input
->
ReadTag
();
}
bool
ProxyInputStream
::
IsAvailable
()
noexcept
{
return
input
.
IsAvailable
();
return
input
->
IsAvailable
();
}
size_t
ProxyInputStream
::
Read
(
void
*
ptr
,
size_t
read_size
)
{
size_t
nbytes
=
input
.
Read
(
ptr
,
read_size
);
size_t
nbytes
=
input
->
Read
(
ptr
,
read_size
);
CopyAttributes
();
return
nbytes
;
}
src/input/ProxyInputStream.hxx
View file @
49619fbd
...
...
@@ -21,6 +21,7 @@
#define MPD_PROXY_INPUT_STREAM_HXX
#include "InputStream.hxx"
#include "Ptr.hxx"
struct
Tag
;
...
...
@@ -31,11 +32,11 @@ struct Tag;
*/
class
ProxyInputStream
:
public
InputStream
{
protected
:
InputStream
&
input
;
InputStream
Ptr
input
;
public
:
gcc_nonnull_all
ProxyInputStream
(
InputStream
*
_input
)
noexcept
;
explicit
ProxyInputStream
(
InputStreamPtr
_input
)
noexcept
;
virtual
~
ProxyInputStream
()
noexcept
;
...
...
src/input/plugins/CurlInputPlugin.cxx
View file @
49619fbd
...
...
@@ -438,21 +438,16 @@ CurlInputStream::DoSeek(offset_type new_offset)
inline
InputStream
*
CurlInputStream
::
Open
(
const
char
*
url
,
Mutex
&
mutex
,
Cond
&
cond
)
{
CurlInputStream
*
c
=
new
CurlInputStream
((
*
curl_init
)
->
GetEventLoop
(),
url
,
mutex
,
cond
);
auto
c
=
std
::
make_unique
<
CurlInputStream
>
((
*
curl_init
)
->
GetEventLoop
(),
url
,
mutex
,
cond
);
try
{
BlockingCall
(
c
->
GetEventLoop
(),
[
c
](){
c
->
InitEasy
();
c
->
StartRequest
();
});
}
catch
(...)
{
delete
c
;
throw
;
}
BlockingCall
(
c
->
GetEventLoop
(),
[
&
c
](){
c
->
InitEasy
();
c
->
StartRequest
();
});
auto
icy
=
c
->
icy
;
return
new
IcyInputStream
(
c
,
std
::
move
(
icy
));
return
new
IcyInputStream
(
std
::
move
(
c
)
,
std
::
move
(
icy
));
}
static
InputStream
*
...
...
src/input/plugins/RewindInputPlugin.cxx
View file @
49619fbd
...
...
@@ -47,9 +47,8 @@ class RewindInputStream final : public ProxyInputStream {
char
buffer
[
64
*
1024
];
public
:
RewindInputStream
(
InputStream
*
_input
)
:
ProxyInputStream
(
_input
)
{
}
explicit
RewindInputStream
(
InputStreamPtr
_input
)
:
ProxyInputStream
(
std
::
move
(
_input
))
{}
/* virtual methods from InputStream */
...
...
@@ -71,7 +70,7 @@ private:
* buffer contain more data for the next read operation?
*/
bool
ReadingFromBuffer
()
const
noexcept
{
return
tail
>
0
&&
offset
<
input
.
GetOffset
();
return
tail
>
0
&&
offset
<
input
->
GetOffset
();
}
};
...
...
@@ -82,7 +81,7 @@ RewindInputStream::Read(void *ptr, size_t read_size)
/* buffered read */
assert
(
head
==
(
size_t
)
offset
);
assert
(
tail
==
(
size_t
)
input
.
GetOffset
());
assert
(
tail
==
(
size_t
)
input
->
GetOffset
());
if
(
read_size
>
tail
-
head
)
read_size
=
tail
-
head
;
...
...
@@ -95,9 +94,9 @@ RewindInputStream::Read(void *ptr, size_t read_size)
}
else
{
/* pass method call to underlying stream */
size_t
nbytes
=
input
.
Read
(
ptr
,
read_size
);
size_t
nbytes
=
input
->
Read
(
ptr
,
read_size
);
if
(
input
.
GetOffset
()
>
(
offset_type
)
sizeof
(
buffer
))
if
(
input
->
GetOffset
()
>
(
offset_type
)
sizeof
(
buffer
))
/* disable buffering */
tail
=
0
;
else
if
(
tail
==
(
size_t
)
offset
)
{
...
...
@@ -106,7 +105,7 @@ RewindInputStream::Read(void *ptr, size_t read_size)
memcpy
(
buffer
+
tail
,
ptr
,
nbytes
);
tail
+=
nbytes
;
assert
(
tail
==
(
size_t
)
input
.
GetOffset
());
assert
(
tail
==
(
size_t
)
input
->
GetOffset
());
}
CopyAttributes
();
...
...
@@ -125,7 +124,7 @@ RewindInputStream::Seek(offset_type new_offset)
assert
(
!
ReadingFromBuffer
()
||
head
==
(
size_t
)
offset
);
assert
(
tail
==
(
size_t
)
input
.
GetOffset
());
assert
(
tail
==
(
size_t
)
input
->
GetOffset
());
head
=
(
size_t
)
new_offset
;
offset
=
new_offset
;
...
...
@@ -138,8 +137,8 @@ RewindInputStream::Seek(offset_type new_offset)
}
}
InputStream
*
input_rewind_open
(
InputStream
*
is
)
InputStream
Ptr
input_rewind_open
(
InputStream
Ptr
is
)
{
assert
(
is
!=
nullptr
);
assert
(
!
is
->
IsReady
()
||
is
->
GetOffset
()
==
0
);
...
...
@@ -148,5 +147,5 @@ input_rewind_open(InputStream *is)
/* seekable resources don't need this plugin */
return
is
;
return
new
RewindInputStream
(
is
);
return
InputStreamPtr
(
new
RewindInputStream
(
std
::
move
(
is
))
);
}
src/input/plugins/RewindInputPlugin.hxx
View file @
49619fbd
...
...
@@ -28,10 +28,9 @@
#define MPD_INPUT_REWIND_HXX
#include "check.h"
#include "input/Ptr.hxx"
class
InputStream
;
InputStream
*
input_rewind_open
(
InputStream
*
is
);
InputStreamPtr
input_rewind_open
(
InputStreamPtr
is
);
#endif
test/test_rewind.cxx
View file @
49619fbd
...
...
@@ -61,8 +61,8 @@ public:
"foo bar"
);
CPPUNIT_ASSERT
(
sis
->
IsReady
());
InputStream
*
ris
=
input_rewind_open
(
sis
);
CPPUNIT_ASSERT
(
ris
!=
sis
);
auto
ris
=
input_rewind_open
(
InputStreamPtr
(
sis
)
);
CPPUNIT_ASSERT
(
ris
.
get
()
!=
sis
);
CPPUNIT_ASSERT
(
ris
!=
nullptr
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
...
...
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