webrtc_m130/audio/audio_send_stream.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

234 lines
9.0 KiB
C
Raw Normal View History

/*
* 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.
*/
#ifndef AUDIO_AUDIO_SEND_STREAM_H_
#define AUDIO_AUDIO_SEND_STREAM_H_
#include <memory>
#include <utility>
#include <vector>
#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"
#include "audio/channel_send.h"
#include "call/audio_send_stream.h"
#include "call/audio_state.h"
#include "call/bitrate_allocator.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#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"
#include "rtc_base/synchronization/mutex.h"
Adds ChannelSend specific encoder task queue. Before this change the encoder tasks runs on a shared worker queue. That makes the destruction require synchronization to avoid races. By keeping a separate encode queue to ChannelSend, we can safely destruct the object without worrying for left over tasks, as they will be stopped when the task queue is destroyed. For TaskQueue implementations using one thread per TaskQueue this will increase the thread count by the number of AudioSendStreams, which typically is just one. This is partly a reland of 9b9344742b186b14d87e827e71a1757f4c94b30e Original change's description: > Removes lock from ChannelSend. > > The lock isn't really needed as encoder_queue_is_active_ can be checked > on the task queue to provide synchronization. > > There is one behavioral change due to this: We will not cancel any currently > pending encoding tasks when we stop sending, they will be allowed to finish. > > Bug: webrtc:10365 > Change-Id: I2b4897dde8d49bc7ee5d2d69694616aee8aaea38 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125096 > Reviewed-by: Oskar Sundbom <ossu@webrtc.org> > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#26963} Bug: webrtc:10365 Change-Id: Iafb84e25d90ec8639359be80fad65763d08e5719 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125740 Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27038}
2019-03-08 14:50:30 +01:00
#include "rtc_base/task_queue.h"
namespace webrtc {
class RtcEventLog;
class RtcpBandwidthObserver;
class RtcpRttStats;
class RtpTransportControllerSendInterface;
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();
};
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;
class AudioSendStream final : public webrtc::AudioSendStream,
public webrtc::BitrateAllocatorObserver {
public:
AudioSendStream(Clock* clock,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Adds ChannelSend specific encoder task queue. Before this change the encoder tasks runs on a shared worker queue. That makes the destruction require synchronization to avoid races. By keeping a separate encode queue to ChannelSend, we can safely destruct the object without worrying for left over tasks, as they will be stopped when the task queue is destroyed. For TaskQueue implementations using one thread per TaskQueue this will increase the thread count by the number of AudioSendStreams, which typically is just one. This is partly a reland of 9b9344742b186b14d87e827e71a1757f4c94b30e Original change's description: > Removes lock from ChannelSend. > > The lock isn't really needed as encoder_queue_is_active_ can be checked > on the task queue to provide synchronization. > > There is one behavioral change due to this: We will not cancel any currently > pending encoding tasks when we stop sending, they will be allowed to finish. > > Bug: webrtc:10365 > Change-Id: I2b4897dde8d49bc7ee5d2d69694616aee8aaea38 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125096 > Reviewed-by: Oskar Sundbom <ossu@webrtc.org> > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#26963} Bug: webrtc:10365 Change-Id: Iafb84e25d90ec8639359be80fad65763d08e5719 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125740 Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27038}
2019-03-08 14:50:30 +01:00
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
RtcpRttStats* rtcp_rtt_stats,
const absl::optional<RtpState>& suspended_rtp_state);
// For unit tests, which need to supply a mock ChannelSend.
AudioSendStream(Clock* clock,
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
Adds ChannelSend specific encoder task queue. Before this change the encoder tasks runs on a shared worker queue. That makes the destruction require synchronization to avoid races. By keeping a separate encode queue to ChannelSend, we can safely destruct the object without worrying for left over tasks, as they will be stopped when the task queue is destroyed. For TaskQueue implementations using one thread per TaskQueue this will increase the thread count by the number of AudioSendStreams, which typically is just one. This is partly a reland of 9b9344742b186b14d87e827e71a1757f4c94b30e Original change's description: > Removes lock from ChannelSend. > > The lock isn't really needed as encoder_queue_is_active_ can be checked > on the task queue to provide synchronization. > > There is one behavioral change due to this: We will not cancel any currently > pending encoding tasks when we stop sending, they will be allowed to finish. > > Bug: webrtc:10365 > Change-Id: I2b4897dde8d49bc7ee5d2d69694616aee8aaea38 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125096 > Reviewed-by: Oskar Sundbom <ossu@webrtc.org> > Commit-Queue: Sebastian Jansson <srte@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#26963} Bug: webrtc:10365 Change-Id: Iafb84e25d90ec8639359be80fad65763d08e5719 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125740 Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27038}
2019-03-08 14:50:30 +01:00
TaskQueueFactory* task_queue_factory,
RtpTransportControllerSendInterface* rtp_transport,
BitrateAllocatorInterface* bitrate_allocator,
RtcEventLog* event_log,
const absl::optional<RtpState>& suspended_rtp_state,
std::unique_ptr<voe::ChannelSendInterface> channel_send);
AudioSendStream() = delete;
AudioSendStream(const AudioSendStream&) = delete;
AudioSendStream& operator=(const AudioSendStream&) = delete;
~AudioSendStream() override;
// webrtc::AudioSendStream implementation.
const webrtc::AudioSendStream::Config& GetConfig() const override;
void Reconfigure(const webrtc::AudioSendStream::Config& config) override;
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;
bool SendTelephoneEvent(int payload_type,
int payload_frequency,
int event,
int duration_ms) override;
void SetMuted(bool muted) override;
webrtc::AudioSendStream::Stats GetStats() const override;
webrtc::AudioSendStream::Stats GetStats(
bool has_remote_tracks) const override;
void DeliverRtcp(const uint8_t* packet, size_t length);
// Implements BitrateAllocatorObserver.
uint32_t OnBitrateUpdated(BitrateAllocationUpdate update) override;
void SetTransportOverhead(int transport_overhead_per_packet_bytes);
RtpState GetRtpState() const;
const voe::ChannelSendInterface* GetChannel() const;
// Returns combined per-packet overhead.
size_t TestOnlyGetPerPacketOverheadBytes() const
RTC_LOCKS_EXCLUDED(overhead_per_packet_lock_);
private:
class TimedTransport;
// Constraints including overhead.
struct TargetAudioBitrateConstraints {
DataRate min;
DataRate max;
};
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;
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
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_);
// Returns bitrate constraints, maybe including overhead when enabled by
// field trial.
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
2021-02-03 13:33:28 +01:00
absl::optional<TargetAudioBitrateConstraints> GetMinMaxBitrateConstraints()
const RTC_RUN_ON(worker_thread_checker_);
// 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_);
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
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_);
Clock* clock_;
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
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_;
rtc::TaskQueue* rtp_transport_queue_;
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_;
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
2021-02-03 13:33:28 +01:00
webrtc::AudioSendStream::Config config_
RTC_GUARDED_BY(worker_thread_checker_);
rtc::scoped_refptr<webrtc::AudioState> audio_state_;
const std::unique_ptr<voe::ChannelSendInterface> channel_send_;
RtcEventLog* const event_log_;
const bool use_legacy_overhead_calculation_;
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
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;
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
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
BitrateAllocatorInterface* const bitrate_allocator_
RTC_GUARDED_BY(rtp_transport_queue_);
// Constrains cached to be accessed from `rtp_transport_queue_`.
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
2021-02-03 13:33:28 +01:00
absl::optional<AudioSendStream::TargetAudioBitrateConstraints>
cached_constraints_ RTC_GUARDED_BY(rtp_transport_queue_) = absl::nullopt;
RtpTransportControllerSendInterface* const rtp_transport_;
RtpRtcpInterface* const rtp_rtcp_module_;
absl::optional<RtpState> const suspended_rtp_state_;
// 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;
int abs_send_time = 0;
int abs_capture_time = 0;
int transport_sequence_number = 0;
int mid = 0;
int rid = 0;
int repaired_rid = 0;
};
static ExtensionIds FindExtensionIds(
const std::vector<RtpExtension>& extensions);
static int TransportSeqNumId(const Config& config);
mutable Mutex overhead_per_packet_lock_;
size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
// Current transport overhead (ICE, TURN, etc.)
size_t transport_overhead_per_packet_bytes_
RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
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;
absl::optional<std::pair<TimeDelta, TimeDelta>> frame_length_range_
Reland "Fix data race for config_ in AudioSendStream" This is a reland of 51e5c4b0f47926e2586d809e47dc60fe4812b782 It may happen that user will pass config with min bitrate > max bitrate. In such case we can't generate cached_constraints and will crash before. The reland will handle this situation gracefully. Original change's description: > Fix data race for config_ in AudioSendStream > > config_ was written and read on different threads without sync. This CL > moves config access on worker_thread_ with all other required fields. > It keeps only bitrate allocator accessed from worker_queue_, because > it is used from it in other classes and supposed to be single threaded. > > Bug: None > Change-Id: I23ece4dc8b09b41a8c589412bedd36d63b76cbc5 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203267 > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > Reviewed-by: Niels Moller <nisse@webrtc.org> > Reviewed-by: Per Åhgren <peah@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#33125} Bug: None Change-Id: I274ff15208d69c25fb25a0f1dd0a0e37b72480b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205523 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33162}
2021-02-03 13:33:28 +01:00
RTC_GUARDED_BY(worker_thread_checker_);
};
} // namespace internal
} // namespace webrtc
#endif // AUDIO_AUDIO_SEND_STREAM_H_