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

Side by Side Diff: media/cast/audio_receiver/audio_receiver.cc

Issue 70713002: Cast: Restructure RTCP interface to better fit our usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/cast/audio_receiver/audio_receiver.h" 5 #include "media/cast/audio_receiver/audio_receiver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "media/cast/audio_receiver/audio_decoder.h" 10 #include "media/cast/audio_receiver/audio_decoder.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 private: 74 private:
75 RtpReceiver* rtp_receiver_; 75 RtpReceiver* rtp_receiver_;
76 }; 76 };
77 77
78 AudioReceiver::AudioReceiver(scoped_refptr<CastEnvironment> cast_environment, 78 AudioReceiver::AudioReceiver(scoped_refptr<CastEnvironment> cast_environment,
79 const AudioReceiverConfig& audio_config, 79 const AudioReceiverConfig& audio_config,
80 PacedPacketSender* const packet_sender) 80 PacedPacketSender* const packet_sender)
81 : cast_environment_(cast_environment), 81 : cast_environment_(cast_environment),
82 codec_(audio_config.codec), 82 codec_(audio_config.codec),
83 incoming_ssrc_(audio_config.incoming_ssrc),
84 frequency_(audio_config.frequency), 83 frequency_(audio_config.frequency),
85 audio_buffer_(), 84 audio_buffer_(),
86 audio_decoder_(), 85 audio_decoder_(),
87 time_offset_(), 86 time_offset_(),
88 weak_factory_(this) { 87 weak_factory_(this) {
89 target_delay_delta_ = 88 target_delay_delta_ =
90 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms); 89 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms);
91 incoming_payload_callback_.reset(new LocalRtpAudioData(this)); 90 incoming_payload_callback_.reset(new LocalRtpAudioData(this));
92 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this)); 91 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this));
93 if (audio_config.use_external_decoder) { 92 if (audio_config.use_external_decoder) {
(...skipping 13 matching lines...) Expand all
107 new LocalRtpReceiverStatistics(rtp_receiver_.get())); 106 new LocalRtpReceiverStatistics(rtp_receiver_.get()));
108 base::TimeDelta rtcp_interval_delta = 107 base::TimeDelta rtcp_interval_delta =
109 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval); 108 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval);
110 rtcp_.reset(new Rtcp(cast_environment->Clock(), 109 rtcp_.reset(new Rtcp(cast_environment->Clock(),
111 NULL, 110 NULL,
112 packet_sender, 111 packet_sender,
113 NULL, 112 NULL,
114 rtp_audio_receiver_statistics_.get(), 113 rtp_audio_receiver_statistics_.get(),
115 audio_config.rtcp_mode, 114 audio_config.rtcp_mode,
116 rtcp_interval_delta, 115 rtcp_interval_delta,
117 false,
118 audio_config.feedback_ssrc, 116 audio_config.feedback_ssrc,
117 audio_config.incoming_ssrc,
119 audio_config.rtcp_c_name)); 118 audio_config.rtcp_c_name));
120 rtcp_->SetRemoteSSRC(audio_config.incoming_ssrc);
121 ScheduleNextRtcpReport(); 119 ScheduleNextRtcpReport();
122 ScheduleNextCastMessage(); 120 ScheduleNextCastMessage();
123 } 121 }
124 122
125 AudioReceiver::~AudioReceiver() {} 123 AudioReceiver::~AudioReceiver() {}
126 124
127 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data, 125 void AudioReceiver::IncomingParsedRtpPacket(const uint8* payload_data,
128 size_t payload_size, 126 size_t payload_size,
129 const RtpCastHeader& rtp_header) { 127 const RtpCastHeader& rtp_header) {
130 // TODO(pwestin): update this as video to refresh over time. 128 // TODO(pwestin): update this as video to refresh over time.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length); 271 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length);
274 if (!rtcp_packet) { 272 if (!rtcp_packet) {
275 rtp_receiver_->ReceivedPacket(packet, length); 273 rtp_receiver_->ReceivedPacket(packet, length);
276 } else { 274 } else {
277 rtcp_->IncomingRtcpPacket(packet, length); 275 rtcp_->IncomingRtcpPacket(packet, length);
278 } 276 }
279 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); 277 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback);
280 } 278 }
281 279
282 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) { 280 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) {
283 rtcp_->SendRtcpCast(cast_message); 281 // TODO(pwestin): add logging.
282 rtcp_->SendRtcpFromRtpReceiver(&cast_message, NULL);
284 } 283 }
285 284
286 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now, 285 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now,
287 uint32 rtp_timestamp) { 286 uint32 rtp_timestamp) {
288 // Senders time in ms when this frame was recorded. 287 // Senders time in ms when this frame was recorded.
289 // Note: the senders clock and our local clock might not be synced. 288 // Note: the senders clock and our local clock might not be synced.
290 base::TimeTicks rtp_timestamp_in_ticks; 289 base::TimeTicks rtp_timestamp_in_ticks;
291 if (time_offset_ == base::TimeDelta()) { 290 if (time_offset_ == base::TimeDelta()) {
292 if (rtcp_->RtpTimestampInSenderTime(frequency_, 291 if (rtcp_->RtpTimestampInSenderTime(frequency_,
293 first_incoming_rtp_timestamp_, 292 first_incoming_rtp_timestamp_,
(...skipping 26 matching lines...) Expand all
320 319
321 time_to_send = std::max(time_to_send, 320 time_to_send = std::max(time_to_send,
322 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); 321 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs));
323 322
324 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, 323 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE,
325 base::Bind(&AudioReceiver::SendNextRtcpReport, 324 base::Bind(&AudioReceiver::SendNextRtcpReport,
326 weak_factory_.GetWeakPtr()), time_to_send); 325 weak_factory_.GetWeakPtr()), time_to_send);
327 } 326 }
328 327
329 void AudioReceiver::SendNextRtcpReport() { 328 void AudioReceiver::SendNextRtcpReport() {
330 rtcp_->SendRtcpReport(incoming_ssrc_); 329 // TODO(pwestin): add logging.
330 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL);
331 ScheduleNextRtcpReport(); 331 ScheduleNextRtcpReport();
332 } 332 }
333 333
334 // Cast messages should be sent within a maximum interval. Schedule a call 334 // Cast messages should be sent within a maximum interval. Schedule a call
335 // if not triggered elsewhere, e.g. by the cast message_builder. 335 // if not triggered elsewhere, e.g. by the cast message_builder.
336 void AudioReceiver::ScheduleNextCastMessage() { 336 void AudioReceiver::ScheduleNextCastMessage() {
337 if (audio_buffer_) { 337 if (audio_buffer_) {
338 base::TimeTicks send_time; 338 base::TimeTicks send_time;
339 audio_buffer_->TimeToSendNextCastMessage(&send_time); 339 audio_buffer_->TimeToSendNextCastMessage(&send_time);
340 340
341 base::TimeDelta time_to_send = send_time - 341 base::TimeDelta time_to_send = send_time -
342 cast_environment_->Clock()->NowTicks(); 342 cast_environment_->Clock()->NowTicks();
343 time_to_send = std::max(time_to_send, 343 time_to_send = std::max(time_to_send,
344 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); 344 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs));
345 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, 345 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE,
346 base::Bind(&AudioReceiver::SendNextCastMessage, 346 base::Bind(&AudioReceiver::SendNextCastMessage,
347 weak_factory_.GetWeakPtr()), time_to_send); 347 weak_factory_.GetWeakPtr()), time_to_send);
348 } 348 }
349 } 349 }
350 350
351 void AudioReceiver::SendNextCastMessage() { 351 void AudioReceiver::SendNextCastMessage() {
352 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; 352 DCHECK(audio_buffer_) << "Invalid function call in this configuration";
353 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. 353 audio_buffer_->SendCastMessage(); // Will only send a message if it is time.
354 ScheduleNextCastMessage(); 354 ScheduleNextCastMessage();
355 } 355 }
356 356
357 } // namespace cast 357 } // namespace cast
358 } // namespace media 358 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698