- add sources.
[platform/framework/web/crosswalk.git] / src / media / video / capture / video_capture_proxy.cc
1 // Copyright (c) 2011 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 "media/video/capture/video_capture_proxy.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10
11 namespace {
12
13 // Called on VC thread: extracts the state out of the VideoCapture, and
14 // serialize it into a VideoCaptureState.
15 media::VideoCaptureHandlerProxy::VideoCaptureState GetState(
16     media::VideoCapture* capture) {
17   media::VideoCaptureHandlerProxy::VideoCaptureState state;
18   state.started = capture->CaptureStarted();
19   state.frame_rate = capture->CaptureFrameRate();
20   return state;
21 }
22
23 }  // anonymous namespace
24
25 namespace media {
26
27 VideoCaptureHandlerProxy::VideoCaptureHandlerProxy(
28     VideoCapture::EventHandler* proxied,
29     scoped_refptr<base::MessageLoopProxy> main_message_loop)
30     : proxied_(proxied),
31       main_message_loop_(main_message_loop) {
32 }
33
34 VideoCaptureHandlerProxy::~VideoCaptureHandlerProxy() {
35 }
36
37 void VideoCaptureHandlerProxy::OnStarted(VideoCapture* capture) {
38   main_message_loop_->PostTask(FROM_HERE, base::Bind(
39         &VideoCaptureHandlerProxy::OnStartedOnMainThread,
40         base::Unretained(this),
41         capture,
42         GetState(capture)));
43 }
44
45 void VideoCaptureHandlerProxy::OnStopped(VideoCapture* capture) {
46   main_message_loop_->PostTask(FROM_HERE, base::Bind(
47         &VideoCaptureHandlerProxy::OnStoppedOnMainThread,
48         base::Unretained(this),
49         capture,
50         GetState(capture)));
51 }
52
53 void VideoCaptureHandlerProxy::OnPaused(VideoCapture* capture) {
54   main_message_loop_->PostTask(FROM_HERE, base::Bind(
55       &VideoCaptureHandlerProxy::OnPausedOnMainThread,
56       base::Unretained(this),
57       capture,
58       GetState(capture)));
59 }
60
61 void VideoCaptureHandlerProxy::OnError(VideoCapture* capture, int error_code) {
62   main_message_loop_->PostTask(FROM_HERE, base::Bind(
63       &VideoCaptureHandlerProxy::OnErrorOnMainThread,
64       base::Unretained(this),
65       capture,
66       GetState(capture),
67       error_code));
68 }
69
70 void VideoCaptureHandlerProxy::OnRemoved(VideoCapture* capture) {
71   main_message_loop_->PostTask(FROM_HERE, base::Bind(
72       &VideoCaptureHandlerProxy::OnRemovedOnMainThread,
73       base::Unretained(this),
74       capture,
75       GetState(capture)));
76 }
77
78 void VideoCaptureHandlerProxy::OnFrameReady(
79     VideoCapture* capture,
80     const scoped_refptr<VideoFrame>& frame) {
81   main_message_loop_->PostTask(
82       FROM_HERE,
83       base::Bind(&VideoCaptureHandlerProxy::OnFrameReadyOnMainThread,
84                  base::Unretained(this),
85                  capture,
86                  GetState(capture),
87                  frame));
88 }
89
90 void VideoCaptureHandlerProxy::OnStartedOnMainThread(
91     VideoCapture* capture,
92     const VideoCaptureState& state) {
93   state_ = state;
94   proxied_->OnStarted(capture);
95 }
96
97 void VideoCaptureHandlerProxy::OnStoppedOnMainThread(
98     VideoCapture* capture,
99     const VideoCaptureState& state) {
100   state_ = state;
101   proxied_->OnStopped(capture);
102 }
103
104 void VideoCaptureHandlerProxy::OnPausedOnMainThread(
105     VideoCapture* capture,
106     const VideoCaptureState& state) {
107   state_ = state;
108   proxied_->OnPaused(capture);
109 }
110
111 void VideoCaptureHandlerProxy::OnErrorOnMainThread(
112     VideoCapture* capture,
113     const VideoCaptureState& state,
114     int error_code) {
115   state_ = state;
116   proxied_->OnError(capture, error_code);
117 }
118
119 void VideoCaptureHandlerProxy::OnRemovedOnMainThread(
120     VideoCapture* capture,
121     const VideoCaptureState& state) {
122   state_ = state;
123   proxied_->OnRemoved(capture);
124 }
125
126 void VideoCaptureHandlerProxy::OnFrameReadyOnMainThread(
127     VideoCapture* capture,
128     const VideoCaptureState& state,
129     const scoped_refptr<VideoFrame>& frame) {
130   state_ = state;
131   proxied_->OnFrameReady(capture, frame);
132 }
133
134 }  // namespace media