Skip to content

Commit 7ce73af

Browse files
committed
ffi_client wip
1 parent 944fc94 commit 7ce73af

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

examples/basic_room/room.py

Whitespace-only changes.

livekit/_ffi_client.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import ctypes, sys, os
1+
from ctypes import *
2+
import sys, os
23
import livekit._proto.ffi_pb2 as proto
34

45
basedir = os.path.abspath(os.path.dirname(__file__))
@@ -10,7 +11,14 @@
1011
libfile = 'liblivekit_ffi.so'
1112
libpath = os.path.join(basedir, libfile)
1213

13-
ffi_lib = ctypes.CDLL(libpath)
14+
ffi_lib = CDLL(libpath)
15+
16+
# C function types
17+
ffi_lib.livekit_ffi_request.argtypes = [POINTER(c_ubyte), c_size_t, POINTER(POINTER(c_ubyte)), c_size_t]
18+
ffi_lib.livekit_ffi_request.restype = c_size_t
19+
20+
ffi_lib.livekit_ffi_drop_handle.argtypes = [c_size_t]
21+
ffi_lib.livekit_ffi_drop_handle.restype = c_bool
1422

1523
INVALID_HANDLE = 0
1624

@@ -19,7 +27,18 @@ def __init__(self):
1927
pass
2028

2129
def request(self, req: proto.FFIRequest) -> proto.FFIResponse:
22-
pass
30+
data = bytearray(req.SerializeToString())
31+
data_len = len(data)
32+
resp_ptr = POINTER(c_ubyte)()
33+
resp_len = c_size_t()
34+
handle = ffi_lib.livekit_ffi_request(data, data_len, byref(resp_ptr), byref(resp_len))
35+
36+
resp_data = bytearray(resp_ptr[:resp_len.value])
37+
resp = proto.FFIResponse()
38+
resp.ParseFromString(resp_data)
39+
40+
FfiHandle(handle)
41+
return resp
2342

2443
class FfiHandle:
2544
handle = INVALID_HANDLE
@@ -29,4 +48,4 @@ def __init__(self, handle: int):
2948

3049
def __del__(self):
3150
if self.handle != INVALID_HANDLE:
32-
assert(ffi_lib.livekit_ffi_drop_handle(self.handle))
51+
assert(ffi_lib.livekit_ffi_drop_handle(c_size_t(self.handle)))

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build-system]
2+
requires = ["flit_core >=3.2,<4"]
3+
build-backend = "flit_core.buildapi"
4+
5+
[project]
6+
name = "livekit"
7+
authors = [{name = "Theo Monnom", email = "[email protected]"}]
8+
license = {file = "LICENSE"}
9+
classifiers = ["License :: OSI Approved :: Apache Software License"]
10+
dynamic = ["version", "description"]
11+
12+
[project.urls]
13+
"Homepage" = "https://github.com/livekit/client-sdk-python"

0 commit comments

Comments
 (0)