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 if (io_message_loop_->BelongsToCurrentThread()) { | |
23 // Option 1: Last reference was freed from the IO thread, no problem. | |
24 global_instance_ = NULL; | |
25 } else { | |
26 // Option 2: Something went wrong before we got added as a filter, and | |
acolwell GONE FROM CHROMIUM
2014/02/14 20:45:20
How are we supposed to hit this case? The pointer
hubbe
2014/02/14 20:58:06
Actually, the more I think about it, the more I th
| |
27 // the last reference was freed from some other thread. | |
28 DCHECK(!global_instance_); | |
29 global_instance_ = NULL; | |
acolwell GONE FROM CHROMIUM
2014/02/14 20:45:20
This still global pointer business still feels wro
hubbe
2014/02/14 20:58:06
I can do that, but I'm not sure that solves anythi
| |
30 } | |
31 } | |
32 | |
33 CastIPCDispatcher* CastIPCDispatcher::Get() { | |
34 return global_instance_; | |
35 } | |
36 | |
37 void CastIPCDispatcher::Send(IPC::Message* message) { | |
38 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
39 if (channel_) { | |
40 channel_->Send(message); | |
41 } else { | |
42 delete message; | |
43 } | |
44 } | |
45 | |
46 int32 CastIPCDispatcher::AddSender(CastTransportSenderIPC* sender) { | |
47 return id_map_.Add(sender); | |
48 } | |
49 | |
50 void CastIPCDispatcher::RemoveSender(int32 channel_id) { | |
51 return id_map_.Remove(channel_id); | |
52 } | |
53 | |
54 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) { | |
55 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
56 bool handled = true; | |
57 IPC_BEGIN_MESSAGE_MAP(CastIPCDispatcher, message) | |
58 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) | |
59 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) | |
60 IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics) | |
61 IPC_MESSAGE_UNHANDLED(handled = false); | |
62 IPC_END_MESSAGE_MAP(); | |
63 return handled; | |
64 } | |
65 | |
66 void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) { | |
67 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
68 DCHECK(!global_instance_); | |
69 global_instance_ = this; | |
70 channel_ = channel; | |
71 } | |
72 | |
73 void CastIPCDispatcher::OnFilterRemoved() { | |
74 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
75 DCHECK_EQ(this, global_instance_); | |
76 global_instance_ = NULL; | |
77 channel_ = NULL; | |
78 } | |
79 | |
80 void CastIPCDispatcher::OnChannelClosing() { | |
81 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
82 DCHECK_EQ(this, global_instance_); | |
83 channel_ = NULL; | |
84 } | |
85 | |
86 void CastIPCDispatcher::OnReceivedPacket( | |
87 int32 channel_id, | |
88 const media::cast::transport::Packet& packet) { | |
89 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
90 if (sender) { | |
91 sender->OnReceivedPacket(packet); | |
92 } else { | |
93 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
94 << "on non-existing channel."; | |
95 } | |
96 } | |
97 | |
98 void CastIPCDispatcher::OnNotifyStatusChange( | |
99 int32 channel_id, | |
100 media::cast::transport::CastTransportStatus status) { | |
101 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
102 if (sender) { | |
103 sender->OnNotifyStatusChange(status); | |
104 } else { | |
105 LOG(ERROR) | |
106 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
107 } | |
108 } | |
109 | |
110 void CastIPCDispatcher::OnRtpStatistics( | |
111 int32 channel_id, | |
112 bool audio, | |
113 const media::cast::transport::RtcpSenderInfo& sender_info, | |
114 base::TimeTicks time_sent, | |
115 uint32 rtp_timestamp) { | |
116 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id); | |
117 if (sender) { | |
118 sender->OnRtpStatistics(audio, sender_info, time_sent, rtp_timestamp); | |
119 } else { | |
120 LOG(ERROR) | |
121 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
122 } | |
123 } | |
OLD | NEW |