1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/host/ipc_video_frame_capturer.h"
6
7#include "remoting/host/desktop_session_proxy.h"
8#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
9#include "third_party/webrtc/modules/desktop_capture/mouse_cursor_shape.h"
10
11namespace remoting {
12
13IpcVideoFrameCapturer::IpcVideoFrameCapturer(
14    scoped_refptr<DesktopSessionProxy> desktop_session_proxy)
15    : callback_(NULL),
16      mouse_shape_observer_(NULL),
17      desktop_session_proxy_(desktop_session_proxy),
18      capture_pending_(false),
19      weak_factory_(this) {
20}
21
22IpcVideoFrameCapturer::~IpcVideoFrameCapturer() {
23}
24
25void IpcVideoFrameCapturer::Start(Callback* callback) {
26  DCHECK(!callback_);
27  DCHECK(callback);
28  callback_ = callback;
29  desktop_session_proxy_->SetVideoCapturer(weak_factory_.GetWeakPtr());
30}
31
32void IpcVideoFrameCapturer::SetMouseShapeObserver(
33      MouseShapeObserver* mouse_shape_observer) {
34  DCHECK(!mouse_shape_observer_);
35  DCHECK(mouse_shape_observer);
36  mouse_shape_observer_ = mouse_shape_observer;
37}
38
39void IpcVideoFrameCapturer::Capture(const webrtc::DesktopRegion& region) {
40  DCHECK(!capture_pending_);
41  capture_pending_ = true;
42  desktop_session_proxy_->CaptureFrame();
43}
44
45void IpcVideoFrameCapturer::OnCaptureCompleted(
46    scoped_ptr<webrtc::DesktopFrame> frame) {
47  DCHECK(capture_pending_);
48  capture_pending_ = false;
49  callback_->OnCaptureCompleted(frame.release());
50}
51
52void IpcVideoFrameCapturer::OnCursorShapeChanged(
53    scoped_ptr<webrtc::MouseCursorShape> cursor_shape) {
54  if (mouse_shape_observer_)
55    mouse_shape_observer_->OnCursorShapeChanged(cursor_shape.release());
56}
57
58}  // namespace remoting
59