public class

CameraCapture

extends Object
java.lang.Object
   ↳ org.opencdnunion.media.streamer.capture.CameraCapture

Class Overview

The CameraCapture class is used to capture video frames from camera.

Summary

Nested Classes
interface CameraCapture.OnCameraCaptureListener Notify the event occurred while camera capturing. 
class CameraCapture.Size  
Constants
int CAMERA_ERROR_EVICTED
int CAMERA_ERROR_SERVER_DIED
int CAMERA_ERROR_START_FAILED
int CAMERA_ERROR_UNKNOWN
int CAMERA_STATE_IDLE
int CAMERA_STATE_INITIALIZING
int CAMERA_STATE_PREVIEWING
int CAMERA_STATE_STOPPING
int DEFAULT_PREVIEW_FPS
Fields
public static final int FACING_BACK
public static final int FACING_FRONT
public final SrcPin<ImgBufFrame> mImgBufSrcPin Source pin transfer ImgBufFrame, used for fallback cpu path
public final SrcPin<ImgTexFrame> mImgTexSrcPin Source pin transfer ImgTexFrame, used for gpu path and preview
Public Constructors
CameraCapture(Context context, GLRender glRender)
Public Methods
synchronized void autoFocus(Camera.AutoFocusCallback cb)
Starts camera auto-focus and registers a callback function to run when the camera is focused.
synchronized void cancelAutoFocus()
Cancels any auto-focus function in progress.Whether or not auto-focus is currently in progress,this function will return the focus position to the default.
int getCameraDisplayOrientation()
Get camera display orientation.
int getCameraFacing()
synchronized Camera.Parameters getCameraParameters()
Get parameters of current camera.
float getCurrentPreviewFps()
Get actual preview fps in the last second.
int getState()
Get current mState.
float getTargetPreviewFps()
Get actual preview fps set to camera.
CameraCapture.Size getTargetPreviewSize()
Get actual preview size currently used
boolean isRecording()
Is recording.
synchronized boolean isTorchSupported()
Check if flash torch mode supported of current camera.
void onFrameAvailable(SurfaceTexture surfaceTexture)
synchronized void release()
Clean resources.
synchronized boolean setCameraParameters(Camera.Parameters parameters)
Set new parameters to current camera.
synchronized void setCameraParametersAsync(Camera.Parameters parameters)
Set new parameters to current camera asynchronous.
void setEnableExposureWorkaround(boolean enableExposureWorkaround)
Fix dark preview in some device(such as Pixel) with 24/30fps.
void setEnableFrameDrop(boolean enableFrameDrop)
Drop frame if the real preview fps greater than the set value.
void setOnCameraCaptureListener(CameraCapture.OnCameraCaptureListener listener)
Set CameraCapture Listener.
void setOnPreviewFrameListener(OnPreviewFrameListener listener)
void setOrientation(int degrees)
Set preview orientation.
void setPreviewFps(float fps)
Set preset preview fps.
void setPreviewSize(int width, int height)
Set preset preview size of camera preview.
void setSpeed(float speed)
synchronized void start(int facing)
Start camera preview.
void startRecord()
start recording
synchronized void stop()
Stop camera preview.
void stopRecord()
stop recording
synchronized boolean switchCamera()
Switch front/back camera if supported.
synchronized boolean toggleTorch(boolean open)
Toggle torch of current camera.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CAMERA_ERROR_EVICTED

Constant Value: -2007 (0xfffff829)

public static final int CAMERA_ERROR_SERVER_DIED

Constant Value: -2006 (0xfffff82a)

public static final int CAMERA_ERROR_START_FAILED

Constant Value: -2002 (0xfffff82e)

public static final int CAMERA_ERROR_UNKNOWN

Constant Value: -2001 (0xfffff82f)

public static final int CAMERA_STATE_IDLE

Constant Value: 0 (0x00000000)

public static final int CAMERA_STATE_INITIALIZING

Constant Value: 1 (0x00000001)

public static final int CAMERA_STATE_PREVIEWING

Constant Value: 2 (0x00000002)

public static final int CAMERA_STATE_STOPPING

Constant Value: 3 (0x00000003)

public static final int DEFAULT_PREVIEW_FPS

Constant Value: 15 (0x0000000f)

Fields

public static final int FACING_BACK

public static final int FACING_FRONT

public final SrcPin<ImgBufFrame> mImgBufSrcPin

Source pin transfer ImgBufFrame, used for fallback cpu path

public final SrcPin<ImgTexFrame> mImgTexSrcPin

