| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content/android/screen_capture_machine_android.h" | 5 #include "media/capture/content/android/screen_capture_machine_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "jni/ScreenCapture_jni.h" | 10 #include "jni/ScreenCapture_jni.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 jobject obj, | 192 jobject obj, |
| 193 jboolean result) { | 193 jboolean result) { |
| 194 if (!result) { | 194 if (!result) { |
| 195 oracle_proxy_->ReportError(FROM_HERE, "The user denied screen capture"); | 195 oracle_proxy_->ReportError(FROM_HERE, "The user denied screen capture"); |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 | 198 |
| 199 Java_ScreenCapture_startCapture(env, obj); | 199 Java_ScreenCapture_startCapture(env, obj); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ScreenCaptureMachineAndroid::OnOrientationChange(JNIEnv* env, |
| 203 jobject obj, |
| 204 jint rotation) { |
| 205 DeviceOrientation orientation = kDefault; |
| 206 switch (rotation) { |
| 207 case 0: |
| 208 case 180: |
| 209 orientation = kPortrait; |
| 210 break; |
| 211 case 90: |
| 212 case 270: |
| 213 orientation = kLandscape; |
| 214 break; |
| 215 default: |
| 216 break; |
| 217 } |
| 218 |
| 219 gfx::Size capture_size = oracle_proxy_->GetCaptureSize(); |
| 220 const int width = capture_size.width(); |
| 221 const int height = capture_size.height(); |
| 222 |
| 223 if ((orientation == kLandscape && width < height) || |
| 224 (orientation == kPortrait && height < width)) { |
| 225 capture_size.SetSize(height, width); |
| 226 oracle_proxy_->UpdateCaptureSize(capture_size); |
| 227 } |
| 228 } |
| 229 |
| 202 void ScreenCaptureMachineAndroid::Start( | 230 void ScreenCaptureMachineAndroid::Start( |
| 203 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 231 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
| 204 const VideoCaptureParams& params, | 232 const VideoCaptureParams& params, |
| 205 const base::Callback<void(bool)> callback) { | 233 const base::Callback<void(bool)> callback) { |
| 206 DCHECK(oracle_proxy.get()); | 234 DCHECK(oracle_proxy.get()); |
| 207 oracle_proxy_ = oracle_proxy; | 235 oracle_proxy_ = oracle_proxy; |
| 208 | 236 |
| 209 j_capture_.Reset( | 237 j_capture_.Reset( |
| 210 createScreenCaptureMachineAndroid(reinterpret_cast<intptr_t>(this))); | 238 createScreenCaptureMachineAndroid(reinterpret_cast<intptr_t>(this))); |
| 211 | 239 |
| 212 if (j_capture_.obj() == nullptr) { | 240 if (j_capture_.obj() == nullptr) { |
| 213 DLOG(ERROR) << "Failed to createScreenCaptureAndroid"; | 241 DLOG(ERROR) << "Failed to createScreenCaptureAndroid"; |
| 214 callback.Run(false); | 242 callback.Run(false); |
| 215 return; | 243 return; |
| 216 } | 244 } |
| 217 | 245 |
| 218 DCHECK(params.requested_format.frame_size.GetArea()); | 246 DCHECK(params.requested_format.frame_size.GetArea()); |
| 219 DCHECK(!(params.requested_format.frame_size.width() % 2)); | 247 DCHECK(!(params.requested_format.frame_size.width() % 2)); |
| 220 DCHECK(!(params.requested_format.frame_size.height() % 2)); | 248 DCHECK(!(params.requested_format.frame_size.height() % 2)); |
| 221 | 249 |
| 222 const jboolean ret = Java_ScreenCapture_startPrompt( | 250 jboolean ret = |
| 223 AttachCurrentThread(), j_capture_, | 251 Java_ScreenCapture_allocate(AttachCurrentThread(), j_capture_, |
| 224 params.requested_format.frame_size.width(), | 252 params.requested_format.frame_size.width(), |
| 225 params.requested_format.frame_size.height()); | 253 params.requested_format.frame_size.height()); |
| 254 if (!ret) { |
| 255 DLOG(ERROR) << "Failed to init ScreenCaptureAndroid"; |
| 256 callback.Run(ret); |
| 257 return; |
| 258 } |
| 259 |
| 260 ret = Java_ScreenCapture_startPrompt(AttachCurrentThread(), j_capture_); |
| 226 | 261 |
| 227 callback.Run(ret); | 262 callback.Run(ret); |
| 228 } | 263 } |
| 229 | 264 |
| 230 void ScreenCaptureMachineAndroid::Stop(const base::Closure& callback) { | 265 void ScreenCaptureMachineAndroid::Stop(const base::Closure& callback) { |
| 231 Java_ScreenCapture_stopCapture(AttachCurrentThread(), j_capture_); | 266 if (j_capture_.obj() != nullptr) { |
| 267 Java_ScreenCapture_stopCapture(AttachCurrentThread(), j_capture_); |
| 268 } |
| 232 | 269 |
| 233 callback.Run(); | 270 callback.Run(); |
| 234 } | 271 } |
| 235 | 272 |
| 236 // ScreenCapture on Android works in a passive way and there are no captured | 273 // ScreenCapture on Android works in a passive way and there are no captured |
| 237 // frames when there is no update to the screen. When the oracle asks for a | 274 // frames when there is no update to the screen. When the oracle asks for a |
| 238 // capture refresh, the cached captured frame is redelivered. | 275 // capture refresh, the cached captured frame is redelivered. |
| 239 void ScreenCaptureMachineAndroid::MaybeCaptureForRefresh() { | 276 void ScreenCaptureMachineAndroid::MaybeCaptureForRefresh() { |
| 240 if (lastFrame_.get() == nullptr) | 277 if (lastFrame_.get() == nullptr) |
| 241 return; | 278 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 267 frame->visible_data(VideoFrame::kUPlane), | 304 frame->visible_data(VideoFrame::kUPlane), |
| 268 frame->stride(VideoFrame::kUPlane), | 305 frame->stride(VideoFrame::kUPlane), |
| 269 frame->visible_data(VideoFrame::kVPlane), | 306 frame->visible_data(VideoFrame::kVPlane), |
| 270 frame->stride(VideoFrame::kVPlane), frame->visible_rect().width(), | 307 frame->stride(VideoFrame::kVPlane), frame->visible_rect().width(), |
| 271 frame->visible_rect().height(), libyuv::kFilterBilinear); | 308 frame->visible_rect().height(), libyuv::kFilterBilinear); |
| 272 | 309 |
| 273 capture_frame_cb.Run(frame, start_time, true); | 310 capture_frame_cb.Run(frame, start_time, true); |
| 274 } | 311 } |
| 275 | 312 |
| 276 } // namespace media | 313 } // namespace media |
| OLD | NEW |