Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
acolwell GONE FROM CHROMIUM
2014/02/13 19:28:58
nit: Remove "(c) ". New files are not supposed to
hubbe
2014/02/14 00:03:24
Done.
| |
| 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 "chrome/renderer/media/cast_ipc_dispatcher.h" | |
| 6 | |
| 7 #include "chrome/common/cast_messages.h" | |
| 8 #include "chrome/renderer/media/cast_transport_sender_ipc.h" | |
| 9 #include "ipc/ipc_message_macros.h" | |
| 10 | |
| 11 CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL; | |
|
acolwell GONE FROM CHROMIUM
2014/02/13 19:28:58
This global static makes me nervous. Is this how o
hubbe
2014/02/14 00:03:24
No, most filters use RenderThread::Current()->get_
acolwell GONE FROM CHROMIUM
2014/02/14 02:17:18
This response actually makes me more nervous.
not
hubbe
2014/02/14 19:34:46
I thought about it and changed it so that the glob
| |
| 12 | |
| 13 CastIPCDispatcher::CastIPCDispatcher( | |
| 14 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | |
| 15 : channel_(NULL), | |
| 16 io_message_loop_(io_message_loop) { | |
| 17 DCHECK(io_message_loop_); | |
| 18 DCHECK(!global_instance_); | |
| 19 global_instance_ = this; | |
| 20 } | |
| 21 | |
| 22 CastIPCDispatcher::~CastIPCDispatcher() { | |
| 23 global_instance_ = NULL; | |
| 24 } | |
| 25 | |
| 26 CastIPCDispatcher* CastIPCDispatcher::Get() { | |
| 27 return global_instance_; | |
| 28 } | |
| 29 | |
| 30 void CastIPCDispatcher::Send(IPC::Message* message) { | |
| 31 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 32 if (channel_) { | |
| 33 channel_->Send(message); | |
| 34 } else { | |
| 35 delete message; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 int32 CastIPCDispatcher::AddSender(CastTransportSenderIPC* sender) { | |
| 40 return id_map_.Add(sender); | |
| 41 } | |
| 42 | |
| 43 void CastIPCDispatcher::RemoveSender(int32 channel_id) { | |
| 44 return id_map_.Remove(channel_id); | |
| 45 } | |
| 46 | |
| 47 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) { | |
| 48 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 49 bool handled = true; | |
| 50 IPC_BEGIN_MESSAGE_MAP(CastIPCDispatcher, message) | |
| 51 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) | |
| 52 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) | |
| 53 IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics) | |
| 54 IPC_MESSAGE_UNHANDLED(handled = false); | |
| 55 IPC_END_MESSAGE_MAP(); | |
| 56 return handled; | |
| 57 } | |
| 58 | |
| 59 void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) { | |
| 60 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 61 channel_ = channel; | |
| 62 } | |
| 63 | |
| 64 void CastIPCDispatcher::OnFilterRemoved() { | |
| 65 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 66 channel_ = NULL; | |
| 67 } | |
| 68 | |
| 69 void CastIPCDispatcher::OnChannelClosing() { | |
| 70 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 71 channel_ = NULL; | |
| 72 } | |
| 73 | |
| 74 void CastIPCDispatcher::OnReceivedPacket( | |
| 75 int32 channel_id, | |
| 76 const media::cast::transport::Packet& packet) { | |
| 77 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
|
acolwell GONE FROM CHROMIUM
2014/02/13 19:28:58
nit: s/ptr/sender/ here and below just to make the
hubbe
2014/02/14 00:03:24
Done.
| |
| 78 if (ptr) { | |
| 79 ptr->OnReceivedPacket(packet); | |
| 80 } else { | |
| 81 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
| 82 << "on non-existing channel."; | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 void CastIPCDispatcher::OnNotifyStatusChange( | |
| 87 int32 channel_id, | |
| 88 media::cast::transport::CastTransportStatus status) { | |
| 89 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
| 90 if (ptr) { | |
| 91 ptr->OnNotifyStatusChange(status); | |
| 92 } else { | |
| 93 LOG(ERROR) | |
| 94 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void CastIPCDispatcher::OnRtpStatistics( | |
| 99 int32 channel_id, | |
| 100 bool audio, | |
| 101 const media::cast::transport::RtcpSenderInfo& sender_info, | |
| 102 base::TimeTicks time_sent, | |
| 103 uint32 rtp_timestamp) { | |
| 104 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
| 105 if (ptr) { | |
| 106 ptr->OnRtpStatistics(audio, sender_info, time_sent, rtp_timestamp); | |
| 107 } else { | |
| 108 LOG(ERROR) | |
| 109 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
| 110 } | |
| 111 } | |
| OLD | NEW |