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

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

Issue 23903032: Move NV21 colorspace treatment from VideoCapture java to C++ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unused GetIntField in VCDA; protected nv21_intermediate_buffer allocation in VCC Created 7 years, 3 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_android.h" 5 #include "media/video/capture/android/video_capture_device_android.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "jni/VideoCapture_jni.h" 14 #include "jni/VideoCapture_jni.h"
15 #include "media/base/video_util.h" 15 #include "media/base/video_util.h"
16 16
17 using base::android::AttachCurrentThread; 17 using base::android::AttachCurrentThread;
18 using base::android::CheckException; 18 using base::android::CheckException;
19 using base::android::GetClass; 19 using base::android::GetClass;
20 using base::android::MethodID; 20 using base::android::MethodID;
21 using base::android::JavaRef; 21 using base::android::JavaRef;
22 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
23 23
24 namespace {
25
26 int GetIntField(JNIEnv* env,
27 const JavaRef<jclass>& clazz,
28 const JavaRef<jobject>& instance,
29 const char* field_name) {
30 jfieldID field = GetFieldID(env, clazz, field_name, "I");
31 jint int_value = env->GetIntField(instance.obj(), field);
32 return int_value;
33 }
34
35 } // namespace
36
37 namespace media { 24 namespace media {
38 25
39 // static 26 // static
40 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 27 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
41 device_names->clear(); 28 device_names->clear();
42 29
43 JNIEnv* env = AttachCurrentThread(); 30 JNIEnv* env = AttachCurrentThread();
44 31
45 int num_cameras = Java_ChromiumCameraInfo_getNumberOfCameras(env); 32 int num_cameras = Java_ChromiumCameraInfo_getNumberOfCameras(env);
46 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras; 33 DVLOG(1) << "VideoCaptureDevice::GetDeviceNames: num_cameras=" << num_cameras;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return; 131 return;
145 } 132 }
146 133
147 // Store current width and height. 134 // Store current width and height.
148 current_settings_.width = 135 current_settings_.width =
149 Java_VideoCapture_queryWidth(env, j_capture_.obj()); 136 Java_VideoCapture_queryWidth(env, j_capture_.obj());
150 current_settings_.height = 137 current_settings_.height =
151 Java_VideoCapture_queryHeight(env, j_capture_.obj()); 138 Java_VideoCapture_queryHeight(env, j_capture_.obj());
152 current_settings_.frame_rate = 139 current_settings_.frame_rate =
153 Java_VideoCapture_queryFrameRate(env, j_capture_.obj()); 140 Java_VideoCapture_queryFrameRate(env, j_capture_.obj());
154 current_settings_.color = PIXEL_FORMAT_YV12; 141 current_settings_.color = GetColorspace();
142 DCHECK_NE(current_settings_.color, media::PIXEL_FORMAT_UNKNOWN);
155 CHECK(current_settings_.width > 0 && !(current_settings_.width % 2)); 143 CHECK(current_settings_.width > 0 && !(current_settings_.width % 2));
156 CHECK(current_settings_.height > 0 && !(current_settings_.height % 2)); 144 CHECK(current_settings_.height > 0 && !(current_settings_.height % 2));
157 145
158 DVLOG(1) << "VideoCaptureDeviceAndroid::Allocate: queried width=" 146 DVLOG(1) << "VideoCaptureDeviceAndroid::Allocate: queried width="
159 << current_settings_.width 147 << current_settings_.width
160 << ", height=" 148 << ", height="
161 << current_settings_.height 149 << current_settings_.height
162 << ", frame_rate=" 150 << ", frame_rate="
163 << current_settings_.frame_rate; 151 << current_settings_.frame_rate;
164 // Report the frame size to the observer. 152 // Report the frame size to the observer.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return; 237 return;
250 } 238 }
251 239
252 observer_->OnIncomingCapturedFrame( 240 observer_->OnIncomingCapturedFrame(
253 reinterpret_cast<uint8*>(buffer), length, base::Time::Now(), 241 reinterpret_cast<uint8*>(buffer), length, base::Time::Now(),
254 rotation, flip_vert, flip_horiz); 242 rotation, flip_vert, flip_horiz);
255 243
256 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT); 244 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT);
257 } 245 }
258 246
247 VideoPixelFormat VideoCaptureDeviceAndroid::GetColorspace() {
248 JNIEnv* env = AttachCurrentThread();
249 jclass cls = env->FindClass("android/graphics/ImageFormat");
250
251 int current_capture_colorspace =
252 Java_VideoCapture_getColorspace(env, j_capture_.obj());
253 if (current_capture_colorspace ==
Jói 2013/09/10 16:31:18 With all the continuation indents, I think this if
mcasas 2013/09/11 09:03:28 Done.
254 env->GetStaticIntField(cls, env->GetStaticFieldID(cls, "YV12", "I")))
255 return media::PIXEL_FORMAT_YV12;
256 else if (current_capture_colorspace ==
257 env->GetStaticIntField(cls, env->GetStaticFieldID(cls, "NV21", "I")))
258 return media::PIXEL_FORMAT_NV21;
259 else if (current_capture_colorspace ==
260 env->GetStaticIntField(cls, env->GetStaticFieldID(cls, "YUY2", "I")))
261 return media::PIXEL_FORMAT_YUY2;
262 else
263 // NOTE(mcasas): Other formats include NV16, JPEG, RGB565, and are not
264 // supported see http://goo.gl/iPbdYj .
265 return media::PIXEL_FORMAT_UNKNOWN;
266 }
267
259 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) { 268 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) {
260 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason; 269 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason;
261 { 270 {
262 base::AutoLock lock(lock_); 271 base::AutoLock lock(lock_);
263 state_ = kError; 272 state_ = kError;
264 } 273 }
265 observer_->OnError(); 274 observer_->OnError();
266 } 275 }
267 276
268 } // namespace media 277 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698