Commit 613dd677 authored by Max Kellermann's avatar Max Kellermann

output/Internal: move the AudioOutputSource to struct AudioOutputControl

parent 58683f02
......@@ -1370,7 +1370,6 @@ OUTPUT_LIBS = \
OUTPUT_API_SRC = \
src/output/Client.hxx \
src/output/OutputAPI.hxx \
src/output/Internal.cxx \
src/output/Internal.hxx \
src/output/Wrapper.hxx \
src/output/Registry.cxx src/output/Registry.hxx \
......
......@@ -245,15 +245,19 @@ AudioOutputControl::LockUpdate(const AudioFormat audio_format,
}
bool
AudioOutputControl::LockIsChunkConsumed(const MusicChunk &chunk) const noexcept
AudioOutputControl::IsChunkConsumed(const MusicChunk &chunk) const noexcept
{
return output->LockIsChunkConsumed(chunk);
if (!output->open)
return true;
return source.IsChunkConsumed(chunk);
}
void
AudioOutputControl::ClearTailChunk(const MusicChunk &chunk) noexcept
bool
AudioOutputControl::LockIsChunkConsumed(const MusicChunk &chunk) const noexcept
{
output->ClearTailChunk(chunk);
const std::lock_guard<Mutex> protect(mutex);
return IsChunkConsumed(chunk);
}
void
......@@ -335,12 +339,6 @@ AudioOutputControl::LockCloseWait() noexcept
}
void
AudioOutputControl::SetReplayGainMode(ReplayGainMode _mode) noexcept
{
return output->SetReplayGainMode(_mode);
}
void
AudioOutputControl::StopThread() noexcept
{
assert(thread.IsDefined());
......
......@@ -20,6 +20,7 @@
#ifndef MPD_OUTPUT_CONTROL_HXX
#define MPD_OUTPUT_CONTROL_HXX
#include "Source.hxx"
#include "AudioFormat.hxx"
#include "thread/Thread.hxx"
#include "thread/Cond.hxx"
......@@ -57,6 +58,11 @@ class AudioOutputControl {
AudioOutputClient &client;
/**
* Source of audio data.
*/
AudioOutputSource source;
/**
* The error that occurred in the output thread. It is
* cleared whenever the output is opened successfully.
*
......@@ -327,7 +333,9 @@ public:
*/
void LockRelease() noexcept;
void SetReplayGainMode(ReplayGainMode _mode) noexcept;
void SetReplayGainMode(ReplayGainMode _mode) noexcept {
source.SetReplayGainMode(_mode);
}
/**
* Caller must lock the mutex.
......@@ -345,10 +353,20 @@ public:
const MusicPipe &mp,
bool force) noexcept;
/**
* Did we already consumed this chunk?
*
* Caller must lock the mutex.
*/
gcc_pure
bool IsChunkConsumed(const MusicChunk &chunk) const noexcept;
gcc_pure
bool LockIsChunkConsumed(const MusicChunk &chunk) const noexcept;
void ClearTailChunk(const MusicChunk &chunk) noexcept;
void ClearTailChunk(const MusicChunk &chunk) {
source.ClearTailChunk(chunk);
}
void LockPlay() noexcept;
void LockDrainAsync() noexcept;
......
/*
* Copyright 2003-2017 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Internal.hxx"
bool
AudioOutput::IsChunkConsumed(const MusicChunk &chunk) const noexcept
{
if (!open)
return true;
return source.IsChunkConsumed(chunk);
}
......@@ -20,7 +20,6 @@
#ifndef MPD_OUTPUT_INTERNAL_HXX
#define MPD_OUTPUT_INTERNAL_HXX
#include "Source.hxx"
#include "AudioFormat.hxx"
#include "filter/Observer.hxx"
#include "thread/Mutex.hxx"
......@@ -123,11 +122,6 @@ struct AudioOutput {
mutable Mutex mutex;
/**
* Source of audio data.
*/
AudioOutputSource source;
/**
* Throws #std::runtime_error on error.
*/
AudioOutput(const AudioOutputPlugin &_plugin,
......@@ -158,28 +152,6 @@ public:
return open;
}
void SetReplayGainMode(ReplayGainMode _mode) noexcept {
source.SetReplayGainMode(_mode);
}
/**
* Did we already consumed this chunk?
*
* Caller must lock the mutex.
*/
gcc_pure
bool IsChunkConsumed(const MusicChunk &chunk) const noexcept;
gcc_pure
bool LockIsChunkConsumed(const MusicChunk &chunk) noexcept {
const std::lock_guard<Mutex> protect(mutex);
return IsChunkConsumed(chunk);
}
void ClearTailChunk(const MusicChunk &chunk) {
source.ClearTailChunk(chunk);
}
/**
* Throws #std::runtime_error on error.
*/
......
......@@ -217,7 +217,6 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
try {
try {
auto &source = output->source;
f = source.Open(in_audio_format, pipe,
output->prepared_replay_gain_filter,
output->prepared_other_replay_gain_filter,
......@@ -230,7 +229,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
try {
output->Open(f);
} catch (...) {
output->source.Close();
source.Close();
throw;
}
} catch (const std::runtime_error &e) {
......@@ -253,7 +252,7 @@ AudioOutputControl::InternalClose(bool drain) noexcept
return;
output->Close(drain);
output->source.Close();
source.Close();
}
void
......@@ -307,7 +306,7 @@ AudioOutputControl::WaitForDelay() noexcept
bool
AudioOutputControl::FillSourceOrClose()
try {
return output->source.Fill(mutex);
return source.Fill(mutex);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to filter for output \"%s\" [%s]",
GetName(), output->plugin.name);
......@@ -324,7 +323,7 @@ inline bool
AudioOutputControl::PlayChunk() noexcept
{
if (tags) {
const auto *tag = output->source.ReadTag();
const auto *tag = source.ReadTag();
if (tag != nullptr) {
const ScopeUnlock unlock(mutex);
try {
......@@ -337,7 +336,7 @@ AudioOutputControl::PlayChunk() noexcept
}
while (command == Command::NONE) {
const auto data = output->source.PeekData();
const auto data = source.PeekData();
if (data.IsEmpty())
break;
......@@ -372,7 +371,7 @@ AudioOutputControl::PlayChunk() noexcept
assert(nbytes % output->out_audio_format.GetFrameSize() == 0);
output->source.ConsumeData(nbytes);
source.ConsumeData(nbytes);
}
return true;
......@@ -457,8 +456,10 @@ AudioOutputControl::InternalPause() noexcept
if (!WaitForDelay())
break;
if (!output->IteratePause())
if (!output->IteratePause()) {
source.Close();
break;
}
} while (command == Command::NONE);
pause = false;
......@@ -535,7 +536,7 @@ AudioOutputControl::Task()
continue;
case Command::CANCEL:
output->source.Cancel();
source.Cancel();
if (output->open) {
const ScopeUnlock unlock(mutex);
......@@ -547,7 +548,7 @@ AudioOutputControl::Task()
case Command::KILL:
InternalDisable();
output->source.Cancel();
source.Cancel();
CommandFinished();
return;
}
......
......@@ -26,6 +26,7 @@
#include <chrono>
struct ConfigBlock;
struct Tag;
template<class T>
struct AudioOutputWrapper {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment