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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
2016-08-08 10:26:09 -07:00
|
|
|
#include <vector>
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-07-28 06:24:14 -07:00
|
|
|
#include "webrtc/base/thread_checker.h"
|
2016-07-04 06:33:02 -07:00
|
|
|
#include "webrtc/engine_configurations.h"
|
2016-08-24 02:20:54 -07:00
|
|
|
#include "webrtc/modules/audio_mixer/audio_mixer.h"
|
2016-07-04 06:33:02 -07:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2016-08-24 01:17:12 -07:00
|
|
|
#include "webrtc/voice_engine/level_indicator.h"
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
class AudioProcessing;
|
|
|
|
|
class CriticalSectionWrapper;
|
|
|
|
|
|
|
|
|
|
struct FrameAndMuteInfo {
|
|
|
|
|
FrameAndMuteInfo(AudioFrame* f, bool m) : frame(f), muted(m) {}
|
|
|
|
|
AudioFrame* frame;
|
|
|
|
|
bool muted;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<FrameAndMuteInfo> AudioFrameList;
|
|
|
|
|
typedef std::list<MixerAudioSource*> MixerAudioSourceList;
|
|
|
|
|
|
|
|
|
|
// Cheshire cat implementation of MixerAudioSource's non virtual functions.
|
|
|
|
|
class NewMixHistory {
|
|
|
|
|
public:
|
|
|
|
|
NewMixHistory();
|
|
|
|
|
~NewMixHistory();
|
|
|
|
|
|
2016-07-28 03:52:15 -07:00
|
|
|
// Returns true if the audio source is being mixed.
|
2016-07-04 06:33:02 -07:00
|
|
|
bool IsMixed() const;
|
|
|
|
|
|
2016-07-28 03:52:15 -07:00
|
|
|
// Returns true if the audio source was mixed previous mix
|
2016-07-04 06:33:02 -07:00
|
|
|
// iteration.
|
|
|
|
|
bool WasMixed() const;
|
|
|
|
|
|
|
|
|
|
// Updates the mixed status.
|
|
|
|
|
int32_t SetIsMixed(bool mixed);
|
|
|
|
|
|
|
|
|
|
void ResetMixedStatus();
|
|
|
|
|
|
|
|
|
|
private:
|
2016-08-08 10:25:04 -07:00
|
|
|
bool is_mixed_;
|
2016-07-04 06:33:02 -07:00
|
|
|
};
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
class AudioMixerImpl : public AudioMixer {
|
2016-07-04 06:33:02 -07:00
|
|
|
public:
|
|
|
|
|
// 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
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
explicit AudioMixerImpl(int id);
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
~AudioMixerImpl() override;
|
2016-08-16 02:15:49 -07:00
|
|
|
|
2016-07-04 06:33:02 -07:00
|
|
|
// Must be called after ctor.
|
|
|
|
|
bool Init();
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
// AudioMixer functions
|
2016-07-28 03:52:15 -07:00
|
|
|
int32_t SetMixabilityStatus(MixerAudioSource* audio_source,
|
2016-07-04 06:33:02 -07:00
|
|
|
bool mixable) override;
|
2016-07-28 03:52:15 -07:00
|
|
|
bool MixabilityStatus(const MixerAudioSource& audio_source) const override;
|
|
|
|
|
int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source,
|
2016-07-04 06:33:02 -07:00
|
|
|
bool mixable) override;
|
2016-08-08 10:18:58 -07:00
|
|
|
void Mix(int sample_rate,
|
|
|
|
|
size_t number_of_channels,
|
|
|
|
|
AudioFrame* audio_frame_for_mixing) override;
|
2016-07-04 06:33:02 -07:00
|
|
|
bool AnonymousMixabilityStatus(
|
2016-07-28 03:52:15 -07:00
|
|
|
const MixerAudioSource& audio_source) const override;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Set/get mix frequency
|
|
|
|
|
int32_t SetOutputFrequency(const Frequency& frequency);
|
|
|
|
|
Frequency OutputFrequency() const;
|
|
|
|
|
|
2016-07-29 02:12:41 -07:00
|
|
|
// Compute what audio sources to mix from audio_source_list_. Ramp in
|
|
|
|
|
// and out. Update mixed status. maxAudioFrameCounter specifies how
|
|
|
|
|
// many participants are allowed to be mixed.
|
|
|
|
|
AudioFrameList UpdateToMix(size_t maxAudioFrameCounter) const;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// Return the lowest mixing frequency that can be used without having to
|
|
|
|
|
// downsample any audio.
|
|
|
|
|
int32_t GetLowestMixingFrequency() const;
|
|
|
|
|
int32_t GetLowestMixingFrequencyFromList(
|
|
|
|
|
const MixerAudioSourceList& mixList) const;
|
|
|
|
|
|
|
|
|
|
// Return the AudioFrames that should be mixed anonymously.
|
|
|
|
|
void GetAdditionalAudio(AudioFrameList* additionalFramesList) const;
|
|
|
|
|
|
|
|
|
|
// This function returns true if it finds the MixerAudioSource in the
|
|
|
|
|
// specified list of MixerAudioSources.
|
2016-07-28 03:52:15 -07:00
|
|
|
bool IsAudioSourceInList(const MixerAudioSource& audio_source,
|
|
|
|
|
const MixerAudioSourceList& audioSourceList) const;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// Add/remove the MixerAudioSource to the specified
|
|
|
|
|
// MixerAudioSource list.
|
2016-07-28 03:52:15 -07:00
|
|
|
bool AddAudioSourceToList(MixerAudioSource* audio_source,
|
|
|
|
|
MixerAudioSourceList* audioSourceList) const;
|
|
|
|
|
bool RemoveAudioSourceFromList(MixerAudioSource* removeAudioSource,
|
|
|
|
|
MixerAudioSourceList* audioSourceList) const;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// Mix the AudioFrames stored in audioFrameList into mixedAudio.
|
2016-07-28 03:52:15 -07:00
|
|
|
static int32_t MixFromList(AudioFrame* mixedAudio,
|
|
|
|
|
const AudioFrameList& audioFrameList,
|
|
|
|
|
int32_t id,
|
|
|
|
|
bool use_limiter);
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// Mix the AudioFrames stored in audioFrameList into mixedAudio. No
|
|
|
|
|
// record will be kept of this mix (e.g. the corresponding MixerAudioSources
|
|
|
|
|
// will not be marked as IsMixed()
|
|
|
|
|
int32_t MixAnonomouslyFromList(AudioFrame* mixedAudio,
|
|
|
|
|
const AudioFrameList& audioFrameList) const;
|
|
|
|
|
|
|
|
|
|
bool LimitMixedAudio(AudioFrame* mixedAudio) const;
|
|
|
|
|
|
2016-08-24 01:17:12 -07:00
|
|
|
// Output level functions for VoEVolumeControl.
|
|
|
|
|
int GetOutputAudioLevel() override;
|
|
|
|
|
|
|
|
|
|
int GetOutputAudioLevelFullRange() override;
|
|
|
|
|
|
2016-08-08 10:25:04 -07:00
|
|
|
std::unique_ptr<CriticalSectionWrapper> crit_;
|
|
|
|
|
std::unique_ptr<CriticalSectionWrapper> cb_crit_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-08-08 10:25:04 -07:00
|
|
|
int32_t id_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// The current sample frequency and sample size when mixing.
|
2016-08-08 10:25:04 -07:00
|
|
|
Frequency output_frequency_;
|
|
|
|
|
size_t sample_size_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-07-28 03:52:15 -07:00
|
|
|
// List of all audio sources. Note all lists are disjunct
|
|
|
|
|
MixerAudioSourceList audio_source_list_; // May be mixed.
|
2016-07-28 06:36:22 -07:00
|
|
|
|
2016-07-04 06:33:02 -07:00
|
|
|
// Always mixed, anonomously.
|
2016-07-28 03:52:15 -07:00
|
|
|
MixerAudioSourceList additional_audio_source_list_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-07-28 03:52:15 -07:00
|
|
|
size_t num_mixed_audio_sources_;
|
2016-07-04 06:33:02 -07:00
|
|
|
// Determines if we will use a limiter for clipping protection during
|
|
|
|
|
// mixing.
|
|
|
|
|
bool use_limiter_;
|
|
|
|
|
|
2016-08-08 10:25:04 -07:00
|
|
|
uint32_t time_stamp_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
2016-07-28 06:24:14 -07:00
|
|
|
// Ensures that Mix is called from the same thread.
|
|
|
|
|
rtc::ThreadChecker thread_checker_;
|
2016-07-04 06:33:02 -07:00
|
|
|
|
|
|
|
|
// Used for inhibiting saturation in mixing.
|
2016-08-08 10:25:04 -07:00
|
|
|
std::unique_ptr<AudioProcessing> limiter_;
|
2016-08-24 01:17:12 -07:00
|
|
|
|
|
|
|
|
// Measures audio level for the combined signal.
|
|
|
|
|
voe::AudioLevel audio_level_;
|
2016-07-04 06:33:02 -07:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-08-24 02:20:54 -07:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
|