| 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 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) | 66 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) |
| 67 : remote_bitrate_estimator_(remote_bitrate_estimator), | 67 : remote_bitrate_estimator_(remote_bitrate_estimator), |
| 68 config_(config), | 68 config_(config), |
| 69 audio_state_(audio_state), | 69 audio_state_(audio_state), |
| 70 rtp_header_parser_(RtpHeaderParser::Create()) { | 70 rtp_header_parser_(RtpHeaderParser::Create()) { |
| 71 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 71 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
| 72 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 72 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 73 RTC_DCHECK(remote_bitrate_estimator_); | 73 RTC_DCHECK(remote_bitrate_estimator_); |
| 74 RTC_DCHECK(audio_state_.get()); | 74 RTC_DCHECK(audio_state_.get()); |
| 75 RTC_DCHECK(rtp_header_parser_); | 75 RTC_DCHECK(rtp_header_parser_); |
| 76 for (const auto& ext : config.rtp.extensions) { | 76 |
| 77 const int channel_id = config.voe_channel_id; |
| 78 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine()); |
| 79 int error = rtp->SetLocalSSRC(channel_id, config.rtp.local_ssrc); |
| 80 RTC_DCHECK_EQ(0, error); |
| 81 for (const auto& extension : config.rtp.extensions) { |
| 77 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 82 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
| 78 RTC_DCHECK_GE(ext.id, 1); | 83 RTC_DCHECK_GE(extension.id, 1); |
| 79 RTC_DCHECK_LE(ext.id, 14); | 84 RTC_DCHECK_LE(extension.id, 14); |
| 80 if (ext.name == RtpExtension::kAudioLevel) { | 85 if (extension.name == RtpExtension::kAudioLevel) { |
| 81 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 86 error = rtp->SetReceiveAudioLevelIndicationStatus(channel_id, true, |
| 82 kRtpExtensionAudioLevel, ext.id)); | 87 extension.id); |
| 83 } else if (ext.name == RtpExtension::kAbsSendTime) { | 88 RTC_DCHECK_EQ(0, error); |
| 84 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 89 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 85 kRtpExtensionAbsoluteSendTime, ext.id)); | 90 kRtpExtensionAudioLevel, extension.id); |
| 86 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { | 91 RTC_DCHECK(registered); |
| 87 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 92 } else if (extension.name == RtpExtension::kAbsSendTime) { |
| 88 kRtpExtensionTransportSequenceNumber, ext.id)); | 93 error = rtp->SetReceiveAbsoluteSenderTimeStatus(channel_id, true, |
| 94 extension.id); |
| 95 RTC_DCHECK_EQ(0, error); |
| 96 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 97 kRtpExtensionAbsoluteSendTime, extension.id); |
| 98 RTC_DCHECK(registered); |
| 99 } else if (extension.name == RtpExtension::kTransportSequenceNumber) { |
| 100 // TODO(holmer): Need to do something here or in DeliverRtp() to actually |
| 101 // handle audio packets with this header extension. |
| 102 bool registered = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 103 kRtpExtensionTransportSequenceNumber, extension.id); |
| 104 RTC_DCHECK(registered); |
| 89 } else { | 105 } else { |
| 90 RTC_NOTREACHED() << "Unsupported RTP extension."; | 106 RTC_NOTREACHED() << "Unsupported RTP extension."; |
| 91 } | 107 } |
| 92 } | 108 } |
| 93 } | 109 } |
| 94 | 110 |
| 95 AudioReceiveStream::~AudioReceiveStream() { | 111 AudioReceiveStream::~AudioReceiveStream() { |
| 96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 112 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 113 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
| 98 } | 114 } |
| 99 | 115 |
| 116 void AudioReceiveStream::Start() { |
| 117 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 } |
| 119 |
| 120 void AudioReceiveStream::Stop() { |
| 121 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 122 } |
| 123 |
| 124 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
| 125 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 126 } |
| 127 |
| 128 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 129 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 130 // calls on the worker thread. We should move towards always using a network |
| 131 // thread. Then this check can be enabled. |
| 132 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
| 133 return false; |
| 134 } |
| 135 |
| 136 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, |
| 137 size_t length, |
| 138 const PacketTime& packet_time) { |
| 139 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 140 // calls on the worker thread. We should move towards always using a network |
| 141 // thread. Then this check can be enabled. |
| 142 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
| 143 RTPHeader header; |
| 144 if (!rtp_header_parser_->Parse(packet, length, &header)) { |
| 145 return false; |
| 146 } |
| 147 |
| 148 // Only forward if the parsed header has absolute sender time. RTP timestamps |
| 149 // may have different rates for audio and video and shouldn't be mixed. |
| 150 if (config_.combined_audio_video_bwe && |
| 151 header.extension.hasAbsoluteSendTime) { |
| 152 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); |
| 153 if (packet_time.timestamp >= 0) |
| 154 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 155 size_t payload_size = length - header.headerLength; |
| 156 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
| 157 header, false); |
| 158 } |
| 159 return true; |
| 160 } |
| 161 |
| 100 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 162 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
| 101 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 163 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 webrtc::AudioReceiveStream::Stats stats; | 164 webrtc::AudioReceiveStream::Stats stats; |
| 103 stats.remote_ssrc = config_.rtp.remote_ssrc; | 165 stats.remote_ssrc = config_.rtp.remote_ssrc; |
| 104 internal::AudioState* audio_state = | 166 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
| 105 static_cast<internal::AudioState*>(audio_state_.get()); | 167 ScopedVoEInterface<VoENetEqStats> neteq(voice_engine()); |
| 106 VoiceEngine* voice_engine = audio_state->voice_engine(); | 168 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine()); |
| 107 ScopedVoEInterface<VoECodec> codec(voice_engine); | 169 ScopedVoEInterface<VoEVideoSync> sync(voice_engine()); |
| 108 ScopedVoEInterface<VoENetEqStats> neteq(voice_engine); | 170 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine()); |
| 109 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine); | |
| 110 ScopedVoEInterface<VoEVideoSync> sync(voice_engine); | |
| 111 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine); | |
| 112 | 171 |
| 113 webrtc::CallStatistics call_stats = {0}; | 172 webrtc::CallStatistics call_stats = {0}; |
| 114 int error = rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats); | 173 int error = rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats); |
| 115 RTC_DCHECK_EQ(0, error); | 174 RTC_DCHECK_EQ(0, error); |
| 116 webrtc::CodecInst codec_inst = {0}; | 175 webrtc::CodecInst codec_inst = {0}; |
| 117 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 176 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
| 118 return stats; | 177 return stats; |
| 119 } | 178 } |
| 120 | 179 |
| 121 stats.bytes_rcvd = call_stats.bytesReceived; | 180 stats.bytes_rcvd = call_stats.bytesReceived; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 stats.decoding_plc_cng = ds.decoded_plc_cng; | 227 stats.decoding_plc_cng = ds.decoded_plc_cng; |
| 169 | 228 |
| 170 return stats; | 229 return stats; |
| 171 } | 230 } |
| 172 | 231 |
| 173 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 232 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
| 174 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 233 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 175 return config_; | 234 return config_; |
| 176 } | 235 } |
| 177 | 236 |
| 178 void AudioReceiveStream::Start() { | 237 VoiceEngine* AudioReceiveStream::voice_engine() const { |
| 179 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 238 internal::AudioState* audio_state = |
| 180 } | 239 static_cast<internal::AudioState*>(audio_state_.get()); |
| 181 | 240 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 182 void AudioReceiveStream::Stop() { | 241 RTC_DCHECK(voice_engine); |
| 183 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 242 return voice_engine; |
| 184 } | |
| 185 | |
| 186 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | |
| 187 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 188 } | |
| 189 | |
| 190 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | |
| 191 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
| 192 // calls on the worker thread. We should move towards always using a network | |
| 193 // thread. Then this check can be enabled. | |
| 194 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
| 195 return false; | |
| 196 } | |
| 197 | |
| 198 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, | |
| 199 size_t length, | |
| 200 const PacketTime& packet_time) { | |
| 201 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
| 202 // calls on the worker thread. We should move towards always using a network | |
| 203 // thread. Then this check can be enabled. | |
| 204 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
| 205 RTPHeader header; | |
| 206 if (!rtp_header_parser_->Parse(packet, length, &header)) { | |
| 207 return false; | |
| 208 } | |
| 209 | |
| 210 // Only forward if the parsed header has absolute sender time. RTP timestamps | |
| 211 // may have different rates for audio and video and shouldn't be mixed. | |
| 212 if (config_.combined_audio_video_bwe && | |
| 213 header.extension.hasAbsoluteSendTime) { | |
| 214 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); | |
| 215 if (packet_time.timestamp >= 0) | |
| 216 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | |
| 217 size_t payload_size = length - header.headerLength; | |
| 218 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | |
| 219 header, false); | |
| 220 } | |
| 221 return true; | |
| 222 } | 243 } |
| 223 } // namespace internal | 244 } // namespace internal |
| 224 } // namespace webrtc | 245 } // namespace webrtc |
| OLD | NEW |