跳转到主要内容

PreOptionCamera

PreOptionCamera 类中包含 CameraCaptureOptions、VideoPublishOptions 两个属性
CameraCaptureOptions摄像头采集配置参数
VideoPublishOptions视频流发布配置参数

CameraCaptureOptions

CameraCaptureOptions 类主要用于配置摄像头采集参数,具体参数如下
deviceIdString 类型,设备 id
positionCamraPosition 类型,摄像头位置。手机专用
CamraPosition.FRONT:前置摄像头
CamraPosition.BACK:后置摄像头
facingModeCameraFacingMode 类型,摄像头位置。webrtc 专用
CameraFacingMode.USER:朝向用户
CameraFacingMode.ENVIRONMENT:朝向环境
CameraFacingMode.LEFT:朝向左边
CameraFacingMode.RIGHT:朝向右边
widthInt 类型,预览画面宽
heightInt 类型,预览画面高
maxFpsInt 类型,最大帧率

VideoPublishOptions

VideoPublishOptions 类主要用于配置视频流发布参数,具体参数如下
descString 类型,轨道描述
codecCodecType 类型,编码格式
CodecType.unknow:未知
CodecType.H264:h264 格式
CodecType.H265:h265 格式
maxBitrateInt 类型,最大码率
widthInt 类型,发布的画面宽度
heightInt 类型,发布的画面高度
maxFpsInt 类型,最大帧率
propsAny 类型,自定义属性。可空
simulcastsMutableList<VideoPublishOptions> 类型。
+ 摄像头流可以发布两条视频流,一条主流、一条辅流,可以在这里对辅流进行配置
+ 目前只可以配置一条辅流,所以该列表的大小只能为 1。
+ 可空,空表示不配置辅流。

PublishCustomOptions

PublishCustomOptions 类是用于在发布时对 desc、props 这两个参数做修改
descString 类型,轨道描述。
+ 可空,表示不做修改
propsAny 类型,自定义属性。
+ 可空,表示不做修改
simulcastsMutableList<PublishCustomOptions> 类型。
+ 因为摄像头流可能存在主流、辅流两路流,这里就是用于对辅流参数做修改的
+ 该列表大小只能为 1,因为最多只能配置一条辅流。
+ 可空,表示不修改辅流配置

预设值

目前预设值只有一个 PreOptionCamera.def
  • 可以通过直接修改 PreOptionCamera.def 获取到的实例的参数值,然后使用。如无特殊需求不建议修改
// 获取默认预设值
val preOpt: PreOptionCamera = PreOptionCamera.get_1080P()
// 修改采集配置中的摄像头位置
preOpt.capture.position = CameraCaptureOptions.CamraPosition.BACK
// 修改发布配置中的编码格式
preOpt.publish.codec = CodecType.H265
// 使用修改后的预设值
...
```kotlin

### PreOptionCamera.def
配置如下:

```kotlin
val _1080P: PreOptionCamera = PreOptionCamera(
    CameraCaptureOptions(
        deviceId = "cameraCapMain",
        position = CameraCaptureOptions.CamraPosition.FRONT,
        facingMode = CameraCaptureOptions.CameraFacingMode.USER,
        width = 1920,
        height = 1080,
        maxFps = 30
    ),
    VideoPublishOptions(
        desc = TrackDesc.TRACK_MAIN.value,
        codec = CodecType.H264,
        maxBitrate = 2000 * 1024,
        width = 1920,
        height = 1080,
        maxFps = 25,
        props = null,
        simulcasts = mutableListOf(
            VideoPublishOptions(
                desc = TrackDesc.TRACK_SUB.value,
                codec = CodecType.H264,
                maxBitrate = 128 * 1024,
                width = 320,
                height = 180,
                maxFps = 25,
                props = null,
                simulcasts = null
            )
        )
    )
)

val _720P: PreOptionCamera = PreOptionCamera(
    CameraCaptureOptions(
        deviceId = "cameraCapMain",
        position = CameraCaptureOptions.CamraPosition.FRONT,
        facingMode = CameraCaptureOptions.CameraFacingMode.USER,
        width = 1280,
        height = 720,
        maxFps = 30
    ),
    VideoPublishOptions(
        desc = TrackDesc.TRACK_MAIN.value,
        codec = CodecType.H264,
        maxBitrate = 900 * 1024,
        width = 1280,
        height = 720,
        maxFps = 25,
        props = null,
        simulcasts = mutableListOf(
            VideoPublishOptions(
                desc = TrackDesc.TRACK_SUB.value,
                codec = CodecType.H264,
                maxBitrate = 128 * 1024,
                width = 320,
                height = 180,
                maxFps = 25,
                props = null,
                simulcasts = null
            )
        )
    )
)

val _480P: PreOptionCamera = PreOptionCamera(
    CameraCaptureOptions(
        deviceId = "cameraCapMain",
        position = CameraCaptureOptions.CamraPosition.FRONT,
        facingMode = CameraCaptureOptions.CameraFacingMode.USER,
        width = 640,
        height = 480,
        maxFps = 30
    ),
    VideoPublishOptions(
        desc = TrackDesc.TRACK_MAIN.value,
        codec = CodecType.H264,
        maxBitrate = 512 * 1024,
        width = 640,
        height = 480,
        maxFps = 25,
        props = null,
        simulcasts = mutableListOf(
            VideoPublishOptions(
                desc = TrackDesc.TRACK_SUB.value,
                codec = CodecType.H264,
                maxBitrate = 128 * 1024,
                width = 320,
                height = 180,
                maxFps = 25,
                props = null,
                simulcasts = null
            )
        )
    )
)

val _180P: PreOptionCamera = PreOptionCamera(
    CameraCaptureOptions(
        deviceId = "cameraCapMain",
        position = CameraCaptureOptions.CamraPosition.FRONT,
        facingMode = CameraCaptureOptions.CameraFacingMode.USER,
        width = 320,
        height = 180,
        maxFps = 30
    ),
    VideoPublishOptions(
        desc = TrackDesc.TRACK_MAIN.value,
        codec = CodecType.H264,
        maxBitrate = 128 * 1024,
        width = 320,
        height = 180,
        maxFps = 25,
        props = null,
        simulcasts = mutableListOf(
            VideoPublishOptions(
                desc = TrackDesc.TRACK_SUB.value,
                codec = CodecType.H264,
                maxBitrate = 128 * 1024,
                width = 320,
                height = 180,
                maxFps = 25,
                props = null,
                simulcasts = null
            )
        )
    )
)