Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: media/capture/video/android/video_capture_device_factory_android.cc

Issue 2169013002: Change class VideoCaptureDevice::Name to struct VideoCaptureDeviceDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring of VideoCaptureDeviceFactory interface Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 ScopedJavaLocalRef<jobject> 28 ScopedJavaLocalRef<jobject>
29 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( 29 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid(
30 int id, 30 int id,
31 jlong nativeVideoCaptureDeviceAndroid) { 31 jlong nativeVideoCaptureDeviceAndroid) {
32 return (Java_VideoCaptureFactory_createVideoCapture( 32 return (Java_VideoCaptureFactory_createVideoCapture(
33 AttachCurrentThread(), base::android::GetApplicationContext(), id, 33 AttachCurrentThread(), base::android::GetApplicationContext(), id,
34 nativeVideoCaptureDeviceAndroid)); 34 nativeVideoCaptureDeviceAndroid));
35 } 35 }
36 36
37 std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryAndroid::Create( 37 std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryAndroid::Create(
38 const VideoCaptureDevice::Name& device_name) { 38 const VideoCaptureDeviceDescriptor& device_descriptor) {
39 DCHECK(thread_checker_.CalledOnValidThread()); 39 DCHECK(thread_checker_.CalledOnValidThread());
40 int id; 40 int id;
41 if (!base::StringToInt(device_name.id(), &id)) 41 if (!base::StringToInt(device_descriptor.device_id, &id))
42 return std::unique_ptr<VideoCaptureDevice>(); 42 return std::unique_ptr<VideoCaptureDevice>();
43 43
44 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( 44 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device(
45 new VideoCaptureDeviceAndroid(device_name)); 45 new VideoCaptureDeviceAndroid(device_descriptor));
46 46
47 if (video_capture_device->Init()) 47 if (video_capture_device->Init())
48 return std::move(video_capture_device); 48 return std::move(video_capture_device);
49 49
50 DLOG(ERROR) << "Error creating Video Capture Device."; 50 DLOG(ERROR) << "Error creating Video Capture Device.";
51 return std::unique_ptr<VideoCaptureDevice>(); 51 return std::unique_ptr<VideoCaptureDevice>();
52 } 52 }
53 53
54 void VideoCaptureDeviceFactoryAndroid::GetDeviceNames( 54 void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors(
55 VideoCaptureDevice::Names* device_names) { 55 VideoCaptureDeviceDescriptors* device_descriptors) {
56 DCHECK(thread_checker_.CalledOnValidThread()); 56 DCHECK(thread_checker_.CalledOnValidThread());
57 device_names->clear(); 57 device_descriptors->clear();
58 58
59 JNIEnv* env = AttachCurrentThread(); 59 JNIEnv* env = AttachCurrentThread();
60 60
61 const jobject context = base::android::GetApplicationContext(); 61 const jobject context = base::android::GetApplicationContext();
62 const int num_cameras = 62 const int num_cameras =
63 Java_VideoCaptureFactory_getNumberOfCameras(env, context); 63 Java_VideoCaptureFactory_getNumberOfCameras(env, context);
64 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras; 64 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras;
65 if (num_cameras <= 0) 65 if (num_cameras <= 0)
66 return; 66 return;
67 67
68 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) { 68 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) {
69 base::android::ScopedJavaLocalRef<jstring> device_name = 69 base::android::ScopedJavaLocalRef<jstring> device_name =
70 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context); 70 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context);
71 if (device_name.obj() == NULL) 71 if (device_name.obj() == NULL)
72 continue; 72 continue;
73 73
74 const int capture_api_type = 74 const int capture_api_type =
75 Java_VideoCaptureFactory_getCaptureApiType(env, camera_id, context); 75 Java_VideoCaptureFactory_getCaptureApiType(env, camera_id, context);
76 76
77 VideoCaptureDevice::Name name( 77 VideoCaptureDeviceDescriptor descriptor;
78 base::android::ConvertJavaStringToUTF8(device_name), 78 descriptor.friendly_name =
79 base::IntToString(camera_id), 79 base::android::ConvertJavaStringToUTF8(device_name);
80 static_cast<VideoCaptureDevice::Name::CaptureApiType>( 80 descriptor.device_id = base::IntToString(camera_id);
81 capture_api_type)); 81 descriptor.capture_api = static_cast<VideoCaptureApiType>(capture_api_type);
82 device_names->push_back(name); 82 device_descriptors->push_back(descriptor);
83 83
84 DVLOG(1) << "VideoCaptureDeviceFactoryAndroid::GetDeviceNames: camera " 84 DVLOG(1) << "VideoCaptureDeviceFactoryAndroid::GetDeviceNames: camera "
85 << "device_name=" << name.name() << ", unique_id=" << name.id(); 85 << "device_name=" << descriptor.friendly_name
86 << ", unique_id=" << descriptor.device_id;
86 } 87 }
87 } 88 }
88 89
90 void VideoCaptureDeviceFactoryAndroid::GetDeviceInfo(
91 const VideoCaptureDeviceDescriptor& device_descriptor,
92 VideoCaptureDeviceInfo* device_info) {
93 DCHECK(device_info);
94 device_info->descriptor = device_descriptor;
95 GetDeviceSupportedFormats(device_descriptor,
96 &(device_info->supported_formats));
97 // Android cameras are not typically USB devices, and the model_id is
98 // currently only used for USB model identifiers, so this implementation just
99 // indicates an unknown device model.
100 device_info->model_id = "";
101 }
102
89 void VideoCaptureDeviceFactoryAndroid::GetDeviceSupportedFormats( 103 void VideoCaptureDeviceFactoryAndroid::GetDeviceSupportedFormats(
90 const VideoCaptureDevice::Name& device, 104 const VideoCaptureDeviceDescriptor& device,
91 VideoCaptureFormats* capture_formats) { 105 VideoCaptureFormats* capture_formats) {
92 DCHECK(thread_checker_.CalledOnValidThread()); 106 DCHECK(thread_checker_.CalledOnValidThread());
93 int id; 107 int id;
94 if (!base::StringToInt(device.id(), &id)) 108 if (!base::StringToInt(device.device_id, &id))
95 return; 109 return;
96 JNIEnv* env = AttachCurrentThread(); 110 JNIEnv* env = AttachCurrentThread();
97 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = 111 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats =
98 Java_VideoCaptureFactory_getDeviceSupportedFormats( 112 Java_VideoCaptureFactory_getDeviceSupportedFormats(
99 env, base::android::GetApplicationContext(), id); 113 env, base::android::GetApplicationContext(), id);
100 if (collected_formats.is_null()) 114 if (collected_formats.is_null())
101 return; 115 return;
102 116
103 jsize num_formats = env->GetArrayLength(collected_formats.obj()); 117 jsize num_formats = env->GetArrayLength(collected_formats.obj());
104 for (int i = 0; i < num_formats; ++i) { 118 for (int i = 0; i < num_formats; ++i) {
(...skipping 15 matching lines...) Expand all
120 } 134 }
121 VideoCaptureFormat capture_format( 135 VideoCaptureFormat capture_format(
122 gfx::Size(media::Java_VideoCaptureFactory_getCaptureFormatWidth( 136 gfx::Size(media::Java_VideoCaptureFactory_getCaptureFormatWidth(
123 env, format.obj()), 137 env, format.obj()),
124 media::Java_VideoCaptureFactory_getCaptureFormatHeight( 138 media::Java_VideoCaptureFactory_getCaptureFormatHeight(
125 env, format.obj())), 139 env, format.obj())),
126 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, 140 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env,
127 format.obj()), 141 format.obj()),
128 pixel_format); 142 pixel_format);
129 capture_formats->push_back(capture_format); 143 capture_formats->push_back(capture_format);
130 DVLOG(1) << device.name() << " " 144 DVLOG(1) << device.friendly_name << " "
131 << VideoCaptureFormat::ToString(capture_format); 145 << VideoCaptureFormat::ToString(capture_format);
132 } 146 }
133 } 147 }
134 148
135 // static 149 // static
136 VideoCaptureDeviceFactory* 150 VideoCaptureDeviceFactory*
137 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 151 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
138 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 152 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
139 return new VideoCaptureDeviceFactoryAndroid(); 153 return new VideoCaptureDeviceFactoryAndroid();
140 } 154 }
141 155
142 } // namespace media 156 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698