From c371a0f929d6ad3fd05912715fe7fbff6da4bfe0 Mon Sep 17 00:00:00 2001 From: tnoho Date: Thu, 2 Jan 2025 15:45:09 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88=E3=81=9A?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=82=AF=E3=81=97=E3=81=AA=E3=81=8F=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sora_sdk/__init__.py | 26 ++++++++++++++++++++++++++ src/sora_sdk_ext.cpp | 34 +--------------------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/sora_sdk/__init__.py b/src/sora_sdk/__init__.py index 227fb0c6..18283742 100644 --- a/src/sora_sdk/__init__.py +++ b/src/sora_sdk/__init__.py @@ -36,3 +36,29 @@ def __init__(self, track): def __del__(self): super().__del__() del self.__track + + +class Sora(SoraImpl): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._connections = [] + + def __del__(self): + self._connections.clear() + + def create_connection(self, *args, **kwargs): + # 新しい接続を生成してリストに追加 + conn = super().create_connection(*args, **kwargs) + self._connections.append(conn) + return conn + + def _remove_connection(self, conn): + # 閉じられた接続をリストから除外 + if conn in self._connections: + self._connections.remove(conn) + + def create_audio_source(self, *args): + return super().create_audio_source(*args) + + def create_video_source(self): + return super().create_video_source() \ No newline at end of file diff --git a/src/sora_sdk_ext.cpp b/src/sora_sdk_ext.cpp index c3d0b409..b97f2ed8 100644 --- a/src/sora_sdk_ext.cpp +++ b/src/sora_sdk_ext.cpp @@ -288,38 +288,6 @@ PyType_Slot connection_slots[] = { {Py_tp_clear, (void*)connection_tp_clear}, {0, nullptr}}; -int sora_tp_traverse(PyObject* self, visitproc visit, void* arg) { - if (!nb::inst_ready(self)) { - return 0; - } - - Sora* sora = nb::inst_ptr(self); - for (auto wc : sora->weak_connections_) { - auto conn = wc.lock(); - if (conn) { - nb::object conn_obj = nb::find(conn); - Py_VISIT(conn_obj.ptr()); - } - } - - return 0; -} - -int sora_tp_clear(PyObject* self) { - if (!nb::inst_ready(self)) { - return 0; - } - - Sora* sora = nb::inst_ptr(self); - sora->weak_connections_.clear(); - - return 0; -} - -PyType_Slot sora_slots[] = {{Py_tp_traverse, (void*)sora_tp_traverse}, - {Py_tp_clear, (void*)sora_tp_clear}, - {0, nullptr}}; - /** * Python で利用するすべてのクラスと定数は以下のように定義しなければならない */ @@ -561,7 +529,7 @@ NB_MODULE(sora_sdk_ext, m) { .def("__del__", &SoraVideoFrameTransformer::Del) .def_rw("on_transform", &SoraVideoFrameTransformer::on_transform_); - nb::class_(m, "Sora", nb::type_slots(sora_slots)) + nb::class_(m, "SoraImpl") .def(nb::init, std::optional>(), "use_hardware_encoder"_a = nb::none(), "openh264"_a = nb::none()) .def("create_connection", &Sora::CreateConnection, "signaling_urls"_a,