OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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_transport_sender_ipc.h" | |
6 | |
7 namespace cast { | |
8 | |
9 CastIPCDispatcher* CastIPCDispatcher::global_instance_ = NULL; | |
10 | |
11 CastIPCDispatcher::CastIPCDispatcher( | |
12 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | |
13 : channel_(NULL), | |
14 io_message_loop_(io_message_loop) { | |
15 DCHECK(!global_instance_); | |
16 global_instance_ = this; | |
17 } | |
18 | |
19 CastIPCDispatcher::~CastIPCDispatcher() { | |
20 global_instance_ = NULL; | |
21 } | |
22 | |
23 bool CastIPCDispatcher::OnMessageReceived(const IPC::Message& message) { | |
24 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
25 bool handled = true; | |
26 bool msg_is_good = true; | |
27 IPC_BEGIN_MESSAGE_MAP_EX(CastIPCDispatcher, message, msg_is_good) | |
28 IPC_MESSAGE_HANDLER(CastMsg_ReceivedPacket, OnReceivedPacket) | |
29 IPC_MESSAGE_HANDLER(CastMsg_NotifyStatusChange, OnNotifyStatusChange) | |
30 IPC_MESSAGE_HANDLER(CastMsg_RtpStatistics, OnRtpStatistics) | |
31 IPC_MESSAGE_UNHANDLED(handled = false); | |
32 IPC_END_MESSAGE_MAP_EX(); | |
33 if (!msg_is_good) { | |
34 LOG(ERROR) << "Failed to parse incoming message."; | |
scherkus (not reviewing)
2014/02/07 00:11:06
avoid LOG(ERROR)
heck, there's nothing you can re
hubbe
2014/02/07 00:52:22
That's what I get for following documentation I gu
| |
35 } | |
36 return handled; | |
37 } | |
38 | |
39 void CastIPCDispatcher::OnFilterAdded(IPC::Channel* channel) { | |
40 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
41 channel_ = channel; | |
42 } | |
43 | |
44 void CastIPCDispatcher::OnFilterRemoved() { | |
45 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
46 channel_ = NULL; | |
47 } | |
48 | |
49 void CastIPCDispatcher::OnChannelClosing() { | |
50 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
51 channel_ = NULL; | |
52 } | |
53 | |
54 | |
scherkus (not reviewing)
2014/02/07 00:11:06
remove extra bit o' whitespace
hubbe
2014/02/07 00:52:22
Done.
| |
55 void CastIPCDispatcher::OnReceivedPacket( | |
56 int32 channel_id, | |
57 const media::cast::transport::Packet& packet) { | |
58 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
59 if (ptr) { | |
60 if (!ptr->packet_callback_.is_null()) { | |
61 // TODO(hubbe): Perhaps an non-ownership-transferring cb would be better? | |
62 scoped_ptr<media::cast::transport::Packet> packet_copy( | |
63 new media::cast::transport::Packet(packet)); | |
64 ptr->packet_callback_.Run(packet_copy.Pass()); | |
65 } else { | |
66 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
67 << "no packet callback yet."; | |
68 } | |
69 } else { | |
70 LOG(ERROR) << "CastIPCDispatcher::OnReceivedPacket " | |
71 << "on non-existing channel."; | |
72 } | |
73 } | |
74 | |
75 void CastIPCDispatcher::OnNotifyStatusChange( | |
76 int32 channel_id, | |
77 media::cast::transport::CastTransportStatus status) { | |
78 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
79 if (ptr) { | |
80 ptr->status_callback_.Run(status); | |
81 } else { | |
82 LOG(ERROR) | |
83 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
84 } | |
85 } | |
86 | |
87 void CastIPCDispatcher::OnRtpStatistics( | |
88 int32 channel_id, | |
89 bool audio, | |
90 const media::cast::transport::RtcpSenderInfo& sender_info, | |
91 base::TimeTicks time_sent, | |
92 uint32 rtp_timestamp) { | |
93 CastTransportSenderIPC* ptr = id_map_.Lookup(channel_id); | |
94 if (ptr) { | |
95 const media::cast::transport::CastTransportRtpStatistics& callback = | |
96 audio ? ptr->audio_rtp_callback_ : ptr->video_rtp_callback_; | |
97 callback.Run(sender_info, time_sent, rtp_timestamp); | |
98 } else { | |
99 LOG(ERROR) | |
100 << "CastIPCDispatcher::OnNotifystatusChange on non-existing channel."; | |
101 } | |
102 } | |
103 | |
104 CastTransportSenderIPC::CastTransportSenderIPC( | |
105 const media::cast::transport::CastTransportConfig& config, | |
106 const media::cast::transport::CastTransportStatusCallback& status_cb) | |
107 : status_callback_(status_cb) { | |
108 channel_id_ = CastIPCDispatcher::global_instance_->id_map_.Add(this); | |
109 Send(new CastHostMsg_New(channel_id_, config)); | |
110 } | |
111 | |
112 CastTransportSenderIPC::~CastTransportSenderIPC() { | |
113 Send(new CastHostMsg_Delete(channel_id_)); | |
114 if (CastIPCDispatcher::global_instance_) { | |
115 CastIPCDispatcher::global_instance_->id_map_.Remove(channel_id_); | |
scherkus (not reviewing)
2014/02/07 00:11:06
over indented
hubbe
2014/02/07 00:52:22
Done.
| |
116 } | |
117 } | |
118 | |
119 bool CastTransportSenderIPC::Send(IPC::Message *message) { | |
scherkus (not reviewing)
2014/02/07 00:11:06
this method is bool, yet you ignore the result eve
hubbe
2014/02/07 00:52:22
Making it void.
| |
120 if (CastIPCDispatcher::global_instance_ && | |
121 CastIPCDispatcher::global_instance_->channel_) { | |
122 DCHECK(CastIPCDispatcher::global_instance_->io_message_loop_-> | |
123 BelongsToCurrentThread()); | |
124 return CastIPCDispatcher::global_instance_->channel_->Send(message); | |
125 } else { | |
126 // TODO(Hubbe): Notify caller that send failed and close channel. | |
127 delete message; | |
128 return false; | |
129 } | |
130 } | |
131 | |
132 void CastTransportSenderIPC::SetPacketReceiver( | |
133 const media::cast::transport::PacketReceiverCallback& packet_callback) { | |
134 packet_callback_ = packet_callback; | |
135 } | |
136 | |
137 void CastTransportSenderIPC::InsertCodedAudioFrame( | |
138 const media::cast::transport::EncodedAudioFrame* audio_frame, | |
139 const base::TimeTicks& recorded_time) { | |
140 Send(new CastHostMsg_InsertCodedAudioFrame(channel_id_, | |
141 *audio_frame, | |
142 recorded_time)); | |
143 } | |
144 | |
145 void CastTransportSenderIPC::InsertCodedVideoFrame( | |
146 const media::cast::transport::EncodedVideoFrame* video_frame, | |
147 const base::TimeTicks& capture_time) { | |
148 Send(new CastHostMsg_InsertCodedVideoFrame(channel_id_, | |
149 *video_frame, | |
150 capture_time)); | |
151 } | |
152 | |
153 void CastTransportSenderIPC::SendRtcpFromRtpSender( | |
154 uint32 packet_type_flags, | |
155 const media::cast::transport::RtcpSenderInfo& sender_info, | |
156 const media::cast::transport::RtcpDlrrReportBlock& dlrr, | |
157 const media::cast::transport::RtcpSenderLogMessage& sender_log, | |
158 uint32 sending_ssrc, | |
159 const std::string& c_name) { | |
160 struct media::cast::transport::SendRtcpFromRtpSenderData data; | |
161 data.packet_type_flags = packet_type_flags; | |
162 data.sending_ssrc = sending_ssrc; | |
163 data.c_name = data.c_name; | |
164 Send(new CastHostMsg_SendRtcpFromRtpSender( | |
165 channel_id_, | |
166 data, | |
167 sender_info, | |
168 dlrr, | |
169 sender_log)); | |
170 } | |
171 | |
172 void CastTransportSenderIPC::ResendPackets( | |
173 bool is_audio, | |
174 const media::cast::MissingFramesAndPacketsMap& missing_packets) { | |
175 Send(new CastHostMsg_ResendPackets(channel_id_, | |
176 is_audio, | |
177 missing_packets)); | |
178 } | |
179 | |
180 void CastTransportSenderIPC::SubscribeAudioRtpStatsCallback( | |
181 const media::cast::transport::CastTransportRtpStatistics& callback) { | |
182 audio_rtp_callback_ = callback; | |
183 } | |
184 | |
185 // Retrieves video RTP statistics. | |
scherkus (not reviewing)
2014/02/07 00:11:06
nuke comment?
hubbe
2014/02/07 00:52:22
Done.
| |
186 void CastTransportSenderIPC::SubscribeVideoRtpStatsCallback( | |
187 const media::cast::transport::CastTransportRtpStatistics& callback) { | |
188 video_rtp_callback_ = callback; | |
189 } | |
190 | |
191 | |
192 | |
193 | |
194 | |
scherkus (not reviewing)
2014/02/07 00:11:06
nuke all this extra whitespace
hubbe
2014/02/07 00:52:22
Done.
| |
195 } // namespace cast | |
OLD | NEW |