Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/renderer/media/cast_ipc_dispatcher.cc

Issue 138753004: Cast: IPC glue between cast library transport and encoders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/media/cast_ipc_dispatcher.h ('k') | chrome/renderer/media/cast_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 DCHECK(io_message_loop_->BelongsToCurrentThread());
23 // Unfortunately, you do not always get a OnFilterRemoved call.
24 global_instance_ = NULL;
25 }
26
27 CastIPCDispatcher* CastIPCDispatcher::Get() {
28 return global_instance_;
29 }
30
31 void CastIPCDispatcher::Send(IPC::Message* message) {
32 DCHECK(io_message_loop_->BelongsToCurrentThread());
33 if (channel_) {
34 channel_->Send(message);
35 } else {
36 delete message;
37 }
38 }
39
40 int32 CastIPCDispatcher::AddSender(CastTransportSenderIPC* sender) {
41 return id_map_.Add(sender);
42 }
43
44 void CastIPCDispatcher::RemoveSender(int32 channel_id) {
45 return id_map_.Remove(channel_id);
46 }
47
48 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) {
49 DCHECK(io_message_loop_->BelongsToCurrentThread());
50 bool handled = true;
51 IPC_BEGIN_MESSAGE_MAP(CastIPCDispatcher, message)
52 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket)
53 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange)
54 IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics)
55 IPC_MESSAGE_UNHANDLED(handled = false);
56 IPC_END_MESSAGE_MAP();
57 return handled;
58 }
59
60 void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) {
61 DCHECK(io_message_loop_->BelongsToCurrentThread());
62 DCHECK(!global_instance_);
63 global_instance_ = this;
64 channel_ = channel;
65 }
66
67 void CastIPCDispatcher::OnFilterRemoved() {
68 DCHECK(io_message_loop_->BelongsToCurrentThread());
69 DCHECK_EQ(this, global_instance_);
70 global_instance_ = NULL;
71 channel_ = NULL;
72 }
73
74 void CastIPCDispatcher::OnChannelClosing() {
75 DCHECK(io_message_loop_->BelongsToCurrentThread());
76 DCHECK_EQ(this, global_instance_);
77 channel_ = NULL;
78 }
79
80 void CastIPCDispatcher::OnReceivedPacket(
81 int32 channel_id,
82 const media::cast::transport::Packet& packet) {
83 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
84 if (sender) {
85 sender->OnReceivedPacket(packet);
86 } else {
87 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket "
88 << "on non-existing channel.";
89 }
90 }
91
92 void CastIPCDispatcher::OnNotifyStatusChange(
93 int32 channel_id,
94 media::cast::transport::CastTransportStatus status) {
95 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
96 if (sender) {
97 sender->OnNotifyStatusChange(status);
98 } else {
99 LOG(ERROR)
100 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
101 }
102 }
103
104 void CastIPCDispatcher::OnRtpStatistics(
105 int32 channel_id,
106 bool audio,
107 const media::cast::transport::RtcpSenderInfo& sender_info,
108 base::TimeTicks time_sent,
109 uint32 rtp_timestamp) {
110 CastTransportSenderIPC* sender = id_map_.Lookup(channel_id);
111 if (sender) {
112 sender->OnRtpStatistics(audio, sender_info, time_sent, rtp_timestamp);
113 } else {
114 LOG(ERROR)
115 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel.";
116 }
117 }
OLDNEW
« no previous file with comments | « chrome/renderer/media/cast_ipc_dispatcher.h ('k') | chrome/renderer/media/cast_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698