2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2007-05-30 18:52:56 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2007-05-30 18:52:56 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-02-02 09:30:29 +01:00
|
|
|
#include "NullOutputPlugin.hxx"
|
2014-01-23 23:49:50 +01:00
|
|
|
#include "../OutputAPI.hxx"
|
2014-02-19 09:00:29 +01:00
|
|
|
#include "../Timer.hxx"
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
class NullOutput final : AudioOutput {
|
2016-11-09 12:03:20 +01:00
|
|
|
const bool sync;
|
2009-01-22 16:06:47 +01:00
|
|
|
|
2013-05-12 15:03:42 +02:00
|
|
|
Timer *timer;
|
2013-04-17 01:21:33 +02:00
|
|
|
|
2015-01-09 19:30:22 +01:00
|
|
|
public:
|
2016-11-09 12:03:20 +01:00
|
|
|
NullOutput(const ConfigBlock &block)
|
2017-08-09 16:58:44 +02:00
|
|
|
:AudioOutput(0),
|
2016-11-09 12:03:20 +01:00
|
|
|
sync(block.GetBlockValue("sync", true)) {}
|
2009-01-22 16:06:45 +01:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
static AudioOutput *Create(EventLoop &,
|
|
|
|
const ConfigBlock &block) {
|
|
|
|
return new NullOutput(block);
|
|
|
|
}
|
2009-01-22 16:06:45 +01:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
private:
|
|
|
|
void Open(AudioFormat &audio_format) override {
|
2015-01-09 17:44:00 +01:00
|
|
|
if (sync)
|
|
|
|
timer = new Timer(audio_format);
|
|
|
|
}
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
void Close() noexcept override {
|
2015-01-09 17:44:00 +01:00
|
|
|
if (sync)
|
|
|
|
delete timer;
|
|
|
|
}
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
std::chrono::steady_clock::duration Delay() const noexcept override {
|
2015-01-09 17:44:00 +01:00
|
|
|
return sync && timer->IsStarted()
|
2016-12-28 10:11:07 +01:00
|
|
|
? timer->GetDelay()
|
2016-12-28 21:44:18 +01:00
|
|
|
: std::chrono::steady_clock::duration::zero();
|
2015-01-09 17:44:00 +01:00
|
|
|
}
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
size_t Play(gcc_unused const void *chunk, size_t size) override {
|
2015-01-09 17:44:00 +01:00
|
|
|
if (sync) {
|
|
|
|
if (!timer->IsStarted())
|
|
|
|
timer->Start();
|
|
|
|
timer->Add(size);
|
|
|
|
}
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
return size;
|
|
|
|
}
|
2011-12-13 21:11:04 +01:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
void Cancel() noexcept override {
|
2015-01-09 17:44:00 +01:00
|
|
|
if (sync)
|
|
|
|
timer->Reset();
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 21:11:04 +01:00
|
|
|
|
2014-01-28 11:22:27 +01:00
|
|
|
const struct AudioOutputPlugin null_output_plugin = {
|
2013-02-02 09:30:29 +01:00
|
|
|
"null",
|
|
|
|
nullptr,
|
2017-08-09 16:58:44 +02:00
|
|
|
&NullOutput::Create,
|
2013-02-02 09:30:29 +01:00
|
|
|
nullptr,
|
2007-05-30 18:52:56 +02:00
|
|
|
};
|