2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2016-02-26 17:54:05 +01:00
|
|
|
* Copyright 2003-2016 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"
|
2015-01-09 17:44:00 +01:00
|
|
|
#include "../Wrapper.hxx"
|
2014-02-19 09:00:29 +01:00
|
|
|
#include "../Timer.hxx"
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2015-01-09 19:30:22 +01:00
|
|
|
class NullOutput {
|
|
|
|
friend struct AudioOutputWrapper<NullOutput>;
|
|
|
|
|
2014-01-28 11:34:09 +01:00
|
|
|
AudioOutput base;
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2009-01-22 16:06:47 +01:00
|
|
|
bool sync;
|
|
|
|
|
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:
|
2014-01-28 23:39:48 +01:00
|
|
|
NullOutput()
|
|
|
|
:base(null_output_plugin) {}
|
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
bool Initialize(const ConfigBlock &block, Error &error) {
|
|
|
|
return base.Configure(block, error);
|
2013-04-17 01:21:33 +02:00
|
|
|
}
|
2009-01-22 16:06:45 +01:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
static NullOutput *Create(const ConfigBlock &block, Error &error);
|
2009-01-22 16:06:45 +01:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
bool Open(AudioFormat &audio_format, gcc_unused Error &error) {
|
|
|
|
if (sync)
|
|
|
|
timer = new Timer(audio_format);
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-22 16:06:43 +01:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
void Close() {
|
|
|
|
if (sync)
|
|
|
|
delete timer;
|
|
|
|
}
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
unsigned Delay() const {
|
|
|
|
return sync && timer->IsStarted()
|
|
|
|
? timer->GetDelay()
|
|
|
|
: 0;
|
|
|
|
}
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
size_t Play(gcc_unused const void *chunk, size_t size,
|
|
|
|
gcc_unused Error &error) {
|
|
|
|
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
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
void Cancel() {
|
|
|
|
if (sync)
|
|
|
|
timer->Reset();
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 21:11:04 +01:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
inline NullOutput *
|
2015-01-21 22:13:44 +01:00
|
|
|
NullOutput::Create(const ConfigBlock &block, Error &error)
|
2007-05-30 18:52:56 +02:00
|
|
|
{
|
2015-01-09 17:44:00 +01:00
|
|
|
NullOutput *nd = new NullOutput();
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
if (!nd->Initialize(block, error)) {
|
2015-01-09 17:44:00 +01:00
|
|
|
delete nd;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2009-01-22 16:06:47 +01:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
nd->sync = block.GetBlockValue("sync", true);
|
2007-05-30 18:52:56 +02:00
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
return nd;
|
2007-05-30 18:52:56 +02:00
|
|
|
}
|
|
|
|
|
2015-01-09 17:44:00 +01:00
|
|
|
typedef AudioOutputWrapper<NullOutput> Wrapper;
|
2007-05-30 20:16:35 +02: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,
|
2015-01-09 17:44:00 +01:00
|
|
|
&Wrapper::Init,
|
|
|
|
&Wrapper::Finish,
|
2013-02-02 09:30:29 +01:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2015-01-09 17:44:00 +01:00
|
|
|
&Wrapper::Open,
|
|
|
|
&Wrapper::Close,
|
|
|
|
&Wrapper::Delay,
|
2013-02-02 09:30:29 +01:00
|
|
|
nullptr,
|
2015-01-09 17:44:00 +01:00
|
|
|
&Wrapper::Play,
|
2013-02-02 09:30:29 +01:00
|
|
|
nullptr,
|
2015-01-09 17:44:00 +01:00
|
|
|
&Wrapper::Cancel,
|
2013-02-02 09:30:29 +01:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2007-05-30 18:52:56 +02:00
|
|
|
};
|