Skip to content

Commit

Permalink
feat: update setup for pip
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyusong committed Sep 20, 2024
1 parent 880ef18 commit f16e74e
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 2 deletions.
1 change: 1 addition & 0 deletions agora_rtc/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude agora_rtc/agora/rtc/agora_sdk/*
48 changes: 48 additions & 0 deletions agora_rtc/README.cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 注意
- 这是一个 Python SDK 封装的 Agora RTC SDK。
- 支持Linux和Mac平台。
- examples只是作为非常简单的演示,不建议在生产环境中使用。

# 非常重要的通知 !!!!!!!
- 一个进程只能有一个实例
- 一个实例,可以有多个connection
- 所有的observer或者是回调中,都不能在调用sdk自身的api,也不能在回调中做cpu耗时的工作,数据拷贝是可以的。

# 所需的操作系统和 Python 版本
- 支持的 Linux 版本:
- Ubuntu 18.04 LTS 及以上
- CentOS 7.0 及以上

- 支持的 Mac 版本:
- MacOS 13 及以上

- Python 版本:
- Python 3.8 及以上

# 测试数据
- 下载并解压 [test_data.zip](https://download.agora.io/demo/test/test_data_202408221437.zip)
- 在与 **agora_rtc** 同一目录下创建 **test_data** 目录

# Linux 调试与开发
## 准备 C 版本的 Agora RTC SDK
- 在与 **agora_rtc/agora/rtc** 目录下创建 **agora_sdk** 目录
- 下载并解压 [agora_sdk.zip](https://download.agora.io/sdk/release/agora_rtc_sdk_linux_v4.4_20240914_1538_336910.zip)**agora_sdk** 目录。
- **agora_sdk** 目录中应有 **libagora_rtc_sdk.so****include_c**

## 在 Linux 上运行示例
```
python agora_rtc/examples/example_audio_pcm_send.py --appId=xxx --channelId=xxx --userId=xxx --audioFile=./test_data/demo.pcm --sampleRate=16000 --numOfChannels=1
```


# Mac 调试与开发
## 准备 C 版本的 Agora RTC SDK
- 在与 **agora_rtc/agora/rtc** 目录下创建 **agora_sdk** 目录
- 下载并解压 [agora_sdk.zip](https://download.agora.io/sdk/release/agora_rtc_sdk_mac_v4.4_20240914_1538_336910.zip),到**agora_sdk** 目录。
- **agora_sdk** 目录中应有 **libAgoraRtcKit.dylib**

## 在 Mac 上运行示例
```
python agora_rtc/examples/example_audio_pcm_send.py --appId=xxx --channelId=xxx --userId=xxx --audioFile=./test_data/demo.pcm --sampleRate=16000 --numOfChannels=1
```

59 changes: 59 additions & 0 deletions agora_rtc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Notice
- this is a python sdk wrappered agora rtc sdk.
- can dev under mac, and release unde linux
- the examples is just a simple demo, it is not a good practice to use it in production
# Very import notice !!!!!!!
- It's crucial that a process can only have one instance.
- One instance can have multiple connections.
- In all observers or callbacks, it is not allowed to call the SDK's own APIs, nor is it permitted to perform CPU-intensive tasks within the callbacks. However, data copying is allowed.

# Required OS and python version
- supported Linux version:
- Ubuntu 18.04 LTS and above
- CentOS 7.0 and above

- supported Mac version:

- MacOS 13 and above

- python version:
- python 3.8 above

# Test Data
- download and unzip [test_data.zip](https://download.agora.io/demo/test/test_data_202408221437.zip)
- make **test_data** directory in the same directory with **agora_rtc**

# Linux debug & develop
## Prepare C version of agora rtc sdk

- make **agora_sdk** directory under the directory of **agora_rtc/agora/rtc**
- download and unzip [agora_sdk.zip](https://download.agora.io/sdk/release/agora_rtc_sdk_linux_v4.4_20240914_1538_336910.zip) to **agora_sdk**
- there should be **libagora_rtc_sdk.so** and **include_c** in **agora_sdk** directory

## run example on linux
```
python agora_rtc/examples/example_audio_pcm_send.py --appId=xxx --channelId=xxx --userId=xxx --audioFile=./test_data/demo.pcm --sampleRate=16000 --numOfChannels=1
```

# Mac debug & develop
## Prepare C version of agora rtc sdk
- make **agora_sdk** directory under the directory of **agora_rtc/agora/rtc**
- download and unzip [agora_sdk.zip](https://download.agora.io/sdk/release/agora_rtc_sdk_mac_v4.4_20240914_1538_336910.zip) to **agora_sdk**
- there should be **libAgoraRtcKit.dylib** in **agora_sdk** directory

## run example on mac

```
python agora_rtc/examples/example_audio_pcm_send.py --appId=xxx --channelId=xxx --userId=xxx --audioFile=./test_data/demo.pcm --sampleRate=16000 --numOfChannels=1
```
# Some import call sequence
- 1. about audio frame observer:

set_playback_audio_frame_before_mixing_parameters MUST be call before register_audio_frame_observer

sample code:
```
localuser.set_playback_audio_frame_before_mixing_parameters(1, 16000)
audio_observer = BizAudioFrameObserver()
localuser.register_audio_frame_observer(audio_observer)
```
4 changes: 2 additions & 2 deletions agora_rtc/agora/rtc/audio_vad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
from enum import Enum,IntEnum

sdk_dir = os.path.dirname(os.path.abspath(__file__))
lib_path = os.path.join(sdk_dir, 'agora_sdk')
from . import lib_path

if sys.platform == 'darwin':
agora_vad_lib_path =os.path.join(lib_path, 'libuap_aed.dylib')
elif sys.platform == 'linux':
Expand Down
4 changes: 4 additions & 0 deletions agora_rtc/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

75 changes: 75 additions & 0 deletions agora_rtc/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os
import sys
import zipfile
# import urllib
from urllib import request
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
import site
from setuptools import setup
from setuptools.command.install import install

class CustomInstallCommand(install):
def run(self):
self.download_and_extract_sdk()
install.run(self)

def download_and_extract_sdk(self):
print("download_and_extract_sdk--------------")

agora_service_path = os.path.join(site.getsitepackages()[0], 'agora', 'rtc')
url = "https://download.agora.io/sdk/release/agora_rtc_sdk_linux_v4.0.1_202409051524_333459.zip"
libagora_rtc_sdk_path = os.path.join(agora_service_path, "agora_sdk/libagora_rtc_sdk.so")
if sys.platform == 'darwin':
url = "https://download.agora.io/sdk/release/agora_rtc_sdk_mac_4.0.1_20240913_320567.zip"
libagora_rtc_sdk_path = os.path.join(agora_service_path, "agora_sdk/libAgoraRtcKit.dylib")

sdk_dir = os.path.join(agora_service_path, "agora_sdk")
if os.path.exists(sdk_dir):
os.system(f"rm -rf {sdk_dir}")
zip_path = os.path.join(agora_service_path, "agora_rtc_sdk.zip")
libagora_rtc_sdk_path = os.path.join(agora_service_path, "libagora_rtc_sdk.so")
os.makedirs(agora_service_path, exist_ok=True)

print("agora_service_path:", agora_service_path)
if not os.path.exists(zip_path):
print(f"Downloading {url}...")
request.urlretrieve(url, zip_path)

if not os.path.exists(libagora_rtc_sdk_path):
print(f"Extracting {zip_path}...")
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(agora_service_path)

if os.path.exists(zip_path):
os.remove(zip_path)


setup(
name='agora_python_server_sdk',
version='2.0.0',
description='A Python SDK for Agora Server',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/AgoraIO-Extensions/Agora-Python-Server-SDK',
packages=["agora.rtc"],
classifiers=[
"Intended Audience :: Developers",
'License :: OSI Approved :: MIT License',
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Multimedia :: Video",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3 :: Only",

],
python_requires='>=3.8',
cmdclass={
'install': CustomInstallCommand,
},
)

if __name__ == "__main__":
print("run setup -------------")

0 comments on commit f16e74e

Please sign in to comment.