Added scaffolding for a PipeWire output plugin.

This commit is contained in:
casey langen 2021-03-03 22:53:59 -08:00
parent 710eecbee9
commit 104a65f183
5 changed files with 262 additions and 0 deletions

View File

@ -155,6 +155,10 @@ add_dependencies(musikcubed musikcube)
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory(src/plugins/alsaout)
add_subdirectory(src/plugins/pulseout)
if (${ENABLE_PIPEWIRE} MATCHES "true")
add_subdirectory(src/plugins/pipewireout)
add_dependencies(musikcube pipewireout)
endif()
if (${ENABLE_MPRIS} MATCHES "true")
add_subdirectory(src/plugins/mpris)
add_dependencies(musikcube mpris)

View File

@ -0,0 +1,9 @@
set (pipewireout_SOURCES
pipewireout_plugin.cpp
PipeWireOut.cpp
)
message(STATUS "[pipewireout] plugin enabled")
add_library(pipewireout SHARED ${pipewireout_SOURCES})
target_link_libraries(pipewireout ${musikcube_LINK_LIBS} pipewire-0.3)

View File

@ -0,0 +1,114 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "PipeWireOut.h"
#include <musikcore/sdk/constants.h>
#include <musikcore/sdk/IPreferences.h>
#include <musikcore/sdk/ISchema.h>
#include <unistd.h>
static IPreferences* prefs = nullptr;
extern "C" void SetPreferences(IPreferences* prefs) {
::prefs = prefs;
}
extern "C" musik::core::sdk::ISchema* GetSchema() {
auto schema = new TSchema<>();
return schema;
}
PipeWireOut::PipeWireOut() {
this->volume = 1.0f;
this->state = StateStopped;
}
PipeWireOut::~PipeWireOut() {
}
void PipeWireOut::Release() {
delete this;
}
void PipeWireOut::Pause() {
this->state = StatePaused;
}
void PipeWireOut::Resume() {
this->state = StatePlaying;
}
void PipeWireOut::SetVolume(double volume) {
this->volume = volume;
}
double PipeWireOut::GetVolume() {
return this->volume;
}
void PipeWireOut::Stop() {
this->state = StateStopped;
}
void PipeWireOut::Drain() {
}
IDeviceList* PipeWireOut::GetDeviceList() {
return nullptr;
}
bool PipeWireOut::SetDefaultDevice(const char* deviceId) {
return false;
}
IDevice* PipeWireOut::GetDefaultDevice() {
return nullptr;
}
OutputState PipeWireOut::Play(IBuffer *buffer, IBufferProvider *provider) {
if (this->state == StatePaused) {
return OutputState::InvalidState;
}
/* order of operations matters, otherwise overflow. */
int micros = ((buffer->Samples() * 1000) / buffer->SampleRate() * 1000) / buffer->Channels();
usleep((long)((float) micros));
provider->OnBufferProcessed(buffer);
return OutputState::BufferWritten;
}
double PipeWireOut::Latency() {
return 0.0;
}

View File

@ -0,0 +1,72 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <musikcore/sdk/IOutput.h>
using namespace musik::core::sdk;
class PipeWireOut : public IOutput {
public:
PipeWireOut();
~PipeWireOut();
/* IPlugin */
const char* Name() override { return "PipeWire"; };
void Release() override;
/* IOutput */
void Pause() override;
void Resume() override;
void SetVolume(double volume) override;
double GetVolume() override;
void Stop() override;
OutputState Play(IBuffer *buffer, IBufferProvider *provider) override;
double Latency() override;
void Drain() override;
IDeviceList* GetDeviceList() override;
bool SetDefaultDevice(const char* deviceId) override;
IDevice* GetDefaultDevice() override;
private:
enum State {
StateStopped,
StatePaused,
StatePlaying
};
State state;
double volume;
};

View File

@ -0,0 +1,63 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "config.h"
#include <musikcore/sdk/constants.h>
#include <musikcore/sdk/IPlugin.h>
#include <musikcore/sdk/ISchema.h>
#include "PipeWireOut.h"
class PipeWirePlugin : public musik::core::sdk::IPlugin {
public:
void Release() noexcept override { delete this; }
const char* Name() override { return "PipeWire IOutput"; }
const char* Version() override { return "0.1.0"; }
const char* Author() override { return "clangen"; }
const char* Guid() override { return "ab79e0f2-53d8-4774-ad00-266a30c50427"; }
bool Configurable() override { return false; }
void Configure() override { }
void Reload() override { }
int SdkVersion() override { return musik::core::sdk::SdkVersion; }
};
extern "C" musik::core::sdk::IPlugin* GetPlugin() {
return new PipeWirePlugin();
}
extern "C" musik::core::sdk::IOutput* GetAudioOutput() {
return new PipeWireOut();
}
extern "C" musik::core::sdk::ISchema* GetSchema();