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

Side by Side Diff: media/capture/video/android/java/src/org/chromium/media/VideoCapture.java

Issue 2847523002: Android: Remove GetApplicationContext part 4 (Closed)
Patch Set: Rebase and fix build Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.media; 5 package org.chromium.media;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.ImageFormat; 8 import android.graphics.ImageFormat;
9 import android.view.Surface; 9 import android.view.Surface;
10 import android.view.WindowManager; 10 import android.view.WindowManager;
11 11
12 import org.chromium.base.ContextUtils;
12 import org.chromium.base.annotations.CalledByNative; 13 import org.chromium.base.annotations.CalledByNative;
13 import org.chromium.base.annotations.JNINamespace; 14 import org.chromium.base.annotations.JNINamespace;
14 15
15 import java.nio.ByteBuffer; 16 import java.nio.ByteBuffer;
16 import java.util.ArrayList; 17 import java.util.ArrayList;
17 import java.util.Collections; 18 import java.util.Collections;
18 import java.util.Comparator; 19 import java.util.Comparator;
19 import java.util.List; 20 import java.util.List;
20 21
21 /** 22 /**
22 * Video Capture Device base class, defines a set of methods that native code 23 * Video Capture Device base class, defines a set of methods that native code
23 * needs to use to configure, start capture, and to be reached by callbacks and 24 * needs to use to configure, start capture, and to be reached by callbacks and
24 * provides some neccesary data type(s) with accessors. 25 * provides some necessary data type(s) with accessors.
25 **/ 26 **/
26 @JNINamespace("media") 27 @JNINamespace("media")
27 public abstract class VideoCapture { 28 public abstract class VideoCapture {
28 /** 29 /**
29 * Common class for storing a framerate range. Values should be multiplied b y 1000. 30 * Common class for storing a framerate range. Values should be multiplied b y 1000.
30 */ 31 */
31 protected static class FramerateRange { 32 protected static class FramerateRange {
32 public int min; 33 public int min;
33 public int max; 34 public int max;
34 35
35 public FramerateRange(int min, int max) { 36 public FramerateRange(int min, int max) {
36 this.min = min; 37 this.min = min;
37 this.max = max; 38 this.max = max;
38 } 39 }
39 } 40 }
40 41
41 // The angle (0, 90, 180, 270) that the image needs to be rotated to show in 42 // The angle (0, 90, 180, 270) that the image needs to be rotated to show in
42 // the display's native orientation. 43 // the display's native orientation.
43 protected int mCameraNativeOrientation; 44 protected int mCameraNativeOrientation;
44 // In some occasions we need to invert the device rotation readings, see the 45 // In some occasions we need to invert the device rotation readings, see the
45 // individual implementations. 46 // individual implementations.
46 protected boolean mInvertDeviceOrientationReadings; 47 protected boolean mInvertDeviceOrientationReadings;
47 48
48 protected VideoCaptureFormat mCaptureFormat; 49 protected VideoCaptureFormat mCaptureFormat;
49 protected final Context mContext;
50 protected final int mId; 50 protected final int mId;
51 // Native callback context variable. 51 // Native callback context variable.
52 protected final long mNativeVideoCaptureDeviceAndroid; 52 protected final long mNativeVideoCaptureDeviceAndroid;
53 53
54 protected boolean mUseBackgroundThreadForTesting; 54 protected boolean mUseBackgroundThreadForTesting;
55 55
56 VideoCapture(Context context, int id, long nativeVideoCaptureDeviceAndroid) { 56 VideoCapture(int id, long nativeVideoCaptureDeviceAndroid) {
57 mContext = context;
58 mId = id; 57 mId = id;
59 mNativeVideoCaptureDeviceAndroid = nativeVideoCaptureDeviceAndroid; 58 mNativeVideoCaptureDeviceAndroid = nativeVideoCaptureDeviceAndroid;
60 } 59 }
61 60
62 // Allocate necessary resources for capture. 61 // Allocate necessary resources for capture.
63 @CalledByNative 62 @CalledByNative
64 public abstract boolean allocate(int width, int height, int frameRate); 63 public abstract boolean allocate(int width, int height, int frameRate);
65 64
66 @CalledByNative 65 @CalledByNative
67 public abstract boolean startCapture(); 66 public abstract boolean startCapture();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 mUseBackgroundThreadForTesting = true; 136 mUseBackgroundThreadForTesting = true;
138 } 137 }
139 138
140 protected final int getCameraRotation() { 139 protected final int getCameraRotation() {
141 int rotation = mInvertDeviceOrientationReadings ? (360 - getDeviceRotati on()) 140 int rotation = mInvertDeviceOrientationReadings ? (360 - getDeviceRotati on())
142 : getDeviceRotation(); 141 : getDeviceRotation();
143 return (mCameraNativeOrientation + rotation) % 360; 142 return (mCameraNativeOrientation + rotation) % 360;
144 } 143 }
145 144
146 protected final int getDeviceRotation() { 145 protected final int getDeviceRotation() {
147 if (mContext == null) return 0;
148 final int orientation; 146 final int orientation;
149 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WIN DOW_SERVICE); 147 WindowManager wm = (WindowManager) ContextUtils.getApplicationContext(). getSystemService(
148 Context.WINDOW_SERVICE);
150 switch (wm.getDefaultDisplay().getRotation()) { 149 switch (wm.getDefaultDisplay().getRotation()) {
151 case Surface.ROTATION_90: 150 case Surface.ROTATION_90:
152 orientation = 90; 151 orientation = 90;
153 break; 152 break;
154 case Surface.ROTATION_180: 153 case Surface.ROTATION_180:
155 orientation = 180; 154 orientation = 180;
156 break; 155 break;
157 case Surface.ROTATION_270: 156 case Surface.ROTATION_270:
158 orientation = 270; 157 orientation = 270;
159 break; 158 break;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // Method for VideoCapture implementations to signal an asynchronous error. 230 // Method for VideoCapture implementations to signal an asynchronous error.
232 public native void nativeOnError(long nativeVideoCaptureDeviceAndroid, Strin g message); 231 public native void nativeOnError(long nativeVideoCaptureDeviceAndroid, Strin g message);
233 232
234 // Method for VideoCapture implementations to send Photos back to. 233 // Method for VideoCapture implementations to send Photos back to.
235 public native void nativeOnPhotoTaken( 234 public native void nativeOnPhotoTaken(
236 long nativeVideoCaptureDeviceAndroid, long callbackId, byte[] data); 235 long nativeVideoCaptureDeviceAndroid, long callbackId, byte[] data);
237 236
238 // Method for VideoCapture implementations to report device started event. 237 // Method for VideoCapture implementations to report device started event.
239 public native void nativeOnStarted(long nativeVideoCaptureDeviceAndroid); 238 public native void nativeOnStarted(long nativeVideoCaptureDeviceAndroid);
240 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698