Skip to content

Commit d5a4299

Browse files
LIVEKIT_INTERNAL_API bool dropFfiHandle
1 parent 958624f commit d5a4299

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎src/ffi_client.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ extern "C" void livekit_ffi_dispose();
6767

6868
extern "C" LIVEKIT_INTERNAL_API void ffiEventCallback(const uint8_t* buf, size_t len);
6969

70+
/// @brief Release a Rust FFI handle and report whether it existed.
71+
/// Internal ownership test seam; not part of the public SDK API.
72+
/// @param handle Rust resource handle to release.
73+
/// @return True if the handle was released; false if it did not exist.
74+
[[nodiscard]] LIVEKIT_INTERNAL_API bool dropFfiHandle(std::uint64_t handle) noexcept;
75+
7076
// The FfiClient is used to communicate with the FFI interface of the Rust SDK
7177
// We use the generated protocol messages to facilitate the communication.
7278
class LIVEKIT_INTERNAL_API FfiClient {

‎src/ffi_handle.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
#include "livekit/ffi_handle.h"
1818

19+
#include "ffi_client.h"
1920
#include "livekit_ffi.h"
2021

2122
namespace livekit {
2223

24+
bool dropFfiHandle(std::uint64_t handle) noexcept { return livekit_ffi_drop_handle(handle); }
25+
2326
FfiHandle::FfiHandle(uintptr_t h) noexcept : handle_(h) {}
2427

2528
FfiHandle::~FfiHandle() { reset(); }
@@ -35,7 +38,7 @@ FfiHandle& FfiHandle::operator=(FfiHandle&& other) noexcept {
3538

3639
void FfiHandle::reset(uintptr_t new_handle) noexcept {
3740
if (handle_) {
38-
livekit_ffi_drop_handle(handle_);
41+
static_cast<void>(dropFfiHandle(handle_));
3942
}
4043
handle_ = new_handle;
4144
}

‎src/tests/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ if(UNIT_TEST_SOURCES)
8989
target_link_libraries(livekit_unit_tests
9090
PRIVATE
9191
livekit
92-
livekit_ffi # Capture ownership tests verify Rust handle disposal directly.
9392
spdlog::spdlog
9493
${LIVEKIT_PROTOBUF_TARGET}
9594
GTest::gtest_main

‎src/tests/unit/test_capture_source.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "capture.pb.h"
2626
#include "capture_source_internal.h"
2727
#include "ffi_client.h"
28-
#include "livekit_ffi.h"
2928

3029
namespace livekit {
3130

@@ -169,8 +168,8 @@ TEST_F(CaptureSourceCallbackTest, AbandonedAndInvalidResultsReleaseBothRustHandl
169168
EXPECT_THROW(static_cast<void>(future.get()), CaptureSourceError);
170169
}
171170
// A second drop must fail. If ownership leaked, this also cleans it up.
172-
EXPECT_FALSE(livekit_ffi_drop_handle(capture.handle().id()));
173-
EXPECT_FALSE(livekit_ffi_drop_handle(video.handle().id()));
171+
EXPECT_FALSE(dropFfiHandle(capture.handle().id()));
172+
EXPECT_FALSE(dropFfiHandle(video.handle().id()));
174173
EXPECT_EQ(FfiClientTestAccess::listenerCount(), 0u);
175174
}
176175
}

0 commit comments

Comments
 (0)