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"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
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();
25 } // anonymous namespace
29 VideoCaptureHandlerProxy::VideoCaptureHandlerProxy(
30 VideoCapture::EventHandler
* proxied
,
31 scoped_refptr
<base::MessageLoopProxy
> main_message_loop
)
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),
47 void VideoCaptureHandlerProxy::OnStopped(VideoCapture
* capture
) {
48 main_message_loop_
->PostTask(FROM_HERE
, base::Bind(
49 &VideoCaptureHandlerProxy::OnStoppedOnMainThread
,
50 base::Unretained(this),
55 void VideoCaptureHandlerProxy::OnPaused(VideoCapture
* capture
) {
56 main_message_loop_
->PostTask(FROM_HERE
, base::Bind(
57 &VideoCaptureHandlerProxy::OnPausedOnMainThread
,
58 base::Unretained(this),
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),
72 void VideoCaptureHandlerProxy::OnRemoved(VideoCapture
* capture
) {
73 main_message_loop_
->PostTask(FROM_HERE
, base::Bind(
74 &VideoCaptureHandlerProxy::OnRemovedOnMainThread
,
75 base::Unretained(this),
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),
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),
102 void VideoCaptureHandlerProxy::OnStartedOnMainThread(
103 VideoCapture
* capture
,
104 const VideoCaptureState
& state
) {
106 proxied_
->OnStarted(capture
);
109 void VideoCaptureHandlerProxy::OnStoppedOnMainThread(
110 VideoCapture
* capture
,
111 const VideoCaptureState
& state
) {
113 proxied_
->OnStopped(capture
);
116 void VideoCaptureHandlerProxy::OnPausedOnMainThread(
117 VideoCapture
* capture
,
118 const VideoCaptureState
& state
) {
120 proxied_
->OnPaused(capture
);
123 void VideoCaptureHandlerProxy::OnErrorOnMainThread(
124 VideoCapture
* capture
,
125 const VideoCaptureState
& state
,
128 proxied_
->OnError(capture
, error_code
);
131 void VideoCaptureHandlerProxy::OnRemovedOnMainThread(
132 VideoCapture
* capture
,
133 const VideoCaptureState
& state
) {
135 proxied_
->OnRemoved(capture
);
138 void VideoCaptureHandlerProxy::OnBufferReadyOnMainThread(
139 VideoCapture
* capture
,
140 const VideoCaptureState
& state
,
141 scoped_refptr
<VideoCapture::VideoFrameBuffer
> buffer
) {
143 proxied_
->OnBufferReady(capture
, buffer
);
146 void VideoCaptureHandlerProxy::OnDeviceInfoReceivedOnMainThread(
147 VideoCapture
* capture
,
148 const VideoCaptureState
& state
,
149 const VideoCaptureParams
& device_info
) {
151 proxied_
->OnDeviceInfoReceived(capture
, device_info
);