| 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 23 matching lines...) Expand all Loading... |
| 34 VideoCaptureDeviceFactoryAndroid::CreateDevice( | 34 VideoCaptureDeviceFactoryAndroid::CreateDevice( |
| 35 const VideoCaptureDeviceDescriptor& device_descriptor) { | 35 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 int id; | 37 int id; |
| 38 if (!base::StringToInt(device_descriptor.device_id, &id)) | 38 if (!base::StringToInt(device_descriptor.device_id, &id)) |
| 39 return std::unique_ptr<VideoCaptureDevice>(); | 39 return std::unique_ptr<VideoCaptureDevice>(); |
| 40 | 40 |
| 41 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( | 41 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( |
| 42 new VideoCaptureDeviceAndroid(device_descriptor)); | 42 new VideoCaptureDeviceAndroid(device_descriptor)); |
| 43 | 43 |
| 44 if (video_capture_device->Init()) { | 44 if (video_capture_device->Init()) |
| 45 if (test_mode_) | |
| 46 video_capture_device->ConfigureForTesting(); | |
| 47 return std::move(video_capture_device); | 45 return std::move(video_capture_device); |
| 48 } | |
| 49 | 46 |
| 50 DLOG(ERROR) << "Error creating Video Capture Device."; | 47 DLOG(ERROR) << "Error creating Video Capture Device."; |
| 51 return nullptr; | 48 return std::unique_ptr<VideoCaptureDevice>(); |
| 52 } | 49 } |
| 53 | 50 |
| 54 void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors( | 51 void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors( |
| 55 VideoCaptureDeviceDescriptors* device_descriptors) { | 52 VideoCaptureDeviceDescriptors* device_descriptors) { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 device_descriptors->clear(); | 54 device_descriptors->clear(); |
| 58 | 55 |
| 59 JNIEnv* env = AttachCurrentThread(); | 56 JNIEnv* env = AttachCurrentThread(); |
| 60 | 57 |
| 61 const JavaRef<jobject>& context = base::android::GetApplicationContext(); | 58 const JavaRef<jobject>& context = base::android::GetApplicationContext(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Java_VideoCaptureFactory_getDeviceSupportedFormats( | 98 Java_VideoCaptureFactory_getDeviceSupportedFormats( |
| 102 env, base::android::GetApplicationContext(), id); | 99 env, base::android::GetApplicationContext(), id); |
| 103 if (collected_formats.is_null()) | 100 if (collected_formats.is_null()) |
| 104 return; | 101 return; |
| 105 | 102 |
| 106 jsize num_formats = env->GetArrayLength(collected_formats.obj()); | 103 jsize num_formats = env->GetArrayLength(collected_formats.obj()); |
| 107 for (int i = 0; i < num_formats; ++i) { | 104 for (int i = 0; i < num_formats; ++i) { |
| 108 base::android::ScopedJavaLocalRef<jobject> format( | 105 base::android::ScopedJavaLocalRef<jobject> format( |
| 109 env, env->GetObjectArrayElement(collected_formats.obj(), i)); | 106 env, env->GetObjectArrayElement(collected_formats.obj(), i)); |
| 110 | 107 |
| 111 VideoPixelFormat pixel_format = media::PIXEL_FORMAT_UNKNOWN; | 108 VideoPixelFormat pixel_format = |
| 109 media::PIXEL_FORMAT_UNKNOWN; |
| 112 switch (media::Java_VideoCaptureFactory_getCaptureFormatPixelFormat( | 110 switch (media::Java_VideoCaptureFactory_getCaptureFormatPixelFormat( |
| 113 env, format)) { | 111 env, format)) { |
| 114 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_YV12: | 112 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_YV12: |
| 115 pixel_format = media::PIXEL_FORMAT_YV12; | 113 pixel_format = media::PIXEL_FORMAT_YV12; |
| 116 break; | 114 break; |
| 117 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_NV21: | 115 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_NV21: |
| 118 pixel_format = media::PIXEL_FORMAT_NV21; | 116 pixel_format = media::PIXEL_FORMAT_NV21; |
| 119 break; | 117 break; |
| 120 default: | 118 default: |
| 121 // VideoCaptureCamera2 doesn't know the provided format until capture. | 119 continue; |
| 122 break; | |
| 123 } | 120 } |
| 124 VideoCaptureFormat capture_format( | 121 VideoCaptureFormat capture_format( |
| 125 gfx::Size( | 122 gfx::Size( |
| 126 media::Java_VideoCaptureFactory_getCaptureFormatWidth(env, format), | 123 media::Java_VideoCaptureFactory_getCaptureFormatWidth(env, format), |
| 127 media::Java_VideoCaptureFactory_getCaptureFormatHeight(env, | 124 media::Java_VideoCaptureFactory_getCaptureFormatHeight(env, |
| 128 format)), | 125 format)), |
| 129 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, format), | 126 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, format), |
| 130 pixel_format); | 127 pixel_format); |
| 131 capture_formats->push_back(capture_format); | 128 capture_formats->push_back(capture_format); |
| 132 DVLOG(1) << device.display_name << " " | 129 DVLOG(1) << device.display_name << " " |
| 133 << VideoCaptureFormat::ToString(capture_format); | 130 << VideoCaptureFormat::ToString(capture_format); |
| 134 } | 131 } |
| 135 } | 132 } |
| 136 | 133 |
| 137 bool VideoCaptureDeviceFactoryAndroid::IsLegacyOrDeprecatedDevice( | |
| 138 const std::string& device_id) { | |
| 139 int id; | |
| 140 if (!base::StringToInt(device_id, &id)) | |
| 141 return true; | |
| 142 return (Java_VideoCaptureFactory_isLegacyOrDeprecatedDevice( | |
| 143 AttachCurrentThread(), base::android::GetApplicationContext(), id)); | |
| 144 } | |
| 145 | |
| 146 // static | 134 // static |
| 147 VideoCaptureDeviceFactory* | 135 VideoCaptureDeviceFactory* |
| 148 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 136 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
| 149 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 137 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 150 return new VideoCaptureDeviceFactoryAndroid(); | 138 return new VideoCaptureDeviceFactoryAndroid(); |
| 151 } | 139 } |
| 152 | 140 |
| 153 } // namespace media | 141 } // namespace media |
| OLD | NEW |