OLD | NEW |
---|---|
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 #include "media/capture/video/android/video_capture_device_factory_android.h" | 5 #include "media/capture/video/android/video_capture_device_factory_android.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // static | 27 // static |
28 ScopedJavaLocalRef<jobject> | 28 ScopedJavaLocalRef<jobject> |
29 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( | 29 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( |
30 int id, | 30 int id, |
31 jlong nativeVideoCaptureDeviceAndroid) { | 31 jlong nativeVideoCaptureDeviceAndroid) { |
32 return (Java_VideoCaptureFactory_createVideoCapture( | 32 return (Java_VideoCaptureFactory_createVideoCapture( |
33 AttachCurrentThread(), base::android::GetApplicationContext(), id, | 33 AttachCurrentThread(), base::android::GetApplicationContext(), id, |
34 nativeVideoCaptureDeviceAndroid)); | 34 nativeVideoCaptureDeviceAndroid)); |
35 } | 35 } |
36 | 36 |
37 std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryAndroid::Create( | 37 std::unique_ptr<VideoCaptureDevice> |
38 const VideoCaptureDevice::Name& device_name) { | 38 VideoCaptureDeviceFactoryAndroid::CreateDevice( |
39 const VideoCaptureDeviceDescriptor& device_descriptor) { | |
39 DCHECK(thread_checker_.CalledOnValidThread()); | 40 DCHECK(thread_checker_.CalledOnValidThread()); |
40 int id; | 41 int id; |
41 if (!base::StringToInt(device_name.id(), &id)) | 42 if (!base::StringToInt(device_descriptor.device_id, &id)) |
42 return std::unique_ptr<VideoCaptureDevice>(); | 43 return std::unique_ptr<VideoCaptureDevice>(); |
43 | 44 |
44 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( | 45 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( |
45 new VideoCaptureDeviceAndroid(device_name)); | 46 new VideoCaptureDeviceAndroid(device_descriptor)); |
46 | 47 |
47 if (video_capture_device->Init()) | 48 if (video_capture_device->Init()) |
48 return std::move(video_capture_device); | 49 return std::move(video_capture_device); |
49 | 50 |
50 DLOG(ERROR) << "Error creating Video Capture Device."; | 51 DLOG(ERROR) << "Error creating Video Capture Device."; |
51 return std::unique_ptr<VideoCaptureDevice>(); | 52 return std::unique_ptr<VideoCaptureDevice>(); |
52 } | 53 } |
53 | 54 |
54 void VideoCaptureDeviceFactoryAndroid::GetDeviceNames( | 55 void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors( |
55 VideoCaptureDevice::Names* device_names) { | 56 VideoCaptureDeviceDescriptors* device_descriptors) { |
56 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
57 device_names->clear(); | 58 device_descriptors->clear(); |
58 | 59 |
59 JNIEnv* env = AttachCurrentThread(); | 60 JNIEnv* env = AttachCurrentThread(); |
60 | 61 |
61 const jobject context = base::android::GetApplicationContext(); | 62 const jobject context = base::android::GetApplicationContext(); |
62 const int num_cameras = | 63 const int num_cameras = |
63 Java_VideoCaptureFactory_getNumberOfCameras(env, context); | 64 Java_VideoCaptureFactory_getNumberOfCameras(env, context); |
64 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras; | 65 DVLOG(1) << __FUNCTION__ << ": num_cameras=" << num_cameras; |
65 if (num_cameras <= 0) | 66 if (num_cameras <= 0) |
66 return; | 67 return; |
67 | 68 |
68 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) { | 69 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) { |
69 base::android::ScopedJavaLocalRef<jstring> device_name = | 70 base::android::ScopedJavaLocalRef<jstring> device_name = |
70 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context); | 71 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context); |
71 if (device_name.obj() == NULL) | 72 if (device_name.obj() == NULL) |
72 continue; | 73 continue; |
73 | 74 |
74 const int capture_api_type = | 75 const int capture_api_type = |
75 Java_VideoCaptureFactory_getCaptureApiType(env, camera_id, context); | 76 Java_VideoCaptureFactory_getCaptureApiType(env, camera_id, context); |
77 const std::string display_name = | |
78 base::android::ConvertJavaStringToUTF8(device_name); | |
79 const std::string device_id = base::IntToString(camera_id); | |
76 | 80 |
77 VideoCaptureDevice::Name name( | 81 // Android cameras are not typically USB devices, and the model_id is |
78 base::android::ConvertJavaStringToUTF8(device_name), | 82 // currently only used for USB model identifiers, so this implementation |
79 base::IntToString(camera_id), | 83 // just indicates an unknown device model (by not providing one). |
80 static_cast<VideoCaptureDevice::Name::CaptureApiType>( | 84 device_descriptors->emplace_back( |
81 capture_api_type)); | 85 display_name, device_id, |
mcasas
2016/07/30 00:06:11
format? Looks like it fits in one line.
Pro-tip:
chfremer
2016/08/01 18:53:12
Thanks for the tip. I tried re-applying the format
| |
82 device_names->push_back(name); | 86 static_cast<VideoCaptureApi>(capture_api_type)); |
83 | 87 |
84 DVLOG(1) << "VideoCaptureDeviceFactoryAndroid::GetDeviceNames: camera " | 88 DVLOG(1) << __FUNCTION__ << ": camera " |
85 << "device_name=" << name.name() << ", unique_id=" << name.id(); | 89 << "device_name=" << display_name << ", unique_id=" << device_id; |
86 } | 90 } |
87 } | 91 } |
88 | 92 |
89 void VideoCaptureDeviceFactoryAndroid::GetDeviceSupportedFormats( | 93 void VideoCaptureDeviceFactoryAndroid::GetSupportedFormats( |
90 const VideoCaptureDevice::Name& device, | 94 const VideoCaptureDeviceDescriptor& device, |
91 VideoCaptureFormats* capture_formats) { | 95 VideoCaptureFormats* capture_formats) { |
92 DCHECK(thread_checker_.CalledOnValidThread()); | 96 DCHECK(thread_checker_.CalledOnValidThread()); |
93 int id; | 97 int id; |
94 if (!base::StringToInt(device.id(), &id)) | 98 if (!base::StringToInt(device.device_id, &id)) |
95 return; | 99 return; |
96 JNIEnv* env = AttachCurrentThread(); | 100 JNIEnv* env = AttachCurrentThread(); |
97 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = | 101 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = |
98 Java_VideoCaptureFactory_getDeviceSupportedFormats( | 102 Java_VideoCaptureFactory_getDeviceSupportedFormats( |
99 env, base::android::GetApplicationContext(), id); | 103 env, base::android::GetApplicationContext(), id); |
100 if (collected_formats.is_null()) | 104 if (collected_formats.is_null()) |
101 return; | 105 return; |
102 | 106 |
103 jsize num_formats = env->GetArrayLength(collected_formats.obj()); | 107 jsize num_formats = env->GetArrayLength(collected_formats.obj()); |
104 for (int i = 0; i < num_formats; ++i) { | 108 for (int i = 0; i < num_formats; ++i) { |
(...skipping 15 matching lines...) Expand all Loading... | |
120 } | 124 } |
121 VideoCaptureFormat capture_format( | 125 VideoCaptureFormat capture_format( |
122 gfx::Size(media::Java_VideoCaptureFactory_getCaptureFormatWidth( | 126 gfx::Size(media::Java_VideoCaptureFactory_getCaptureFormatWidth( |
123 env, format.obj()), | 127 env, format.obj()), |
124 media::Java_VideoCaptureFactory_getCaptureFormatHeight( | 128 media::Java_VideoCaptureFactory_getCaptureFormatHeight( |
125 env, format.obj())), | 129 env, format.obj())), |
126 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, | 130 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, |
127 format.obj()), | 131 format.obj()), |
128 pixel_format); | 132 pixel_format); |
129 capture_formats->push_back(capture_format); | 133 capture_formats->push_back(capture_format); |
130 DVLOG(1) << device.name() << " " | 134 DVLOG(1) << device.display_name << " " |
131 << VideoCaptureFormat::ToString(capture_format); | 135 << VideoCaptureFormat::ToString(capture_format); |
132 } | 136 } |
133 } | 137 } |
134 | 138 |
135 // static | 139 // static |
136 VideoCaptureDeviceFactory* | 140 VideoCaptureDeviceFactory* |
137 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 141 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
138 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 142 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
139 return new VideoCaptureDeviceFactoryAndroid(); | 143 return new VideoCaptureDeviceFactoryAndroid(); |
140 } | 144 } |
141 | 145 |
142 } // namespace media | 146 } // namespace media |
OLD | NEW |