summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/media/cast_ipc_dispatcher.h
blob: 6dcbf0a0c53318b43bf5f3f812664e609c143e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_
#define CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_

#include "base/callback.h"
#include "base/id_map.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/message_filter.h"
#include "media/cast/cast_sender.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/net/cast_transport_sender.h"

class CastTransportSenderIPC;

// This dispatcher listens to incoming IPC messages and sends
// the call to the correct CastTransportSenderIPC instance.
class CastIPCDispatcher : public IPC::MessageFilter {
 public:
  explicit CastIPCDispatcher(
      const scoped_refptr<base::MessageLoopProxy>& io_message_loop);

  static CastIPCDispatcher* Get();
  void Send(IPC::Message* message);
  int32 AddSender(CastTransportSenderIPC* sender);
  void RemoveSender(int32 channel_id);

  // IPC::MessageFilter implementation
  virtual bool OnMessageReceived(const IPC::Message& message) override;
  virtual void OnFilterAdded(IPC::Sender* sender) override;
  virtual void OnFilterRemoved() override;
  virtual void OnChannelClosing() override;

 protected:
  virtual ~CastIPCDispatcher();

 private:
  void OnNotifyStatusChange(
      int32 channel_id,
      media::cast::CastTransportStatus status);
  void OnRtpStatistics(
      int32 channel_id,
      bool audio,
      const media::cast::RtcpSenderInfo& sender_info,
      base::TimeTicks time_sent,
      uint32 rtp_timestamp);
  void OnRawEvents(int32 channel_id,
                   const std::vector<media::cast::PacketEvent>& packet_events,
                   const std::vector<media::cast::FrameEvent>& frame_events);
  void OnRtt(int32 channel_id, uint32 ssrc, base::TimeDelta rtt);
  void OnRtcpCastMessage(int32 channel_id,
                         uint32 ssrc,
                         const media::cast::RtcpCastMessage& cast_message);

  static CastIPCDispatcher* global_instance_;

  // For IPC Send(); must only be accesed on |io_message_loop_|.
  IPC::Sender* sender_;

  // Message loop on which IPC calls are driven.
  const scoped_refptr<base::MessageLoopProxy> io_message_loop_;

  // A map of stream ids to delegates; must only be accessed on
  // |io_message_loop_|.
  IDMap<CastTransportSenderIPC> id_map_;
  DISALLOW_COPY_AND_ASSIGN(CastIPCDispatcher);
};

#endif  // CHROME_RENDERER_MEDIA_CAST_IPC_DISPATCHER_H_