Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Main global runtime state (in `serum-decode.cpp`):
- Current output: `mySerum` (`Serum_Frame_Struc`).
- Scene playback state: `sceneFrameCount`, `sceneCurrentFrame`, duration/flags/repeat, etc.
- Identification state: `lastfound`, `lastfound_normal`, `lastfound_scene`, CRC tracking.
- Public C API entrypoints are serialized through a recursive runtime mutex
because this state is process-global and scene rendering may re-enter
colorization internally. `Serum_Rotate()` must not run concurrently with
`Serum_Colorize()` while shared output buffers, flags, widths, rotation
tables, or scene state are being updated.
- Scene lookup acceleration:
- `g_serumData.frameIsScene`: frame ID -> scene/non-scene marker.
- `g_serumData.sceneFramesBySignature`: `(mask,shape,hash)` -> matching scene frame IDs.
Expand Down
16 changes: 11 additions & 5 deletions src/serum-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,18 @@ static void EnsureWindowsCrashHandlerInstalled() {
}
#endif

static std::recursive_mutex g_serumApiMutex;

#if defined(_WIN32) || defined(_WIN64)
#define SERUM_API_GUARD_START(apiName) \
ClearLastErrorMessage(); \
EnsureWindowsCrashHandlerInstalled(); \
#define SERUM_API_GUARD_START(apiName) \
ClearLastErrorMessage(); \
EnsureWindowsCrashHandlerInstalled(); \
std::lock_guard<std::recursive_mutex> serumApiLock(g_serumApiMutex); \
try {
#else
#define SERUM_API_GUARD_START(apiName) \
ClearLastErrorMessage(); \
#define SERUM_API_GUARD_START(apiName) \
ClearLastErrorMessage(); \
std::lock_guard<std::recursive_mutex> serumApiLock(g_serumApiMutex); \
try {
#endif

Expand Down Expand Up @@ -5269,12 +5273,14 @@ static uint32_t Serum_ColorizeWithMetadatav2Internal(uint8_t* frame,

SERUM_API uint32_t
Serum_ColorizeWithMetadatav2(uint8_t* frame, bool sceneFrameRequested = false) {
SERUM_API_GUARD_START("Serum_ColorizeWithMetadatav2")
BeginProfileFrameOperation();
const uint32_t result = Serum_ColorizeWithMetadatav2Internal(
frame, sceneFrameRequested, IDENTIFY_NO_FRAME);
EndProfileFrameOperation();
MaybeLogDynamicHotPathProfileWindow(sceneFrameRequested);
return result;
SERUM_API_GUARD_END("Serum_ColorizeWithMetadatav2", IDENTIFY_NO_FRAME)
}

SERUM_API uint32_t Serum_Colorize(uint8_t* frame) {
Expand Down
Loading