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

Side by Side Diff: chrome/browser/media/cast_transport_host_filter.cc

Issue 1878883003: Refactor: simplify interface of SenderRtcpSession and CastTransport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 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/browser/media/cast_transport_host_filter.h" 5 #include "chrome/browser/media/cast_transport_host_filter.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/thread_task_runner_handle.h" 8 #include "base/thread_task_runner_handle.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/cast_messages.h" 10 #include "chrome/common/cast_messages.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 cast_transport_host_filter_->Send( 51 cast_transport_host_filter_->Send(
52 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events)); 52 new CastMsg_RawEvents(channel_id_, *packet_events, *frame_events));
53 } 53 }
54 54
55 void TransportClient::ProcessRtpPacket( 55 void TransportClient::ProcessRtpPacket(
56 std::unique_ptr<media::cast::Packet> packet) { 56 std::unique_ptr<media::cast::Packet> packet) {
57 cast_transport_host_filter_->Send( 57 cast_transport_host_filter_->Send(
58 new CastMsg_ReceivedPacket(channel_id_, *packet)); 58 new CastMsg_ReceivedPacket(channel_id_, *packet));
59 } 59 }
60 60
61 class RtcpClient : public media::cast::RtcpObserver {
62 public:
63 RtcpClient(
64 int32_t channel_id,
65 uint32_t rtp_sender_ssrc,
66 base::WeakPtr<cast::CastTransportHostFilter> cast_transport_host_filter)
67 : channel_id_(channel_id),
68 rtp_sender_ssrc_(rtp_sender_ssrc),
69 cast_transport_host_filter_(cast_transport_host_filter) {}
70
71 void OnReceivedCastMessage(
72 const media::cast::RtcpCastMessage& cast_message) override {
73 if (cast_transport_host_filter_)
74 cast_transport_host_filter_->Send(new CastMsg_RtcpCastMessage(
75 channel_id_, rtp_sender_ssrc_, cast_message));
76 }
77
78 void OnReceivedRtt(base::TimeDelta round_trip_time) override {
79 if (cast_transport_host_filter_)
80 cast_transport_host_filter_->Send(
81 new CastMsg_Rtt(channel_id_, rtp_sender_ssrc_, round_trip_time));
82 }
83
84 void OnReceivedPli() override {
85 if (cast_transport_host_filter_)
86 cast_transport_host_filter_->Send(
87 new CastMsg_Pli(channel_id_, rtp_sender_ssrc_));
88 }
89
90 private:
91 const int32_t channel_id_;
92 const uint32_t rtp_sender_ssrc_;
93 const base::WeakPtr<cast::CastTransportHostFilter>
94 cast_transport_host_filter_;
95
96 DISALLOW_COPY_AND_ASSIGN(RtcpClient);
97 };
98
61 } // namespace 99 } // namespace
62 100
63 namespace cast { 101 namespace cast {
64 102
65 CastTransportHostFilter::CastTransportHostFilter() 103 CastTransportHostFilter::CastTransportHostFilter()
66 : BrowserMessageFilter(CastMsgStart), 104 : BrowserMessageFilter(CastMsgStart),
67 weak_factory_(this) {} 105 weak_factory_(this) {}
68 106
69 CastTransportHostFilter::~CastTransportHostFilter() {} 107 CastTransportHostFilter::~CastTransportHostFilter() {}
70 108
(...skipping 25 matching lines...) Expand all
96 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtcpEvents, OnAddRtcpEvents) 134 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtcpEvents, OnAddRtcpEvents)
97 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtpReceiverReport, 135 IPC_MESSAGE_HANDLER(CastHostMsg_AddRtpReceiverReport,
98 OnAddRtpReceiverReport) 136 OnAddRtpReceiverReport)
99 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver, 137 IPC_MESSAGE_HANDLER(CastHostMsg_SendRtcpFromRtpReceiver,
100 OnSendRtcpFromRtpReceiver) 138 OnSendRtcpFromRtpReceiver)
101 IPC_MESSAGE_UNHANDLED(handled = false) 139 IPC_MESSAGE_UNHANDLED(handled = false)
102 IPC_END_MESSAGE_MAP() 140 IPC_END_MESSAGE_MAP()
103 return handled; 141 return handled;
104 } 142 }
105 143
106 void CastTransportHostFilter::SendRtt(int32_t channel_id,
107 uint32_t rtp_sender_ssrc,
108 base::TimeDelta rtt) {
109 Send(new CastMsg_Rtt(channel_id, rtp_sender_ssrc, rtt));
110 }
111
112 void CastTransportHostFilter::SendCastMessage(
113 int32_t channel_id,
114 uint32_t rtp_sender_ssrc,
115 const media::cast::RtcpCastMessage& cast_message) {
116 Send(new CastMsg_RtcpCastMessage(channel_id, rtp_sender_ssrc, cast_message));
117 }
118
119 void CastTransportHostFilter::SendReceivedPli(int32_t channel_id,
120 uint32_t rtp_sender_ssrc) {
121 Send(new CastMsg_Pli(channel_id, rtp_sender_ssrc));
122 }
123
124 void CastTransportHostFilter::OnNew(int32_t channel_id, 144 void CastTransportHostFilter::OnNew(int32_t channel_id,
125 const net::IPEndPoint& local_end_point, 145 const net::IPEndPoint& local_end_point,
126 const net::IPEndPoint& remote_end_point, 146 const net::IPEndPoint& remote_end_point,
127 const base::DictionaryValue& options) { 147 const base::DictionaryValue& options) {
128 if (!power_save_blocker_) { 148 if (!power_save_blocker_) {
129 DVLOG(1) << ("Preventing the application from being suspended while one or " 149 DVLOG(1) << ("Preventing the application from being suspended while one or "
130 "more transports are active for Cast Streaming."); 150 "more transports are active for Cast Streaming.");
131 power_save_blocker_ = content::PowerSaveBlocker::Create( 151 power_save_blocker_ = content::PowerSaveBlocker::Create(
132 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 152 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
133 content::PowerSaveBlocker::kReasonOther, 153 content::PowerSaveBlocker::kReasonOther,
(...skipping 30 matching lines...) Expand all
164 } 184 }
165 185
166 if (id_map_.IsEmpty()) { 186 if (id_map_.IsEmpty()) {
167 DVLOG_IF(1, power_save_blocker_) << 187 DVLOG_IF(1, power_save_blocker_) <<
168 ("Releasing the block on application suspension since no transports " 188 ("Releasing the block on application suspension since no transports "
169 "are active anymore for Cast Streaming."); 189 "are active anymore for Cast Streaming.");
170 power_save_blocker_.reset(); 190 power_save_blocker_.reset();
171 } 191 }
172 } 192 }
173 193
194 // TODO(xjz): Replace all the separate "init/start audio" and "init/start video"
195 // methods with a single "init/start rtp stream" that handles either media type.
174 void CastTransportHostFilter::OnInitializeAudio( 196 void CastTransportHostFilter::OnInitializeAudio(
175 int32_t channel_id, 197 int32_t channel_id,
176 const media::cast::CastTransportRtpConfig& config) { 198 const media::cast::CastTransportRtpConfig& config) {
177 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); 199 media::cast::CastTransport* sender = id_map_.Lookup(channel_id);
178 if (sender) { 200 if (sender) {
179 sender->InitializeAudio( 201 sender->InitializeAudio(
180 config, base::Bind(&CastTransportHostFilter::SendCastMessage, 202 config, base::WrapUnique(new RtcpClient(channel_id, config.ssrc,
181 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), 203 weak_factory_.GetWeakPtr())));
182 base::Bind(&CastTransportHostFilter::SendRtt,
183 weak_factory_.GetWeakPtr(), channel_id, config.ssrc),
184 base::Bind(&CastTransportHostFilter::SendReceivedPli,
185 weak_factory_.GetWeakPtr(), channel_id, config.ssrc));
186 } else { 204 } else {
187 DVLOG(1) 205 DVLOG(1)
188 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel"; 206 << "CastTransportHostFilter::OnInitializeAudio on non-existing channel";
189 } 207 }
190 } 208 }
191 209
192 void CastTransportHostFilter::OnInitializeVideo( 210 void CastTransportHostFilter::OnInitializeVideo(
193 int32_t channel_id, 211 int32_t channel_id,
194 const media::cast::CastTransportRtpConfig& config) { 212 const media::cast::CastTransportRtpConfig& config) {
195 media::cast::CastTransport* sender = id_map_.Lookup(channel_id); 213 media::cast::CastTransport* sender = id_map_.Lookup(channel_id);
196 if (sender) { 214 if (sender) {
197 sender->InitializeVideo( 215 sender->InitializeVideo(
198 config, base::Bind(&CastTransportHostFilter::SendCastMessage, 216 config, base::WrapUnique(new RtcpClient(channel_id, config.ssrc,
199 weak_factory_.GetWeakPtr(), channel_id, config.ssrc), 217 weak_factory_.GetWeakPtr())));
200 base::Bind(&CastTransportHostFilter::SendRtt,
201 weak_factory_.GetWeakPtr(), channel_id, config.ssrc),
202 base::Bind(&CastTransportHostFilter::SendReceivedPli,
203 weak_factory_.GetWeakPtr(), channel_id, config.ssrc));
204 } else { 218 } else {
205 DVLOG(1) 219 DVLOG(1)
206 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel"; 220 << "CastTransportHostFilter::OnInitializeVideo on non-existing channel";
207 } 221 }
208 } 222 }
209 223
210 void CastTransportHostFilter::OnInsertFrame( 224 void CastTransportHostFilter::OnInsertFrame(
211 int32_t channel_id, 225 int32_t channel_id,
212 uint32_t ssrc, 226 uint32_t ssrc,
213 const media::cast::EncodedFrame& frame) { 227 const media::cast::EncodedFrame& frame) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (sender) { 358 if (sender) {
345 sender->SendRtcpFromRtpReceiver(); 359 sender->SendRtcpFromRtpReceiver();
346 } else { 360 } else {
347 DVLOG(1) 361 DVLOG(1)
348 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver " 362 << "CastTransportHostFilter::OnSendRtcpFromRtpReceiver "
349 << "on non-existing channel"; 363 << "on non-existing channel";
350 } 364 }
351 } 365 }
352 366
353 } // namespace cast 367 } // namespace cast
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_transport_host_filter.h ('k') | chrome/renderer/media/cast_transport_ipc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698