Skip to content

Commit

Permalink
Revert of Support adding and removing MediaRecorder to camera 2 sessi…
Browse files Browse the repository at this point in the history
…on. (patchset #5 id:80001 of https://codereview.webrtc.org/2833773003/ )

Reason for revert:
Breaks external bot

Original issue's description:
> 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}
> Committed: https://chromium.googlesource.com/external/webrtc/+/2fc04769faec0031a202963eaeb602420a082c07

TBR=sakal@webrtc.org,glaznev@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=b/36684011

Review-Url: https://codereview.webrtc.org/2844233002
Cr-Commit-Position: refs/heads/master@{#17905}
  • Loading branch information
Hnoo112233 authored and Commit bot committed Apr 27, 2017
1 parent 20a4b3f commit 6702739
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 302 deletions.
12 changes: 6 additions & 6 deletions webrtc/sdk/android/api/org/webrtc/Camera1Capturer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

package org.webrtc;

import org.webrtc.CameraEnumerationAndroid.CaptureFormat;

import android.content.Context;
import android.media.MediaRecorder;

import java.util.List;

public class Camera1Capturer extends CameraCapturer {
private final boolean captureToTexture;
Expand All @@ -26,11 +29,8 @@ public Camera1Capturer(
@Override
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
CameraSession.Events events, Context applicationContext,
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.");
}
SurfaceTextureHelper surfaceTextureHelper, String cameraName, int width, int height,
int framerate) {
Camera1Session.create(createSessionCallback, events, captureToTexture, applicationContext,
surfaceTextureHelper, Camera1Enumerator.getCameraIndex(cameraName), width, height,
framerate);
Expand Down
7 changes: 3 additions & 4 deletions webrtc/sdk/android/api/org/webrtc/Camera2Capturer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.hardware.camera2.CameraManager;
import android.media.MediaRecorder;

@TargetApi(21)
public class Camera2Capturer extends CameraCapturer {
Expand All @@ -30,9 +29,9 @@ public Camera2Capturer(Context context, String cameraName, CameraEventsHandler e
@Override
protected void createCameraSession(CameraSession.CreateSessionCallback createSessionCallback,
CameraSession.Events events, Context applicationContext,
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecoder, String cameraName,
int width, int height, int framerate) {
SurfaceTextureHelper surfaceTextureHelper, String cameraName, int width, int height,
int framerate) {
Camera2Session.create(createSessionCallback, events, applicationContext, cameraManager,
surfaceTextureHelper, mediaRecoder, cameraName, width, height, framerate);
surfaceTextureHelper, cameraName, width, height, framerate);
}
}
28 changes: 0 additions & 28 deletions webrtc/sdk/android/api/org/webrtc/CameraVideoCapturer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

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
Expand Down Expand Up @@ -61,32 +59,6 @@ public interface CameraSwitchHandler {
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.junit.After;
Expand Down Expand Up @@ -245,12 +244,6 @@ public void testCameraEvents() throws InterruptedException {
fixtures.cameraEventsInvoked();
}

@Test
@MediumTest
public void testUpdateMediaRecorder() throws InterruptedException, IOException {
fixtures.updateMediaRecorder(true /* useSurfaceCapture */);
}

// Test what happens when attempting to call e.g. switchCamera() after camera has been stopped.
@Test
@MediumTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.annotation.TargetApi;
import android.content.Context;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Environment;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -508,95 +502,6 @@ public void onCameraSwitchError(String errorDescription) {
disposeVideoTrackWithRenderer(videoTrackWithRenderer);
}

@TargetApi(21)
public void updateMediaRecorder(boolean useSurfaceCapture)
throws InterruptedException, IOException {
final CapturerInstance capturerInstance = createCapturer(false /* initialize */);
final VideoTrackWithRenderer videoTrackWithRenderer =
createVideoTrackWithRenderer(capturerInstance.capturer);
// Wait for the camera to start so we can add and remove MediaRecorder.
assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender() > 0);

final String videoOutPath = Environment.getExternalStorageDirectory().getPath()
+ "/chromium_tests_root/testmediarecorder.mp4";
File outputFile = new File(videoOutPath);

// Create MediaRecorder object
MediaRecorder mediaRecorder = new MediaRecorder();
mediaRecorder.setVideoSource(
useSurfaceCapture ? MediaRecorder.VideoSource.SURFACE : MediaRecorder.VideoSource.CAMERA);
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
profile.videoCodec = MediaRecorder.VideoEncoder.H264;
profile.videoBitRate = 2500000;
profile.videoFrameWidth = 640;
profile.videoFrameHeight = 480;
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoEncoder(profile.videoCodec);
mediaRecorder.setOutputFile(outputFile.getPath());
mediaRecorder.prepare();

// Add MediaRecorder to camera pipeline.
final boolean[] addMediaRecorderSuccessful = new boolean[1];
final CountDownLatch addBarrier = new CountDownLatch(1);
CameraVideoCapturer.MediaRecorderHandler addMediaRecorderHandler =
new CameraVideoCapturer.MediaRecorderHandler() {
@Override
public void onMediaRecorderSuccess() {
addMediaRecorderSuccessful[0] = true;
addBarrier.countDown();
}
@Override
public void onMediaRecorderError(String errorDescription) {
addMediaRecorderSuccessful[0] = false;
addBarrier.countDown();
}
};
capturerInstance.capturer.addMediaRecorderToCamera(mediaRecorder, addMediaRecorderHandler);
// Wait until MediaRecoder has been added.
addBarrier.await();
// Check result.
assertTrue(addMediaRecorderSuccessful[0]);

// Start MediaRecorder and wait for a few frames to capture.
mediaRecorder.start();
for (int i = 0; i < 5; i++) {
assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender() > 0);
}
mediaRecorder.stop();

// Remove MediaRecorder from camera pipeline.
final boolean[] removeMediaRecorderSuccessful = new boolean[1];
final CountDownLatch removeBarrier = new CountDownLatch(1);
CameraVideoCapturer.MediaRecorderHandler removeMediaRecorderHandler =
new CameraVideoCapturer.MediaRecorderHandler() {
@Override
public void onMediaRecorderSuccess() {
removeMediaRecorderSuccessful[0] = true;
removeBarrier.countDown();
}
@Override
public void onMediaRecorderError(String errorDescription) {
removeMediaRecorderSuccessful[0] = false;
removeBarrier.countDown();
}
};
capturerInstance.capturer.removeMediaRecorderFromCamera(removeMediaRecorderHandler);
// Wait until MediaRecoder has been removed.
removeBarrier.await();
// Check result.
assertTrue(removeMediaRecorderSuccessful[0]);
// Ensure that frames are received after removing MediaRecorder.
assertTrue(videoTrackWithRenderer.rendererCallbacks.waitForNextFrameToRender() > 0);
// Check that recorded file contains some data.
assertTrue(outputFile.length() > 0);

disposeCapturer(capturerInstance);
disposeVideoTrackWithRenderer(videoTrackWithRenderer);
}

public void cameraEventsInvoked() throws InterruptedException {
final CapturerInstance capturerInstance = createCapturer(true /* initialize */);
startCapture(capturerInstance);
Expand Down
28 changes: 8 additions & 20 deletions webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureFailure;
import android.hardware.camera2.CaptureRequest;
import android.media.MediaRecorder;
import android.os.Handler;
import android.util.Range;
import android.view.Surface;
import android.view.WindowManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
Expand All @@ -50,7 +49,6 @@ private static enum SessionState { RUNNING, STOPPED }
private final Context applicationContext;
private final CameraManager cameraManager;
private final SurfaceTextureHelper surfaceTextureHelper;
private final Surface mediaRecorderSurface;
private final String cameraId;
private final int width;
private final int height;
Expand Down Expand Up @@ -125,14 +123,9 @@ public void onOpened(CameraDevice camera) {
final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
surface = new Surface(surfaceTexture);
List<Surface> surfaces = new ArrayList<Surface>();
surfaces.add(surface);
if (mediaRecorderSurface != null) {
Logging.d(TAG, "Add MediaRecorder surface to capture session.");
surfaces.add(mediaRecorderSurface);
}
try {
camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
camera.createCaptureSession(
Arrays.asList(surface), new CaptureSessionCallback(), cameraThreadHandler);
} catch (CameraAccessException e) {
reportError("Failed to create capture session. " + e);
return;
Expand Down Expand Up @@ -182,10 +175,6 @@ public void onConfigured(CameraCaptureSession session) {
chooseFocusMode(captureRequestBuilder);

captureRequestBuilder.addTarget(surface);
if (mediaRecorderSurface != null) {
Logging.d(TAG, "Add MediaRecorder surface to CaptureRequest.Builder");
captureRequestBuilder.addTarget(mediaRecorderSurface);
}
session.setRepeatingRequest(
captureRequestBuilder.build(), new CameraCaptureCallback(), cameraThreadHandler);
} catch (CameraAccessException e) {
Expand Down Expand Up @@ -291,15 +280,15 @@ public void onCaptureFailed(

public static void create(CreateSessionCallback callback, Events events,
Context applicationContext, CameraManager cameraManager,
SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, String cameraId,
int width, int height, int framerate) {
SurfaceTextureHelper surfaceTextureHelper, String cameraId, int width, int height,
int framerate) {
new Camera2Session(callback, events, applicationContext, cameraManager, surfaceTextureHelper,
mediaRecorder, cameraId, width, height, framerate);
cameraId, width, height, framerate);
}

private Camera2Session(CreateSessionCallback callback, Events events, Context applicationContext,
CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper,
MediaRecorder mediaRecorder, String cameraId, int width, int height, int framerate) {
CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper, String cameraId,
int width, int height, int framerate) {
Logging.d(TAG, "Create new camera2 session on camera " + cameraId);

constructionTimeNs = System.nanoTime();
Expand All @@ -310,7 +299,6 @@ private Camera2Session(CreateSessionCallback callback, Events events, Context ap
this.applicationContext = applicationContext;
this.cameraManager = cameraManager;
this.surfaceTextureHelper = surfaceTextureHelper;
this.mediaRecorderSurface = (mediaRecorder != null) ? mediaRecorder.getSurface() : null;
this.cameraId = cameraId;
this.width = width;
this.height = height;
Expand Down
Loading

0 comments on commit 6702739

Please sign in to comment.