From 2be905b2e23f15a0c78c89601c7624d4a10241f5 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sat, 23 Jun 2018 18:04:09 +0200
Subject: [PATCH] MusicPipe: eliminate the unused MusicBuffer reference

This requires re-adding the reference to struct DecoderControl, which
was removed recently by commit
9f14e7a98d8be5cc4b916456df0124b65ece8ae4
---
 src/MusicPipe.hxx              | 21 ---------------------
 src/decoder/Bridge.cxx         |  2 +-
 src/decoder/DecoderControl.cxx |  3 ++-
 src/decoder/DecoderControl.hxx |  6 +++++-
 src/output/MultipleOutputs.cxx |  7 ++-----
 src/output/MultipleOutputs.hxx |  4 +---
 src/player/Outputs.hxx         |  6 +-----
 src/player/Thread.cxx          | 10 +++++-----
 8 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/src/MusicPipe.hxx b/src/MusicPipe.hxx
index 65e620a83..e4546ed44 100644
--- a/src/MusicPipe.hxx
+++ b/src/MusicPipe.hxx
@@ -30,18 +30,11 @@
 
 #include <assert.h>
 
-class MusicBuffer;
-
 /**
  * A queue of #MusicChunk objects.  One party appends chunks at the
  * tail, and the other consumes them from the head.
  */
 class MusicPipe {
-	/**
-	 * The #MusicBuffer where all chunks must be returned.
-	 */
-	MusicBuffer &buffer;
-
 	/** the first chunk */
 	MusicChunkPtr head;
 
@@ -59,24 +52,10 @@ class MusicPipe {
 #endif
 
 public:
-	/**
-	 * Creates a new #MusicPipe object.  It is empty.
-	 */
-	explicit MusicPipe(MusicBuffer &_buffer) noexcept
-		:buffer(_buffer) {}
-
-	MusicPipe(const MusicPipe &) = delete;
-
 	~MusicPipe() noexcept {
 		Clear();
 	}
 
-	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
diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx
index c8ae799b9..a38b89b3b 100644
--- a/src/decoder/Bridge.cxx
+++ b/src/decoder/Bridge.cxx
@@ -98,7 +98,7 @@ DecoderBridge::GetChunk() noexcept
 		return current_chunk.get();
 
 	do {
-		current_chunk = dc.pipe->GetBuffer().Allocate();
+		current_chunk = dc.buffer->Allocate();
 		if (current_chunk != nullptr) {
 			current_chunk->replay_gain_serial = replay_gain_serial;
 			if (replay_gain_serial != 0)
diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx
index d121b60b0..aa2721e86 100644
--- a/src/decoder/DecoderControl.cxx
+++ b/src/decoder/DecoderControl.cxx
@@ -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,
-		      MusicPipe &_pipe) noexcept
+		      MusicBuffer &_buffer, MusicPipe &_pipe) noexcept
 {
 	assert(_song != nullptr);
 	assert(_pipe.IsEmpty());
@@ -100,6 +100,7 @@ DecoderControl::Start(std::unique_ptr<DetachedSong> _song,
 	song = std::move(_song);
 	start_time = _start_time;
 	end_time = _end_time;
+	buffer = &_buffer;
 	pipe = &_pipe;
 
 	ClearError();
diff --git a/src/decoder/DecoderControl.hxx b/src/decoder/DecoderControl.hxx
index da3472e04..e77237481 100644
--- a/src/decoder/DecoderControl.hxx
+++ b/src/decoder/DecoderControl.hxx
@@ -44,6 +44,7 @@
 #endif
 
 class DetachedSong;
+class MusicBuffer;
 class MusicPipe;
 
 enum class DecoderState : uint8_t {
@@ -151,6 +152,9 @@ 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.
@@ -379,7 +383,7 @@ public:
 	 */
 	void Start(std::unique_ptr<DetachedSong> song,
 		   SongTime start_time, SongTime end_time,
-		   MusicPipe &pipe) noexcept;
+		   MusicBuffer &buffer, MusicPipe &pipe) noexcept;
 
 	/**
 	 * Caller must lock the object.
diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx
index 3f4fee177..4f5413e96 100644
--- a/src/output/MultipleOutputs.cxx
+++ b/src/output/MultipleOutputs.cxx
@@ -221,19 +221,16 @@ MultipleOutputs::Play(MusicChunkPtr chunk)
 }
 
 void
-MultipleOutputs::Open(const AudioFormat audio_format,
-		      MusicBuffer &buffer)
+MultipleOutputs::Open(const AudioFormat audio_format)
 {
 	bool ret = false, enabled = false;
 
-	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(buffer);
+		pipe = new MusicPipe();
 	else
 		/* if the pipe hasn't been cleared, the the audio
 		   format must not have changed */
diff --git a/src/output/MultipleOutputs.hxx b/src/output/MultipleOutputs.hxx
index 79f9becca..9f74fefdd 100644
--- a/src/output/MultipleOutputs.hxx
+++ b/src/output/MultipleOutputs.hxx
@@ -38,7 +38,6 @@
 
 #include <assert.h>
 
-class MusicBuffer;
 class MusicPipe;
 class EventLoop;
 class MixerListener;
@@ -181,8 +180,7 @@ private:
 
 	/* virtual methods from class PlayerOutputs */
 	void EnableDisable() override;
-	void Open(const AudioFormat audio_format,
-		  MusicBuffer &_buffer) override;
+	void Open(const AudioFormat audio_format) override;
 	void Close() noexcept override;
 	void Release() noexcept override;
 	void Play(MusicChunkPtr chunk) override;
diff --git a/src/player/Outputs.hxx b/src/player/Outputs.hxx
index 71e5e43d8..54e340931 100644
--- a/src/player/Outputs.hxx
+++ b/src/player/Outputs.hxx
@@ -26,7 +26,6 @@
 
 struct AudioFormat;
 struct MusicChunk;
-class MusicBuffer;
 
 /**
  * An interface for the player thread to control all outputs.  This
@@ -50,11 +49,8 @@ public:
 	 * Throws on error.
 	 *
 	 * @param audio_format the preferred audio format
-	 * @param buffer the #MusicBuffer where consumed #MusicChunk
-	 * objects should be returned
 	 */
-	virtual void Open(const AudioFormat audio_format,
-			  MusicBuffer &buffer) = 0;
+	virtual void Open(const AudioFormat audio_format) = 0;
 
 	/**
 	 * Closes all audio outputs.
diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx
index e841ea673..c19fe1504 100644
--- a/src/player/Thread.cxx
+++ b/src/player/Thread.cxx
@@ -343,7 +343,7 @@ Player::StartDecoder(MusicPipe &_pipe) noexcept
 
 	dc.Start(std::make_unique<DetachedSong>(*pc.next_song),
 		 start_time, pc.next_song->GetEndTime(),
-		 _pipe);
+		 buffer, _pipe);
 }
 
 void
@@ -445,7 +445,7 @@ Player::OpenOutput() noexcept
 
 	try {
 		const ScopeUnlock unlock(pc.mutex);
-		pc.outputs.Open(play_audio_format, buffer);
+		pc.outputs.Open(play_audio_format);
 	} catch (...) {
 		LogError(std::current_exception());
 
@@ -661,7 +661,7 @@ Player::ProcessCommand() noexcept
 		pc.CommandFinished();
 
 		if (dc.IsIdle())
-			StartDecoder(*new MusicPipe(buffer));
+			StartDecoder(*new MusicPipe());
 
 		break;
 
@@ -932,7 +932,7 @@ Player::SongBorder() noexcept
 inline void
 Player::Run() noexcept
 {
-	pipe = new MusicPipe(buffer);
+	pipe = new MusicPipe();
 
 	const std::lock_guard<Mutex> lock(pc.mutex);
 
@@ -979,7 +979,7 @@ Player::Run() noexcept
 
 			assert(dc.pipe == nullptr || dc.pipe == pipe);
 
-			StartDecoder(*new MusicPipe(buffer));
+			StartDecoder(*new MusicPipe());
 		}
 
 		if (/* no cross-fading if MPD is going to pause at the