Add Chromium-only Blender WebEngine parity work
This commit is contained in:
158
blender-5.2.0/extern/audaspace/src/devices/DeviceManager.cpp
vendored
Normal file
158
blender-5.2.0/extern/audaspace/src/devices/DeviceManager.cpp
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2009-2016 Jörg Müller
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
#include "devices/DeviceManager.h"
|
||||
#include "devices/ICaptureDeviceFactory.h"
|
||||
#include "devices/IDeviceFactory.h"
|
||||
#include "devices/IDevice.h"
|
||||
#include "devices/I3DDevice.h"
|
||||
#include "Exception.h"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
AUD_NAMESPACE_BEGIN
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<IDeviceFactory>> DeviceManager::m_factories;
|
||||
std::shared_ptr<IDevice> DeviceManager::m_device;
|
||||
std::unordered_map<std::string, std::shared_ptr<ICaptureDeviceFactory>> DeviceManager::m_capture_factories;
|
||||
|
||||
void DeviceManager::registerDevice(const std::string &name, std::shared_ptr<IDeviceFactory> factory)
|
||||
{
|
||||
m_factories[name] = factory;
|
||||
}
|
||||
|
||||
std::shared_ptr<IDeviceFactory> DeviceManager::getDeviceFactory(const std::string &name)
|
||||
{
|
||||
auto it = m_factories.find(name);
|
||||
|
||||
if(it == m_factories.end())
|
||||
return nullptr;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<IDeviceFactory> DeviceManager::getDefaultDeviceFactory()
|
||||
{
|
||||
int min = std::numeric_limits<int>::min();
|
||||
|
||||
std::shared_ptr<IDeviceFactory> result;
|
||||
|
||||
for(auto factory : m_factories)
|
||||
{
|
||||
if(factory.second->getPriority() >= min)
|
||||
{
|
||||
result = factory.second;
|
||||
min = result->getPriority();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DeviceManager::setDevice(std::shared_ptr<IDevice> device)
|
||||
{
|
||||
m_device = device;
|
||||
}
|
||||
|
||||
void DeviceManager::openDevice(const std::string &name)
|
||||
{
|
||||
setDevice(getDeviceFactory(name)->openDevice());
|
||||
}
|
||||
|
||||
void DeviceManager::openDefaultDevice()
|
||||
{
|
||||
setDevice(getDefaultDeviceFactory()->openDevice());
|
||||
}
|
||||
|
||||
void DeviceManager::releaseDevice()
|
||||
{
|
||||
m_device = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<IDevice> DeviceManager::getDevice()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
std::shared_ptr<I3DDevice> DeviceManager::get3DDevice()
|
||||
{
|
||||
return std::dynamic_pointer_cast<I3DDevice>(m_device);
|
||||
}
|
||||
|
||||
std::vector<std::string> DeviceManager::getAvailableDeviceNames()
|
||||
{
|
||||
struct DeviceNamePriority {
|
||||
std::string name;
|
||||
int priority;
|
||||
};
|
||||
|
||||
std::vector<DeviceNamePriority> devices;
|
||||
devices.reserve(m_factories.size());
|
||||
|
||||
for(const auto& pair : m_factories)
|
||||
devices.push_back({pair.first, pair.second->getPriority()});
|
||||
|
||||
auto sort = [](const DeviceNamePriority& lhs, const DeviceNamePriority& rhs){
|
||||
return lhs.priority > rhs.priority;
|
||||
};
|
||||
|
||||
std::sort(devices.begin(), devices.end(), sort);
|
||||
|
||||
std::vector<std::string> names;
|
||||
names.reserve(devices.size());
|
||||
|
||||
for(const auto& device : devices)
|
||||
names.push_back(device.name);
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
std::vector<std::string> DeviceManager::getAvailableCaptureDeviceNames()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
names.reserve(m_capture_factories.size());
|
||||
|
||||
for(auto& entry : m_capture_factories)
|
||||
names.push_back(entry.first);
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
std::shared_ptr<ICaptureDeviceFactory> DeviceManager::getCaptureDeviceFactory(const std::string& name)
|
||||
{
|
||||
auto it = m_capture_factories.find(name);
|
||||
|
||||
if(it == m_capture_factories.end())
|
||||
return nullptr;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void DeviceManager::registerCaptureDevice(const std::string& name, std::shared_ptr<ICaptureDeviceFactory> factory)
|
||||
{
|
||||
m_capture_factories[name] = factory;
|
||||
}
|
||||
|
||||
std::shared_ptr<IReader> DeviceManager::openCaptureDevice(const std::string& name,
|
||||
Specs specs,
|
||||
int buffersize)
|
||||
{
|
||||
return getCaptureDeviceFactory(name)->openDevice(specs, buffersize);
|
||||
}
|
||||
|
||||
AUD_NAMESPACE_END
|
||||
102
blender-5.2.0/extern/audaspace/src/devices/MixingThreadDevice.cpp
vendored
Normal file
102
blender-5.2.0/extern/audaspace/src/devices/MixingThreadDevice.cpp
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2009-2016 Jörg Müller
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
#include "devices/MixingThreadDevice.h"
|
||||
|
||||
AUD_NAMESPACE_BEGIN
|
||||
|
||||
void MixingThreadDevice::updateRingBuffer()
|
||||
{
|
||||
unsigned int samplesize = AUD_DEVICE_SAMPLE_SIZE(m_specs);
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mixingLock);
|
||||
|
||||
while(m_valid)
|
||||
{
|
||||
{
|
||||
std::lock_guard<ILockable> device_lock(*this);
|
||||
|
||||
preMixingWork(m_playback);
|
||||
|
||||
if(m_playback)
|
||||
{
|
||||
size_t size = m_ringBuffer.getWriteSize();
|
||||
|
||||
size_t sample_count = size / samplesize;
|
||||
|
||||
while(sample_count > 0)
|
||||
{
|
||||
size = sample_count * samplesize;
|
||||
|
||||
mix(reinterpret_cast<data_t*>(m_mixingBuffer.getBuffer()), sample_count);
|
||||
|
||||
m_ringBuffer.write(reinterpret_cast<data_t*>(m_mixingBuffer.getBuffer()), size);
|
||||
|
||||
sample_count = m_ringBuffer.getWriteSize() / samplesize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_mixingCondition.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
void MixingThreadDevice::startMixingThread(size_t buffersize)
|
||||
{
|
||||
m_mixingBuffer.resize(buffersize);
|
||||
m_ringBuffer.resize(buffersize);
|
||||
|
||||
m_valid = true;
|
||||
|
||||
m_mixingThread = std::thread(&MixingThreadDevice::updateRingBuffer, this);
|
||||
}
|
||||
|
||||
void MixingThreadDevice::notifyMixingThread()
|
||||
{
|
||||
m_mixingCondition.notify_all();
|
||||
}
|
||||
|
||||
void MixingThreadDevice::playing(bool playing)
|
||||
{
|
||||
std::lock_guard<ILockable> lock(*this);
|
||||
|
||||
m_playback = playing;
|
||||
|
||||
if(playing)
|
||||
notifyMixingThread();
|
||||
}
|
||||
|
||||
void MixingThreadDevice::preMixingWork(bool playing)
|
||||
{
|
||||
}
|
||||
|
||||
MixingThreadDevice::MixingThreadDevice()
|
||||
{
|
||||
}
|
||||
|
||||
void aud::MixingThreadDevice::stopMixingThread()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mixingLock);
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
m_mixingCondition.notify_all();
|
||||
|
||||
m_mixingThread.join();
|
||||
}
|
||||
|
||||
AUD_NAMESPACE_END
|
||||
214
blender-5.2.0/extern/audaspace/src/devices/NULLDevice.cpp
vendored
Normal file
214
blender-5.2.0/extern/audaspace/src/devices/NULLDevice.cpp
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2009-2016 Jörg Müller
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
#include "devices/NULLDevice.h"
|
||||
#include "devices/DeviceManager.h"
|
||||
#include "devices/IDeviceFactory.h"
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
AUD_NAMESPACE_BEGIN
|
||||
|
||||
NULLDevice::NULLHandle::NULLHandle()
|
||||
{
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::pause()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::resume()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::stop()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::getKeep()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::setKeep(bool keep)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::seek(double position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double NULLDevice::NULLHandle::getPosition()
|
||||
{
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
Status NULLDevice::NULLHandle::getStatus()
|
||||
{
|
||||
return STATUS_INVALID;
|
||||
}
|
||||
|
||||
float NULLDevice::NULLHandle::getVolume()
|
||||
{
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::setVolume(float volume)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float NULLDevice::NULLHandle::getPitch()
|
||||
{
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::setPitch(float pitch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int NULLDevice::NULLHandle::getLoopCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::setLoopCount(int count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NULLDevice::NULLHandle::setStopCallback(stopCallback callback, void* data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NULLDevice::NULLDevice()
|
||||
{
|
||||
}
|
||||
|
||||
NULLDevice::~NULLDevice()
|
||||
{
|
||||
}
|
||||
|
||||
DeviceSpecs NULLDevice::getSpecs() const
|
||||
{
|
||||
DeviceSpecs specs;
|
||||
specs.channels = CHANNELS_INVALID;
|
||||
specs.format = FORMAT_INVALID;
|
||||
specs.rate = RATE_INVALID;
|
||||
return specs;
|
||||
}
|
||||
|
||||
std::shared_ptr<IHandle> NULLDevice::play(std::shared_ptr<IReader> reader, bool keep)
|
||||
{
|
||||
return std::shared_ptr<IHandle>(new NULLHandle());
|
||||
}
|
||||
|
||||
std::shared_ptr<IHandle> NULLDevice::play(std::shared_ptr<ISound> sound, bool keep)
|
||||
{
|
||||
return std::shared_ptr<IHandle>(new NULLHandle());
|
||||
}
|
||||
|
||||
void NULLDevice::stopAll()
|
||||
{
|
||||
}
|
||||
|
||||
void NULLDevice::lock()
|
||||
{
|
||||
}
|
||||
|
||||
void NULLDevice::unlock()
|
||||
{
|
||||
}
|
||||
|
||||
float NULLDevice::getVolume() const
|
||||
{
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
void NULLDevice::setVolume(float volume)
|
||||
{
|
||||
}
|
||||
|
||||
void NULLDevice::seekSynchronizer(double time)
|
||||
{
|
||||
}
|
||||
|
||||
double NULLDevice::getSynchronizerPosition()
|
||||
{
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
void NULLDevice::playSynchronizer()
|
||||
{
|
||||
}
|
||||
|
||||
void NULLDevice::stopSynchronizer()
|
||||
{
|
||||
}
|
||||
|
||||
void NULLDevice::setSyncCallback(syncFunction function, void* data)
|
||||
{
|
||||
}
|
||||
|
||||
int NULLDevice::isSynchronizerPlaying()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
class NULLDeviceFactory : public IDeviceFactory
|
||||
{
|
||||
public:
|
||||
NULLDeviceFactory()
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<IDevice> openDevice()
|
||||
{
|
||||
return std::shared_ptr<IDevice>(new NULLDevice());
|
||||
}
|
||||
|
||||
virtual int getPriority()
|
||||
{
|
||||
return std::numeric_limits<int>::min();
|
||||
}
|
||||
|
||||
virtual void setSpecs(DeviceSpecs specs)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void setBufferSize(int buffersize)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void setName(const std::string &name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void NULLDevice::registerPlugin()
|
||||
{
|
||||
DeviceManager::registerDevice("None", std::shared_ptr<IDeviceFactory>(new NULLDeviceFactory));
|
||||
}
|
||||
|
||||
AUD_NAMESPACE_END
|
||||
69
blender-5.2.0/extern/audaspace/src/devices/ReadDevice.cpp
vendored
Normal file
69
blender-5.2.0/extern/audaspace/src/devices/ReadDevice.cpp
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2009-2016 Jörg Müller
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
#include "devices/ReadDevice.h"
|
||||
#include "IReader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
AUD_NAMESPACE_BEGIN
|
||||
|
||||
ReadDevice::ReadDevice(DeviceSpecs specs) :
|
||||
m_playing(false)
|
||||
{
|
||||
m_specs = specs;
|
||||
|
||||
create();
|
||||
}
|
||||
|
||||
ReadDevice::ReadDevice(Specs specs) :
|
||||
m_playing(false)
|
||||
{
|
||||
m_specs.specs = specs;
|
||||
m_specs.format = FORMAT_FLOAT32;
|
||||
|
||||
create();
|
||||
}
|
||||
|
||||
ReadDevice::~ReadDevice()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
bool ReadDevice::read(data_t* buffer, int length)
|
||||
{
|
||||
if(m_playing)
|
||||
mix(buffer, length);
|
||||
else
|
||||
if(m_specs.format == FORMAT_U8)
|
||||
std::memset(buffer, 0x80, length * AUD_DEVICE_SAMPLE_SIZE(m_specs));
|
||||
else
|
||||
std::memset(buffer, 0, length * AUD_DEVICE_SAMPLE_SIZE(m_specs));
|
||||
return m_playing;
|
||||
}
|
||||
|
||||
void ReadDevice::changeSpecs(Specs specs)
|
||||
{
|
||||
if(!AUD_COMPARE_SPECS(specs, m_specs.specs))
|
||||
setSpecs(specs);
|
||||
}
|
||||
|
||||
void ReadDevice::playing(bool playing)
|
||||
{
|
||||
m_playing = playing;
|
||||
}
|
||||
|
||||
AUD_NAMESPACE_END
|
||||
1059
blender-5.2.0/extern/audaspace/src/devices/SoftwareDevice.cpp
vendored
Normal file
1059
blender-5.2.0/extern/audaspace/src/devices/SoftwareDevice.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
65
blender-5.2.0/extern/audaspace/src/devices/ThreadedDevice.cpp
vendored
Normal file
65
blender-5.2.0/extern/audaspace/src/devices/ThreadedDevice.cpp
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2009-2016 Jörg Müller
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
#include "devices/ThreadedDevice.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
AUD_NAMESPACE_BEGIN
|
||||
|
||||
void ThreadedDevice::start()
|
||||
{
|
||||
std::lock_guard<ILockable> lock(*this);
|
||||
|
||||
// thread is still running, we can abort stopping it
|
||||
if(m_stop)
|
||||
m_stop = false;
|
||||
|
||||
// thread is not running, let's start it
|
||||
else if(!m_playing)
|
||||
{
|
||||
if(m_thread.joinable())
|
||||
m_thread.join();
|
||||
|
||||
m_playing = true;
|
||||
|
||||
m_thread = std::thread(&ThreadedDevice::runMixingThread, this);
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadedDevice::playing(bool playing)
|
||||
{
|
||||
if((!m_playing || m_stop) && playing)
|
||||
start();
|
||||
else
|
||||
m_stop = true;
|
||||
}
|
||||
|
||||
ThreadedDevice::ThreadedDevice() :
|
||||
m_playing(false),
|
||||
m_stop(false)
|
||||
{
|
||||
}
|
||||
|
||||
void aud::ThreadedDevice::stopMixingThread()
|
||||
{
|
||||
stopAll();
|
||||
|
||||
if(m_thread.joinable())
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
AUD_NAMESPACE_END
|
||||
Reference in New Issue
Block a user