summaryrefslogtreecommitdiff
path: root/src/player
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-12-30 18:00:40 +0100
committerMax Kellermann <max@musicpd.org>2018-06-22 23:11:52 +0200
commit54d295c247deb1f543d922eb838d3eff2f7a89ce (patch)
tree1f97982f7a1feb5e70a9ff4cc29d0c08e197cf0c /src/player
parente81b089612833b61c566b482640615e182949ac6 (diff)
MusicChunkPtr: managed MusicChunk pointer
Make all uses of MusicChunk safe.
Diffstat (limited to 'src/player')
-rw-r--r--src/player/Outputs.hxx3
-rw-r--r--src/player/Thread.cxx28
2 files changed, 15 insertions, 16 deletions
diff --git a/src/player/Outputs.hxx b/src/player/Outputs.hxx
index 9b896ce5d..71e5e43d8 100644
--- a/src/player/Outputs.hxx
+++ b/src/player/Outputs.hxx
@@ -20,6 +20,7 @@
#ifndef MPD_PLAYER_OUTPUT_INTERFACE_HXX
#define MPD_PLAYER_OUTPUT_INTERFACE_HXX
+#include "MusicChunkPtr.hxx"
#include "Chrono.hxx"
#include "Compiler.h"
@@ -74,7 +75,7 @@ public:
*
* @param chunk the #MusicChunk object to be played
*/
- virtual void Play(MusicChunk *chunk) = 0;
+ virtual void Play(MusicChunkPtr chunk) = 0;
/**
* Checks if the output devices have drained their music pipe, and
diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx
index b359ec4b8..e841ea673 100644
--- a/src/player/Thread.cxx
+++ b/src/player/Thread.cxx
@@ -751,8 +751,7 @@ update_song_tag(PlayerControl &pc, DetachedSong &song,
*/
static void
play_chunk(PlayerControl &pc,
- DetachedSong &song, MusicChunk *chunk,
- MusicBuffer &buffer,
+ DetachedSong &song, MusicChunkPtr chunk,
const AudioFormat format)
{
assert(chunk->CheckFormat(format));
@@ -760,10 +759,8 @@ play_chunk(PlayerControl &pc,
if (chunk->tag != nullptr)
update_song_tag(pc, song, *chunk->tag);
- if (chunk->IsEmpty()) {
- buffer.Return(chunk);
+ if (chunk->IsEmpty())
return;
- }
{
const std::lock_guard<Mutex> lock(pc.mutex);
@@ -772,9 +769,10 @@ play_chunk(PlayerControl &pc,
/* send the chunk to the audio outputs */
- pc.outputs.Play(chunk);
- pc.total_play_time += (double)chunk->length /
- format.GetTimeToSize();
+ const double chunk_length(chunk->length);
+
+ pc.outputs.Play(std::move(chunk));
+ pc.total_play_time += chunk_length / format.GetTimeToSize();
}
inline bool
@@ -796,7 +794,7 @@ Player::PlayNextChunk() noexcept
xfade_state = CrossFadeState::ACTIVE;
}
- MusicChunk *chunk = nullptr;
+ MusicChunkPtr chunk;
if (xfade_state == CrossFadeState::ACTIVE) {
/* perform cross fade */
@@ -805,7 +803,7 @@ Player::PlayNextChunk() noexcept
unsigned cross_fade_position = pipe->GetSize();
assert(cross_fade_position <= cross_fade_chunks);
- MusicChunk *other_chunk = dc.pipe->Shift();
+ auto other_chunk = dc.pipe->Shift();
if (other_chunk != nullptr) {
chunk = pipe->Shift();
assert(chunk != nullptr);
@@ -832,11 +830,10 @@ Player::PlayNextChunk() noexcept
beginning of the new song, we can
easily recover by throwing it away
now */
- buffer.Return(other_chunk);
- other_chunk = nullptr;
+ other_chunk.reset();
}
- chunk->other = other_chunk;
+ chunk->other = std::move(other_chunk);
} else {
/* there are not enough decoded chunks yet */
@@ -872,11 +869,12 @@ Player::PlayNextChunk() noexcept
/* play the current chunk */
try {
- play_chunk(pc, *song, chunk, buffer, play_audio_format);
+ play_chunk(pc, *song, std::move(chunk),
+ play_audio_format);
} catch (...) {
LogError(std::current_exception());
- buffer.Return(chunk);
+ chunk.reset();
/* pause: the user may resume playback as soon as an
audio output becomes available */