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.
5 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
7 #include "chrome/common/cast_messages.h"
8 #include "chrome/renderer/media/cast_transport_sender_ipc.h"
9 #include "ipc/ipc_message_macros.h"
11 CastIPCDispatcher
* CastIPCDispatcher::global_instance_
= NULL
;
13 CastIPCDispatcher::CastIPCDispatcher(
14 const scoped_refptr
<base::MessageLoopProxy
>& io_message_loop
)
16 io_message_loop_(io_message_loop
) {
17 DCHECK(io_message_loop_
.get());
18 DCHECK(!global_instance_
);
21 CastIPCDispatcher::~CastIPCDispatcher() {
22 DCHECK(io_message_loop_
->BelongsToCurrentThread());
23 DCHECK(!global_instance_
);
26 CastIPCDispatcher
* CastIPCDispatcher::Get() {
27 return global_instance_
;
30 void CastIPCDispatcher::Send(IPC::Message
* message
) {
31 DCHECK(io_message_loop_
->BelongsToCurrentThread());
33 sender_
->Send(message
);
39 int32
CastIPCDispatcher::AddSender(CastTransportSenderIPC
* sender
) {
40 return id_map_
.Add(sender
);
43 void CastIPCDispatcher::RemoveSender(int32 channel_id
) {
44 return id_map_
.Remove(channel_id
);
47 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message
& message
) {
48 DCHECK(io_message_loop_
->BelongsToCurrentThread());
50 IPC_BEGIN_MESSAGE_MAP(CastIPCDispatcher
, message
)
51 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange
, OnNotifyStatusChange
)
52 IPC_MESSAGE_HANDLER(CastMsg_RawEvents
, OnRawEvents
)
53 IPC_MESSAGE_HANDLER(CastMsg_Rtt
, OnRtt
)
54 IPC_MESSAGE_HANDLER(CastMsg_RtcpCastMessage
, OnRtcpCastMessage
)
55 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket
, OnReceivedPacket
)
56 IPC_MESSAGE_UNHANDLED(handled
= false);
57 IPC_END_MESSAGE_MAP();
61 void CastIPCDispatcher::OnFilterAdded(IPC::Sender
* sender
) {
62 DCHECK(io_message_loop_
->BelongsToCurrentThread());
63 DCHECK(!global_instance_
);
64 global_instance_
= this;
68 void CastIPCDispatcher::OnFilterRemoved() {
69 DCHECK(io_message_loop_
->BelongsToCurrentThread());
70 DCHECK_EQ(this, global_instance_
);
71 global_instance_
= NULL
;
75 void CastIPCDispatcher::OnChannelClosing() {
76 DCHECK(io_message_loop_
->BelongsToCurrentThread());
77 DCHECK_EQ(this, global_instance_
);
80 void CastIPCDispatcher::OnNotifyStatusChange(
82 media::cast::CastTransportStatus status
) {
83 CastTransportSenderIPC
* sender
= id_map_
.Lookup(channel_id
);
85 sender
->OnNotifyStatusChange(status
);
88 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
92 void CastIPCDispatcher::OnRawEvents(
94 const std::vector
<media::cast::PacketEvent
>& packet_events
,
95 const std::vector
<media::cast::FrameEvent
>& frame_events
) {
96 CastTransportSenderIPC
* sender
= id_map_
.Lookup(channel_id
);
98 sender
->OnRawEvents(packet_events
, frame_events
);
100 DVLOG(1) << "CastIPCDispatcher::OnRawEvents on non-existing channel.";
104 void CastIPCDispatcher::OnRtt(int32 channel_id
,
106 base::TimeDelta rtt
) {
107 CastTransportSenderIPC
* sender
= id_map_
.Lookup(channel_id
);
109 sender
->OnRtt(ssrc
, rtt
);
111 DVLOG(1) << "CastIPCDispatcher::OnRtt on non-existing channel.";
115 void CastIPCDispatcher::OnRtcpCastMessage(
118 const media::cast::RtcpCastMessage
& cast_message
) {
119 CastTransportSenderIPC
* sender
= id_map_
.Lookup(channel_id
);
121 sender
->OnRtcpCastMessage(ssrc
, cast_message
);
123 DVLOG(1) << "CastIPCDispatcher::OnRtt on non-existing channel.";
127 void CastIPCDispatcher::OnReceivedPacket(
129 const media::cast::Packet
& packet
) {
130 CastTransportSenderIPC
* sender
= id_map_
.Lookup(channel_id
);
132 sender
->OnReceivedPacket(packet
);
134 DVLOG(1) << "CastIPCDispatcher::OnReceievdPacket on non-existing channel.";