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

Side by Side Diff: content/browser/media/capture/desktop_capture_device.cc

Issue 1140113002: Implement screen capture for android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 "content/browser/media/capture/desktop_capture_device.h" 5 #include "content/browser/media/capture/desktop_capture_device.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 15 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/desktop_media_id.h" 17 #include "content/public/browser/desktop_media_id.h"
18 #include "content/public/browser/power_save_blocker.h" 18 #include "content/public/browser/power_save_blocker.h"
19 #include "media/base/video_util.h" 19 #include "media/base/video_util.h"
20 #if defined(OS_ANDROID)
21 #include "media/screen_capture/android/screen_capturer_android.h"
22 #endif
20 #include "third_party/libyuv/include/libyuv/scale_argb.h" 23 #include "third_party/libyuv/include/libyuv/scale_argb.h"
21 #include "third_party/webrtc/modules/desktop_capture/cropping_window_capturer.h" 24 #include "third_party/webrtc/modules/desktop_capture/cropping_window_capturer.h"
22 #include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer .h" 25 #include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer .h"
23 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" 26 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
24 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" 27 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 28 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
26 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h" 29 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
27 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" 30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
28 31
29 namespace content { 32 namespace content {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 capture_format_.pixel_format = media::PIXEL_FORMAT_ARGB; 178 capture_format_.pixel_format = media::PIXEL_FORMAT_ARGB;
176 179
177 power_save_blocker_.reset( 180 power_save_blocker_.reset(
178 PowerSaveBlocker::Create( 181 PowerSaveBlocker::Create(
179 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, 182 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
180 PowerSaveBlocker::kReasonOther, 183 PowerSaveBlocker::kReasonOther,
181 "DesktopCaptureDevice is running").release()); 184 "DesktopCaptureDevice is running").release());
182 185
183 desktop_capturer_->Start(this); 186 desktop_capturer_->Start(this);
184 187
188 #if defined(OS_ANDROID)
189 // For android, we don't use capture_timer_ to triger capturing. Instead,
190 // we use ImageReader.OnImageAvailableListener to listen when a screen frame
191 // available which is similar with VideoCapture
miu 2015/05/20 03:33:27 What happens if the screen does not update for a l
192 return;
193 #endif
194
185 CaptureFrameAndScheduleNext(); 195 CaptureFrameAndScheduleNext();
186 } 196 }
187 197
188 void DesktopCaptureDevice::Core::SetNotificationWindowId( 198 void DesktopCaptureDevice::Core::SetNotificationWindowId(
189 gfx::NativeViewId window_id) { 199 gfx::NativeViewId window_id) {
190 DCHECK(task_runner_->BelongsToCurrentThread()); 200 DCHECK(task_runner_->BelongsToCurrentThread());
191 DCHECK(window_id); 201 DCHECK(window_id);
192 desktop_capturer_->SetExcludedWindow(window_id); 202 desktop_capturer_->SetExcludedWindow(window_id);
193 } 203 }
194 204
195 webrtc::SharedMemory* 205 webrtc::SharedMemory*
196 DesktopCaptureDevice::Core::CreateSharedMemory(size_t size) { 206 DesktopCaptureDevice::Core::CreateSharedMemory(size_t size) {
197 return NULL; 207 return NULL;
198 } 208 }
199 209
200 void DesktopCaptureDevice::Core::OnCaptureCompleted( 210 void DesktopCaptureDevice::Core::OnCaptureCompleted(
201 webrtc::DesktopFrame* frame) { 211 webrtc::DesktopFrame* frame) {
212 #if !defined(OS_ANDROID)
miu 2015/05/20 03:33:27 Why don't these statements apply to the android pl
202 DCHECK(task_runner_->BelongsToCurrentThread()); 213 DCHECK(task_runner_->BelongsToCurrentThread());
203 DCHECK(capture_in_progress_); 214 DCHECK(capture_in_progress_);
215 #endif
204 216
205 if (!first_capture_returned_) { 217 if (!first_capture_returned_) {
206 first_capture_returned_ = true; 218 first_capture_returned_ = true;
207 if (capturer_type_ == DesktopMediaID::TYPE_SCREEN) { 219 if (capturer_type_ == DesktopMediaID::TYPE_SCREEN) {
208 IncrementDesktopCaptureCounter(frame ? FIRST_SCREEN_CAPTURE_SUCCEEDED 220 IncrementDesktopCaptureCounter(frame ? FIRST_SCREEN_CAPTURE_SUCCEEDED
209 : FIRST_SCREEN_CAPTURE_FAILED); 221 : FIRST_SCREEN_CAPTURE_FAILED);
210 } else { 222 } else {
211 IncrementDesktopCaptureCounter(frame ? FIRST_WINDOW_CAPTURE_SUCCEEDED 223 IncrementDesktopCaptureCounter(frame ? FIRST_WINDOW_CAPTURE_SUCCEEDED
212 : FIRST_WINDOW_CAPTURE_FAILED); 224 : FIRST_WINDOW_CAPTURE_FAILED);
213 } 225 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 options.set_disable_effects(false); 415 options.set_disable_effects(false);
404 416
405 #if defined(OS_WIN) 417 #if defined(OS_WIN)
406 options.set_allow_use_magnification_api(true); 418 options.set_allow_use_magnification_api(true);
407 #endif 419 #endif
408 420
409 scoped_ptr<webrtc::DesktopCapturer> capturer; 421 scoped_ptr<webrtc::DesktopCapturer> capturer;
410 422
411 switch (source.type) { 423 switch (source.type) {
412 case DesktopMediaID::TYPE_SCREEN: { 424 case DesktopMediaID::TYPE_SCREEN: {
425 #if defined(OS_ANDROID)
426 scoped_ptr<webrtc::ScreenCapturer> screen_capturer(
427 new media::ScreenCapturerAndroid());
428 #else
413 scoped_ptr<webrtc::ScreenCapturer> screen_capturer( 429 scoped_ptr<webrtc::ScreenCapturer> screen_capturer(
414 webrtc::ScreenCapturer::Create(options)); 430 webrtc::ScreenCapturer::Create(options));
431 #endif
415 if (screen_capturer && screen_capturer->SelectScreen(source.id)) { 432 if (screen_capturer && screen_capturer->SelectScreen(source.id)) {
416 capturer.reset(new webrtc::DesktopAndCursorComposer( 433 capturer.reset(new webrtc::DesktopAndCursorComposer(
417 screen_capturer.release(), 434 screen_capturer.release(),
418 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id))); 435 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id)));
419 IncrementDesktopCaptureCounter(SCREEN_CAPTURER_CREATED); 436 IncrementDesktopCaptureCounter(SCREEN_CAPTURER_CREATED);
420 } 437 }
421 break; 438 break;
422 } 439 }
423 440
424 case DesktopMediaID::TYPE_WINDOW: { 441 case DesktopMediaID::TYPE_WINDOW: {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 #else 505 #else
489 base::MessageLoop::Type thread_type = base::MessageLoop::TYPE_DEFAULT; 506 base::MessageLoop::Type thread_type = base::MessageLoop::TYPE_DEFAULT;
490 #endif 507 #endif
491 508
492 thread_.StartWithOptions(base::Thread::Options(thread_type, 0)); 509 thread_.StartWithOptions(base::Thread::Options(thread_type, 0));
493 510
494 core_.reset(new Core(thread_.task_runner(), capturer.Pass(), type)); 511 core_.reset(new Core(thread_.task_runner(), capturer.Pass(), type));
495 } 512 }
496 513
497 } // namespace content 514 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698