Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/audio/audio_receive_stream.h" | 11 #include "webrtc/audio/audio_receive_stream.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/audio/audio_sink.h" | 16 #include "webrtc/audio/audio_sink.h" |
| 17 #include "webrtc/audio/audio_state.h" | 17 #include "webrtc/audio/audio_state.h" |
| 18 #include "webrtc/audio/conversion.h" | 18 #include "webrtc/audio/conversion.h" |
| 19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/call/congestion_controller.h" | |
| 21 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" |
| 22 #include "webrtc/system_wrappers/include/tick_util.h" | 23 #include "webrtc/system_wrappers/include/tick_util.h" |
| 23 #include "webrtc/voice_engine/channel_proxy.h" | 24 #include "webrtc/voice_engine/channel_proxy.h" |
| 24 #include "webrtc/voice_engine/include/voe_base.h" | 25 #include "webrtc/voice_engine/include/voe_base.h" |
| 25 #include "webrtc/voice_engine/include/voe_codec.h" | 26 #include "webrtc/voice_engine/include/voe_codec.h" |
| 26 #include "webrtc/voice_engine/include/voe_neteq_stats.h" | 27 #include "webrtc/voice_engine/include/voe_neteq_stats.h" |
| 27 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 28 #include "webrtc/voice_engine/include/voe_video_sync.h" | 29 #include "webrtc/voice_engine/include/voe_video_sync.h" |
| 29 #include "webrtc/voice_engine/include/voe_volume_control.h" | 30 #include "webrtc/voice_engine/include/voe_volume_control.h" |
| 30 #include "webrtc/voice_engine/voice_engine_impl.h" | 31 #include "webrtc/voice_engine/voice_engine_impl.h" |
| 31 | 32 |
| 32 namespace webrtc { | 33 namespace webrtc { |
| 34 namespace { | |
| 35 | |
| 36 static bool UseSendSideBwe(const webrtc::AudioReceiveStream::Config& config) { | |
|
the sun
2015/12/22 00:14:14
no need to declare static inside an anonymous name
stefan-webrtc
2016/01/07 13:43:41
Done.
| |
| 37 if (!config.rtp.transport_cc) | |
|
the sun
2015/12/22 00:14:13
nit: This file consistently uses {} for one-line c
stefan-webrtc
2016/01/07 13:43:41
Done.
| |
| 38 return false; | |
| 39 for (const auto& extension : config.rtp.extensions) { | |
| 40 if (extension.name == RtpExtension::kTransportSequenceNumber) | |
| 41 return true; | |
| 42 } | |
| 43 return false; | |
| 44 } | |
| 45 } // namespace | |
| 46 | |
| 33 std::string AudioReceiveStream::Config::Rtp::ToString() const { | 47 std::string AudioReceiveStream::Config::Rtp::ToString() const { |
| 34 std::stringstream ss; | 48 std::stringstream ss; |
| 35 ss << "{remote_ssrc: " << remote_ssrc; | 49 ss << "{remote_ssrc: " << remote_ssrc; |
| 36 ss << ", local_ssrc: " << local_ssrc; | 50 ss << ", local_ssrc: " << local_ssrc; |
| 37 ss << ", extensions: ["; | 51 ss << ", extensions: ["; |
| 38 for (size_t i = 0; i < extensions.size(); ++i) { | 52 for (size_t i = 0; i < extensions.size(); ++i) { |
| 39 ss << extensions[i].ToString(); | 53 ss << extensions[i].ToString(); |
| 40 if (i != extensions.size() - 1) { | 54 if (i != extensions.size() - 1) { |
| 41 ss << ", "; | 55 ss << ", "; |
| 42 } | 56 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 58 ss << ", sync_group: " << sync_group; | 72 ss << ", sync_group: " << sync_group; |
| 59 } | 73 } |
| 60 ss << ", combined_audio_video_bwe: " | 74 ss << ", combined_audio_video_bwe: " |
| 61 << (combined_audio_video_bwe ? "true" : "false"); | 75 << (combined_audio_video_bwe ? "true" : "false"); |
| 62 ss << '}'; | 76 ss << '}'; |
| 63 return ss.str(); | 77 return ss.str(); |
| 64 } | 78 } |
| 65 | 79 |
| 66 namespace internal { | 80 namespace internal { |
| 67 AudioReceiveStream::AudioReceiveStream( | 81 AudioReceiveStream::AudioReceiveStream( |
| 68 RemoteBitrateEstimator* remote_bitrate_estimator, | 82 CongestionController* congestion_controller, |
| 69 const webrtc::AudioReceiveStream::Config& config, | 83 const webrtc::AudioReceiveStream::Config& config, |
| 70 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) | 84 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) |
| 71 : remote_bitrate_estimator_(remote_bitrate_estimator), | 85 : remote_bitrate_estimator_( |
| 86 config.combined_audio_video_bwe | |
| 87 ? congestion_controller->GetRemoteBitrateEstimator( | |
|
the sun
2015/12/22 00:14:14
Why not have two accessor methods on the CC? Sendi
stefan-webrtc
2016/01/07 13:43:40
Yes, I agree that it'd be nicer with two accessors
the sun
2016/01/08 10:29:35
In that case, making the CC ref counted would make
| |
| 88 UseSendSideBwe(config)) | |
| 89 : nullptr), | |
| 72 config_(config), | 90 config_(config), |
| 73 audio_state_(audio_state), | 91 audio_state_(audio_state), |
| 74 rtp_header_parser_(RtpHeaderParser::Create()) { | 92 rtp_header_parser_(RtpHeaderParser::Create()) { |
| 75 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 93 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
| 76 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 94 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 77 RTC_DCHECK(remote_bitrate_estimator_); | |
| 78 RTC_DCHECK(audio_state_.get()); | 95 RTC_DCHECK(audio_state_.get()); |
| 79 RTC_DCHECK(rtp_header_parser_); | 96 RTC_DCHECK(rtp_header_parser_); |
| 80 | 97 |
| 81 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 98 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
| 82 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 99 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
| 83 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); | 100 channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc); |
| 84 for (const auto& extension : config.rtp.extensions) { | 101 for (const auto& extension : config.rtp.extensions) { |
| 85 if (extension.name == RtpExtension::kAudioLevel) { | 102 if (extension.name == RtpExtension::kAudioLevel) { |
| 86 channel_proxy_->SetReceiveAudioLevelIndicationStatus(true, extension.id); | 103 channel_proxy_->SetReceiveAudioLevelIndicationStatus(true, extension.id); |
| 87 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( | 104 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 88 kRtpExtensionAudioLevel, extension.id); | 105 kRtpExtensionAudioLevel, extension.id); |
| 89 RTC_DCHECK(registered); | 106 RTC_DCHECK(registered); |
| 90 } else if (extension.name == RtpExtension::kAbsSendTime) { | 107 } else if (extension.name == RtpExtension::kAbsSendTime) { |
| 91 channel_proxy_->SetReceiveAbsoluteSenderTimeStatus(true, extension.id); | 108 channel_proxy_->SetReceiveAbsoluteSenderTimeStatus(true, extension.id); |
| 92 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( | 109 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 93 kRtpExtensionAbsoluteSendTime, extension.id); | 110 kRtpExtensionAbsoluteSendTime, extension.id); |
| 94 RTC_DCHECK(registered); | 111 RTC_DCHECK(registered); |
| 95 } else if (extension.name == RtpExtension::kTransportSequenceNumber) { | 112 } else if (extension.name == RtpExtension::kTransportSequenceNumber) { |
| 96 // TODO(holmer): Need to do something here or in DeliverRtp() to actually | |
| 97 // handle audio packets with this header extension. | |
| 98 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( | 113 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 99 kRtpExtensionTransportSequenceNumber, extension.id); | 114 kRtpExtensionTransportSequenceNumber, extension.id); |
| 100 RTC_DCHECK(registered); | 115 RTC_DCHECK(registered); |
| 101 } else { | 116 } else { |
| 102 RTC_NOTREACHED() << "Unsupported RTP extension."; | 117 RTC_NOTREACHED() << "Unsupported RTP extension."; |
| 103 } | 118 } |
| 104 } | 119 } |
| 120 if (config.combined_audio_video_bwe && UseSendSideBwe(config)) { | |
| 121 channel_proxy_->SetCongestionControlObjects( | |
|
the sun
2015/12/22 00:14:14
We are relying on the underlying channel *only* be
stefan-webrtc
2016/01/07 13:43:41
Yes, but the packet router is needed both when sen
| |
| 122 nullptr, nullptr, congestion_controller->packet_router()); | |
| 123 } | |
| 105 } | 124 } |
| 106 | 125 |
| 107 AudioReceiveStream::~AudioReceiveStream() { | 126 AudioReceiveStream::~AudioReceiveStream() { |
| 108 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 127 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 128 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
| 129 if (config_.combined_audio_video_bwe) { | |
| 130 if (UseSendSideBwe(config_)) | |
| 131 channel_proxy_->SetCongestionControlObjects(nullptr, nullptr, nullptr); | |
|
the sun
2015/12/22 00:14:13
Can we always set the CC obj nullptrs? Make the co
stefan-webrtc
2016/01/07 13:43:41
Yes, good suggestion.
| |
| 132 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | |
| 133 } | |
| 110 } | 134 } |
| 111 | 135 |
| 112 void AudioReceiveStream::Start() { | 136 void AudioReceiveStream::Start() { |
| 113 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 137 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 } | 138 } |
| 115 | 139 |
| 116 void AudioReceiveStream::Stop() { | 140 void AudioReceiveStream::Stop() { |
| 117 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 141 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 } | 142 } |
| 119 | 143 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 134 const PacketTime& packet_time) { | 158 const PacketTime& packet_time) { |
| 135 // TODO(solenberg): Tests call this function on a network thread, libjingle | 159 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 136 // calls on the worker thread. We should move towards always using a network | 160 // calls on the worker thread. We should move towards always using a network |
| 137 // thread. Then this check can be enabled. | 161 // thread. Then this check can be enabled. |
| 138 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 162 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
| 139 RTPHeader header; | 163 RTPHeader header; |
| 140 if (!rtp_header_parser_->Parse(packet, length, &header)) { | 164 if (!rtp_header_parser_->Parse(packet, length, &header)) { |
| 141 return false; | 165 return false; |
| 142 } | 166 } |
| 143 | 167 |
| 144 // Only forward if the parsed header has absolute sender time. RTP timestamps | 168 // Only forward if the parsed header has one of the headers necessary for |
| 145 // may have different rates for audio and video and shouldn't be mixed. | 169 // bandwidth estimation. RTP timestamps has different rates for audio and |
| 170 // video and shouldn't be mixed. | |
| 146 if (config_.combined_audio_video_bwe && | 171 if (config_.combined_audio_video_bwe && |
| 147 header.extension.hasAbsoluteSendTime) { | 172 (header.extension.hasAbsoluteSendTime || |
| 173 header.extension.hasTransportSequenceNumber)) { | |
|
the sun
2015/12/22 00:14:13
No need to logic-and with confg_.rtp.transport_cc
stefan-webrtc
2016/01/07 13:43:41
I think it's a matter of interpretation. Should au
| |
| 148 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); | 174 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); |
| 149 if (packet_time.timestamp >= 0) | 175 if (packet_time.timestamp >= 0) |
| 150 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 176 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 151 size_t payload_size = length - header.headerLength; | 177 size_t payload_size = length - header.headerLength; |
| 152 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 178 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
| 153 header, false); | 179 header, false); |
| 154 } | 180 } |
| 155 return true; | 181 return true; |
| 156 } | 182 } |
| 157 | 183 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 241 |
| 216 VoiceEngine* AudioReceiveStream::voice_engine() const { | 242 VoiceEngine* AudioReceiveStream::voice_engine() const { |
| 217 internal::AudioState* audio_state = | 243 internal::AudioState* audio_state = |
| 218 static_cast<internal::AudioState*>(audio_state_.get()); | 244 static_cast<internal::AudioState*>(audio_state_.get()); |
| 219 VoiceEngine* voice_engine = audio_state->voice_engine(); | 245 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 220 RTC_DCHECK(voice_engine); | 246 RTC_DCHECK(voice_engine); |
| 221 return voice_engine; | 247 return voice_engine; |
| 222 } | 248 } |
| 223 } // namespace internal | 249 } // namespace internal |
| 224 } // namespace webrtc | 250 } // namespace webrtc |
| OLD | NEW |