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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "media/cast/common/rtp_time.h" | 13 #include "media/cast/common/rtp_time.h" |
| 13 #include "media/cast/net/cast_transport_config.h" | 14 #include "media/cast/net/cast_transport_config.h" |
| 14 #include "media/cast/sender/audio_encoder.h" | 15 #include "media/cast/sender/audio_encoder.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 namespace cast { | 18 namespace cast { |
| 18 | 19 |
| 20 namespace { | |
| 21 | |
| 22 class AudioSenderRtcpClient : public RtpSenderRtcpClient { | |
|
miu
2016/04/15 23:14:39
This is duplicate code (same as in VideoSender).
xjz
2016/04/20 01:09:03
Done.
| |
| 23 public: | |
| 24 explicit AudioSenderRtcpClient(base::WeakPtr<AudioSender> audio_sender) | |
| 25 : audio_sender_(audio_sender) {} | |
| 26 | |
| 27 void OnCastMessageReceived(const RtcpCastMessage& cast_message) override { | |
| 28 if (audio_sender_) | |
| 29 audio_sender_->OnReceivedCastFeedback(cast_message); | |
| 30 } | |
| 31 | |
| 32 void OnRttReceived(base::TimeDelta round_trip_time) override { | |
| 33 if (audio_sender_) | |
| 34 audio_sender_->OnMeasuredRoundTripTime(round_trip_time); | |
| 35 } | |
| 36 | |
| 37 void OnPliReceived() override { | |
| 38 if (audio_sender_) | |
| 39 audio_sender_->OnReceivedPli(); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 base::WeakPtr<AudioSender> audio_sender_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(AudioSenderRtcpClient); | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 19 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 50 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
| 20 const AudioSenderConfig& audio_config, | 51 const AudioSenderConfig& audio_config, |
| 21 const StatusChangeCallback& status_change_cb, | 52 const StatusChangeCallback& status_change_cb, |
| 22 CastTransport* const transport_sender) | 53 CastTransport* const transport_sender) |
| 23 : FrameSender(cast_environment, | 54 : FrameSender(cast_environment, |
| 24 true, | 55 true, |
| 25 transport_sender, | 56 transport_sender, |
| 26 audio_config.frequency, | 57 audio_config.frequency, |
| 27 audio_config.ssrc, | 58 audio_config.ssrc, |
| 28 0, // |max_frame_rate_| is set after encoder initialization. | 59 0, // |max_frame_rate_| is set after encoder initialization. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 audio_config.frequency / audio_encoder_->GetSamplesPerFrame(); | 92 audio_config.frequency / audio_encoder_->GetSamplesPerFrame(); |
| 62 | 93 |
| 63 media::cast::CastTransportRtpConfig transport_config; | 94 media::cast::CastTransportRtpConfig transport_config; |
| 64 transport_config.ssrc = audio_config.ssrc; | 95 transport_config.ssrc = audio_config.ssrc; |
| 65 transport_config.feedback_ssrc = audio_config.receiver_ssrc; | 96 transport_config.feedback_ssrc = audio_config.receiver_ssrc; |
| 66 transport_config.rtp_payload_type = audio_config.rtp_payload_type; | 97 transport_config.rtp_payload_type = audio_config.rtp_payload_type; |
| 67 transport_config.aes_key = audio_config.aes_key; | 98 transport_config.aes_key = audio_config.aes_key; |
| 68 transport_config.aes_iv_mask = audio_config.aes_iv_mask; | 99 transport_config.aes_iv_mask = audio_config.aes_iv_mask; |
| 69 | 100 |
| 70 transport_sender->InitializeAudio( | 101 transport_sender->InitializeAudio( |
| 71 transport_config, base::Bind(&AudioSender::OnReceivedCastFeedback, | 102 transport_config, |
| 72 weak_factory_.GetWeakPtr()), | 103 base::WrapUnique(new AudioSenderRtcpClient(weak_factory_.GetWeakPtr()))); |
| 73 base::Bind(&AudioSender::OnMeasuredRoundTripTime, | |
| 74 weak_factory_.GetWeakPtr()), | |
| 75 base::Bind(&AudioSender::OnReceivedPli, weak_factory_.GetWeakPtr())); | |
| 76 } | 104 } |
| 77 | 105 |
| 78 AudioSender::~AudioSender() {} | 106 AudioSender::~AudioSender() {} |
| 79 | 107 |
| 80 void AudioSender::InsertAudio(scoped_ptr<AudioBus> audio_bus, | 108 void AudioSender::InsertAudio(std::unique_ptr<AudioBus> audio_bus, |
| 81 const base::TimeTicks& recorded_time) { | 109 const base::TimeTicks& recorded_time) { |
| 82 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 110 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 83 | 111 |
| 84 if (!audio_encoder_) { | 112 if (!audio_encoder_) { |
| 85 NOTREACHED(); | 113 NOTREACHED(); |
| 86 return; | 114 return; |
| 87 } | 115 } |
| 88 | 116 |
| 89 const base::TimeDelta next_frame_duration = | 117 const base::TimeDelta next_frame_duration = |
| 90 RtpTimeDelta::FromTicks(audio_bus->frames()).ToTimeDelta(rtp_timebase()); | 118 RtpTimeDelta::FromTicks(audio_bus->frames()).ToTimeDelta(rtp_timebase()); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 115 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 143 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 116 | 144 |
| 117 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; | 145 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; |
| 118 DCHECK_GE(samples_in_encoder_, 0); | 146 DCHECK_GE(samples_in_encoder_, 0); |
| 119 | 147 |
| 120 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 148 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
| 121 } | 149 } |
| 122 | 150 |
| 123 } // namespace cast | 151 } // namespace cast |
| 124 } // namespace media | 152 } // namespace media |
| OLD | NEW |