2015-04-29 15:24:01 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-09-25 13:58:30 +02:00
|
|
|
#include "webrtc/audio/audio_receive_stream.h"
|
2015-04-29 15:24:01 +02:00
|
|
|
|
|
|
|
|
#include <string>
|
2015-12-12 01:37:01 +01:00
|
|
|
#include <utility>
|
2015-04-29 15:24:01 +02:00
|
|
|
|
2016-02-26 22:46:09 +01:00
|
|
|
#include "webrtc/audio_sink.h"
|
2015-11-06 15:34:49 -08:00
|
|
|
#include "webrtc/audio/audio_state.h"
|
2015-10-22 10:49:27 +02:00
|
|
|
#include "webrtc/audio/conversion.h"
|
2015-04-29 15:24:01 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2015-10-15 05:22:13 -07:00
|
|
|
#include "webrtc/base/logging.h"
|
2016-05-10 16:31:47 +02:00
|
|
|
#include "webrtc/base/timeutils.h"
|
2016-02-23 13:30:42 +01:00
|
|
|
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
|
2015-04-29 15:24:01 +02:00
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
|
2015-11-25 08:16:52 -08:00
|
|
|
#include "webrtc/voice_engine/channel_proxy.h"
|
2015-10-22 10:49:27 +02:00
|
|
|
#include "webrtc/voice_engine/include/voe_base.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_codec.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_neteq_stats.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_video_sync.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_volume_control.h"
|
2015-11-25 08:16:52 -08:00
|
|
|
#include "webrtc/voice_engine/voice_engine_impl.h"
|
2015-04-29 15:24:01 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-01-12 13:55:00 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool UseSendSideBwe(const webrtc::AudioReceiveStream::Config& config) {
|
|
|
|
|
if (!config.rtp.transport_cc) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (const auto& extension : config.rtp.extensions) {
|
2016-05-26 11:24:55 -07:00
|
|
|
if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
|
2016-01-12 13:55:00 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2015-04-29 15:24:01 +02:00
|
|
|
std::string AudioReceiveStream::Config::Rtp::ToString() const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "{remote_ssrc: " << remote_ssrc;
|
2015-10-27 03:35:21 -07:00
|
|
|
ss << ", local_ssrc: " << local_ssrc;
|
2016-06-14 12:13:00 -07:00
|
|
|
ss << ", transport_cc: " << (transport_cc ? "on" : "off");
|
|
|
|
|
ss << ", nack: " << nack.ToString();
|
2015-04-29 15:24:01 +02:00
|
|
|
ss << ", extensions: [";
|
|
|
|
|
for (size_t i = 0; i < extensions.size(); ++i) {
|
|
|
|
|
ss << extensions[i].ToString();
|
2015-10-22 10:49:27 +02:00
|
|
|
if (i != extensions.size() - 1) {
|
2015-04-29 15:24:01 +02:00
|
|
|
ss << ", ";
|
2015-10-22 10:49:27 +02:00
|
|
|
}
|
2015-04-29 15:24:01 +02:00
|
|
|
}
|
|
|
|
|
ss << ']';
|
|
|
|
|
ss << '}';
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string AudioReceiveStream::Config::ToString() const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "{rtp: " << rtp.ToString();
|
2015-10-27 03:35:21 -07:00
|
|
|
ss << ", rtcp_send_transport: "
|
|
|
|
|
<< (rtcp_send_transport ? "(Transport)" : "nullptr");
|
2015-07-15 08:02:58 -07:00
|
|
|
ss << ", voe_channel_id: " << voe_channel_id;
|
2015-10-22 10:49:27 +02:00
|
|
|
if (!sync_group.empty()) {
|
2015-07-15 08:02:58 -07:00
|
|
|
ss << ", sync_group: " << sync_group;
|
2015-10-22 10:49:27 +02:00
|
|
|
}
|
2015-04-29 15:24:01 +02:00
|
|
|
ss << '}';
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
AudioReceiveStream::AudioReceiveStream(
|
2016-01-12 13:55:00 +01:00
|
|
|
CongestionController* congestion_controller,
|
2015-11-06 15:34:49 -08:00
|
|
|
const webrtc::AudioReceiveStream::Config& config,
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
const rtc::scoped_refptr<webrtc::AudioState>& audio_state)
|
2016-01-12 13:55:00 +01:00
|
|
|
: config_(config),
|
2015-11-06 15:34:49 -08:00
|
|
|
audio_state_(audio_state),
|
2015-04-29 15:24:01 +02:00
|
|
|
rtp_header_parser_(RtpHeaderParser::Create()) {
|
2015-10-15 05:22:13 -07:00
|
|
|
LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString();
|
2015-11-06 15:34:49 -08:00
|
|
|
RTC_DCHECK_NE(config_.voe_channel_id, -1);
|
|
|
|
|
RTC_DCHECK(audio_state_.get());
|
2016-01-12 13:55:00 +01:00
|
|
|
RTC_DCHECK(congestion_controller);
|
2015-11-06 15:34:49 -08:00
|
|
|
RTC_DCHECK(rtp_header_parser_);
|
2015-11-20 09:59:34 -08:00
|
|
|
|
2015-11-25 08:16:52 -08:00
|
|
|
VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
|
2016-02-23 10:46:32 -08:00
|
|
|
channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
|
2015-11-25 08:16:52 -08:00
|
|
|
channel_proxy_->SetLocalSSRC(config.rtp.local_ssrc);
|
2016-06-14 12:13:00 -07:00
|
|
|
// TODO(solenberg): Config NACK history window (which is a packet count),
|
|
|
|
|
// using the actual packet size for the configured codec.
|
|
|
|
|
channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0,
|
|
|
|
|
config_.rtp.nack.rtp_history_ms / 20);
|
2016-04-29 00:57:13 -07:00
|
|
|
|
2016-06-13 07:34:51 -07:00
|
|
|
// TODO(ossu): This is where we'd like to set the decoder factory to
|
|
|
|
|
// use. However, since it needs to be included when constructing Channel, we
|
|
|
|
|
// cannot do that until we're able to move Channel ownership into the
|
|
|
|
|
// Audio{Send,Receive}Streams. The best we can do is check that we're not
|
|
|
|
|
// trying to use two different factories using the different interfaces.
|
|
|
|
|
RTC_CHECK(config.decoder_factory);
|
|
|
|
|
RTC_CHECK_EQ(config.decoder_factory,
|
|
|
|
|
channel_proxy_->GetAudioDecoderFactory());
|
|
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
channel_proxy_->RegisterExternalTransport(config.rtcp_send_transport);
|
|
|
|
|
|
2015-11-20 09:59:34 -08:00
|
|
|
for (const auto& extension : config.rtp.extensions) {
|
2016-05-26 11:24:55 -07:00
|
|
|
if (extension.uri == RtpExtension::kAudioLevelUri) {
|
2015-11-27 10:46:42 -08:00
|
|
|
channel_proxy_->SetReceiveAudioLevelIndicationStatus(true, extension.id);
|
2015-11-20 09:59:34 -08:00
|
|
|
bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
|
|
|
|
|
kRtpExtensionAudioLevel, extension.id);
|
|
|
|
|
RTC_DCHECK(registered);
|
2016-05-26 11:24:55 -07:00
|
|
|
} else if (extension.uri == RtpExtension::kAbsSendTimeUri) {
|
2015-11-27 10:46:42 -08:00
|
|
|
channel_proxy_->SetReceiveAbsoluteSenderTimeStatus(true, extension.id);
|
2015-11-20 09:59:34 -08:00
|
|
|
bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
|
|
|
|
|
kRtpExtensionAbsoluteSendTime, extension.id);
|
|
|
|
|
RTC_DCHECK(registered);
|
2016-05-26 11:24:55 -07:00
|
|
|
} else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
|
2016-01-21 06:32:43 -08:00
|
|
|
channel_proxy_->EnableReceiveTransportSequenceNumber(extension.id);
|
2015-11-20 09:59:34 -08:00
|
|
|
bool registered = rtp_header_parser_->RegisterRtpHeaderExtension(
|
|
|
|
|
kRtpExtensionTransportSequenceNumber, extension.id);
|
|
|
|
|
RTC_DCHECK(registered);
|
2015-04-29 15:24:01 +02:00
|
|
|
} else {
|
|
|
|
|
RTC_NOTREACHED() << "Unsupported RTP extension.";
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-12 13:55:00 +01:00
|
|
|
// Configure bandwidth estimation.
|
2016-02-01 04:39:55 -08:00
|
|
|
channel_proxy_->RegisterReceiverCongestionControlObjects(
|
|
|
|
|
congestion_controller->packet_router());
|
2016-02-04 04:12:24 -08:00
|
|
|
if (UseSendSideBwe(config)) {
|
|
|
|
|
remote_bitrate_estimator_ =
|
|
|
|
|
congestion_controller->GetRemoteBitrateEstimator(true);
|
2016-01-12 13:55:00 +01:00
|
|
|
}
|
2015-04-29 15:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-15 05:22:13 -07:00
|
|
|
AudioReceiveStream::~AudioReceiveStream() {
|
2015-10-22 10:49:27 +02:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-10-15 05:22:13 -07:00
|
|
|
LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString();
|
2016-04-29 00:57:13 -07:00
|
|
|
channel_proxy_->DeRegisterExternalTransport();
|
2016-02-01 04:39:55 -08:00
|
|
|
channel_proxy_->ResetCongestionControlObjects();
|
2016-01-12 13:55:00 +01:00
|
|
|
if (remote_bitrate_estimator_) {
|
|
|
|
|
remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc);
|
|
|
|
|
}
|
2015-10-15 05:22:13 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-20 09:59:34 -08:00
|
|
|
void AudioReceiveStream::Start() {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioReceiveStream::Stop() {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 13:04:56 +02:00
|
|
|
webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
|
2015-10-22 10:49:27 +02:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
webrtc::AudioReceiveStream::Stats stats;
|
|
|
|
|
stats.remote_ssrc = config_.rtp.remote_ssrc;
|
2015-11-20 09:59:34 -08:00
|
|
|
ScopedVoEInterface<VoECodec> codec(voice_engine());
|
2015-11-27 10:46:42 -08:00
|
|
|
|
|
|
|
|
webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
|
2015-10-27 03:35:21 -07:00
|
|
|
webrtc::CodecInst codec_inst = {0};
|
2015-11-16 09:48:04 -08:00
|
|
|
if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) {
|
2015-10-22 10:49:27 +02:00
|
|
|
return stats;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-27 03:35:21 -07:00
|
|
|
stats.bytes_rcvd = call_stats.bytesReceived;
|
|
|
|
|
stats.packets_rcvd = call_stats.packetsReceived;
|
|
|
|
|
stats.packets_lost = call_stats.cumulativeLost;
|
|
|
|
|
stats.fraction_lost = Q8ToFloat(call_stats.fractionLost);
|
2015-11-16 09:48:04 -08:00
|
|
|
stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
|
2015-10-27 03:35:21 -07:00
|
|
|
if (codec_inst.pltype != -1) {
|
|
|
|
|
stats.codec_name = codec_inst.plname;
|
2015-10-22 10:49:27 +02:00
|
|
|
}
|
2015-10-27 03:35:21 -07:00
|
|
|
stats.ext_seqnum = call_stats.extendedMax;
|
|
|
|
|
if (codec_inst.plfreq / 1000 > 0) {
|
|
|
|
|
stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000);
|
2015-10-22 10:49:27 +02:00
|
|
|
}
|
2015-11-27 10:46:42 -08:00
|
|
|
stats.delay_estimate_ms = channel_proxy_->GetDelayEstimate();
|
|
|
|
|
stats.audio_level = channel_proxy_->GetSpeechOutputLevelFullRange();
|
2015-10-22 10:49:27 +02:00
|
|
|
|
2015-11-16 09:48:04 -08:00
|
|
|
// Get jitter buffer and total delay (alg + jitter + playout) stats.
|
2015-11-27 10:46:42 -08:00
|
|
|
auto ns = channel_proxy_->GetNetworkStatistics();
|
2015-11-16 09:48:04 -08:00
|
|
|
stats.jitter_buffer_ms = ns.currentBufferSize;
|
|
|
|
|
stats.jitter_buffer_preferred_ms = ns.preferredBufferSize;
|
|
|
|
|
stats.expand_rate = Q14ToFloat(ns.currentExpandRate);
|
|
|
|
|
stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate);
|
|
|
|
|
stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate);
|
|
|
|
|
stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate);
|
|
|
|
|
stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate);
|
2015-10-22 10:49:27 +02:00
|
|
|
|
2015-11-27 10:46:42 -08:00
|
|
|
auto ds = channel_proxy_->GetDecodingCallStatistics();
|
2015-11-16 09:48:04 -08:00
|
|
|
stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator;
|
|
|
|
|
stats.decoding_calls_to_neteq = ds.calls_to_neteq;
|
|
|
|
|
stats.decoding_normal = ds.decoded_normal;
|
|
|
|
|
stats.decoding_plc = ds.decoded_plc;
|
|
|
|
|
stats.decoding_cng = ds.decoded_cng;
|
|
|
|
|
stats.decoding_plc_cng = ds.decoded_plc_cng;
|
2015-10-22 10:49:27 +02:00
|
|
|
|
|
|
|
|
return stats;
|
2015-06-08 13:04:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-23 10:46:32 -08:00
|
|
|
void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
|
2015-12-12 01:37:01 +01:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2016-02-23 10:46:32 -08:00
|
|
|
channel_proxy_->SetSink(std::move(sink));
|
2015-12-12 01:37:01 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-17 08:30:54 -07:00
|
|
|
void AudioReceiveStream::SetGain(float gain) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
channel_proxy_->SetChannelOutputVolumeScaling(gain);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 05:22:13 -07:00
|
|
|
const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
|
2015-10-22 10:49:27 +02:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-10-15 05:22:13 -07:00
|
|
|
return config_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-01 20:18:34 -07:00
|
|
|
void AudioReceiveStream::SignalNetworkState(NetworkState state) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
// TODO(solenberg): Tests call this function on a network thread, libjingle
|
|
|
|
|
// calls on the worker thread. We should move towards always using a network
|
|
|
|
|
// thread. Then this check can be enabled.
|
|
|
|
|
// RTC_DCHECK(!thread_checker_.CalledOnValidThread());
|
|
|
|
|
return channel_proxy_->ReceivedRTCPPacket(packet, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioReceiveStream::DeliverRtp(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
const PacketTime& packet_time) {
|
|
|
|
|
// TODO(solenberg): Tests call this function on a network thread, libjingle
|
|
|
|
|
// calls on the worker thread. We should move towards always using a network
|
|
|
|
|
// thread. Then this check can be enabled.
|
|
|
|
|
// RTC_DCHECK(!thread_checker_.CalledOnValidThread());
|
|
|
|
|
RTPHeader header;
|
|
|
|
|
if (!rtp_header_parser_->Parse(packet, length, &header)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only forward if the parsed header has one of the headers necessary for
|
|
|
|
|
// bandwidth estimation. RTP timestamps has different rates for audio and
|
|
|
|
|
// video and shouldn't be mixed.
|
|
|
|
|
if (remote_bitrate_estimator_ &&
|
|
|
|
|
header.extension.hasTransportSequenceNumber) {
|
2016-05-10 16:31:47 +02:00
|
|
|
int64_t arrival_time_ms = rtc::TimeMillis();
|
2016-05-01 20:18:34 -07:00
|
|
|
if (packet_time.timestamp >= 0)
|
|
|
|
|
arrival_time_ms = (packet_time.timestamp + 500) / 1000;
|
|
|
|
|
size_t payload_size = length - header.headerLength;
|
|
|
|
|
remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
|
2016-06-20 11:53:02 -07:00
|
|
|
header);
|
2016-05-01 20:18:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return channel_proxy_->ReceivedRTPPacket(packet, length, packet_time);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-20 09:59:34 -08:00
|
|
|
VoiceEngine* AudioReceiveStream::voice_engine() const {
|
|
|
|
|
internal::AudioState* audio_state =
|
|
|
|
|
static_cast<internal::AudioState*>(audio_state_.get());
|
|
|
|
|
VoiceEngine* voice_engine = audio_state->voice_engine();
|
|
|
|
|
RTC_DCHECK(voice_engine);
|
|
|
|
|
return voice_engine;
|
2015-04-29 15:24:01 +02:00
|
|
|
}
|
|
|
|
|
} // namespace internal
|
|
|
|
|
} // namespace webrtc
|