diff --git a/CMakeLists.txt b/CMakeLists.txt index d62ab005d..ab3654b86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,11 +102,14 @@ endif() add_dependencies(taglibreader taglib) -if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") +if (CMAKE_SYSTEM_NAME MATCHES "Linux") add_subdirectory(src/plugins/alsaout) add_subdirectory(src/plugins/pulseout) -else() - add_subdirectory(src/plugins/coreaudioout) # macOS +elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + add_subdirectory(src/plugins/sndioout) + add_subdirectory(src/plugins/pulseout) +elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") + add_subdirectory(src/plugins/coreaudioout) endif() # install the binary @@ -119,12 +122,18 @@ install( # install the plugins if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + if (CMAKE_SYSTEM_NAME MATCHES "Linux") + set(ADDITIONAL_OUTPUTS bin/plugins/libalsaout.so) + else() + set(ADDITIONAL_OUTPUTS bin/plugins/libsndioout.so) + endif() + if (${FFMPEG_DECODER} MATCHES "true") install( FILES - bin/plugins/libalsaout.so bin/plugins/libpulseout.so bin/plugins/libnullout.so + ${ADDITIONAL_OUTPUTS} bin/plugins/libffmpegdecoder.so bin/plugins/libtaglibreader.so bin/plugins/libserver.so @@ -134,9 +143,9 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") else() install( FILES - bin/plugins/libalsaout.so bin/plugins/libpulseout.so bin/plugins/libnullout.so + ${ADDITIONAL_OUTPUTS} bin/plugins/libflacdecoder.so bin/plugins/libm4adecoder.so bin/plugins/libnomaddecoder.so diff --git a/src/core/audio/Outputs.cpp b/src/core/audio/Outputs.cpp index afc7da2ba..20985fe7b 100644 --- a/src/core/audio/Outputs.cpp +++ b/src/core/audio/Outputs.cpp @@ -53,6 +53,8 @@ using OutputList = std::vector; static const std::string defaultOutput = "WASAPI"; #elif defined(__APPLE__) static const std::string defaultOutput = "CoreAudio"; +#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__) +static const std::string defaultOutput = "sndio"; #else static const std::string defaultOutput = "PulseAudio"; #endif @@ -131,4 +133,4 @@ namespace musik { } } } -} \ No newline at end of file +} diff --git a/src/plugins/sndioout/CMakeLists.txt b/src/plugins/sndioout/CMakeLists.txt new file mode 100644 index 000000000..0befbdae2 --- /dev/null +++ b/src/plugins/sndioout/CMakeLists.txt @@ -0,0 +1,7 @@ +set (sndioout_SOURCES + plugin.cpp + SndioOut.cpp +) + +add_library(sndioout SHARED ${sndioout_SOURCES}) +target_link_libraries(sndioout ${musikcube_LINK_LIBS}) diff --git a/src/plugins/sndioout/SndioOut.cpp b/src/plugins/sndioout/SndioOut.cpp new file mode 100644 index 000000000..659ef019e --- /dev/null +++ b/src/plugins/sndioout/SndioOut.cpp @@ -0,0 +1,100 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2017 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 "SndioOut.h" + +#include +#include + +using namespace musik::core::sdk; + +SndioOut::SndioOut() { + this->volume = 1.0f; + this->state = StateStopped; +} + +SndioOut::~SndioOut() { +} + +void SndioOut::Release() { + delete this; +} + +void SndioOut::Pause() { + this->state = StatePaused; +} + +void SndioOut::Resume() { + this->state = StatePlaying; +} + +void SndioOut::SetVolume(double volume) { + this->volume = volume; +} + +double SndioOut::GetVolume() { + return this->volume; +} + +void SndioOut::Stop() { + this->state = StateStopped; +} + +void SndioOut::Drain() { + +} + +IDeviceList* SndioOut::GetDeviceList() { + return nullptr; +} + +bool SndioOut::SetDefaultDevice(const char* deviceId) { + return false; +} + +IDevice* SndioOut::GetDefaultDevice() { + return nullptr; +} + +int SndioOut::Play(IBuffer *buffer, IBufferProvider *provider) { + if (this->state == StatePaused) { + return OutputInvalidState; + } + + return OutputBufferWritten; +} + +double SndioOut::Latency() { + return 0.0; +} diff --git a/src/plugins/sndioout/SndioOut.h b/src/plugins/sndioout/SndioOut.h new file mode 100644 index 000000000..9a5b42b67 --- /dev/null +++ b/src/plugins/sndioout/SndioOut.h @@ -0,0 +1,71 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2017 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 + +using namespace musik::core::sdk; + +class SndioOut : public IOutput { + public: + SndioOut(); + ~SndioOut(); + + /* IPlugin */ + virtual const char* Name() override { return "sndio"; }; + virtual void Release() override; + + /* IOutput */ + virtual void Pause() override; + virtual void Resume() override; + virtual void SetVolume(double volume) override; + virtual double GetVolume() override; + virtual void Stop() override; + virtual int Play(IBuffer *buffer, IBufferProvider *provider) override; + virtual double Latency() override; + virtual void Drain() override; + virtual IDeviceList* GetDeviceList() override; + virtual bool SetDefaultDevice(const char* deviceId) override; + virtual IDevice* GetDefaultDevice() override; + + private: + enum State { + StateStopped, + StatePaused, + StatePlaying + }; + + State state; + double volume; +}; diff --git a/src/plugins/sndioout/plugin.cpp b/src/plugins/sndioout/plugin.cpp new file mode 100644 index 000000000..9047a1d23 --- /dev/null +++ b/src/plugins/sndioout/plugin.cpp @@ -0,0 +1,58 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2017 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 +#include +#include "SndioOut.h" + +class SndioPlugin : public musik::core::sdk::IPlugin { + public: + virtual void Release() { delete this; } + virtual const char* Name() { return "Sndio IOutput"; } + virtual const char* Version() { return "0.1.0"; } + virtual const char* Author() { return "clangen"; } + virtual const char* Guid() { return "13903ab8-b387-4de9-86e3-14ba22057dcd"; } + virtual bool Configurable() { return false; } + virtual void Configure() { } + virtual void Reload() { } + virtual int SdkVersion() { return musik::core::sdk::SdkVersion; } +}; + +extern "C" musik::core::sdk::IPlugin* GetPlugin() { + return new SndioPlugin(); +} + +extern "C" musik::core::sdk::IOutput* GetAudioOutput() { + return new SndioOut(); +}