Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / remoting / host / ipc_video_frame_capturer.cc
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
11 namespace remoting {
12
13 IpcVideoFrameCapturer::IpcVideoFrameCapturer(
14     scoped_refptr<DesktopSessionProxy> desktop_session_proxy)
15     : callback_(NULL),
16       desktop_session_proxy_(desktop_session_proxy),
17       capture_pending_(false),
18       weak_factory_(this) {
19 }
20
21 IpcVideoFrameCapturer::~IpcVideoFrameCapturer() {
22 }
23
24 void IpcVideoFrameCapturer::Start(Callback* callback) {
25   DCHECK(!callback_);
26   DCHECK(callback);
27   callback_ = callback;
28   desktop_session_proxy_->SetVideoCapturer(weak_factory_.GetWeakPtr());
29 }
30
31 void IpcVideoFrameCapturer::Capture(const webrtc::DesktopRegion& region) {
32   DCHECK(!capture_pending_);
33   capture_pending_ = true;
34   desktop_session_proxy_->CaptureFrame();
35 }
36
37 void IpcVideoFrameCapturer::OnCaptureCompleted(
38     scoped_ptr<webrtc::DesktopFrame> frame) {
39   DCHECK(capture_pending_);
40   capture_pending_ = false;
41   callback_->OnCaptureCompleted(frame.release());
42 }
43
44 }  // namespace remoting