MusicPipe: add MusicBuffer reference

This tiny amount of overhead allows omitting the MusicBuffer in
Clear().
This commit is contained in:
Max Kellermann
2017-12-30 17:24:58 +01:00
parent cb412b221c
commit 9f14e7a98d
9 changed files with 34 additions and 49 deletions

View File

@@ -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();