Moved MixerAudioSource and removed audio_mixer_defines.h.
MixerAudioSource is moved to AudioMixerImpl::Source. Structures and methods of the MixerAudioSource interface have been renamed. The RemixFrame method has added checks and is moved to audio_frame_manipulator.h BUG=webrtc:6346 Review-Url: https://codereview.webrtc.org/2396803004 Cr-Commit-Position: refs/heads/master@{#14600}
This commit is contained in:
parent
14acf658ad
commit
e89141500a
@ -17,7 +17,6 @@ rtc_static_library("audio_mixer") {
|
||||
"audio_frame_manipulator.cc",
|
||||
"audio_frame_manipulator.h",
|
||||
"audio_mixer.h",
|
||||
"audio_mixer_defines.h",
|
||||
"audio_mixer_impl.cc",
|
||||
"audio_mixer_impl.h",
|
||||
"audio_source_with_mix_status.cc",
|
||||
@ -25,7 +24,6 @@ rtc_static_library("audio_mixer") {
|
||||
]
|
||||
|
||||
public = [
|
||||
"audio_mixer_defines.h",
|
||||
"audio_mixer.h",
|
||||
]
|
||||
|
||||
|
||||
@ -8,8 +8,10 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_frame_manipulator.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/modules/utility/include/audio_frame_operations.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -59,4 +61,15 @@ void NewMixerRampOut(AudioFrame* audio_frame) {
|
||||
(audio_frame->samples_per_channel_ - kRampSize) *
|
||||
sizeof(audio_frame->data_[0]));
|
||||
}
|
||||
|
||||
void RemixFrame(size_t target_number_of_channels, AudioFrame* frame) {
|
||||
RTC_DCHECK_GE(target_number_of_channels, static_cast<size_t>(1));
|
||||
RTC_DCHECK_LE(target_number_of_channels, static_cast<size_t>(2));
|
||||
if (frame->num_channels_ == 1 && target_number_of_channels == 2) {
|
||||
AudioFrameOperations::MonoToStereo(frame);
|
||||
} else if (frame->num_channels_ == 2 && target_number_of_channels == 1) {
|
||||
AudioFrameOperations::StereoToMono(frame);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -23,6 +23,9 @@ uint32_t AudioMixerCalculateEnergy(const AudioFrame& audio_frame);
|
||||
void NewMixerRampIn(AudioFrame* audio_frame);
|
||||
void NewMixerRampOut(AudioFrame* audio_frame);
|
||||
|
||||
// Downmixes or upmixes a frame between stereo and mono.
|
||||
void RemixFrame(size_t target_number_of_channels, AudioFrame* frame);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_FRAME_MANIPULATOR_H_
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
'audio_frame_manipulator.cc',
|
||||
'audio_frame_manipulator.h',
|
||||
'audio_mixer.h',
|
||||
'audio_mixer_defines.h',
|
||||
'audio_mixer_impl.cc',
|
||||
'audio_mixer_impl.h',
|
||||
'audio_source_with_mix_status.cc',
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
|
||||
#include "webrtc/modules/include/module.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
|
||||
@ -30,21 +29,52 @@ class AudioMixer {
|
||||
kDefaultFrequency = kWbInHz
|
||||
};
|
||||
|
||||
// A callback class that all mixer participants must inherit from/implement.
|
||||
class Source {
|
||||
public:
|
||||
enum class AudioFrameInfo {
|
||||
kNormal, // The samples in audio_frame are valid and should be used.
|
||||
kMuted, // The samples in audio_frame should not be used, but should be
|
||||
// implicitly interpreted as zero. Other fields in audio_frame
|
||||
// may be read and should contain meaningful values.
|
||||
kError // audio_frame will not be used.
|
||||
};
|
||||
|
||||
struct AudioFrameWithInfo {
|
||||
AudioFrame* audio_frame;
|
||||
AudioFrameInfo audio_frame_info;
|
||||
};
|
||||
|
||||
// The implementation of GetAudioFrameWithInfo should update
|
||||
// audio_frame with new audio every time it's called. Implementing
|
||||
// classes are allowed to return the same AudioFrame pointer on
|
||||
// different calls. The pointer must stay valid until the next
|
||||
// mixing call or until this audio source is disconnected from the
|
||||
// mixer. The mixer may modify the contents of the passed
|
||||
// AudioFrame pointer at any time until the next call to
|
||||
// GetAudioFrameWithInfo, or until the source is removed from the
|
||||
// mixer.
|
||||
virtual AudioFrameWithInfo GetAudioFrameWithInfo(int32_t id,
|
||||
int sample_rate_hz) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Source() {}
|
||||
};
|
||||
|
||||
// Factory method. Constructor disabled.
|
||||
static std::unique_ptr<AudioMixer> Create(int id);
|
||||
virtual ~AudioMixer() {}
|
||||
|
||||
// Add/remove audio sources as candidates for mixing.
|
||||
virtual int32_t SetMixabilityStatus(MixerAudioSource* audio_source,
|
||||
bool mixable) = 0;
|
||||
virtual int32_t SetMixabilityStatus(Source* audio_source, bool mixable) = 0;
|
||||
// Returns true if an audio source is a candidate for mixing.
|
||||
virtual bool MixabilityStatus(const MixerAudioSource& audio_source) const = 0;
|
||||
virtual bool MixabilityStatus(const Source& audio_source) const = 0;
|
||||
|
||||
// Inform the mixer that the audio source should always be mixed and not
|
||||
// count toward the number of mixed audio sources. Note that an audio source
|
||||
// must have been added to the mixer (by calling SetMixabilityStatus())
|
||||
// before this function can be successfully called.
|
||||
virtual int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source,
|
||||
virtual int32_t SetAnonymousMixabilityStatus(Source* audio_source,
|
||||
bool mixable) = 0;
|
||||
|
||||
// Performs mixing by asking registered audio sources for audio. The
|
||||
@ -56,8 +86,7 @@ class AudioMixer {
|
||||
AudioFrame* audio_frame_for_mixing) = 0;
|
||||
|
||||
// Returns true if the audio source is mixed anonymously.
|
||||
virtual bool AnonymousMixabilityStatus(
|
||||
const MixerAudioSource& audio_source) const = 0;
|
||||
virtual bool AnonymousMixabilityStatus(const Source& audio_source) const = 0;
|
||||
|
||||
// Output level functions for VoEVolumeControl. Return value
|
||||
// between 0 and 9 is returned by voe::AudioLevel.
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 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 WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_
|
||||
#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// A callback class that all mixer participants must inherit from/implement.
|
||||
class MixerAudioSource {
|
||||
public:
|
||||
enum class AudioFrameInfo {
|
||||
kNormal, // The samples in audio_frame are valid and should be used.
|
||||
kMuted, // The samples in audio_frame should not be used, but should be
|
||||
// implicitly interpreted as zero. Other fields in audio_frame
|
||||
// may be read and should contain meaningful values.
|
||||
kError // audio_frame will not be used.
|
||||
};
|
||||
|
||||
struct AudioFrameWithMuted {
|
||||
AudioFrame* audio_frame;
|
||||
AudioFrameInfo audio_frame_info;
|
||||
};
|
||||
|
||||
virtual ~MixerAudioSource() = default;
|
||||
|
||||
// The implementation of GetAudioFrameWithMuted should update
|
||||
// audio_frame with new audio every time it's called. Implementing
|
||||
// classes are allowed to return the same AudioFrame pointer on
|
||||
// different calls. The pointer must stay valid until the next
|
||||
// mixing call or until this audio source is disconnected from the
|
||||
// mixer.
|
||||
virtual AudioFrameWithMuted GetAudioFrameWithMuted(int32_t id,
|
||||
int sample_rate_hz) = 0;
|
||||
};
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_
|
||||
@ -64,15 +64,6 @@ class SourceFrame {
|
||||
uint32_t energy_ = 0;
|
||||
};
|
||||
|
||||
// Remixes a frame between stereo and mono.
|
||||
void RemixFrame(AudioFrame* frame, size_t number_of_channels) {
|
||||
RTC_DCHECK(number_of_channels == 1 || number_of_channels == 2);
|
||||
if (frame->num_channels_ == 1 && number_of_channels == 2) {
|
||||
AudioFrameOperations::MonoToStereo(frame);
|
||||
} else if (frame->num_channels_ == 2 && number_of_channels == 1) {
|
||||
AudioFrameOperations::StereoToMono(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void Ramp(const std::vector<SourceFrame>& mixed_sources_and_frames) {
|
||||
for (const auto& source_frame : mixed_sources_and_frames) {
|
||||
@ -131,7 +122,7 @@ int32_t MixFromList(AudioFrame* mixed_audio,
|
||||
}
|
||||
|
||||
MixerAudioSourceList::const_iterator FindSourceInList(
|
||||
MixerAudioSource const* audio_source,
|
||||
AudioMixerImpl::Source const* audio_source,
|
||||
MixerAudioSourceList const* audio_source_list) {
|
||||
return std::find_if(audio_source_list->begin(), audio_source_list->end(),
|
||||
[audio_source](const AudioSourceWithMixStatus& p) {
|
||||
@ -140,7 +131,7 @@ MixerAudioSourceList::const_iterator FindSourceInList(
|
||||
}
|
||||
|
||||
MixerAudioSourceList::iterator FindSourceInList(
|
||||
MixerAudioSource const* audio_source,
|
||||
AudioMixerImpl::Source const* audio_source,
|
||||
MixerAudioSourceList* audio_source_list) {
|
||||
return std::find_if(audio_source_list->begin(), audio_source_list->end(),
|
||||
[audio_source](const AudioSourceWithMixStatus& p) {
|
||||
@ -230,7 +221,7 @@ void AudioMixerImpl::Mix(int sample_rate,
|
||||
anonymous_mix_list.end());
|
||||
|
||||
for (const auto& frame : mix_list) {
|
||||
RemixFrame(frame, number_of_channels);
|
||||
RemixFrame(number_of_channels, frame);
|
||||
}
|
||||
|
||||
audio_frame_for_mixing->UpdateFrame(
|
||||
@ -272,7 +263,7 @@ AudioMixer::Frequency AudioMixerImpl::OutputFrequency() const {
|
||||
return output_frequency_;
|
||||
}
|
||||
|
||||
int32_t AudioMixerImpl::SetMixabilityStatus(MixerAudioSource* audio_source,
|
||||
int32_t AudioMixerImpl::SetMixabilityStatus(Source* audio_source,
|
||||
bool mixable) {
|
||||
if (!mixable) {
|
||||
// Anonymous audio sources are in a separate list. Make sure that the
|
||||
@ -312,16 +303,14 @@ int32_t AudioMixerImpl::SetMixabilityStatus(MixerAudioSource* audio_source,
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AudioMixerImpl::MixabilityStatus(
|
||||
const MixerAudioSource& audio_source) const {
|
||||
bool AudioMixerImpl::MixabilityStatus(const Source& audio_source) const {
|
||||
rtc::CritScope lock(&crit_);
|
||||
return FindSourceInList(&audio_source, &audio_source_list_) !=
|
||||
audio_source_list_.end();
|
||||
}
|
||||
|
||||
int32_t AudioMixerImpl::SetAnonymousMixabilityStatus(
|
||||
MixerAudioSource* audio_source,
|
||||
bool anonymous) {
|
||||
int32_t AudioMixerImpl::SetAnonymousMixabilityStatus(Source* audio_source,
|
||||
bool anonymous) {
|
||||
rtc::CritScope lock(&crit_);
|
||||
if (FindSourceInList(audio_source, &additional_audio_source_list_) !=
|
||||
additional_audio_source_list_.end()) {
|
||||
@ -356,7 +345,7 @@ int32_t AudioMixerImpl::SetAnonymousMixabilityStatus(
|
||||
}
|
||||
|
||||
bool AudioMixerImpl::AnonymousMixabilityStatus(
|
||||
const MixerAudioSource& audio_source) const {
|
||||
const Source& audio_source) const {
|
||||
rtc::CritScope lock(&crit_);
|
||||
return FindSourceInList(&audio_source, &additional_audio_source_list_) !=
|
||||
additional_audio_source_list_.end();
|
||||
@ -373,20 +362,20 @@ AudioFrameList AudioMixerImpl::GetNonAnonymousAudio() {
|
||||
// Get audio source audio and put it in the struct vector.
|
||||
for (auto& source_and_status : audio_source_list_) {
|
||||
auto audio_frame_with_info =
|
||||
source_and_status.audio_source()->GetAudioFrameWithMuted(
|
||||
source_and_status.audio_source()->GetAudioFrameWithInfo(
|
||||
id_, static_cast<int>(OutputFrequency()));
|
||||
|
||||
const auto audio_frame_info = audio_frame_with_info.audio_frame_info;
|
||||
AudioFrame* audio_source_audio_frame = audio_frame_with_info.audio_frame;
|
||||
|
||||
if (audio_frame_info == MixerAudioSource::AudioFrameInfo::kError) {
|
||||
if (audio_frame_info == Source::AudioFrameInfo::kError) {
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceAudioMixerServer, id_,
|
||||
"failed to GetAudioFrameWithMuted() from source");
|
||||
continue;
|
||||
}
|
||||
audio_source_mixing_data_list.emplace_back(
|
||||
&source_and_status, audio_source_audio_frame,
|
||||
audio_frame_info == MixerAudioSource::AudioFrameInfo::kMuted);
|
||||
audio_frame_info == Source::AudioFrameInfo::kMuted);
|
||||
}
|
||||
|
||||
// Sort frames by sorting function.
|
||||
@ -426,16 +415,16 @@ AudioFrameList AudioMixerImpl::GetAnonymousAudio() {
|
||||
AudioFrameList result;
|
||||
for (auto& source_and_status : additional_audio_source_list_) {
|
||||
const auto audio_frame_with_info =
|
||||
source_and_status.audio_source()->GetAudioFrameWithMuted(
|
||||
source_and_status.audio_source()->GetAudioFrameWithInfo(
|
||||
id_, OutputFrequency());
|
||||
const auto ret = audio_frame_with_info.audio_frame_info;
|
||||
AudioFrame* audio_frame = audio_frame_with_info.audio_frame;
|
||||
if (ret == MixerAudioSource::AudioFrameInfo::kError) {
|
||||
if (ret == Source::AudioFrameInfo::kError) {
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceAudioMixerServer, id_,
|
||||
"failed to GetAudioFrameWithMuted() from audio_source");
|
||||
continue;
|
||||
}
|
||||
if (ret != MixerAudioSource::AudioFrameInfo::kMuted) {
|
||||
if (ret != Source::AudioFrameInfo::kMuted) {
|
||||
result.push_back(audio_frame);
|
||||
ramp_list.emplace_back(&source_and_status, audio_frame, false, 0);
|
||||
source_and_status.SetIsMixed(true);
|
||||
@ -446,7 +435,7 @@ AudioFrameList AudioMixerImpl::GetAnonymousAudio() {
|
||||
}
|
||||
|
||||
bool AudioMixerImpl::AddAudioSourceToList(
|
||||
MixerAudioSource* audio_source,
|
||||
Source* audio_source,
|
||||
MixerAudioSourceList* audio_source_list) const {
|
||||
WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, id_,
|
||||
"AddAudioSourceToList(audio_source, audio_source_list)");
|
||||
@ -455,7 +444,7 @@ bool AudioMixerImpl::AddAudioSourceToList(
|
||||
}
|
||||
|
||||
bool AudioMixerImpl::RemoveAudioSourceFromList(
|
||||
MixerAudioSource* audio_source,
|
||||
Source* audio_source,
|
||||
MixerAudioSourceList* audio_source_list) const {
|
||||
WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, id_,
|
||||
"RemoveAudioSourceFromList(audio_source, audio_source_list)");
|
||||
@ -515,7 +504,7 @@ int AudioMixerImpl::GetOutputAudioLevelFullRange() {
|
||||
}
|
||||
|
||||
bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest(
|
||||
MixerAudioSource* audio_source) {
|
||||
AudioMixerImpl::Source* audio_source) {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
rtc::CritScope lock(&crit_);
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "webrtc/base/thread_annotations.h"
|
||||
#include "webrtc/base/thread_checker.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_source_with_mix_status.h"
|
||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
@ -41,21 +40,19 @@ class AudioMixerImpl : public AudioMixer {
|
||||
~AudioMixerImpl() override;
|
||||
|
||||
// AudioMixer functions
|
||||
int32_t SetMixabilityStatus(MixerAudioSource* audio_source,
|
||||
bool mixable) override;
|
||||
bool MixabilityStatus(const MixerAudioSource& audio_source) const override;
|
||||
int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source,
|
||||
int32_t SetMixabilityStatus(Source* audio_source, bool mixable) override;
|
||||
bool MixabilityStatus(const Source& audio_source) const override;
|
||||
int32_t SetAnonymousMixabilityStatus(Source* audio_source,
|
||||
bool mixable) override;
|
||||
void Mix(int sample_rate,
|
||||
size_t number_of_channels,
|
||||
AudioFrame* audio_frame_for_mixing) override;
|
||||
bool AnonymousMixabilityStatus(
|
||||
const MixerAudioSource& audio_source) const override;
|
||||
bool AnonymousMixabilityStatus(const Source& audio_source) const override;
|
||||
|
||||
// Returns true if the source was mixed last round. Returns
|
||||
// false and logs an error if the source was never added to the
|
||||
// mixer.
|
||||
bool GetAudioSourceMixabilityStatusForTest(MixerAudioSource* audio_source);
|
||||
bool GetAudioSourceMixabilityStatusForTest(Source* audio_source);
|
||||
|
||||
private:
|
||||
AudioMixerImpl(int id, std::unique_ptr<AudioProcessing> limiter);
|
||||
@ -75,9 +72,9 @@ class AudioMixerImpl : public AudioMixer {
|
||||
|
||||
// Add/remove the MixerAudioSource to the specified
|
||||
// MixerAudioSource list.
|
||||
bool AddAudioSourceToList(MixerAudioSource* audio_source,
|
||||
bool AddAudioSourceToList(Source* audio_source,
|
||||
MixerAudioSourceList* audio_source_list) const;
|
||||
bool RemoveAudioSourceFromList(MixerAudioSource* remove_audio_source,
|
||||
bool RemoveAudioSourceFromList(Source* remove_audio_source,
|
||||
MixerAudioSourceList* audio_source_list) const;
|
||||
|
||||
bool LimitMixedAudio(AudioFrame* mixed_audio) const;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
namespace webrtc {
|
||||
|
||||
AudioSourceWithMixStatus::AudioSourceWithMixStatus(
|
||||
MixerAudioSource* audio_source)
|
||||
AudioMixer::Source* audio_source)
|
||||
: audio_source_(audio_source) {}
|
||||
|
||||
AudioSourceWithMixStatus::~AudioSourceWithMixStatus() {}
|
||||
@ -36,7 +36,7 @@ void AudioSourceWithMixStatus::ResetMixedStatus() {
|
||||
is_mixed_ = false;
|
||||
}
|
||||
|
||||
MixerAudioSource* AudioSourceWithMixStatus::audio_source() const {
|
||||
AudioMixer::Source* AudioSourceWithMixStatus::audio_source() const {
|
||||
return audio_source_;
|
||||
}
|
||||
|
||||
|
||||
@ -11,14 +11,14 @@
|
||||
#ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_SOURCE_WITH_MIX_STATUS_H_
|
||||
#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_SOURCE_WITH_MIX_STATUS_H_
|
||||
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// A class that holds a mixer participant and its mixing status.
|
||||
class AudioSourceWithMixStatus {
|
||||
public:
|
||||
explicit AudioSourceWithMixStatus(MixerAudioSource* audio_source);
|
||||
explicit AudioSourceWithMixStatus(AudioMixer::Source* audio_source);
|
||||
~AudioSourceWithMixStatus();
|
||||
|
||||
AudioSourceWithMixStatus(const AudioSourceWithMixStatus&) = default;
|
||||
@ -33,10 +33,10 @@ class AudioSourceWithMixStatus {
|
||||
// Updates the mixed status.
|
||||
void SetIsMixed(const bool mixed);
|
||||
void ResetMixedStatus();
|
||||
MixerAudioSource* audio_source() const;
|
||||
AudioMixer::Source* audio_source() const;
|
||||
|
||||
private:
|
||||
MixerAudioSource* audio_source_ = nullptr;
|
||||
AudioMixer::Source* audio_source_ = nullptr;
|
||||
bool is_mixed_ = false;
|
||||
};
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
#include "webrtc/base/bind.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
|
||||
#include "webrtc/modules/audio_mixer/audio_mixer.h"
|
||||
#include "webrtc/test/gmock.h"
|
||||
|
||||
using testing::_;
|
||||
@ -48,17 +48,17 @@ AudioFrame frame_for_mixing;
|
||||
|
||||
} // namespace
|
||||
|
||||
class MockMixerAudioSource : public MixerAudioSource {
|
||||
class MockMixerAudioSource : public AudioMixer::Source {
|
||||
public:
|
||||
MockMixerAudioSource()
|
||||
: fake_audio_frame_info_(MixerAudioSource::AudioFrameInfo::kNormal) {
|
||||
ON_CALL(*this, GetAudioFrameWithMuted(_, _))
|
||||
: fake_audio_frame_info_(AudioMixer::Source::AudioFrameInfo::kNormal) {
|
||||
ON_CALL(*this, GetAudioFrameWithInfo(_, _))
|
||||
.WillByDefault(
|
||||
Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithMuted));
|
||||
Invoke(this, &MockMixerAudioSource::FakeAudioFrameWithInfo));
|
||||
}
|
||||
|
||||
MOCK_METHOD2(GetAudioFrameWithMuted,
|
||||
AudioFrameWithMuted(const int32_t id, int sample_rate_hz));
|
||||
MOCK_METHOD2(GetAudioFrameWithInfo,
|
||||
AudioFrameWithInfo(const int32_t id, int sample_rate_hz));
|
||||
|
||||
AudioFrame* fake_frame() { return &fake_frame_; }
|
||||
AudioFrameInfo fake_info() { return fake_audio_frame_info_; }
|
||||
@ -69,8 +69,8 @@ class MockMixerAudioSource : public MixerAudioSource {
|
||||
private:
|
||||
AudioFrame fake_frame_, fake_output_frame_;
|
||||
AudioFrameInfo fake_audio_frame_info_;
|
||||
AudioFrameWithMuted FakeAudioFrameWithMuted(const int32_t id,
|
||||
int sample_rate_hz) {
|
||||
AudioFrameWithInfo FakeAudioFrameWithInfo(const int32_t id,
|
||||
int sample_rate_hz) {
|
||||
fake_output_frame_.CopyFrom(fake_frame_);
|
||||
return {
|
||||
&fake_output_frame_, // audio_frame_pointer
|
||||
@ -83,7 +83,7 @@ class MockMixerAudioSource : public MixerAudioSource {
|
||||
// to the mixer. Compares mixed status with |expected_status|
|
||||
void MixAndCompare(
|
||||
const std::vector<AudioFrame>& frames,
|
||||
const std::vector<MixerAudioSource::AudioFrameInfo>& frame_info,
|
||||
const std::vector<AudioMixer::Source::AudioFrameInfo>& frame_info,
|
||||
const std::vector<bool>& expected_status) {
|
||||
int num_audio_sources = frames.size();
|
||||
RTC_DCHECK(frames.size() == frame_info.size());
|
||||
@ -99,8 +99,7 @@ void MixAndCompare(
|
||||
|
||||
for (int i = 0; i < num_audio_sources; i++) {
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
|
||||
EXPECT_CALL(participants[i],
|
||||
GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
}
|
||||
|
||||
@ -180,8 +179,7 @@ TEST(AudioMixer, LargestEnergyVadActiveMixed) {
|
||||
participants[i].fake_frame()->data_[80] = i;
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
|
||||
EXPECT_CALL(participants[i], GetAudioFrameWithMuted(_, _))
|
||||
.Times(Exactly(1));
|
||||
EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, _)).Times(Exactly(1));
|
||||
}
|
||||
|
||||
// Last participant gives audio frame with passive VAD, although it has the
|
||||
@ -222,7 +220,7 @@ TEST(AudioMixer, FrameNotModifiedForSingleParticipant) {
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, _)).Times(Exactly(2));
|
||||
|
||||
AudioFrame audio_frame;
|
||||
// Two mix iteration to compare after the ramp-up step.
|
||||
@ -251,7 +249,7 @@ TEST(AudioMixer, FrameNotModifiedForSingleAnonymousParticipant) {
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
|
||||
EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&participant, true));
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, _)).Times(Exactly(2));
|
||||
|
||||
AudioFrame audio_frame;
|
||||
// Two mix iteration to compare after the ramp-up step.
|
||||
@ -273,7 +271,7 @@ TEST(AudioMixer, ParticipantSampleRate) {
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
|
||||
for (auto frequency : {8000, 16000, 32000, 48000}) {
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, frequency))
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, frequency))
|
||||
.Times(Exactly(1));
|
||||
participant.fake_frame()->sample_rate_hz_ = frequency;
|
||||
participant.fake_frame()->samples_per_channel_ = frequency / 100;
|
||||
@ -290,7 +288,7 @@ TEST(AudioMixer, ParticipantNumberOfChannels) {
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
|
||||
for (size_t number_of_channels : {1, 2}) {
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
mixer->Mix(kDefaultSampleRateHz, number_of_channels, &frame_for_mixing);
|
||||
EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_);
|
||||
@ -307,7 +305,7 @@ TEST(AudioMixer, LevelIsZeroWhenMixingZeroes) {
|
||||
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
|
||||
for (int i = 0; i < 11; i++) {
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
|
||||
}
|
||||
@ -334,7 +332,7 @@ TEST(AudioMixer, LevelIsMaximalWhenMixingMaximalValues) {
|
||||
// We do >10 iterations, because the audio level indicator only
|
||||
// updates once every 10 calls.
|
||||
for (int i = 0; i < 11; i++) {
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
|
||||
}
|
||||
@ -366,8 +364,7 @@ TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) {
|
||||
// Add all participants but the loudest for mixing.
|
||||
for (int i = 0; i < kAudioSources - 1; i++) {
|
||||
EXPECT_EQ(0, mixer->SetMixabilityStatus(&participants[i], true));
|
||||
EXPECT_CALL(participants[i],
|
||||
GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
}
|
||||
|
||||
@ -384,8 +381,7 @@ TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) {
|
||||
EXPECT_EQ(0,
|
||||
mixer->SetMixabilityStatus(&participants[kAudioSources - 1], true));
|
||||
for (int i = 0; i < kAudioSources; i++) {
|
||||
EXPECT_CALL(participants[i],
|
||||
GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
}
|
||||
|
||||
@ -426,7 +422,7 @@ TEST(AudioMixer, ConstructFromOtherThread) {
|
||||
RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetAnonymousMixabilityStatus,
|
||||
mixer.get(), &participant, true)));
|
||||
|
||||
EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
|
||||
EXPECT_CALL(participant, GetAudioFrameWithInfo(_, kDefaultSampleRateHz))
|
||||
.Times(Exactly(1));
|
||||
|
||||
// Do one mixer iteration
|
||||
@ -442,9 +438,9 @@ TEST(AudioMixer, MutedShouldMixAfterUnmuted) {
|
||||
ResetFrame(&frame);
|
||||
}
|
||||
|
||||
std::vector<MixerAudioSource::AudioFrameInfo> frame_info(
|
||||
kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal);
|
||||
frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted;
|
||||
std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
|
||||
kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
|
||||
frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
|
||||
std::vector<bool> expected_status(kAudioSources, true);
|
||||
expected_status[0] = false;
|
||||
|
||||
@ -460,8 +456,8 @@ TEST(AudioMixer, PassiveShouldMixAfterNormal) {
|
||||
ResetFrame(&frame);
|
||||
}
|
||||
|
||||
std::vector<MixerAudioSource::AudioFrameInfo> frame_info(
|
||||
kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal);
|
||||
std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
|
||||
kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
|
||||
frames[0].vad_activity_ = AudioFrame::kVadPassive;
|
||||
std::vector<bool> expected_status(kAudioSources, true);
|
||||
expected_status[0] = false;
|
||||
@ -478,8 +474,8 @@ TEST(AudioMixer, ActiveShouldMixBeforeLoud) {
|
||||
ResetFrame(&frame);
|
||||
}
|
||||
|
||||
std::vector<MixerAudioSource::AudioFrameInfo> frame_info(
|
||||
kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal);
|
||||
std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
|
||||
kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
|
||||
frames[0].vad_activity_ = AudioFrame::kVadPassive;
|
||||
std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
|
||||
std::numeric_limits<int16_t>::max());
|
||||
@ -498,9 +494,9 @@ TEST(AudioMixer, UnmutedShouldMixBeforeLoud) {
|
||||
ResetFrame(&frame);
|
||||
}
|
||||
|
||||
std::vector<MixerAudioSource::AudioFrameInfo> frame_info(
|
||||
kAudioSources, MixerAudioSource::AudioFrameInfo::kNormal);
|
||||
frame_info[0] = MixerAudioSource::AudioFrameInfo::kMuted;
|
||||
std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
|
||||
kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
|
||||
frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
|
||||
std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100,
|
||||
std::numeric_limits<int16_t>::max());
|
||||
std::vector<bool> expected_status(kAudioSources, true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user