Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 int current_capture_colorspace = | |
| 250 Java_VideoCapture_getColorspace(env, j_capture_.obj()); | |
| 251 switch (current_capture_colorspace){ | |
| 252 case ANDROID_IMAGEFORMAT_YV12: | |
| 253 return media::PIXEL_FORMAT_YV12; | |
| 254 case ANDROID_IMAGEFORMAT_NV21: | |
| 255 return media::PIXEL_FORMAT_NV21; | |
| 256 case ANDROID_IMAGEFORMAT_YUY2: | |
| 257 return media::PIXEL_FORMAT_YUY2; | |
| 258 case ANDROID_IMAGEFORMAT_NV16: | |
| 259 case ANDROID_IMAGEFORMAT_JPEG: | |
| 260 case ANDROID_IMAGEFORMAT_RGB_565: | |
| 261 case ANDROID_IMAGEFORMAT_UNKNOWN: | |
| 262 // NOTE(mcasas): NV16, JPEG, RGB565 not supported in VideoFormatPixel. | |
|
Ami GONE FROM CHROMIUM
2013/09/12 17:03:16
indent is strange :)
mcasas
2013/09/16 08:43:02
Done.
| |
| 263 default: | |
|
Ami GONE FROM CHROMIUM
2013/09/12 17:03:16
omitting the default case will let the compiler wa
mcasas
2013/09/16 08:43:02
Problem is: is not an enum :( but an integer; we n
| |
| 264 return media::PIXEL_FORMAT_UNKNOWN; | |
| 265 } | |
| 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 |
| OLD | NEW |