| Index: media/cast/sender/audio_sender.cc
|
| diff --git a/media/cast/sender/audio_sender.cc b/media/cast/sender/audio_sender.cc
|
| index a36e6de882ccdf64c0b732927fda7eabadc764dd..0a458911358c5af323ff1320be4e81deed858665 100644
|
| --- a/media/cast/sender/audio_sender.cc
|
| +++ b/media/cast/sender/audio_sender.cc
|
| @@ -15,8 +15,6 @@ namespace media {
|
| namespace cast {
|
| namespace {
|
|
|
| -const int kNumAggressiveReportsSentAtStart = 100;
|
| -
|
| // TODO(miu): This should be specified in AudioSenderConfig, but currently it is
|
| // fixed to 100 FPS (i.e., 10 ms per frame), and AudioEncoder assumes this as
|
| // well.
|
| @@ -29,13 +27,15 @@ AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
|
| CastTransportSender* const transport_sender)
|
| : FrameSender(
|
| cast_environment,
|
| + true,
|
| transport_sender,
|
| base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval),
|
| audio_config.frequency,
|
| audio_config.ssrc,
|
| kAudioFrameRate * 2.0, // We lie to increase max outstanding frames.
|
| - audio_config.target_playout_delay),
|
| - configured_encoder_bitrate_(audio_config.bitrate),
|
| + audio_config.target_playout_delay,
|
| + NewFixedCongestionControl(audio_config.bitrate)),
|
| + samples_sent_to_encoder_(0),
|
| weak_factory_(this) {
|
| cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED;
|
| VLOG(1) << "max_unacked_frames " << max_unacked_frames_;
|
| @@ -48,8 +48,9 @@ AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
|
| audio_config.frequency,
|
| audio_config.bitrate,
|
| audio_config.codec,
|
| - base::Bind(&AudioSender::SendEncodedAudioFrame,
|
| - weak_factory_.GetWeakPtr())));
|
| + base::Bind(&FrameSender::SendEncodedFrame,
|
| + weak_factory_.GetWeakPtr(),
|
| + audio_config.bitrate)));
|
| cast_initialization_status_ = audio_encoder_->InitializationResult();
|
| } else {
|
| NOTREACHED(); // No support for external audio encoding.
|
| @@ -89,142 +90,17 @@ void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus,
|
| return;
|
| }
|
|
|
| - audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time);
|
| -}
|
| -
|
| -void AudioSender::SendEncodedAudioFrame(
|
| - scoped_ptr<EncodedFrame> encoded_frame) {
|
| - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
|
| -
|
| - const uint32 frame_id = encoded_frame->frame_id;
|
| -
|
| - const bool is_first_frame_to_be_sent = last_send_time_.is_null();
|
| - last_send_time_ = cast_environment_->Clock()->NowTicks();
|
| - last_sent_frame_id_ = frame_id;
|
| - // If this is the first frame about to be sent, fake the value of
|
| - // |latest_acked_frame_id_| to indicate the receiver starts out all caught up.
|
| - // Also, schedule the periodic frame re-send checks.
|
| - if (is_first_frame_to_be_sent) {
|
| - latest_acked_frame_id_ = frame_id - 1;
|
| - ScheduleNextResendCheck();
|
| - }
|
| -
|
| - cast_environment_->Logging()->InsertEncodedFrameEvent(
|
| - last_send_time_, FRAME_ENCODED, AUDIO_EVENT, encoded_frame->rtp_timestamp,
|
| - frame_id, static_cast<int>(encoded_frame->data.size()),
|
| - encoded_frame->dependency == EncodedFrame::KEY,
|
| - configured_encoder_bitrate_);
|
| -
|
| - RecordLatestFrameTimestamps(frame_id,
|
| - encoded_frame->reference_time,
|
| - encoded_frame->rtp_timestamp);
|
| -
|
| - // At the start of the session, it's important to send reports before each
|
| - // frame so that the receiver can properly compute playout times. The reason
|
| - // more than one report is sent is because transmission is not guaranteed,
|
| - // only best effort, so we send enough that one should almost certainly get
|
| - // through.
|
| - if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) {
|
| - // SendRtcpReport() will schedule future reports to be made if this is the
|
| - // last "aggressive report."
|
| - ++num_aggressive_rtcp_reports_sent_;
|
| - const bool is_last_aggressive_report =
|
| - (num_aggressive_rtcp_reports_sent_ == kNumAggressiveReportsSentAtStart);
|
| - VLOG_IF(1, is_last_aggressive_report) << "Sending last aggressive report.";
|
| - SendRtcpReport(is_last_aggressive_report);
|
| - }
|
| -
|
| - if (send_target_playout_delay_) {
|
| - encoded_frame->new_playout_delay_ms =
|
| - target_playout_delay_.InMilliseconds();
|
| - }
|
| - transport_sender_->InsertFrame(ssrc_, *encoded_frame);
|
| -}
|
| + int64 old_frames_sent =
|
| + samples_sent_to_encoder_ * kAudioFrameRate / rtp_timebase_;
|
| + samples_sent_to_encoder_ += audio_bus->frames();
|
| + int64 new_frames_sent =
|
| + samples_sent_to_encoder_ * kAudioFrameRate / rtp_timebase_;
|
| + frames_in_encoder_ += new_frames_sent - old_frames_sent;
|
|
|
| -void AudioSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) {
|
| - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
|
| -
|
| - if (is_rtt_available()) {
|
| - // Having the RTT values implies the receiver sent back a receiver report
|
| - // based on it having received a report from here. Therefore, ensure this
|
| - // sender stops aggressively sending reports.
|
| - if (num_aggressive_rtcp_reports_sent_ < kNumAggressiveReportsSentAtStart) {
|
| - VLOG(1) << "No longer a need to send reports aggressively (sent "
|
| - << num_aggressive_rtcp_reports_sent_ << ").";
|
| - num_aggressive_rtcp_reports_sent_ = kNumAggressiveReportsSentAtStart;
|
| - ScheduleNextRtcpReport();
|
| - }
|
| - }
|
| -
|
| - if (last_send_time_.is_null())
|
| - return; // Cannot get an ACK without having first sent a frame.
|
| -
|
| - if (cast_feedback.missing_frames_and_packets.empty()) {
|
| - // We only count duplicate ACKs when we have sent newer frames.
|
| - if (latest_acked_frame_id_ == cast_feedback.ack_frame_id &&
|
| - latest_acked_frame_id_ != last_sent_frame_id_) {
|
| - duplicate_ack_counter_++;
|
| - } else {
|
| - duplicate_ack_counter_ = 0;
|
| - }
|
| - // TODO(miu): The values "2" and "3" should be derived from configuration.
|
| - if (duplicate_ack_counter_ >= 2 && duplicate_ack_counter_ % 3 == 2) {
|
| - VLOG(1) << "Received duplicate ACK for frame " << latest_acked_frame_id_;
|
| - ResendForKickstart();
|
| - }
|
| - } else {
|
| - // Only count duplicated ACKs if there is no NACK request in between.
|
| - // This is to avoid aggresive resend.
|
| - duplicate_ack_counter_ = 0;
|
| - }
|
| -
|
| - cast_environment_->Logging()->InsertFrameEvent(
|
| - cast_environment_->Clock()->NowTicks(),
|
| - FRAME_ACK_RECEIVED,
|
| - AUDIO_EVENT,
|
| - GetRecordedRtpTimestamp(cast_feedback.ack_frame_id),
|
| - cast_feedback.ack_frame_id);
|
| -
|
| - const bool is_acked_out_of_order =
|
| - static_cast<int32>(cast_feedback.ack_frame_id -
|
| - latest_acked_frame_id_) < 0;
|
| - VLOG(2) << "Received ACK" << (is_acked_out_of_order ? " out-of-order" : "")
|
| - << " for frame " << cast_feedback.ack_frame_id;
|
| - if (!is_acked_out_of_order) {
|
| - // Cancel resends of acked frames.
|
| - std::vector<uint32> cancel_sending_frames;
|
| - while (latest_acked_frame_id_ != cast_feedback.ack_frame_id) {
|
| - latest_acked_frame_id_++;
|
| - cancel_sending_frames.push_back(latest_acked_frame_id_);
|
| - }
|
| - transport_sender_->CancelSendingFrames(ssrc_, cancel_sending_frames);
|
| - latest_acked_frame_id_ = cast_feedback.ack_frame_id;
|
| - }
|
| + audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time);
|
| }
|
|
|
| -bool AudioSender::ShouldDropNextFrame(base::TimeTicks capture_time) const {
|
| - DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
|
| - int frames_in_flight = 0;
|
| - base::TimeDelta duration_in_flight;
|
| - if (!last_send_time_.is_null()) {
|
| - frames_in_flight =
|
| - static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_);
|
| - if (frames_in_flight > 0) {
|
| - const uint32 oldest_unacked_frame_id = latest_acked_frame_id_ + 1;
|
| - duration_in_flight =
|
| - capture_time - GetRecordedReferenceTime(oldest_unacked_frame_id);
|
| - }
|
| - }
|
| - VLOG(2) << frames_in_flight
|
| - << " frames in flight; last sent: " << last_sent_frame_id_
|
| - << "; latest acked: " << latest_acked_frame_id_
|
| - << "; duration in flight: "
|
| - << duration_in_flight.InMicroseconds() << " usec ("
|
| - << (target_playout_delay_ > base::TimeDelta() ?
|
| - 100 * duration_in_flight / target_playout_delay_ :
|
| - kint64max) << "%)";
|
| - return frames_in_flight >= max_unacked_frames_ ||
|
| - duration_in_flight >= target_playout_delay_;
|
| +void AudioSender::OnAck(uint32 frame_id) {
|
| }
|
|
|
| } // namespace cast
|
|
|