| 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/renderer/media/video_capture_message_filter.h" | 5 #include "content/renderer/media/video_capture_message_filter.h" |
| 6 | 6 |
| 7 #include "content/common/media/video_capture_messages.h" | 7 #include "content/common/media/video_capture_messages.h" |
| 8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
| 9 #include "ipc/ipc_channel.h" | 9 #include "ipc/ipc_sender.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 VideoCaptureMessageFilter::VideoCaptureMessageFilter() | 13 VideoCaptureMessageFilter::VideoCaptureMessageFilter() |
| 14 : last_device_id_(0), | 14 : last_device_id_(0), |
| 15 channel_(NULL) { | 15 sender_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) { | 18 void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) { |
| 19 if (++last_device_id_ <= 0) | 19 if (++last_device_id_ <= 0) |
| 20 last_device_id_ = 1; | 20 last_device_id_ = 1; |
| 21 while (delegates_.find(last_device_id_) != delegates_.end()) | 21 while (delegates_.find(last_device_id_) != delegates_.end()) |
| 22 last_device_id_++; | 22 last_device_id_++; |
| 23 | 23 |
| 24 if (channel_) { | 24 if (sender_) { |
| 25 delegates_[last_device_id_] = delegate; | 25 delegates_[last_device_id_] = delegate; |
| 26 delegate->OnDelegateAdded(last_device_id_); | 26 delegate->OnDelegateAdded(last_device_id_); |
| 27 } else { | 27 } else { |
| 28 pending_delegates_[last_device_id_] = delegate; | 28 pending_delegates_[last_device_id_] = delegate; |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { | 32 void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { |
| 33 for (Delegates::iterator it = delegates_.begin(); | 33 for (Delegates::iterator it = delegates_.begin(); |
| 34 it != delegates_.end(); it++) { | 34 it != delegates_.end(); it++) { |
| 35 if (it->second == delegate) { | 35 if (it->second == delegate) { |
| 36 delegates_.erase(it); | 36 delegates_.erase(it); |
| 37 break; | 37 break; |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 for (Delegates::iterator it = pending_delegates_.begin(); | 40 for (Delegates::iterator it = pending_delegates_.begin(); |
| 41 it != pending_delegates_.end(); it++) { | 41 it != pending_delegates_.end(); it++) { |
| 42 if (it->second == delegate) { | 42 if (it->second == delegate) { |
| 43 pending_delegates_.erase(it); | 43 pending_delegates_.erase(it); |
| 44 break; | 44 break; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool VideoCaptureMessageFilter::Send(IPC::Message* message) { | 49 bool VideoCaptureMessageFilter::Send(IPC::Message* message) { |
| 50 if (!channel_) { | 50 if (!sender_) { |
| 51 delete message; | 51 delete message; |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 | 54 |
| 55 return channel_->Send(message); | 55 return sender_->Send(message); |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool VideoCaptureMessageFilter::OnMessageReceived(const IPC::Message& message) { | 58 bool VideoCaptureMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| 59 bool handled = true; | 59 bool handled = true; |
| 60 IPC_BEGIN_MESSAGE_MAP(VideoCaptureMessageFilter, message) | 60 IPC_BEGIN_MESSAGE_MAP(VideoCaptureMessageFilter, message) |
| 61 IPC_MESSAGE_HANDLER(VideoCaptureMsg_BufferReady, OnBufferReceived) | 61 IPC_MESSAGE_HANDLER(VideoCaptureMsg_BufferReady, OnBufferReceived) |
| 62 IPC_MESSAGE_HANDLER(VideoCaptureMsg_MailboxBufferReady, | 62 IPC_MESSAGE_HANDLER(VideoCaptureMsg_MailboxBufferReady, |
| 63 OnMailboxBufferReceived) | 63 OnMailboxBufferReceived) |
| 64 IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnDeviceStateChanged) | 64 IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnDeviceStateChanged) |
| 65 IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnBufferCreated) | 65 IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnBufferCreated) |
| 66 IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferDestroyed) | 66 IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferDestroyed) |
| 67 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceSupportedFormatsEnumerated, | 67 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceSupportedFormatsEnumerated, |
| 68 OnDeviceSupportedFormatsEnumerated) | 68 OnDeviceSupportedFormatsEnumerated) |
| 69 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceFormatsInUseReceived, | 69 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceFormatsInUseReceived, |
| 70 OnDeviceFormatsInUseReceived) | 70 OnDeviceFormatsInUseReceived) |
| 71 IPC_MESSAGE_UNHANDLED(handled = false) | 71 IPC_MESSAGE_UNHANDLED(handled = false) |
| 72 IPC_END_MESSAGE_MAP() | 72 IPC_END_MESSAGE_MAP() |
| 73 return handled; | 73 return handled; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void VideoCaptureMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 76 void VideoCaptureMessageFilter::OnFilterAdded(IPC::Sender* sender) { |
| 77 DVLOG(1) << "VideoCaptureMessageFilter::OnFilterAdded()"; | 77 DVLOG(1) << "VideoCaptureMessageFilter::OnFilterAdded()"; |
| 78 channel_ = channel; | 78 sender_ = sender; |
| 79 | 79 |
| 80 for (Delegates::iterator it = pending_delegates_.begin(); | 80 for (Delegates::iterator it = pending_delegates_.begin(); |
| 81 it != pending_delegates_.end(); it++) { | 81 it != pending_delegates_.end(); it++) { |
| 82 it->second->OnDelegateAdded(it->first); | 82 it->second->OnDelegateAdded(it->first); |
| 83 delegates_[it->first] = it->second; | 83 delegates_[it->first] = it->second; |
| 84 } | 84 } |
| 85 pending_delegates_.clear(); | 85 pending_delegates_.clear(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void VideoCaptureMessageFilter::OnFilterRemoved() { | 88 void VideoCaptureMessageFilter::OnFilterRemoved() { |
| 89 channel_ = NULL; | 89 sender_ = NULL; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void VideoCaptureMessageFilter::OnChannelClosing() { | 92 void VideoCaptureMessageFilter::OnChannelClosing() { |
| 93 channel_ = NULL; | 93 sender_ = NULL; |
| 94 } | 94 } |
| 95 | 95 |
| 96 VideoCaptureMessageFilter::~VideoCaptureMessageFilter() {} | 96 VideoCaptureMessageFilter::~VideoCaptureMessageFilter() {} |
| 97 | 97 |
| 98 VideoCaptureMessageFilter::Delegate* VideoCaptureMessageFilter::find_delegate( | 98 VideoCaptureMessageFilter::Delegate* VideoCaptureMessageFilter::find_delegate( |
| 99 int device_id) const { | 99 int device_id) const { |
| 100 Delegates::const_iterator i = delegates_.find(device_id); | 100 Delegates::const_iterator i = delegates_.find(device_id); |
| 101 return i != delegates_.end() ? i->second : NULL; | 101 return i != delegates_.end() ? i->second : NULL; |
| 102 } | 102 } |
| 103 | 103 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 const media::VideoCaptureFormats& formats_in_use) { | 206 const media::VideoCaptureFormats& formats_in_use) { |
| 207 Delegate* delegate = find_delegate(device_id); | 207 Delegate* delegate = find_delegate(device_id); |
| 208 if (!delegate) { | 208 if (!delegate) { |
| 209 DLOG(WARNING) << "OnDeviceFormatInUse: unknown device"; | 209 DLOG(WARNING) << "OnDeviceFormatInUse: unknown device"; |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 delegate->OnDeviceFormatsInUseReceived(formats_in_use); | 212 delegate->OnDeviceFormatsInUseReceived(formats_in_use); |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace content | 215 } // namespace content |
| OLD | NEW |