-
-
Save skydoves/373e6ca678a34833b7e8809fdcda404b to your computer and use it in GitHub Desktop.
video_suource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Stream.IO, Inc. All Rights Reserved. | |
// SPDX-License-Identifier: Apache-2.0 | |
// getting front camera | |
private val videoCapturer: VideoCapturer by lazy { buildCameraCapturer() } | |
// we need it to initialize video capturer | |
private val surfaceTextureHelper = SurfaceTextureHelper.create( | |
"SurfaceTextureHelperThread", | |
peerConnectionFactory.eglBaseContext | |
) | |
private val videoSource by lazy { | |
peerConnectionFactory.makeVideoSource(videoCapturer.isScreencast).apply { | |
videoCapturer.initialize(surfaceTextureHelper, context, this.capturerObserver) | |
videoCapturer.startCapture(480, 720, 30) | |
} | |
} | |
private val localVideoTrack: VideoTrack by lazy { | |
peerConnectionFactory.makeVideoTrack( | |
source = videoSource, | |
trackId = "Video${UUID.randomUUID()}" | |
) | |
} | |
private fun buildCameraCapturer(): VideoCapturer { | |
val manager = cameraManager ?: throw RuntimeException("CameraManager was not initialized!") | |
val ids = manager.cameraIdList | |
var foundCamera = false | |
var cameraId = "" | |
for (id in ids) { | |
val characteristics = manager.getCameraCharacteristics(id) | |
val cameraLensFacing = characteristics.get(CameraCharacteristics.LENS_FACING) | |
if (cameraLensFacing == CameraMetadata.LENS_FACING_FRONT) { | |
foundCamera = true | |
cameraId = id | |
} | |
} | |
if (!foundCamera && ids.isNotEmpty()) { | |
cameraId = ids.first() | |
} | |
val camera2Capturer = Camera2Capturer(context, cameraId, null) | |
return camera2Capturer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment