OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "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; | |
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 } | |
20 | |
21 CastIPCDispatcher::~CastIPCDispatcher() { | |
22 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
23 global_instance_ = NULL; | |
acolwell GONE FROM CHROMIUM
2014/02/14 23:09:28
nit: I believe you should be able to change this t
hubbe
2014/02/14 23:13:10
Done.
hubbe
2014/02/14 23:39:57
Actually, that seems to be not true, at least in m
| |
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 DCHECK(!global_instance_); | |
62 global_instance_ = this; | |
63 channel_ = channel; | |
64 } | |
65 | |
66 void CastIPCDispatcher::OnFilterRemoved() { | |
67 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
68 DCHECK_EQ(this, global_instance_); | |
69 global_instance_ = NULL; | |
70 channel_ = NULL; | |
71 } | |
72 | |
73 void CastIPCDispatcher::OnChannelClosing() { | |
74 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
75 DCHECK_EQ(this, global_instance_); | |
76 channel_ = NULL; | |
77 } | |
78 | |
79 void CastIPCDispatcher::OnReceivedPacket( | |
80 int32 channel_id, | |
81 const media::cast::transport::Packet& packet) { | |
82 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
83 if (sender) { | |
84 sender->OnReceivedPacket(packet); | |
85 } else { | |
86 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
87 << "on non-existing channel."; | |
88 } | |
89 } | |
90 | |
91 void CastIPCDispatcher::OnNotifyStatusChange( | |
92 int32 channel_id, | |
93 media::cast::transport::CastTransportStatus status) { | |
94 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
95 if (sender) { | |
96 sender->OnNotifyStatusChange(status); | |
97 } else { | |
98 LOG(ERROR) | |
99 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
100 } | |
101 } | |
102 | |
103 void CastIPCDispatcher::OnRtpStatistics( | |
104 int32 channel_id, | |
105 bool audio, | |
106 const media::cast::transport::RtcpSenderInfo& sender_info, | |
107 base::TimeTicks time_sent, | |
108 uint32 rtp_timestamp) { | |
109 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
110 if (sender) { | |
111 sender->OnRtpStatistics(audio, sender_info, time_sent, rtp_timestamp); | |
112 } else { | |
113 LOG(ERROR) | |
114 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
115 } | |
116 } | |
OLD | NEW |