| 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/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "jni/VideoCaptureFactory_jni.h" | 14 #include "jni/VideoCaptureFactory_jni.h" |
| 15 #include "media/capture/video/android/video_capture_device_android.h" | 15 #include "media/capture/video/android/video_capture_device_android.h" |
| 16 #include "media/capture/video/android/video_capture_device_tango_android.h" |
| 16 | 17 |
| 17 using base::android::AttachCurrentThread; | 18 using base::android::AttachCurrentThread; |
| 18 using base::android::JavaRef; | 19 using base::android::JavaRef; |
| 19 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 // static | 24 // static |
| 24 ScopedJavaLocalRef<jobject> | 25 ScopedJavaLocalRef<jobject> |
| 25 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( | 26 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( |
| 26 int id, | 27 int id, |
| 27 jlong nativeVideoCaptureDeviceAndroid) { | 28 jlong nativeVideoCaptureDeviceAndroid) { |
| 28 return (Java_VideoCaptureFactory_createVideoCapture( | 29 return (Java_VideoCaptureFactory_createVideoCapture( |
| 29 AttachCurrentThread(), id, nativeVideoCaptureDeviceAndroid)); | 30 AttachCurrentThread(), id, nativeVideoCaptureDeviceAndroid)); |
| 30 } | 31 } |
| 31 | 32 |
| 32 std::unique_ptr<VideoCaptureDevice> | 33 std::unique_ptr<VideoCaptureDevice> |
| 33 VideoCaptureDeviceFactoryAndroid::CreateDevice( | 34 VideoCaptureDeviceFactoryAndroid::CreateDevice( |
| 34 const VideoCaptureDeviceDescriptor& device_descriptor) { | 35 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 int id; | 37 int id; |
| 37 if (!base::StringToInt(device_descriptor.device_id, &id)) | 38 if (!base::StringToInt(device_descriptor.device_id, &id)) |
| 38 return std::unique_ptr<VideoCaptureDevice>(); | 39 return std::unique_ptr<VideoCaptureDevice>(); |
| 39 | 40 |
| 41 if (device_descriptor.capture_api == VideoCaptureApi::ANDROID_TANGO) |
| 42 return std::unique_ptr<VideoCaptureDeviceTangoAndroid>( |
| 43 new VideoCaptureDeviceTangoAndroid(device_descriptor)); |
| 40 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( | 44 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( |
| 41 new VideoCaptureDeviceAndroid(device_descriptor)); | 45 new VideoCaptureDeviceAndroid(device_descriptor)); |
| 42 | 46 |
| 43 if (video_capture_device->Init()) { | 47 if (video_capture_device->Init()) { |
| 44 if (test_mode_) | 48 if (test_mode_) |
| 45 video_capture_device->ConfigureForTesting(); | 49 video_capture_device->ConfigureForTesting(); |
| 46 return std::move(video_capture_device); | 50 return std::move(video_capture_device); |
| 47 } | 51 } |
| 48 | 52 |
| 49 DLOG(ERROR) << "Error creating Video Capture Device."; | 53 DLOG(ERROR) << "Error creating Video Capture Device."; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 // Android cameras are not typically USB devices, and the model_id is | 81 // Android cameras are not typically USB devices, and the model_id is |
| 78 // currently only used for USB model identifiers, so this implementation | 82 // currently only used for USB model identifiers, so this implementation |
| 79 // just indicates an unknown device model (by not providing one). | 83 // just indicates an unknown device model (by not providing one). |
| 80 device_descriptors->emplace_back( | 84 device_descriptors->emplace_back( |
| 81 display_name, device_id, | 85 display_name, device_id, |
| 82 static_cast<VideoCaptureApi>(capture_api_type)); | 86 static_cast<VideoCaptureApi>(capture_api_type)); |
| 83 | 87 |
| 84 DVLOG(1) << __func__ << ": camera " | 88 DVLOG(1) << __func__ << ": camera " |
| 85 << "device_name=" << display_name << ", unique_id=" << device_id; | 89 << "device_name=" << display_name << ", unique_id=" << device_id; |
| 86 } | 90 } |
| 91 // Also retrieve Tango device cameras, if present, via Tango API. |
| 92 VideoCaptureDeviceTangoAndroid::EnumerateDevices(device_descriptors); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void VideoCaptureDeviceFactoryAndroid::GetSupportedFormats( | 95 void VideoCaptureDeviceFactoryAndroid::GetSupportedFormats( |
| 90 const VideoCaptureDeviceDescriptor& device, | 96 const VideoCaptureDeviceDescriptor& device, |
| 91 VideoCaptureFormats* capture_formats) { | 97 VideoCaptureFormats* capture_formats) { |
| 92 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| 93 int id; | 99 int id; |
| 94 if (!base::StringToInt(device.device_id, &id)) | 100 if (!base::StringToInt(device.device_id, &id)) |
| 95 return; | 101 return; |
| 102 if (device.capture_api == VideoCaptureApi::ANDROID_TANGO) |
| 103 return VideoCaptureDeviceTangoAndroid::EnumerateDeviceCapabilities( |
| 104 device, capture_formats); |
| 96 JNIEnv* env = AttachCurrentThread(); | 105 JNIEnv* env = AttachCurrentThread(); |
| 97 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = | 106 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = |
| 98 Java_VideoCaptureFactory_getDeviceSupportedFormats(env, id); | 107 Java_VideoCaptureFactory_getDeviceSupportedFormats(env, id); |
| 99 if (collected_formats.is_null()) | 108 if (collected_formats.is_null()) |
| 100 return; | 109 return; |
| 101 | 110 |
| 102 jsize num_formats = env->GetArrayLength(collected_formats.obj()); | 111 jsize num_formats = env->GetArrayLength(collected_formats.obj()); |
| 103 for (int i = 0; i < num_formats; ++i) { | 112 for (int i = 0; i < num_formats; ++i) { |
| 104 base::android::ScopedJavaLocalRef<jobject> format( | 113 base::android::ScopedJavaLocalRef<jobject> format( |
| 105 env, env->GetObjectArrayElement(collected_formats.obj(), i)); | 114 env, env->GetObjectArrayElement(collected_formats.obj(), i)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 151 } |
| 143 | 152 |
| 144 // static | 153 // static |
| 145 VideoCaptureDeviceFactory* | 154 VideoCaptureDeviceFactory* |
| 146 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 155 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
| 147 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 156 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 148 return new VideoCaptureDeviceFactoryAndroid(); | 157 return new VideoCaptureDeviceFactoryAndroid(); |
| 149 } | 158 } |
| 150 | 159 |
| 151 } // namespace media | 160 } // namespace media |
| OLD | NEW |