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

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

Issue 2214533002: move //media/capture to //device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/capture/video/android/video_capture_device_factory_android.h"
6
7 #include <utility>
8
9 #include "base/android/context_utils.h"
10 #include "base/android/jni_string.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h"
13 #include "jni/VideoCaptureFactory_jni.h"
14 #include "media/capture/video/android/video_capture_device_android.h"
15
16 using base::android::AttachCurrentThread;
17 using base::android::ScopedJavaLocalRef;
18
19 namespace media {
20
21 // static
22 ScopedJavaLocalRef<jobject>
23 VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid(
24 int id,
25 jlong nativeVideoCaptureDeviceAndroid) {
26 return (Java_VideoCaptureFactory_createVideoCapture(
27 AttachCurrentThread(), base::android::GetApplicationContext(), id,
28 nativeVideoCaptureDeviceAndroid));
29 }
30
31 std::unique_ptr<VideoCaptureDevice>
32 VideoCaptureDeviceFactoryAndroid::CreateDevice(
33 const VideoCaptureDeviceDescriptor& device_descriptor) {
34 DCHECK(thread_checker_.CalledOnValidThread());
35 int id;
36 if (!base::StringToInt(device_descriptor.device_id, &id))
37 return std::unique_ptr<VideoCaptureDevice>();
38
39 std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device(
40 new VideoCaptureDeviceAndroid(device_descriptor));
41
42 if (video_capture_device->Init())
43 return std::move(video_capture_device);
44
45 DLOG(ERROR) << "Error creating Video Capture Device.";
46 return std::unique_ptr<VideoCaptureDevice>();
47 }
48
49 void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors(
50 VideoCaptureDeviceDescriptors* device_descriptors) {
51 DCHECK(thread_checker_.CalledOnValidThread());
52 device_descriptors->clear();
53
54 JNIEnv* env = AttachCurrentThread();
55
56 const jobject context = base::android::GetApplicationContext();
57 const int num_cameras =
58 Java_VideoCaptureFactory_getNumberOfCameras(env, context);
59 DVLOG(1) << __FUNCTION__ << ": num_cameras=" << num_cameras;
60 if (num_cameras <= 0)
61 return;
62
63 for (int camera_id = num_cameras - 1; camera_id >= 0; --camera_id) {
64 base::android::ScopedJavaLocalRef<jstring> device_name =
65 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context);
66 if (device_name.obj() == NULL)
67 continue;
68
69 const int capture_api_type =
70 Java_VideoCaptureFactory_getCaptureApiType(env, camera_id, context);
71 const std::string display_name =
72 base::android::ConvertJavaStringToUTF8(device_name);
73 const std::string device_id = base::IntToString(camera_id);
74
75 // Android cameras are not typically USB devices, and the model_id is
76 // currently only used for USB model identifiers, so this implementation
77 // just indicates an unknown device model (by not providing one).
78 device_descriptors->emplace_back(
79 display_name, device_id,
80 static_cast<VideoCaptureApi>(capture_api_type));
81
82 DVLOG(1) << __FUNCTION__ << ": camera "
83 << "device_name=" << display_name << ", unique_id=" << device_id;
84 }
85 }
86
87 void VideoCaptureDeviceFactoryAndroid::GetSupportedFormats(
88 const VideoCaptureDeviceDescriptor& device,
89 VideoCaptureFormats* capture_formats) {
90 DCHECK(thread_checker_.CalledOnValidThread());
91 int id;
92 if (!base::StringToInt(device.device_id, &id))
93 return;
94 JNIEnv* env = AttachCurrentThread();
95 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats =
96 Java_VideoCaptureFactory_getDeviceSupportedFormats(
97 env, base::android::GetApplicationContext(), id);
98 if (collected_formats.is_null())
99 return;
100
101 jsize num_formats = env->GetArrayLength(collected_formats.obj());
102 for (int i = 0; i < num_formats; ++i) {
103 base::android::ScopedJavaLocalRef<jobject> format(
104 env, env->GetObjectArrayElement(collected_formats.obj(), i));
105
106 VideoPixelFormat pixel_format =
107 media::PIXEL_FORMAT_UNKNOWN;
108 switch (media::Java_VideoCaptureFactory_getCaptureFormatPixelFormat(
109 env, format.obj())) {
110 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_YV12:
111 pixel_format = media::PIXEL_FORMAT_YV12;
112 break;
113 case VideoCaptureDeviceAndroid::ANDROID_IMAGE_FORMAT_NV21:
114 pixel_format = media::PIXEL_FORMAT_NV21;
115 break;
116 default:
117 continue;
118 }
119 VideoCaptureFormat capture_format(
120 gfx::Size(media::Java_VideoCaptureFactory_getCaptureFormatWidth(
121 env, format.obj()),
122 media::Java_VideoCaptureFactory_getCaptureFormatHeight(
123 env, format.obj())),
124 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env,
125 format.obj()),
126 pixel_format);
127 capture_formats->push_back(capture_format);
128 DVLOG(1) << device.display_name << " "
129 << VideoCaptureFormat::ToString(capture_format);
130 }
131 }
132
133 // static
134 VideoCaptureDeviceFactory*
135 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
136 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
137 return new VideoCaptureDeviceFactoryAndroid();
138 }
139
140 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/android/video_capture_device_factory_android.h ('k') | media/capture/video/fake_video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698