| 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 "device/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 "device/capture/content/video_capture_oracle.h" |
| 10 #include "jni/ScreenCapture_jni.h" | 11 #include "jni/ScreenCapture_jni.h" |
| 11 #include "media/capture/content/video_capture_oracle.h" | |
| 12 #include "third_party/libyuv/include/libyuv.h" | 12 #include "third_party/libyuv/include/libyuv.h" |
| 13 | 13 |
| 14 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
| 15 | 15 |
| 16 namespace media { | 16 namespace device { |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 bool ScreenCaptureMachineAndroid::RegisterScreenCaptureMachine(JNIEnv* env) { | 19 bool ScreenCaptureMachineAndroid::RegisterScreenCaptureMachine(JNIEnv* env) { |
| 20 return RegisterNativesImpl(env); | 20 return RegisterNativesImpl(env); |
| 21 } | 21 } |
| 22 | 22 |
| 23 ScreenCaptureMachineAndroid::ScreenCaptureMachineAndroid() {} | 23 ScreenCaptureMachineAndroid::ScreenCaptureMachineAndroid() {} |
| 24 | 24 |
| 25 ScreenCaptureMachineAndroid::~ScreenCaptureMachineAndroid() {} | 25 ScreenCaptureMachineAndroid::~ScreenCaptureMachineAndroid() {} |
| 26 | 26 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 48 const base::TimeTicks start_time = | 48 const base::TimeTicks start_time = |
| 49 base::TimeTicks() + base::TimeDelta::FromMicroseconds(absolute_micro); | 49 base::TimeTicks() + base::TimeDelta::FromMicroseconds(absolute_micro); |
| 50 scoped_refptr<VideoFrame> frame; | 50 scoped_refptr<VideoFrame> frame; |
| 51 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 51 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 52 | 52 |
| 53 if (!oracle_proxy_->ObserveEventAndDecideCapture( | 53 if (!oracle_proxy_->ObserveEventAndDecideCapture( |
| 54 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 54 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 | 57 |
| 58 DCHECK(frame->format() == PIXEL_FORMAT_I420 || | 58 DCHECK(frame->format() == media::PIXEL_FORMAT_I420 || |
| 59 frame->format() == PIXEL_FORMAT_YV12); | 59 frame->format() == media::PIXEL_FORMAT_YV12); |
| 60 | 60 |
| 61 scoped_refptr<VideoFrame> temp_frame = frame; | 61 scoped_refptr<VideoFrame> temp_frame = frame; |
| 62 if (frame->visible_rect().width() != width || | 62 if (frame->visible_rect().width() != width || |
| 63 frame->visible_rect().height() != height) { | 63 frame->visible_rect().height() != height) { |
| 64 temp_frame = VideoFrame::CreateFrame( | 64 temp_frame = VideoFrame::CreateFrame( |
| 65 PIXEL_FORMAT_I420, gfx::Size(width, height), gfx::Rect(width, height), | 65 media::PIXEL_FORMAT_I420, gfx::Size(width, height), |
| 66 gfx::Size(width, height), base::TimeDelta()); | 66 gfx::Rect(width, height), gfx::Size(width, height), base::TimeDelta()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 uint8_t* const src = | 69 uint8_t* const src = |
| 70 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(buf)); | 70 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(buf)); |
| 71 CHECK(src); | 71 CHECK(src); |
| 72 | 72 |
| 73 const int offset = top * row_stride + left * 4; | 73 const int offset = top * row_stride + left * 4; |
| 74 // ABGR little endian (rgba in memory) to I420. | 74 // ABGR little endian (rgba in memory) to I420. |
| 75 libyuv::ABGRToI420( | 75 libyuv::ABGRToI420( |
| 76 src + offset, row_stride, temp_frame->visible_data(VideoFrame::kYPlane), | 76 src + offset, row_stride, temp_frame->visible_data(VideoFrame::kYPlane), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 const base::TimeTicks start_time = | 123 const base::TimeTicks start_time = |
| 124 base::TimeTicks() + base::TimeDelta::FromMicroseconds(absolute_micro); | 124 base::TimeTicks() + base::TimeDelta::FromMicroseconds(absolute_micro); |
| 125 scoped_refptr<VideoFrame> frame; | 125 scoped_refptr<VideoFrame> frame; |
| 126 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 126 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 127 | 127 |
| 128 if (!oracle_proxy_->ObserveEventAndDecideCapture( | 128 if (!oracle_proxy_->ObserveEventAndDecideCapture( |
| 129 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 129 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 | 132 |
| 133 DCHECK(frame->format() == PIXEL_FORMAT_I420 || | 133 DCHECK(frame->format() == media::PIXEL_FORMAT_I420 || |
| 134 frame->format() == PIXEL_FORMAT_YV12); | 134 frame->format() == media::PIXEL_FORMAT_YV12); |
| 135 | 135 |
| 136 scoped_refptr<VideoFrame> temp_frame = frame; | 136 scoped_refptr<VideoFrame> temp_frame = frame; |
| 137 if (frame->visible_rect().width() != width || | 137 if (frame->visible_rect().width() != width || |
| 138 frame->visible_rect().height() != height) { | 138 frame->visible_rect().height() != height) { |
| 139 temp_frame = VideoFrame::CreateFrame( | 139 temp_frame = VideoFrame::CreateFrame( |
| 140 PIXEL_FORMAT_I420, gfx::Size(width, height), gfx::Rect(width, height), | 140 media::PIXEL_FORMAT_I420, gfx::Size(width, height), |
| 141 gfx::Size(width, height), base::TimeDelta()); | 141 gfx::Rect(width, height), gfx::Size(width, height), base::TimeDelta()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 uint8_t* const y_src = | 144 uint8_t* const y_src = |
| 145 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer)); | 145 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer)); |
| 146 CHECK(y_src); | 146 CHECK(y_src); |
| 147 uint8_t* u_src = | 147 uint8_t* u_src = |
| 148 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(u_buffer)); | 148 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(u_buffer)); |
| 149 CHECK(u_src); | 149 CHECK(u_src); |
| 150 uint8_t* v_src = | 150 uint8_t* v_src = |
| 151 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(v_buffer)); | 151 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(v_buffer)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 VideoCaptureOracle::kActiveRefreshRequest; | 243 VideoCaptureOracle::kActiveRefreshRequest; |
| 244 const base::TimeTicks start_time = base::TimeTicks::Now(); | 244 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 245 scoped_refptr<VideoFrame> frame; | 245 scoped_refptr<VideoFrame> frame; |
| 246 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 246 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 247 | 247 |
| 248 if (!oracle_proxy_->ObserveEventAndDecideCapture( | 248 if (!oracle_proxy_->ObserveEventAndDecideCapture( |
| 249 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 249 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 | 252 |
| 253 DCHECK(frame->format() == PIXEL_FORMAT_I420 || | 253 DCHECK(frame->format() == media::PIXEL_FORMAT_I420 || |
| 254 frame->format() == PIXEL_FORMAT_YV12); | 254 frame->format() == media::PIXEL_FORMAT_YV12); |
| 255 | 255 |
| 256 libyuv::I420Scale( | 256 libyuv::I420Scale( |
| 257 lastFrame_->visible_data(VideoFrame::kYPlane), | 257 lastFrame_->visible_data(VideoFrame::kYPlane), |
| 258 lastFrame_->stride(VideoFrame::kYPlane), | 258 lastFrame_->stride(VideoFrame::kYPlane), |
| 259 lastFrame_->visible_data(VideoFrame::kUPlane), | 259 lastFrame_->visible_data(VideoFrame::kUPlane), |
| 260 lastFrame_->stride(VideoFrame::kUPlane), | 260 lastFrame_->stride(VideoFrame::kUPlane), |
| 261 lastFrame_->visible_data(VideoFrame::kVPlane), | 261 lastFrame_->visible_data(VideoFrame::kVPlane), |
| 262 lastFrame_->stride(VideoFrame::kVPlane), | 262 lastFrame_->stride(VideoFrame::kVPlane), |
| 263 lastFrame_->visible_rect().width(), lastFrame_->visible_rect().height(), | 263 lastFrame_->visible_rect().width(), lastFrame_->visible_rect().height(), |
| 264 frame->visible_data(VideoFrame::kYPlane), | 264 frame->visible_data(VideoFrame::kYPlane), |
| 265 frame->stride(VideoFrame::kYPlane), | 265 frame->stride(VideoFrame::kYPlane), |
| 266 frame->visible_data(VideoFrame::kUPlane), | 266 frame->visible_data(VideoFrame::kUPlane), |
| 267 frame->stride(VideoFrame::kUPlane), | 267 frame->stride(VideoFrame::kUPlane), |
| 268 frame->visible_data(VideoFrame::kVPlane), | 268 frame->visible_data(VideoFrame::kVPlane), |
| 269 frame->stride(VideoFrame::kVPlane), frame->visible_rect().width(), | 269 frame->stride(VideoFrame::kVPlane), frame->visible_rect().width(), |
| 270 frame->visible_rect().height(), libyuv::kFilterBilinear); | 270 frame->visible_rect().height(), libyuv::kFilterBilinear); |
| 271 | 271 |
| 272 capture_frame_cb.Run(frame, start_time, true); | 272 capture_frame_cb.Run(frame, start_time, true); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace media | 275 } // namespace device |
| OLD | NEW |