human: 如何处理七牛云的实时音视频QNRTCClient

gpt: [实时音视频](https://developer.qiniu.com/rtc) > API 文档 > Linux >QNRTCClient

#  QNRTCClient

最近更新时间: 2022-03-28 17:57:26

RTC 核心类，包含加入房间，离开房间，订阅、发布 Track，获取统计信息等功能

Index

Core Methods

  * SetClientRole
  * SetAutoSubscribe
  * Join
  * Leave
  * GetConnectionState
  * Publish
  * UnPublish
  * Subscribe
  * UnSubscribe
  * SendCustomMessage
  * SetLiveStreamingListener
  * StartLiveStreaming[1/2]
  * StartLiveStreaming[2/2]
  * StopLiveStreaming[1/2]
  * StopLiveStreaming[2/2]
  * SetTranscodingLiveStreamingTracks
  * RemoveTranscodingLiveStreamingTracks
  * SetRemoteAudioMixedFrameListener
  * GetPublishedTracks
  * GetRemoteUsers[1/2]
  * GetRemoteUsers[2/2]
  * GetRemoteVideoTrackStats
  * GetRemoteAudioTrackStats
  * GetLocalVideoTrackStats
  * GetLocalAudioTrackStats

Core Methods

SetClientRole

  * virtual void SetClientRole([QNClientRole](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11263/QNClientRole-Linux) client_role, [QNClientRoleListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11264/QNClientRoleListener-Linux)* listener) = 0
  * 设置直播场景下的用户角色

该方法在加入频道前后均可调用。

Parameters

    * client_role: [QNClientRole](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11263/QNClientRole-Linux)

目标角色

    * listener: [QNClientRoleListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11264/QNClientRoleListener-Linux)

设置角色结果回调

SetAutoSubscribe

  * virtual void SetAutoSubscribe(bool auto_subscribe) = 0
  * 设置是否启用自动订阅

当开启此选项后，房间内有任意用户新发布 Track 的时候，会自动订阅此路 Track，订阅成功后，会触发
[QNClientEventListener.OnSubscribed](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11261) 回调

Parameters

    * auto_subscribe: bool 

是否自动订阅

Join

  * virtual void Join(const std::string& token, const std::string& user_data = "") = 0
  * 加入房间

接口调用成功后，将会触发
[QNClientEventListener.OnConnectionStateChanged](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11261) 回调

> 请确保在
> [QNConnectionState.kDisconnected](https://developer.qiniu.com/rtc/11288/QNRTCClient-
> Linux/11266) 状态下调用该接口加入房间，否则接口调用无效

Parameters

    * token: string 

房间 Token

    * user_data: string 

用户信息

Leave

  * virtual void Leave() = 0
  * 离开房间

成功离开房间后，会触发
[QNClientEventListener.OnConnectionStateChanged](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11261) 回调

GetConnectionState

  * virtual QNConnectionState GetConnectionState() = 0
  * 获取当前房间连接状态

Returns [QNConnectionState](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/undefined)

Publish

  * virtual void Publish(LocalTrackList& track_list, QNPublishResultCallback* listener) = 0
  * 发布本地媒体流，结果通过 [QNPublishResultCallback](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11283/QNPublishResultCallback-Linux) 接口通知

Parameters

    * track_list: std::list<[QNLocalTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11208/QNLocalTrack-Linux)*>

要发布的本地 Track 列表

    * listener: [QNPublishResultCallback](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11283/QNPublishResultCallback-Linux)

发布结果回调函数

UnPublish

  * virtual void UnPublish(LocalTrackList& track_list) = 0
  * 取消发布本地媒体列表

Parameters

    * track_list: std::list<[QNLocalTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11208/QNLocalTrack-Linux)*>

要取消发布的本地 Track 列表

Subscribe

  * virtual void Subscribe(const RemoteTrackList& track_list) = 0
  * 订阅远端 Track 列表，订阅成功后，会触发 [QNClientEventListener.OnSubscribed](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11261) 回调

Parameters

    * track_list: std::list<shared_ptr<[QNRemoteTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11213/QNRemoteTrack-Linux)>>

要订阅的远端 Track 列表

UnSubscribe

  * virtual void UnSubscribe(const RemoteTrackList& track_list) = 0
  * 取消订阅远端 Track 列表

Parameters

    * track_list: std::list<shared_ptr<[QNRemoteTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11213/QNRemoteTrack-Linux)>>

要取消订阅的远端 Track 列表

SendCustomMessage

  * virtual void SendCustomMessage(const std::list<std::string>& users_list, const std::string& message_id, const std::string& message) = 0
  * 发送自定义消息到指定用户群，发送成功后，会触发远端用户的 [QNClientEventListener.OnMessageReceived](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11261) 回调接口

Parameters

    * users_list: std::list<std::string>

用户 ID 列表

    * message_id: string 

自定义消息 ID

    * message: string 

自定义消息内容

SetLiveStreamingListener

  * virtual void SetLiveStreamingListener([QNLiveStreamingListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11272/QNLiveStreamingListener-Linux)* listener) = 0
  * 设置 CDN 转推监听接口

Parameters

    * listener: [QNLiveStreamingListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11272/QNLiveStreamingListener-Linux)

转推监听接口

StartLiveStreaming[1/2]

  * virtual void StartLiveStreaming([QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11268/QNDirectLiveStreamingConfig-Linux)& config) = 0
  * 开始单路 CDN 转推

Parameters

    * config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11268/QNDirectLiveStreamingConfig-Linux)

