cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / video / capture / video_capture_proxy.cc
blobeb8fd071909dc34af9e21a2c41bf8ec05a30204e
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.
5 #include "media/video/capture/video_capture_proxy.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
11 namespace {
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.width = capture->CaptureWidth();
20 state.height = capture->CaptureHeight();
21 state.frame_rate = capture->CaptureFrameRate();
22 return state;
25 } // anonymous namespace
27 namespace media {
29 VideoCaptureHandlerProxy::VideoCaptureHandlerProxy(
30 VideoCapture::EventHandler* proxied,
31 scoped_refptr<base::MessageLoopProxy> main_message_loop)
32 : proxied_(proxied),
33 main_message_loop_(main_message_loop) {
36 VideoCaptureHandlerProxy::~VideoCaptureHandlerProxy() {
39 void VideoCaptureHandlerProxy::OnStarted(VideoCapture* capture) {
40 main_message_loop_->PostTask(FROM_HERE, base::Bind(
41 &VideoCaptureHandlerProxy::OnStartedOnMainThread,
42 base::Unretained(this),
43 capture,
44 GetState(capture)));
47 void VideoCaptureHandlerProxy::OnStopped(VideoCapture* capture) {
48 main_message_loop_->PostTask(FROM_HERE, base::Bind(
49 &VideoCaptureHandlerProxy::OnStoppedOnMainThread,
50 base::Unretained(this),
51 capture,
52 GetState(capture)));
55 void VideoCaptureHandlerProxy::OnPaused(VideoCapture* capture) {
56 main_message_loop_->PostTask(FROM_HERE, base::Bind(
57 &VideoCaptureHandlerProxy::OnPausedOnMainThread,
58 base::Unretained(this),
59 capture,
60 GetState(capture)));
63 void VideoCaptureHandlerProxy::OnError(VideoCapture* capture, int error_code) {
64 main_message_loop_->PostTask(FROM_HERE, base::Bind(
65 &VideoCaptureHandlerProxy::OnErrorOnMainThread,
66 base::Unretained(this),
67 capture,
68 GetState(capture),
69 error_code));
72 void VideoCaptureHandlerProxy::OnRemoved(VideoCapture* capture) {
73 main_message_loop_->PostTask(FROM_HERE, base::Bind(
74 &VideoCaptureHandlerProxy::OnRemovedOnMainThread,
75 base::Unretained(this),
76 capture,
77 GetState(capture)));
80 void VideoCaptureHandlerProxy::OnBufferReady(
81 VideoCapture* capture,
82 scoped_refptr<VideoCapture::VideoFrameBuffer> buffer) {
83 main_message_loop_->PostTask(FROM_HERE, base::Bind(
84 &VideoCaptureHandlerProxy::OnBufferReadyOnMainThread,
85 base::Unretained(this),
86 capture,
87 GetState(capture),
88 buffer));
91 void VideoCaptureHandlerProxy::OnDeviceInfoReceived(
92 VideoCapture* capture,
93 const VideoCaptureParams& device_info) {
94 main_message_loop_->PostTask(FROM_HERE, base::Bind(
95 &VideoCaptureHandlerProxy::OnDeviceInfoReceivedOnMainThread,
96 base::Unretained(this),
97 capture,
98 GetState(capture),
99 device_info));
102 void VideoCaptureHandlerProxy::OnStartedOnMainThread(
103 VideoCapture* capture,
104 const VideoCaptureState& state) {
105 state_ = state;
106 proxied_->OnStarted(capture);
109 void VideoCaptureHandlerProxy::OnStoppedOnMainThread(
110 VideoCapture* capture,
111 const VideoCaptureState& state) {
112 state_ = state;
113 proxied_->OnStopped(capture);
116 void VideoCaptureHandlerProxy::OnPausedOnMainThread(
117 VideoCapture* capture,
118 const VideoCaptureState& state) {
119 state_ = state;
120 proxied_->OnPaused(capture);
123 void VideoCaptureHandlerProxy::OnErrorOnMainThread(
124 VideoCapture* capture,
125 const VideoCaptureState& state,
126 int error_code) {
127 state_ = state;
128 proxied_->OnError(capture, error_code);
131 void VideoCaptureHandlerProxy::OnRemovedOnMainThread(
132 VideoCapture* capture,
133 const VideoCaptureState& state) {
134 state_ = state;
135 proxied_->OnRemoved(capture);
138 void VideoCaptureHandlerProxy::OnBufferReadyOnMainThread(
139 VideoCapture* capture,
140 const VideoCaptureState& state,
141 scoped_refptr<VideoCapture::VideoFrameBuffer> buffer) {
142 state_ = state;
143 proxied_->OnBufferReady(capture, buffer);
146 void VideoCaptureHandlerProxy::OnDeviceInfoReceivedOnMainThread(
147 VideoCapture* capture,
148 const VideoCaptureState& state,
149 const VideoCaptureParams& device_info) {
150 state_ = state;
151 proxied_->OnDeviceInfoReceived(capture, device_info);
154 } // namespace media