如果你的业务场景中既需要高质量的音视频传输,又需要易集成、低内存占用以及低功耗的特性,例如智能摄像头、智能门铃场景,声网推荐你同时使用 RTC SDK(v4.x)和 RTSA Lite SDK。
下表展示 RTSA Lite SDK 与 RTC SDK(v4.x)互通时支持的数据格式:
SDK 类型 | RTSA Lite SDK |
---|---|
RTC Native/第三方框架 SDK(v4.x) | |
RTC Web SDK(v4.x) | |
RTC 小程序 SDK |
发送端和接收端只有设置的数据格式一致且符合上表,才可以实现互通。
本文介绍如何在 SDK 中设置音视频数据格式。
RTSA Lite SDK 仅支持单声道音频数据,数据发送间隔为 20 ms。
如需发送和接收 AAC 音频数据,操作如下:
调用 agora_rtc_send_audio_data
方法发送音频数据时,设置 audio_frame_info_t.data_type
为 AUDIO_DATA_TYPE_AACLC
或 AUDIO_DATA_TYPE_HEAAC
数据类型,及对应的数据大小。AAC 音频数据的大小需用户自行解析。
如需发送和接收 Opus、G722、G711 音频数据,操作如下:
agora_rtc_join_channel
方法加入 RTC 频道时,设置 rtc_channel_options_t.audio_codec_opt.audio_codec_type
为 AUDIO_CODEC_TYPE_OPUS
、AUDIO_CODEC_TYPE_G722
、AUDIO_CODEC_TYPE_G711A
或 AUDIO_CODEC_TYPE_G711U
编码格式,及对应的采样率。agora_rtc_send_audio_data
方法发送音频数据时,设置 audio_frame_info_t.data_type
为 AUDIO_DATA_TYPE_PCM
数据类型,及对应的数据大小。下表展示了 Opus、G722、G711 音频数据推荐的采样率及对应的数据大小。
音频格式 | 采样率(Hz) | 音频数据大小(Byte) |
---|---|---|
G711 | 8000 | 320 |
G722 | 16000 | 640 |
OPUS | 16000 | 640 |
OPUS | 48000 | 1920 |
在 RTSA Lite SDK 中,默认发送和接收 H.264 视频数据。
如需发送和接收 JPEG 视频数据,调用 agora_rtc_send_video_data
方法发送视频数据时,设置 video_frame_info_t.data_type
为 VIDEO_DATA_TYPE_GENERIC_JPEG
。
在 RTC Native/第三方框架 SDK(v4.x)中,默认发送和接收 Opus 或 AAC 音频数据。
如需发送和接收 G722 或 G711 音频数据,调用如下方法:
SDK 类型 | G722 | G711(PCMA) | G711 (PCMU) |
---|---|---|---|
RTC Android SDK | mRtcEngine.setAudioProfile(6) 或者 mRtcEngine.setParameters("{\"che.audio. custom_payload_type\":9}") |
mRtcEngine.setParameters("{\"che.audio. custom_payload_type\":8}") |
mRtcEngine.setParameters("{\"che.audio. custom_payload_type\":0}") |
RTC iOS/macOS SDK | agoraKit.setAudioProfile(6) 或者 agoraKit.setParameters("{\"che.audio. custom_payload_type\":9}") |
agoraKit.setParameters("{\"che.audio. custom_payload_type\":8}") |
agoraKit.setParameters("{\"che.audio. custom_payload_type\":0}") |
RTC Windows SDK | m_rtcEngine->setAudioProfile(6) 或者 agora::base::AParameter apm(m_rtcEngine); apm->setParameters("{\"che.audio. custom_payload_type\":9}") |
agora::base::AParameter apm(m_rtcEngine);apm->m_rtcEngine->setParameters("{\"che.audio. custom_payload_type\":8}") |
agora::base::AParameter apm(m_rtcEngine);apm->m_rtcEngine->setParameters("{\"che.audio. custom_payload_type\":0}") |
RTC Electron SDK | this.rtcEngine?.setAudioProfile(6) 或者 this.rtcEngine?.setParameters("{\"che.audio. custom_payload_type\":9}") |
this.rtcEngine?.setParameters("{\"rtc.audio. custom_payload_type\":8}") |
this.rtcEngine?.setParameters("{\"rtc.audio. custom_payload_type\":0}") |
RTC UnitySDK | RtcEngine.SetAudioProfile(6) 或者 RtcEngine.SetParameters("{\"che.audio. custom_payload_type\":9}") |
RtcEngine.SetParameters("{\"rtc.audio. custom_payload_type\":8}") |
RtcEngine.SetParameters("{\"rtc.audio. custom_payload_type\":0}") |
RTC Flutter SDK | await _engine.setAudioProfile(profile: AudioProfileType.audioProfileIot) 或者 await _engine.setParameters("{\"che.audio. custom_payload_type\":9}") |
await _engine.setParameters("{\"che.audio. custom_payload_type\":8}") |
await _engine.setParameters("{\"che.audio. custom_payload_type\":0}") |
RTC React Native SDK | await _engine.current?.setAudioProfile(6) 或者 await _engine.current?.setParameters("{\"che.audio. custom_payload_type\":9}") |
await _engine.current?.setParameters("{\"che.audio. custom_payload_type\":8}") |
await _engine.current?.setParameters("{\"che.audio. custom_payload_type\":0}") |
在 RTC Native/第三方框架 SDK(v4.x)中,默认发送和接收 H.264 视频数据。
如需发送和接收 JPEG 视频数据,调用如下方法:
mRtcEngine.setParameters("{\"engine.video.codec_type\": \"20\"}")
agoraKit.setParameters("{\"engine.video.codec_type\": \"20\"}")
agora::base::AParameter apm(m_rtcEngine);
apm->setParameters("{\"engine.video.codec_type\": \"20\"}")
this.engine.setParameters("{\"engine.video.codec_type\": \"20\"}");
RtcEngine.SetParameters("{\"engine.video.codec_type\": \"20\"}");
await _engine.setParameters("{\"engine.video.codec_type\": \"20\"}");
this.engine.setParameters("{\"engine.video.codec_type\": \"20\"}");
在 RTC Web SDK(v4.x)中,默认发送和接收 Opus 音频数据。
如需发送和接收 G722、G711 音频数据,调用如下方法:
AgoraRTC.createClient({mode: "live", codec: "h264", audioCodec: "pcma"})
AgoraRTC.createClient({mode: "live", codec: "h264", audioCodec: "pcmu"})
AgoraRTC.createClient({mode: "live", codec: "h264", audioCodec: "g722"})
在 RTC Web SDK(v4.x)中,默认发送和接收 VP8 视频数据。你需要在调用 createClient
创建客户端对象时,设置视频数据格式为 "h264"
。
在 RTC 小程序 SDK 中,默认发送和接收 Opus 音频数据、H.264 视频数据。如需接收 JPEG 视频数据或发送和接收 G711 音频数据,联系 sales@agora.io 开通。
开通服务的邮件模板如下:
标题:小程序IOT服务开通
正文: