| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 RtpReceiver* rtp_receiver_; | 74 RtpReceiver* rtp_receiver_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 AudioReceiver::AudioReceiver(scoped_refptr<CastEnvironment> cast_environment, | 77 AudioReceiver::AudioReceiver(scoped_refptr<CastEnvironment> cast_environment, |
| 78 const AudioReceiverConfig& audio_config, | 78 const AudioReceiverConfig& audio_config, |
| 79 PacedPacketSender* const packet_sender) | 79 PacedPacketSender* const packet_sender) |
| 80 : cast_environment_(cast_environment), | 80 : cast_environment_(cast_environment), |
| 81 codec_(audio_config.codec), | 81 codec_(audio_config.codec), |
| 82 incoming_ssrc_(audio_config.incoming_ssrc), | |
| 83 frequency_(audio_config.frequency), | 82 frequency_(audio_config.frequency), |
| 84 audio_buffer_(), | 83 audio_buffer_(), |
| 85 audio_decoder_(), | 84 audio_decoder_(), |
| 86 time_offset_(), | 85 time_offset_(), |
| 87 weak_factory_(this) { | 86 weak_factory_(this) { |
| 88 target_delay_delta_ = | 87 target_delay_delta_ = |
| 89 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms); | 88 base::TimeDelta::FromMilliseconds(audio_config.rtp_max_delay_ms); |
| 90 incoming_payload_callback_.reset(new LocalRtpAudioData(this)); | 89 incoming_payload_callback_.reset(new LocalRtpAudioData(this)); |
| 91 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this)); | 90 incoming_payload_feedback_.reset(new LocalRtpAudioFeedback(this)); |
| 92 if (audio_config.use_external_decoder) { | 91 if (audio_config.use_external_decoder) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 new LocalRtpReceiverStatistics(rtp_receiver_.get())); | 105 new LocalRtpReceiverStatistics(rtp_receiver_.get())); |
| 107 base::TimeDelta rtcp_interval_delta = | 106 base::TimeDelta rtcp_interval_delta = |
| 108 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval); | 107 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval); |
| 109 rtcp_.reset(new Rtcp(cast_environment->Clock(), | 108 rtcp_.reset(new Rtcp(cast_environment->Clock(), |
| 110 NULL, | 109 NULL, |
| 111 packet_sender, | 110 packet_sender, |
| 112 NULL, | 111 NULL, |
| 113 rtp_audio_receiver_statistics_.get(), | 112 rtp_audio_receiver_statistics_.get(), |
| 114 audio_config.rtcp_mode, | 113 audio_config.rtcp_mode, |
| 115 rtcp_interval_delta, | 114 rtcp_interval_delta, |
| 116 false, | |
| 117 audio_config.feedback_ssrc, | 115 audio_config.feedback_ssrc, |
| 116 audio_config.incoming_ssrc, |
| 118 audio_config.rtcp_c_name)); | 117 audio_config.rtcp_c_name)); |
| 119 rtcp_->SetRemoteSSRC(audio_config.incoming_ssrc); | |
| 120 } | 118 } |
| 121 | 119 |
| 122 AudioReceiver::~AudioReceiver() {} | 120 AudioReceiver::~AudioReceiver() {} |
| 123 | 121 |
| 124 void AudioReceiver::InitializeTimers() { | 122 void AudioReceiver::InitializeTimers() { |
| 125 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 123 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 126 ScheduleNextRtcpReport(); | 124 ScheduleNextRtcpReport(); |
| 127 ScheduleNextCastMessage(); | 125 ScheduleNextCastMessage(); |
| 128 } | 126 } |
| 129 | 127 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length); | 281 bool rtcp_packet = Rtcp::IsRtcpPacket(packet, length); |
| 284 if (!rtcp_packet) { | 282 if (!rtcp_packet) { |
| 285 rtp_receiver_->ReceivedPacket(packet, length); | 283 rtp_receiver_->ReceivedPacket(packet, length); |
| 286 } else { | 284 } else { |
| 287 rtcp_->IncomingRtcpPacket(packet, length); | 285 rtcp_->IncomingRtcpPacket(packet, length); |
| 288 } | 286 } |
| 289 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); | 287 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); |
| 290 } | 288 } |
| 291 | 289 |
| 292 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) { | 290 void AudioReceiver::CastFeedback(const RtcpCastMessage& cast_message) { |
| 293 rtcp_->SendRtcpCast(cast_message); | 291 // TODO(pwestin): add logging. |
| 292 rtcp_->SendRtcpFromRtpReceiver(&cast_message, NULL); |
| 294 } | 293 } |
| 295 | 294 |
| 296 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now, | 295 base::TimeTicks AudioReceiver::GetPlayoutTime(base::TimeTicks now, |
| 297 uint32 rtp_timestamp) { | 296 uint32 rtp_timestamp) { |
| 298 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 297 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 299 // Senders time in ms when this frame was recorded. | 298 // Senders time in ms when this frame was recorded. |
| 300 // Note: the senders clock and our local clock might not be synced. | 299 // Note: the senders clock and our local clock might not be synced. |
| 301 base::TimeTicks rtp_timestamp_in_ticks; | 300 base::TimeTicks rtp_timestamp_in_ticks; |
| 302 if (time_offset_ == base::TimeDelta()) { | 301 if (time_offset_ == base::TimeDelta()) { |
| 303 if (rtcp_->RtpTimestampInSenderTime(frequency_, | 302 if (rtcp_->RtpTimestampInSenderTime(frequency_, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 333 time_to_send = std::max(time_to_send, | 332 time_to_send = std::max(time_to_send, |
| 334 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); | 333 base::TimeDelta::FromMilliseconds(kMinSchedulingDelayMs)); |
| 335 | 334 |
| 336 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, | 335 cast_environment_->PostDelayedTask(CastEnvironment::MAIN, FROM_HERE, |
| 337 base::Bind(&AudioReceiver::SendNextRtcpReport, | 336 base::Bind(&AudioReceiver::SendNextRtcpReport, |
| 338 weak_factory_.GetWeakPtr()), time_to_send); | 337 weak_factory_.GetWeakPtr()), time_to_send); |
| 339 } | 338 } |
| 340 | 339 |
| 341 void AudioReceiver::SendNextRtcpReport() { | 340 void AudioReceiver::SendNextRtcpReport() { |
| 342 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 341 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 343 rtcp_->SendRtcpReport(incoming_ssrc_); | 342 // TODO(pwestin): add logging. |
| 343 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
| 344 ScheduleNextRtcpReport(); | 344 ScheduleNextRtcpReport(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Cast messages should be sent within a maximum interval. Schedule a call | 347 // Cast messages should be sent within a maximum interval. Schedule a call |
| 348 // if not triggered elsewhere, e.g. by the cast message_builder. | 348 // if not triggered elsewhere, e.g. by the cast message_builder. |
| 349 void AudioReceiver::ScheduleNextCastMessage() { | 349 void AudioReceiver::ScheduleNextCastMessage() { |
| 350 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 350 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 351 if (audio_buffer_) { | 351 if (audio_buffer_) { |
| 352 base::TimeTicks send_time; | 352 base::TimeTicks send_time; |
| 353 audio_buffer_->TimeToSendNextCastMessage(&send_time); | 353 audio_buffer_->TimeToSendNextCastMessage(&send_time); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 364 | 364 |
| 365 void AudioReceiver::SendNextCastMessage() { | 365 void AudioReceiver::SendNextCastMessage() { |
| 366 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 366 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 367 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; | 367 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; |
| 368 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. | 368 audio_buffer_->SendCastMessage(); // Will only send a message if it is time. |
| 369 ScheduleNextCastMessage(); | 369 ScheduleNextCastMessage(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 } // namespace cast | 372 } // namespace cast |
| 373 } // namespace media | 373 } // namespace media |
| OLD | NEW |