2016-07-04 06:33:02 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|
|
|
|
|
#define MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-07-04 06:33:02 -07:00
|
|
|
#include <memory>
|
2016-08-08 10:26:09 -07:00
|
|
|
#include <vector>
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2020-10-19 14:23:46 +02:00
|
|
|
#include "api/array_view.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/audio/audio_frame.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/audio/audio_mixer.h"
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_mixer/frame_combiner.h"
|
|
|
|
|
#include "modules/audio_mixer/output_rate_calculator.h"
|
|
|
|
|
#include "rtc_base/race_checker.h"
|
2020-07-07 15:53:34 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
class AudioMixerImpl : public AudioMixer {
|
2016-07-04 06:33:02 -07:00
|
|
|
public:
|
2020-10-19 14:23:46 +02:00
|
|
|
struct SourceStatus;
|
2016-10-12 02:14:59 -07:00
|
|
|
|
2016-07-04 06:33:02 -07:00
|
|
|
// AudioProcessing only accepts 10 ms frames.
|
2016-08-24 02:20:54 -07:00
|
|
|
static const int kFrameDurationInMs = 10;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2021-05-17 14:15:58 +02:00
|
|
|
static const int kDefaultNumberOfMixedAudioSources = 3;
|
|
|
|
|
|
|
|
|
|
static rtc::scoped_refptr<AudioMixerImpl> Create(
|
|
|
|
|
int max_sources_to_mix = kDefaultNumberOfMixedAudioSources);
|
2017-02-21 05:06:29 -08:00
|
|
|
|
2017-02-21 08:27:08 -08:00
|
|
|
static rtc::scoped_refptr<AudioMixerImpl> Create(
|
2017-02-21 05:06:29 -08:00
|
|
|
std::unique_ptr<OutputRateCalculator> output_rate_calculator,
|
2021-05-17 14:15:58 +02:00
|
|
|
bool use_limiter,
|
|
|
|
|
int max_sources_to_mix = kDefaultNumberOfMixedAudioSources);
|
2017-02-21 05:06:29 -08:00
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
~AudioMixerImpl() override;
|
2016-08-16 02:15:49 -07:00
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
AudioMixerImpl(const AudioMixerImpl&) = delete;
|
|
|
|
|
AudioMixerImpl& operator=(const AudioMixerImpl&) = delete;
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
// AudioMixer functions
|
2016-10-12 06:07:07 -07:00
|
|
|
bool AddSource(Source* audio_source) override;
|
2016-11-18 02:03:04 -08:00
|
|
|
void RemoveSource(Source* audio_source) override;
|
2016-10-12 06:07:07 -07:00
|
|
|
|
2016-11-08 06:39:50 -08:00
|
|
|
void Mix(size_t number_of_channels,
|
2017-09-07 07:53:45 -07:00
|
|
|
AudioFrame* audio_frame_for_mixing) override
|
2020-07-07 15:53:34 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(mutex_);
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-10-07 05:28:32 -07:00
|
|
|
// Returns true if the source was mixed last round. Returns
|
|
|
|
|
// false and logs an error if the source was never added to the
|
|
|
|
|
// mixer.
|
2016-10-12 03:06:09 -07:00
|
|
|
bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const;
|
2016-10-07 05:28:32 -07:00
|
|
|
|
2016-10-12 06:07:07 -07:00
|
|
|
protected:
|
2017-02-21 05:06:29 -08:00
|
|
|
AudioMixerImpl(std::unique_ptr<OutputRateCalculator> output_rate_calculator,
|
2021-05-17 14:15:58 +02:00
|
|
|
bool use_limiter,
|
|
|
|
|
int max_sources_to_mix);
|
2016-09-07 06:13:12 -07:00
|
|
|
|
2016-10-12 06:07:07 -07:00
|
|
|
private:
|
2020-10-19 14:23:46 +02:00
|
|
|
struct HelperContainers;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-09-07 07:42:14 -07:00
|
|
|
// Compute what audio sources to mix from audio_source_list_. Ramp
|
|
|
|
|
// in and out. Update mixed status. Mixes up to
|
|
|
|
|
// kMaximumAmountOfMixedAudioSources audio sources.
|
2020-10-19 14:23:46 +02:00
|
|
|
rtc::ArrayView<AudioFrame* const> GetAudioFromSources(int output_frequency)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-10-20 14:23:24 -07:00
|
|
|
// The critical section lock guards audio source insertion and
|
|
|
|
|
// removal, which can be done from any thread. The race checker
|
|
|
|
|
// checks that mixing is done sequentially.
|
2020-07-07 15:53:34 +02:00
|
|
|
mutable Mutex mutex_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2021-05-17 14:15:58 +02:00
|
|
|
const int max_sources_to_mix_;
|
|
|
|
|
|
2016-12-08 02:37:58 -08:00
|
|
|
std::unique_ptr<OutputRateCalculator> output_rate_calculator_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2020-10-19 14:23:46 +02:00
|
|
|
// List of all audio sources.
|
|
|
|
|
std::vector<std::unique_ptr<SourceStatus>> audio_source_list_
|
|
|
|
|
RTC_GUARDED_BY(mutex_);
|
|
|
|
|
const std::unique_ptr<HelperContainers> helper_containers_
|
|
|
|
|
RTC_GUARDED_BY(mutex_);
|
2016-07-28 06:36:22 -07:00
|
|
|
|
2017-02-21 05:06:29 -08:00
|
|
|
// Component that handles actual adding of audio frames.
|
2020-10-19 14:23:46 +02:00
|
|
|
FrameCombiner frame_combiner_;
|
2016-07-04 06:33:02 -07:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|