Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/cast/sender/audio_sender.h" | 5 #include "media/cast/sender/audio_sender.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/cast_defines.h" | 10 #include "media/cast/cast_defines.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 25 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
| 26 const AudioSenderConfig& audio_config, | 26 const AudioSenderConfig& audio_config, |
| 27 CastTransportSender* const transport_sender) | 27 CastTransportSender* const transport_sender) |
| 28 : FrameSender( | 28 : FrameSender( |
| 29 cast_environment, | 29 cast_environment, |
| 30 true, | 30 true, |
| 31 transport_sender, | 31 transport_sender, |
| 32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), | 32 base::TimeDelta::FromMilliseconds(audio_config.rtcp_interval), |
| 33 audio_config.frequency, | 33 audio_config.frequency, |
| 34 audio_config.ssrc, | 34 audio_config.ssrc, |
| 35 kAudioFrameRate * 2.0, // We lie to increase max outstanding frames. | 35 kAudioFrameRate, |
|
hubbe
2014/09/18 17:56:05
Does we still give more buffer to audio, or do you
miu
2014/09/18 21:38:43
Not needed. According to the simulation data, the
| |
| 36 audio_config.min_playout_delay, | 36 audio_config.min_playout_delay, |
| 37 audio_config.max_playout_delay, | 37 audio_config.max_playout_delay, |
| 38 NewFixedCongestionControl(audio_config.bitrate)), | 38 NewFixedCongestionControl(audio_config.bitrate)), |
| 39 samples_in_encoder_(0), | 39 samples_in_encoder_(0), |
| 40 weak_factory_(this) { | 40 weak_factory_(this) { |
| 41 cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED; | 41 cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED; |
| 42 VLOG(1) << "max_unacked_frames " << max_unacked_frames_; | 42 VLOG(1) << "max_unacked_frames " << max_unacked_frames_; |
| 43 DCHECK_GT(max_unacked_frames_, 0); | 43 DCHECK_GT(max_unacked_frames_, 0); |
| 44 | 44 |
| 45 if (!audio_config.use_external_encoder) { | 45 if (!audio_config.use_external_encoder) { |
| 46 audio_encoder_.reset( | 46 audio_encoder_.reset( |
| 47 new AudioEncoder(cast_environment, | 47 new AudioEncoder(cast_environment, |
| 48 audio_config.channels, | 48 audio_config.channels, |
| 49 audio_config.frequency, | 49 audio_config.frequency, |
| 50 audio_config.bitrate, | 50 audio_config.bitrate, |
| 51 audio_config.codec, | 51 audio_config.codec, |
| 52 base::Bind(&AudioSender::OnEncodedAudioFrame, | 52 base::Bind(&AudioSender::OnEncodedAudioFrame, |
| 53 weak_factory_.GetWeakPtr(), | 53 weak_factory_.GetWeakPtr(), |
| 54 audio_config.bitrate))); | 54 audio_config.bitrate))); |
| 55 cast_initialization_status_ = audio_encoder_->InitializationResult(); | 55 cast_initialization_status_ = audio_encoder_->InitializationResult(); |
| 56 } else { | 56 } else { |
| 57 NOTREACHED(); // No support for external audio encoding. | 57 NOTREACHED(); // No support for external audio encoding. |
| 58 cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED; | 58 cast_initialization_status_ = STATUS_AUDIO_UNINITIALIZED; |
| 59 } | 59 } |
| 60 | 60 |
| 61 media::cast::CastTransportRtpConfig transport_config; | 61 media::cast::CastTransportRtpConfig transport_config; |
| 62 transport_config.ssrc = audio_config.ssrc; | 62 transport_config.ssrc = audio_config.ssrc; |
| 63 transport_config.feedback_ssrc = audio_config.incoming_feedback_ssrc; | 63 transport_config.feedback_ssrc = audio_config.incoming_feedback_ssrc; |
| 64 transport_config.rtp_payload_type = audio_config.rtp_payload_type; | 64 transport_config.rtp_payload_type = audio_config.rtp_payload_type; |
| 65 transport_config.stored_frames = | |
| 66 std::min(kMaxUnackedFrames, | |
| 67 1 + static_cast<int>(max_playout_delay_ * | |
| 68 max_frame_rate_ / | |
| 69 base::TimeDelta::FromSeconds(1))); | |
| 70 transport_config.aes_key = audio_config.aes_key; | 65 transport_config.aes_key = audio_config.aes_key; |
| 71 transport_config.aes_iv_mask = audio_config.aes_iv_mask; | 66 transport_config.aes_iv_mask = audio_config.aes_iv_mask; |
| 72 | 67 |
| 73 transport_sender->InitializeAudio( | 68 transport_sender->InitializeAudio( |
| 74 transport_config, | 69 transport_config, |
| 75 base::Bind(&AudioSender::OnReceivedCastFeedback, | 70 base::Bind(&AudioSender::OnReceivedCastFeedback, |
| 76 weak_factory_.GetWeakPtr()), | 71 weak_factory_.GetWeakPtr()), |
| 77 base::Bind(&AudioSender::OnMeasuredRoundTripTime, | 72 base::Bind(&AudioSender::OnMeasuredRoundTripTime, |
| 78 weak_factory_.GetWeakPtr())); | 73 weak_factory_.GetWeakPtr())); |
| 79 } | 74 } |
| 80 | 75 |
| 81 AudioSender::~AudioSender() {} | 76 AudioSender::~AudioSender() {} |
| 82 | 77 |
| 83 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, | 78 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
| 84 const base::TimeTicks& recorded_time) { | 79 const base::TimeTicks& recorded_time) { |
| 85 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 80 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 86 if (cast_initialization_status_ != STATUS_AUDIO_INITIALIZED) { | 81 if (cast_initialization_status_ != STATUS_AUDIO_INITIALIZED) { |
| 87 NOTREACHED(); | 82 NOTREACHED(); |
| 88 return; | 83 return; |
| 89 } | 84 } |
| 90 DCHECK(audio_encoder_.get()) << "Invalid internal state"; | 85 DCHECK(audio_encoder_.get()) << "Invalid internal state"; |
| 91 | 86 |
| 92 // TODO(miu): An |audio_bus| that represents more duration than a single | 87 const base::TimeDelta next_frame_duration = |
| 93 // frame's duration can defeat our logic here, causing too much data to become | 88 RtpDeltaToTimeDelta(audio_bus->frames(), rtp_timebase()); |
| 94 // enqueued. This will be addressed in a soon-upcoming change. | 89 if (ShouldDropNextFrame(next_frame_duration)) |
| 95 if (ShouldDropNextFrame(recorded_time)) { | |
| 96 VLOG(1) << "Dropping frame due to too many frames currently in-flight."; | |
| 97 return; | 90 return; |
| 98 } | |
| 99 | 91 |
| 100 samples_in_encoder_ += audio_bus->frames(); | 92 samples_in_encoder_ += audio_bus->frames(); |
| 101 | 93 |
| 102 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); | 94 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); |
| 103 } | 95 } |
| 104 | 96 |
| 105 int AudioSender::GetNumberOfFramesInEncoder() const { | 97 int AudioSender::GetNumberOfFramesInEncoder() const { |
| 106 // Note: It's possible for a partial frame to be in the encoder, but returning | 98 // Note: It's possible for a partial frame to be in the encoder, but returning |
| 107 // the floor() is good enough for the "design limit" check in FrameSender. | 99 // the floor() is good enough for the "design limit" check in FrameSender. |
| 108 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); | 100 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); |
| 109 } | 101 } |
| 110 | 102 |
| 103 base::TimeDelta AudioSender::GetInFlightMediaDuration() const { | |
| 104 const int samples_in_flight = samples_in_encoder_ + | |
| 105 GetUnacknowledgedFrameCount() * audio_encoder_->GetSamplesPerFrame(); | |
| 106 return RtpDeltaToTimeDelta(samples_in_flight, rtp_timebase()); | |
| 107 } | |
| 108 | |
| 111 void AudioSender::OnAck(uint32 frame_id) { | 109 void AudioSender::OnAck(uint32 frame_id) { |
| 112 } | 110 } |
| 113 | 111 |
| 114 void AudioSender::OnEncodedAudioFrame( | 112 void AudioSender::OnEncodedAudioFrame( |
| 115 int encoder_bitrate, | 113 int encoder_bitrate, |
| 116 scoped_ptr<EncodedFrame> encoded_frame, | 114 scoped_ptr<EncodedFrame> encoded_frame, |
| 117 int samples_skipped) { | 115 int samples_skipped) { |
| 118 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 116 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 119 | 117 |
| 120 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; | 118 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; |
| 121 DCHECK_GE(samples_in_encoder_, 0); | 119 DCHECK_GE(samples_in_encoder_, 0); |
| 122 | 120 |
| 123 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 121 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
| 124 } | 122 } |
| 125 | 123 |
| 126 } // namespace cast | 124 } // namespace cast |
| 127 } // namespace media | 125 } // namespace media |
| OLD | NEW |