format: reformatting files

This commit is contained in:
2026-07-13 15:30:43 +08:00
parent 7522543c48
commit e5eeaddf2f
511 changed files with 274803 additions and 207140 deletions
+9 -9
View File
@@ -15,13 +15,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
render/ipc/frameslotpool.cpp
render/ipc/frameslotpool.h
render/ipc/ipcmessage.cpp
render/ipc/ipcmessage.h
render/ipc/sharedmemoryregion.cpp
render/ipc/sharedmemoryregion.h
render/ipc/spscringbuffer.h
PARENT_SCOPE
${OLIVE_SOURCES}
render/ipc/frameslotpool.cpp
render/ipc/frameslotpool.h
render/ipc/ipcmessage.cpp
render/ipc/ipcmessage.h
render/ipc/sharedmemoryregion.cpp
render/ipc/sharedmemoryregion.h
render/ipc/spscringbuffer.h
PARENT_SCOPE
)
+17 -11
View File
@@ -36,18 +36,21 @@ size_t AlignUp(size_t value, size_t align)
return (value + (align - 1)) & ~(align - 1);
}
constexpr size_t kAlign = 64; // Cache-line alignment for each sub-region.
constexpr size_t kAlign = 64; // Cache-line alignment for each sub-region.
} // namespace
} // namespace
size_t FrameSlotPool::BytesNeeded(uint32_t slot_count, size_t slot_data_bytes)
{
const uint32_t ring_cap = RingCapacity(slot_count);
size_t total = AlignUp(sizeof(Header), kAlign);
total += AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // free ring
total += AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // ready ring
total += AlignUp(sizeof(FrameSlotMeta) * slot_count, kAlign); // metadata array
total += AlignUp(slot_data_bytes, kAlign) * slot_count; // pixel data blocks
total +=
AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // free ring
total +=
AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // ready ring
total +=
AlignUp(sizeof(FrameSlotMeta) * slot_count, kAlign); // metadata array
total += AlignUp(slot_data_bytes, kAlign) * slot_count; // pixel data blocks
return total;
}
@@ -111,9 +114,12 @@ FrameSlotPool FrameSlotPool::Attach(void *mem)
return pool;
}
pool.free_ring_ = SpscRingBuffer::Attach(pool.base_ + pool.header_->free_ring_offset);
pool.ready_ring_ = SpscRingBuffer::Attach(pool.base_ + pool.header_->ready_ring_offset);
pool.meta_ = reinterpret_cast<FrameSlotMeta *>(pool.base_ + pool.header_->meta_offset);
pool.free_ring_ =
SpscRingBuffer::Attach(pool.base_ + pool.header_->free_ring_offset);
pool.ready_ring_ =
SpscRingBuffer::Attach(pool.base_ + pool.header_->ready_ring_offset);
pool.meta_ = reinterpret_cast<FrameSlotMeta *>(pool.base_ +
pool.header_->meta_offset);
pool.data_ = pool.base_ + pool.header_->data_offset;
return pool;
@@ -169,5 +175,5 @@ bool FrameSlotPool::Release(uint32_t index)
return free_ring_->Push(index);
}
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
+13 -13
View File
@@ -40,16 +40,16 @@ namespace ipc
* not guaranteed shared-memory-safe).
*/
struct FrameSlotMeta {
int64_t id; ///< Caller-defined tag (e.g. ticket id, or footage stream hash).
int64_t time_num; ///< Frame timestamp numerator.
int64_t time_den; ///< Frame timestamp denominator.
int64_t id; ///< Caller-defined tag (e.g. ticket id, or footage stream hash).
int64_t time_num; ///< Frame timestamp numerator.
int64_t time_den; ///< Frame timestamp denominator.
int32_t width;
int32_t height;
int32_t format; ///< olive::PixelFormat::Format value.
int32_t format; ///< olive::PixelFormat::Format value.
int32_t channel_count;
int32_t linesize; ///< Bytes per scanline (stride).
int32_t data_size; ///< Valid bytes written into the slot's data block.
char colorspace[128]; ///< Input colorspace name for color-managed footage.
int32_t linesize; ///< Bytes per scanline (stride).
int32_t data_size; ///< Valid bytes written into the slot's data block.
char colorspace[128]; ///< Input colorspace name for color-managed footage.
};
/**
@@ -90,7 +90,8 @@ public:
* Initializes both rings, seeds the free ring with every slot index, and zeroes metadata.
* `mem` must provide at least BytesNeeded(slot_count, slot_data_bytes) bytes.
*/
static FrameSlotPool Create(void *mem, uint32_t slot_count, size_t slot_data_bytes);
static FrameSlotPool Create(void *mem, uint32_t slot_count,
size_t slot_data_bytes);
/**
* @brief Map an existing, already-initialized pool (peer side).
@@ -148,7 +149,6 @@ public:
FrameSlotPool() = default;
private:
struct Header {
uint32_t magic;
uint32_t slot_count;
@@ -160,7 +160,7 @@ private:
uint64_t data_offset;
};
static constexpr uint32_t kMagic = 0x4F4B5350; // 'OKSP'
static constexpr uint32_t kMagic = 0x4F4B5350; // 'OKSP'
// Ring capacity must exceed slot_count by one because a ring can hold at most capacity-1 entries
// and we need to be able to enqueue every slot at once.
@@ -177,7 +177,7 @@ private:
uint8_t *data_ = nullptr;
};
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
#endif // IPC_FRAMESLOTPOOL_H
#endif // IPC_FRAMESLOTPOOL_H
+2 -2
View File
@@ -227,5 +227,5 @@ bool LoadGraphMsg::FromJson(const QJsonObject &o, LoadGraphMsg *out)
return true;
}
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
+25 -20
View File
@@ -63,7 +63,7 @@ constexpr const char *kCancel = "cancel";
constexpr const char *kGraphUpdate = "graph_update";
constexpr const char *kShutdown = "shutdown";
constexpr const char *kError = "error";
} // namespace msgtype
} // namespace msgtype
/**
* @brief Write one NDJSON message line to `device`.
@@ -92,29 +92,34 @@ bool ReadMessage(QByteArray *buffer, QJsonObject *out, bool *ok = nullptr);
struct HandshakeMsg {
int protocol_version = 0;
QString shm_key; ///< Worker->main output shared-memory segment key.
QString input_shm_key; ///< Main->worker input shared-memory segment key (optional).
int input_slots = 0; ///< Number of main->worker input frame slots.
int output_slots = 0; ///< Number of worker->main output frame slots.
qint64 slot_data_bytes = 0; ///< Per-output-slot pixel block size.
qint64 input_slot_data_bytes = 0; ///< Per-input-slot pixel block size.
QString shm_key; ///< Worker->main output shared-memory segment key.
QString
input_shm_key; ///< Main->worker input shared-memory segment key (optional).
int input_slots = 0; ///< Number of main->worker input frame slots.
int output_slots = 0; ///< Number of worker->main output frame slots.
qint64 slot_data_bytes = 0; ///< Per-output-slot pixel block size.
qint64 input_slot_data_bytes = 0; ///< Per-input-slot pixel block size.
QJsonObject ToJson() const;
static bool FromJson(const QJsonObject &o, HandshakeMsg *out);
};
struct RenderFrameMsg {
qint64 ticket_id = 0; ///< Correlates this request with the eventual frame_ready.
QString node_uuid; ///< Output/viewer node to render, by stable uuid in the loaded graph.
qint64 ticket_id =
0; ///< Correlates this request with the eventual frame_ready.
QString
node_uuid; ///< Output/viewer node to render, by stable uuid in the loaded graph.
qint64 time_num = 0;
qint64 time_den = 1;
int width = 0; ///< Forced output size (0 = use graph default).
int width = 0; ///< Forced output size (0 = use graph default).
int height = 0;
int format = -1; ///< Forced PixelFormat::Format (-1 = default/INVALID).
int channel_count = 0; ///< 0 = default.
int mode = 0; ///< RenderMode::Mode.
int input_slot = -1; ///< Optional main->worker decoded input slot for footage nodes.
QVector<int> input_slots; ///< Optional ordered decoded input slots for footage nodes.
int format = -1; ///< Forced PixelFormat::Format (-1 = default/INVALID).
int channel_count = 0; ///< 0 = default.
int mode = 0; ///< RenderMode::Mode.
int input_slot =
-1; ///< Optional main->worker decoded input slot for footage nodes.
QVector<int>
input_slots; ///< Optional ordered decoded input slots for footage nodes.
// Output color transform to apply before returning the frame. When empty,
// the worker returns the image in the project's reference space.
@@ -130,7 +135,7 @@ struct RenderFrameMsg {
struct FrameReadyMsg {
qint64 ticket_id = 0;
int output_slot = 0; ///< Index into the worker->main output FrameSlotPool.
int output_slot = 0; ///< Index into the worker->main output FrameSlotPool.
QJsonObject ToJson() const;
static bool FromJson(const QJsonObject &o, FrameReadyMsg *out);
@@ -144,13 +149,13 @@ struct CancelMsg {
};
struct LoadGraphMsg {
QString path; ///< Temporary file holding the serialized node graph.
QString path; ///< Temporary file holding the serialized node graph.
QJsonObject ToJson() const;
static bool FromJson(const QJsonObject &o, LoadGraphMsg *out);
};
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
#endif // IPC_IPCMESSAGE_H
#endif // IPC_IPCMESSAGE_H
+16 -10
View File
@@ -75,16 +75,20 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
const std::wstring wname = mapping_name.toStdWString();
if (mode == kCreate) {
const DWORD size_high = static_cast<DWORD>((quint64(size) >> 32) & 0xFFFFFFFF);
const DWORD size_high =
static_cast<DWORD>((quint64(size) >> 32) & 0xFFFFFFFF);
const DWORD size_low = static_cast<DWORD>(quint64(size) & 0xFFFFFFFF);
handle_ = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE,
size_high, size_low, wname.c_str());
handle_ = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr,
PAGE_READWRITE, size_high, size_low,
wname.c_str());
if (!handle_) {
error_ = QStringLiteral("CreateFileMapping failed: %1").arg(GetLastError());
error_ = QStringLiteral("CreateFileMapping failed: %1")
.arg(GetLastError());
return false;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
error_ = QStringLiteral("Shared memory key already exists: %1").arg(key);
error_ =
QStringLiteral("Shared memory key already exists: %1").arg(key);
CloseHandle(handle_);
handle_ = nullptr;
return false;
@@ -92,7 +96,8 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
} else {
handle_ = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, wname.c_str());
if (!handle_) {
error_ = QStringLiteral("OpenFileMapping failed: %1").arg(GetLastError());
error_ =
QStringLiteral("OpenFileMapping failed: %1").arg(GetLastError());
return false;
}
}
@@ -124,7 +129,7 @@ void SharedMemoryRegion::Close()
size_ = 0;
}
#else // POSIX
#else // POSIX
bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
{
@@ -165,7 +170,8 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
data_ = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
if (data_ == MAP_FAILED) {
error_ = QStringLiteral("mmap failed: %1").arg(QString::fromUtf8(strerror(errno)));
error_ = QStringLiteral("mmap failed: %1")
.arg(QString::fromUtf8(strerror(errno)));
data_ = nullptr;
::close(fd_);
fd_ = -1;
@@ -201,5 +207,5 @@ void SharedMemoryRegion::Close()
#endif
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
+6 -6
View File
@@ -110,14 +110,14 @@ private:
QString error_;
#if defined(Q_OS_WIN)
void *handle_; // HANDLE from CreateFileMapping/OpenFileMapping
void *handle_; // HANDLE from CreateFileMapping/OpenFileMapping
#else
int fd_; // file descriptor from shm_open
QString shm_name_; // the platform-prefixed name actually passed to shm_open
int fd_; // file descriptor from shm_open
QString shm_name_; // the platform-prefixed name actually passed to shm_open
#endif
};
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
#endif // IPC_SHAREDMEMORYREGION_H
#endif // IPC_SHAREDMEMORYREGION_H
+6 -5
View File
@@ -174,11 +174,12 @@ private:
std::atomic<uint32_t> tail_;
uint32_t capacity_;
static_assert(sizeof(std::atomic<uint32_t>) == sizeof(uint32_t),
"atomic<uint32_t> must be lock-free POD-sized for shared memory use");
static_assert(
sizeof(std::atomic<uint32_t>) == sizeof(uint32_t),
"atomic<uint32_t> must be lock-free POD-sized for shared memory use");
};
} // namespace ipc
} // namespace olive
} // namespace ipc
} // namespace olive
#endif // IPC_SPSCRINGBUFFER_H
#endif // IPC_SPSCRINGBUFFER_H