Package 

Class Camera2Capturer

  • All Implemented Interfaces:
    com.twilio.video.VideoCapturer , tvi.webrtc.VideoCapturer

    
    public class Camera2Capturer
     implements VideoCapturer
                        

    The Camera2Capturer class is used to provide video frames for a LocalVideoTrack from the provided cameraId. The frames are provided via a . Camera2Capturer must be run on devices or higher.

    This class represents an implementation of a VideoCapturer interface. Although public, these methods are not meant to be invoked directly.

    This capturer can be reused, but cannot be shared across multiple LocalVideoTracks simultaneously. It is possible to construct multiple instances with different camera IDs, but there are device specific limitations on how many camera2 sessions can be open.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private String cameraId
    • Method Summary

      Modifier and Type Method Description
      synchronized String getCameraId() Returns the currently set camera ID.
      static boolean isSupported(@NonNull() Context context) Indicates if Camera2Capturer is compatible with device.
      boolean isScreencast() Indicates that the camera2 capturer is not a screen cast.
      void initialize(@NonNull() SurfaceTextureHelper surfaceTextureHelper, @NonNull() Context context, @NonNull() CapturerObserver capturerObserver)
      void startCapture(int width, int height, int framerate)
      void stopCapture() Stops all frames being captured.
      void dispose() This method provides an optional step to perform a final cleanup.
      synchronized void switchCamera(@NonNull() String newCameraId) Switches the current cameraId.
      synchronized boolean updateCaptureRequest(@NonNull() CaptureRequestUpdater captureRequestUpdater) Schedules a capture request update.
      • Methods inherited from class com.twilio.video.VideoCapturer

        changeCaptureFormat, getCaptureFormat
      • Methods inherited from class tvi.webrtc.VideoCapturer

        changeCaptureFormat, dispose, initialize, isScreencast, startCapture, stopCapture
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Camera2Capturer

        Camera2Capturer(Context context, String cameraId)
        Constructs a Camera2Capturer instance.
        Parameters:
        context - application context
        cameraId - unique identifier of the camera device to open that must be specified ingetCameraIdList
      • Camera2Capturer

        Camera2Capturer(Context context, String cameraId, Camera2Capturer.Listener listener)
        Constructs a Camera2Capturer instance.
        Parameters:
        context - application context
        cameraId - unique identifier of the camera device to open that must be specified ingetCameraIdList
        listener - an optional listener of camera2 capturer events
    • Method Detail

      • isSupported

         static boolean isSupported(@NonNull() Context context)

        Indicates if Camera2Capturer is compatible with device.

        This method checks that all the following conditions are true:

        • The device API level is at least LOLLIPOP.
        • All device cameras have hardware support level greater than .
        For more details on supported hardware levels see the Androiddocumentation.
        Parameters:
        context - application context.
      • isScreencast

         boolean isScreencast()

        Indicates that the camera2 capturer is not a screen cast.

      • startCapture

         void startCapture(int width, int height, int framerate)
      • stopCapture

         void stopCapture()

        Stops all frames being captured.

        Note: This method is not meant to be invoked directly.

      • dispose

         void dispose()

        This method provides an optional step to perform a final cleanup.

      • updateCaptureRequest

         synchronized boolean updateCaptureRequest(@NonNull() CaptureRequestUpdater captureRequestUpdater)

        Schedules a capture request update.

        A CaptureRequest.Builder optimal for capturing video for streaming will beprovided for modification to the provided CaptureRequestUpdater. Modifications to the CaptureRequest.Builder will be applied to the after the invocation of . can be invoked while capturing frames or not.If the Camera2Capturer is not capturing the CaptureRequestUpdater will becalled when capturer resumes.

        The following snippet demonstrates how to turn on the flash of a camera while capturing.

         // Create the camera2 capturer Camera2Capturer camera2Capturer = new Camera2Capturer(context, cameraId, camera2Listener); // Start the camera2 capturer LocalVideoTrack camera2VideoTrack = LocalVideoTrack.create(context, true, camera2Capturer); // Schedule the capture request update camera2Capturer.updateCaptureRequest(new CaptureRequestUpdater() { {@literal @}Override public void apply(@NonNull CaptureRequest.Builder captureRequestBuilder) { captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH); } } 

        The camera2 capturer will raise an Exception to the provided Listener withthe code CAPTURE_REQUEST_UPDATE_FAILED if a successfully scheduled capturerequest update failed to be applied.

        Parameters:
        captureRequestUpdater - capture request updater that receives the capture requestbuilder that can be modified.