Support adding and removing MediaRecorder to camera 2 session.
Camera 1 API is not supported. BUG=b/36684011 Review-Url: https://codereview.webrtc.org/2833773003 Cr-Commit-Position: refs/heads/master@{#17901}
This commit is contained in:
@ -10,11 +10,8 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
public class Camera1Capturer extends CameraCapturer {
|
||||
private final boolean captureToTexture;
|
||||
@ -29,8 +26,11 @@ public class Camera1Capturer extends CameraCapturer {
|
||||
@Override
|
||||
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
|
||||
CameraSession.Events events, Context applicationContext,
|
||||
SurfaceTextureHelper surfaceTextureHelper, String cameraName, int width, int height,
|
||||
int framerate) {
|
||||
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, String cameraName,
|
||||
int width, int height, int framerate) {
|
||||
if (mediaRecorder != null) {
|
||||
throw new RuntimeException("MediaRecoder is not supported for camera 1.");
|
||||
}
|
||||
Camera1Session.create(createSessionCallback, events, captureToTexture, applicationContext,
|
||||
surfaceTextureHelper, Camera1Enumerator.getCameraIndex(cameraName), width, height,
|
||||
framerate);
|
||||
|
||||
@ -13,6 +13,7 @@ package org.webrtc;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
@TargetApi(21)
|
||||
public class Camera2Capturer extends CameraCapturer {
|
||||
@ -29,9 +30,9 @@ public class Camera2Capturer extends CameraCapturer {
|
||||
@Override
|
||||
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
|
||||
CameraSession.Events events, Context applicationContext,
|
||||
SurfaceTextureHelper surfaceTextureHelper, String cameraName, int width, int height,
|
||||
int framerate) {
|
||||
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecoder, String cameraName,
|
||||
int width, int height, int framerate) {
|
||||
Camera2Session.create(createSessionCallback, events, applicationContext, cameraManager,
|
||||
surfaceTextureHelper, cameraName, width, height, framerate);
|
||||
surfaceTextureHelper, mediaRecoder, cameraName, width, height, framerate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
/**
|
||||
* Base interface for camera1 and camera2 implementations. Extends VideoCapturer with a
|
||||
* switchCamera() function. Also provides subinterfaces for handling camera events, and a helper
|
||||
@ -59,6 +61,32 @@ public interface CameraVideoCapturer extends VideoCapturer {
|
||||
*/
|
||||
void switchCamera(CameraSwitchHandler switchEventsHandler);
|
||||
|
||||
/**
|
||||
* MediaRecorder add/remove handler - one of these functions are invoked with the result of
|
||||
* addMediaRecorderToCamera() or removeMediaRecorderFromCamera calls.
|
||||
* The callback may be called on an arbitrary thread.
|
||||
*/
|
||||
public interface MediaRecorderHandler {
|
||||
// Invoked on success.
|
||||
void onMediaRecorderSuccess();
|
||||
|
||||
// Invoked on failure, e.g. camera is stopped or any exception happens.
|
||||
void onMediaRecorderError(String errorDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add MediaRecorder to camera pipeline. This can only be called while the camera is running.
|
||||
* Once MediaRecorder is added to camera pipeline camera switch is not allowed.
|
||||
* This function can be called from any thread.
|
||||
*/
|
||||
void addMediaRecorderToCamera(MediaRecorder mediaRecorder, MediaRecorderHandler resultHandler);
|
||||
|
||||
/**
|
||||
* Remove MediaRecorder from camera pipeline. This can only be called while the camera is running.
|
||||
* This function can be called from any thread.
|
||||
*/
|
||||
void removeMediaRecorderFromCamera(MediaRecorderHandler resultHandler);
|
||||
|
||||
/**
|
||||
* Helper class to log framerate and detect if the camera freezes. It will run periodic callbacks
|
||||
* on the SurfaceTextureHelper thread passed in the ctor, and should only be operated from that
|
||||
|
||||
Reference in New Issue
Block a user