mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-15 16:03:55 +02:00
Allow resizing shared memory buffers
This commit is contained in:
@@ -36,9 +36,32 @@ AudioShmBuffer::~AudioShmBuffer() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioShmBuffer::resize(const Config& new_config) {
|
||||||
|
if (new_config.name != config.name) {
|
||||||
|
throw std::invalid_argument("Expected buffer configuration for \"" +
|
||||||
|
config.name + "\", got \"" +
|
||||||
|
new_config.name + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
config = new_config;
|
||||||
|
shm.truncate(config.size);
|
||||||
|
buffer =
|
||||||
|
boost::interprocess::mapped_region(shm, boost::interprocess::read_write,
|
||||||
|
0, config.size, nullptr, MAP_LOCKED);
|
||||||
|
}
|
||||||
|
|
||||||
AudioShmBuffer::AudioShmBuffer(AudioShmBuffer&& o) noexcept
|
AudioShmBuffer::AudioShmBuffer(AudioShmBuffer&& o) noexcept
|
||||||
: config(std::move(o.config)),
|
: config(std::move(o.config)),
|
||||||
shm(std::move(o.shm)),
|
shm(std::move(o.shm)),
|
||||||
buffer(std::move(o.buffer)) {
|
buffer(std::move(o.buffer)) {
|
||||||
o.is_moved = true;
|
o.is_moved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioShmBuffer& AudioShmBuffer::operator=(AudioShmBuffer&& o) noexcept {
|
||||||
|
config = std::move(o.config);
|
||||||
|
shm = std::move(o.shm);
|
||||||
|
buffer = std::move(o.buffer);
|
||||||
|
o.is_moved = true;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|||||||
+15
-4
@@ -121,11 +121,21 @@ class AudioShmBuffer {
|
|||||||
AudioShmBuffer& operator=(const AudioShmBuffer&) = delete;
|
AudioShmBuffer& operator=(const AudioShmBuffer&) = delete;
|
||||||
|
|
||||||
AudioShmBuffer(AudioShmBuffer&&) noexcept;
|
AudioShmBuffer(AudioShmBuffer&&) noexcept;
|
||||||
AudioShmBuffer& operator=(AudioShmBuffer&&) = delete;
|
AudioShmBuffer& operator=(AudioShmBuffer&&) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapt to a new buffer size or channel layout. The name of the buffer
|
||||||
|
* needs to remain the same.
|
||||||
|
*
|
||||||
|
* @throw `std::invalid_argument` If the config is for a buffer with a
|
||||||
|
* different name.
|
||||||
|
*/
|
||||||
|
void resize(const Config& new_config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a pointer to the part of the buffer where this input audio channel is
|
* Get a pointer to the part of the buffer where this input audio channel is
|
||||||
* stored in. Both the bus and the channel indices start at zero.
|
* stored in. Both the bus and the channel indices start at zero. These
|
||||||
|
* addresses might change after a call to `resize()`.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* input_channel_ptr(const uint32_t bus, const uint32_t channel) {
|
T* input_channel_ptr(const uint32_t bus, const uint32_t channel) {
|
||||||
@@ -135,7 +145,8 @@ class AudioShmBuffer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a pointer to the part of the buffer where this output audio channel
|
* Get a pointer to the part of the buffer where this output audio channel
|
||||||
* is stored in. Both the bus and the channel indices start at zero.
|
* is stored in. Both the bus and the channel indices start at zero. These
|
||||||
|
* addresses might change after a call to `resize()`.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* output_channel_ptr(const uint32_t bus, const uint32_t channel) {
|
T* output_channel_ptr(const uint32_t bus, const uint32_t channel) {
|
||||||
@@ -143,7 +154,7 @@ class AudioShmBuffer {
|
|||||||
config.output_offsets[bus][channel];
|
config.output_offsets[bus][channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Config config;
|
Config config;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::interprocess::shared_memory_object shm;
|
boost::interprocess::shared_memory_object shm;
|
||||||
|
|||||||
Reference in New Issue
Block a user