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
fb9a2c54
Commit
fb9a2c54
authored
Dec 26, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/Icy: manage the parser in a std::shared_ptr
This resolves the circular dependency between IcyInputStream and CurlInputStream.
parent
cd38aa3b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
20 deletions
+34
-20
IcyInputStream.cxx
src/input/IcyInputStream.cxx
+14
-4
IcyInputStream.hxx
src/input/IcyInputStream.hxx
+12
-10
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+8
-6
No files found.
src/input/IcyInputStream.cxx
View file @
fb9a2c54
...
...
@@ -19,15 +19,25 @@
#include "config.h"
#include "IcyInputStream.hxx"
#include "IcyMetaDataParser.hxx"
#include "tag/Tag.hxx"
IcyInputStream
::
IcyInputStream
(
InputStream
*
_input
)
noexcept
:
ProxyInputStream
(
_input
)
IcyInputStream
::
IcyInputStream
(
InputStream
*
_input
,
std
::
shared_ptr
<
IcyMetaDataParser
>
_parser
)
noexcept
:
ProxyInputStream
(
_input
),
parser
(
std
::
move
(
_parser
))
{
}
IcyInputStream
::~
IcyInputStream
()
noexcept
=
default
;
inline
bool
IcyInputStream
::
IsEnabled
()
const
noexcept
{
assert
(
parser
);
return
parser
->
IsDefined
();
}
void
IcyInputStream
::
Update
()
noexcept
{
...
...
@@ -48,7 +58,7 @@ IcyInputStream::ReadTag()
if
(
new_input_tag
!=
nullptr
)
input_tag
=
std
::
move
(
new_input_tag
);
auto
new_icy_tag
=
parser
.
ReadTag
();
auto
new_icy_tag
=
parser
->
ReadTag
();
const
bool
had_new_icy_tag
=
!!
new_icy_tag
;
if
(
new_icy_tag
!=
nullptr
)
icy_tag
=
std
::
move
(
new_icy_tag
);
...
...
@@ -81,7 +91,7 @@ IcyInputStream::Read(void *ptr, size_t read_size)
if
(
nbytes
==
0
)
return
0
;
size_t
result
=
parser
.
ParseInPlace
(
ptr
,
nbytes
);
size_t
result
=
parser
->
ParseInPlace
(
ptr
,
nbytes
);
if
(
result
>
0
)
{
override_offset
+=
result
;
offset
=
override_offset
;
...
...
src/input/IcyInputStream.hxx
View file @
fb9a2c54
...
...
@@ -21,18 +21,18 @@
#define MPD_ICY_INPUT_STREAM_HXX
#include "ProxyInputStream.hxx"
#include "IcyMetaDataParser.hxx"
#include "Compiler.h"
#include <memory>
struct
Tag
;
class
IcyMetaDataParser
;
/**
* An #InputStream filter that parses Icy metadata.
*/
class
IcyInputStream
final
:
public
ProxyInputStream
{
IcyMetaDataParser
parser
;
std
::
shared_ptr
<
IcyMetaDataParser
>
parser
;
/**
* The #Tag object ready to be requested via ReadTag().
...
...
@@ -47,19 +47,21 @@ class IcyInputStream final : public ProxyInputStream {
offset_type
override_offset
=
0
;
public
:
IcyInputStream
(
InputStream
*
_input
)
noexcept
;
/**
* @param _parser a IcyMetaDataParser instance which is shared
* with our input; it needs to be shared because our input
* needs to feed parameters (e.g. from the "icy-metaint"
* header) into it
*/
IcyInputStream
(
InputStream
*
_input
,
std
::
shared_ptr
<
IcyMetaDataParser
>
_parser
)
noexcept
;
virtual
~
IcyInputStream
()
noexcept
;
IcyInputStream
(
const
IcyInputStream
&
)
=
delete
;
IcyInputStream
&
operator
=
(
const
IcyInputStream
&
)
=
delete
;
void
Enable
(
size_t
_data_size
)
noexcept
{
parser
.
Start
(
_data_size
);
}
bool
IsEnabled
()
const
noexcept
{
return
parser
.
IsDefined
();
}
gcc_pure
bool
IsEnabled
()
const
noexcept
;
/* virtual methods from InputStream */
void
Update
()
noexcept
override
;
...
...
src/input/plugins/CurlInputPlugin.cxx
View file @
fb9a2c54
...
...
@@ -27,6 +27,7 @@
#include "lib/curl/Slist.hxx"
#include "../AsyncInputStream.hxx"
#include "../IcyInputStream.hxx"
#include "IcyMetaDataParser.hxx"
#include "../InputPlugin.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/Block.hxx"
...
...
@@ -72,14 +73,14 @@ struct CurlInputStream final : public AsyncInputStream, CurlResponseHandler {
CurlRequest
*
request
=
nullptr
;
/** parser for icy-metadata */
IcyInputStream
*
icy
;
std
::
shared_ptr
<
IcyMetaDataParser
>
icy
;
CurlInputStream
(
EventLoop
&
event_loop
,
const
char
*
_url
,
Mutex
&
_mutex
,
Cond
&
_cond
)
:
AsyncInputStream
(
event_loop
,
_url
,
_mutex
,
_cond
,
CURL_MAX_BUFFERED
,
CURL_RESUME_AT
),
icy
(
new
Icy
InputStream
(
this
))
{
icy
(
new
Icy
MetaDataParser
(
))
{
}
~
CurlInputStream
();
...
...
@@ -199,7 +200,7 @@ CurlInputStream::OnHeaders(unsigned status,
return
;
}
if
(
!
icy
->
Is
Enabl
ed
()
&&
if
(
!
icy
->
Is
Defin
ed
()
&&
headers
.
find
(
"accept-ranges"
)
!=
headers
.
end
())
/* a stream with icy-metadata is not seekable */
seekable
=
true
;
...
...
@@ -226,7 +227,7 @@ CurlInputStream::OnHeaders(unsigned status,
SetTag
(
tag_builder
.
CommitNew
());
}
if
(
!
icy
->
Is
Enabl
ed
())
{
if
(
!
icy
->
Is
Defin
ed
())
{
i
=
headers
.
find
(
"icy-metaint"
);
if
(
i
!=
headers
.
end
())
{
...
...
@@ -237,7 +238,7 @@ CurlInputStream::OnHeaders(unsigned status,
#endif
if
(
icy_metaint
>
0
)
{
icy
->
Enable
(
icy_metaint
);
icy
->
Start
(
icy_metaint
);
/* a stream with icy-metadata is not
seekable */
...
...
@@ -450,7 +451,8 @@ CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
throw
;
}
return
c
->
icy
;
auto
icy
=
c
->
icy
;
return
new
IcyInputStream
(
c
,
std
::
move
(
icy
));
}
static
InputStream
*
...
...
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