public class ScreenCapturerAndroid extends java.lang.Object implements VideoCapturer, java.lang.Cloneable, SurfaceTextureHelper.OnTextureFrameAvailableListener
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.限定符和类型 | 类和说明 |
---|---|
static interface |
ScreenCapturerAndroid.TextureFrameAvailable |
VideoCapturer.CapturerObserver
构造器和说明 |
---|
ScreenCapturerAndroid(Intent mediaProjectionPermissionResultData,
MediaProjection.Callback mediaProjectionCallback)
Constructs a new Screen Capturer.
|
限定符和类型 | 方法和说明 |
---|---|
void |
changeCaptureFormat(int width,
int height,
int ignoredFramerate)
Changes output video format.
|
static void |
configureContext(Context weakContext) |
void |
dispose()
Perform any final cleanup here.
|
long |
getNumCapturedFrames() |
void |
initialize(SurfaceTextureHelper surfaceTextureHelper,
Context applicationContext,
VideoCapturer.CapturerObserver capturerObserver)
This function is used to initialize the camera thread, the android application context, and the
capture observer.
|
boolean |
isScreencast() |
void |
onTextureFrameAvailable(int oesTextureId,
float[] transformMatrix,
long timestampNs) |
void |
pauseCapture()
暂停桌面数据采集
|
void |
resumeCapture()
重启桌面数据采集
|
void |
setTextureFrameAvailableListener(ScreenCapturerAndroid.TextureFrameAvailable listener) |
void |
startCapture(int width,
int height,
int maxFPS)
Start capturing frames in a format that is as close as possible to
width x height and
framerate . |
void |
stopCapture()
Stop capturing.
|
public ScreenCapturerAndroid(Intent mediaProjectionPermissionResultData, 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, Context applicationContext, VideoCapturer.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
在接口中 VideoCapturer
public void startCapture(int width, int height, int maxFPS)
VideoCapturer
width x height
and
framerate
.startCapture
在接口中 VideoCapturer
public void stopCapture()
VideoCapturer
stopCapture
在接口中 VideoCapturer
public void pauseCapture()
public void resumeCapture()
public void dispose()
VideoCapturer
dispose
在接口中 VideoCapturer
public void changeCaptureFormat(int width, int height, int ignoredFramerate)
changeCaptureFormat
在接口中 VideoCapturer
width
- new output video widthheight
- new output video heightignoredFramerate
- ignoredpublic void onTextureFrameAvailable(int oesTextureId, float[] transformMatrix, long timestampNs)
public static void configureContext(Context weakContext)
public boolean isScreencast()
isScreencast
在接口中 VideoCapturer
public long getNumCapturedFrames()
public void setTextureFrameAvailableListener(ScreenCapturerAndroid.TextureFrameAvailable listener)