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

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

Issue 611283002: Android Video Capture: Added static methods for device & capabilities enumeration using Camera2 API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years 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
« no previous file with comments | « media/base/android/java/src/org/chromium/media/VideoCaptureFactory.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/video/capture/android/video_capture_device_factory_android.h" 5 #include "media/video/capture/android/video_capture_device_factory_android.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return scoped_ptr<VideoCaptureDevice>(); 51 return scoped_ptr<VideoCaptureDevice>();
52 } 52 }
53 53
54 void VideoCaptureDeviceFactoryAndroid::GetDeviceNames( 54 void VideoCaptureDeviceFactoryAndroid::GetDeviceNames(
55 VideoCaptureDevice::Names* device_names) { 55 VideoCaptureDevice::Names* device_names) {
56 DCHECK(thread_checker_.CalledOnValidThread()); 56 DCHECK(thread_checker_.CalledOnValidThread());
57 device_names->clear(); 57 device_names->clear();
58 58
59 JNIEnv* env = AttachCurrentThread(); 59 JNIEnv* env = AttachCurrentThread();
60 60
61 int num_cameras = Java_VideoCaptureFactory_getNumberOfCameras( 61 const jobject context = base::android::GetApplicationContext();
62 env, base::android::GetApplicationContext()); 62 const int num_cameras = Java_VideoCaptureFactory_getNumberOfCameras(env,
63 context);
63 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras; 64 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras;
64 if (num_cameras <= 0) 65 if (num_cameras <= 0)
65 return; 66 return;
66 67
67 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) {
68 base::android::ScopedJavaLocalRef<jstring> device_name = 69 base::android::ScopedJavaLocalRef<jstring> device_name =
69 Java_VideoCaptureFactory_getDeviceName(env, camera_id); 70 Java_VideoCaptureFactory_getDeviceName(env, camera_id, context);
70 if (device_name.obj() == NULL) 71 if (device_name.obj() == NULL)
71 continue; 72 continue;
72 73
73 VideoCaptureDevice::Name name( 74 VideoCaptureDevice::Name name(
74 base::android::ConvertJavaStringToUTF8(device_name), 75 base::android::ConvertJavaStringToUTF8(device_name),
75 base::IntToString(camera_id)); 76 base::IntToString(camera_id));
76 device_names->push_back(name); 77 device_names->push_back(name);
77 78
78 DVLOG(1) << "VideoCaptureDeviceFactoryAndroid::GetDeviceNames: camera " 79 DVLOG(1) << "VideoCaptureDeviceFactoryAndroid::GetDeviceNames: camera "
79 << "device_name=" << name.name() << ", unique_id=" << name.id(); 80 << "device_name=" << name.name() << ", unique_id=" << name.id();
80 } 81 }
81 } 82 }
82 83
83 void VideoCaptureDeviceFactoryAndroid::GetDeviceSupportedFormats( 84 void VideoCaptureDeviceFactoryAndroid::GetDeviceSupportedFormats(
84 const VideoCaptureDevice::Name& device, 85 const VideoCaptureDevice::Name& device,
85 VideoCaptureFormats* capture_formats) { 86 VideoCaptureFormats* capture_formats) {
86 DCHECK(thread_checker_.CalledOnValidThread()); 87 DCHECK(thread_checker_.CalledOnValidThread());
87 int id; 88 int id;
88 if (!base::StringToInt(device.id(), &id)) 89 if (!base::StringToInt(device.id(), &id))
89 return; 90 return;
90 JNIEnv* env = AttachCurrentThread(); 91 JNIEnv* env = AttachCurrentThread();
91 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats = 92 base::android::ScopedJavaLocalRef<jobjectArray> collected_formats =
92 Java_VideoCaptureFactory_getDeviceSupportedFormats(env, id); 93 Java_VideoCaptureFactory_getDeviceSupportedFormats(env,
94 base::android::GetApplicationContext(), id);
93 if (collected_formats.is_null()) 95 if (collected_formats.is_null())
94 return; 96 return;
95 97
96 jsize num_formats = env->GetArrayLength(collected_formats.obj()); 98 jsize num_formats = env->GetArrayLength(collected_formats.obj());
97 for (int i = 0; i < num_formats; ++i) { 99 for (int i = 0; i < num_formats; ++i) {
98 base::android::ScopedJavaLocalRef<jobject> format( 100 base::android::ScopedJavaLocalRef<jobject> format(
99 env, env->GetObjectArrayElement(collected_formats.obj(), i)); 101 env, env->GetObjectArrayElement(collected_formats.obj(), i));
100 102
101 VideoPixelFormat pixel_format = media::PIXEL_FORMAT_UNKNOWN; 103 VideoPixelFormat pixel_format = media::PIXEL_FORMAT_UNKNOWN;
102 switch (media::Java_VideoCaptureFactory_getCaptureFormatPixelFormat( 104 switch (media::Java_VideoCaptureFactory_getCaptureFormatPixelFormat(
(...skipping 14 matching lines...) Expand all
117 format.obj())), 119 format.obj())),
118 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env, 120 media::Java_VideoCaptureFactory_getCaptureFormatFramerate(env,
119 format.obj()), 121 format.obj()),
120 pixel_format); 122 pixel_format);
121 capture_formats->push_back(capture_format); 123 capture_formats->push_back(capture_format);
122 DVLOG(1) << device.name() << " " << capture_format.ToString(); 124 DVLOG(1) << device.name() << " " << capture_format.ToString();
123 } 125 }
124 } 126 }
125 127
126 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/java/src/org/chromium/media/VideoCaptureFactory.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698