public class ScreenCapturerAndroid extends java.lang.Object implements VideoCapturer, VideoSink
MediaProjection
on a SurfaceTexture
. We interact with this
SurfaceTexture
using a SurfaceTextureHelper
.
The SurfaceTextureHelper
is created by the native code and passed to this capturer in
VideoCapturer.initialize()
. On receiving a new frame, this capturer passes it
as a texture to the native code via CapturerObserver.onFrameCaptured()
. This takes
place on the HandlerThread of the given SurfaceTextureHelper
. When done with each frame,
the native code returns the buffer to the SurfaceTextureHelper
to be used for new
frames. At any time, at most one frame is being processed.
Note: This class is only supported on Android Lollipop and above.Constructor and Description |
---|
ScreenCapturerAndroid(android.content.Intent mediaProjectionPermissionResultData,
android.media.projection.MediaProjection.Callback mediaProjectionCallback)
Constructs a new Screen Capturer.
|
Modifier and Type | Method and Description |
---|---|
void |
changeCaptureFormat(int width,
int height,
int ignoredFramerate)
Changes output video format.
|
void |
dispose()
Perform any final cleanup here.
|
long |
getNumCapturedFrames() |
void |
initialize(SurfaceTextureHelper surfaceTextureHelper,
android.content.Context applicationContext,
CapturerObserver capturerObserver)
This function is used to initialize the camera thread, the android application context, and the
capture observer.
|
boolean |
isScreencast() |
void |
onFrame(VideoFrame frame)
Implementations should call frame.retain() if they need to hold a reference to the frame after
this function returns.
|
void |
startCapture(int width,
int height,
int ignoredFramerate)
Start capturing frames in a format that is as close as possible to
width x height and
framerate . |
void |
stopCapture()
Stop capturing.
|
public ScreenCapturerAndroid(android.content.Intent mediaProjectionPermissionResultData, android.media.projection.MediaProjection.Callback mediaProjectionCallback)
mediaProjectionPermissionResultData
- the result data of MediaProjection permission
activity; the calling app must validate that result code is Activity.RESULT_OK before
calling this method.mediaProjectionCallback
- MediaProjection callback to implement application specific
logic in events such as when the user revokes a previously granted capture permission.public void initialize(SurfaceTextureHelper surfaceTextureHelper, android.content.Context applicationContext, CapturerObserver capturerObserver)
VideoCapturer
surfaceTextureHelper
, register itself as a listener, and forward the frames to
CapturerObserver.onFrameCaptured(). The caller still has ownership of surfaceTextureHelper
and is responsible for making sure surfaceTextureHelper.dispose() is
called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new
VideoCapturer once the previous VideoCapturer has been disposed.initialize
in interface VideoCapturer
public void startCapture(int width, int height, int ignoredFramerate)
VideoCapturer
width x height
and
framerate
.startCapture
in interface VideoCapturer
public void stopCapture()
VideoCapturer
stopCapture
in interface VideoCapturer
public void dispose()
VideoCapturer
dispose
in interface VideoCapturer
public void changeCaptureFormat(int width, int height, int ignoredFramerate)
changeCaptureFormat
in interface VideoCapturer
width
- new output video widthheight
- new output video heightignoredFramerate
- ignoredpublic void onFrame(VideoFrame frame)
VideoSink
public boolean isScreencast()
isScreencast
in interface VideoCapturer
public long getNumCapturedFrames()
6.0.0