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