webrtc_m130/media/engine/webrtc_voice_engine.h

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

336 lines
13 KiB
C
Raw Normal View History

/*
* Copyright (c) 2004 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 MEDIA_ENGINE_WEBRTC_VOICE_ENGINE_H_
#define MEDIA_ENGINE_WEBRTC_VOICE_ENGINE_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
Reland "in WebrtcVoiceEngine allow to set TaskQueueFactory" in production code keep using GlobalTaskQueueFactory() in tests switch to use DefaultTaskQueueFactory directly. This reverts commit e27ccf9a1681e0e4ff9281f9a18fea357d2bc890. Reason for revert: addressed the failure with patchset#2 Original change's description: > Revert "in WebrtcVoiceEngine allow to set TaskQueueFactory" > > This reverts commit a39254da593bbdb0b1e072a44827229680afe3ee. > > Reason for revert: Tests are failing due to ThreadChecker's called on valid thread. > > Original change's description: > > in WebrtcVoiceEngine allow to set TaskQueueFactory > > > > in production code keep using GlobalTaskQueueFactory() > > in tests switch to use DefaultTaskQueueFactory directly. > > > > Bug: webrtc:10284 > > Change-Id: I170274a98324796623089a965a39f0cbb7e281d9 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128878 > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27296} > > TBR=danilchap@webrtc.org,steveanton@webrtc.org > > Change-Id: I9742e5d0171a94f3840e197c40fdb44523e4963b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10284 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129780 > Reviewed-by: Amit Hilbuch <amithi@webrtc.org> > Commit-Queue: Amit Hilbuch <amithi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27297} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10284 Change-Id: I55fd5811c68d04c3e8cf537974496460b38c1d4f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129933 Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27348}
2019-03-27 18:51:45 +01:00
#include "api/task_queue/task_queue_factory.h"
#include "api/transport/rtp/rtp_source.h"
#include "api/transport/webrtc_key_value_config.h"
#include "call/audio_state.h"
#include "call/call.h"
#include "media/base/media_engine.h"
#include "media/base/rtp_utils.h"
#include "modules/async_audio_processing/async_audio_processing.h"
#include "rtc_base/buffer.h"
#include "rtc_base/network_route.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/task_utils/pending_task_safety_flag.h"
namespace webrtc {
class AudioFrameProcessor;
}
namespace cricket {
class AudioSource;
class WebRtcVoiceMediaChannel;
// WebRtcVoiceEngine is a class to be used with CompositeMediaEngine.
// It uses the WebRtc VoiceEngine library for audio handling.
class WebRtcVoiceEngine final : public VoiceEngineInterface {
friend class WebRtcVoiceMediaChannel;
public:
WebRtcVoiceEngine(
Reland "in WebrtcVoiceEngine allow to set TaskQueueFactory" in production code keep using GlobalTaskQueueFactory() in tests switch to use DefaultTaskQueueFactory directly. This reverts commit e27ccf9a1681e0e4ff9281f9a18fea357d2bc890. Reason for revert: addressed the failure with patchset#2 Original change's description: > Revert "in WebrtcVoiceEngine allow to set TaskQueueFactory" > > This reverts commit a39254da593bbdb0b1e072a44827229680afe3ee. > > Reason for revert: Tests are failing due to ThreadChecker's called on valid thread. > > Original change's description: > > in WebrtcVoiceEngine allow to set TaskQueueFactory > > > > in production code keep using GlobalTaskQueueFactory() > > in tests switch to use DefaultTaskQueueFactory directly. > > > > Bug: webrtc:10284 > > Change-Id: I170274a98324796623089a965a39f0cbb7e281d9 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128878 > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27296} > > TBR=danilchap@webrtc.org,steveanton@webrtc.org > > Change-Id: I9742e5d0171a94f3840e197c40fdb44523e4963b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10284 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129780 > Reviewed-by: Amit Hilbuch <amithi@webrtc.org> > Commit-Queue: Amit Hilbuch <amithi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27297} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10284 Change-Id: I55fd5811c68d04c3e8cf537974496460b38c1d4f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129933 Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27348}
2019-03-27 18:51:45 +01:00
webrtc::TaskQueueFactory* task_queue_factory,
webrtc::AudioDeviceModule* adm,
const rtc::scoped_refptr<webrtc::AudioEncoderFactory>& encoder_factory,
const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory,
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing,
webrtc::AudioFrameProcessor* audio_frame_processor,
const webrtc::WebRtcKeyValueConfig& trials);
WebRtcVoiceEngine() = delete;
WebRtcVoiceEngine(const WebRtcVoiceEngine&) = delete;
WebRtcVoiceEngine& operator=(const WebRtcVoiceEngine&) = delete;
~WebRtcVoiceEngine() override;
// Does initialization that needs to occur on the worker thread.
void Init() override;
rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override;
VoiceMediaChannel* CreateMediaChannel(
webrtc::Call* call,
const MediaConfig& config,
const AudioOptions& options,
const webrtc::CryptoOptions& crypto_options) override;
const std::vector<AudioCodec>& send_codecs() const override;
const std::vector<AudioCodec>& recv_codecs() const override;
std::vector<webrtc::RtpHeaderExtensionCapability> GetRtpHeaderExtensions()
const override;
// Starts AEC dump using an existing file. A maximum file size in bytes can be
// specified. When the maximum file size is reached, logging is stopped and
// the file is closed. If max_size_bytes is set to <= 0, no limit will be
// used.
bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override;
// Stops AEC dump.
void StopAecDump() override;
private:
// Every option that is "set" will be applied. Every option not "set" will be
// ignored. This allows us to selectively turn on and off different options
// easily at any time.
bool ApplyOptions(const AudioOptions& options);
int CreateVoEChannel();
Reland of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2910633002/ ) Reason for revert: Revert of revert of revert of revert of 'Activating..'. Or "reland of reland of 'Activate..'". *Now* the internal projects are fixed and the fix is verified. Original issue's description: > Revert of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2903153005/ ) > > Reason for revert: > Reverting again: internal project issues were apparently not completely fixed. > > Original issue's description: > > Reland of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2904893002/ ) > > > > Reason for revert: > > Revert the revert now that internal projects are updated. > > > > Original issue's description: > > > Revert of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #4 id:160001 of https://codereview.webrtc.org/2896813002/ ) > > > > > > Reason for revert: > > > Breaks internal project. > > > > > > Original issue's description: > > > > Activate 'offload debug dump recordings from audio thread to TaskQueue'. > > > > > > > > A low priority task queue is added to WebRTCVoiceEngine. The > > > > start/stop debug calls make file logging happen on the task queue. > > > > > > > > In a dependent CL (https://codereview.webrtc.org/2888303003), the task queue is moved to PeerConnectionFactory, > > > > so that it can be shared for low priority tasks between different > > > > subcomponents. It will require some changes to MediaEngine, > > > > CompositeMediaEngine, WebRTCVoiceEngine, and changes in internal > > > > projects. > > > > > > > > A task queue must be created and destroyed from the same thread. With > > > > this CL that will be the worker thread, which creates and destroys > > > > WebRTCVoiceEngine. With the dependent CL, it will probably change to > > > > the signaling thread. > > > > > > > > NOTRY=True # tests just passed > > > > > > > > BUG=webrtc:7404 > > > > > > > > Review-Url: https://codereview.webrtc.org/2896813002 > > > > Cr-Commit-Position: refs/heads/master@{#18252} > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/c61bf947b4ac31f3500858ffcae6fee39d799930 > > > > > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > > > # Skipping CQ checks because original CL landed less than 1 days ago. > > > NOPRESUBMIT=true > > > NOTREECHECKS=true > > > NOTRY=true > > > BUG=webrtc:7404 > > > > > > Review-Url: https://codereview.webrtc.org/2904893002 > > > Cr-Commit-Position: refs/heads/master@{#18255} > > > Committed: https://chromium.googlesource.com/external/webrtc/+/be68b72cfad0686dcd892bba1368b199a7ee16ca > > > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > > # Not skipping CQ checks because original CL landed more than 1 days ago. > > BUG=webrtc:7404 > > > > Review-Url: https://codereview.webrtc.org/2903153005 > > Cr-Commit-Position: refs/heads/master@{#18270} > > Committed: https://chromium.googlesource.com/external/webrtc/+/d2303a2338106feab684860f1c133877b46bdd4f > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7404 > > Review-Url: https://codereview.webrtc.org/2910633002 > Cr-Commit-Position: refs/heads/master@{#18272} > Committed: https://chromium.googlesource.com/external/webrtc/+/fe9ecb07ea8254d8a09605f25203a4d045b3ffee TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7404 Review-Url: https://codereview.webrtc.org/2904423002 Cr-Commit-Position: refs/heads/master@{#18300}
2017-05-29 02:56:27 -07:00
Reland "in WebrtcVoiceEngine allow to set TaskQueueFactory" in production code keep using GlobalTaskQueueFactory() in tests switch to use DefaultTaskQueueFactory directly. This reverts commit e27ccf9a1681e0e4ff9281f9a18fea357d2bc890. Reason for revert: addressed the failure with patchset#2 Original change's description: > Revert "in WebrtcVoiceEngine allow to set TaskQueueFactory" > > This reverts commit a39254da593bbdb0b1e072a44827229680afe3ee. > > Reason for revert: Tests are failing due to ThreadChecker's called on valid thread. > > Original change's description: > > in WebrtcVoiceEngine allow to set TaskQueueFactory > > > > in production code keep using GlobalTaskQueueFactory() > > in tests switch to use DefaultTaskQueueFactory directly. > > > > Bug: webrtc:10284 > > Change-Id: I170274a98324796623089a965a39f0cbb7e281d9 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128878 > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27296} > > TBR=danilchap@webrtc.org,steveanton@webrtc.org > > Change-Id: I9742e5d0171a94f3840e197c40fdb44523e4963b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10284 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129780 > Reviewed-by: Amit Hilbuch <amithi@webrtc.org> > Commit-Queue: Amit Hilbuch <amithi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27297} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10284 Change-Id: I55fd5811c68d04c3e8cf537974496460b38c1d4f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129933 Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27348}
2019-03-27 18:51:45 +01:00
webrtc::TaskQueueFactory* const task_queue_factory_;
std::unique_ptr<rtc::TaskQueue> low_priority_worker_queue_;
Reland of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2910633002/ ) Reason for revert: Revert of revert of revert of revert of 'Activating..'. Or "reland of reland of 'Activate..'". *Now* the internal projects are fixed and the fix is verified. Original issue's description: > Revert of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2903153005/ ) > > Reason for revert: > Reverting again: internal project issues were apparently not completely fixed. > > Original issue's description: > > Reland of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #1 id:1 of https://codereview.webrtc.org/2904893002/ ) > > > > Reason for revert: > > Revert the revert now that internal projects are updated. > > > > Original issue's description: > > > Revert of Activate 'offload debug dump recordings from audio thread to TaskQueue'. (patchset #4 id:160001 of https://codereview.webrtc.org/2896813002/ ) > > > > > > Reason for revert: > > > Breaks internal project. > > > > > > Original issue's description: > > > > Activate 'offload debug dump recordings from audio thread to TaskQueue'. > > > > > > > > A low priority task queue is added to WebRTCVoiceEngine. The > > > > start/stop debug calls make file logging happen on the task queue. > > > > > > > > In a dependent CL (https://codereview.webrtc.org/2888303003), the task queue is moved to PeerConnectionFactory, > > > > so that it can be shared for low priority tasks between different > > > > subcomponents. It will require some changes to MediaEngine, > > > > CompositeMediaEngine, WebRTCVoiceEngine, and changes in internal > > > > projects. > > > > > > > > A task queue must be created and destroyed from the same thread. With > > > > this CL that will be the worker thread, which creates and destroys > > > > WebRTCVoiceEngine. With the dependent CL, it will probably change to > > > > the signaling thread. > > > > > > > > NOTRY=True # tests just passed > > > > > > > > BUG=webrtc:7404 > > > > > > > > Review-Url: https://codereview.webrtc.org/2896813002 > > > > Cr-Commit-Position: refs/heads/master@{#18252} > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/c61bf947b4ac31f3500858ffcae6fee39d799930 > > > > > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > > > # Skipping CQ checks because original CL landed less than 1 days ago. > > > NOPRESUBMIT=true > > > NOTREECHECKS=true > > > NOTRY=true > > > BUG=webrtc:7404 > > > > > > Review-Url: https://codereview.webrtc.org/2904893002 > > > Cr-Commit-Position: refs/heads/master@{#18255} > > > Committed: https://chromium.googlesource.com/external/webrtc/+/be68b72cfad0686dcd892bba1368b199a7ee16ca > > > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > > # Not skipping CQ checks because original CL landed more than 1 days ago. > > BUG=webrtc:7404 > > > > Review-Url: https://codereview.webrtc.org/2903153005 > > Cr-Commit-Position: refs/heads/master@{#18270} > > Committed: https://chromium.googlesource.com/external/webrtc/+/d2303a2338106feab684860f1c133877b46bdd4f > > TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7404 > > Review-Url: https://codereview.webrtc.org/2910633002 > Cr-Commit-Position: refs/heads/master@{#18272} > Committed: https://chromium.googlesource.com/external/webrtc/+/fe9ecb07ea8254d8a09605f25203a4d045b3ffee TBR=solenberg@webrtc.org,tommi@webrtc.org,perkj@webrtc.org,danilchap@webrtc.org,tommi@chromium.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7404 Review-Url: https://codereview.webrtc.org/2904423002 Cr-Commit-Position: refs/heads/master@{#18300}
2017-05-29 02:56:27 -07:00
webrtc::AudioDeviceModule* adm();
webrtc::AudioProcessing* apm() const;
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
webrtc::AudioState* audio_state();
std::vector<AudioCodec> CollectCodecs(
const std::vector<webrtc::AudioCodecSpec>& specs) const;
webrtc::SequenceChecker signal_thread_checker_;
webrtc::SequenceChecker worker_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
// The audio device module.
rtc::scoped_refptr<webrtc::AudioDeviceModule> adm_;
rtc::scoped_refptr<webrtc::AudioEncoderFactory> encoder_factory_;
rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory_;
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer_;
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
// The audio processing module.
rtc::scoped_refptr<webrtc::AudioProcessing> apm_;
// Asynchronous audio processing.
webrtc::AudioFrameProcessor* const audio_frame_processor_;
// The primary instance of WebRtc VoiceEngine.
rtc::scoped_refptr<webrtc::AudioState> audio_state_;
std::vector<AudioCodec> send_codecs_;
std::vector<AudioCodec> recv_codecs_;
bool is_dumping_aec_ = false;
bool initialized_ = false;
// Cache experimental_ns and apply in case they are missing in the audio
// options.
absl::optional<bool> experimental_ns_;
// Jitter buffer settings for new streams.
size_t audio_jitter_buffer_max_packets_ = 200;
bool audio_jitter_buffer_fast_accelerate_ = false;
int audio_jitter_buffer_min_delay_ms_ = 0;
bool audio_jitter_buffer_enable_rtx_handling_ = false;
// If this field trial is enabled, we will negotiate and use RFC 2198
// redundancy for opus audio.
const bool audio_red_for_opus_trial_enabled_;
const bool minimized_remsampling_on_mobile_trial_enabled_;
};
// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
// WebRtc Voice Engine.
class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
public webrtc::Transport {
public:
WebRtcVoiceMediaChannel(WebRtcVoiceEngine* engine,
const MediaConfig& config,
const AudioOptions& options,
const webrtc::CryptoOptions& crypto_options,
webrtc::Call* call);
WebRtcVoiceMediaChannel() = delete;
WebRtcVoiceMediaChannel(const WebRtcVoiceMediaChannel&) = delete;
WebRtcVoiceMediaChannel& operator=(const WebRtcVoiceMediaChannel&) = delete;
~WebRtcVoiceMediaChannel() override;
const AudioOptions& options() const { return options_; }
bool SetSendParameters(const AudioSendParameters& params) override;
bool SetRecvParameters(const AudioRecvParameters& params) override;
webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
webrtc::RTCError SetRtpSendParameters(
uint32_t ssrc,
const webrtc::RtpParameters& parameters) override;
webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override;
webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override;
void SetPlayout(bool playout) override;
void SetSend(bool send) override;
bool SetAudioSend(uint32_t ssrc,
bool enable,
const AudioOptions* options,
AudioSource* source) override;
bool AddSendStream(const StreamParams& sp) override;
bool RemoveSendStream(uint32_t ssrc) override;
bool AddRecvStream(const StreamParams& sp) override;
bool RemoveRecvStream(uint32_t ssrc) override;
void ResetUnsignaledRecvStream() override;
Fix unsignalled ssrc race in WebRtcVideoChannel. BaseChannel adds and removes receive streams on the worker thread (UpdateRemoteStreams_w) and then posts a task to the network thread to update the demuxer criteria. Until this happens, OnRtpPacket() keeps forwarding "recently removed" ssrc packets to the WebRtcVideoChannel. Furthermore WebRtcVideoChannel::OnPacketReceived() posts task from the network thread to the worker thread, so even if the demuxer criteria was instantly updated we would still have an issue of in-flight packets for old ssrcs arriving late on the worker thread inside WebRtcVideoChannel. The wrong ssrc could also arrive when the demuxer goes from forwarding all packets to a single m= section to forwarding to different m= sections. In this case we get packets with an ssrc for a recently created m= section and the ssrc was never intended for our channel. This is a problem because when WebRtcVideoChannel sees an unknown ssrc it treats it as an unsignalled stream, creating and destroying default streams which can be very expensive and introduce large delays when lots of packets are queued up. This CL addresses the issue with callbacks for when a demuxer criteria update is pending and when it has completed. During this window of time, WebRtcVideoChannel will drop packets for unknown ssrcs. This approach fixes the race without introducing any new locks and packets belonging to ssrcs that were not removed continue to be forwarded even if a demuxer criteria update is pending. This should make a=inactive for 50p receive streams a glitch-free experience. Bug: webrtc:12258, chromium:1069603 Change-Id: I30d85f53d84e7eddf7d21380fb608631863aad21 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214964 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Taylor <deadbeef@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33757}
2021-04-16 09:54:18 +02:00
void OnDemuxerCriteriaUpdatePending() override;
void OnDemuxerCriteriaUpdateComplete() override;
// E2EE Frame API
// Set a frame decryptor to a particular ssrc that will intercept all
// incoming audio payloads and attempt to decrypt them before forwarding the
// result.
void SetFrameDecryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
frame_decryptor) override;
// Set a frame encryptor to a particular ssrc that will intercept all
// outgoing audio payloads frames and attempt to encrypt them and forward the
// result to the packetizer.
void SetFrameEncryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
frame_encryptor) override;
bool SetOutputVolume(uint32_t ssrc, double volume) override;
// Applies the new volume to current and future unsignaled streams.
bool SetDefaultOutputVolume(double volume) override;
bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override;
absl::optional<int> GetBaseMinimumPlayoutDelayMs(
uint32_t ssrc) const override;
bool CanInsertDtmf() override;
bool InsertDtmf(uint32_t ssrc, int event, int duration) override;
void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) override;
void OnPacketSent(const rtc::SentPacket& sent_packet) override;
void OnNetworkRouteChanged(const std::string& transport_name,
const rtc::NetworkRoute& network_route) override;
void OnReadyToSend(bool ready) override;
bool GetStats(VoiceMediaInfo* info, bool get_and_clear_legacy_stats) override;
// Set the audio sink for an existing stream.
void SetRawAudioSink(
uint32_t ssrc,
std::unique_ptr<webrtc::AudioSinkInterface> sink) override;
// Will set the audio sink on the latest unsignaled stream, future or
// current. Only one stream at a time will use the sink.
void SetDefaultRawAudioSink(
std::unique_ptr<webrtc::AudioSinkInterface> sink) override;
std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override;
Reland of Implemented the GetSources() in native code. (patchset #1 id:1 of https://codereview.webrtc.org/2809613002/ ) Reason for revert: Re-land, reverting did not fix bug. https://bugs.chromium.org/p/webrtc/issues/detail?id=7465 Original issue's description: > Revert of Implemented the GetSources() in native code. (patchset #11 id:510001 of https://codereview.webrtc.org/2770233003/ ) > > Reason for revert: > Suspected of WebRtcApprtcBrowserTest.MANUAL_WorksOnApprtc breakage, see > > https://bugs.chromium.org/p/webrtc/issues/detail?id=7465 > > Original issue's description: > > Added the GetSources() to the RtpReceiverInterface and implemented > > it for the AudioRtpReceiver. > > > > This method returns a vector of RtpSource(both CSRC source and SSRC > > source) which contains the ID of a source, the timestamp, the source > > type (SSRC or CSRC) and the audio level. > > > > The RtpSource objects are buffered and maintained by the > > RtpReceiver in webrtc/modules/rtp_rtcp/. When the method is called, > > the info of the contributing source will be pulled along the object > > chain: > > AudioRtpReceiver -> VoiceChannel -> WebRtcVoiceMediaChannel -> > > AudioReceiveStream -> voe::Channel -> RtpRtcp module > > > > Spec:https://w3c.github.io/webrtc-pc/archives/20151006/webrtc.html#widl-RTCRtpReceiver-getContributingSources-sequence-RTCRtpContributingSource > > > > BUG=chromium:703122 > > TBR=stefan@webrtc.org, danilchap@webrtc.org > > > > Review-Url: https://codereview.webrtc.org/2770233003 > > Cr-Commit-Position: refs/heads/master@{#17591} > > Committed: https://chromium.googlesource.com/external/webrtc/+/292084c3765d9f3ee406ca2ec86eae206b540053 > > TBR=deadbeef@webrtc.org,solenberg@webrtc.org,hbos@webrtc.org,philipel@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,zhihuang@webrtc.org > # Not skipping CQ checks because original CL landed more than 1 days ago. > BUG=chromium:703122 > > Review-Url: https://codereview.webrtc.org/2809613002 > Cr-Commit-Position: refs/heads/master@{#17616} > Committed: https://chromium.googlesource.com/external/webrtc/+/fbcc5cb3869d1370008e40f24fc03ac8fb69c675 TBR=deadbeef@webrtc.org,solenberg@webrtc.org,philipel@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,zhihuang@webrtc.org,olka@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=chromium:703122 Review-Url: https://codereview.webrtc.org/2810623003 Cr-Commit-Position: refs/heads/master@{#17621}
2017-04-10 07:39:05 -07:00
// Sets a frame transformer between encoder and packetizer, to transform
// encoded frames before sending them out the network.
void SetEncoderToPacketizerFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override;
void SetDepacketizerToDecoderFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override;
// implements Transport interface
bool SendRtp(const uint8_t* data,
size_t len,
const webrtc::PacketOptions& options) override;
bool SendRtcp(const uint8_t* data, size_t len) override;
private:
bool SetOptions(const AudioOptions& options);
bool SetRecvCodecs(const std::vector<AudioCodec>& codecs);
bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
bool SetLocalSource(uint32_t ssrc, AudioSource* source);
bool MuteStream(uint32_t ssrc, bool mute);
WebRtcVoiceEngine* engine() { return engine_; }
int CreateVoEChannel();
bool DeleteVoEChannel(int channel);
bool SetMaxSendBitrate(int bps);
void SetupRecording();
// Check if 'ssrc' is an unsignaled stream, and if so mark it as not being
// unsignaled anymore (i.e. it is now removed, or signaled), and return true.
bool MaybeDeregisterUnsignaledRecvStream(uint32_t ssrc);
webrtc::TaskQueueBase* const worker_thread_;
webrtc::ScopedTaskSafety task_safety_;
webrtc::SequenceChecker network_thread_checker_;
WebRtcVoiceEngine* const engine_ = nullptr;
std::vector<AudioCodec> send_codecs_;
// TODO(kwiberg): decoder_map_ and recv_codecs_ store the exact same
// information, in slightly different formats. Eliminate recv_codecs_.
std::map<int, webrtc::SdpAudioFormat> decoder_map_;
std::vector<AudioCodec> recv_codecs_;
int max_send_bitrate_bps_ = 0;
AudioOptions options_;
absl::optional<int> dtmf_payload_type_;
int dtmf_payload_freq_ = -1;
bool recv_transport_cc_enabled_ = false;
bool recv_nack_enabled_ = false;
bool playout_ = false;
bool send_ = false;
webrtc::Call* const call_ = nullptr;
const MediaConfig::Audio audio_config_;
// Queue of unsignaled SSRCs; oldest at the beginning.
std::vector<uint32_t> unsignaled_recv_ssrcs_;
// This is a stream param that comes from the remote description, but wasn't
// signaled with any a=ssrc lines. It holds the information that was signaled
// before the unsignaled receive stream is created when the first packet is
// received.
StreamParams unsignaled_stream_params_;
// Volume for unsignaled streams, which may be set before the stream exists.
double default_recv_volume_ = 1.0;
// Delay for unsignaled streams, which may be set before the stream exists.
int default_recv_base_minimum_delay_ms_ = 0;
// Sink for latest unsignaled stream - may be set before the stream exists.
std::unique_ptr<webrtc::AudioSinkInterface> default_sink_;
// Default SSRC to use for RTCP receiver reports in case of no signaled
// send streams. See: https://code.google.com/p/webrtc/issues/detail?id=4740
// and https://code.google.com/p/chromium/issues/detail?id=547661
uint32_t receiver_reports_ssrc_ = 0xFA17FA17u;
class WebRtcAudioSendStream;
std::map<uint32_t, WebRtcAudioSendStream*> send_streams_;
std::vector<webrtc::RtpExtension> send_rtp_extensions_;
std::string mid_;
class WebRtcAudioReceiveStream;
std::map<uint32_t, WebRtcAudioReceiveStream*> recv_streams_;
std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
absl::optional<webrtc::AudioSendStream::Config::SendCodecSpec>
send_codec_spec_;
// TODO(kwiberg): Per-SSRC codec pair IDs?
const webrtc::AudioCodecPairId codec_pair_id_ =
webrtc::AudioCodecPairId::Create();
// Per peer connection crypto options that last for the lifetime of the peer
// connection.
const webrtc::CryptoOptions crypto_options_;
// Unsignaled streams have an option to have a frame decryptor set on them.
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
unsignaled_frame_decryptor_;
const bool audio_red_for_opus_trial_enabled_;
};
} // namespace cricket
#endif // MEDIA_ENGINE_WEBRTC_VOICE_ENGINE_H_