Skip to content

Commit

Permalink
VideoFrameCapturer for pushing frames directly (#538)
Browse files Browse the repository at this point in the history
* VideoFrameCapturer for pushing frames directly

* changeset and spotless
  • Loading branch information
davidliu authored Nov 13, 2024
1 parent 7a9a32f commit 05ac208
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-feet-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Added VideoFrameCapturer for pushing video frames directly
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.livekit.android.room.track.video

import android.content.Context
import livekit.org.webrtc.CapturerObserver
import livekit.org.webrtc.SurfaceTextureHelper
import livekit.org.webrtc.VideoCapturer
import livekit.org.webrtc.VideoFrame

/**
* A [VideoCapturer] that can be manually driven by passing in [VideoFrame] to [pushVideoFrame].
*
* Once [startCapture] is called, call [pushVideoFrame] to publish video frames.
*/
open class VideoFrameCapturer : VideoCapturer {

var capturerObserver: CapturerObserver? = null

// This is automatically called when creating the LocalVideoTrack with the capturer.
override fun initialize(helper: SurfaceTextureHelper, context: Context?, capturerObserver: CapturerObserver) {
this.capturerObserver = capturerObserver
}

override fun startCapture(width: Int, height: Int, framerate: Int) {
capturerObserver?.onCapturerStarted(true)
}

override fun stopCapture() {
capturerObserver?.onCapturerStopped()
}

override fun changeCaptureFormat(width: Int, height: Int, framerate: Int) {
}

override fun dispose() {
}

override fun isScreencast(): Boolean = false

fun pushVideoFrame(frame: VideoFrame) {
capturerObserver?.onFrameCaptured(frame)
}
}

0 comments on commit 05ac208

Please sign in to comment.