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