Commit dc59e542 authored by mcasas's avatar mcasas Committed by Commit bot

Android Video Capture: Using full class path for Camera+subclasses to avoid @deprecation warnings

Since @SuppressWarnings("deprecated") doesn't work for
import statements, the only option is to use the fully
qualified class path in every reference.

To be sure, two deprecation warnings still remain,
namely in the use of

public abstract class VideoCapture implements android.hardware.Camera.PreviewCallback {

That somehow is not covered by the suppression.

TBR=qinmin@chromium.org
BUG=398669

Review URL: https://codereview.chromium.org/605183002

Cr-Commit-Position: refs/heads/master@{#296918}
parent d5597f9c
...@@ -7,8 +7,6 @@ package org.chromium.media; ...@@ -7,8 +7,6 @@ package org.chromium.media;
import android.content.Context; import android.content.Context;
import android.graphics.ImageFormat; import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
...@@ -26,7 +24,7 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -26,7 +24,7 @@ import java.util.concurrent.locks.ReentrantLock;
**/ **/
@JNINamespace("media") @JNINamespace("media")
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class VideoCapture implements PreviewCallback { public abstract class VideoCapture implements android.hardware.Camera.PreviewCallback {
protected static class CaptureFormat { protected static class CaptureFormat {
int mWidth; int mWidth;
...@@ -59,7 +57,7 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -59,7 +57,7 @@ public abstract class VideoCapture implements PreviewCallback {
} }
} }
protected Camera mCamera; protected android.hardware.Camera mCamera;
protected CaptureFormat mCaptureFormat = null; protected CaptureFormat mCaptureFormat = null;
// Lock to mutually exclude execution of OnPreviewFrame {start/stop}Capture. // Lock to mutually exclude execution of OnPreviewFrame {start/stop}Capture.
protected ReentrantLock mPreviewBufferLock = new ReentrantLock(); protected ReentrantLock mPreviewBufferLock = new ReentrantLock();
...@@ -92,13 +90,13 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -92,13 +90,13 @@ public abstract class VideoCapture implements PreviewCallback {
Log.d(TAG, "allocate: requested (" + width + "x" + height + ")@" + Log.d(TAG, "allocate: requested (" + width + "x" + height + ")@" +
frameRate + "fps"); frameRate + "fps");
try { try {
mCamera = Camera.open(mId); mCamera = android.hardware.Camera.open(mId);
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
Log.e(TAG, "allocate: Camera.open: " + ex); Log.e(TAG, "allocate: Camera.open: " + ex);
return false; return false;
} }
Camera.CameraInfo cameraInfo = getCameraInfo(mId); android.hardware.Camera.CameraInfo cameraInfo = getCameraInfo(mId);
if (cameraInfo == null) { if (cameraInfo == null) {
mCamera.release(); mCamera.release();
mCamera = null; mCamera = null;
...@@ -111,7 +109,7 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -111,7 +109,7 @@ public abstract class VideoCapture implements PreviewCallback {
Log.d(TAG, "allocate: orientation dev=" + mDeviceOrientation + Log.d(TAG, "allocate: orientation dev=" + mDeviceOrientation +
", cam=" + mCameraOrientation + ", facing=" + mCameraFacing); ", cam=" + mCameraOrientation + ", facing=" + mCameraFacing);
Camera.Parameters parameters = getCameraParameters(mCamera); android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) { if (parameters == null) {
mCamera = null; mCamera = null;
return false; return false;
...@@ -139,12 +137,12 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -139,12 +137,12 @@ public abstract class VideoCapture implements PreviewCallback {
Log.d(TAG, "allocate: fps set to " + frameRate); Log.d(TAG, "allocate: fps set to " + frameRate);
// Calculate size. // Calculate size.
List<Camera.Size> listCameraSize = List<android.hardware.Camera.Size> listCameraSize =
parameters.getSupportedPreviewSizes(); parameters.getSupportedPreviewSizes();
int minDiff = Integer.MAX_VALUE; int minDiff = Integer.MAX_VALUE;
int matchedWidth = width; int matchedWidth = width;
int matchedHeight = height; int matchedHeight = height;
for (Camera.Size size : listCameraSize) { for (android.hardware.Camera.Size size : listCameraSize) {
int diff = Math.abs(size.width - width) + int diff = Math.abs(size.width - width) +
Math.abs(size.height - height); Math.abs(size.height - height);
Log.d(TAG, "allocate: supported (" + Log.d(TAG, "allocate: supported (" +
...@@ -288,7 +286,7 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -288,7 +286,7 @@ public abstract class VideoCapture implements PreviewCallback {
int width, int width,
int height, int height,
int frameRate, int frameRate,
Camera.Parameters cameraParameters); android.hardware.Camera.Parameters cameraParameters);
// Local hook to allow derived classes to configure and plug capture // Local hook to allow derived classes to configure and plug capture
// buffers if needed. // buffers if needed.
...@@ -296,7 +294,7 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -296,7 +294,7 @@ public abstract class VideoCapture implements PreviewCallback {
// Local method to be overriden with the particular setPreviewCallback to be // Local method to be overriden with the particular setPreviewCallback to be
// used in the implementations. // used in the implementations.
abstract void setPreviewCallback(Camera.PreviewCallback cb); abstract void setPreviewCallback(android.hardware.Camera.PreviewCallback cb);
@CalledByNative @CalledByNative
public int queryWidth() { public int queryWidth() {
...@@ -357,24 +355,25 @@ public abstract class VideoCapture implements PreviewCallback { ...@@ -357,24 +355,25 @@ public abstract class VideoCapture implements PreviewCallback {
int length, int length,
int rotation); int rotation);
protected static Camera.Parameters getCameraParameters(Camera camera) { protected static android.hardware.Camera.Parameters getCameraParameters(
Camera.Parameters parameters; android.hardware.Camera camera) {
android.hardware.Camera.Parameters parameters;
try { try {
parameters = camera.getParameters(); parameters = camera.getParameters();
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
Log.e(TAG, "getCameraParameters: Camera.getParameters: " + ex); Log.e(TAG, "getCameraParameters: android.hardware.Camera.getParameters: " + ex);
camera.release(); camera.release();
return null; return null;
} }
return parameters; return parameters;
} }
private Camera.CameraInfo getCameraInfo(int id) { private android.hardware.Camera.CameraInfo getCameraInfo(int id) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); android.hardware.Camera.CameraInfo cameraInfo = new android.hardware.Camera.CameraInfo();
try { try {
Camera.getCameraInfo(id, cameraInfo); android.hardware.Camera.getCameraInfo(id, cameraInfo);
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
Log.e(TAG, "getCameraInfo: Camera.getCameraInfo: " + ex); Log.e(TAG, "getCameraInfo: android.hardware.Camera.getCameraInfo: " + ex);
return null; return null;
} }
return cameraInfo; return cameraInfo;
......
...@@ -6,8 +6,6 @@ package org.chromium.media; ...@@ -6,8 +6,6 @@ package org.chromium.media;
import android.content.Context; import android.content.Context;
import android.graphics.ImageFormat; import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.util.Log; import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -82,14 +80,14 @@ public class VideoCaptureAndroid extends VideoCapture { ...@@ -82,14 +80,14 @@ public class VideoCaptureAndroid extends VideoCapture {
private static final String TAG = "VideoCaptureAndroid"; private static final String TAG = "VideoCaptureAndroid";
static CaptureFormat[] getDeviceSupportedFormats(int id) { static CaptureFormat[] getDeviceSupportedFormats(int id) {
Camera camera; android.hardware.Camera camera;
try { try {
camera = Camera.open(id); camera = android.hardware.Camera.open(id);
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
Log.e(TAG, "Camera.open: " + ex); Log.e(TAG, "Camera.open: " + ex);
return null; return null;
} }
Camera.Parameters parameters = getCameraParameters(camera); android.hardware.Camera.Parameters parameters = getCameraParameters(camera);
if (parameters == null) { if (parameters == null) {
return null; return null;
} }
...@@ -123,15 +121,15 @@ public class VideoCaptureAndroid extends VideoCapture { ...@@ -123,15 +121,15 @@ public class VideoCaptureAndroid extends VideoCapture {
listFpsRange.add(new int[] {0, 0}); listFpsRange.add(new int[] {0, 0});
} }
for (int[] fpsRange : listFpsRange) { for (int[] fpsRange : listFpsRange) {
List<Camera.Size> supportedSizes = List<android.hardware.Camera.Size> supportedSizes =
parameters.getSupportedPreviewSizes(); parameters.getSupportedPreviewSizes();
if (supportedSizes == null) { if (supportedSizes == null) {
supportedSizes = new ArrayList<Camera.Size>(); supportedSizes = new ArrayList<android.hardware.Camera.Size>();
} }
if (supportedSizes.size() == 0) { if (supportedSizes.size() == 0) {
supportedSizes.add(camera.new Size(0, 0)); supportedSizes.add(camera.new Size(0, 0));
} }
for (Camera.Size size : supportedSizes) { for (android.hardware.Camera.Size size : supportedSizes) {
formatList.add(new CaptureFormat(size.width, formatList.add(new CaptureFormat(size.width,
size.height, size.height,
(fpsRange[1] + 999) / 1000, (fpsRange[1] + 999) / 1000,
...@@ -154,7 +152,7 @@ public class VideoCaptureAndroid extends VideoCapture { ...@@ -154,7 +152,7 @@ public class VideoCaptureAndroid extends VideoCapture {
int width, int width,
int height, int height,
int frameRate, int frameRate,
Camera.Parameters cameraParameters) { android.hardware.Camera.Parameters cameraParameters) {
mCaptureFormat = new CaptureFormat( mCaptureFormat = new CaptureFormat(
width, height, frameRate, BuggyDeviceHack.getImageFormat()); width, height, frameRate, BuggyDeviceHack.getImageFormat());
// Hack to avoid certain capture resolutions under a minimum one, // Hack to avoid certain capture resolutions under a minimum one,
...@@ -173,12 +171,12 @@ public class VideoCaptureAndroid extends VideoCapture { ...@@ -173,12 +171,12 @@ public class VideoCaptureAndroid extends VideoCapture {
} }
@Override @Override
protected void setPreviewCallback(Camera.PreviewCallback cb) { protected void setPreviewCallback(android.hardware.Camera.PreviewCallback cb) {
mCamera.setPreviewCallbackWithBuffer(cb); mCamera.setPreviewCallbackWithBuffer(cb);
} }
@Override @Override
public void onPreviewFrame(byte[] data, Camera camera) { public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
mPreviewBufferLock.lock(); mPreviewBufferLock.lock();
try { try {
if (!mIsRunning) { if (!mIsRunning) {
...@@ -189,7 +187,7 @@ public class VideoCaptureAndroid extends VideoCapture { ...@@ -189,7 +187,7 @@ public class VideoCaptureAndroid extends VideoCapture {
if (rotation != mDeviceOrientation) { if (rotation != mDeviceOrientation) {
mDeviceOrientation = rotation; mDeviceOrientation = rotation;
} }
if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_BACK) { if (mCameraFacing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK) {
rotation = 360 - rotation; rotation = 360 - rotation;
} }
rotation = (mCameraOrientation + rotation) % 360; rotation = (mCameraOrientation + rotation) % 360;
......
...@@ -6,7 +6,6 @@ package org.chromium.media; ...@@ -6,7 +6,6 @@ package org.chromium.media;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.util.Log; import android.util.Log;
import org.chromium.base.CalledByNative; import org.chromium.base.CalledByNative;
...@@ -45,7 +44,7 @@ class VideoCaptureFactory { ...@@ -45,7 +44,7 @@ class VideoCaptureFactory {
static class ChromiumCameraInfo { static class ChromiumCameraInfo {
private final int mId; private final int mId;
private final Camera.CameraInfo mCameraInfo; private final android.hardware.Camera.CameraInfo mCameraInfo;
// Special devices have more cameras than usual. Those devices are // Special devices have more cameras than usual. Those devices are
// identified by model & device. Currently only the Tango is supported. // identified by model & device. Currently only the Tango is supported.
// Note that these devices have no Camera.CameraInfo. // Note that these devices have no Camera.CameraInfo.
...@@ -91,7 +90,7 @@ class VideoCaptureFactory { ...@@ -91,7 +90,7 @@ class VideoCaptureFactory {
if (PackageManager.PERMISSION_GRANTED == if (PackageManager.PERMISSION_GRANTED ==
appContext.getPackageManager().checkPermission( appContext.getPackageManager().checkPermission(
"android.permission.CAMERA", appContext.getPackageName())) { "android.permission.CAMERA", appContext.getPackageName())) {
sNumberOfSystemCameras = Camera.getNumberOfCameras(); sNumberOfSystemCameras = android.hardware.Camera.getNumberOfCameras();
} else { } else {
sNumberOfSystemCameras = 0; sNumberOfSystemCameras = 0;
Log.w(TAG, "Missing android.permission.CAMERA permission, " Log.w(TAG, "Missing android.permission.CAMERA permission, "
...@@ -126,10 +125,10 @@ class VideoCaptureFactory { ...@@ -126,10 +125,10 @@ class VideoCaptureFactory {
return ""; return "";
} }
Log.d(TAG, "Camera enumerated: " + (mCameraInfo.facing == Log.d(TAG, "Camera enumerated: " + (mCameraInfo.facing ==
Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" : android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" :
"back")); "back"));
return "camera " + mId + ", facing " + (mCameraInfo.facing == return "camera " + mId + ", facing " + (mCameraInfo.facing ==
Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" : android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" :
"back"); "back");
} }
} }
...@@ -137,18 +136,19 @@ class VideoCaptureFactory { ...@@ -137,18 +136,19 @@ class VideoCaptureFactory {
@CalledByNative("ChromiumCameraInfo") @CalledByNative("ChromiumCameraInfo")
private int getOrientation() { private int getOrientation() {
if (isSpecialCamera(mId)) { if (isSpecialCamera(mId)) {
return Camera.CameraInfo.CAMERA_FACING_BACK; return android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK;
} else { } else {
return (mCameraInfo == null ? 0 : mCameraInfo.orientation); return (mCameraInfo == null ? 0 : mCameraInfo.orientation);
} }
} }
private Camera.CameraInfo getCameraInfo(int id) { private android.hardware.Camera.CameraInfo getCameraInfo(int id) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); android.hardware.Camera.CameraInfo cameraInfo =
new android.hardware.Camera.CameraInfo();
try { try {
Camera.getCameraInfo(id, cameraInfo); android.hardware.Camera.getCameraInfo(id, cameraInfo);
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
Log.e(TAG, "getCameraInfo: Camera.getCameraInfo: " + ex); Log.e(TAG, "getCameraInfo: android.hardware.Camera.getCameraInfo: " + ex);
return null; return null;
} }
return cameraInfo; return cameraInfo;
......
...@@ -6,7 +6,6 @@ package org.chromium.media; ...@@ -6,7 +6,6 @@ package org.chromium.media;
import android.content.Context; import android.content.Context;
import android.graphics.ImageFormat; import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.util.Log; import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -78,7 +77,7 @@ public class VideoCaptureTango extends VideoCapture { ...@@ -78,7 +77,7 @@ public class VideoCaptureTango extends VideoCapture {
@Override @Override
protected void setCaptureParameters(int width, int height, int frameRate, protected void setCaptureParameters(int width, int height, int frameRate,
Camera.Parameters cameraParameters) { android.hardware.Camera.Parameters cameraParameters) {
mCaptureFormat = new CaptureFormat(CAM_PARAMS[mTangoCameraId].mWidth, mCaptureFormat = new CaptureFormat(CAM_PARAMS[mTangoCameraId].mWidth,
CAM_PARAMS[mTangoCameraId].mHeight, CAM_PARAMS[mTangoCameraId].mHeight,
frameRate, frameRate,
...@@ -98,12 +97,12 @@ public class VideoCaptureTango extends VideoCapture { ...@@ -98,12 +97,12 @@ public class VideoCaptureTango extends VideoCapture {
} }
@Override @Override
protected void setPreviewCallback(Camera.PreviewCallback cb) { protected void setPreviewCallback(android.hardware.Camera.PreviewCallback cb) {
mCamera.setPreviewCallback(cb); mCamera.setPreviewCallback(cb);
} }
@Override @Override
public void onPreviewFrame(byte[] data, Camera camera) { public void onPreviewFrame(byte[] data, android.hardware.Camera camera) {
mPreviewBufferLock.lock(); mPreviewBufferLock.lock();
try { try {
if (!mIsRunning) return; if (!mIsRunning) return;
...@@ -113,7 +112,7 @@ public class VideoCaptureTango extends VideoCapture { ...@@ -113,7 +112,7 @@ public class VideoCaptureTango extends VideoCapture {
if (rotation != mDeviceOrientation) { if (rotation != mDeviceOrientation) {
mDeviceOrientation = rotation; mDeviceOrientation = rotation;
} }
if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_BACK) { if (mCameraFacing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK) {
rotation = 360 - rotation; rotation = 360 - rotation;
} }
rotation = (mCameraOrientation + rotation) % 360; rotation = (mCameraOrientation + rotation) % 360;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment