
# 自采集自渲染
 #### setExternalVideoCapture
```
virtual int setExternalVideoCapture(bool enable, HRTCVideoFrameFormat format)
```
【**功能说明**】
设置是否开启外部视频采集。
【**请求参数**】
- enable：true表示开启视频自采集，false表示取消视频自采集。默认值为false。
- format：设置外部采集的视频格式，默认为I420（即yuv420P）。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 加入房间前调用，不支持房间内切换。
- 视频支持格式：I420，texture2d。
- 开启视频自采集后不支持视频预览。
 
 #### pushExternalVideoFrame
```
virtual int pushExternalVideoFrame(HRTCVideoFrame* videoFrame)
```
【**功能说明**】
推送外部视频数据。
【**请求参数**】
videoFrame：视频自采集数据格式。具体请参见[HRTCVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section252640124317)。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 此方法调用前，需要先调用[setExternalVideoCapture]设置开启外部视频采集。
- 数据输入周期：同视频周期，1/帧率。
 
 #### setExternalVideoFrameOutput
```
virtual int setExternalVideoFrameOutput(bool localEnable, bool remoteEnable, HRTCImageBufferFormat format = HRTCImageBufferFormat())
```
【**功能说明**】
设置是否开启视频流自渲染。开启后，回调[onRenderExternalVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__section62458161940)中会有视频帧数据上报。
【**请求参数**】
- localEnable：开启本地视频自渲染，默认sdk渲染。
- remoteEnable：开启远端视频自渲染，默认sdk渲染。
- format：默认imageFormat为HRTC_VIDEO_IMAGE_FORMAT_YUV420P，bufferType为HRTC_VIDEO_IMAGE_BUFFER_BYTE_ARRAY。具体请参见[HRTCImageBufferFormat](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section19598133419235)。
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
自渲染模式下，仍需要调用[startRemoteStreamView](https://support.huaweicloud.com/csdk-rtc/rtc_05_0101.html#rtc_05_0101__zh-cn_topic_0000001113689814_section194352285256)，接收到远端视频数据。
 #### setAuxiliaryExternalVideoFrameOutput
```
virtual int setAuxiliaryExternalVideoFrameOutput(bool localEnable, bool remoteEnable)
```
【**功能说明**】
设置是否开启辅流自渲染。开启后，回调[onRenderAuxiliaryExternalVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__zh-cn_topic_0277015530_section380329145316)中会有辅流数据上报。
【**请求参数**】
- localEnable：开启本地辅流自渲染，默认sdk渲染。
- remoteEnable：开启远端辅流自渲染，默认sdk渲染。
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
辅流暂不支持本地渲染，该方法只对远端辅流生效。
 #### setExternalAudioCapture
```
virtual int setExternalAudioCapture(int enabled, int sampleRate, int channels)
```
【**功能说明**】
设置是否开启外部音频采集。
【**请求参数**】
- enable：true表示开启音频自采集，false表示取消音频自采集。
- sampleRate：音频采样率，支持16k/48k。
- channels：音频声道数，支持单声道。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 加入房间前调用，不支持房间内切换。
- 自采集音频输入规格：
  - 格式：PCM。
  
  - 采样率：16k/48k 。
  
  - 声道数：单声道。
  
  - 位数：16。
   
 
 #### pushExternalAudioFrame
```
virtual int pushExternalAudioFrame(void* audioData, int size)
```
【**功能说明**】
推送外部音频数据。
【**请求参数**】
- audioData：音频数据。
- size：音频输入数据大小。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 此方法调用前，需要先调用[setExternalAudioCapture]设置开启外部音频采集。
- 数据输入周期：10ms。
- 音频输入数据大小：10 \* sampleRate \* channels \* 16 / 8 / 1000。
 
 #### setExternalAudioFrameOutput
```
virtual int setExternalAudioFrameOutput(bool localEnable, bool remoteEnable)
```
【**功能说明**】
设置是否开启音频自渲染。开启后，回调[onPlaybackExternalAudioFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__section122089554413)中会有音频帧数据上报。
【**请求参数**】
- localEnable：开启本地音频自渲染，默认sdk渲染。
- remoteEnable：开启远端音频自渲染，默认sdk渲染
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
