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#ifndef CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_ 6#define CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_ 7 8#include "base/callback.h" 9#include "base/id_map.h" 10#include "ipc/ipc_channel_proxy.h" 11#include "ipc/message_filter.h" 12#include "media/cast/cast_sender.h" 13#include "media/cast/logging/logging_defines.h" 14#include "media/cast/net/cast_transport_sender.h" 15 16class CastTransportSenderIPC; 17 18// This dispatcher listens to incoming IPC messages and sends 19// the call to the correct CastTransportSenderIPC instance. 20class CastIPCDispatcher : public IPC::MessageFilter { 21 public: 22 explicit CastIPCDispatcher( 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); 24 25 static CastIPCDispatcher* Get(); 26 void Send(IPC::Message* message); 27 int32 AddSender(CastTransportSenderIPC* sender); 28 void RemoveSender(int32 channel_id); 29 30 // IPC::MessageFilter implementation 31 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 32 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE; 33 virtual void OnFilterRemoved() OVERRIDE; 34 virtual void OnChannelClosing() OVERRIDE; 35 36 protected: 37 virtual ~CastIPCDispatcher(); 38 39 private: 40 void OnNotifyStatusChange( 41 int32 channel_id, 42 media::cast::CastTransportStatus status); 43 void OnRtpStatistics( 44 int32 channel_id, 45 bool audio, 46 const media::cast::RtcpSenderInfo& sender_info, 47 base::TimeTicks time_sent, 48 uint32 rtp_timestamp); 49 void OnRawEvents(int32 channel_id, 50 const std::vector<media::cast::PacketEvent>& packet_events, 51 const std::vector<media::cast::FrameEvent>& frame_events); 52 void OnRtt(int32 channel_id, uint32 ssrc, base::TimeDelta rtt); 53 void OnRtcpCastMessage(int32 channel_id, 54 uint32 ssrc, 55 const media::cast::RtcpCastMessage& cast_message); 56 57 static CastIPCDispatcher* global_instance_; 58 59 // For IPC Send(); must only be accesed on |io_message_loop_|. 60 IPC::Sender* sender_; 61 62 // Message loop on which IPC calls are driven. 63 const scoped_refptr<base::MessageLoopProxy> io_message_loop_; 64 65 // A map of stream ids to delegates; must only be accessed on 66 // |io_message_loop_|. 67 IDMap<CastTransportSenderIPC> id_map_; 68 DISALLOW_COPY_AND_ASSIGN(CastIPCDispatcher); 69}; 70 71#endif // CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_ 72