Package org.webrtc
Class NativeAndroidVideoTrackSource
java.lang.Object
org.webrtc.NativeAndroidVideoTrackSource
This class is meant to be a simple layer that only handles the JNI wrapping of a C++
AndroidVideoTrackSource, that can easily be mocked out in Java unit tests. Refrain from adding
any unnecessary logic to this class.
This class is thred safe and methods can be called from any thread, but if frames A, B, ..., are
sent to adaptFrame(), the adapted frames adaptedA, adaptedB, ..., needs to be passed in the same
order to onFrameCaptured().
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadaptFrame
(VideoFrame frame) This function should be called before delivering any frame to determine if the frame should be dropped or what the cropping and scaling parameters should be.void
adaptOutputFormat
(VideoSource.AspectRatio targetLandscapeAspectRatio, Integer maxLandscapePixelCount, VideoSource.AspectRatio targetPortraitAspectRatio, Integer maxPortraitPixelCount, Integer maxFps) Calling this function will cause frames to be scaled down to the requested resolution.(package private) static VideoProcessor.FrameAdaptationParameters
createFrameAdaptationParameters
(int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight, long timestampNs, boolean drop) private static VideoProcessor.FrameAdaptationParameters
nativeAdaptFrame
(long nativeAndroidVideoTrackSource, int width, int height, int rotation, long timestampNs) private static void
nativeAdaptOutputFormat
(long nativeAndroidVideoTrackSource, int landscapeWidth, int landscapeHeight, Integer maxLandscapePixelCount, int portraitWidth, int portraitHeight, Integer maxPortraitPixelCount, Integer maxFps) private static void
nativeOnFrameCaptured
(long nativeAndroidVideoTrackSource, int rotation, long timestampNs, VideoFrame.Buffer buffer) private static void
nativeSetIsScreencast
(long nativeAndroidVideoTrackSource, boolean isScreencast) private static void
nativeSetState
(long nativeAndroidVideoTrackSource, boolean isLive) void
onFrameCaptured
(VideoFrame frame) Pass an adapted frame to the native AndroidVideoTrackSource.void
setIsScreencast
(boolean isScreencast) void
setState
(boolean isLive) Set the state for the native MediaSourceInterface.
-
Field Details
-
nativeAndroidVideoTrackSource
private final long nativeAndroidVideoTrackSource
-
-
Constructor Details
-
NativeAndroidVideoTrackSource
public NativeAndroidVideoTrackSource(long nativeAndroidVideoTrackSource)
-
-
Method Details
-
setState
public void setState(boolean isLive) Set the state for the native MediaSourceInterface. Maps boolean to either SourceState::kLive or SourceState::kEnded. -
adaptFrame
This function should be called before delivering any frame to determine if the frame should be dropped or what the cropping and scaling parameters should be. If the return value is null, the frame should be dropped, otherwise the frame should be adapted in accordance to the frame adaptation parameters before calling onFrameCaptured(). -
onFrameCaptured
Pass an adapted frame to the native AndroidVideoTrackSource. Note that adaptFrame() is expected to be called first and that the passed frame conforms to those parameters. -
adaptOutputFormat
public void adaptOutputFormat(VideoSource.AspectRatio targetLandscapeAspectRatio, @Nullable Integer maxLandscapePixelCount, VideoSource.AspectRatio targetPortraitAspectRatio, @Nullable Integer maxPortraitPixelCount, @Nullable Integer maxFps) Calling this function will cause frames to be scaled down to the requested resolution. Also, frames will be cropped to match the requested aspect ratio, and frames will be dropped to match the requested fps. -
setIsScreencast
public void setIsScreencast(boolean isScreencast) -
createFrameAdaptationParameters
static VideoProcessor.FrameAdaptationParameters createFrameAdaptationParameters(int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight, long timestampNs, boolean drop) -
nativeSetIsScreencast
private static void nativeSetIsScreencast(long nativeAndroidVideoTrackSource, boolean isScreencast) -
nativeSetState
private static void nativeSetState(long nativeAndroidVideoTrackSource, boolean isLive) -
nativeAdaptOutputFormat
-
nativeAdaptFrame
@Nullable private static VideoProcessor.FrameAdaptationParameters nativeAdaptFrame(long nativeAndroidVideoTrackSource, int width, int height, int rotation, long timestampNs) -
nativeOnFrameCaptured
private static void nativeOnFrameCaptured(long nativeAndroidVideoTrackSource, int rotation, long timestampNs, VideoFrame.Buffer buffer)
-