Skip to content

Commit

Permalink
fix: fix asan detect error
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxilin committed Jan 7, 2025
1 parent e79b77d commit 5cb491b
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 6 deletions.
32 changes: 32 additions & 0 deletions packages/example_extensions/simple_echo_python/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
}
13 changes: 13 additions & 0 deletions packages/example_extensions/simple_echo_python/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/example_extensions/simple_echo_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import addon
17 changes: 17 additions & 0 deletions packages/example_extensions/simple_echo_python/addon.py
Original file line number Diff line number Diff line change
@@ -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)
102 changes: 102 additions & 0 deletions packages/example_extensions/simple_echo_python/extension.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions packages/example_extensions/simple_echo_python/manifest.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"type": "extension",
"name": "pil_demo_python",
"name": "simple_echo_python",
"version": "0.1.0"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand All @@ -49,7 +49,7 @@
"name": "test",
"dest": [
{
"extension": "pil_demo_python"
"extension": "simple_echo_python"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cb491b

Please sign in to comment.