| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/video_capture_host.h" | 5 #include "content/browser/renderer_host/video_capture_host.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "content/common/video_capture_messages.h" | 9 #include "content/common/video_capture_messages.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 NewRunnableMethod(this, &VideoCaptureHost::OnReadyToDelete, it->first)); | 24 NewRunnableMethod(this, &VideoCaptureHost::OnReadyToDelete, it->first)); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 void VideoCaptureHost::OnDestruct() const { | 28 void VideoCaptureHost::OnDestruct() const { |
| 29 BrowserThread::DeleteOnIOThread::Destruct(this); | 29 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
| 33 | 33 |
| 34 // Implements VideoCaptureController::EventHandler. | 34 // Implements VideoCaptureControllerEventHandler. |
| 35 void VideoCaptureHost::OnError(VideoCaptureController::ControllerId id) { | 35 void VideoCaptureHost::OnError(const VideoCaptureControllerID& id) { |
| 36 BrowserThread::PostTask( | 36 BrowserThread::PostTask( |
| 37 BrowserThread::IO, FROM_HERE, | 37 BrowserThread::IO, FROM_HERE, |
| 38 NewRunnableMethod(this, &VideoCaptureHost::DoHandleError, id.first, | 38 NewRunnableMethod(this, &VideoCaptureHost::DoHandleError, id.routing_id, |
| 39 id.second)); | 39 id.device_id)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void VideoCaptureHost::OnBufferReady( | 42 void VideoCaptureHost::OnBufferReady( |
| 43 VideoCaptureController::ControllerId id, | 43 const VideoCaptureControllerID& id, |
| 44 TransportDIB::Handle handle, | 44 TransportDIB::Handle handle, |
| 45 base::Time timestamp) { | 45 base::Time timestamp) { |
| 46 BrowserThread::PostTask( | 46 BrowserThread::PostTask( |
| 47 BrowserThread::IO, FROM_HERE, | 47 BrowserThread::IO, FROM_HERE, |
| 48 NewRunnableMethod(this, &VideoCaptureHost::DoSendFilledBuffer, id.first, | 48 NewRunnableMethod(this, &VideoCaptureHost::DoSendFilledBuffer, |
| 49 id.second, handle, timestamp)); | 49 id.routing_id, id.device_id, handle, timestamp)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void VideoCaptureHost::OnFrameInfo(VideoCaptureController::ControllerId id, | 52 void VideoCaptureHost::OnFrameInfo(const VideoCaptureControllerID& id, |
| 53 int width, | 53 int width, |
| 54 int height, | 54 int height, |
| 55 int frame_per_second) { | 55 int frame_per_second) { |
| 56 BrowserThread::PostTask( | 56 BrowserThread::PostTask( |
| 57 BrowserThread::IO, FROM_HERE, | 57 BrowserThread::IO, FROM_HERE, |
| 58 NewRunnableMethod(this, &VideoCaptureHost::DoSendFrameInfo, id.first, | 58 NewRunnableMethod(this, &VideoCaptureHost::DoSendFrameInfo, id.routing_id, |
| 59 id.second, width, height, frame_per_second)); | 59 id.device_id, width, height, frame_per_second)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void VideoCaptureHost::OnReadyToDelete( | 62 void VideoCaptureHost::OnReadyToDelete(const VideoCaptureControllerID& id) { |
| 63 VideoCaptureController::ControllerId id) { | |
| 64 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
| 65 BrowserThread::IO, FROM_HERE, | 64 BrowserThread::IO, FROM_HERE, |
| 66 NewRunnableMethod(this, &VideoCaptureHost::DoDeleteVideoCaptureController, | 65 NewRunnableMethod(this, &VideoCaptureHost::DoDeleteVideoCaptureController, |
| 67 id)); | 66 id)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void VideoCaptureHost::DoSendFilledBuffer(int32 routing_id, | 69 void VideoCaptureHost::DoSendFilledBuffer(int32 routing_id, |
| 71 int device_id, | 70 int device_id, |
| 72 TransportDIB::Handle handle, | 71 TransportDIB::Handle handle, |
| 73 base::Time timestamp) { | 72 base::Time timestamp) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 75 | 74 |
| 76 Send(new VideoCaptureMsg_BufferReady(routing_id, device_id, handle, | 75 Send(new VideoCaptureMsg_BufferReady(routing_id, device_id, handle, |
| 77 timestamp)); | 76 timestamp)); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void VideoCaptureHost::DoHandleError(int32 routing_id, int device_id) { | 79 void VideoCaptureHost::DoHandleError(int32 routing_id, int device_id) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 82 | 81 |
| 83 Send(new VideoCaptureMsg_StateChanged(routing_id, device_id, | 82 Send(new VideoCaptureMsg_StateChanged(routing_id, device_id, |
| 84 media::VideoCapture::kError)); | 83 media::VideoCapture::kError)); |
| 85 | 84 |
| 86 VideoCaptureController::ControllerId id(routing_id, device_id); | 85 VideoCaptureControllerID id(routing_id, device_id); |
| 87 EntryMap::iterator it = entries_.find(id); | 86 EntryMap::iterator it = entries_.find(id); |
| 88 if (it != entries_.end()) { | 87 if (it != entries_.end()) { |
| 89 VideoCaptureController* controller = it->second; | 88 VideoCaptureController* controller = it->second; |
| 90 controller->StopCapture(NULL); | 89 controller->StopCapture(NULL); |
| 91 } | 90 } |
| 92 } | 91 } |
| 93 | 92 |
| 94 void VideoCaptureHost::DoSendFrameInfo(int32 routing_id, | 93 void VideoCaptureHost::DoSendFrameInfo(int32 routing_id, |
| 95 int device_id, | 94 int device_id, |
| 96 int width, | 95 int width, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 120 IPC_MESSAGE_UNHANDLED(handled = false) | 119 IPC_MESSAGE_UNHANDLED(handled = false) |
| 121 IPC_END_MESSAGE_MAP_EX() | 120 IPC_END_MESSAGE_MAP_EX() |
| 122 | 121 |
| 123 return handled; | 122 return handled; |
| 124 } | 123 } |
| 125 | 124 |
| 126 void VideoCaptureHost::OnStartCapture(const IPC::Message& msg, int device_id, | 125 void VideoCaptureHost::OnStartCapture(const IPC::Message& msg, int device_id, |
| 127 const media::VideoCaptureParams& params) { | 126 const media::VideoCaptureParams& params) { |
| 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 129 | 128 |
| 130 VideoCaptureController::ControllerId controller_id(msg.routing_id(), | 129 VideoCaptureControllerID controller_id(msg.routing_id(), device_id); |
| 131 device_id); | |
| 132 | 130 |
| 133 DCHECK(entries_.find(controller_id) == entries_.end()); | 131 DCHECK(entries_.find(controller_id) == entries_.end()); |
| 134 | 132 |
| 135 scoped_refptr<VideoCaptureController> controller = | 133 scoped_refptr<VideoCaptureController> controller = |
| 136 new VideoCaptureController(controller_id, peer_handle(), this); | 134 new VideoCaptureController(controller_id, peer_handle(), this); |
| 137 entries_.insert(std::make_pair(controller_id, controller)); | 135 entries_.insert(std::make_pair(controller_id, controller)); |
| 138 controller->StartCapture(params); | 136 controller->StartCapture(params); |
| 139 } | 137 } |
| 140 | 138 |
| 141 void VideoCaptureHost::OnStopCapture(const IPC::Message& msg, int device_id) { | 139 void VideoCaptureHost::OnStopCapture(const IPC::Message& msg, int device_id) { |
| 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 143 | 141 |
| 144 VideoCaptureController::ControllerId controller_id(msg.routing_id(), | 142 VideoCaptureControllerID controller_id(msg.routing_id(), device_id); |
| 145 device_id); | |
| 146 EntryMap::iterator it = entries_.find(controller_id); | 143 EntryMap::iterator it = entries_.find(controller_id); |
| 147 if (it != entries_.end()) { | 144 if (it != entries_.end()) { |
| 148 scoped_refptr<VideoCaptureController> controller = it->second; | 145 scoped_refptr<VideoCaptureController> controller = it->second; |
| 149 controller->StopCapture(NULL); | 146 controller->StopCapture(NULL); |
| 150 } else { | 147 } else { |
| 151 // It does not exist so it must have been stopped already. | 148 // It does not exist so it must have been stopped already. |
| 152 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id, | 149 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id, |
| 153 media::VideoCapture::kStopped)); | 150 media::VideoCapture::kStopped)); |
| 154 } | 151 } |
| 155 } | 152 } |
| 156 | 153 |
| 157 void VideoCaptureHost::OnPauseCapture(const IPC::Message& msg, int device_id) { | 154 void VideoCaptureHost::OnPauseCapture(const IPC::Message& msg, int device_id) { |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 159 // Not used. | 156 // Not used. |
| 160 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id, | 157 Send(new VideoCaptureMsg_StateChanged(msg.routing_id(), device_id, |
| 161 media::VideoCapture::kError)); | 158 media::VideoCapture::kError)); |
| 162 } | 159 } |
| 163 | 160 |
| 164 void VideoCaptureHost::OnReceiveEmptyBuffer(const IPC::Message& msg, | 161 void VideoCaptureHost::OnReceiveEmptyBuffer(const IPC::Message& msg, |
| 165 int device_id, | 162 int device_id, |
| 166 TransportDIB::Handle handle) { | 163 TransportDIB::Handle handle) { |
| 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 168 | 165 |
| 169 VideoCaptureController::ControllerId controller_id(msg.routing_id(), | 166 VideoCaptureControllerID controller_id(msg.routing_id(), device_id); |
| 170 device_id); | |
| 171 EntryMap::iterator it = entries_.find(controller_id); | 167 EntryMap::iterator it = entries_.find(controller_id); |
| 172 if (it != entries_.end()) { | 168 if (it != entries_.end()) { |
| 173 scoped_refptr<VideoCaptureController> controller = it->second; | 169 scoped_refptr<VideoCaptureController> controller = it->second; |
| 174 controller->ReturnTransportDIB(handle); | 170 controller->ReturnTransportDIB(handle); |
| 175 } | 171 } |
| 176 } | 172 } |
| 177 | 173 |
| 178 void VideoCaptureHost::DoDeleteVideoCaptureController( | 174 void VideoCaptureHost::DoDeleteVideoCaptureController( |
| 179 VideoCaptureController::ControllerId id) { | 175 const VideoCaptureControllerID& id) { |
| 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 181 | 177 |
| 182 // Report that the device have successfully been stopped. | 178 // Report that the device have successfully been stopped. |
| 183 Send(new VideoCaptureMsg_StateChanged(id.first, id.second, | 179 Send(new VideoCaptureMsg_StateChanged(id.routing_id, id.device_id, |
| 184 media::VideoCapture::kStopped)); | 180 media::VideoCapture::kStopped)); |
| 185 entries_.erase(id); | 181 entries_.erase(id); |
| 186 } | 182 } |
| OLD | NEW |