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
David Liu
2021-11-01 20:49:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
05c46c0a3060d30ebb32d09cd7c0112aa58fe683
05c46c0a
1 parent
b4ddecf6
more accurate dimensions for video tracks
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
127 行增加
和
15 行删除
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrack.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/track/video/VideoCapturerWithSize.kt
livekit-android-sdk/src/main/java/org/webrtc/Camera1Helper.kt
livekit-android-sdk/src/main/java/org/webrtc/Camera2Helper.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrack.kt
查看文件 @
05c46c0
...
...
@@ -3,7 +3,11 @@ package io.livekit.android.room.track
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.hardware.camera2.CameraManager
import androidx.core.content.ContextCompat
import io.livekit.android.room.track.video.Camera1CapturerWithSize
import io.livekit.android.room.track.video.Camera2CapturerWithSize
import io.livekit.android.room.track.video.VideoCapturerWithSize
import io.livekit.android.util.LKLog
import org.webrtc.*
import java.util.*
...
...
@@ -28,14 +32,17 @@ open class LocalVideoTrack(
override var rtcTrack: org.webrtc.VideoTrack = rtcTrack
internal set
/**
* Note: these dimensions are only requested params, and may differ
* from the actual capture format used by the camera.
*
* TODO: capture actual dimensions used
*/
val dimensions: Dimensions
get() = Dimensions(options.captureParams.width, options.captureParams.height)
get() {
(capturer as? VideoCapturerWithSize)?.let { capturerWithSize ->
val size = capturerWithSize.findCaptureFormat(
options.captureParams.width,
options.captureParams.height
)
return Dimensions(size.width, size.height)
}
return Dimensions(options.captureParams.width, options.captureParams.height)
}
internal var transceiver: RtpTransceiver? = null
private val sender: RtpSender?
...
...
@@ -127,9 +134,9 @@ open class LocalVideoTrack(
private fun createVideoCapturer(context: Context, position: CameraPosition): VideoCapturer? {
val videoCapturer: VideoCapturer? = if (Camera2Enumerator.isSupported(context)) {
createCameraCapturer(Camera2Enumerator(context), position)
createCameraCapturer(
context,
Camera2Enumerator(context), position)
} else {
createCameraCapturer(Camera1Enumerator(true), position)
createCameraCapturer(
context,
Camera1Enumerator(true), position)
}
if (videoCapturer == null) {
LKLog.d { "Failed to open camera" }
...
...
@@ -138,26 +145,47 @@ open class LocalVideoTrack(
return videoCapturer
}
private fun createCameraCapturer(enumerator: CameraEnumerator, position: CameraPosition): VideoCapturer? {
private fun createCameraCapturer(
context: Context,
enumerator: CameraEnumerator,
position: CameraPosition
): VideoCapturer? {
val deviceNames = enumerator.deviceNames
var targetDeviceName: String? = null
var targetVideoCapturer: VideoCapturer? = null
for (deviceName in deviceNames) {
if (enumerator.isFrontFacing(deviceName) && position == CameraPosition.FRONT) {
LKLog.v { "Creating front facing camera capturer." }
val videoCapturer = enumerator.createCapturer(deviceName, null)
if (videoCapturer != null) {
return videoCapturer
targetDeviceName = deviceName
targetVideoCapturer = videoCapturer
break
}
} else if (enumerator.isBackFacing(deviceName) && position == CameraPosition.BACK) {
LKLog.v { "Creating back facing camera capturer." }
val videoCapturer = enumerator.createCapturer(deviceName, null)
if (videoCapturer != null) {
return videoCapturer
targetDeviceName = deviceName
targetVideoCapturer = videoCapturer
break
}
}
}
if (targetVideoCapturer is Camera1Capturer) {
return Camera1CapturerWithSize(targetVideoCapturer, targetDeviceName)
}
if (targetVideoCapturer is Camera2Capturer) {
return Camera2CapturerWithSize(
targetVideoCapturer,
context.getSystemService(Context.CAMERA_SERVICE) as CameraManager,
targetDeviceName
)
}
return null
}
}
}
\ No newline at end of file
}
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/track/video/VideoCapturerWithSize.kt
0 → 100644
查看文件 @
05c46c0
package io.livekit.android.room.track.video
import android.hardware.camera2.CameraManager
import org.webrtc.*
/**
* @suppress
*/
internal interface VideoCapturerWithSize : VideoCapturer {
fun findCaptureFormat(width: Int, height: Int): Size
}
/**
* @suppress
*/
internal class Camera1CapturerWithSize(
private val capturer: Camera1Capturer,
private val deviceName: String?
) : VideoCapturer by capturer, VideoCapturerWithSize {
override fun findCaptureFormat(width: Int, height: Int): Size {
val cameraId = Camera1Helper.getCameraId(deviceName)
return Camera1Helper.findClosestCaptureFormat(cameraId, width, height)
}
}
/**
* @suppress
*/
internal class Camera2CapturerWithSize(
private val capturer: Camera2Capturer,
private val cameraManager: CameraManager,
private val deviceName: String?
) : VideoCapturer by capturer, VideoCapturerWithSize {
override fun findCaptureFormat(width: Int, height: Int): Size {
return Camera2Helper.findClosestCaptureFormat(cameraManager, deviceName, width, height)
}
}
\ No newline at end of file
...
...
livekit-android-sdk/src/main/java/org/webrtc/Camera1Helper.kt
0 → 100644
查看文件 @
05c46c0
package org.webrtc
/**
* A helper to access package-protected methods used in [Camera2Session]
* @suppress
*/
internal class Camera1Helper {
companion object {
fun getCameraId(deviceName: String?) = Camera1Enumerator.getCameraIndex(deviceName)
fun findClosestCaptureFormat(
cameraId: Int,
width: Int,
height: Int
): Size {
return CameraEnumerationAndroid.getClosestSupportedSize(
Camera1Enumerator.getSupportedFormats(cameraId)
.map { Size(it.width, it.height) },
width,
height
)
}
}
}
\ No newline at end of file
...
...
livekit-android-sdk/src/main/java/org/webrtc/Camera2Helper.kt
0 → 100644
查看文件 @
05c46c0
package org.webrtc
import android.hardware.camera2.CameraManager
/**
* A helper to access package-protected methods used in [Camera2Session]
* @suppress
*/
internal class Camera2Helper {
companion object {
fun findClosestCaptureFormat(
cameraManager: CameraManager,
cameraId: String?,
width: Int,
height: Int
): Size {
val sizes = Camera2Enumerator.getSupportedFormats(cameraManager, cameraId)
?.map { Size(it.width, it.height) }
?: emptyList()
return CameraEnumerationAndroid.getClosestSupportedSize(sizes, width, height)
}
}
}
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论