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: |
119 continue; | 121 // VideoCaptureCamera2 doesn't know the provided format until capture. |
| 122 break; |
120 } | 123 } |
121 VideoCaptureFormat capture_format( | 124 VideoCaptureFormat capture_format( |
122 gfx::Size( | 125 gfx::Size( |
123 media::Java_VideoCaptureFactory_getCaptureFormatWidth(env, format), | 126 media::Java_VideoCaptureFactory_getCaptureFormatWidth(env, format), |
124 media::Java_VideoCaptureFactory_getCaptureFormatHeight(env, | 127 media::Java_VideoCaptureFactory_getCaptureFormatHeight(env, |
125 format)), | 128 format)), |
126 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, format), | 129 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, format), |
127 pixel_format); | 130 pixel_format); |
128 capture_formats->push_back(capture_format); | 131 capture_formats->push_back(capture_format); |
129 DVLOG(1) << device.display_name << " " | 132 DVLOG(1) << device.display_name << " " |
130 << VideoCaptureFormat::ToString(capture_format); | 133 << VideoCaptureFormat::ToString(capture_format); |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
| 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 |
134 // static | 146 // static |
135 VideoCaptureDeviceFactory* | 147 VideoCaptureDeviceFactory* |
136 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 148 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
137 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 149 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
138 return new VideoCaptureDeviceFactoryAndroid(); | 150 return new VideoCaptureDeviceFactoryAndroid(); |
139 } | 151 } |
140 | 152 |
141 } // namespace media | 153 } // namespace media |
OLD | NEW |