OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/media/cast_transport_ipc.h" | 5 #include "chrome/renderer/media/cast_transport_ipc.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
12 #include "chrome/common/cast_messages.h" | 12 #include "chrome/common/cast_messages.h" |
13 #include "chrome/renderer/media/cast_ipc_dispatcher.h" | 13 #include "chrome/renderer/media/cast_ipc_dispatcher.h" |
14 #include "ipc/ipc_channel_proxy.h" | 14 #include "ipc/ipc_channel_proxy.h" |
15 #include "media/cast/cast_sender.h" | 15 #include "media/cast/cast_sender.h" |
16 | 16 |
17 CastTransportIPC::ClientCallbacks::ClientCallbacks() {} | |
18 CastTransportIPC::ClientCallbacks::ClientCallbacks( | |
19 const ClientCallbacks& other) = default; | |
20 CastTransportIPC::ClientCallbacks::~ClientCallbacks() {} | |
21 | |
22 CastTransportIPC::CastTransportIPC( | 17 CastTransportIPC::CastTransportIPC( |
23 const net::IPEndPoint& local_end_point, | 18 const net::IPEndPoint& local_end_point, |
24 const net::IPEndPoint& remote_end_point, | 19 const net::IPEndPoint& remote_end_point, |
25 std::unique_ptr<base::DictionaryValue> options, | 20 std::unique_ptr<base::DictionaryValue> options, |
26 const media::cast::PacketReceiverCallback& packet_callback, | 21 const media::cast::PacketReceiverCallback& packet_callback, |
27 const media::cast::CastTransportStatusCallback& status_cb, | 22 const media::cast::CastTransportStatusCallback& status_cb, |
28 const media::cast::BulkRawEventsCallback& raw_events_cb) | 23 const media::cast::BulkRawEventsCallback& raw_events_cb) |
29 : packet_callback_(packet_callback), | 24 : packet_callback_(packet_callback), |
30 status_callback_(status_cb), | 25 status_callback_(status_cb), |
31 raw_events_callback_(raw_events_cb) { | 26 raw_events_callback_(raw_events_cb) { |
32 if (CastIPCDispatcher::Get()) { | 27 if (CastIPCDispatcher::Get()) { |
33 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); | 28 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); |
34 } | 29 } |
35 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point, | 30 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point, |
36 *options)); | 31 *options)); |
37 } | 32 } |
38 | 33 |
39 CastTransportIPC::~CastTransportIPC() { | 34 CastTransportIPC::~CastTransportIPC() { |
40 Send(new CastHostMsg_Delete(channel_id_)); | 35 Send(new CastHostMsg_Delete(channel_id_)); |
41 if (CastIPCDispatcher::Get()) { | 36 if (CastIPCDispatcher::Get()) { |
42 CastIPCDispatcher::Get()->RemoveSender(channel_id_); | 37 CastIPCDispatcher::Get()->RemoveSender(channel_id_); |
43 } | 38 } |
44 } | 39 } |
45 | 40 |
46 void CastTransportIPC::InitializeAudio( | 41 void CastTransportIPC::InitializeAudio( |
47 const media::cast::CastTransportRtpConfig& config, | 42 const media::cast::CastTransportRtpConfig& config, |
48 const media::cast::RtcpCastMessageCallback& cast_message_cb, | 43 std::unique_ptr<media::cast::RtcpObserver> rtcp_observer) { |
49 const media::cast::RtcpRttCallback& rtt_cb, | 44 DCHECK(clients_.find(config.ssrc) == clients_.end()); |
50 const media::cast::RtcpPliCallback& pli_cb) { | 45 clients_[config.ssrc] = std::move(rtcp_observer); |
51 clients_[config.ssrc].cast_message_cb = cast_message_cb; | |
52 clients_[config.ssrc].rtt_cb = rtt_cb; | |
53 clients_[config.ssrc].pli_cb = pli_cb; | |
54 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); | 46 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); |
55 } | 47 } |
56 | 48 |
57 void CastTransportIPC::InitializeVideo( | 49 void CastTransportIPC::InitializeVideo( |
58 const media::cast::CastTransportRtpConfig& config, | 50 const media::cast::CastTransportRtpConfig& config, |
59 const media::cast::RtcpCastMessageCallback& cast_message_cb, | 51 std::unique_ptr<media::cast::RtcpObserver> rtcp_observer) { |
60 const media::cast::RtcpRttCallback& rtt_cb, | 52 DCHECK(clients_.find(config.ssrc) == clients_.end()); |
61 const media::cast::RtcpPliCallback& pli_cb) { | 53 clients_[config.ssrc] = std::move(rtcp_observer); |
62 clients_[config.ssrc].cast_message_cb = cast_message_cb; | |
63 clients_[config.ssrc].rtt_cb = rtt_cb; | |
64 clients_[config.ssrc].pli_cb = pli_cb; | |
65 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); | 54 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); |
66 } | 55 } |
67 | 56 |
68 void CastTransportIPC::InsertFrame(uint32_t ssrc, | 57 void CastTransportIPC::InsertFrame(uint32_t ssrc, |
69 const media::cast::EncodedFrame& frame) { | 58 const media::cast::EncodedFrame& frame) { |
70 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); | 59 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); |
71 } | 60 } |
72 | 61 |
73 void CastTransportIPC::SendSenderReport( | 62 void CastTransportIPC::SendSenderReport( |
74 uint32_t ssrc, | 63 uint32_t ssrc, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 raw_events_callback_.Run(std::move(taken_frame_events), | 139 raw_events_callback_.Run(std::move(taken_frame_events), |
151 std::move(taken_packet_events)); | 140 std::move(taken_packet_events)); |
152 } | 141 } |
153 | 142 |
154 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) { | 143 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) { |
155 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); | 144 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); |
156 if (it == clients_.end()) { | 145 if (it == clients_.end()) { |
157 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc; | 146 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc; |
158 return; | 147 return; |
159 } | 148 } |
160 if (!it->second.rtt_cb.is_null()) | 149 it->second->OnReceivedRtt(rtt); |
161 it->second.rtt_cb.Run(rtt); | |
162 } | 150 } |
163 | 151 |
164 void CastTransportIPC::OnRtcpCastMessage( | 152 void CastTransportIPC::OnRtcpCastMessage( |
165 uint32_t rtp_sender_ssrc, | 153 uint32_t rtp_sender_ssrc, |
166 const media::cast::RtcpCastMessage& cast_message) { | 154 const media::cast::RtcpCastMessage& cast_message) { |
167 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); | 155 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); |
168 if (it == clients_.end()) { | 156 if (it == clients_.end()) { |
169 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc; | 157 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc; |
170 return; | 158 return; |
171 } | 159 } |
172 if (it->second.cast_message_cb.is_null()) | 160 it->second->OnReceivedCastMessage(cast_message); |
173 return; | |
174 it->second.cast_message_cb.Run(cast_message); | |
175 } | 161 } |
176 | 162 |
177 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) { | 163 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) { |
178 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); | 164 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); |
179 if (it == clients_.end()) { | 165 if (it == clients_.end()) { |
180 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: " | 166 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: " |
181 << rtp_sender_ssrc; | 167 << rtp_sender_ssrc; |
182 return; | 168 return; |
183 } | 169 } |
184 if (!it->second.pli_cb.is_null()) | 170 it->second->OnReceivedPli(); |
185 it->second.pli_cb.Run(); | |
186 } | 171 } |
187 | 172 |
188 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) { | 173 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) { |
189 if (!packet_callback_.is_null()) { | 174 if (!packet_callback_.is_null()) { |
190 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? | 175 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? |
191 std::unique_ptr<media::cast::Packet> packet_copy( | 176 std::unique_ptr<media::cast::Packet> packet_copy( |
192 new media::cast::Packet(packet)); | 177 new media::cast::Packet(packet)); |
193 packet_callback_.Run(std::move(packet_copy)); | 178 packet_callback_.Run(std::move(packet_copy)); |
194 } else { | 179 } else { |
195 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; | 180 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; |
196 } | 181 } |
197 } | 182 } |
198 | 183 |
199 void CastTransportIPC::Send(IPC::Message* message) { | 184 void CastTransportIPC::Send(IPC::Message* message) { |
200 if (CastIPCDispatcher::Get()) { | 185 if (CastIPCDispatcher::Get()) { |
201 CastIPCDispatcher::Get()->Send(message); | 186 CastIPCDispatcher::Get()->Send(message); |
202 } else { | 187 } else { |
203 delete message; | 188 delete message; |
204 } | 189 } |
205 } | 190 } |
OLD | NEW |