Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
livekitAndroidXuningTest
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
davidliu
2022-04-23 02:51:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2022-04-23 02:51:03 +0900
Commit
8cce1880783442f83286ff7501ae438689cdff02
8cce1880
1 parent
25f2f6d0
Fallback for camera choosing (#76)
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
44 行增加
和
25 行删除
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrack.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrack.kt
查看文件 @
8cce188
...
...
@@ -200,38 +200,37 @@ constructor(
context: Context,
enumerator: CameraEnumerator,
options: LocalVideoTrackOptions
): Pair<VideoCapturerWithSize, LocalVideoTrackOptions>? {
val deviceNames = enumerator.deviceNames
): Pair<VideoCapturer, LocalVideoTrackOptions>? {
var targetDeviceName: String? = null
var targetVideoCapturer: VideoCapturer? = null
for (deviceName in deviceNames) {
if ((options.deviceId != null && deviceName == options.deviceId)
|| (enumerator.isFrontFacing(deviceName) && options.position == CameraPosition.FRONT)
) {
LKLog.v { "Creating front facing camera capturer." }
val videoCapturer = enumerator.createCapturer(deviceName, null)
if (videoCapturer != null) {
targetDeviceName = deviceName
targetVideoCapturer = videoCapturer
break
}
} else if ((options.deviceId != null && deviceName == options.deviceId)
|| (enumerator.isBackFacing(deviceName) && options.position == CameraPosition.BACK)
) {
LKLog.v { "Creating back facing camera capturer." }
val videoCapturer = enumerator.createCapturer(deviceName, null)
if (videoCapturer != null) {
targetDeviceName = deviceName
targetVideoCapturer = videoCapturer
break
}
val targetVideoCapturer: VideoCapturer?
// Prioritize search by deviceId first
if (options.deviceId != null) {
targetDeviceName = enumerator.findCamera { deviceName -> deviceName == options.deviceId }
}
// Search by camera position
if (targetDeviceName == null && options.position != null) {
targetDeviceName = enumerator.findCamera { deviceName ->
enumerator.getCameraPosition(deviceName) == options.position
}
}
// Fall back by choosing first available camera.
if (targetDeviceName == null) {
targetDeviceName = enumerator.findCamera { true }
}
if (targetDeviceName == null) {
return null
}
targetVideoCapturer = enumerator.createCapturer(targetDeviceName, null)
// back fill any missing information
val newOptions = options.copy(
deviceId = targetDeviceName,
position = enumerator.getCameraPosition(targetDeviceName
!!
)
position = enumerator.getCameraPosition(targetDeviceName)
)
if (targetVideoCapturer is Camera1Capturer) {
// Cache supported capture formats ahead of time to avoid future camera locks.
...
...
@@ -253,6 +252,26 @@ constructor(
)
}
LKLog.w { "unknown CameraCapturer class: ${targetVideoCapturer.javaClass.canonicalName}. Reported dimensions may be inaccurate." }
if (targetVideoCapturer != null) {
return Pair(
targetVideoCapturer,
newOptions
)
}
return null
}
fun CameraEnumerator.findCamera(predicate: (deviceName: String) -> Boolean): String? {
for (deviceName in deviceNames) {
if (predicate(deviceName)) {
val videoCapturer = createCapturer(deviceName, null)
if (videoCapturer != null) {
return deviceName
}
}
}
return null
}
...
...
请
注册
或
登录
后发表评论