单路转推配置

StartLiveStreaming[2/2]

  * virtual void StartLiveStreaming([QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11294/QNTranscodingLiveStreamingConfig-Linux)& config) = 0;
  * 开始合流转码 CDN 转推

Parameters

    * config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11294/QNTranscodingLiveStreamingConfig-Linux)

合流转推配置

StopLiveStreaming[1/2]

  * virtual void StopLiveStreaming([QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11268/QNDirectLiveStreamingConfig-Linux)& config) = 0
  * 停止单路 CDN 转推

Parameters

    * config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11268/QNDirectLiveStreamingConfig-Linux)

单路 CDN 转推配置

StopLiveStreaming[2/2]

  * virtual void StopLiveStreaming([QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11294/QNTranscodingLiveStreamingConfig-Linux)& config) = 0
  * 停止合流转码 CDN 转推

Parameters

    * config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11294/QNTranscodingLiveStreamingConfig-Linux)

合流转推配置

SetTranscodingLiveStreamingTracks

  * virtual void SetTranscodingLiveStreamingTracks(std::string& stream_id, QNTranscodeingTrackList& transcoding_track_list) = 0
  * 新增、更新合流转推布局配置

> 新增 track 布局以及对已有的 track 的合流布局进行更新均可通过该接口实现，只需修改 transcodingTracks 对应的 track
> 内容即可。

Parameters

    * stream_id: string 

合流任务 stream id

    * transcoding_track_list: std::list<[QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11296/QNTranscodingLiveStreamingTrack-Linux)>

待新增、更新的合流转推布局配置

RemoveTranscodingLiveStreamingTracks

  * virtual void RemoveTranscodingLiveStreamingTracks(std::string& stream_id, QNTranscodeingTrackList& transcoding_track_list) = 0
  * 移除合流转推布局配置

Parameters

    * stream_id: string 

合流任务 stream id

    * transcoding_track_list: std::list<[QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11296/QNTranscodingLiveStreamingTrack-Linux)>

待移除合流转推布局配置

SetRemoteAudioMixedFrameListener

  * virtual void SetRemoteAudioMixedFrameListener([QNRemoteAudioMixedFrameListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11284/QNRemoteAudioMixedFrameListener-Linux)* listener) = 0
  * 设置监听远端所有音频 Track 混合后的音频数据

Parameters

    * listener: [QNRemoteAudioMixedFrameListener](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11284/QNRemoteAudioMixedFrameListener-Linux)

音频数据监听接口

GetPublishedTracks

  * virtual LocalTrackList& GetPublishedTracks() = 0
  * 获取所有已经发布的本地 Track

Returns
std::list<[QNLocalTrack](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11208/QNLocalTrack-Linux)*>

GetRemoteUsers[1/2]

  * virtual [QNRemoteUser](https://developer.qiniu.com/rtc/11288/QNRTCClient-Linux/11214/QNRemoteUser-Linux)& GetRemoteUsers(const std::string& user_id) = 0
  * 获取对应 ID 的远端用户

Parameters

    * user_id: string 

远端用户 ID

Returns [QNRemoteUser](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11214/QNRemoteUser-Linux)

GetRemoteUsers[2/2]

  * virtual RemoteUserList& GetRemoteUsers() = 0
  * 获取房间内所有的远端用户

Returns
std::list<[QNRemoteUser](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11214/QNRemoteUser-Linux)>

GetRemoteVideoTrackStats

  * virtual QNRemoteVideoTrackStatsMap& GetRemoteVideoTrackStats() = 0
  * 获取已订阅的远端视频轨道统计信息

Returns std::map<std::string,
[QNRemoteVideoTrackStats](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11286/QNRemoteVideoTrackStats-Linux)>

GetRemoteAudioTrackStats

  * virtual QNRemoteAudioTrackStatsMap& GetRemoteAudioTrackStats() = 0
  * 获取已订阅的远端音频轨道统计信息

Returns std::map<std::string,
[QNRemoteAudioTrackStats](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11285/QNRemoteAudioTrackStats-Linux)>

GetLocalVideoTrackStats

  * virtual QNLocalVideoTracksStatsMap& GetLocalVideoTrackStats() = 0
  * 获取已发布的近端视频轨道统计信息

Returns std::map<std::string,
std::list<[QNLocalVideoTrackStats](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11274/QNLocalVideoTrackStats-Linux)>>

GetLocalAudioTrackStats

  * virtual QNLocalAudioTrackStatsMap& GetLocalAudioTrackStats() = 0
  * 获取已发布的近端音频轨道统计信息

Returns std::map<std::string,
[QNLocalAudioTrackStats](https://developer.qiniu.com/rtc/11288/QNRTCClient-
Linux/11273/QNLocalAudioTrackStats-Linux)>

以上内容是否对您有帮助？