Committed by
GitHub
VideoFrameCapturer for pushing frames directly (#538)
* VideoFrameCapturer for pushing frames directly * changeset and spotless
正在显示
2 个修改的文件
包含
63 行增加
和
0 行删除
.changeset/rude-feet-teach.md
0 → 100644
livekit-android-sdk/src/main/java/io/livekit/android/room/track/video/VideoFrameCapturer.kt
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2024 LiveKit, Inc. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package io.livekit.android.room.track.video | ||
| 18 | + | ||
| 19 | +import android.content.Context | ||
| 20 | +import livekit.org.webrtc.CapturerObserver | ||
| 21 | +import livekit.org.webrtc.SurfaceTextureHelper | ||
| 22 | +import livekit.org.webrtc.VideoCapturer | ||
| 23 | +import livekit.org.webrtc.VideoFrame | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * A [VideoCapturer] that can be manually driven by passing in [VideoFrame] to [pushVideoFrame]. | ||
| 27 | + * | ||
| 28 | + * Once [startCapture] is called, call [pushVideoFrame] to publish video frames. | ||
| 29 | + */ | ||
| 30 | +open class VideoFrameCapturer : VideoCapturer { | ||
| 31 | + | ||
| 32 | + var capturerObserver: CapturerObserver? = null | ||
| 33 | + | ||
| 34 | + // This is automatically called when creating the LocalVideoTrack with the capturer. | ||
| 35 | + override fun initialize(helper: SurfaceTextureHelper, context: Context?, capturerObserver: CapturerObserver) { | ||
| 36 | + this.capturerObserver = capturerObserver | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + override fun startCapture(width: Int, height: Int, framerate: Int) { | ||
| 40 | + capturerObserver?.onCapturerStarted(true) | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + override fun stopCapture() { | ||
| 44 | + capturerObserver?.onCapturerStopped() | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + override fun changeCaptureFormat(width: Int, height: Int, framerate: Int) { | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + override fun dispose() { | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + override fun isScreencast(): Boolean = false | ||
| 54 | + | ||
| 55 | + fun pushVideoFrame(frame: VideoFrame) { | ||
| 56 | + capturerObserver?.onFrameCaptured(frame) | ||
| 57 | + } | ||
| 58 | +} |
-
请 注册 或 登录 后发表评论