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
9f14e7a9
Commit
9f14e7a9
authored
Dec 30, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MusicPipe: add MusicBuffer reference
This tiny amount of overhead allows omitting the MusicBuffer in Clear().
parent
cb412b22
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
34 additions
and
49 deletions
+34
-49
MusicPipe.cxx
src/MusicPipe.cxx
+1
-1
MusicPipe.hxx
src/MusicPipe.hxx
+12
-4
Bridge.cxx
src/decoder/Bridge.cxx
+4
-4
DecoderControl.cxx
src/decoder/DecoderControl.cxx
+1
-2
DecoderControl.hxx
src/decoder/DecoderControl.hxx
+1
-5
DecoderThread.cxx
src/decoder/DecoderThread.cxx
+1
-1
MultipleOutputs.cxx
src/output/MultipleOutputs.cxx
+7
-20
MultipleOutputs.hxx
src/output/MultipleOutputs.hxx
+0
-5
Thread.cxx
src/player/Thread.cxx
+7
-7
No files found.
src/MusicPipe.cxx
View file @
9f14e7a9
...
...
@@ -73,7 +73,7 @@ MusicPipe::Shift() noexcept
}
void
MusicPipe
::
Clear
(
MusicBuffer
&
buffer
)
noexcept
MusicPipe
::
Clear
()
noexcept
{
MusicChunk
*
chunk
;
...
...
src/MusicPipe.hxx
View file @
9f14e7a9
...
...
@@ -37,6 +37,11 @@ class MusicBuffer;
* tail, and the other consumes them from the head.
*/
class
MusicPipe
{
/**
* The #MusicBuffer where all chunks must be returned.
*/
MusicBuffer
&
buffer
;
/** the first chunk */
MusicChunk
*
head
=
nullptr
;
...
...
@@ -57,7 +62,8 @@ public:
/**
* Creates a new #MusicPipe object. It is empty.
*/
MusicPipe
()
=
default
;
explicit
MusicPipe
(
MusicBuffer
&
_buffer
)
noexcept
:
buffer
(
_buffer
)
{}
MusicPipe
(
const
MusicPipe
&
)
=
delete
;
...
...
@@ -71,6 +77,10 @@ public:
MusicPipe
&
operator
=
(
const
MusicPipe
&
)
=
delete
;
MusicBuffer
&
GetBuffer
()
noexcept
{
return
buffer
;
}
#ifndef NDEBUG
/**
* Checks if the audio format if the chunk is equal to the specified
...
...
@@ -106,10 +116,8 @@ public:
/**
* Clears the whole pipe and returns the chunks to the buffer.
*
* @param buffer the buffer object to return the chunks to
*/
void
Clear
(
MusicBuffer
&
buffer
)
noexcept
;
void
Clear
()
noexcept
;
/**
* Pushes a chunk to the tail of the pipe.
...
...
src/decoder/Bridge.cxx
View file @
9f14e7a9
...
...
@@ -98,7 +98,7 @@ DecoderBridge::GetChunk() noexcept
return
current_chunk
;
do
{
current_chunk
=
dc
.
buffer
->
Allocate
();
current_chunk
=
dc
.
pipe
->
GetBuffer
().
Allocate
();
if
(
current_chunk
!=
nullptr
)
{
current_chunk
->
replay_gain_serial
=
replay_gain_serial
;
if
(
replay_gain_serial
!=
0
)
...
...
@@ -123,7 +123,7 @@ DecoderBridge::FlushChunk()
auto
*
chunk
=
std
::
exchange
(
current_chunk
,
nullptr
);
if
(
chunk
->
IsEmpty
())
dc
.
buffer
->
Return
(
chunk
);
dc
.
pipe
->
GetBuffer
().
Return
(
chunk
);
else
dc
.
pipe
->
Push
(
chunk
);
...
...
@@ -303,11 +303,11 @@ DecoderBridge::CommandFinished()
/* delete frames from the old song position */
if
(
current_chunk
!=
nullptr
)
{
dc
.
buffer
->
Return
(
current_chunk
);
dc
.
pipe
->
GetBuffer
().
Return
(
current_chunk
);
current_chunk
=
nullptr
;
}
dc
.
pipe
->
Clear
(
*
dc
.
buffer
);
dc
.
pipe
->
Clear
();
if
(
convert
!=
nullptr
)
convert
->
Reset
();
...
...
src/decoder/DecoderControl.cxx
View file @
9f14e7a9
...
...
@@ -92,7 +92,7 @@ DecoderControl::IsCurrentSong(const DetachedSong &_song) const noexcept
void
DecoderControl
::
Start
(
std
::
unique_ptr
<
DetachedSong
>
_song
,
SongTime
_start_time
,
SongTime
_end_time
,
Music
Buffer
&
_buffer
,
Music
Pipe
&
_pipe
)
noexcept
MusicPipe
&
_pipe
)
noexcept
{
assert
(
_song
!=
nullptr
);
assert
(
_pipe
.
IsEmpty
());
...
...
@@ -100,7 +100,6 @@ DecoderControl::Start(std::unique_ptr<DetachedSong> _song,
song
=
std
::
move
(
_song
);
start_time
=
_start_time
;
end_time
=
_end_time
;
buffer
=
&
_buffer
;
pipe
=
&
_pipe
;
ClearError
();
...
...
src/decoder/DecoderControl.hxx
View file @
9f14e7a9
...
...
@@ -44,7 +44,6 @@
#endif
class
DetachedSong
;
class
MusicBuffer
;
class
MusicPipe
;
enum
class
DecoderState
:
uint8_t
{
...
...
@@ -152,9 +151,6 @@ struct DecoderControl final : InputStreamHandler {
SignedSongTime
total_time
;
/** the #MusicChunk allocator */
MusicBuffer
*
buffer
;
/**
* The destination pipe for decoded chunks. The caller thread
* owns this object, and is responsible for freeing it.
...
...
@@ -383,7 +379,7 @@ public:
*/
void
Start
(
std
::
unique_ptr
<
DetachedSong
>
song
,
SongTime
start_time
,
SongTime
end_time
,
Music
Buffer
&
buffer
,
Music
Pipe
&
pipe
)
noexcept
;
MusicPipe
&
pipe
)
noexcept
;
/**
* Caller must lock the object.
...
...
src/decoder/DecoderThread.cxx
View file @
9f14e7a9
...
...
@@ -551,7 +551,7 @@ DecoderControl::RunThread() noexcept
/* we need to clear the pipe here; usually the
PlayerThread is responsible, but it is not
aware that the decoder has finished */
pipe
->
Clear
(
*
buffer
);
pipe
->
Clear
();
decoder_run
(
*
this
);
break
;
...
...
src/output/MultipleOutputs.cxx
View file @
9f14e7a9
...
...
@@ -207,7 +207,6 @@ MultipleOutputs::SetReplayGainMode(ReplayGainMode mode) noexcept
void
MultipleOutputs
::
Play
(
MusicChunk
*
chunk
)
{
assert
(
buffer
!=
nullptr
);
assert
(
pipe
!=
nullptr
);
assert
(
chunk
!=
nullptr
);
assert
(
chunk
->
CheckFormat
(
input_audio_format
));
...
...
@@ -224,21 +223,18 @@ MultipleOutputs::Play(MusicChunk *chunk)
void
MultipleOutputs
::
Open
(
const
AudioFormat
audio_format
,
MusicBuffer
&
_
buffer
)
MusicBuffer
&
buffer
)
{
bool
ret
=
false
,
enabled
=
false
;
assert
(
buffer
==
nullptr
||
buffer
==
&
_buffer
);
assert
((
pipe
==
nullptr
)
==
(
buffer
==
nullptr
));
buffer
=
&
_buffer
;
assert
(
pipe
==
nullptr
||
&
pipe
->
GetBuffer
()
==
&
buffer
);
/* the audio format must be the same as existing chunks in the
pipe */
assert
(
pipe
==
nullptr
||
pipe
->
CheckFormat
(
audio_format
));
if
(
pipe
==
nullptr
)
pipe
=
new
MusicPipe
();
pipe
=
new
MusicPipe
(
buffer
);
else
/* if the pipe hasn't been cleared, the the audio
format must not have changed */
...
...
@@ -321,7 +317,6 @@ MultipleOutputs::CheckPipe() noexcept
MusicChunk
*
shifted
;
bool
locked
[
outputs
.
size
()];
assert
(
buffer
!=
nullptr
);
assert
(
pipe
!=
nullptr
);
while
((
chunk
=
pipe
->
Peek
())
!=
nullptr
)
{
...
...
@@ -355,7 +350,7 @@ MultipleOutputs::CheckPipe() noexcept
outputs
[
i
]
->
mutex
.
unlock
();
/* return the chunk to the buffer */
buffer
->
Return
(
shifted
);
pipe
->
GetBuffer
().
Return
(
shifted
);
}
return
0
;
...
...
@@ -394,7 +389,7 @@ MultipleOutputs::Cancel() noexcept
/* clear the music pipe and return all chunks to the buffer */
if
(
pipe
!=
nullptr
)
pipe
->
Clear
(
*
buffer
);
pipe
->
Clear
();
/* the audio outputs are now waiting for a signal, to
synchronize the cleared music pipe */
...
...
@@ -413,15 +408,11 @@ MultipleOutputs::Close() noexcept
ao
->
LockCloseWait
();
if
(
pipe
!=
nullptr
)
{
assert
(
buffer
!=
nullptr
);
pipe
->
Clear
(
*
buffer
);
pipe
->
Clear
();
delete
pipe
;
pipe
=
nullptr
;
}
buffer
=
nullptr
;
input_audio_format
.
Clear
();
elapsed_time
=
SignedSongTime
::
Negative
();
...
...
@@ -434,15 +425,11 @@ MultipleOutputs::Release() noexcept
ao
->
LockRelease
();
if
(
pipe
!=
nullptr
)
{
assert
(
buffer
!=
nullptr
);
pipe
->
Clear
(
*
buffer
);
pipe
->
Clear
();
delete
pipe
;
pipe
=
nullptr
;
}
buffer
=
nullptr
;
input_audio_format
.
Clear
();
elapsed_time
=
SignedSongTime
::
Negative
();
...
...
src/output/MultipleOutputs.hxx
View file @
9f14e7a9
...
...
@@ -53,11 +53,6 @@ class MultipleOutputs final : public PlayerOutputs {
AudioFormat
input_audio_format
=
AudioFormat
::
Undefined
();
/**
* The #MusicBuffer object where consumed chunks are returned.
*/
MusicBuffer
*
buffer
=
nullptr
;
/**
* The #MusicPipe object which feeds all audio outputs. It is
* filled by Play().
*/
...
...
src/player/Thread.cxx
View file @
9f14e7a9
...
...
@@ -170,7 +170,7 @@ private:
}
void
ClearAndDeletePipe
()
noexcept
{
pipe
->
Clear
(
buffer
);
pipe
->
Clear
();
delete
pipe
;
}
...
...
@@ -348,7 +348,7 @@ Player::StartDecoder(MusicPipe &_pipe) noexcept
dc
.
Start
(
std
::
make_unique
<
DetachedSong
>
(
*
pc
.
next_song
),
start_time
,
pc
.
next_song
->
GetEndTime
(),
buffer
,
_pipe
);
_pipe
);
}
void
...
...
@@ -361,7 +361,7 @@ Player::StopDecoder() noexcept
if
(
dc
.
pipe
!=
nullptr
)
{
/* clear and free the decoder pipe */
dc
.
pipe
->
Clear
(
buffer
);
dc
.
pipe
->
Clear
();
if
(
dc
.
pipe
!=
pipe
)
delete
dc
.
pipe
;
...
...
@@ -585,7 +585,7 @@ Player::SeekDecoder() noexcept
/* clear music chunks which might still reside in the
pipe */
pipe
->
Clear
(
buffer
);
pipe
->
Clear
();
/* re-start the decoder */
StartDecoder
(
*
pipe
);
...
...
@@ -666,7 +666,7 @@ Player::ProcessCommand() noexcept
pc
.
CommandFinished
();
if
(
dc
.
IsIdle
())
StartDecoder
(
*
new
MusicPipe
());
StartDecoder
(
*
new
MusicPipe
(
buffer
));
break
;
...
...
@@ -939,7 +939,7 @@ Player::SongBorder() noexcept
inline
void
Player
::
Run
()
noexcept
{
pipe
=
new
MusicPipe
();
pipe
=
new
MusicPipe
(
buffer
);
const
std
::
lock_guard
<
Mutex
>
lock
(
pc
.
mutex
);
...
...
@@ -986,7 +986,7 @@ Player::Run() noexcept
assert
(
dc
.
pipe
==
nullptr
||
dc
.
pipe
==
pipe
);
StartDecoder
(
*
new
MusicPipe
());
StartDecoder
(
*
new
MusicPipe
(
buffer
));
}
if
(
/* no cross-fading if MPD is going to pause at the
...
...
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