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