2015-10-16 14:35:07 -07: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef AUDIO_AUDIO_SEND_STREAM_H_
|
|
|
|
|
#define AUDIO_AUDIO_SEND_STREAM_H_
|
2015-10-16 14:35:07 -07:00
|
|
|
|
2016-02-23 10:46:32 -08:00
|
|
|
#include <memory>
|
2019-10-02 12:27:06 +02:00
|
|
|
#include <utility>
|
2017-03-23 11:04:48 -07:00
|
|
|
#include <vector>
|
2016-02-23 10:46:32 -08:00
|
|
|
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
[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
|
|
|
#include "audio/audio_level.h"
|
2018-11-19 10:27:07 +01:00
|
|
|
#include "audio/channel_send.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/audio_send_stream.h"
|
|
|
|
|
#include "call/audio_state.h"
|
|
|
|
|
#include "call/bitrate_allocator.h"
|
2020-06-03 22:55:33 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
|
2019-10-03 10:03:55 +02:00
|
|
|
#include "rtc_base/experiments/struct_parameters_parser.h"
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
#include "rtc_base/race_checker.h"
|
2020-07-06 15:15:07 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2019-03-08 14:50:30 +01:00
|
|
|
#include "rtc_base/task_queue.h"
|
2015-10-16 14:35:07 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-09-21 06:51:47 -07:00
|
|
|
class RtcEventLog;
|
2017-02-07 07:14:08 -08:00
|
|
|
class RtcpBandwidthObserver;
|
2016-11-30 07:51:13 -08:00
|
|
|
class RtcpRttStats;
|
2017-03-27 05:36:15 -07:00
|
|
|
class RtpTransportControllerSendInterface;
|
2015-11-16 07:34:50 -08:00
|
|
|
|
2019-10-03 10:03:55 +02:00
|
|
|
struct AudioAllocationConfig {
|
|
|
|
|
static constexpr char kKey[] = "WebRTC-Audio-Allocation";
|
|
|
|
|
// Field Trial configured bitrates to use as overrides over default/user
|
|
|
|
|
// configured bitrate range when audio bitrate allocation is enabled.
|
|
|
|
|
absl::optional<DataRate> min_bitrate;
|
|
|
|
|
absl::optional<DataRate> max_bitrate;
|
|
|
|
|
DataRate priority_bitrate = DataRate::Zero();
|
|
|
|
|
// By default the priority_bitrate is compensated for packet overhead.
|
|
|
|
|
// Use this flag to configure a raw value instead.
|
|
|
|
|
absl::optional<DataRate> priority_bitrate_raw;
|
|
|
|
|
absl::optional<double> bitrate_priority;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<StructParametersParser> Parser();
|
|
|
|
|
AudioAllocationConfig();
|
|
|
|
|
};
|
2015-11-25 08:16:52 -08:00
|
|
|
namespace internal {
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
class AudioState;
|
|
|
|
|
|
2016-07-26 04:44:06 -07:00
|
|
|
class AudioSendStream final : public webrtc::AudioSendStream,
|
2020-05-07 18:18:32 +02:00
|
|
|
public webrtc::BitrateAllocatorObserver {
|
2015-10-16 14:35:07 -07:00
|
|
|
public:
|
2019-03-04 17:43:34 +01:00
|
|
|
AudioSendStream(Clock* clock,
|
|
|
|
|
const webrtc::AudioSendStream::Config& config,
|
2015-12-07 10:26:18 +01:00
|
|
|
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
|
2019-03-08 14:50:30 +01:00
|
|
|
TaskQueueFactory* task_queue_factory,
|
2018-10-26 12:57:07 +02:00
|
|
|
RtpTransportControllerSendInterface* rtp_transport,
|
2018-10-22 13:00:40 +02:00
|
|
|
BitrateAllocatorInterface* bitrate_allocator,
|
2016-11-30 07:51:13 -08:00
|
|
|
RtcEventLog* event_log,
|
2017-05-23 06:07:11 -07:00
|
|
|
RtcpRttStats* rtcp_rtt_stats,
|
2018-11-20 17:15:13 +01:00
|
|
|
const absl::optional<RtpState>& suspended_rtp_state);
|
2018-11-19 10:27:07 +01:00
|
|
|
// For unit tests, which need to supply a mock ChannelSend.
|
2019-03-04 17:43:34 +01:00
|
|
|
AudioSendStream(Clock* clock,
|
|
|
|
|
const webrtc::AudioSendStream::Config& config,
|
2018-01-11 13:52:30 +01:00
|
|
|
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
|
2019-03-08 14:50:30 +01:00
|
|
|
TaskQueueFactory* task_queue_factory,
|
2018-10-26 12:57:07 +02:00
|
|
|
RtpTransportControllerSendInterface* rtp_transport,
|
2018-10-22 13:00:40 +02:00
|
|
|
BitrateAllocatorInterface* bitrate_allocator,
|
2018-01-11 13:52:30 +01:00
|
|
|
RtcEventLog* event_log,
|
2018-06-15 12:28:07 +02:00
|
|
|
const absl::optional<RtpState>& suspended_rtp_state,
|
2018-11-19 10:27:07 +01:00
|
|
|
std::unique_ptr<voe::ChannelSendInterface> channel_send);
|
2020-09-29 09:46:21 +02:00
|
|
|
|
|
|
|
|
AudioSendStream() = delete;
|
|
|
|
|
AudioSendStream(const AudioSendStream&) = delete;
|
|
|
|
|
AudioSendStream& operator=(const AudioSendStream&) = delete;
|
|
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
~AudioSendStream() override;
|
|
|
|
|
|
2016-05-01 20:18:34 -07:00
|
|
|
// webrtc::AudioSendStream implementation.
|
2017-07-26 02:09:44 -07:00
|
|
|
const webrtc::AudioSendStream::Config& GetConfig() const override;
|
2017-04-27 02:08:52 -07:00
|
|
|
void Reconfigure(const webrtc::AudioSendStream::Config& config) override;
|
2015-10-16 14:35:07 -07:00
|
|
|
void Start() override;
|
|
|
|
|
void Stop() override;
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
void SendAudioData(std::unique_ptr<AudioFrame> audio_frame) override;
|
2016-11-17 05:25:37 -08:00
|
|
|
bool SendTelephoneEvent(int payload_type,
|
|
|
|
|
int payload_frequency,
|
|
|
|
|
int event,
|
2016-03-11 03:06:41 -08:00
|
|
|
int duration_ms) override;
|
2016-06-16 10:53:22 -07:00
|
|
|
void SetMuted(bool muted) override;
|
2015-10-16 14:35:07 -07:00
|
|
|
webrtc::AudioSendStream::Stats GetStats() const override;
|
2017-11-24 17:29:59 +01:00
|
|
|
webrtc::AudioSendStream::Stats GetStats(
|
|
|
|
|
bool has_remote_tracks) const override;
|
2015-10-16 14:35:07 -07:00
|
|
|
|
2019-03-05 14:29:42 +01:00
|
|
|
void DeliverRtcp(const uint8_t* packet, size_t length);
|
2016-07-26 04:44:06 -07:00
|
|
|
|
|
|
|
|
// Implements BitrateAllocatorObserver.
|
2018-10-25 15:08:32 +02:00
|
|
|
uint32_t OnBitrateUpdated(BitrateAllocationUpdate update) override;
|
2016-07-26 04:44:06 -07:00
|
|
|
|
2019-02-04 15:16:06 -08:00
|
|
|
void SetTransportOverhead(int transport_overhead_per_packet_bytes);
|
|
|
|
|
|
2017-05-23 06:07:11 -07:00
|
|
|
RtpState GetRtpState() const;
|
2018-11-19 10:27:07 +01:00
|
|
|
const voe::ChannelSendInterface* GetChannel() const;
|
2017-05-23 06:07:11 -07:00
|
|
|
|
2019-02-04 15:16:06 -08:00
|
|
|
// Returns combined per-packet overhead.
|
|
|
|
|
size_t TestOnlyGetPerPacketOverheadBytes() const
|
|
|
|
|
RTC_LOCKS_EXCLUDED(overhead_per_packet_lock_);
|
|
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
private:
|
2017-07-19 00:39:19 -07:00
|
|
|
class TimedTransport;
|
2019-05-03 14:40:13 +02:00
|
|
|
// Constraints including overhead.
|
|
|
|
|
struct TargetAudioBitrateConstraints {
|
|
|
|
|
DataRate min;
|
|
|
|
|
DataRate max;
|
|
|
|
|
};
|
2017-07-19 00:39:19 -07:00
|
|
|
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
internal::AudioState* audio_state();
|
|
|
|
|
const internal::AudioState* audio_state() const;
|
2015-11-16 07:34:50 -08:00
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
void StoreEncoderProperties(int sample_rate_hz, size_t num_channels)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
|
|
|
|
|
void ConfigureStream(const Config& new_config, bool first_time)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
bool SetupSendCodec(const Config& new_config)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
bool ReconfigureSendCodec(const Config& new_config)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
void ReconfigureANA(const Config& new_config)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
void ReconfigureCNG(const Config& new_config)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
void ReconfigureBitrateObserver(const Config& new_config)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
|
|
|
|
|
void ConfigureBitrateObserver() RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
void RemoveBitrateObserver() RTC_RUN_ON(worker_thread_checker_);
|
2016-10-20 03:27:12 -07:00
|
|
|
|
2019-05-03 14:40:13 +02:00
|
|
|
// Returns bitrate constraints, maybe including overhead when enabled by
|
|
|
|
|
// field trial.
|
2021-02-03 13:33:28 +01:00
|
|
|
absl::optional<TargetAudioBitrateConstraints> GetMinMaxBitrateConstraints()
|
|
|
|
|
const RTC_RUN_ON(worker_thread_checker_);
|
2019-05-03 14:40:13 +02:00
|
|
|
|
2019-02-04 15:16:06 -08:00
|
|
|
// Sets per-packet overhead on encoded (for ANA) based on current known values
|
|
|
|
|
// of transport and packetization overheads.
|
|
|
|
|
void UpdateOverheadForEncoder()
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
|
|
|
|
|
|
|
|
|
|
// Returns combined per-packet overhead.
|
|
|
|
|
size_t GetPerPacketOverheadBytes() const
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
|
|
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
void RegisterCngPayloadType(int payload_type, int clockrate_hz)
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
|
|
|
|
|
void UpdateCachedTargetAudioBitrateConstraints()
|
|
|
|
|
RTC_RUN_ON(worker_thread_checker_);
|
|
|
|
|
|
2019-03-04 17:43:34 +01:00
|
|
|
Clock* clock_;
|
2017-04-27 08:03:42 -07:00
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
SequenceChecker worker_thread_checker_;
|
|
|
|
|
SequenceChecker pacer_thread_checker_;
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
rtc::RaceChecker audio_capture_race_checker_;
|
2021-06-01 09:07:20 +02:00
|
|
|
rtc::TaskQueue* rtp_transport_queue_;
|
2019-10-03 10:03:55 +02:00
|
|
|
|
|
|
|
|
const bool allocate_audio_without_feedback_;
|
|
|
|
|
const bool force_no_audio_feedback_ = allocate_audio_without_feedback_;
|
|
|
|
|
const bool enable_audio_alr_probing_;
|
|
|
|
|
const bool send_side_bwe_with_overhead_;
|
|
|
|
|
const AudioAllocationConfig allocation_settings_;
|
|
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
webrtc::AudioSendStream::Config config_
|
|
|
|
|
RTC_GUARDED_BY(worker_thread_checker_);
|
2015-11-06 15:34:49 -08:00
|
|
|
rtc::scoped_refptr<webrtc::AudioState> audio_state_;
|
2018-11-19 10:27:07 +01:00
|
|
|
const std::unique_ptr<voe::ChannelSendInterface> channel_send_;
|
2017-04-27 02:08:52 -07:00
|
|
|
RtcEventLog* const event_log_;
|
2019-10-02 12:27:06 +02:00
|
|
|
const bool use_legacy_overhead_calculation_;
|
2015-10-27 03:35:21 -07:00
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
int encoder_sample_rate_hz_ RTC_GUARDED_BY(worker_thread_checker_) = 0;
|
|
|
|
|
size_t encoder_num_channels_ RTC_GUARDED_BY(worker_thread_checker_) = 0;
|
|
|
|
|
bool sending_ RTC_GUARDED_BY(worker_thread_checker_) = false;
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex audio_level_lock_;
|
[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
|
|
|
// Keeps track of audio level, total audio energy and total samples duration.
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#dom-rtcaudiohandlerstats-totalaudioenergy
|
2020-07-06 17:46:36 +02:00
|
|
|
webrtc::voe::AudioLevel audio_level_ RTC_GUARDED_BY(audio_level_lock_);
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
|
2019-03-01 15:57:55 +01:00
|
|
|
BitrateAllocatorInterface* const bitrate_allocator_
|
2021-06-01 09:07:20 +02:00
|
|
|
RTC_GUARDED_BY(rtp_transport_queue_);
|
2021-07-26 11:47:07 +02:00
|
|
|
// Constrains cached to be accessed from `rtp_transport_queue_`.
|
2021-02-03 13:33:28 +01:00
|
|
|
absl::optional<AudioSendStream::TargetAudioBitrateConstraints>
|
2021-06-01 09:07:20 +02:00
|
|
|
cached_constraints_ RTC_GUARDED_BY(rtp_transport_queue_) = absl::nullopt;
|
2018-10-26 12:57:07 +02:00
|
|
|
RtpTransportControllerSendInterface* const rtp_transport_;
|
2016-07-26 04:44:06 -07:00
|
|
|
|
2020-06-03 22:55:33 +02:00
|
|
|
RtpRtcpInterface* const rtp_rtcp_module_;
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::optional<RtpState> const suspended_rtp_state_;
|
2017-05-23 06:07:11 -07:00
|
|
|
|
2017-12-07 20:54:55 +01:00
|
|
|
// RFC 5285: Each distinct extension MUST have a unique ID. The value 0 is
|
|
|
|
|
// reserved for padding and MUST NOT be used as a local identifier.
|
|
|
|
|
// So it should be safe to use 0 here to indicate "not configured".
|
|
|
|
|
struct ExtensionIds {
|
|
|
|
|
int audio_level = 0;
|
2019-08-14 11:31:02 +02:00
|
|
|
int abs_send_time = 0;
|
2020-03-05 11:33:13 +01:00
|
|
|
int abs_capture_time = 0;
|
2017-12-07 20:54:55 +01:00
|
|
|
int transport_sequence_number = 0;
|
2018-03-26 10:24:32 -07:00
|
|
|
int mid = 0;
|
2018-12-21 09:23:38 -08:00
|
|
|
int rid = 0;
|
|
|
|
|
int repaired_rid = 0;
|
2017-12-07 20:54:55 +01:00
|
|
|
};
|
|
|
|
|
static ExtensionIds FindExtensionIds(
|
|
|
|
|
const std::vector<RtpExtension>& extensions);
|
2019-01-23 12:37:49 +01:00
|
|
|
static int TransportSeqNumId(const Config& config);
|
2017-12-07 20:54:55 +01:00
|
|
|
|
2020-07-06 15:15:07 +02:00
|
|
|
mutable Mutex overhead_per_packet_lock_;
|
2020-05-13 14:43:11 +02:00
|
|
|
size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
|
2019-02-04 15:16:06 -08:00
|
|
|
|
|
|
|
|
// Current transport overhead (ICE, TURN, etc.)
|
|
|
|
|
size_t transport_overhead_per_packet_bytes_
|
|
|
|
|
RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
|
|
|
|
|
|
2021-02-03 13:33:28 +01:00
|
|
|
bool registered_with_allocator_ RTC_GUARDED_BY(worker_thread_checker_) =
|
|
|
|
|
false;
|
|
|
|
|
size_t total_packet_overhead_bytes_ RTC_GUARDED_BY(worker_thread_checker_) =
|
|
|
|
|
0;
|
2019-10-02 12:27:06 +02:00
|
|
|
absl::optional<std::pair<TimeDelta, TimeDelta>> frame_length_range_
|
2021-02-03 13:33:28 +01:00
|
|
|
RTC_GUARDED_BY(worker_thread_checker_);
|
2015-10-16 14:35:07 -07:00
|
|
|
};
|
|
|
|
|
} // namespace internal
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // AUDIO_AUDIO_SEND_STREAM_H_
|