-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for video processing and examples (#495)
* Add utility class NoDropVideoProcessor to force video processing while not connected * Fix local video tracks not rendering processed frames
- Loading branch information
Showing
7 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"client-sdk-android": patch | ||
--- | ||
|
||
Fix local video tracks not rendering processed frames |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"client-sdk-android": patch | ||
--- | ||
|
||
Add utility class NoDropVideoProcessor to force video processing while not connected |
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
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
25 changes: 25 additions & 0 deletions
25
livekit-android-sdk/src/main/java/io/livekit/android/annotations/WebRTCSensitive.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.annotations | ||
|
||
/** | ||
* The target marked with this annotation is sensitive to the internal | ||
* code of WebRTC, and should be directly retested whenever WebRTC version | ||
* is upgraded. | ||
*/ | ||
@Retention(AnnotationRetention.SOURCE) | ||
annotation class WebRTCSensitive |
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
56 changes: 56 additions & 0 deletions
56
...kit-android-sdk/src/main/java/io/livekit/android/room/track/video/NoDropVideoProcessor.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 io.livekit.android.annotations.WebRTCSensitive | ||
import livekit.org.webrtc.VideoFrame | ||
import livekit.org.webrtc.VideoProcessor | ||
|
||
/** | ||
* When not connected to a room, the base [VideoProcessor] implementation will refuse | ||
* to process frames as they will all be dropped (i.e. not sent). | ||
* | ||
* This implementation by default forces all frames to be processed regardless of publish status. | ||
* | ||
* Change [allowDropping] to true if you want to allow dropping of frames. | ||
*/ | ||
abstract class NoDropVideoProcessor : VideoProcessor { | ||
/** | ||
* If set to false, forces all frames to be processed regardless of publish status. | ||
* If set to true, frames will only be processed when the associated video track is published. | ||
* | ||
* By default, set to false. | ||
*/ | ||
@Suppress("MemberVisibilityCanBePrivate") | ||
var allowDropping = false | ||
|
||
@WebRTCSensitive | ||
override fun onFrameCaptured(frame: VideoFrame, parameters: VideoProcessor.FrameAdaptationParameters) { | ||
if (allowDropping) { | ||
super.onFrameCaptured(frame, parameters) | ||
} else { | ||
// Altered from VideoProcessor | ||
val adaptedFrame = VideoProcessor.applyFrameAdaptationParameters(frame, parameters) | ||
if (adaptedFrame != null) { | ||
this.onFrameCaptured(adaptedFrame) | ||
adaptedFrame.release() | ||
} else { | ||
this.onFrameCaptured(frame) | ||
} | ||
} | ||
} | ||
} |