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

Side by Side Diff: media/video/capture/android/video_capture_device_android.cc

Issue 12604003: Android: cleans up hand-written JNI for video_capture_device_android.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « media/media.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "media/video/capture/android/video_capture_device_android.h" 5 #include "media/video/capture/android/video_capture_device_android.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "jni/Camera_jni.h"
14 #include "jni/VideoCapture_jni.h" 14 #include "jni/VideoCapture_jni.h"
15 #include "media/base/video_util.h" 15 #include "media/base/video_util.h"
16 16
17 using base::android::AttachCurrentThread; 17 using base::android::AttachCurrentThread;
18 using base::android::CheckException; 18 using base::android::CheckException;
19 using base::android::GetClass; 19 using base::android::GetClass;
20 using base::android::MethodID; 20 using base::android::MethodID;
21 using base::android::JavaRef; 21 using base::android::JavaRef;
22 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
23 23
(...skipping 11 matching lines...) Expand all
35 } // namespace 35 } // namespace
36 36
37 namespace media { 37 namespace media {
38 38
39 // static 39 // static
40 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 40 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
41 device_names->clear(); 41 device_names->clear();
42 42
43 JNIEnv* env = AttachCurrentThread(); 43 JNIEnv* env = AttachCurrentThread();
44 44
45 int num_cameras = JNI_Camera::Java_Camera_getNumberOfCameras(env); 45 int num_cameras = Java_ChromiumCameraInfo_getNumberOfCameras(env);
wjia(left Chromium) 2013/03/07 17:26:42 Just curious, any reason to move this function get
46 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras; 46 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras;
47 if (num_cameras <= 0) 47 if (num_cameras <= 0)
48 return; 48 return;
49 49
50 // TODO(wjia): switch to using same approach as Camera when
51 // jar_file_jni_generator.gypi supports system inner classes.
52 std::string camera_info_string("android/hardware/Camera$CameraInfo");
53
54 ScopedJavaLocalRef<jclass> camera_info_class(
55 GetClass(env, camera_info_string.c_str()));
56 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>(
57 env, camera_info_class.obj(), "<init>", "()V");
58
59 ScopedJavaLocalRef<jobject> object_camera_info(
60 env, env->NewObject(camera_info_class.obj(), constructor));
61
62 jfieldID field_facing = GetFieldID(env, camera_info_class, "facing", "I");
63 jfieldID field_facing_front = GetStaticFieldID(
64 env, camera_info_class, "CAMERA_FACING_FRONT", "I");
65
66 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) { 50 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) {
67 JNI_Camera::Java_Camera_getCameraInfo( 51 ScopedJavaLocalRef<jobject> ci =
68 env, camera_id, object_camera_info.obj()); 52 Java_ChromiumCameraInfo_getAt(env, camera_id);
69 53
70 Name name; 54 Name name;
71 name.unique_id = StringPrintf("%d", camera_id); 55 name.unique_id = StringPrintf(
72 std::string facing_string; 56 "%d", Java_ChromiumCameraInfo_getId(env, ci.obj()));
73 if (env->GetIntField(object_camera_info.obj(), field_facing) == 57 name.device_name = base::android::ConvertJavaStringToUTF8(
74 env->GetStaticIntField(camera_info_class.obj(), field_facing_front)) { 58 Java_ChromiumCameraInfo_getDeviceName(env, ci.obj()));
75 facing_string = "front";
76 } else {
77 facing_string = "back";
78 }
79 name.device_name = StringPrintf(
80 "camera %d, facing %s", camera_id, facing_string.c_str());
81 device_names->push_back(name); 59 device_names->push_back(name);
82 jfieldID field_orientation = GetFieldID( 60
83 env, camera_info_class, "orientation", "I");
84 jint orientation = env->GetIntField(object_camera_info.obj(),
85 field_orientation);
86 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: camera device_name=" 61 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: camera device_name="
87 << name.device_name 62 << name.device_name
88 << ", unique_id=" 63 << ", unique_id="
89 << name.unique_id 64 << name.unique_id
90 << ", orientation " 65 << ", orientation "
91 << orientation; 66 << Java_ChromiumCameraInfo_getOrientation(env, ci.obj());
92 } 67 }
93 } 68 }
94 69
95 // static 70 // static
96 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { 71 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
97 return VideoCaptureDeviceAndroid::Create(device_name); 72 return VideoCaptureDeviceAndroid::Create(device_name);
98 } 73 }
99 74
100 // static 75 // static
101 VideoCaptureDevice* VideoCaptureDeviceAndroid::Create(const Name& device_name) { 76 VideoCaptureDevice* VideoCaptureDeviceAndroid::Create(const Name& device_name) {
102 scoped_ptr<VideoCaptureDeviceAndroid> ret( 77 scoped_ptr<VideoCaptureDeviceAndroid> ret(
103 new VideoCaptureDeviceAndroid(device_name)); 78 new VideoCaptureDeviceAndroid(device_name));
104 if (ret->Init()) 79 if (ret->Init())
105 return ret.release(); 80 return ret.release();
106 return NULL; 81 return NULL;
107 } 82 }
108 83
109 // static 84 // static
110 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { 85 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) {
111 return RegisterNativesImpl(env) && JNI_Camera::RegisterNativesImpl(env); 86 return RegisterNativesImpl(env);
112 } 87 }
113 88
114 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid(const Name& device_name) 89 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid(const Name& device_name)
115 : state_(kIdle), 90 : state_(kIdle),
116 observer_(NULL), 91 observer_(NULL),
117 device_name_(device_name), 92 device_name_(device_name),
118 current_settings_() { 93 current_settings_() {
119 } 94 }
120 95
121 VideoCaptureDeviceAndroid::~VideoCaptureDeviceAndroid() { 96 VideoCaptureDeviceAndroid::~VideoCaptureDeviceAndroid() {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) { 255 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) {
281 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason; 256 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason;
282 { 257 {
283 base::AutoLock lock(lock_); 258 base::AutoLock lock(lock_);
284 state_ = kError; 259 state_ = kError;
285 } 260 }
286 observer_->OnError(); 261 observer_->OnError();
287 } 262 }
288 263
289 } // namespace media 264 } // namespace media
OLDNEW
« no previous file with comments | « media/media.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698