From 5cb491b70b378a23c7a7dc4cb95e9fe04bcfab96 Mon Sep 17 00:00:00 2001 From: sunxilin Date: Tue, 7 Jan 2025 11:53:14 +0800 Subject: [PATCH] fix: fix asan detect error --- .../simple_echo_python/BUILD.gn | 32 ++++++ .../simple_echo_python/LICENSE | 13 +++ .../simple_echo_python/__init__.py | 1 + .../simple_echo_python/addon.py | 17 +++ .../simple_echo_python/extension.py | 102 ++++++++++++++++++ .../simple_echo_python/manifest.json | 13 +++ .../simple_echo_python/property.json | 1 + .../simple_echo_python/requirements.txt | 0 .../nodejs/mix_python_ext_nodejs/BUILD.gn | 2 +- .../mix_python_ext_nodejs_app/manifest.json | 2 +- .../mix_python_ext_nodejs_app/property.json | 6 +- .../nodejs/mix_python_ext_nodejs/test_case.py | 1 - 12 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 packages/example_extensions/simple_echo_python/BUILD.gn create mode 100644 packages/example_extensions/simple_echo_python/LICENSE create mode 100644 packages/example_extensions/simple_echo_python/__init__.py create mode 100644 packages/example_extensions/simple_echo_python/addon.py create mode 100644 packages/example_extensions/simple_echo_python/extension.py create mode 100644 packages/example_extensions/simple_echo_python/manifest.json create mode 100644 packages/example_extensions/simple_echo_python/property.json create mode 100644 packages/example_extensions/simple_echo_python/requirements.txt diff --git a/packages/example_extensions/simple_echo_python/BUILD.gn b/packages/example_extensions/simple_echo_python/BUILD.gn new file mode 100644 index 0000000000..c195803f2e --- /dev/null +++ b/packages/example_extensions/simple_echo_python/BUILD.gn @@ -0,0 +1,32 @@ +# +# This file is part of TEN Framework, an open source project. +# Licensed under the Apache License, Version 2.0. +# See the LICENSE file for more information. +# +import("//build/feature/ten_package.gni") +import("//build/ten_runtime/feature/publish.gni") +import("//build/ten_runtime/glob.gni") +import("//build/ten_runtime/options.gni") + +ten_package("simple_echo_python") { + package_kind = "extension" + + resources = [ + "__init__.py", + "addon.py", + "extension.py", + "manifest.json", + "property.json", + "requirements.txt", + ] + + deps = [ "//core/src/ten_runtime" ] +} + +if (ten_enable_ten_manager) { + ten_package_publish("upload_simple_echo_python_to_server") { + base_dir = + rebase_path("${root_out_dir}/ten_packages/extension/simple_echo_python") + deps = [ ":simple_echo_python" ] + } +} diff --git a/packages/example_extensions/simple_echo_python/LICENSE b/packages/example_extensions/simple_echo_python/LICENSE new file mode 100644 index 0000000000..ff6db6373e --- /dev/null +++ b/packages/example_extensions/simple_echo_python/LICENSE @@ -0,0 +1,13 @@ +Copyright © 2025 Agora + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/example_extensions/simple_echo_python/__init__.py b/packages/example_extensions/simple_echo_python/__init__.py new file mode 100644 index 0000000000..f3c731cdd5 --- /dev/null +++ b/packages/example_extensions/simple_echo_python/__init__.py @@ -0,0 +1 @@ +from . import addon diff --git a/packages/example_extensions/simple_echo_python/addon.py b/packages/example_extensions/simple_echo_python/addon.py new file mode 100644 index 0000000000..20d201dee2 --- /dev/null +++ b/packages/example_extensions/simple_echo_python/addon.py @@ -0,0 +1,17 @@ +# +# This file is part of TEN Framework, an open source project. +# Licensed under the Apache License, Version 2.0. +# See the LICENSE file for more information. +# +from ten import ( + Addon, + register_addon_as_extension, + TenEnv, +) +from .extension import SimpleEchoExtension + + +@register_addon_as_extension("simple_echo_python") +class SimpleEchoExtensionAddon(Addon): + def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None: + ten_env.on_create_instance_done(SimpleEchoExtension(name), context) diff --git a/packages/example_extensions/simple_echo_python/extension.py b/packages/example_extensions/simple_echo_python/extension.py new file mode 100644 index 0000000000..0d4887c5cb --- /dev/null +++ b/packages/example_extensions/simple_echo_python/extension.py @@ -0,0 +1,102 @@ +# +# This file is part of TEN Framework, an open source project. +# Licensed under the Apache License, Version 2.0. +# See the LICENSE file for more information. +# +from ten import ( + AudioFrame, + VideoFrame, + AsyncExtension, + AsyncTenEnv, + Cmd, + StatusCode, + CmdResult, + Data, +) + + +class SimpleEchoExtension(AsyncExtension): + async def on_init(self, ten_env: AsyncTenEnv) -> None: + ten_env.log_debug("on_init") + + async def on_start(self, ten_env: AsyncTenEnv) -> None: + ten_env.log_debug("on_start") + + # TODO: read properties, initialize resources + + async def on_stop(self, ten_env: AsyncTenEnv) -> None: + ten_env.log_debug("on_stop") + + # TODO: clean up resources + + async def on_deinit(self, ten_env: AsyncTenEnv) -> None: + ten_env.log_debug("on_deinit") + + async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: + cmd_name = cmd.get_name() + ten_env.log_debug("on_cmd name {}".format(cmd_name)) + + cmd_result = CmdResult.create(StatusCode.OK) + cmd_result.set_property_string("detail", cmd_name + ", too") + + await ten_env.return_result(cmd_result, cmd) + + async def on_data(self, ten_env: AsyncTenEnv, data: Data) -> None: + data_name = data.get_name() + ten_env.log_debug("on_data name {}".format(data_name)) + + buf = data.get_buf() + + new_data = Data.create(data_name) + new_data.alloc_buf(len(buf)) + new_buf = new_data.lock_buf() + new_buf[:] = buf + new_data.unlock_buf(new_buf) + + await ten_env.send_data(new_data) + + async def on_audio_frame( + self, ten_env: AsyncTenEnv, audio_frame: AudioFrame + ) -> None: + audio_frame_name = audio_frame.get_name() + ten_env.log_debug("on_audio_frame name {}".format(audio_frame_name)) + + buf = audio_frame.get_buf() + new_audio_frame = AudioFrame.create(audio_frame_name) + new_audio_frame.alloc_buf(len(buf)) + new_buf = new_audio_frame.lock_buf() + new_buf[:] = buf + new_audio_frame.unlock_buf(new_buf) + + new_audio_frame.set_bytes_per_sample(audio_frame.get_bytes_per_sample()) + new_audio_frame.set_sample_rate(audio_frame.get_sample_rate()) + new_audio_frame.set_data_fmt(audio_frame.get_data_fmt()) + new_audio_frame.set_eof(audio_frame.is_eof()) + new_audio_frame.set_line_size(audio_frame.get_line_size()) + new_audio_frame.set_number_of_channels( + audio_frame.get_number_of_channels() + ) + new_audio_frame.set_timestamp(audio_frame.get_timestamp()) + + await ten_env.send_audio_frame(new_audio_frame) + + async def on_video_frame( + self, ten_env: AsyncTenEnv, video_frame: VideoFrame + ) -> None: + video_frame_name = video_frame.get_name() + ten_env.log_debug("on_video_frame name {}".format(video_frame_name)) + + buf = video_frame.get_buf() + new_video_frame = VideoFrame.create(video_frame_name) + new_video_frame.alloc_buf(len(buf)) + new_buf = new_video_frame.lock_buf() + new_buf[:] = buf + new_video_frame.unlock_buf(new_buf) + + new_video_frame.set_eof(video_frame.is_eof()) + new_video_frame.set_height(video_frame.get_height()) + new_video_frame.set_width(video_frame.get_width()) + new_video_frame.set_timestamp(video_frame.get_timestamp()) + new_video_frame.set_pixel_fmt(video_frame.get_pixel_fmt()) + + await ten_env.send_video_frame(new_video_frame) diff --git a/packages/example_extensions/simple_echo_python/manifest.json b/packages/example_extensions/simple_echo_python/manifest.json new file mode 100644 index 0000000000..07881f3da7 --- /dev/null +++ b/packages/example_extensions/simple_echo_python/manifest.json @@ -0,0 +1,13 @@ +{ + "type": "extension", + "name": "simple_echo_python", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_python", + "version": "0.6.0" + } + ], + "api": {} +} \ No newline at end of file diff --git a/packages/example_extensions/simple_echo_python/property.json b/packages/example_extensions/simple_echo_python/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/packages/example_extensions/simple_echo_python/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/example_extensions/simple_echo_python/requirements.txt b/packages/example_extensions/simple_echo_python/requirements.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/BUILD.gn b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/BUILD.gn index 02a8bf8722..37dc5e4971 100644 --- a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/BUILD.gn +++ b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/BUILD.gn @@ -28,7 +28,7 @@ ten_package_test_prepare_app("mix_python_ext_nodejs_app") { "//packages/core_addon_loaders/python_addon_loader:upload_python_addon_loader_to_server", "//packages/core_apps/default_app_nodejs:upload_default_app_nodejs_to_server", "//packages/core_extensions/default_extension_nodejs:upload_default_extension_ts_to_server", - "//packages/example_extensions/pil_demo_python:upload_pil_demo_python_to_server", + "//packages/example_extensions/simple_echo_python:upload_simple_echo_python_to_server", "//packages/example_extensions/simple_http_server_cpp:upload_simple_http_server_cpp_to_server", ] } diff --git a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/manifest.json b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/manifest.json index 820a7d37f2..74aaff8bf9 100644 --- a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/manifest.json +++ b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/manifest.json @@ -17,7 +17,7 @@ }, { "type": "extension", - "name": "pil_demo_python", + "name": "simple_echo_python", "version": "0.1.0" }, { diff --git a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/property.json b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/property.json index bf9ca1a83b..553adf17a2 100644 --- a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/property.json +++ b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/mix_python_ext_nodejs_app/property.json @@ -23,8 +23,8 @@ }, { "type": "extension", - "name": "pil_demo_python", - "addon": "pil_demo_python", + "name": "simple_echo_python", + "addon": "simple_echo_python", "extension_group": "default_extension_group" } ], @@ -49,7 +49,7 @@ "name": "test", "dest": [ { - "extension": "pil_demo_python" + "extension": "simple_echo_python" } ] } diff --git a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/test_case.py b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/test_case.py index 0b3e6f0b92..d64906b779 100644 --- a/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/test_case.py +++ b/tests/ten_runtime/integration/nodejs/mix_python_ext_nodejs/test_case.py @@ -33,7 +33,6 @@ def test_mix_python_ext_nodejs(): # Set the required environment variables for the test. my_env["PYTHONMALLOC"] = "malloc" - my_env["PYTHONDEVMODE"] = "1" # Launch virtual environment. my_env["VIRTUAL_ENV"] = venv_dir