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 #ifndef CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_
6 #define CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_
8 #include "base/callback.h"
9 #include "base/id_map.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "ipc/ipc_channel_proxy.h"
12 #include "ipc/message_filter.h"
13 #include "media/cast/cast_sender.h"
14 #include "media/cast/logging/logging_defines.h"
15 #include "media/cast/net/cast_transport_sender.h"
17 class CastTransportSenderIPC
;
19 // This dispatcher listens to incoming IPC messages and sends
20 // the call to the correct CastTransportSenderIPC instance.
21 class CastIPCDispatcher
: public IPC::MessageFilter
{
23 explicit CastIPCDispatcher(
24 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_task_runner
);
26 static CastIPCDispatcher
* Get();
27 void Send(IPC::Message
* message
);
28 int32
AddSender(CastTransportSenderIPC
* sender
);
29 void RemoveSender(int32 channel_id
);
31 // IPC::MessageFilter implementation
32 bool OnMessageReceived(const IPC::Message
& message
) override
;
33 void OnFilterAdded(IPC::Sender
* sender
) override
;
34 void OnFilterRemoved() override
;
35 void OnChannelClosing() override
;
38 ~CastIPCDispatcher() override
;
41 void OnNotifyStatusChange(
43 media::cast::CastTransportStatus status
);
47 const media::cast::RtcpSenderInfo
& sender_info
,
48 base::TimeTicks time_sent
,
49 uint32 rtp_timestamp
);
50 void OnRawEvents(int32 channel_id
,
51 const std::vector
<media::cast::PacketEvent
>& packet_events
,
52 const std::vector
<media::cast::FrameEvent
>& frame_events
);
53 void OnRtt(int32 channel_id
, uint32 ssrc
, base::TimeDelta rtt
);
54 void OnRtcpCastMessage(int32 channel_id
,
56 const media::cast::RtcpCastMessage
& cast_message
);
57 void OnReceivedPacket(int32 channel_id
, const media::cast::Packet
& packet
);
59 static CastIPCDispatcher
* global_instance_
;
61 // For IPC Send(); must only be accesed on |io_message_loop_|.
64 // Task runner on which IPC calls are driven.
65 const scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner_
;
67 // A map of stream ids to delegates; must only be accessed on
68 // |io_message_loop_|.
69 IDMap
<CastTransportSenderIPC
> id_map_
;
70 DISALLOW_COPY_AND_ASSIGN(CastIPCDispatcher
);
73 #endif // CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_