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

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: Addressed comments. 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::SenderRtcpObserver> rtcp_observer) {
48 const media::cast::RtcpRttCallback& rtt_cb, 43 DCHECK(clients_.find(config.ssrc) == clients_.end());
49 const media::cast::RtcpPliCallback& pli_cb) { 44 clients_[config.ssrc] = std::move(rtcp_observer);
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)); 45 Send(new CastHostMsg_InitializeAudio(channel_id_, config));
54 } 46 }
55 47
56 void CastTransportIPC::InitializeVideo( 48 void CastTransportIPC::InitializeVideo(
57 const media::cast::CastTransportRtpConfig& config, 49 const media::cast::CastTransportRtpConfig& config,
58 const media::cast::RtcpCastMessageCallback& cast_message_cb, 50 std::unique_ptr<media::cast::SenderRtcpObserver> rtcp_observer) {
59 const media::cast::RtcpRttCallback& rtt_cb, 51 DCHECK(clients_.find(config.ssrc) == clients_.end());
60 const media::cast::RtcpPliCallback& pli_cb) { 52 clients_[config.ssrc] = std::move(rtcp_observer);
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)); 53 Send(new CastHostMsg_InitializeVideo(channel_id_, config));
65 } 54 }
66 55
67 void CastTransportIPC::InsertFrame(uint32_t ssrc, 56 void CastTransportIPC::InsertFrame(uint32_t ssrc,
68 const media::cast::EncodedFrame& frame) { 57 const media::cast::EncodedFrame& frame) {
69 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame)); 58 Send(new CastHostMsg_InsertFrame(channel_id_, ssrc, frame));
70 } 59 }
71 60
72 void CastTransportIPC::SendSenderReport( 61 void CastTransportIPC::SendSenderReport(
73 uint32_t ssrc, 62 uint32_t ssrc,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 media::cast::CastTransportStatus status) { 120 media::cast::CastTransportStatus status) {
132 status_callback_.Run(status); 121 status_callback_.Run(status);
133 } 122 }
134 123
135 void CastTransportIPC::OnRawEvents( 124 void CastTransportIPC::OnRawEvents(
136 const std::vector<media::cast::PacketEvent>& packet_events, 125 const std::vector<media::cast::PacketEvent>& packet_events,
137 const std::vector<media::cast::FrameEvent>& frame_events) { 126 const std::vector<media::cast::FrameEvent>& frame_events) {
138 // Note: Casting away const to avoid having to copy all the data elements. As 127 // 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 128 // 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. 129 // should be acceptable. Just nod and blame the interface we were given here.
141 scoped_ptr<std::vector<media::cast::FrameEvent>> taken_frame_events( 130 std::unique_ptr<std::vector<media::cast::FrameEvent>> taken_frame_events(
142 new std::vector<media::cast::FrameEvent>()); 131 new std::vector<media::cast::FrameEvent>());
143 taken_frame_events->swap( 132 taken_frame_events->swap(
144 const_cast<std::vector<media::cast::FrameEvent>&>(frame_events)); 133 const_cast<std::vector<media::cast::FrameEvent>&>(frame_events));
145 scoped_ptr<std::vector<media::cast::PacketEvent>> taken_packet_events( 134 std::unique_ptr<std::vector<media::cast::PacketEvent>> taken_packet_events(
146 new std::vector<media::cast::PacketEvent>()); 135 new std::vector<media::cast::PacketEvent>());
147 taken_packet_events->swap( 136 taken_packet_events->swap(
148 const_cast<std::vector<media::cast::PacketEvent>&>(packet_events)); 137 const_cast<std::vector<media::cast::PacketEvent>&>(packet_events));
149 raw_events_callback_.Run(std::move(taken_frame_events), 138 raw_events_callback_.Run(std::move(taken_frame_events),
150 std::move(taken_packet_events)); 139 std::move(taken_packet_events));
151 } 140 }
152 141
153 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) { 142 void CastTransportIPC::OnRtt(uint32_t rtp_sender_ssrc, base::TimeDelta rtt) {
154 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 143 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
155 if (it == clients_.end()) { 144 if (it == clients_.end()) {
156 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc; 145 LOG(ERROR) << "Received RTT report for unknown SSRC: " << rtp_sender_ssrc;
157 return; 146 return;
158 } 147 }
159 if (!it->second.rtt_cb.is_null()) 148 it->second->OnRttReceived(rtt);
160 it->second.rtt_cb.Run(rtt);
161 } 149 }
162 150
163 void CastTransportIPC::OnRtcpCastMessage( 151 void CastTransportIPC::OnRtcpCastMessage(
164 uint32_t rtp_sender_ssrc, 152 uint32_t rtp_sender_ssrc,
165 const media::cast::RtcpCastMessage& cast_message) { 153 const media::cast::RtcpCastMessage& cast_message) {
166 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 154 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
167 if (it == clients_.end()) { 155 if (it == clients_.end()) {
168 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc; 156 LOG(ERROR) << "Received cast message for unknown SSRC: " << rtp_sender_ssrc;
169 return; 157 return;
170 } 158 }
171 if (it->second.cast_message_cb.is_null()) 159 it->second->OnCastMessageReceived(cast_message);
172 return;
173 it->second.cast_message_cb.Run(cast_message);
174 } 160 }
175 161
176 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) { 162 void CastTransportIPC::OnReceivedPli(uint32_t rtp_sender_ssrc) {
177 ClientMap::iterator it = clients_.find(rtp_sender_ssrc); 163 ClientMap::iterator it = clients_.find(rtp_sender_ssrc);
178 if (it == clients_.end()) { 164 if (it == clients_.end()) {
179 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: " 165 LOG(ERROR) << "Received picture loss indicator for unknown SSRC: "
180 << rtp_sender_ssrc; 166 << rtp_sender_ssrc;
181 return; 167 return;
182 } 168 }
183 if (!it->second.pli_cb.is_null()) 169 it->second->OnPliReceived();
184 it->second.pli_cb.Run();
185 } 170 }
186 171
187 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) { 172 void CastTransportIPC::OnReceivedPacket(const media::cast::Packet& packet) {
188 if (!packet_callback_.is_null()) { 173 if (!packet_callback_.is_null()) {
189 // TODO(hubbe): Perhaps an non-ownership-transferring cb here? 174 // TODO(hubbe): Perhaps an non-ownership-transferring cb here?
190 scoped_ptr<media::cast::Packet> packet_copy( 175 std::unique_ptr<media::cast::Packet> packet_copy(
191 new media::cast::Packet(packet)); 176 new media::cast::Packet(packet));
192 packet_callback_.Run(std::move(packet_copy)); 177 packet_callback_.Run(std::move(packet_copy));
193 } else { 178 } else {
194 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet."; 179 DVLOG(1) << "CastIPCDispatcher::OnReceivedPacket no packet callback yet.";
195 } 180 }
196 } 181 }
197 182
198 void CastTransportIPC::Send(IPC::Message* message) { 183 void CastTransportIPC::Send(IPC::Message* message) {
199 if (CastIPCDispatcher::Get()) { 184 if (CastIPCDispatcher::Get()) {
200 CastIPCDispatcher::Get()->Send(message); 185 CastIPCDispatcher::Get()->Send(message);
201 } else { 186 } else {
202 delete message; 187 delete message;
203 } 188 }
204 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698