| 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/common/rtp_time.h" |
| 10 #include "media/cast/net/cast_transport_config.h" | 11 #include "media/cast/net/cast_transport_config.h" |
| 11 #include "media/cast/sender/audio_encoder.h" | 12 #include "media/cast/sender/audio_encoder.h" |
| 12 | 13 |
| 13 namespace media { | 14 namespace media { |
| 14 namespace cast { | 15 namespace cast { |
| 15 | 16 |
| 16 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 17 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
| 17 const AudioSenderConfig& audio_config, | 18 const AudioSenderConfig& audio_config, |
| 18 const StatusChangeCallback& status_change_cb, | 19 const StatusChangeCallback& status_change_cb, |
| 19 CastTransportSender* const transport_sender) | 20 CastTransportSender* const transport_sender) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, | 78 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
| 78 const base::TimeTicks& recorded_time) { | 79 const base::TimeTicks& recorded_time) { |
| 79 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 80 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 80 | 81 |
| 81 if (!audio_encoder_) { | 82 if (!audio_encoder_) { |
| 82 NOTREACHED(); | 83 NOTREACHED(); |
| 83 return; | 84 return; |
| 84 } | 85 } |
| 85 | 86 |
| 86 const base::TimeDelta next_frame_duration = | 87 const base::TimeDelta next_frame_duration = |
| 87 RtpDeltaToTimeDelta(audio_bus->frames(), rtp_timebase()); | 88 RtpTimeDelta::FromTicks(audio_bus->frames()).ToTimeDelta(rtp_timebase()); |
| 88 if (ShouldDropNextFrame(next_frame_duration)) | 89 if (ShouldDropNextFrame(next_frame_duration)) |
| 89 return; | 90 return; |
| 90 | 91 |
| 91 samples_in_encoder_ += audio_bus->frames(); | 92 samples_in_encoder_ += audio_bus->frames(); |
| 92 | 93 |
| 93 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); | 94 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); |
| 94 } | 95 } |
| 95 | 96 |
| 96 int AudioSender::GetNumberOfFramesInEncoder() const { | 97 int AudioSender::GetNumberOfFramesInEncoder() const { |
| 97 // 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 |
| 98 // 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. |
| 99 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); | 100 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 base::TimeDelta AudioSender::GetInFlightMediaDuration() const { | 103 base::TimeDelta AudioSender::GetInFlightMediaDuration() const { |
| 103 const int samples_in_flight = samples_in_encoder_ + | 104 const int samples_in_flight = samples_in_encoder_ + |
| 104 GetUnacknowledgedFrameCount() * audio_encoder_->GetSamplesPerFrame(); | 105 GetUnacknowledgedFrameCount() * audio_encoder_->GetSamplesPerFrame(); |
| 105 return RtpDeltaToTimeDelta(samples_in_flight, rtp_timebase()); | 106 return RtpTimeDelta::FromTicks(samples_in_flight).ToTimeDelta(rtp_timebase()); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void AudioSender::OnEncodedAudioFrame( | 109 void AudioSender::OnEncodedAudioFrame( |
| 109 int encoder_bitrate, | 110 int encoder_bitrate, |
| 110 scoped_ptr<SenderEncodedFrame> encoded_frame, | 111 scoped_ptr<SenderEncodedFrame> encoded_frame, |
| 111 int samples_skipped) { | 112 int samples_skipped) { |
| 112 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 113 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 113 | 114 |
| 114 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; | 115 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; |
| 115 DCHECK_GE(samples_in_encoder_, 0); | 116 DCHECK_GE(samples_in_encoder_, 0); |
| 116 | 117 |
| 117 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 118 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace cast | 121 } // namespace cast |
| 121 } // namespace media | 122 } // namespace media |
| OLD | NEW |