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

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

Issue 1878883003: Refactor: simplify interface of SenderRtcpSession and CastTransport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/id_map.h" 10 #include "base/id_map.h"
11 #include "chrome/common/cast_messages.h" 11 #include "chrome/common/cast_messages.h"
12 #include "chrome/renderer/media/cast_ipc_dispatcher.h" 12 #include "chrome/renderer/media/cast_ipc_dispatcher.h"
13 #include "ipc/ipc_channel_proxy.h" 13 #include "ipc/ipc_channel_proxy.h"
14 #include "media/cast/cast_sender.h" 14 #include "media/cast/cast_sender.h"
15 15
16 CastTransportIPC::ClientCallbacks::ClientCallbacks() {}
17 CastTransportIPC::ClientCallbacks::ClientCallbacks(
18 const ClientCallbacks& other) = default;
19 CastTransportIPC::ClientCallbacks::~ClientCallbacks() {}
20
21 CastTransportIPC::CastTransportIPC( 16 CastTransportIPC::CastTransportIPC(
22 const net::IPEndPoint& local_end_point, 17 const net::IPEndPoint& local_end_point,
23 const net::IPEndPoint& remote_end_point, 18 const net::IPEndPoint& remote_end_point,
24 scoped_ptr<base::DictionaryValue> options, 19 std::unique_ptr<base::DictionaryValue> options,
25 const media::cast::PacketReceiverCallback& packet_callback, 20 const media::cast::PacketReceiverCallback& packet_callback,
26 const media::cast::CastTransportStatusCallback& status_cb, 21 const media::cast::CastTransportStatusCallback& status_cb,
27 const media::cast::BulkRawEventsCallback& raw_events_cb) 22 const media::cast::BulkRawEventsCallback& raw_events_cb)
28 : packet_callback_(packet_callback), 23 : packet_callback_(packet_callback),
29 status_callback_(status_cb), 24 status_callback_(status_cb),
30 raw_events_callback_(raw_events_cb) { 25 raw_events_callback_(raw_events_cb) {
31 if (CastIPCDispatcher::Get()) { 26 if (CastIPCDispatcher::Get()) {
32 channel_id_ = CastIPCDispatcher::Get()->AddSender(this); 27 channel_id_ = CastIPCDispatcher::Get()->AddSender(this);
33 } 28 }
34 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point, 29 Send(new CastHostMsg_New(channel_id_, local_end_point, remote_end_point,
35 *options)); 30 *options));
36 } 31 }
37 32
38 CastTransportIPC::~CastTransportIPC() { 33 CastTransportIPC::~CastTransportIPC() {
39 Send(new CastHostMsg_Delete(channel_id_)); 34 Send(new CastHostMsg_Delete(channel_id_));
40 if (CastIPCDispatcher::Get()) { 35 if (CastIPCDispatcher::Get()) {
41 CastIPCDispatcher::Get()->RemoveSender(channel_id_); 36 CastIPCDispatcher::Get()->RemoveSender(channel_id_);
42 } 37 }
43 } 38 }
44 39
45 void CastTransportIPC::InitializeAudio( 40 void CastTransportIPC::InitializeAudio(
46 const media::cast::CastTransportRtpConfig& config, 41 const media::cast::CastTransportRtpConfig& config,
47 const media::cast::RtcpCastMessageCallback& cast_message_cb, 42 std::unique_ptr<media::cast::RtpSenderRtcpClient> rtcp_client) {
48 const media::cast::RtcpRttCallback& rtt_cb, 43 clients_[config.ssrc] = std::move(rtcp_client);
miu 2016/04/15 23:14:39 This was missing before, but consider adding: DCHE
xjz 2016/04/20 01:09:02 Done.
49 const media::cast::RtcpPliCallback& pli_cb) {
50 clients_[config.ssrc].cast_message_cb = cast_message_cb;
51 clients_[config.ssrc].rtt_cb = rtt_cb;
52 clients_[config.ssrc].pli_cb = pli_cb;
53 Send(new CastHostMsg_InitializeAudio(channel_id_, config)); 44 Send(new CastHostMsg_InitializeAudio(channel_id_, config));
54 } 45 }
55 46
56 void CastTransportIPC::InitializeVideo( 47 void CastTransportIPC::InitializeVideo(
57 const media::cast::CastTransportRtpConfig& config, 48 const media::cast::CastTransportRtpConfig& config,
58 const media::cast::RtcpCastMessageCallback& cast_message_cb, 49 std::unique_ptr<media::cast::RtpSenderRtcpClient> rtcp_client) {
59 const media::cast::RtcpRttCallback& rtt_cb, 50 clients_[config.ssrc] = std::move(rtcp_client);
miu 2016/04/15 23:14:39 ditto here (maybe add DCHECK?)
xjz 2016/04/20 01:09:02 Done.
60 const media::cast::RtcpPliCallback& pli_cb) {
61 clients_[config.ssrc].cast_message_cb = cast_message_cb;
62 clients_[config.ssrc].rtt_cb = rtt_cb;
63 clients_[config.ssrc].pli_cb = pli_cb;
64 Send(new CastHostMsg_InitializeVideo(channel_id_, config)); 51 Send(new CastHostMsg_InitializeVideo(channel_id_, config));
65 } 52 }
66 53
67 void CastTransportIPC::InsertFrame(uint32_t ssrc, 54 void CastTransportIPC::InsertFrame(uint32_t ssrc,
68 const media::cast::EncodedFrame& frame) { 55 const media::cast::EncodedFrame& frame) {
69 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); 56 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame));
70 } 57 }
71 58
72 void CastTransportIPC::SendSenderReport( 59 void CastTransportIPC::SendSenderReport(
73 uint32_t ssrc, 60 uint32_t ssrc,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 media::cast::CastTransportStatus status) { 118 media::cast::CastTransportStatus status) {
132 status_callback_.Run(status); 119 status_callback_.Run(status);
133 } 120 }
134 121
135 void CastTransportIPC::OnRawEvents( 122 void CastTransportIPC::OnRawEvents(
136 const std::vector<media::cast::PacketEvent>& packet_events, 123 const std::vector<media::cast::PacketEvent>& packet_events,
137 const std::vector<media::cast::FrameEvent>& frame_events) { 124 const std::vector<media::cast::FrameEvent>& frame_events) {
138 // Note: Casting away const to avoid having to copy all the data elements. As 125 // Note: Casting away const to avoid having to copy all the data elements. As
139 // the only consumer of this data in the IPC message, mutating the inputs 126 // the only consumer of this data in the IPC message, mutating the inputs
140 // should be acceptable. Just nod and blame the interface we were given here. 127 // should be acceptable. Just nod and blame the interface we were given here.
141 scoped_ptr<std::vector<media::cast::FrameEvent>> taken_frame_events( 128 std::unique_ptr<std::vector<media::cast::FrameEvent>> taken_frame_events(
142 new std::vector<media::cast::FrameEvent>()); 129 new std::vector<media::cast::FrameEvent>());
143 taken_frame_events->swap( 130 taken_frame_events->swap(
144 const_cast<std::vector<media::cast::FrameEvent>&>(frame_events)); 131 const_cast<std::vector<media::cast::FrameEvent>&>(frame_events));
145 scoped_ptr<std::vector<media::cast::PacketEvent>> taken_packet_events( 132 std::unique_ptr<std::vector<media::cast::PacketEvent>> taken_packet_events(
146 new std::vector<media::cast::PacketEvent>()); 133 new std::vector<media::cast::PacketEvent>());
147 taken_packet_events->swap( 134 taken_packet_events->swap(
148 const_cast<std::vector<media::cast::PacketEvent>&>(packet_events)); 135 const_cast<std::vector<media::cast::PacketEvent>&>(packet_events));
149 raw_events_callback_.Run(std::move(taken_frame_events), 136 raw_events_callback_.Run(std::move(taken_frame_events),
150 std::move(taken_packet_events)); 137 std::move(taken_packet_events));
151 } 138 }
152 139
153 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) { 140 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) {
154 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 141 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
155 if (it == clients_.end()) { 142 if (it == clients_.end()) {
156 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc; 143 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc;
157 return; 144 return;
158 } 145 }
159 if (!it->second.rtt_cb.is_null()) 146 it->second->OnRttReceived(rtt);
160 it->second.rtt_cb.Run(rtt);
161 } 147 }
162 148
163 void CastTransportIPC::OnRtcpCastMessage( 149 void CastTransportIPC::OnRtcpCastMessage(
164 uint32_t rtp_sender_ssrc, 150 uint32_t rtp_sender_ssrc,
165 const media::cast::RtcpCastMessage& cast_message) { 151 const media::cast::RtcpCastMessage& cast_message) {
166 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 152 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
167 if (it == clients_.end()) { 153 if (it == clients_.end()) {
168 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc; 154 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc;
169 return; 155 return;
170 } 156 }
171 if (it->second.cast_message_cb.is_null()) 157 it->second->OnCastMessageReceived(cast_message);
172 return;
173 it->second.cast_message_cb.Run(cast_message);
174 } 158 }
175 159
176 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) { 160 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) {
177 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 161 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
178 if (it == clients_.end()) { 162 if (it == clients_.end()) {
179 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: " 163 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: "
180 << rtp_sender_ssrc; 164 << rtp_sender_ssrc;
181 return; 165 return;
182 } 166 }
183 if (!it->second.pli_cb.is_null()) 167 it->second->OnPliReceived();
184 it->second.pli_cb.Run();
185 } 168 }
186 169
187 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) { 170 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) {
188 if (!packet_callback_.is_null()) { 171 if (!packet_callback_.is_null()) {
189 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? 172 // TODO(hubbe): Perhaps an non-ownership-transferring cb here?
190 scoped_ptr<media::cast::Packet> packet_copy( 173 std::unique_ptr<media::cast::Packet> packet_copy(
191 new media::cast::Packet(packet)); 174 new media::cast::Packet(packet));
192 packet_callback_.Run(std::move(packet_copy)); 175 packet_callback_.Run(std::move(packet_copy));
193 } else { 176 } else {
194 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; 177 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet.";
195 } 178 }
196 } 179 }
197 180
198 void CastTransportIPC::Send(IPC::Message* message) { 181 void CastTransportIPC::Send(IPC::Message* message) {
199 if (CastIPCDispatcher::Get()) { 182 if (CastIPCDispatcher::Get()) {
200 CastIPCDispatcher::Get()->Send(message); 183 CastIPCDispatcher::Get()->Send(message);
201 } else { 184 } else {
202 delete message; 185 delete message;
203 } 186 }
204 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698