Bug 1651745 - Use the right thread for AudioInputProcessing::SetPassThrough and constify some ControlMessages. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D95937
This commit is contained in:
Andreas Pehrson 2020-11-05 16:42:41 +00:00
Родитель 3d227dbad2
Коммит e6ea00c8f4
3 изменённых файлов: 32 добавлений и 13 удалений

Просмотреть файл

@ -104,11 +104,10 @@ void WaitUntil(MediaEventSource<T>& aEvent, const CallbackFunction& aF) {
/*
* Common ControlMessages
*/
class StartInputProcessing : public ControlMessage {
RefPtr<AudioInputTrack> mInputTrack;
RefPtr<AudioInputProcessing> mInputProcessing;
struct StartInputProcessing : public ControlMessage {
const RefPtr<AudioInputTrack> mInputTrack;
const RefPtr<AudioInputProcessing> mInputProcessing;
public:
StartInputProcessing(AudioInputTrack* aTrack,
AudioInputProcessing* aInputProcessing)
: ControlMessage(aTrack),
@ -117,14 +116,29 @@ class StartInputProcessing : public ControlMessage {
void Run() override { mInputProcessing->Start(); }
};
class StopInputProcessing : public ControlMessage {
RefPtr<AudioInputProcessing> mInputProcessing;
struct StopInputProcessing : public ControlMessage {
const RefPtr<AudioInputProcessing> mInputProcessing;
public:
explicit StopInputProcessing(AudioInputProcessing* aInputProcessing)
: ControlMessage(nullptr), mInputProcessing(aInputProcessing) {}
void Run() override { mInputProcessing->Stop(); }
};
struct SetPassThrough : public ControlMessage {
const RefPtr<AudioInputProcessing> mInputProcessing;
const bool mPassThrough;
SetPassThrough(MediaTrack* aTrack, AudioInputProcessing* aInputProcessing,
bool aPassThrough)
: ControlMessage(aTrack),
mInputProcessing(aInputProcessing),
mPassThrough(aPassThrough) {}
void Run() override {
EXPECT_EQ(mInputProcessing->PassThrough(mTrack->GraphImpl()),
!mPassThrough);
mInputProcessing->SetPassThrough(mTrack->GraphImpl(), mPassThrough);
}
};
#endif // MOZ_WEBRTC
class GoFaster : public ControlMessage {
@ -276,7 +290,8 @@ TEST(TestAudioTrackGraph, ErrorCallback)
Unused << WaitFor(Invoke([&] {
inputTrack = AudioInputTrack::Create(graph);
listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE);
listener->SetPassThrough(true);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<SetPassThrough>(inputTrack, listener, true));
inputTrack->SetInputProcessing(listener);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<StartInputProcessing>(inputTrack, listener));
@ -342,7 +357,8 @@ TEST(TestAudioTrackGraph, AudioInputTrack)
port = outputTrack->AllocateInputPort(inputTrack);
/* Primary graph: Open Audio Input through SourceMediaTrack */
listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE);
listener->SetPassThrough(true);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<SetPassThrough>(inputTrack, listener, true));
inputTrack->SetInputProcessing(listener);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<StartInputProcessing>(inputTrack, listener));
@ -429,7 +445,8 @@ void TestCrossGraphPort(uint32_t aInputRate, uint32_t aOutputRate,
DispatchFunction([&] {
inputTrack = AudioInputTrack::Create(primary);
listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE);
listener->SetPassThrough(true);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<SetPassThrough>(inputTrack, listener, true));
inputTrack->SetInputProcessing(listener);
inputTrack->GraphImpl()->AppendMessage(
MakeUnique<StartInputProcessing>(inputTrack, listener));

Просмотреть файл

@ -386,7 +386,7 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings(
mRequestedInputChannelCount(aRequestedInputChannelCount) {}
void Run() override {
mInputProcessing->SetPassThrough(mPassThrough);
mInputProcessing->SetPassThrough(mTrack->GraphImpl(), mPassThrough);
mInputProcessing->SetRequestedInputChannelCount(
mTrack->GraphImpl(), mRequestedInputChannelCount);
}
@ -649,7 +649,9 @@ bool AudioInputProcessing::PassThrough(MediaTrackGraphImpl* aGraph) const {
return mSkipProcessing;
}
void AudioInputProcessing::SetPassThrough(bool aPassThrough) {
void AudioInputProcessing::SetPassThrough(MediaTrackGraphImpl* aGraph,
bool aPassThrough) {
MOZ_ASSERT(aGraph->OnGraphThread());
if (!mSkipProcessing && aPassThrough && mPacketizerInput) {
MOZ_ASSERT(mPacketizerInput->PacketsAvailable() == 0);
mSegment.AppendNullData(mPacketizerInput->FramesAvailable());

Просмотреть файл

@ -176,7 +176,7 @@ class AudioInputProcessing : public AudioDataListener {
const AudioDataValue* aBuffer, size_t aFrames,
TrackRate aRate, uint32_t aChannels);
void SetPassThrough(bool aPassThrough);
void SetPassThrough(MediaTrackGraphImpl* aGraph, bool aPassThrough);
uint32_t GetRequestedInputChannelCount();
void SetRequestedInputChannelCount(MediaTrackGraphImpl* aGraph,
uint32_t aRequestedInputChannelCount);