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

Unified Diff: media/cast/sender/audio_sender.cc

Issue 545593002: [Cast] Track audio queued in encoder; account for it in ShouldDropNextFrame(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/sender/audio_sender.cc
diff --git a/media/cast/sender/audio_sender.cc b/media/cast/sender/audio_sender.cc
index 9d33bce196eb6e0b4e56f7a805ebd89f3c379965..eaea05f360b01922dd23067ecd27675d27c7e10e 100644
--- a/media/cast/sender/audio_sender.cc
+++ b/media/cast/sender/audio_sender.cc
@@ -36,6 +36,7 @@ AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
kAudioFrameRate * 2.0, // We lie to increase max outstanding frames.
audio_config.target_playout_delay),
configured_encoder_bitrate_(audio_config.bitrate),
+ samples_in_encoder_(0),
weak_factory_(this) {
cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED;
VLOG(1) << "max_unacked_frames " << max_unacked_frames_;
@@ -84,18 +85,34 @@ void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus,
}
DCHECK(audio_encoder_.get()) << "Invalid internal state";
+ // TODO(miu): An |audio_bus| that represents more duration than a single
+ // frame's duration can defeat our logic here, causing too much data to become
+ // enqueued. This will be addressed in a soon-upcoming change.
if (ShouldDropNextFrame(recorded_time)) {
VLOG(1) << "Dropping frame due to too many frames currently in-flight.";
return;
}
+ UpdateEncoderBacklogStats(+audio_bus->frames());
Alpha Left Google 2014/09/05 20:02:06 What's with the '+'?
miu 2014/09/05 20:40:27 Readability thing. Just a helper to see that this
+
audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time);
}
+void AudioSender::UpdateEncoderBacklogStats(int samples_added) {
+ samples_in_encoder_ += samples_added;
+ DCHECK_GE(samples_in_encoder_, 0);
+ frames_in_encoder_ =
+ samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame();
+}
+
void AudioSender::SendEncodedAudioFrame(
- scoped_ptr<EncodedFrame> encoded_frame) {
+ scoped_ptr<EncodedFrame> encoded_frame,
+ int samples_skipped) {
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
+ UpdateEncoderBacklogStats(
+ -(audio_encoder_->GetSamplesPerFrame() + samples_skipped));
+
const uint32 frame_id = encoded_frame->frame_id;
const bool is_first_frame_to_be_sent = last_send_time_.is_null();
@@ -202,30 +219,5 @@ void AudioSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) {
}
}
-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_;
-}
-
} // namespace cast
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698