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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, | 77 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, |
77 const base::TimeTicks& recorded_time) { | 78 const base::TimeTicks& recorded_time) { |
78 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 79 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
79 | 80 |
80 if (!audio_encoder_) { | 81 if (!audio_encoder_) { |
81 NOTREACHED(); | 82 NOTREACHED(); |
82 return; | 83 return; |
83 } | 84 } |
84 | 85 |
85 const base::TimeDelta next_frame_duration = | 86 const base::TimeDelta next_frame_duration = |
86 RtpDeltaToTimeDelta(audio_bus->frames(), rtp_timebase()); | 87 RtpTimeDelta::FromTicks(audio_bus->frames()).ToTimeDelta(rtp_timebase()); |
87 if (ShouldDropNextFrame(next_frame_duration)) | 88 if (ShouldDropNextFrame(next_frame_duration)) |
88 return; | 89 return; |
89 | 90 |
90 samples_in_encoder_ += audio_bus->frames(); | 91 samples_in_encoder_ += audio_bus->frames(); |
91 | 92 |
92 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); | 93 audio_encoder_->InsertAudio(audio_bus.Pass(), recorded_time); |
93 } | 94 } |
94 | 95 |
95 int AudioSender::GetNumberOfFramesInEncoder() const { | 96 int AudioSender::GetNumberOfFramesInEncoder() const { |
96 // Note: It's possible for a partial frame to be in the encoder, but returning | 97 // Note: It's possible for a partial frame to be in the encoder, but returning |
97 // the floor() is good enough for the "design limit" check in FrameSender. | 98 // the floor() is good enough for the "design limit" check in FrameSender. |
98 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); | 99 return samples_in_encoder_ / audio_encoder_->GetSamplesPerFrame(); |
99 } | 100 } |
100 | 101 |
101 base::TimeDelta AudioSender::GetInFlightMediaDuration() const { | 102 base::TimeDelta AudioSender::GetInFlightMediaDuration() const { |
102 const int samples_in_flight = samples_in_encoder_ + | 103 const int samples_in_flight = samples_in_encoder_ + |
103 GetUnacknowledgedFrameCount() * audio_encoder_->GetSamplesPerFrame(); | 104 GetUnacknowledgedFrameCount() * audio_encoder_->GetSamplesPerFrame(); |
104 return RtpDeltaToTimeDelta(samples_in_flight, rtp_timebase()); | 105 return RtpTimeDelta::FromTicks(samples_in_flight).ToTimeDelta(rtp_timebase()); |
105 } | 106 } |
106 | 107 |
107 void AudioSender::OnEncodedAudioFrame( | 108 void AudioSender::OnEncodedAudioFrame( |
108 int encoder_bitrate, | 109 int encoder_bitrate, |
109 scoped_ptr<SenderEncodedFrame> encoded_frame, | 110 scoped_ptr<SenderEncodedFrame> encoded_frame, |
110 int samples_skipped) { | 111 int samples_skipped) { |
111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 112 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
112 | 113 |
113 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; | 114 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; |
114 DCHECK_GE(samples_in_encoder_, 0); | 115 DCHECK_GE(samples_in_encoder_, 0); |
115 | 116 |
116 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 117 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
117 } | 118 } |
118 | 119 |
119 } // namespace cast | 120 } // namespace cast |
120 } // namespace media | 121 } // namespace media |
OLD | NEW |