Source pin transfer ImgTexFrame, used for gpu path and preview

Public Constructors

public CameraCapture (Context context, GLRender glRender)

Public Methods

public synchronized void autoFocus (Camera.AutoFocusCallback cb)

Starts camera auto-focus and registers a callback function to run when the camera is focused.
Should be called on state CAMERA_STATE_PREVIEWING.

Parameters
cb the callback to run

public synchronized void cancelAutoFocus ()

Cancels any auto-focus function in progress.Whether or not auto-focus is currently in progress,this function will return the focus position to the default. If the camera does not support auto-focus, this is a no-op.
Should be called on state CAMERA_STATE_PREVIEWING.

public int getCameraDisplayOrientation ()

Get camera display orientation.
Should be called after start(int)

Returns
  • Camera display orientation in degrees.

public int getCameraFacing ()

public synchronized Camera.Parameters getCameraParameters ()

Get parameters of current camera.
Should be called on state CAMERA_STATE_PREVIEWING.

Returns
  • Camera parameters instance or null on invalid state.

public float getCurrentPreviewFps ()

Get actual preview fps in the last second.

Returns
  • current preview fps.

public int getState ()

public float getTargetPreviewFps ()

Get actual preview fps set to camera.

Returns
  • actual preview fps.

public CameraCapture.Size getTargetPreviewSize ()

Get actual preview size currently used

Returns
  • actual preview size.

public boolean isRecording ()

Is recording.

Returns
  • true if in recording, false if not.

public synchronized boolean isTorchSupported ()

Check if flash torch mode supported of current camera.
Should be called after onStarted() called.

Returns
  • false if not supported or called on invalid mState, true if supported.

public void onFrameAvailable (SurfaceTexture surfaceTexture)

public synchronized void release ()

Clean resources.
After this call, this object should not be accessed any more.

public synchronized boolean setCameraParameters (Camera.Parameters parameters)

Set new parameters to current camera.
Should be called on state CAMERA_STATE_PREVIEWING.

Parameters
parameters Camera parameters to be set.
Returns
  • true on success, false otherwise.

public synchronized void setCameraParametersAsync (Camera.Parameters parameters)

Set new parameters to current camera asynchronous.
Should be called on state CAMERA_STATE_PREVIEWING.

Parameters
parameters Camera parameters to be set.

public void setEnableExposureWorkaround (boolean enableExposureWorkaround)

Fix dark preview in some device(such as Pixel) with 24/30fps.

Parameters
enableExposureWorkaround true to enable, false to disable, default: true

public void setEnableFrameDrop (boolean enableFrameDrop)

Drop frame if the real preview fps greater than the set value.

Parameters
enableFrameDrop true to enable, false to disable, default: true

public void setOnCameraCaptureListener (CameraCapture.OnCameraCaptureListener listener)

Set CameraCapture Listener.
Should be set before call start(int)

Parameters
listener listener implemented by user

public void setOnPreviewFrameListener (OnPreviewFrameListener listener)

public void setOrientation (int degrees)

Set preview orientation.
Should be set before call start(int)

Parameters
degrees the rotate degrees of current Activity.
Acceptable value: 0, 90, 180, 270, other values will be ignored.
Default value is 0.

public void setPreviewFps (float fps)

Set preset preview fps.
Should be set before call start(int)

The preset fps may be different with the value finally used for preview.
The actual preview fps can be get by getTargetPreviewFps() after onStarted() called.

Parameters
fps preset fps, default value is 15.0f

public void setPreviewSize (int width, int height)

Set preset preview size of camera preview.
Should be set before call start(int)

The preset value may be different with the value finally used for preview.
The actual preview size can be get by getTargetPreviewSize() after onStarted() called.

Parameters
width preset width, default value is 1280
height preset height, default value is 720

public void setSpeed (float speed)

public synchronized void start (int facing)

Start camera preview.
Can only be called on mState IDLE.

Parameters
facing camera facing, acceptable value FACING_BACK, FACING_FRONT

public void startRecord ()

start recording

public synchronized void stop ()

Stop camera preview.
Can be called on mState CAMERA_STATE_INITIALIZING, CAMERA_STATE_PREVIEWING.

public void stopRecord ()

stop recording

public synchronized boolean switchCamera ()

Switch front/back camera if supported.

Returns
  • true if success, false if failed or on invalid mState.

public synchronized boolean toggleTorch (boolean open)

Toggle torch of current camera.

Parameters
open true to turn on, false to turn off.
Returns
  • true if success, false if failed or on invalid mState.