Introduce class that handles native wrapping of AndroidVideoTrackSource

This CL attempts to do separation of concerns by introducing a simple
class that only handles JNI wrapping of a C++ AndroidVideoTrackSource.
This layer can be easiliy mocked out in Java unit tests.

Bug: webrtc:10247
Change-Id: Idbdbfde6d3e00b64f3f310f76505801fa496580d
Reviewed-on: https://webrtc-review.googlesource.com/c/121562
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26556}
This commit is contained in:
Magnus Jedvert
2019-02-05 16:39:41 +01:00
committed by Commit Bot
parent b3032b6e33
commit 99b275d126
8 changed files with 189 additions and 132 deletions

View File

@ -10,40 +10,32 @@
package org.webrtc;
import android.support.annotation.Nullable;
import org.webrtc.VideoFrame;
/**
* Implements VideoCapturer.CapturerObserver and feeds frames to
* webrtc::jni::AndroidVideoTrackSource.
* Used from native api and implements a simple VideoCapturer.CapturerObserver that feeds frames to
* a webrtc::jni::AndroidVideoTrackSource.
*/
class NativeCapturerObserver implements CapturerObserver {
// Pointer to webrtc::jni::AndroidVideoTrackSource.
private final long nativeSource;
private final NativeAndroidVideoTrackSource nativeAndroidVideoTrackSource;
@CalledByNative
public NativeCapturerObserver(long nativeSource) {
this.nativeSource = nativeSource;
this.nativeAndroidVideoTrackSource = new NativeAndroidVideoTrackSource(nativeSource);
}
@Override
public void onCapturerStarted(boolean success) {
nativeCapturerStarted(nativeSource, success);
nativeAndroidVideoTrackSource.setState(success);
}
@Override
public void onCapturerStopped() {
nativeCapturerStopped(nativeSource);
nativeAndroidVideoTrackSource.setState(/* isLive= */ false);
}
@Override
public void onFrameCaptured(VideoFrame frame) {
nativeOnFrameCaptured(nativeSource, frame.getBuffer().getWidth(), frame.getBuffer().getHeight(),
frame.getRotation(), frame.getTimestampNs(), frame.getBuffer());
nativeAndroidVideoTrackSource.onFrameCaptured(frame);
}
private static native void nativeCapturerStarted(long source, boolean success);
private static native void nativeCapturerStopped(long source);
private static native void nativeOnFrameCaptured(
long source, int width, int height, int rotation, long timestampNs, VideoFrame.Buffer frame);
}