From ed5d76589f07cbfae1ba0446f5ad6135753eb755 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Tue, 28 Mar 2017 23:20:42 +0200 Subject: [PATCH] Tweaks --- src/PulseAudio.php | 113 ++++++++++++++++++++++++++++++++++++++++-- src/Sink/NullSink.php | 19 +++++++ 2 files changed, 129 insertions(+), 3 deletions(-) diff --git a/src/PulseAudio.php b/src/PulseAudio.php index 764ec44..b7a6664 100644 --- a/src/PulseAudio.php +++ b/src/PulseAudio.php @@ -3,16 +3,32 @@ namespace NoccyLabs\PulseAudio; use NoccyLabs\PulseAudio\Module\ModuleList; +use NoccyLabs\PulseAudio\Module\Loopback; use NoccyLabs\PulseAudio\Sink\SinkList; use NoccyLabs\PulseAudio\Sink\SinkInputList; use NoccyLabs\PulseAudio\Sink\NullSink; +use NoccyLabs\PulseAudio\Sink\Sink; use NoccyLabs\PulseAudio\Source\SourceList; use NoccyLabs\PulseAudio\Source\SourceOutputList; +use NoccyLabs\PulseAudio\Source\Source; use NoccyLabs\PulseAudio\Client\ClientList; use NoccyLabs\PulseAudio\Card\CardList; +/** + * @class PulseAudio + * + * + */ class PulseAudio { + + protected $server; + + public function __construct($server=null) + { + $this->server = $server; + } + /** * * @@ -23,48 +39,139 @@ class PulseAudio return new ModuleList($this); } + /** + * + * + * @return SinkList + */ public function getSinks() { return new SinkList($this); } - public function createNullSink($name=null) + /** + * Create a new null sink that can be used + * + * @param Source $source The source to use as input + * @param Sink $sink The sink to use as output + * @return Loopback The created loopback module + */ + public function createNullSink($name=null, $description=null, array $properties=[]) { - return new NullSink($this, $name); + return new NullSink($this, $name, $description, $properties); } - public function getSinkByIndex($index) + /** + * Create a new loopback, connecting a source to a sink. + * + * @param Source $source The source to use as input + * @param Sink $sink The sink to use as output + * @return Loopback The created loopback module + */ + public function createLoopback(Source $source, Sink $sink) + { + return new Loopback($this, $source, $sink); + } + + /** + * + * + * @return Sink + */ + public function getDefaultSink() + { + + } + + /** + * Get an object representing a sink that exist on the system. Both index + * and name can be used to select the sink. + * + * @param int|string $index The index OR name of the sink to retrieve + * @return Sink|null The sink, or null if none found + */ + public function getSink($index) { $sinks = $this->getSinks(); return $sinks[$index]; } + /** + * + * + * + * @return SinkInputList + */ public function getSinkInputs() { return new SinkInputList($this); } + /** + * + * @return SourceList + */ public function getSources() { return new SourceList($this); } + /** + * + * + * @return Source + */ + public function getDefaultSource() + { + + } + + /** + * + * + * @return Source + */ + public function getSource($index) + { + + } + + /** + * + * + * @return SourceOutputList + */ public function getSourceOutputs() { return new SourceOutputList($this); } + /** + * + * + * @return ClientList + */ public function getClients() { return new ClientList($this); } + /** + * + * + * @return Client + */ public function getClientByIndex($index) { $clients = $this->getClients(); return $clients[$index]; } + /** + * + * + * @return CardList + */ public function getCards() { return new CardList($this); diff --git a/src/Sink/NullSink.php b/src/Sink/NullSink.php index 97ee922..48cc7d3 100644 --- a/src/Sink/NullSink.php +++ b/src/Sink/NullSink.php @@ -12,6 +12,8 @@ class NullSink extends Sink protected $destroyed = false; + protected $persistent = false; + protected $moduleIndex; public function __construct(PulseAudio $pulse, $name=null) @@ -33,6 +35,9 @@ class NullSink extends Sink public function __destruct() { + if ($this->persistent) { + return; + } if (!$this->isDestroyed()) { $this->destroySink(); } @@ -49,5 +54,19 @@ class NullSink extends Sink return $this->destroyed; } + /** + * Flags the null-sink as persistent, meaning that it will not be + * automatically destroyed from the NullSink destructor. You can + * still manually destroy the sink within the object scope. + * + * The module-null-sink will have to be manually removed afterwards, + * see the documentation for more information. + * + */ + public function makePersistent() + { + $this->persistent = true; + } + }