Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(783)

Unified Diff: media/base/android/java/src/org/chromium/media/VideoCaptureCamera.java

Issue 656323004: Android Video Capture: Refactor VideoCapture class hierarchy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/android/java/src/org/chromium/media/VideoCaptureCamera.java
diff --git a/media/base/android/java/src/org/chromium/media/VideoCapture.java b/media/base/android/java/src/org/chromium/media/VideoCaptureCamera.java
similarity index 73%
copy from media/base/android/java/src/org/chromium/media/VideoCapture.java
copy to media/base/android/java/src/org/chromium/media/VideoCaptureCamera.java
index 9d008652cc802c484d1f486153fb801c5ec041cd..dd1632b07fb6609667f000d444b7d7d15c24f760 100644
--- a/media/base/android/java/src/org/chromium/media/VideoCapture.java
+++ b/media/base/android/java/src/org/chromium/media/VideoCaptureCamera.java
@@ -5,14 +5,12 @@
package org.chromium.media;
import android.content.Context;
-import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.util.Log;
import android.view.Surface;
import android.view.WindowManager;
-import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import java.io.IOException;
@@ -20,54 +18,21 @@ import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
/**
- * Video Capture Device base class to interface to native Chromium.
+ * Video Capture Device extension of VideoCapture to provide common functionality
+ * for capture using android.hardware.Camera API (deprecated in API 21). Normal
+ * Android and Tango devices are extensions of this class.
**/
@JNINamespace("media")
@SuppressWarnings("deprecation")
-public abstract class VideoCapture implements android.hardware.Camera.PreviewCallback {
-
- protected static class CaptureFormat {
- int mWidth;
- int mHeight;
- final int mFramerate;
- final int mPixelFormat;
-
- public CaptureFormat(
- int width, int height, int framerate, int pixelformat) {
- mWidth = width;
- mHeight = height;
- mFramerate = framerate;
- mPixelFormat = pixelformat;
- }
-
- public int getWidth() {
- return mWidth;
- }
-
- public int getHeight() {
- return mHeight;
- }
-
- public int getFramerate() {
- return mFramerate;
- }
-
- public int getPixelFormat() {
- return mPixelFormat;
- }
- }
+public abstract class VideoCaptureCamera extends VideoCapture
+ implements android.hardware.Camera.PreviewCallback {
protected android.hardware.Camera mCamera;
- protected CaptureFormat mCaptureFormat = null;
- // Lock to mutually exclude execution of OnPreviewFrame {start/stop}Capture.
+ // Lock to mutually exclude execution of OnPreviewFrame() and {start/stop}Capture().
protected ReentrantLock mPreviewBufferLock = new ReentrantLock();
- protected Context mContext = null;
// True when native code has started capture.
protected boolean mIsRunning = false;
- protected int mId;
- // Native callback context variable.
- protected long mNativeVideoCaptureDeviceAndroid;
protected int[] mGlTextures = null;
protected SurfaceTexture mSurfaceTexture = null;
protected static final int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
@@ -75,9 +40,9 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
protected int mCameraOrientation;
protected int mCameraFacing;
protected int mDeviceOrientation;
- private static final String TAG = "VideoCapture";
+ private static final String TAG = "VideoCaptureCamera";
- static android.hardware.Camera.CameraInfo getCameraInfo(int id) {
+ protected static android.hardware.Camera.CameraInfo getCameraInfo(int id) {
android.hardware.Camera.CameraInfo cameraInfo =
new android.hardware.Camera.CameraInfo();
try {
@@ -89,18 +54,29 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
return cameraInfo;
}
- VideoCapture(Context context,
- int id,
- long nativeVideoCaptureDeviceAndroid) {
- mContext = context;
- mId = id;
- mNativeVideoCaptureDeviceAndroid = nativeVideoCaptureDeviceAndroid;
+ protected static android.hardware.Camera.Parameters getCameraParameters(
+ android.hardware.Camera camera) {
+ android.hardware.Camera.Parameters parameters;
+ try {
+ parameters = camera.getParameters();
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "getCameraParameters: android.hardware.Camera.getParameters: " + ex);
+ camera.release();
+ return null;
+ }
+ return parameters;
+ }
+
+ VideoCaptureCamera(Context context,
+ int id,
+ long nativeVideoCaptureDeviceAndroid) {
+ super(context, id, nativeVideoCaptureDeviceAndroid);
}
- @CalledByNative
- boolean allocate(int width, int height, int frameRate) {
- Log.d(TAG, "allocate: requested (" + width + "x" + height + ")@" +
- frameRate + "fps");
+ @Override
+ public boolean allocate(int width, int height, int frameRate) {
+ Log.d(TAG, "allocate: requested (" + width + "x" + height + ")@"
+ + frameRate + "fps");
try {
mCamera = android.hardware.Camera.open(mId);
} catch (RuntimeException ex) {
@@ -108,7 +84,7 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
return false;
}
- android.hardware.Camera.CameraInfo cameraInfo = VideoCapture.getCameraInfo(mId);
+ android.hardware.Camera.CameraInfo cameraInfo = VideoCaptureCamera.getCameraInfo(mId);
if (cameraInfo == null) {
mCamera.release();
mCamera = null;
@@ -118,8 +94,8 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
mCameraOrientation = cameraInfo.orientation;
mCameraFacing = cameraInfo.facing;
mDeviceOrientation = getDeviceOrientation();
- Log.d(TAG, "allocate: orientation dev=" + mDeviceOrientation +
- ", cam=" + mCameraOrientation + ", facing=" + mCameraFacing);
+ Log.d(TAG, "allocate: orientation dev=" + mDeviceOrientation
+ + ", cam=" + mCameraOrientation + ", facing=" + mCameraFacing);
android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) {
@@ -141,15 +117,15 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
// API fps ranges are scaled up x1000 to avoid floating point.
int frameRateScaled = frameRate * 1000;
for (int[] fpsRange : listFpsRange) {
- if (fpsRange[0] <= frameRateScaled && frameRateScaled <= fpsRange[1] &&
- (fpsRange[1] - fpsRange[0]) <= fpsRangeSize) {
+ if (fpsRange[0] <= frameRateScaled && frameRateScaled <= fpsRange[1]
+ && (fpsRange[1] - fpsRange[0]) <= fpsRangeSize) {
chosenFpsRange = fpsRange;
chosenFrameRate = frameRate;
fpsRangeSize = fpsRange[1] - fpsRange[0];
}
}
- Log.d(TAG, "allocate: fps set to " + chosenFrameRate + ", [" +
- chosenFpsRange[0] + "-" + chosenFpsRange[1] + "]");
+ Log.d(TAG, "allocate: fps set to " + chosenFrameRate + ", ["
+ + chosenFpsRange[0] + "-" + chosenFpsRange[1] + "]");
// Calculate size.
List<android.hardware.Camera.Size> listCameraSize =
@@ -158,10 +134,10 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
int matchedWidth = width;
int matchedHeight = height;
for (android.hardware.Camera.Size size : listCameraSize) {
- int diff = Math.abs(size.width - width) +
- Math.abs(size.height - height);
- Log.d(TAG, "allocate: supported (" +
- size.width + ", " + size.height + "), diff=" + diff);
+ int diff = Math.abs(size.width - width)
+ + Math.abs(size.height - height);
+ Log.d(TAG, "allocate: supported ("
+ + size.width + ", " + size.height + "), diff=" + diff);
// TODO(wjia): Remove this hack (forcing width to be multiple
// of 32) by supporting stride in video frame buffer.
// Right now, VideoCaptureController requires compact YV12
@@ -179,8 +155,8 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
Log.d(TAG, "allocate: matched (" + matchedWidth + "x" + matchedHeight + ")");
if (parameters.isVideoStabilizationSupported()) {
- Log.d(TAG, "Image stabilization supported, currently: " +
- parameters.getVideoStabilization() + ", setting it.");
+ Log.d(TAG, "Image stabilization supported, currently: "
+ + parameters.getVideoStabilization() + ", setting it.");
parameters.setVideoStabilization(true);
} else {
Log.d(TAG, "Image stabilization not supported.");
@@ -228,7 +204,7 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
return true;
}
- @CalledByNative
+ @Override
public int startCapture() {
if (mCamera == null) {
Log.e(TAG, "startCapture: camera is null");
@@ -254,7 +230,7 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
return 0;
}
- @CalledByNative
+ @Override
public int stopCapture() {
if (mCamera == null) {
Log.e(TAG, "stopCapture: camera is null");
@@ -276,10 +252,9 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
return 0;
}
- @CalledByNative
+ @Override
public void deallocate() {
- if (mCamera == null)
- return;
+ if (mCamera == null) return;
stopCapture();
try {
@@ -303,42 +278,10 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
int frameRate,
android.hardware.Camera.Parameters cameraParameters);
- // Local hook to allow derived classes to configure and plug capture
- // buffers if needed.
- abstract void allocateBuffers();
-
// Local method to be overriden with the particular setPreviewCallback to be
// used in the implementations.
abstract void setPreviewCallback(android.hardware.Camera.PreviewCallback cb);
- @CalledByNative
- public int queryWidth() {
- return mCaptureFormat.mWidth;
- }
-
- @CalledByNative
- public int queryHeight() {
- return mCaptureFormat.mHeight;
- }
-
- @CalledByNative
- public int queryFrameRate() {
- return mCaptureFormat.mFramerate;
- }
-
- @CalledByNative
- public int getColorspace() {
- switch (mCaptureFormat.mPixelFormat) {
- case ImageFormat.YV12:
- return AndroidImageFormat.YV12;
- case ImageFormat.NV21:
- return AndroidImageFormat.NV21;
- case ImageFormat.UNKNOWN:
- default:
- return AndroidImageFormat.UNKNOWN;
- }
- }
-
protected int getDeviceOrientation() {
int orientation = 0;
if (mContext != null) {
@@ -362,25 +305,4 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
}
return orientation;
}
-
- // Method for VideoCapture implementations to call back native code.
- public native void nativeOnFrameAvailable(
- long nativeVideoCaptureDeviceAndroid,
- byte[] data,
- int length,
- int rotation);
-
- protected static android.hardware.Camera.Parameters getCameraParameters(
- android.hardware.Camera camera) {
- android.hardware.Camera.Parameters parameters;
- try {
- parameters = camera.getParameters();
- } catch (RuntimeException ex) {
- Log.e(TAG, "getCameraParameters: android.hardware.Camera.getParameters: " + ex);
- camera.release();
- return null;
- }
- return parameters;
- }
-
}

Powered by Google App Engine
This is Rietveld 408576698