Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: content/browser/renderer_host/video_capture_host.cc

Issue 7002027: VideoCaptureHost (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 "content/browser/renderer_host/video_capture_host.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util-inl.h"
9 #include "content/common/video_capture_messages.h"
10
11 VideoCaptureHost::VideoCaptureHost() {}
12
13 VideoCaptureHost::~VideoCaptureHost() {
scherkus (not reviewing) 2011/05/23 05:05:09 nit: collapse onto one line {}
Per K 2011/05/23 12:05:47 Done.
14 }
15
16 void VideoCaptureHost::OnChannelClosing() {
17 BrowserMessageFilter::OnChannelClosing();
18
19 // Since the IPC channel is gone, close all requested VideCaptureDevices.
20 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); it++) {
21 VideoCaptureController* controller = it->second;
22 // Since the channel is closing we need a task to make sure VideoCaptureHost
23 // is not deleted before VideoCaptureController.
24 controller->StopCapture(
25 NewRunnableMethod(this, &VideoCaptureHost::OnReadyToDelete, it->first));
26 }
27 }
28
29 void VideoCaptureHost::OnDestruct() const {
30 BrowserThread::DeleteOnIOThread::Destruct(this);
31 }
32
33 ///////////////////////////////////////////////////////////////////////////////
34
35 // Implements VideoCaptureController::EventHandler.
36 void VideoCaptureHost::OnError(VideoCaptureController::ControllerId id) {
37 BrowserThread::PostTask(
38 BrowserThread::IO, FROM_HERE,
39 NewRunnableMethod(this, &VideoCaptureHost::DoHandleError, id.first,
40 id.second));
41 }
42
43 void VideoCaptureHost::OnBufferReady(
44 VideoCaptureController::ControllerId id,
45 TransportDIB::Handle handle,
46 base::Time timestamp) {
47 BrowserThread::PostTask(
48 BrowserThread::IO, FROM_HERE,
49 NewRunnableMethod(this, &VideoCaptureHost::DoSendFilledBuffer, id.first,
50 id.second, handle, timestamp));
51 }
52
53 void VideoCaptureHost::OnFrameInfo(VideoCaptureController::ControllerId id,
54 int width,
55 int height,
56 int frame_per_second) {
57 BrowserThread::PostTask(
58 BrowserThread::IO, FROM_HERE,
59 NewRunnableMethod(this, &VideoCaptureHost::DoSendFrameInfo, id.first,
60 id.second, width, height, frame_per_second));
61 }
62
63 void VideoCaptureHost::OnReadyToDelete(
64 VideoCaptureController::ControllerId id) {
65 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE,
67 NewRunnableMethod(this, &VideoCaptureHost::DoDeleteVideoCaptureController,
68 id));
69 }
70
71 void VideoCaptureHost::DoSendFilledBuffer(int32 routing_id,
72 int device_id,
73 TransportDIB::Handle handle,
74 base::Time timestamp) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
76
77 Send(new VideoCaptureMsg_BufferReady(routing_id, device_id, handle,
78 timestamp));
79 }
80
81 void VideoCaptureHost::DoHandleError(int32 routing_id, int device_id) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
83
84 Send(new VideoCaptureMsg_StateChanged(routing_id, device_id,
85 media::VideoCapture::kError));
86
87 VideoCaptureController::ControllerId id(routing_id, device_id);
88 EntryMap::iterator it = entries_.find(id);
89 if (it != entries_.end()) {
90 VideoCaptureController* controller = it->second;
91 controller->StopCapture(NULL);
92 }
93 }
94
95 void VideoCaptureHost::DoSendFrameInfo(int32 routing_id,
96 int device_id,
97 int width,
98 int height,
99 int frame_per_second) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
101
102 media::VideoCaptureParams params;
103 params.width = width;
104 params.height = height;
105 params.frame_per_second = frame_per_second;
106 Send(new VideoCaptureMsg_DeviceInfo(routing_id, device_id, params));
107 Send(new VideoCaptureMsg_StateChanged(routing_id, device_id,
108 media::VideoCapture::kStarted));
109 }
110
111 ///////////////////////////////////////////////////////////////////////////////
112 // IPC Messages handler.
113 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message,
114 bool* message_was_ok) {
115 bool handled = true;
116 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok)
117 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture)
scherkus (not reviewing) 2011/05/23 05:05:09 indent the HANDLER functions by 2 spaces
Per K 2011/05/23 12:05:47 Done.
118 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture)
119 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture)
120 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer)
121 IPC_MESSAGE_UNHANDLED(handled = false)
122 IPC_END_MESSAGE_MAP_EX()
123
124 return handled;
125 }
126
127 void VideoCaptureHost::OnStartCapture(const IPC::Message& msg, int device_id,
128 const media::VideoCaptureParams& params) {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
130
131 VideoCaptureController::ControllerId controller_id(msg.routing_id(),
132 device_id);
133
134 DCHECK(entries_.find(controller_id) == entries_.end());
scherkus (not reviewing) 2011/05/23 05:05:09 DCHECK_EQ
Per K 2011/05/23 12:05:47 Can I really do that with complex types? I get the
scherkus (not reviewing) 2011/05/23 21:19:17 ah I thought it was a basic type! my bad!
135
136 scoped_refptr<VideoCaptureController> controller =
137 new VideoCaptureController(controller_id, this);
138 entries_.insert(std::make_pair(controller_id, controller));
139 controller->StartCapture(params);
140 }
141
142 void VideoCaptureHost::OnStopCapture(const IPC::Message& msg, int device_id) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
144
145 VideoCaptureController::ControllerId controller_id(msg.routing_id(),
146 device_id);
147 EntryMap::iterator it = entries_.find(controller_id);
148 if (it != entries_.end()) {
149 scoped_refptr<VideoCaptureController> controller = it->second;
150 controller->StopCapture(NULL);
151 } else {
152 // It does not exist so it must have been stopped already.
scherkus (not reviewing) 2011/05/23 05:05:09 indentation
Per K 2011/05/23 12:05:47 Done.
153 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id,
154 media::VideoCapture::kStopped));
155 }
156 }
157
158 void VideoCaptureHost::OnPauseCapture(const IPC::Message& msg, int device_id) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
160 // Not used.
161 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id,
162 media::VideoCapture::kError));
163 }
164
165 void VideoCaptureHost::OnReceiveEmptyBuffer(const IPC::Message& msg,
166 int device_id,
167 TransportDIB::Handle handle) {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
169
170 VideoCaptureController::ControllerId controller_id(msg.routing_id(),
171 device_id);
172 EntryMap::iterator it = entries_.find(controller_id);
173 if (it != entries_.end()) {
174 scoped_refptr<VideoCaptureController> controller = it->second;
175 controller->ReturnTransportDIB(handle);
176 }
177 }
178
179 void VideoCaptureHost::DoDeleteVideoCaptureController(
180 VideoCaptureController::ControllerId id) {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
182
183 // Report that the device have successfully been stopped.
184 Send(new VideoCaptureMsg_StateChanged(id.first, id.second,
185 media::VideoCapture::kStopped));
186 entries_.erase(id);
scherkus (not reviewing) 2011/05/23 05:05:09 will this actually delete the VideoCaptureControll
Per K 2011/05/23 12:05:47 Yes- since it is a ref_counted pointer. VideoCapt
187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698