| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
| 10 #include "content/browser/renderer_host/media/media_stream_manager.h" | 11 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 11 #include "content/browser/renderer_host/media/video_capture_manager.h" | 12 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 12 #include "content/common/media/video_capture_messages.h" | 13 #include "content/common/media/video_capture_messages.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 17 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
| 17 : BrowserMessageFilter(VideoCaptureMsgStart), | 18 : BrowserMessageFilter(VideoCaptureMsgStart), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int buffer_id) { | 70 int buffer_id) { |
| 70 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
| 71 BrowserThread::IO, FROM_HERE, | 72 BrowserThread::IO, FROM_HERE, |
| 72 base::Bind(&VideoCaptureHost::DoSendFreeBufferOnIOThread, | 73 base::Bind(&VideoCaptureHost::DoSendFreeBufferOnIOThread, |
| 73 this, controller_id, buffer_id)); | 74 this, controller_id, buffer_id)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void VideoCaptureHost::OnBufferReady( | 77 void VideoCaptureHost::OnBufferReady( |
| 77 const VideoCaptureControllerID& controller_id, | 78 const VideoCaptureControllerID& controller_id, |
| 78 int buffer_id, | 79 int buffer_id, |
| 79 const media::VideoCaptureFormat& frame_format, | 80 const gfx::Size& coded_size, |
| 80 const gfx::Rect& visible_rect, | 81 const gfx::Rect& visible_rect, |
| 81 base::TimeTicks timestamp) { | 82 base::TimeTicks timestamp, |
| 83 scoped_ptr<base::DictionaryValue> metadata) { |
| 82 BrowserThread::PostTask( | 84 BrowserThread::PostTask( |
| 83 BrowserThread::IO, | 85 BrowserThread::IO, |
| 84 FROM_HERE, | 86 FROM_HERE, |
| 85 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, | 87 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, |
| 86 this, | 88 this, |
| 87 controller_id, | 89 controller_id, |
| 88 buffer_id, | 90 buffer_id, |
| 89 frame_format, | 91 coded_size, |
| 90 visible_rect, | 92 visible_rect, |
| 91 timestamp)); | 93 timestamp, |
| 94 base::Passed(&metadata))); |
| 92 } | 95 } |
| 93 | 96 |
| 94 void VideoCaptureHost::OnMailboxBufferReady( | 97 void VideoCaptureHost::OnMailboxBufferReady( |
| 95 const VideoCaptureControllerID& controller_id, | 98 const VideoCaptureControllerID& controller_id, |
| 96 int buffer_id, | 99 int buffer_id, |
| 97 const gpu::MailboxHolder& mailbox_holder, | 100 const gpu::MailboxHolder& mailbox_holder, |
| 98 const media::VideoCaptureFormat& frame_format, | 101 const gfx::Size& packed_frame_size, |
| 99 base::TimeTicks timestamp) { | 102 base::TimeTicks timestamp, |
| 103 scoped_ptr<base::DictionaryValue> metadata) { |
| 100 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 101 BrowserThread::IO, | 105 BrowserThread::IO, |
| 102 FROM_HERE, | 106 FROM_HERE, |
| 103 base::Bind(&VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread, | 107 base::Bind(&VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread, |
| 104 this, | 108 this, |
| 105 controller_id, | 109 controller_id, |
| 106 buffer_id, | 110 buffer_id, |
| 107 mailbox_holder, | 111 mailbox_holder, |
| 108 frame_format, | 112 packed_frame_size, |
| 109 timestamp)); | 113 timestamp, |
| 114 base::Passed(&metadata))); |
| 110 } | 115 } |
| 111 | 116 |
| 112 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { | 117 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { |
| 113 DVLOG(1) << "VideoCaptureHost::OnEnded"; | 118 DVLOG(1) << "VideoCaptureHost::OnEnded"; |
| 114 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| 115 BrowserThread::IO, FROM_HERE, | 120 BrowserThread::IO, FROM_HERE, |
| 116 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); | 121 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void VideoCaptureHost::DoSendNewBufferOnIOThread( | 124 void VideoCaptureHost::DoSendNewBufferOnIOThread( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 137 | 142 |
| 138 if (entries_.find(controller_id) == entries_.end()) | 143 if (entries_.find(controller_id) == entries_.end()) |
| 139 return; | 144 return; |
| 140 | 145 |
| 141 Send(new VideoCaptureMsg_FreeBuffer(controller_id.device_id, buffer_id)); | 146 Send(new VideoCaptureMsg_FreeBuffer(controller_id.device_id, buffer_id)); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void VideoCaptureHost::DoSendFilledBufferOnIOThread( | 149 void VideoCaptureHost::DoSendFilledBufferOnIOThread( |
| 145 const VideoCaptureControllerID& controller_id, | 150 const VideoCaptureControllerID& controller_id, |
| 146 int buffer_id, | 151 int buffer_id, |
| 147 const media::VideoCaptureFormat& format, | 152 const gfx::Size& coded_size, |
| 148 const gfx::Rect& visible_rect, | 153 const gfx::Rect& visible_rect, |
| 149 base::TimeTicks timestamp) { | 154 base::TimeTicks timestamp, |
| 155 scoped_ptr<base::DictionaryValue> metadata) { |
| 150 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 151 | 157 |
| 152 if (entries_.find(controller_id) == entries_.end()) | 158 if (entries_.find(controller_id) == entries_.end()) |
| 153 return; | 159 return; |
| 154 | 160 |
| 155 Send(new VideoCaptureMsg_BufferReady( | 161 VideoCaptureMsg_BufferReady_Params params; |
| 156 controller_id.device_id, buffer_id, format, visible_rect, timestamp)); | 162 params.device_id = controller_id.device_id; |
| 163 params.buffer_id = buffer_id; |
| 164 params.coded_size = coded_size; |
| 165 params.visible_rect = visible_rect; |
| 166 params.timestamp = timestamp; |
| 167 if (metadata) |
| 168 params.metadata.Swap(metadata.get()); |
| 169 Send(new VideoCaptureMsg_BufferReady(params)); |
| 157 } | 170 } |
| 158 | 171 |
| 159 void VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread( | 172 void VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread( |
| 160 const VideoCaptureControllerID& controller_id, | 173 const VideoCaptureControllerID& controller_id, |
| 161 int buffer_id, | 174 int buffer_id, |
| 162 const gpu::MailboxHolder& mailbox_holder, | 175 const gpu::MailboxHolder& mailbox_holder, |
| 163 const media::VideoCaptureFormat& format, | 176 const gfx::Size& packed_frame_size, |
| 164 base::TimeTicks timestamp) { | 177 base::TimeTicks timestamp, |
| 178 scoped_ptr<base::DictionaryValue> metadata) { |
| 165 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 179 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 166 | 180 |
| 167 if (entries_.find(controller_id) == entries_.end()) | 181 if (entries_.find(controller_id) == entries_.end()) |
| 168 return; | 182 return; |
| 169 | 183 |
| 170 Send(new VideoCaptureMsg_MailboxBufferReady( | 184 VideoCaptureMsg_MailboxBufferReady_Params params; |
| 171 controller_id.device_id, buffer_id, mailbox_holder, format, timestamp)); | 185 params.device_id = controller_id.device_id; |
| 186 params.buffer_id = buffer_id; |
| 187 params.mailbox_holder = mailbox_holder; |
| 188 params.packed_frame_size = packed_frame_size; |
| 189 params.timestamp = timestamp; |
| 190 if (metadata) |
| 191 params.metadata.Swap(metadata.get()); |
| 192 Send(new VideoCaptureMsg_MailboxBufferReady(params)); |
| 172 } | 193 } |
| 173 | 194 |
| 174 void VideoCaptureHost::DoHandleErrorOnIOThread( | 195 void VideoCaptureHost::DoHandleErrorOnIOThread( |
| 175 const VideoCaptureControllerID& controller_id) { | 196 const VideoCaptureControllerID& controller_id) { |
| 176 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 197 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 177 | 198 |
| 178 if (entries_.find(controller_id) == entries_.end()) | 199 if (entries_.find(controller_id) == entries_.end()) |
| 179 return; | 200 return; |
| 180 | 201 |
| 181 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 202 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 return; | 404 return; |
| 384 | 405 |
| 385 if (it->second) { | 406 if (it->second) { |
| 386 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 407 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 387 it->second.get(), controller_id, this, on_error); | 408 it->second.get(), controller_id, this, on_error); |
| 388 } | 409 } |
| 389 entries_.erase(it); | 410 entries_.erase(it); |
| 390 } | 411 } |
| 391 | 412 |
| 392 } // namespace content | 413 } // namespace content |
| OLD | NEW |