Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,353 @@
/*******************************************************************************
* 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 "JackDevice.h"
#include "JackLibrary.h"
#include "devices/DeviceManager.h"
#include "devices/IDeviceFactory.h"
#include "Exception.h"
#include <cstring>
#include <algorithm>
AUD_NAMESPACE_BEGIN
int JackDevice::jack_mix(jack_nframes_t length, void* data)
{
JackDevice* device = (JackDevice*) data;
int count = device->m_specs.channels;
float* buffer;
jack_position_t position;
jack_transport_state_t state = AUD_jack_transport_query(device->m_client, &position);
if(state == JackTransportStarting)
{
// play silence while syncing
for(int i = 0; i < count; i++)
std::memset(AUD_jack_port_get_buffer(device->m_ports[i], length), 0, length * sizeof(float));
}
else
{
// ensure that if two consecutive seeks to exactly the same position result in a sync callback call in jack_sync
if((state == JackTransportRolling) && (device->m_lastMixState != JackTransportRolling))
++device->m_rollingSyncRevision;
size_t sample_size = AUD_DEVICE_SAMPLE_SIZE(device->m_specs);
size_t readsamples = device->getRingBuffer().getReadSize();
readsamples = std::min(readsamples / sample_size, static_cast<size_t>(length));
data_t* deinterleave_buffer = reinterpret_cast<data_t*>(device->m_deinterleavebuf.getBuffer());
device->getRingBuffer().read(deinterleave_buffer, readsamples * sample_size);
if(readsamples < length)
std::memset(deinterleave_buffer + readsamples * sample_size, 0, (length - readsamples) * sample_size);
for(int i = 0; i < count; i++)
{
buffer = reinterpret_cast<float*>(AUD_jack_port_get_buffer(device->m_ports[i], length));
for(int j = 0; j < length; j++)
buffer[j] = reinterpret_cast<float*>(deinterleave_buffer)[i + j * count];
}
// if we are stopped and the jack transport position changes, we need to notify the mixing thread to call the sync callback
if(state == JackTransportStopped)
{
float syncTime = position.frame / (float) position.frame_rate;
if(syncTime != device->m_syncTime)
{
device->m_syncTime = syncTime;
++device->m_syncCallRevision;
}
}
device->notifyMixingThread();
}
device->m_lastMixState = state;
return 0;
}
int JackDevice::jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data)
{
JackDevice* device = (JackDevice*)data;
// we return immediately when the state is stopped as this is handled in the mixing thread separately, as not all stops result in a call here from jack.
if(state == JackTransportStopped)
return 1;
float syncTime = pos->frame / (float) pos->frame_rate;
// We need to call the sync callback in the mixing thread if
// - the sync time is different, i.e., a new sync to a different time is done
// - if the last state is stopped, i.e., we are starting playback
// - if the sync time is the same but the rolling revision is increased, i.e., we are syncing repeatedly to the same time (happens especially when jumping back to the start)
if((syncTime != device->m_syncTime) || (device->m_lastMixState == JackTransportStopped) || (device->m_rollingSyncRevision != device->m_lastRollingSyncRevision))
{
device->m_syncTime = syncTime;
++device->m_syncCallRevision;
device->notifyMixingThread();
device->m_lastRollingSyncRevision = device->m_rollingSyncRevision;
return 0;
}
return device->m_syncCallRevision == device->m_lastSyncCallRevision;
}
void JackDevice::preMixingWork([[maybe_unused]] bool playing)
{
jack_transport_state_t state;
jack_position_t position;
state = AUD_jack_transport_query(m_client, &position);
// we sync either when:
// - there was a jack sync callback that requests a playing sync (either start playback or seek during playback) - caused by a m_syncCallRevision change in jack_sync
// - the jack transport state changed to stop from not stopped (i.e. external stopping) - checked here
// - the sync time changes when seeking during the stopped state - caused by a m_syncCallRevision change in jack_mix
if((m_syncCallRevision != m_lastSyncCallRevision) || (state == JackTransportStopped && m_lastState != JackTransportStopped))
{
int syncRevision = m_syncCallRevision;
float syncTime = m_syncTime;
if(m_syncFunc)
m_syncFunc(m_syncFuncData, state != JackTransportStopped, syncTime);
// we reset the ring buffer when we sync to start from the correct position
getRingBuffer().reset();
m_lastSyncCallRevision = syncRevision;
}
m_lastState = state;
}
void JackDevice::jack_shutdown(void* data)
{
JackDevice* device = (JackDevice*)data;
device->stopMixingThread();
}
JackDevice::JackDevice(const std::string& name, DeviceSpecs specs, int buffersize)
{
if(specs.channels == CHANNELS_INVALID)
specs.channels = CHANNELS_STEREO;
// jack uses floats
m_specs = specs;
m_specs.format = FORMAT_FLOAT32;
jack_options_t options = JackNullOption;
jack_status_t status;
// open client
m_client = AUD_jack_client_open(name.c_str(), options, &status);
if(m_client == nullptr)
AUD_THROW(DeviceException, "Connecting to the JACK server failed.");
// set callbacks
AUD_jack_set_process_callback(m_client, JackDevice::jack_mix, this);
AUD_jack_on_shutdown(m_client, JackDevice::jack_shutdown, this);
AUD_jack_set_sync_callback(m_client, JackDevice::jack_sync, this);
// register our output channels which are called ports in jack
m_ports = new jack_port_t*[m_specs.channels];
try
{
char portname[64];
for(int i = 0; i < m_specs.channels; i++)
{
sprintf(portname, "out %d", i+1);
m_ports[i] = AUD_jack_port_register(m_client, portname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
if(m_ports[i] == nullptr)
AUD_THROW(DeviceException, "Registering output port with JACK failed.");
}
}
catch(Exception&)
{
AUD_jack_client_close(m_client);
delete[] m_ports;
throw;
}
m_specs.rate = (SampleRate)AUD_jack_get_sample_rate(m_client);
if(buffersize < 0)
buffersize = AUD_jack_get_buffer_size(m_client) * 2;
buffersize *= AUD_SAMPLE_SIZE(m_specs);
m_deinterleavebuf.resize(buffersize);
create();
m_lastState = JackTransportStopped;
m_lastMixState = JackTransportStopped;
m_syncFunc = nullptr;
m_syncTime = 0;
m_syncCallRevision = 0;
m_lastSyncCallRevision = 0;
m_rollingSyncRevision = 0;
m_lastRollingSyncRevision = 0;
// activate the client
if(AUD_jack_activate(m_client))
{
AUD_jack_client_close(m_client);
delete[] m_ports;
destroy();
AUD_THROW(DeviceException, "Client activation with JACK failed.");
}
const char** ports = AUD_jack_get_ports(m_client, nullptr, nullptr,
JackPortIsPhysical | JackPortIsInput);
if(ports != nullptr)
{
for(int i = 0; i < m_specs.channels && ports[i]; i++)
AUD_jack_connect(m_client, AUD_jack_port_name(m_ports[i]), ports[i]);
AUD_jack_free(ports);
}
startMixingThread(buffersize);
}
JackDevice::~JackDevice()
{
if(isMixingThreadRunning())
{
stopMixingThread();
AUD_jack_client_close(m_client);
}
delete[] m_ports;
destroy();
}
void JackDevice::playing(bool playing)
{
MixingThreadDevice::playing(playing);
}
void JackDevice::playSynchronizer()
{
AUD_jack_transport_start(m_client);
}
void JackDevice::stopSynchronizer()
{
AUD_jack_transport_stop(m_client);
}
void JackDevice::seekSynchronizer(double time)
{
if(time >= 0.0f)
AUD_jack_transport_locate(m_client, time * m_specs.rate);
}
void JackDevice::setSyncCallback(syncFunction sync, void* data)
{
m_syncFunc = sync;
m_syncFuncData = data;
}
double JackDevice::getSynchronizerPosition()
{
jack_position_t position;
jack_transport_state_t state = AUD_jack_transport_query(m_client, &position);
double result = position.frame / (double) position.frame_rate;
if(state == JackTransportRolling)
{
result += AUD_jack_frames_since_cycle_start(m_client) / (double) position.frame_rate;
}
return result;
}
int JackDevice::isSynchronizerPlaying()
{
return AUD_jack_transport_query(m_client, nullptr);
}
class JackDeviceFactory : public IDeviceFactory
{
private:
DeviceSpecs m_specs;
int m_buffersize;
std::string m_name;
public:
JackDeviceFactory() : m_buffersize(-1), m_name("Audaspace")
{
m_specs.format = FORMAT_FLOAT32;
m_specs.channels = CHANNELS_STEREO;
m_specs.rate = RATE_48000;
}
virtual std::shared_ptr<IDevice> openDevice()
{
return std::shared_ptr<IDevice>(new JackDevice(m_name, m_specs, m_buffersize));
}
virtual int getPriority()
{
return 0;
}
virtual void setSpecs(DeviceSpecs specs)
{
m_specs = specs;
}
virtual void setBufferSize(int buffersize)
{
m_buffersize = buffersize;
}
virtual void setName(const std::string &name)
{
m_name = name;
}
};
void JackDevice::registerPlugin()
{
if(loadJACK())
DeviceManager::registerDevice("JACK", std::shared_ptr<IDeviceFactory>(new JackDeviceFactory));
}
#ifdef JACK_PLUGIN
extern "C" AUD_PLUGIN_API void registerPlugin()
{
JackDevice::registerPlugin();
}
extern "C" AUD_PLUGIN_API const char* getName()
{
return "JACK";
}
#endif
AUD_NAMESPACE_END

View File

@@ -0,0 +1,191 @@
/*******************************************************************************
* 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.
******************************************************************************/
#pragma once
#ifdef JACK_PLUGIN
#define AUD_BUILD_PLUGIN
#endif
/**
* @file JackDevice.h
* @ingroup plugin
* The JackDevice class.
*/
#include <atomic>
#include <condition_variable>
#include <string>
#include <thread>
#include <jack/jack.h>
#include "devices/MixingThreadDevice.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This device plays back through JACK.
*/
class AUD_PLUGIN_API JackDevice : public MixingThreadDevice
{
private:
/**
* The output ports of jack.
*/
jack_port_t** m_ports;
/**
* The jack client.
*/
jack_client_t* m_client;
/**
* The deinterleaving buffer.
*/
Buffer m_deinterleavebuf;
/**
* Invalidates the jack device.
* \param data The jack device that gets invalidet by jack.
*/
AUD_LOCAL static void jack_shutdown(void* data);
/**
* Mixes the next bytes into the buffer.
* \param length The length in samples to be filled.
* \param data A pointer to the jack device.
* \return 0 what shows success.
*/
AUD_LOCAL static int jack_mix(jack_nframes_t length, void* data);
AUD_LOCAL static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
/**
* Last known JACK Transport state used for stop callbacks.
*/
jack_transport_state_t m_lastState;
/**
* Last known JACK Transport state used for stop callbacks.
*/
jack_transport_state_t m_lastMixState;
/**
* Time for a synchronisation request.
*/
std::atomic<float> m_syncTime;
/**
* Sync revision used to notify the mixing thread that a sync call is necessary.
*/
std::atomic<int> m_syncCallRevision;
/**
* The sync revision that the last sync call in the mixing thread handled.
*/
std::atomic<int> m_lastSyncCallRevision;
/**
* Sync revision that is increased every time jack transport enters the rolling state.
*/
int m_rollingSyncRevision;
/**
* The last time the jack_sync callback saw the rolling sync revision.
*
* Used to ensure the sync callback will be called when consecutive syncs target the same sync time.
*/
int m_lastRollingSyncRevision;
/**
* External syncronisation callback function.
*/
syncFunction m_syncFunc;
/**
* Data for the sync function.
*/
void* m_syncFuncData;
AUD_LOCAL void preMixingWork(bool playing) override;
// delete copy constructor and operator=
JackDevice(const JackDevice&) = delete;
JackDevice& operator=(const JackDevice&) = delete;
protected:
virtual void playing(bool playing);
public:
/**
* Creates a JACK client for audio output.
* \param name The client name.
* \param specs The wanted audio specification, where only the channel count
* is important.
* \param buffersize The size of the internal buffer.
* \exception Exception Thrown if the audio device cannot be opened.
*/
JackDevice(const std::string &name, DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
/**
* Closes the JACK client.
*/
virtual ~JackDevice();
/**
* Starts jack transport playback.
*/
void playSynchronizer();
/**
* Stops jack transport playback.
*/
void stopSynchronizer();
/**
* Seeks jack transport playback.
* \param time The time to seek to.
*/
void seekSynchronizer(double time);
/**
* Sets the sync callback for jack transport playback.
* \param sync The callback function.
* \param data The data for the function.
*/
void setSyncCallback(syncFunction sync, void* data);
/**
* Retrieves the jack transport playback time.
* \return The current time position.
*/
double getSynchronizerPosition();
/**
* Returns whether jack transport plays back.
* \return Whether jack transport plays back.
*/
int isSynchronizerPlaying();
/**
* Registers this plugin.
*/
static void registerPlugin();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,59 @@
/*******************************************************************************
* 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.
******************************************************************************/
#define JACK_LIBRARY_IMPLEMENTATION
#include <string>
#include <array>
#include "JackLibrary.h"
#ifdef DYNLOAD_JACK
#include "plugin/PluginManager.h"
#endif
AUD_NAMESPACE_BEGIN
bool loadJACK()
{
#ifdef DYNLOAD_JACK
std::array<const std::string, 5> names = {"libjack.so", "libjack.so.0", "libjack.so.1", "libjack.so.2", "libjack.dll"};
void* handle = nullptr;
for(auto& name : names)
{
handle = PluginManager::openLibrary(name);
if(handle)
break;
}
if (!handle)
return false;
#define JACK_SYMBOL(sym) AUD_##sym = reinterpret_cast<decltype(&sym)>(PluginManager::lookupLibrary(handle, #sym))
#else
#define JACK_SYMBOL(sym) AUD_##sym = &sym
#endif
#include "JackSymbols.h"
#undef JACK_SYMBOL
return AUD_jack_client_open != nullptr;
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,47 @@
/*******************************************************************************
* 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.
******************************************************************************/
#pragma once
#ifdef JACK_PLUGIN
#define AUD_BUILD_PLUGIN
#endif
/**
* @file JackLibrary.h
* @ingroup plugin
*/
#include "Audaspace.h"
#include <jack/jack.h>
#include <jack/ringbuffer.h>
AUD_NAMESPACE_BEGIN
#ifdef JACK_LIBRARY_IMPLEMENTATION
#define JACK_SYMBOL(sym) decltype(&sym) AUD_##sym
#else
#define JACK_SYMBOL(sym) extern decltype(&sym) AUD_##sym
#endif
#include "JackSymbols.h"
#undef JACK_SYMBOL
bool loadJACK();
AUD_NAMESPACE_END

View File

@@ -0,0 +1,47 @@
/*******************************************************************************
* 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.
******************************************************************************/
JACK_SYMBOL(jack_frames_since_cycle_start);
JACK_SYMBOL(jack_transport_query);
JACK_SYMBOL(jack_transport_locate);
JACK_SYMBOL(jack_transport_start);
JACK_SYMBOL(jack_transport_stop);
JACK_SYMBOL(jack_ringbuffer_reset);
JACK_SYMBOL(jack_ringbuffer_write);
JACK_SYMBOL(jack_ringbuffer_write_space);
JACK_SYMBOL(jack_ringbuffer_write_advance);
JACK_SYMBOL(jack_ringbuffer_read);
JACK_SYMBOL(jack_ringbuffer_create);
JACK_SYMBOL(jack_ringbuffer_free);
JACK_SYMBOL(jack_ringbuffer_read_space);
JACK_SYMBOL(jack_set_sync_callback);
JACK_SYMBOL(jack_port_get_buffer);
JACK_SYMBOL(jack_client_open);
JACK_SYMBOL(jack_set_process_callback);
JACK_SYMBOL(jack_on_shutdown);
JACK_SYMBOL(jack_port_register);
JACK_SYMBOL(jack_client_close);
JACK_SYMBOL(jack_get_sample_rate);
JACK_SYMBOL(jack_get_buffer_size);
JACK_SYMBOL(jack_activate);
JACK_SYMBOL(jack_get_ports);
JACK_SYMBOL(jack_port_name);
JACK_SYMBOL(jack_connect);
JACK_SYMBOL(jack_free);