2018-10-04 14:28:39 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "audio/channel_receive.h"
|
|
|
|
|
|
2019-10-28 18:12:51 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2019-09-02 15:16:49 +02:00
|
|
|
#include "api/crypto/frame_decryptor_interface.h"
|
2020-04-01 07:46:16 +02:00
|
|
|
#include "api/frame_transformer_interface.h"
|
2019-08-07 12:24:53 +02:00
|
|
|
#include "api/rtc_event_log/rtc_event_log.h"
|
2018-11-16 09:50:42 +01:00
|
|
|
#include "audio/audio_level.h"
|
2020-04-01 10:19:44 +02:00
|
|
|
#include "audio/channel_receive_frame_transformer_delegate.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "audio/channel_send.h"
|
|
|
|
|
#include "audio/utility/audio_frame_operations.h"
|
|
|
|
|
#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
|
2019-07-30 15:15:59 +02:00
|
|
|
#include "modules/audio_coding/acm2/acm_receiver.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h"
|
|
|
|
|
#include "modules/audio_device/include/audio_device.h"
|
|
|
|
|
#include "modules/pacing/packet_router.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/receive_statistics.h"
|
2018-11-16 09:50:42 +01:00
|
|
|
#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
|
2020-02-11 13:04:02 +01:00
|
|
|
#include "modules/rtp_rtcp/source/absolute_capture_time_receiver.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
2018-12-04 18:03:52 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
2020-06-03 08:54:39 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "modules/utility/include/process_thread.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/format_macros.h"
|
|
|
|
|
#include "rtc_base/location.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2018-11-16 09:50:42 +01:00
|
|
|
#include "rtc_base/numerics/safe_minmax.h"
|
|
|
|
|
#include "rtc_base/race_checker.h"
|
2020-07-06 15:15:07 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "rtc_base/thread_checker.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-10-04 14:28:39 +02:00
|
|
|
#include "system_wrappers/include/metrics.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace voe {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr double kAudioSampleDurationSeconds = 0.01;
|
|
|
|
|
|
|
|
|
|
// Video Sync.
|
|
|
|
|
constexpr int kVoiceEngineMinMinPlayoutDelayMs = 0;
|
|
|
|
|
constexpr int kVoiceEngineMaxMinPlayoutDelayMs = 10000;
|
|
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
AudioCodingModule::Config AcmConfig(
|
2019-11-01 11:47:51 +01:00
|
|
|
NetEqFactory* neteq_factory,
|
2019-07-30 15:15:59 +02:00
|
|
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
|
|
|
|
absl::optional<AudioCodecPairId> codec_pair_id,
|
|
|
|
|
size_t jitter_buffer_max_packets,
|
|
|
|
|
bool jitter_buffer_fast_playout) {
|
|
|
|
|
AudioCodingModule::Config acm_config;
|
2019-11-01 11:47:51 +01:00
|
|
|
acm_config.neteq_factory = neteq_factory;
|
2019-07-30 15:15:59 +02:00
|
|
|
acm_config.decoder_factory = decoder_factory;
|
|
|
|
|
acm_config.neteq_config.codec_pair_id = codec_pair_id;
|
|
|
|
|
acm_config.neteq_config.max_packets_in_buffer = jitter_buffer_max_packets;
|
|
|
|
|
acm_config.neteq_config.enable_fast_accelerate = jitter_buffer_fast_playout;
|
|
|
|
|
acm_config.neteq_config.enable_muted_state = true;
|
|
|
|
|
|
|
|
|
|
return acm_config;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 09:19:40 -08:00
|
|
|
class ChannelReceive : public ChannelReceiveInterface {
|
2018-11-16 09:50:42 +01:00
|
|
|
public:
|
|
|
|
|
// Used for receive streams.
|
2020-04-01 07:46:16 +02:00
|
|
|
ChannelReceive(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
ProcessThread* module_process_thread,
|
|
|
|
|
NetEqFactory* neteq_factory,
|
|
|
|
|
AudioDeviceModule* audio_device_module,
|
|
|
|
|
Transport* rtcp_send_transport,
|
|
|
|
|
RtcEventLog* rtc_event_log,
|
|
|
|
|
uint32_t local_ssrc,
|
|
|
|
|
uint32_t remote_ssrc,
|
|
|
|
|
size_t jitter_buffer_max_packets,
|
|
|
|
|
bool jitter_buffer_fast_playout,
|
|
|
|
|
int jitter_buffer_min_delay_ms,
|
|
|
|
|
bool jitter_buffer_enable_rtx_handling,
|
|
|
|
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
|
|
|
|
absl::optional<AudioCodecPairId> codec_pair_id,
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
|
|
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
|
|
|
|
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
|
2018-11-16 09:50:42 +01:00
|
|
|
~ChannelReceive() override;
|
|
|
|
|
|
|
|
|
|
void SetSink(AudioSinkInterface* sink) override;
|
|
|
|
|
|
|
|
|
|
void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) override;
|
|
|
|
|
|
|
|
|
|
// API methods
|
|
|
|
|
|
|
|
|
|
void StartPlayout() override;
|
|
|
|
|
void StopPlayout() override;
|
|
|
|
|
|
|
|
|
|
// Codecs
|
Reland "Refactor FrameDecryptorInterface::Decrypt to use new API."
This reverts commit 7dd83e2bf73a7f1746c5ee976939bf52e19fa8be.
Reason for revert: This wasn't the cause of the break.
Original change's description:
> Revert "Refactor FrameDecryptorInterface::Decrypt to use new API."
>
> This reverts commit 642aa81f7d5cc55d5b99e2abc51327eed9d40195.
>
> Reason for revert: Speculative revert. The chromium roll is failing:
> https://ci.chromium.org/p/chromium/builders/try/linux-rel/64388
> But I can't figure out exactly what is failing, this looks suspecious.
>
> Original change's description:
> > Refactor FrameDecryptorInterface::Decrypt to use new API.
> >
> > This change refactors the FrameDecryptorInterface to use the new API. The new
> > API surface simply moves bytes_written to the return type and implements a
> > simple Status type.
> >
> > Bug: webrtc:10512
> > Change-Id: I622c5d344d58e618853c94c2f691cf7c8fb73a36
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131460
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Benjamin Wright <benwright@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#27497}
>
> TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
>
> Change-Id: Ia9ec70263762c34671af13f0d519e636eb8473cd
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10512
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132013
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27510}
TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,hbos@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
Change-Id: I8e4b7965cf1d1a1554c3b46e6245f5ad0d2dcbb4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10512
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131982
Reviewed-by: Benjamin Wright <benwright@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27529}
2019-04-09 20:08:41 +00:00
|
|
|
absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
|
|
|
|
|
const override;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2019-03-05 14:29:42 +01:00
|
|
|
void ReceivedRTCPPacket(const uint8_t* data, size_t length) override;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
|
|
|
|
// RtpPacketSinkInterface.
|
|
|
|
|
void OnRtpPacket(const RtpPacketReceived& packet) override;
|
|
|
|
|
|
|
|
|
|
// Muting, Volume and Level.
|
|
|
|
|
void SetChannelOutputVolumeScaling(float scaling) override;
|
|
|
|
|
int GetSpeechOutputLevelFullRange() const override;
|
|
|
|
|
// See description of "totalAudioEnergy" in the WebRTC stats spec:
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
|
|
|
|
|
double GetTotalOutputEnergy() const override;
|
|
|
|
|
double GetTotalOutputDuration() const override;
|
|
|
|
|
|
|
|
|
|
// Stats.
|
2020-09-14 10:47:50 +02:00
|
|
|
NetworkStatistics GetNetworkStatistics(
|
|
|
|
|
bool get_and_clear_legacy_stats) const override;
|
2018-11-16 09:50:42 +01:00
|
|
|
AudioDecodingCallStats GetDecodingCallStatistics() const override;
|
|
|
|
|
|
|
|
|
|
// Audio+Video Sync.
|
|
|
|
|
uint32_t GetDelayEstimate() const override;
|
2020-09-08 16:30:25 +02:00
|
|
|
bool SetMinimumPlayoutDelay(int delayMs) override;
|
2019-10-22 15:23:44 +02:00
|
|
|
bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
|
|
|
|
|
int64_t* time_ms) const override;
|
|
|
|
|
void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
|
|
|
|
|
int64_t time_ms) override;
|
|
|
|
|
absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
|
|
|
|
|
int64_t now_ms) const override;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2019-02-06 09:45:56 +01:00
|
|
|
// Audio quality.
|
|
|
|
|
bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override;
|
|
|
|
|
int GetBaseMinimumPlayoutDelayMs() const override;
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
// Produces the transport-related timestamps; current_delay_ms is left unset.
|
|
|
|
|
absl::optional<Syncable::Info> GetSyncInfo() const override;
|
|
|
|
|
|
|
|
|
|
void RegisterReceiverCongestionControlObjects(
|
|
|
|
|
PacketRouter* packet_router) override;
|
|
|
|
|
void ResetReceiverCongestionControlObjects() override;
|
|
|
|
|
|
|
|
|
|
CallReceiveStatistics GetRTCPStatistics() const override;
|
|
|
|
|
void SetNACKStatus(bool enable, int maxNumberOfPackets) override;
|
|
|
|
|
|
|
|
|
|
AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
AudioFrame* audio_frame) override;
|
|
|
|
|
|
|
|
|
|
int PreferredSampleRate() const override;
|
|
|
|
|
|
|
|
|
|
// Associate to a send channel.
|
|
|
|
|
// Used for obtaining RTT for a receive-only channel.
|
2018-11-19 10:27:07 +01:00
|
|
|
void SetAssociatedSendChannel(const ChannelSendInterface* channel) override;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2020-04-01 07:46:16 +02:00
|
|
|
// Sets a frame transformer between the depacketizer and the decoder, to
|
|
|
|
|
// transform the received frames before decoding them.
|
|
|
|
|
void SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
|
|
|
|
|
override;
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
private:
|
2019-07-30 15:15:59 +02:00
|
|
|
void ReceivePacket(const uint8_t* packet,
|
2018-11-16 09:50:42 +01:00
|
|
|
size_t packet_length,
|
|
|
|
|
const RTPHeader& header);
|
|
|
|
|
int ResendPackets(const uint16_t* sequence_numbers, int length);
|
2019-10-22 15:23:44 +02:00
|
|
|
void UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms);
|
2018-11-16 09:50:42 +01:00
|
|
|
|
|
|
|
|
int GetRtpTimestampRateHz() const;
|
|
|
|
|
int64_t GetRTT() const;
|
|
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
void OnReceivedPayloadData(rtc::ArrayView<const uint8_t> payload,
|
|
|
|
|
const RTPHeader& rtpHeader);
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2020-04-01 10:19:44 +02:00
|
|
|
void InitFrameTransformerDelegate(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
|
|
|
|
|
|
2018-11-19 11:56:13 +01:00
|
|
|
bool Playing() const {
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&playing_lock_);
|
2018-11-19 11:56:13 +01:00
|
|
|
return playing_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
// Thread checkers document and lock usage of some methods to specific threads
|
|
|
|
|
// we know about. The goal is to eventually split up voe::ChannelReceive into
|
|
|
|
|
// parts with single-threaded semantics, and thereby reduce the need for
|
|
|
|
|
// locks.
|
|
|
|
|
rtc::ThreadChecker worker_thread_checker_;
|
|
|
|
|
rtc::ThreadChecker module_process_thread_checker_;
|
|
|
|
|
// Methods accessed from audio and video threads are checked for sequential-
|
|
|
|
|
// only access. We don't necessarily own and control these threads, so thread
|
|
|
|
|
// checkers cannot be used. E.g. Chromium may transfer "ownership" from one
|
|
|
|
|
// audio thread to another, but access is still sequential.
|
|
|
|
|
rtc::RaceChecker audio_thread_race_checker_;
|
|
|
|
|
rtc::RaceChecker video_capture_thread_race_checker_;
|
2020-07-06 15:15:07 +02:00
|
|
|
Mutex callback_mutex_;
|
|
|
|
|
Mutex volume_settings_mutex_;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex playing_lock_;
|
2018-11-19 11:56:13 +01:00
|
|
|
bool playing_ RTC_GUARDED_BY(&playing_lock_) = false;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
|
|
|
|
RtcEventLog* const event_log_;
|
|
|
|
|
|
|
|
|
|
// Indexed by payload type.
|
|
|
|
|
std::map<uint8_t, int> payload_type_frequencies_;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
|
2020-06-03 22:55:33 +02:00
|
|
|
std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_;
|
2018-11-16 09:50:42 +01:00
|
|
|
const uint32_t remote_ssrc_;
|
|
|
|
|
|
2019-08-02 10:29:26 +00:00
|
|
|
// Info for GetSyncInfo is updated on network or worker thread, and queried on
|
|
|
|
|
// the worker thread.
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex sync_info_lock_;
|
2018-11-16 09:50:42 +01:00
|
|
|
absl::optional<uint32_t> last_received_rtp_timestamp_
|
2019-08-02 10:29:26 +00:00
|
|
|
RTC_GUARDED_BY(&sync_info_lock_);
|
2018-11-16 09:50:42 +01:00
|
|
|
absl::optional<int64_t> last_received_rtp_system_time_ms_
|
2019-08-02 10:29:26 +00:00
|
|
|
RTC_GUARDED_BY(&sync_info_lock_);
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
// The AcmReceiver is thread safe, using its own lock.
|
|
|
|
|
acm2::AcmReceiver acm_receiver_;
|
2018-11-16 09:50:42 +01:00
|
|
|
AudioSinkInterface* audio_sink_ = nullptr;
|
|
|
|
|
AudioLevel _outputAudioLevel;
|
|
|
|
|
|
|
|
|
|
RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
|
|
|
|
|
|
|
|
|
|
// Timestamp of the audio pulled from NetEq.
|
|
|
|
|
absl::optional<uint32_t> jitter_buffer_playout_timestamp_;
|
|
|
|
|
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex video_sync_lock_;
|
2018-11-16 09:50:42 +01:00
|
|
|
uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
|
2019-10-22 15:23:44 +02:00
|
|
|
absl::optional<int64_t> playout_timestamp_rtp_time_ms_
|
|
|
|
|
RTC_GUARDED_BY(video_sync_lock_);
|
2018-11-16 09:50:42 +01:00
|
|
|
uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
|
2019-10-22 15:23:44 +02:00
|
|
|
absl::optional<int64_t> playout_timestamp_ntp_
|
|
|
|
|
RTC_GUARDED_BY(video_sync_lock_);
|
|
|
|
|
absl::optional<int64_t> playout_timestamp_ntp_time_ms_
|
|
|
|
|
RTC_GUARDED_BY(video_sync_lock_);
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex ts_stats_lock_;
|
2018-11-16 09:50:42 +01:00
|
|
|
|
|
|
|
|
std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
|
|
|
|
|
// The rtp timestamp of the first played out audio frame.
|
|
|
|
|
int64_t capture_start_rtp_time_stamp_;
|
|
|
|
|
// The capture ntp time (in local timebase) of the first played out audio
|
|
|
|
|
// frame.
|
|
|
|
|
int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
|
|
|
|
|
|
|
|
|
|
// uses
|
|
|
|
|
ProcessThread* _moduleProcessThreadPtr;
|
|
|
|
|
AudioDeviceModule* _audioDeviceModulePtr;
|
2020-07-06 15:15:07 +02:00
|
|
|
float _outputGain RTC_GUARDED_BY(volume_settings_mutex_);
|
2018-11-16 09:50:42 +01:00
|
|
|
|
|
|
|
|
// An associated send channel.
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex assoc_send_channel_lock_;
|
2018-11-19 10:27:07 +01:00
|
|
|
const ChannelSendInterface* associated_send_channel_
|
2018-11-16 09:50:42 +01:00
|
|
|
RTC_GUARDED_BY(assoc_send_channel_lock_);
|
|
|
|
|
|
|
|
|
|
PacketRouter* packet_router_ = nullptr;
|
|
|
|
|
|
|
|
|
|
rtc::ThreadChecker construction_thread_;
|
|
|
|
|
|
|
|
|
|
// E2EE Audio Frame Decryption
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_;
|
|
|
|
|
webrtc::CryptoOptions crypto_options_;
|
2020-02-11 13:04:02 +01:00
|
|
|
|
|
|
|
|
webrtc::AbsoluteCaptureTimeReceiver absolute_capture_time_receiver_;
|
2020-04-01 07:46:16 +02:00
|
|
|
|
2020-04-01 10:19:44 +02:00
|
|
|
rtc::scoped_refptr<ChannelReceiveFrameTransformerDelegate>
|
|
|
|
|
frame_transformer_delegate_;
|
2018-11-16 09:50:42 +01:00
|
|
|
};
|
2018-10-04 14:28:39 +02:00
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
void ChannelReceive::OnReceivedPayloadData(
|
|
|
|
|
rtc::ArrayView<const uint8_t> payload,
|
|
|
|
|
const RTPHeader& rtpHeader) {
|
2018-11-19 11:56:13 +01:00
|
|
|
if (!Playing()) {
|
2018-10-04 14:28:39 +02:00
|
|
|
// Avoid inserting into NetEQ when we are not playing. Count the
|
|
|
|
|
// packet as discarded.
|
2019-07-30 15:15:59 +02:00
|
|
|
return;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Push the incoming payload (parsed and ready for decoding) into the ACM
|
2019-07-30 15:15:59 +02:00
|
|
|
if (acm_receiver_.InsertPacket(rtpHeader, payload) != 0) {
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DLOG(LS_ERROR) << "ChannelReceive::OnReceivedPayloadData() unable to "
|
|
|
|
|
"push data to the ACM";
|
2019-07-30 15:15:59 +02:00
|
|
|
return;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t round_trip_time = 0;
|
2020-06-03 22:55:33 +02:00
|
|
|
rtp_rtcp_->RTT(remote_ssrc_, &round_trip_time, NULL, NULL, NULL);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
std::vector<uint16_t> nack_list = acm_receiver_.GetNackList(round_trip_time);
|
2018-10-04 14:28:39 +02:00
|
|
|
if (!nack_list.empty()) {
|
|
|
|
|
// Can't use nack_list.data() since it's not supported by all
|
|
|
|
|
// compilers.
|
|
|
|
|
ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 10:19:44 +02:00
|
|
|
void ChannelReceive::InitFrameTransformerDelegate(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {
|
|
|
|
|
RTC_DCHECK(frame_transformer);
|
|
|
|
|
RTC_DCHECK(!frame_transformer_delegate_);
|
|
|
|
|
|
2020-04-02 12:10:03 +02:00
|
|
|
// Pass a callback to ChannelReceive::OnReceivedPayloadData, to be called by
|
|
|
|
|
// the delegate to receive transformed audio.
|
2020-04-01 10:19:44 +02:00
|
|
|
ChannelReceiveFrameTransformerDelegate::ReceiveFrameCallback
|
|
|
|
|
receive_audio_callback = [this](rtc::ArrayView<const uint8_t> packet,
|
|
|
|
|
const RTPHeader& header) {
|
2020-04-02 12:10:03 +02:00
|
|
|
OnReceivedPayloadData(packet, header);
|
2020-04-01 10:19:44 +02:00
|
|
|
};
|
|
|
|
|
frame_transformer_delegate_ =
|
|
|
|
|
new rtc::RefCountedObject<ChannelReceiveFrameTransformerDelegate>(
|
|
|
|
|
std::move(receive_audio_callback), std::move(frame_transformer),
|
|
|
|
|
rtc::Thread::Current());
|
|
|
|
|
frame_transformer_delegate_->Init();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
AudioMixer::Source::AudioFrameInfo ChannelReceive::GetAudioFrameWithInfo(
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
AudioFrame* audio_frame) {
|
2018-11-16 09:50:42 +01:00
|
|
|
RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
|
2018-10-04 14:28:39 +02:00
|
|
|
audio_frame->sample_rate_hz_ = sample_rate_hz;
|
|
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
event_log_->Log(std::make_unique<RtcEventAudioPlayout>(remote_ssrc_));
|
2018-11-19 11:56:13 +01:00
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
// Get 10ms raw PCM data from the ACM (mixer limits output frequency)
|
|
|
|
|
bool muted;
|
2019-07-30 15:15:59 +02:00
|
|
|
if (acm_receiver_.GetAudio(audio_frame->sample_rate_hz_, audio_frame,
|
|
|
|
|
&muted) == -1) {
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DLOG(LS_ERROR)
|
|
|
|
|
<< "ChannelReceive::GetAudioFrame() PlayoutData10Ms() failed!";
|
|
|
|
|
// In all likelihood, the audio in this frame is garbage. We return an
|
|
|
|
|
// error so that the audio mixer module doesn't add it to the mix. As
|
|
|
|
|
// a result, it won't be played out and the actions skipped here are
|
|
|
|
|
// irrelevant.
|
|
|
|
|
return AudioMixer::Source::AudioFrameInfo::kError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (muted) {
|
|
|
|
|
// TODO(henrik.lundin): We should be able to do better than this. But we
|
|
|
|
|
// will have to go through all the cases below where the audio samples may
|
|
|
|
|
// be used, and handle the muted case in some way.
|
|
|
|
|
AudioFrameOperations::Mute(audio_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Pass the audio buffers to an optional sink callback, before applying
|
|
|
|
|
// scaling/panning, as that applies to the mix operation.
|
|
|
|
|
// External recipients of the audio (e.g. via AudioTrack), will do their
|
|
|
|
|
// own mixing/dynamic processing.
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&callback_mutex_);
|
2018-10-04 14:28:39 +02:00
|
|
|
if (audio_sink_) {
|
|
|
|
|
AudioSinkInterface::Data data(
|
|
|
|
|
audio_frame->data(), audio_frame->samples_per_channel_,
|
|
|
|
|
audio_frame->sample_rate_hz_, audio_frame->num_channels_,
|
|
|
|
|
audio_frame->timestamp_);
|
|
|
|
|
audio_sink_->OnData(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float output_gain = 1.0f;
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&volume_settings_mutex_);
|
2018-10-04 14:28:39 +02:00
|
|
|
output_gain = _outputGain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Output volume scaling
|
|
|
|
|
if (output_gain < 0.99f || output_gain > 1.01f) {
|
|
|
|
|
// TODO(solenberg): Combine with mute state - this can cause clicks!
|
|
|
|
|
AudioFrameOperations::ScaleWithSat(output_gain, audio_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Measure audio level (0-9)
|
|
|
|
|
// TODO(henrik.lundin) Use the |muted| information here too.
|
|
|
|
|
// TODO(deadbeef): Use RmsLevel for |_outputAudioLevel| (see
|
|
|
|
|
// https://crbug.com/webrtc/7517).
|
|
|
|
|
_outputAudioLevel.ComputeLevel(*audio_frame, kAudioSampleDurationSeconds);
|
|
|
|
|
|
|
|
|
|
if (capture_start_rtp_time_stamp_ < 0 && audio_frame->timestamp_ != 0) {
|
|
|
|
|
// The first frame with a valid rtp timestamp.
|
|
|
|
|
capture_start_rtp_time_stamp_ = audio_frame->timestamp_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (capture_start_rtp_time_stamp_ >= 0) {
|
|
|
|
|
// audio_frame.timestamp_ should be valid from now on.
|
|
|
|
|
|
|
|
|
|
// Compute elapsed time.
|
|
|
|
|
int64_t unwrap_timestamp =
|
|
|
|
|
rtp_ts_wraparound_handler_->Unwrap(audio_frame->timestamp_);
|
|
|
|
|
audio_frame->elapsed_time_ms_ =
|
|
|
|
|
(unwrap_timestamp - capture_start_rtp_time_stamp_) /
|
|
|
|
|
(GetRtpTimestampRateHz() / 1000);
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&ts_stats_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
// Compute ntp time.
|
|
|
|
|
audio_frame->ntp_time_ms_ =
|
|
|
|
|
ntp_estimator_.Estimate(audio_frame->timestamp_);
|
|
|
|
|
// |ntp_time_ms_| won't be valid until at least 2 RTCP SRs are received.
|
|
|
|
|
if (audio_frame->ntp_time_ms_ > 0) {
|
|
|
|
|
// Compute |capture_start_ntp_time_ms_| so that
|
|
|
|
|
// |capture_start_ntp_time_ms_| + |elapsed_time_ms_| == |ntp_time_ms_|
|
|
|
|
|
capture_start_ntp_time_ms_ =
|
|
|
|
|
audio_frame->ntp_time_ms_ - audio_frame->elapsed_time_ms_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.TargetJitterBufferDelayMs",
|
2019-07-30 15:15:59 +02:00
|
|
|
acm_receiver_.TargetDelayMs());
|
|
|
|
|
const int jitter_buffer_delay = acm_receiver_.FilteredCurrentDelayMs();
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDelayEstimateMs",
|
|
|
|
|
jitter_buffer_delay + playout_delay_ms_);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverJitterBufferDelayMs",
|
|
|
|
|
jitter_buffer_delay);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDeviceDelayMs",
|
|
|
|
|
playout_delay_ms_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return muted ? AudioMixer::Source::AudioFrameInfo::kMuted
|
|
|
|
|
: AudioMixer::Source::AudioFrameInfo::kNormal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ChannelReceive::PreferredSampleRate() const {
|
2018-11-16 09:50:42 +01:00
|
|
|
RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
|
2018-10-04 14:28:39 +02:00
|
|
|
// Return the bigger of playout and receive frequency in the ACM.
|
2019-07-30 15:15:59 +02:00
|
|
|
return std::max(acm_receiver_.last_packet_sample_rate_hz().value_or(0),
|
|
|
|
|
acm_receiver_.last_output_sample_rate_hz());
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChannelReceive::ChannelReceive(
|
2019-03-04 17:43:34 +01:00
|
|
|
Clock* clock,
|
2018-10-04 14:28:39 +02:00
|
|
|
ProcessThread* module_process_thread,
|
2019-11-01 11:47:51 +01:00
|
|
|
NetEqFactory* neteq_factory,
|
2018-10-04 14:28:39 +02:00
|
|
|
AudioDeviceModule* audio_device_module,
|
2018-10-05 11:28:38 +02:00
|
|
|
Transport* rtcp_send_transport,
|
2018-10-04 14:28:39 +02:00
|
|
|
RtcEventLog* rtc_event_log,
|
2019-08-21 13:36:20 +02:00
|
|
|
uint32_t local_ssrc,
|
2018-10-04 14:28:39 +02:00
|
|
|
uint32_t remote_ssrc,
|
|
|
|
|
size_t jitter_buffer_max_packets,
|
|
|
|
|
bool jitter_buffer_fast_playout,
|
2018-11-27 15:45:20 +01:00
|
|
|
int jitter_buffer_min_delay_ms,
|
2019-01-10 15:58:36 +01:00
|
|
|
bool jitter_buffer_enable_rtx_handling,
|
2018-10-04 14:28:39 +02:00
|
|
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
2018-10-04 14:22:34 -07:00
|
|
|
absl::optional<AudioCodecPairId> codec_pair_id,
|
2018-10-25 09:52:57 -07:00
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
|
2020-04-01 07:46:16 +02:00
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
|
|
|
|
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer)
|
2018-10-04 14:28:39 +02:00
|
|
|
: event_log_(rtc_event_log),
|
2019-03-04 17:43:34 +01:00
|
|
|
rtp_receive_statistics_(ReceiveStatistics::Create(clock)),
|
2018-10-04 14:28:39 +02:00
|
|
|
remote_ssrc_(remote_ssrc),
|
2019-11-01 11:47:51 +01:00
|
|
|
acm_receiver_(AcmConfig(neteq_factory,
|
|
|
|
|
decoder_factory,
|
2019-07-30 15:15:59 +02:00
|
|
|
codec_pair_id,
|
|
|
|
|
jitter_buffer_max_packets,
|
|
|
|
|
jitter_buffer_fast_playout)),
|
2018-10-04 14:28:39 +02:00
|
|
|
_outputAudioLevel(),
|
2019-03-04 17:43:34 +01:00
|
|
|
ntp_estimator_(clock),
|
2018-10-04 14:28:39 +02:00
|
|
|
playout_timestamp_rtp_(0),
|
|
|
|
|
playout_delay_ms_(0),
|
|
|
|
|
rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()),
|
|
|
|
|
capture_start_rtp_time_stamp_(-1),
|
|
|
|
|
capture_start_ntp_time_ms_(-1),
|
|
|
|
|
_moduleProcessThreadPtr(module_process_thread),
|
|
|
|
|
_audioDeviceModulePtr(audio_device_module),
|
|
|
|
|
_outputGain(1.0f),
|
2018-10-04 14:22:34 -07:00
|
|
|
associated_send_channel_(nullptr),
|
2018-10-15 10:20:24 -07:00
|
|
|
frame_decryptor_(frame_decryptor),
|
2020-02-11 13:04:02 +01:00
|
|
|
crypto_options_(crypto_options),
|
2020-04-01 10:19:44 +02:00
|
|
|
absolute_capture_time_receiver_(clock) {
|
2018-11-16 09:50:42 +01:00
|
|
|
// TODO(nisse): Use _moduleProcessThreadPtr instead?
|
2019-04-08 15:20:44 +02:00
|
|
|
module_process_thread_checker_.Detach();
|
2018-11-16 09:50:42 +01:00
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DCHECK(module_process_thread);
|
|
|
|
|
RTC_DCHECK(audio_device_module);
|
2019-07-30 15:15:59 +02:00
|
|
|
|
|
|
|
|
acm_receiver_.ResetInitialDelay();
|
|
|
|
|
acm_receiver_.SetMinimumDelay(0);
|
|
|
|
|
acm_receiver_.SetMaximumDelay(0);
|
|
|
|
|
acm_receiver_.FlushBuffers();
|
2018-10-04 14:28:39 +02:00
|
|
|
|
[getStats] Implement "media-source" audio levels, fixing Chrome bug.
Implements RTCAudioSourceStats members:
- audioLevel
- totalAudioEnergy
- totalSamplesDuration
In this CL description these are collectively referred to as the audio
levels.
The audio levels are removed from sending "track" stats (in Chrome,
these are now reported as undefined instead of 0).
Background:
For sending tracks, audio levels were always reported as 0 in Chrome
(https://crbug.com/736403), while audio levels were correctly reported
for receiving tracks. This problem affected the standard getStats() but
not the legacy getStats(), blocking some people from migrating. This
was likely not a problem in native third_party/webrtc code because the
delivery of audio frames from device to send-stream uses a different
code path outside of chromium.
A recent PR (https://github.com/w3c/webrtc-stats/pull/451) moved the
send-side audio levels to the RTCAudioSourceStats, while keeping the
receive-side audio levels on the "track" stats. This allows an
implementation to report the audio levels even if samples are not sent
onto the network (such as if an ICE connection has not been established
yet), reflecting some of the current implementation.
Changes:
1. Audio levels are added to RTCAudioSourceStats. Send-side audio
"track" stats are left undefined. Receive-side audio "track" stats
are not changed in this CL and continue to work.
2. Audio level computation is moved from the AudioState and
AudioTransportImpl to the AudioSendStream. This is because a) the
AudioTransportImpl::RecordedDataIsAvailable() code path is not
exercised in chromium, and b) audio levels should, per-spec, not be
calculated on a per-call basis, for which the AudioState is defined.
3. The audio level computation is now performed in
AudioSendStream::SendAudioData(), a code path used by both native
and chromium code.
4. Comments are added to document behavior of existing code, such as
AudioLevel and AudioSendStream::SendAudioData().
Note:
In this CL, just like before this CL, audio level is only calculated
after an AudioSendStream has been created. This means that before an
O/A negotiation, audio levels are unavailable.
According to spec, if we have an audio source, we should have audio
levels. An immediate solution to this would have been to calculate the
audio level at pc/rtp_sender.cc. The problem is that the
LocalAudioSinkAdapter::OnData() code path, while exercised in chromium,
is not exercised in native code. The issue of calculating audio levels
on a per-source bases rather than on a per-send stream basis is left to
https://crbug.com/webrtc/10771, an existing "media-source" bug.
This CL can be verified manually in Chrome at:
https://codepen.io/anon/pen/vqRGyq
Bug: chromium:736403, webrtc:10771
Change-Id: I8036cd9984f3b187c3177470a8c0d6670a201a5a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143789
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28480}
2019-07-03 17:11:10 +02:00
|
|
|
_outputAudioLevel.ResetLevelFullRange();
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
rtp_receive_statistics_->EnableRetransmitDetection(remote_ssrc_, true);
|
2020-06-03 22:55:33 +02:00
|
|
|
RtpRtcpInterface::Configuration configuration;
|
2019-03-04 17:43:34 +01:00
|
|
|
configuration.clock = clock;
|
2018-10-04 14:28:39 +02:00
|
|
|
configuration.audio = true;
|
2018-10-31 15:25:26 +01:00
|
|
|
configuration.receiver_only = true;
|
2018-10-05 11:28:38 +02:00
|
|
|
configuration.outgoing_transport = rtcp_send_transport;
|
2018-10-04 14:28:39 +02:00
|
|
|
configuration.receive_statistics = rtp_receive_statistics_.get();
|
|
|
|
|
configuration.event_log = event_log_;
|
2019-08-21 13:36:20 +02:00
|
|
|
configuration.local_media_ssrc = local_ssrc;
|
2018-10-04 14:28:39 +02:00
|
|
|
|
2020-04-01 10:19:44 +02:00
|
|
|
if (frame_transformer)
|
|
|
|
|
InitFrameTransformerDelegate(std::move(frame_transformer));
|
|
|
|
|
|
2021-01-12 15:54:16 +00:00
|
|
|
rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration);
|
2020-06-03 22:55:33 +02:00
|
|
|
rtp_rtcp_->SetSendingMediaStatus(false);
|
|
|
|
|
rtp_rtcp_->SetRemoteSSRC(remote_ssrc_);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
2020-06-03 22:55:33 +02:00
|
|
|
_moduleProcessThreadPtr->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
2019-08-29 13:47:09 +02:00
|
|
|
// Ensure that RTCP is enabled for the created channel.
|
2020-06-03 22:55:33 +02:00
|
|
|
rtp_rtcp_->SetRTCPStatus(RtcpMode::kCompound);
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-19 11:56:13 +01:00
|
|
|
ChannelReceive::~ChannelReceive() {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(construction_thread_.IsCurrent());
|
2018-10-26 12:57:07 +02:00
|
|
|
|
2020-04-22 11:57:17 +02:00
|
|
|
// Resets the delegate's callback to ChannelReceive::OnReceivedPayloadData.
|
|
|
|
|
if (frame_transformer_delegate_)
|
|
|
|
|
frame_transformer_delegate_->Reset();
|
|
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
StopPlayout();
|
|
|
|
|
|
|
|
|
|
if (_moduleProcessThreadPtr)
|
2020-06-03 22:55:33 +02:00
|
|
|
_moduleProcessThreadPtr->DeRegisterModule(rtp_rtcp_.get());
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelReceive::SetSink(AudioSinkInterface* sink) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&callback_mutex_);
|
2018-10-04 14:28:39 +02:00
|
|
|
audio_sink_ = sink;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 13:22:47 +01:00
|
|
|
void ChannelReceive::StartPlayout() {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&playing_lock_);
|
2018-11-19 11:56:13 +01:00
|
|
|
playing_ = true;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-12 13:22:47 +01:00
|
|
|
void ChannelReceive::StopPlayout() {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&playing_lock_);
|
2018-11-19 11:56:13 +01:00
|
|
|
playing_ = false;
|
[getStats] Implement "media-source" audio levels, fixing Chrome bug.
Implements RTCAudioSourceStats members:
- audioLevel
- totalAudioEnergy
- totalSamplesDuration
In this CL description these are collectively referred to as the audio
levels.
The audio levels are removed from sending "track" stats (in Chrome,
these are now reported as undefined instead of 0).
Background:
For sending tracks, audio levels were always reported as 0 in Chrome
(https://crbug.com/736403), while audio levels were correctly reported
for receiving tracks. This problem affected the standard getStats() but
not the legacy getStats(), blocking some people from migrating. This
was likely not a problem in native third_party/webrtc code because the
delivery of audio frames from device to send-stream uses a different
code path outside of chromium.
A recent PR (https://github.com/w3c/webrtc-stats/pull/451) moved the
send-side audio levels to the RTCAudioSourceStats, while keeping the
receive-side audio levels on the "track" stats. This allows an
implementation to report the audio levels even if samples are not sent
onto the network (such as if an ICE connection has not been established
yet), reflecting some of the current implementation.
Changes:
1. Audio levels are added to RTCAudioSourceStats. Send-side audio
"track" stats are left undefined. Receive-side audio "track" stats
are not changed in this CL and continue to work.
2. Audio level computation is moved from the AudioState and
AudioTransportImpl to the AudioSendStream. This is because a) the
AudioTransportImpl::RecordedDataIsAvailable() code path is not
exercised in chromium, and b) audio levels should, per-spec, not be
calculated on a per-call basis, for which the AudioState is defined.
3. The audio level computation is now performed in
AudioSendStream::SendAudioData(), a code path used by both native
and chromium code.
4. Comments are added to document behavior of existing code, such as
AudioLevel and AudioSendStream::SendAudioData().
Note:
In this CL, just like before this CL, audio level is only calculated
after an AudioSendStream has been created. This means that before an
O/A negotiation, audio levels are unavailable.
According to spec, if we have an audio source, we should have audio
levels. An immediate solution to this would have been to calculate the
audio level at pc/rtp_sender.cc. The problem is that the
LocalAudioSinkAdapter::OnData() code path, while exercised in chromium,
is not exercised in native code. The issue of calculating audio levels
on a per-source bases rather than on a per-send stream basis is left to
https://crbug.com/webrtc/10771, an existing "media-source" bug.
This CL can be verified manually in Chrome at:
https://codepen.io/anon/pen/vqRGyq
Bug: chromium:736403, webrtc:10771
Change-Id: I8036cd9984f3b187c3177470a8c0d6670a201a5a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143789
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28480}
2019-07-03 17:11:10 +02:00
|
|
|
_outputAudioLevel.ResetLevelFullRange();
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 19:08:33 +02:00
|
|
|
absl::optional<std::pair<int, SdpAudioFormat>> ChannelReceive::GetReceiveCodec()
|
|
|
|
|
const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2019-07-30 15:15:59 +02:00
|
|
|
return acm_receiver_.LastDecoder();
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelReceive::SetReceiveCodecs(
|
|
|
|
|
const std::map<int, SdpAudioFormat>& codecs) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
for (const auto& kv : codecs) {
|
|
|
|
|
RTC_DCHECK_GE(kv.second.clockrate_hz, 1000);
|
|
|
|
|
payload_type_frequencies_[kv.first] = kv.second.clockrate_hz;
|
|
|
|
|
}
|
2019-07-30 15:15:59 +02:00
|
|
|
acm_receiver_.SetCodecs(codecs);
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
// May be called on either worker thread or network thread.
|
2018-10-04 14:28:39 +02:00
|
|
|
void ChannelReceive::OnRtpPacket(const RtpPacketReceived& packet) {
|
|
|
|
|
int64_t now_ms = rtc::TimeMillis();
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&sync_info_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
last_received_rtp_timestamp_ = packet.Timestamp();
|
|
|
|
|
last_received_rtp_system_time_ms_ = now_ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store playout timestamp for the received RTP packet
|
2019-10-22 15:23:44 +02:00
|
|
|
UpdatePlayoutTimestamp(false, now_ms);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
const auto& it = payload_type_frequencies_.find(packet.PayloadType());
|
|
|
|
|
if (it == payload_type_frequencies_.end())
|
|
|
|
|
return;
|
|
|
|
|
// TODO(nisse): Set payload_type_frequency earlier, when packet is parsed.
|
|
|
|
|
RtpPacketReceived packet_copy(packet);
|
|
|
|
|
packet_copy.set_payload_type_frequency(it->second);
|
|
|
|
|
|
|
|
|
|
rtp_receive_statistics_->OnRtpPacket(packet_copy);
|
|
|
|
|
|
|
|
|
|
RTPHeader header;
|
|
|
|
|
packet_copy.GetHeader(&header);
|
|
|
|
|
|
2020-02-11 13:04:02 +01:00
|
|
|
// Interpolates absolute capture timestamp RTP header extension.
|
|
|
|
|
header.extension.absolute_capture_time =
|
|
|
|
|
absolute_capture_time_receiver_.OnReceivePacket(
|
|
|
|
|
AbsoluteCaptureTimeReceiver::GetSource(header.ssrc,
|
|
|
|
|
header.arrOfCSRCs),
|
|
|
|
|
header.timestamp,
|
|
|
|
|
rtc::saturated_cast<uint32_t>(packet_copy.payload_type_frequency()),
|
|
|
|
|
header.extension.absolute_capture_time);
|
|
|
|
|
|
2020-04-02 12:10:03 +02:00
|
|
|
ReceivePacket(packet_copy.data(), packet_copy.size(), header);
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-30 15:15:59 +02:00
|
|
|
void ChannelReceive::ReceivePacket(const uint8_t* packet,
|
2018-10-04 14:28:39 +02:00
|
|
|
size_t packet_length,
|
|
|
|
|
const RTPHeader& header) {
|
|
|
|
|
const uint8_t* payload = packet + header.headerLength;
|
|
|
|
|
assert(packet_length >= header.headerLength);
|
|
|
|
|
size_t payload_length = packet_length - header.headerLength;
|
|
|
|
|
|
2018-10-04 14:22:34 -07:00
|
|
|
size_t payload_data_length = payload_length - header.paddingLength;
|
|
|
|
|
|
|
|
|
|
// E2EE Custom Audio Frame Decryption (This is optional).
|
|
|
|
|
// Keep this buffer around for the lifetime of the OnReceivedPayloadData call.
|
|
|
|
|
rtc::Buffer decrypted_audio_payload;
|
|
|
|
|
if (frame_decryptor_ != nullptr) {
|
Reland "Refactor FrameDecryptorInterface::Decrypt to use new API."
This reverts commit 7dd83e2bf73a7f1746c5ee976939bf52e19fa8be.
Reason for revert: This wasn't the cause of the break.
Original change's description:
> Revert "Refactor FrameDecryptorInterface::Decrypt to use new API."
>
> This reverts commit 642aa81f7d5cc55d5b99e2abc51327eed9d40195.
>
> Reason for revert: Speculative revert. The chromium roll is failing:
> https://ci.chromium.org/p/chromium/builders/try/linux-rel/64388
> But I can't figure out exactly what is failing, this looks suspecious.
>
> Original change's description:
> > Refactor FrameDecryptorInterface::Decrypt to use new API.
> >
> > This change refactors the FrameDecryptorInterface to use the new API. The new
> > API surface simply moves bytes_written to the return type and implements a
> > simple Status type.
> >
> > Bug: webrtc:10512
> > Change-Id: I622c5d344d58e618853c94c2f691cf7c8fb73a36
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131460
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Benjamin Wright <benwright@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#27497}
>
> TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
>
> Change-Id: Ia9ec70263762c34671af13f0d519e636eb8473cd
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10512
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132013
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27510}
TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,hbos@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
Change-Id: I8e4b7965cf1d1a1554c3b46e6245f5ad0d2dcbb4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10512
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131982
Reviewed-by: Benjamin Wright <benwright@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27529}
2019-04-09 20:08:41 +00:00
|
|
|
const size_t max_plaintext_size = frame_decryptor_->GetMaxPlaintextByteSize(
|
2018-10-04 14:22:34 -07:00
|
|
|
cricket::MEDIA_TYPE_AUDIO, payload_length);
|
|
|
|
|
decrypted_audio_payload.SetSize(max_plaintext_size);
|
|
|
|
|
|
Reland "Refactor FrameDecryptorInterface::Decrypt to use new API."
This reverts commit 7dd83e2bf73a7f1746c5ee976939bf52e19fa8be.
Reason for revert: This wasn't the cause of the break.
Original change's description:
> Revert "Refactor FrameDecryptorInterface::Decrypt to use new API."
>
> This reverts commit 642aa81f7d5cc55d5b99e2abc51327eed9d40195.
>
> Reason for revert: Speculative revert. The chromium roll is failing:
> https://ci.chromium.org/p/chromium/builders/try/linux-rel/64388
> But I can't figure out exactly what is failing, this looks suspecious.
>
> Original change's description:
> > Refactor FrameDecryptorInterface::Decrypt to use new API.
> >
> > This change refactors the FrameDecryptorInterface to use the new API. The new
> > API surface simply moves bytes_written to the return type and implements a
> > simple Status type.
> >
> > Bug: webrtc:10512
> > Change-Id: I622c5d344d58e618853c94c2f691cf7c8fb73a36
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131460
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Benjamin Wright <benwright@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#27497}
>
> TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
>
> Change-Id: Ia9ec70263762c34671af13f0d519e636eb8473cd
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10512
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132013
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Henrik Boström <hbos@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27510}
TBR=brandtr@webrtc.org,steveanton@webrtc.org,solenberg@webrtc.org,hbos@webrtc.org,ossu@webrtc.org,stefan@webrtc.org,benwright@webrtc.org
Change-Id: I8e4b7965cf1d1a1554c3b46e6245f5ad0d2dcbb4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10512
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131982
Reviewed-by: Benjamin Wright <benwright@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27529}
2019-04-09 20:08:41 +00:00
|
|
|
const std::vector<uint32_t> csrcs(header.arrOfCSRCs,
|
|
|
|
|
header.arrOfCSRCs + header.numCSRCs);
|
|
|
|
|
const FrameDecryptorInterface::Result decrypt_result =
|
|
|
|
|
frame_decryptor_->Decrypt(
|
|
|
|
|
cricket::MEDIA_TYPE_AUDIO, csrcs,
|
|
|
|
|
/*additional_data=*/nullptr,
|
|
|
|
|
rtc::ArrayView<const uint8_t>(payload, payload_data_length),
|
|
|
|
|
decrypted_audio_payload);
|
|
|
|
|
|
|
|
|
|
if (decrypt_result.IsOk()) {
|
|
|
|
|
decrypted_audio_payload.SetSize(decrypt_result.bytes_written);
|
|
|
|
|
} else {
|
|
|
|
|
// Interpret failures as a silent frame.
|
|
|
|
|
decrypted_audio_payload.SetSize(0);
|
2018-10-04 14:22:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
payload = decrypted_audio_payload.data();
|
|
|
|
|
payload_data_length = decrypted_audio_payload.size();
|
2018-10-15 10:20:24 -07:00
|
|
|
} else if (crypto_options_.sframe.require_frame_encryption) {
|
|
|
|
|
RTC_DLOG(LS_ERROR)
|
|
|
|
|
<< "FrameDecryptor required but not set, dropping packet";
|
|
|
|
|
payload_data_length = 0;
|
2018-10-04 14:22:34 -07:00
|
|
|
}
|
|
|
|
|
|
2020-04-02 12:10:03 +02:00
|
|
|
rtc::ArrayView<const uint8_t> payload_data(payload, payload_data_length);
|
|
|
|
|
if (frame_transformer_delegate_) {
|
|
|
|
|
// Asynchronously transform the received payload. After the payload is
|
|
|
|
|
// transformed, the delegate will call OnReceivedPayloadData to handle it.
|
|
|
|
|
frame_transformer_delegate_->Transform(payload_data, header, remote_ssrc_);
|
|
|
|
|
} else {
|
|
|
|
|
OnReceivedPayloadData(payload_data, header);
|
|
|
|
|
}
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
// May be called on either worker thread or network thread.
|
2019-03-05 14:29:42 +01:00
|
|
|
void ChannelReceive::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
|
2018-10-04 14:28:39 +02:00
|
|
|
// Store playout timestamp for the received RTCP packet
|
2019-10-22 15:23:44 +02:00
|
|
|
UpdatePlayoutTimestamp(true, rtc::TimeMillis());
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
// Deliver RTCP packet to RTP/RTCP module for parsing
|
2020-06-03 22:55:33 +02:00
|
|
|
rtp_rtcp_->IncomingRtcpPacket(data, length);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
int64_t rtt = GetRTT();
|
|
|
|
|
if (rtt == 0) {
|
|
|
|
|
// Waiting for valid RTT.
|
2019-03-05 14:29:42 +01:00
|
|
|
return;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t ntp_secs = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t rtp_timestamp = 0;
|
2020-06-03 22:55:33 +02:00
|
|
|
if (0 !=
|
|
|
|
|
rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, &rtp_timestamp)) {
|
2018-10-04 14:28:39 +02:00
|
|
|
// Waiting for RTCP.
|
2019-03-05 14:29:42 +01:00
|
|
|
return;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&ts_stats_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ChannelReceive::GetSpeechOutputLevelFullRange() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
return _outputAudioLevel.LevelFullRange();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double ChannelReceive::GetTotalOutputEnergy() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
return _outputAudioLevel.TotalEnergy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double ChannelReceive::GetTotalOutputDuration() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
return _outputAudioLevel.TotalDuration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelReceive::SetChannelOutputVolumeScaling(float scaling) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&volume_settings_mutex_);
|
2018-10-04 14:28:39 +02:00
|
|
|
_outputGain = scaling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelReceive::RegisterReceiverCongestionControlObjects(
|
|
|
|
|
PacketRouter* packet_router) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DCHECK(packet_router);
|
|
|
|
|
RTC_DCHECK(!packet_router_);
|
|
|
|
|
constexpr bool remb_candidate = false;
|
2020-06-03 22:55:33 +02:00
|
|
|
packet_router->AddReceiveRtpModule(rtp_rtcp_.get(), remb_candidate);
|
2018-10-04 14:28:39 +02:00
|
|
|
packet_router_ = packet_router;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelReceive::ResetReceiverCongestionControlObjects() {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DCHECK(packet_router_);
|
2020-06-03 22:55:33 +02:00
|
|
|
packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get());
|
2018-10-04 14:28:39 +02:00
|
|
|
packet_router_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
// --- RtcpStatistics
|
2018-11-12 13:22:47 +01:00
|
|
|
CallReceiveStatistics stats;
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
// The jitter statistics is updated for each received RTP packet and is
|
|
|
|
|
// based on received packets.
|
2019-08-22 09:40:25 +02:00
|
|
|
RtpReceiveStats rtp_stats;
|
2018-10-04 14:28:39 +02:00
|
|
|
StreamStatistician* statistician =
|
|
|
|
|
rtp_receive_statistics_->GetStatistician(remote_ssrc_);
|
|
|
|
|
if (statistician) {
|
2019-08-22 09:40:25 +02:00
|
|
|
rtp_stats = statistician->GetStats();
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 09:40:25 +02:00
|
|
|
stats.cumulativeLost = rtp_stats.packets_lost;
|
|
|
|
|
stats.jitterSamples = rtp_stats.jitter;
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
// --- RTT
|
|
|
|
|
stats.rttMs = GetRTT();
|
|
|
|
|
|
|
|
|
|
// --- Data counters
|
|
|
|
|
if (statistician) {
|
2019-10-09 15:01:33 +02:00
|
|
|
stats.payload_bytes_rcvd = rtp_stats.packet_counter.payload_bytes;
|
|
|
|
|
|
|
|
|
|
stats.header_and_padding_bytes_rcvd =
|
|
|
|
|
rtp_stats.packet_counter.header_bytes +
|
|
|
|
|
rtp_stats.packet_counter.padding_bytes;
|
2019-08-22 09:40:25 +02:00
|
|
|
stats.packetsReceived = rtp_stats.packet_counter.packets;
|
2019-04-15 17:32:00 +02:00
|
|
|
stats.last_packet_received_timestamp_ms =
|
2019-08-22 09:40:25 +02:00
|
|
|
rtp_stats.last_packet_received_timestamp_ms;
|
2019-04-15 17:32:00 +02:00
|
|
|
} else {
|
2019-10-09 15:01:33 +02:00
|
|
|
stats.payload_bytes_rcvd = 0;
|
|
|
|
|
stats.header_and_padding_bytes_rcvd = 0;
|
2019-04-15 17:32:00 +02:00
|
|
|
stats.packetsReceived = 0;
|
|
|
|
|
stats.last_packet_received_timestamp_ms = absl::nullopt;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Timestamps
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&ts_stats_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
|
|
|
|
|
}
|
2018-11-12 13:22:47 +01:00
|
|
|
return stats;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
void ChannelReceive::SetNACKStatus(bool enable, int max_packets) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
// None of these functions can fail.
|
2018-12-04 18:03:52 +01:00
|
|
|
if (enable) {
|
2019-07-30 15:15:59 +02:00
|
|
|
rtp_receive_statistics_->SetMaxReorderingThreshold(max_packets);
|
|
|
|
|
acm_receiver_.EnableNack(max_packets);
|
2018-12-04 18:03:52 +01:00
|
|
|
} else {
|
|
|
|
|
rtp_receive_statistics_->SetMaxReorderingThreshold(
|
2019-07-30 15:15:59 +02:00
|
|
|
kDefaultMaxReorderingThreshold);
|
|
|
|
|
acm_receiver_.DisableNack();
|
2018-12-04 18:03:52 +01:00
|
|
|
}
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when we are missing one or more packets.
|
|
|
|
|
int ChannelReceive::ResendPackets(const uint16_t* sequence_numbers,
|
|
|
|
|
int length) {
|
2020-06-03 22:55:33 +02:00
|
|
|
return rtp_rtcp_->SendNACK(sequence_numbers, length);
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-19 10:27:07 +01:00
|
|
|
void ChannelReceive::SetAssociatedSendChannel(
|
|
|
|
|
const ChannelSendInterface* channel) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&assoc_send_channel_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
associated_send_channel_ = channel;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 07:46:16 +02:00
|
|
|
void ChannelReceive::SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {
|
|
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-04-01 10:19:44 +02:00
|
|
|
// Depending on when the channel is created, the transformer might be set
|
|
|
|
|
// twice. Don't replace the delegate if it was already initialized.
|
|
|
|
|
if (!frame_transformer || frame_transformer_delegate_)
|
|
|
|
|
return;
|
|
|
|
|
InitFrameTransformerDelegate(std::move(frame_transformer));
|
2020-04-01 07:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-14 10:47:50 +02:00
|
|
|
NetworkStatistics ChannelReceive::GetNetworkStatistics(
|
|
|
|
|
bool get_and_clear_legacy_stats) const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-11-12 13:22:47 +01:00
|
|
|
NetworkStatistics stats;
|
2020-09-14 10:47:50 +02:00
|
|
|
acm_receiver_.GetNetworkStatistics(&stats, get_and_clear_legacy_stats);
|
2018-11-12 13:22:47 +01:00
|
|
|
return stats;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-12 13:22:47 +01:00
|
|
|
AudioDecodingCallStats ChannelReceive::GetDecodingCallStatistics() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2018-11-12 13:22:47 +01:00
|
|
|
AudioDecodingCallStats stats;
|
2019-07-30 15:15:59 +02:00
|
|
|
acm_receiver_.GetDecodingCallStatistics(&stats);
|
2018-11-12 13:22:47 +01:00
|
|
|
return stats;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t ChannelReceive::GetDelayEstimate() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent() ||
|
|
|
|
|
module_process_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2019-07-30 15:15:59 +02:00
|
|
|
return acm_receiver_.FilteredCurrentDelayMs() + playout_delay_ms_;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-08 16:30:25 +02:00
|
|
|
bool ChannelReceive::SetMinimumPlayoutDelay(int delay_ms) {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(module_process_thread_checker_.IsCurrent());
|
2018-11-16 09:50:42 +01:00
|
|
|
// Limit to range accepted by both VoE and ACM, so we're at least getting as
|
|
|
|
|
// close as possible, instead of failing.
|
2019-02-03 22:21:02 +01:00
|
|
|
delay_ms = rtc::SafeClamp(delay_ms, kVoiceEngineMinMinPlayoutDelayMs,
|
|
|
|
|
kVoiceEngineMaxMinPlayoutDelayMs);
|
2019-07-30 15:15:59 +02:00
|
|
|
if (acm_receiver_.SetMinimumDelay(delay_ms) != 0) {
|
2018-10-04 14:28:39 +02:00
|
|
|
RTC_DLOG(LS_ERROR)
|
|
|
|
|
<< "SetMinimumPlayoutDelay() failed to set min playout delay";
|
2020-09-08 16:30:25 +02:00
|
|
|
return false;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
2020-09-08 16:30:25 +02:00
|
|
|
return true;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-22 15:23:44 +02:00
|
|
|
bool ChannelReceive::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
|
|
|
|
|
int64_t* time_ms) const {
|
2018-11-16 09:50:42 +01:00
|
|
|
RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
|
2018-10-04 14:28:39 +02:00
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2019-10-22 15:23:44 +02:00
|
|
|
if (!playout_timestamp_rtp_time_ms_)
|
|
|
|
|
return false;
|
|
|
|
|
*rtp_timestamp = playout_timestamp_rtp_;
|
|
|
|
|
*time_ms = playout_timestamp_rtp_time_ms_.value();
|
|
|
|
|
return true;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 15:23:44 +02:00
|
|
|
void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
|
|
|
|
|
int64_t time_ms) {
|
|
|
|
|
RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2019-10-22 15:23:44 +02:00
|
|
|
playout_timestamp_ntp_ = ntp_timestamp_ms;
|
|
|
|
|
playout_timestamp_ntp_time_ms_ = time_ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
absl::optional<int64_t>
|
|
|
|
|
ChannelReceive::GetCurrentEstimatedPlayoutNtpTimestampMs(int64_t now_ms) const {
|
|
|
|
|
RTC_DCHECK(worker_thread_checker_.IsCurrent());
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2019-10-22 15:23:44 +02:00
|
|
|
if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_ms_)
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
|
|
|
|
|
int64_t elapsed_ms = now_ms - *playout_timestamp_ntp_time_ms_;
|
|
|
|
|
return *playout_timestamp_ntp_ + elapsed_ms;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 09:45:56 +01:00
|
|
|
bool ChannelReceive::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
|
2019-07-30 15:15:59 +02:00
|
|
|
return acm_receiver_.SetBaseMinimumDelayMs(delay_ms);
|
2019-02-06 09:45:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ChannelReceive::GetBaseMinimumPlayoutDelayMs() const {
|
2019-07-30 15:15:59 +02:00
|
|
|
return acm_receiver_.GetBaseMinimumDelayMs();
|
2019-02-06 09:45:56 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
absl::optional<Syncable::Info> ChannelReceive::GetSyncInfo() const {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(module_process_thread_checker_.IsCurrent());
|
2018-10-04 14:28:39 +02:00
|
|
|
Syncable::Info info;
|
2020-06-03 22:55:33 +02:00
|
|
|
if (rtp_rtcp_->RemoteNTP(&info.capture_time_ntp_secs,
|
|
|
|
|
&info.capture_time_ntp_frac, nullptr, nullptr,
|
|
|
|
|
&info.capture_time_source_clock) != 0) {
|
2018-10-04 14:28:39 +02:00
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&sync_info_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
info.latest_received_capture_timestamp = *last_received_rtp_timestamp_;
|
|
|
|
|
info.latest_receive_time_ms = *last_received_rtp_system_time_ms_;
|
|
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 15:23:44 +02:00
|
|
|
void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms) {
|
2019-07-30 15:15:59 +02:00
|
|
|
jitter_buffer_playout_timestamp_ = acm_receiver_.GetPlayoutTimestamp();
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
if (!jitter_buffer_playout_timestamp_) {
|
|
|
|
|
// This can happen if this channel has not received any RTP packets. In
|
|
|
|
|
// this case, NetEq is not capable of computing a playout timestamp.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t delay_ms = 0;
|
|
|
|
|
if (_audioDeviceModulePtr->PlayoutDelay(&delay_ms) == -1) {
|
|
|
|
|
RTC_DLOG(LS_WARNING)
|
|
|
|
|
<< "ChannelReceive::UpdatePlayoutTimestamp() failed to read"
|
2020-01-14 12:11:31 +01:00
|
|
|
" playout delay from the ADM";
|
2018-10-04 14:28:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTC_DCHECK(jitter_buffer_playout_timestamp_);
|
|
|
|
|
uint32_t playout_timestamp = *jitter_buffer_playout_timestamp_;
|
|
|
|
|
|
|
|
|
|
// Remove the playout delay.
|
|
|
|
|
playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
|
|
|
|
|
|
|
|
|
|
{
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&video_sync_lock_);
|
2020-02-18 16:33:21 +01:00
|
|
|
if (!rtcp && playout_timestamp != playout_timestamp_rtp_) {
|
2018-10-04 14:28:39 +02:00
|
|
|
playout_timestamp_rtp_ = playout_timestamp;
|
2019-10-22 15:23:44 +02:00
|
|
|
playout_timestamp_rtp_time_ms_ = now_ms;
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
playout_delay_ms_ = delay_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ChannelReceive::GetRtpTimestampRateHz() const {
|
2019-07-30 15:15:59 +02:00
|
|
|
const auto decoder = acm_receiver_.LastDecoder();
|
2018-10-04 14:28:39 +02:00
|
|
|
// Default to the playout frequency if we've not gotten any packets yet.
|
|
|
|
|
// TODO(ossu): Zero clockrate can only happen if we've added an external
|
|
|
|
|
// decoder for a format we don't support internally. Remove once that way of
|
|
|
|
|
// adding decoders is gone!
|
2019-10-11 09:37:42 +02:00
|
|
|
// TODO(kwiberg): `decoder->second.clockrate_hz` is an RTP clockrate as it
|
|
|
|
|
// should, but `acm_receiver_.last_output_sample_rate_hz()` is a codec sample
|
|
|
|
|
// rate, which is not always the same thing.
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
return (decoder && decoder->second.clockrate_hz != 0)
|
|
|
|
|
? decoder->second.clockrate_hz
|
2019-07-30 15:15:59 +02:00
|
|
|
: acm_receiver_.last_output_sample_rate_hz();
|
2018-10-04 14:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t ChannelReceive::GetRTT() const {
|
|
|
|
|
std::vector<RTCPReportBlock> report_blocks;
|
2020-06-03 22:55:33 +02:00
|
|
|
rtp_rtcp_->RemoteRTCPStat(&report_blocks);
|
2018-10-04 14:28:39 +02:00
|
|
|
|
|
|
|
|
// TODO(nisse): Could we check the return value from the ->RTT() call below,
|
|
|
|
|
// instead of checking if we have any report blocks?
|
|
|
|
|
if (report_blocks.empty()) {
|
2020-07-06 15:15:07 +02:00
|
|
|
MutexLock lock(&assoc_send_channel_lock_);
|
2018-10-04 14:28:39 +02:00
|
|
|
// Tries to get RTT from an associated channel.
|
|
|
|
|
if (!associated_send_channel_) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return associated_send_channel_->GetRTT();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t rtt = 0;
|
|
|
|
|
int64_t avg_rtt = 0;
|
|
|
|
|
int64_t max_rtt = 0;
|
|
|
|
|
int64_t min_rtt = 0;
|
2018-10-31 15:25:26 +01:00
|
|
|
// TODO(nisse): This method computes RTT based on sender reports, even though
|
|
|
|
|
// a receive stream is not supposed to do that.
|
2020-06-03 22:55:33 +02:00
|
|
|
if (rtp_rtcp_->RTT(remote_ssrc_, &rtt, &avg_rtt, &min_rtt, &max_rtt) != 0) {
|
2018-10-04 14:28:39 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return rtt;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
|
2019-03-04 17:43:34 +01:00
|
|
|
Clock* clock,
|
2018-11-16 09:50:42 +01:00
|
|
|
ProcessThread* module_process_thread,
|
2019-11-01 11:47:51 +01:00
|
|
|
NetEqFactory* neteq_factory,
|
2018-11-16 09:50:42 +01:00
|
|
|
AudioDeviceModule* audio_device_module,
|
|
|
|
|
Transport* rtcp_send_transport,
|
|
|
|
|
RtcEventLog* rtc_event_log,
|
2019-08-21 13:36:20 +02:00
|
|
|
uint32_t local_ssrc,
|
2018-11-16 09:50:42 +01:00
|
|
|
uint32_t remote_ssrc,
|
|
|
|
|
size_t jitter_buffer_max_packets,
|
|
|
|
|
bool jitter_buffer_fast_playout,
|
2018-11-27 15:45:20 +01:00
|
|
|
int jitter_buffer_min_delay_ms,
|
2019-01-10 15:58:36 +01:00
|
|
|
bool jitter_buffer_enable_rtx_handling,
|
2018-11-16 09:50:42 +01:00
|
|
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
|
|
|
|
absl::optional<AudioCodecPairId> codec_pair_id,
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
|
2020-04-01 07:46:16 +02:00
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
|
|
|
|
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
|
2019-09-17 17:06:18 +02:00
|
|
|
return std::make_unique<ChannelReceive>(
|
2019-11-01 11:47:51 +01:00
|
|
|
clock, module_process_thread, neteq_factory, audio_device_module,
|
2019-11-26 09:19:40 -08:00
|
|
|
rtcp_send_transport, rtc_event_log, local_ssrc, remote_ssrc,
|
|
|
|
|
jitter_buffer_max_packets, jitter_buffer_fast_playout,
|
2019-01-10 15:58:36 +01:00
|
|
|
jitter_buffer_min_delay_ms, jitter_buffer_enable_rtx_handling,
|
2020-04-01 07:46:16 +02:00
|
|
|
decoder_factory, codec_pair_id, frame_decryptor, crypto_options,
|
|
|
|
|
std::move(frame_transformer));
|
2018-11-16 09:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 14:28:39 +02:00
|
|
|
} // namespace voe
|
|
|
|
|
} // namespace webrtc
|