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
73e69eda
Commit
73e69eda
authored
Dec 20, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/InputStream: ReadTag() returns std::unique_ptr<Tag>
parent
4c4fa682
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
41 additions
and
37 deletions
+41
-37
Bridge.cxx
src/decoder/Bridge.cxx
+1
-1
AsyncInputStream.cxx
src/input/AsyncInputStream.cxx
+9
-5
AsyncInputStream.hxx
src/input/AsyncInputStream.hxx
+4
-7
IcyInputStream.cxx
src/input/IcyInputStream.cxx
+8
-7
IcyInputStream.hxx
src/input/IcyInputStream.hxx
+1
-1
InputStream.cxx
src/input/InputStream.cxx
+3
-2
InputStream.hxx
src/input/InputStream.hxx
+5
-6
ProxyInputStream.cxx
src/input/ProxyInputStream.cxx
+2
-1
ProxyInputStream.hxx
src/input/ProxyInputStream.hxx
+1
-1
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+1
-1
run_input.cxx
test/run_input.cxx
+6
-5
No files found.
src/decoder/Bridge.cxx
View file @
73e69eda
...
...
@@ -223,7 +223,7 @@ bool
DecoderBridge
::
UpdateStreamTag
(
InputStream
*
is
)
{
auto
*
tag
=
is
!=
nullptr
?
is
->
LockReadTag
()
?
is
->
LockReadTag
()
.
release
()
:
nullptr
;
if
(
tag
==
nullptr
)
{
tag
=
song_tag
;
...
...
src/input/AsyncInputStream.cxx
View file @
73e69eda
...
...
@@ -45,15 +45,19 @@ AsyncInputStream::AsyncInputStream(EventLoop &event_loop, const char *_url,
AsyncInputStream
::~
AsyncInputStream
()
{
delete
tag
;
buffer
.
Clear
();
}
void
AsyncInputStream
::
SetTag
(
Tag
*
_tag
)
noexcept
AsyncInputStream
::
SetTag
(
std
::
unique_ptr
<
Tag
>
_tag
)
noexcept
{
tag
=
std
::
move
(
_tag
);
}
void
AsyncInputStream
::
ClearTag
()
noexcept
{
delete
std
::
exchange
(
tag
,
_tag
);
tag
.
reset
(
);
}
void
...
...
@@ -151,7 +155,7 @@ AsyncInputStream::SeekDone() noexcept
cond
.
broadcast
();
}
Tag
*
std
::
unique_ptr
<
Tag
>
AsyncInputStream
::
ReadTag
()
{
return
std
::
exchange
(
tag
,
nullptr
);
...
...
src/input/AsyncInputStream.hxx
View file @
73e69eda
...
...
@@ -61,7 +61,7 @@ class AsyncInputStream : public InputStream {
* The #Tag object ready to be requested via
* InputStream::ReadTag().
*/
Tag
*
tag
=
nullptr
;
std
::
unique_ptr
<
Tag
>
tag
;
offset_type
seek_offset
;
...
...
@@ -84,7 +84,7 @@ public:
void
Check
()
final
;
bool
IsEOF
()
noexcept
final
;
void
Seek
(
offset_type
new_offset
)
final
;
Tag
*
ReadTag
()
final
;
std
::
unique_ptr
<
Tag
>
ReadTag
()
final
;
bool
IsAvailable
()
noexcept
final
;
size_t
Read
(
void
*
ptr
,
size_t
read_size
)
final
;
...
...
@@ -92,11 +92,8 @@ protected:
/**
* Pass an tag from the I/O thread to the client thread.
*/
void
SetTag
(
Tag
*
_tag
)
noexcept
;
void
ClearTag
()
noexcept
{
SetTag
(
nullptr
);
}
void
SetTag
(
std
::
unique_ptr
<
Tag
>
_tag
)
noexcept
;
void
ClearTag
()
noexcept
;
void
Pause
()
noexcept
;
...
...
src/input/IcyInputStream.cxx
View file @
73e69eda
...
...
@@ -38,22 +38,23 @@ IcyInputStream::Update()
offset
=
override_offset
;
}
Tag
*
std
::
unique_ptr
<
Tag
>
IcyInputStream
::
ReadTag
()
{
Tag
*
new_input_tag
=
ProxyInputStream
::
ReadTag
();
auto
new_input_tag
=
ProxyInputStream
::
ReadTag
();
if
(
!
IsEnabled
())
return
new_input_tag
;
const
bool
had_new_input_tag
=
!!
new_input_tag
;
if
(
new_input_tag
!=
nullptr
)
input_tag
.
reset
(
new_input_tag
);
input_tag
=
std
::
move
(
new_input_tag
);
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
);
if
(
new_input_tag
==
nullptr
&&
!
had_new_icy_tag
)
if
(
!
had_new_input_tag
&&
!
had_new_icy_tag
)
/* no change */
return
nullptr
;
...
...
@@ -62,12 +63,12 @@ IcyInputStream::ReadTag()
return
nullptr
;
if
(
input_tag
==
nullptr
)
return
new
Tag
(
*
icy_tag
);
return
std
::
make_unique
<
Tag
>
(
*
icy_tag
);
if
(
icy_tag
==
nullptr
)
return
new
Tag
(
*
input_tag
);
return
std
::
make_unique
<
Tag
>
(
*
input_tag
);
return
Tag
::
Merge
(
*
input_tag
,
*
icy_tag
)
.
release
()
;
return
Tag
::
Merge
(
*
input_tag
,
*
icy_tag
);
}
size_t
...
...
src/input/IcyInputStream.hxx
View file @
73e69eda
...
...
@@ -63,7 +63,7 @@ public:
/* virtual methods from InputStream */
void
Update
()
override
;
Tag
*
ReadTag
()
override
;
std
::
unique_ptr
<
Tag
>
ReadTag
()
override
;
size_t
Read
(
void
*
ptr
,
size_t
size
)
override
;
};
...
...
src/input/InputStream.cxx
View file @
73e69eda
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "InputStream.hxx"
#include "tag/Tag.hxx"
#include "thread/Cond.hxx"
#include "util/StringCompare.hxx"
...
...
@@ -107,13 +108,13 @@ InputStream::LockSkip(offset_type _offset)
Skip
(
_offset
);
}
Tag
*
std
::
unique_ptr
<
Tag
>
InputStream
::
ReadTag
()
{
return
nullptr
;
}
Tag
*
std
::
unique_ptr
<
Tag
>
InputStream
::
LockReadTag
()
{
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
...
...
src/input/InputStream.hxx
View file @
73e69eda
...
...
@@ -27,6 +27,7 @@
#include "Compiler.h"
#include <string>
#include <memory>
#include <assert.h>
...
...
@@ -322,18 +323,16 @@ public:
*
* The caller must lock the mutex.
*
* @return a tag object
which must be freed by the caller, or
*
nullptr if the tag has not changed
since the last call
* @return a tag object
or nullptr if the tag has not changed
* since the last call
*/
gcc_malloc
virtual
Tag
*
ReadTag
();
virtual
std
::
unique_ptr
<
Tag
>
ReadTag
();
/**
* Wrapper for ReadTag() which locks and unlocks the mutex;
* the caller must not be holding it already.
*/
gcc_malloc
Tag
*
LockReadTag
();
std
::
unique_ptr
<
Tag
>
LockReadTag
();
/**
* Returns true if the next read operation will not block: either data
...
...
src/input/ProxyInputStream.cxx
View file @
73e69eda
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "ProxyInputStream.hxx"
#include "tag/Tag.hxx"
ProxyInputStream
::
ProxyInputStream
(
InputStream
*
_input
)
:
InputStream
(
_input
->
GetURI
(),
_input
->
mutex
,
_input
->
cond
),
...
...
@@ -75,7 +76,7 @@ ProxyInputStream::IsEOF() noexcept
return
input
.
IsEOF
();
}
Tag
*
std
::
unique_ptr
<
Tag
>
ProxyInputStream
::
ReadTag
()
{
return
input
.
ReadTag
();
...
...
src/input/ProxyInputStream.hxx
View file @
73e69eda
...
...
@@ -47,7 +47,7 @@ public:
void
Update
()
override
;
void
Seek
(
offset_type
new_offset
)
override
;
bool
IsEOF
()
noexcept
override
;
Tag
*
ReadTag
()
override
;
std
::
unique_ptr
<
Tag
>
ReadTag
()
override
;
bool
IsAvailable
()
noexcept
override
;
size_t
Read
(
void
*
ptr
,
size_t
read_size
)
override
;
...
...
src/input/plugins/CurlInputPlugin.cxx
View file @
73e69eda
...
...
@@ -223,7 +223,7 @@ CurlInputStream::OnHeaders(unsigned status,
TagBuilder
tag_builder
;
tag_builder
.
AddItem
(
TAG_NAME
,
i
->
second
.
c_str
());
SetTag
(
tag_builder
.
CommitNew
()
.
release
()
);
SetTag
(
tag_builder
.
CommitNew
());
}
if
(
!
icy
->
IsEnabled
())
{
...
...
test/run_input.cxx
View file @
73e69eda
...
...
@@ -82,11 +82,12 @@ dump_input_stream(InputStream *is)
/* read data and tags from the stream */
while
(
!
is
->
IsEOF
())
{
Tag
*
tag
=
is
->
ReadTag
();
if
(
tag
!=
NULL
)
{
fprintf
(
stderr
,
"Received a tag:
\n
"
);
tag_save
(
stderr
,
*
tag
);
delete
tag
;
{
auto
tag
=
is
->
ReadTag
();
if
(
tag
)
{
fprintf
(
stderr
,
"Received a tag:
\n
"
);
tag_save
(
stderr
,
*
tag
);
}
}
char
buffer
[
4096
];
...
...
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