2018-01-05 20:10:23 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
2012-07-12 15:53:08 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-08-29 15:38:43 +03:00
|
|
|
#include "MediaEngineWebRTCAudio.h"
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2014-04-02 21:58:19 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <algorithm>
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
|
|
|
#include "AudioConverter.h"
|
|
|
|
#include "MediaManager.h"
|
2019-10-02 13:23:02 +03:00
|
|
|
#include "MediaTrackGraphImpl.h"
|
2014-04-18 23:15:10 +04:00
|
|
|
#include "MediaTrackConstraints.h"
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2018-02-22 17:35:16 +03:00
|
|
|
#include "mozilla/ErrorNames.h"
|
2020-10-29 11:55:41 +03:00
|
|
|
#include "nsContentUtils.h"
|
2020-09-23 00:43:49 +03:00
|
|
|
#include "transport/runnable_utils.h"
|
2018-04-12 18:51:35 +03:00
|
|
|
#include "Tracing.h"
|
2014-04-02 21:58:19 +04:00
|
|
|
|
|
|
|
// scoped_ptr.h uses FF
|
|
|
|
#ifdef FF
|
|
|
|
# undef FF
|
|
|
|
#endif
|
2017-10-31 20:25:41 +03:00
|
|
|
#include "webrtc/voice_engine/voice_engine_defines.h"
|
|
|
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
|
|
|
#include "webrtc/common_audio/include/audio_util.h"
|
|
|
|
|
|
|
|
using namespace webrtc;
|
2017-10-31 20:25:41 +03:00
|
|
|
|
2014-04-02 21:58:19 +04:00
|
|
|
// These are restrictions from the webrtc.org code
|
|
|
|
#define MAX_CHANNELS 2
|
2020-07-17 14:36:59 +03:00
|
|
|
#define MONO 1
|
2014-04-02 21:58:19 +04:00
|
|
|
#define MAX_SAMPLING_FREQ 48000 // Hz - multiple of 100
|
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2018-12-12 08:22:49 +03:00
|
|
|
extern LazyLogModule gMediaManagerLog;
|
|
|
|
#define LOG(...) MOZ_LOG(gMediaManagerLog, LogLevel::Debug, (__VA_ARGS__))
|
|
|
|
#define LOG_FRAME(...) \
|
|
|
|
MOZ_LOG(gMediaManagerLog, LogLevel::Verbose, (__VA_ARGS__))
|
|
|
|
#define LOG_ERROR(...) MOZ_LOG(gMediaManagerLog, LogLevel::Error, (__VA_ARGS__))
|
2012-10-16 00:41:46 +04:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
/**
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
* WebRTC Microphone MediaEngineSource.
|
2012-07-12 15:53:08 +04:00
|
|
|
*/
|
2016-05-23 17:22:47 +03:00
|
|
|
|
2016-07-16 22:33:54 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::MediaEngineWebRTCMicrophoneSource(
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<AudioDeviceInfo> aInfo, const nsString& aDeviceName,
|
2019-03-08 14:51:59 +03:00
|
|
|
const nsCString& aDeviceUUID, const nsString& aDeviceGroup,
|
|
|
|
uint32_t aMaxChannelCount, bool aDelayAgnostic, bool aExtendedFilter)
|
2019-10-02 13:22:53 +03:00
|
|
|
: mPrincipal(PRINCIPAL_HANDLE_NONE),
|
2018-09-05 17:00:33 +03:00
|
|
|
mDeviceInfo(std::move(aInfo)),
|
2017-10-17 23:27:20 +03:00
|
|
|
mDelayAgnostic(aDelayAgnostic),
|
|
|
|
mExtendedFilter(aExtendedFilter),
|
2018-04-30 16:37:18 +03:00
|
|
|
mDeviceName(aDeviceName),
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
mDeviceUUID(aDeviceUUID),
|
2019-03-08 14:51:59 +03:00
|
|
|
mDeviceGroup(aDeviceGroup),
|
2018-09-07 17:53:23 +03:00
|
|
|
mDeviceMaxChannelCount(aMaxChannelCount),
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
mSettings(new nsMainThreadPtrHolder<
|
|
|
|
media::Refcountable<dom::MediaTrackSettings>>(
|
|
|
|
"MediaEngineWebRTCMicrophoneSource::mSettings",
|
|
|
|
new media::Refcountable<dom::MediaTrackSettings>(),
|
|
|
|
// Non-strict means it won't assert main thread for us.
|
|
|
|
// It would be great if it did but we're already on the media thread.
|
|
|
|
/* aStrict = */ false)) {
|
2018-07-04 19:00:57 +03:00
|
|
|
#ifndef ANDROID
|
2018-04-30 16:37:18 +03:00
|
|
|
MOZ_ASSERT(mDeviceInfo->DeviceID());
|
2018-07-04 19:00:57 +03:00
|
|
|
#endif
|
2018-04-30 16:37:18 +03:00
|
|
|
|
|
|
|
// We'll init lazily as needed
|
2017-07-02 01:01:25 +03:00
|
|
|
mSettings->mEchoCancellation.Construct(0);
|
|
|
|
mSettings->mAutoGainControl.Construct(0);
|
|
|
|
mSettings->mNoiseSuppression.Construct(0);
|
|
|
|
mSettings->mChannelCount.Construct(0);
|
2018-04-30 16:37:18 +03:00
|
|
|
|
|
|
|
mState = kReleased;
|
2016-07-16 22:33:54 +03:00
|
|
|
}
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsString MediaEngineWebRTCMicrophoneSource::GetName() const {
|
|
|
|
return mDeviceName;
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsCString MediaEngineWebRTCMicrophoneSource::GetUUID() const {
|
|
|
|
return mDeviceUUID;
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
|
2019-03-08 14:51:59 +03:00
|
|
|
nsString MediaEngineWebRTCMicrophoneSource::GetGroupId() const {
|
|
|
|
return mDeviceGroup;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::EvaluateSettings(
|
|
|
|
const NormalizedConstraints& aConstraintsUpdate,
|
|
|
|
const MediaEnginePrefs& aInPrefs, MediaEnginePrefs* aOutPrefs,
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
const char** aOutBadConstraint) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
FlattenedConstraints c(aConstraintsUpdate);
|
2018-11-28 16:41:02 +03:00
|
|
|
MediaEnginePrefs prefs = aInPrefs;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
prefs.mAecOn = c.mEchoCancellation.Get(aInPrefs.mAecOn);
|
2018-11-28 16:41:02 +03:00
|
|
|
prefs.mAgcOn = c.mAutoGainControl.Get(aInPrefs.mAgcOn && prefs.mAecOn);
|
|
|
|
prefs.mNoiseOn = c.mNoiseSuppression.Get(aInPrefs.mNoiseOn && prefs.mAecOn);
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
// Determine an actual channel count to use for this source. Three factors at
|
|
|
|
// play here: the device capabilities, the constraints passed in by content,
|
|
|
|
// and a pref that can force things (for testing)
|
|
|
|
int32_t maxChannels = mDeviceInfo->MaxChannels();
|
|
|
|
|
|
|
|
// First, check channelCount violation wrt constraints. This fails in case of
|
|
|
|
// error.
|
|
|
|
if (c.mChannelCount.mMin > maxChannels) {
|
|
|
|
*aOutBadConstraint = "channelCount";
|
|
|
|
return NS_ERROR_FAILURE;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
}
|
2018-10-17 16:05:51 +03:00
|
|
|
// A pref can force the channel count to use. If the pref has a value of zero
|
|
|
|
// or lower, it has no effect.
|
|
|
|
if (aInPrefs.mChannels <= 0) {
|
|
|
|
prefs.mChannels = maxChannels;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
}
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
// Get the number of channels asked for by content, and clamp it between the
|
|
|
|
// pref and the maximum number of channels that the device supports.
|
2019-09-30 12:15:42 +03:00
|
|
|
prefs.mChannels = c.mChannelCount.Get(std::min(prefs.mChannels, maxChannels));
|
2018-10-17 16:05:51 +03:00
|
|
|
prefs.mChannels = std::max(1, std::min(prefs.mChannels, maxChannels));
|
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG("Mic source %p Audio config: aec: %d, agc: %d, noise: %d, channels: %d",
|
|
|
|
this, prefs.mAecOn ? prefs.mAec : -1, prefs.mAgcOn ? prefs.mAgc : -1,
|
2018-12-12 08:22:49 +03:00
|
|
|
prefs.mNoiseOn ? prefs.mNoise : -1, prefs.mChannels);
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
*aOutPrefs = prefs;
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::Reconfigure(
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
2019-08-28 11:39:57 +03:00
|
|
|
const MediaEnginePrefs& aPrefs, const char** aOutBadConstraint) {
|
2016-07-16 02:55:59 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-02 13:23:02 +03:00
|
|
|
MOZ_ASSERT(mTrack);
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-12-12 08:22:49 +03:00
|
|
|
LOG("Mic source %p Reconfigure ", this);
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2016-07-16 02:55:59 +03:00
|
|
|
NormalizedConstraints constraints(aConstraints);
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEnginePrefs outputPrefs;
|
|
|
|
nsresult rv =
|
|
|
|
EvaluateSettings(constraints, aPrefs, &outputPrefs, aOutBadConstraint);
|
2018-02-22 17:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (aOutBadConstraint) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
GetErrorName(rv, name);
|
2018-12-12 08:22:49 +03:00
|
|
|
LOG("Mic source %p Reconfigure() failed unexpectedly. rv=%s", this,
|
|
|
|
name.Data());
|
2019-03-27 17:10:24 +03:00
|
|
|
Stop();
|
2018-02-22 17:35:16 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
ApplySettings(outputPrefs);
|
2018-03-26 12:05:52 +03:00
|
|
|
|
2018-10-31 14:57:38 +03:00
|
|
|
mCurrentPrefs = outputPrefs;
|
|
|
|
|
2018-02-22 17:35:16 +03:00
|
|
|
return NS_OK;
|
2016-07-16 02:55:59 +03:00
|
|
|
}
|
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::UpdateAECSettings(
|
2020-05-12 11:30:23 +03:00
|
|
|
bool aEnable, bool aUseAecMobile, EchoCancellation::SuppressionLevel aLevel,
|
2020-07-17 12:40:27 +03:00
|
|
|
EchoControlMobile::RoutingMode aRoutingMode) {
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
2020-07-17 12:40:27 +03:00
|
|
|
__func__,
|
|
|
|
[that, track = mTrack, aEnable, aUseAecMobile, aLevel, aRoutingMode] {
|
2018-09-07 17:53:23 +03:00
|
|
|
class Message : public ControlMessage {
|
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
|
2020-05-12 11:30:23 +03:00
|
|
|
bool aUseAecMobile, EchoCancellation::SuppressionLevel aLevel,
|
2020-07-17 12:40:27 +03:00
|
|
|
EchoControlMobile::RoutingMode aRoutingMode)
|
2018-09-07 17:53:23 +03:00
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mEnable(aEnable),
|
2018-02-20 23:23:09 +03:00
|
|
|
mUseAecMobile(aUseAecMobile),
|
2020-05-12 11:30:23 +03:00
|
|
|
mLevel(aLevel),
|
2020-07-17 12:40:27 +03:00
|
|
|
mRoutingMode(aRoutingMode) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void Run() override {
|
2020-05-12 11:30:23 +03:00
|
|
|
mInputProcessing->UpdateAECSettings(mEnable, mUseAecMobile, mLevel,
|
2020-07-17 12:40:27 +03:00
|
|
|
mRoutingMode);
|
2018-11-19 16:25:37 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mEnable;
|
2018-02-20 23:23:09 +03:00
|
|
|
bool mUseAecMobile;
|
|
|
|
EchoCancellation::SuppressionLevel mLevel;
|
2020-05-12 11:30:23 +03:00
|
|
|
EchoControlMobile::RoutingMode mRoutingMode;
|
2018-09-07 17:53:23 +03:00
|
|
|
};
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
2019-08-29 16:33:08 +03:00
|
|
|
return;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2019-08-29 16:33:08 +03:00
|
|
|
|
2020-07-17 12:40:27 +03:00
|
|
|
track->GraphImpl()->AppendMessage(
|
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable, aUseAecMobile,
|
|
|
|
aLevel, aRoutingMode));
|
2018-09-07 17:53:23 +03:00
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings(
|
|
|
|
bool aEnable, GainControl::Mode aMode) {
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-10-02 13:23:02 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction(__func__, [that, track = mTrack, aEnable, aMode] {
|
2018-09-07 17:53:23 +03:00
|
|
|
class Message : public ControlMessage {
|
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
|
2018-02-20 23:23:09 +03:00
|
|
|
GainControl::Mode aMode)
|
2018-09-07 17:53:23 +03:00
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mEnable(aEnable),
|
|
|
|
mMode(aMode) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void Run() override {
|
2018-02-20 23:23:09 +03:00
|
|
|
mInputProcessing->UpdateAGCSettings(mEnable, mMode);
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mEnable;
|
2018-02-20 23:23:09 +03:00
|
|
|
GainControl::Mode mMode;
|
2018-11-19 16:25:37 +03:00
|
|
|
};
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
2019-08-29 16:33:08 +03:00
|
|
|
return;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2019-08-29 16:33:08 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(
|
2019-08-29 16:33:08 +03:00
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable, aMode));
|
2018-09-07 17:53:23 +03:00
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2020-04-10 13:29:21 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::UpdateHPFSettings(bool aEnable) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction(__func__, [that, track = mTrack, aEnable] {
|
|
|
|
class Message : public ControlMessage {
|
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing, bool aEnable)
|
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mEnable(aEnable) {}
|
|
|
|
|
|
|
|
void Run() override { mInputProcessing->UpdateHPFSettings(mEnable); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mEnable;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (track->IsDestroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
track->GraphImpl()->AppendMessage(
|
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::UpdateNSSettings(
|
|
|
|
bool aEnable, webrtc::NoiseSuppression::Level aLevel) {
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-04-30 16:37:18 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-10-02 13:23:02 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction(__func__, [that, track = mTrack, aEnable, aLevel] {
|
2018-09-07 17:53:23 +03:00
|
|
|
class Message : public ControlMessage {
|
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing, bool aEnable,
|
2018-02-20 23:23:09 +03:00
|
|
|
webrtc::NoiseSuppression::Level aLevel)
|
2018-09-07 17:53:23 +03:00
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mEnable(aEnable),
|
2018-02-20 23:23:09 +03:00
|
|
|
mLevel(aLevel) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void Run() override {
|
2018-02-20 23:23:09 +03:00
|
|
|
mInputProcessing->UpdateNSSettings(mEnable, mLevel);
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mEnable;
|
2018-02-20 23:23:09 +03:00
|
|
|
webrtc::NoiseSuppression::Level mLevel;
|
2018-11-19 16:25:37 +03:00
|
|
|
};
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
2019-08-29 16:33:08 +03:00
|
|
|
return;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2019-08-29 16:33:08 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(
|
2019-08-29 16:33:08 +03:00
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable, aLevel));
|
2018-09-07 17:53:23 +03:00
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions(
|
|
|
|
bool aExtendedFilter, bool aDelayAgnostic) {
|
|
|
|
AssertIsOnOwningThread();
|
2018-05-31 17:44:00 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
2019-10-02 13:23:02 +03:00
|
|
|
__func__, [that, track = mTrack, aExtendedFilter, aDelayAgnostic] {
|
2018-09-07 17:53:23 +03:00
|
|
|
class Message : public ControlMessage {
|
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing, bool aExtendedFilter,
|
|
|
|
bool aDelayAgnostic)
|
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mExtendedFilter(aExtendedFilter),
|
|
|
|
mDelayAgnostic(aDelayAgnostic) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void Run() override {
|
|
|
|
mInputProcessing->UpdateAPMExtraOptions(mExtendedFilter,
|
|
|
|
mDelayAgnostic);
|
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mExtendedFilter;
|
|
|
|
bool mDelayAgnostic;
|
|
|
|
};
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
2019-08-29 16:33:08 +03:00
|
|
|
return;
|
2018-11-19 16:25:37 +03:00
|
|
|
}
|
2019-08-29 16:33:08 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(MakeUnique<Message>(
|
2019-08-29 16:33:08 +03:00
|
|
|
that->mInputProcessing, aExtendedFilter, aDelayAgnostic));
|
2018-09-07 17:53:23 +03:00
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::ApplySettings(
|
|
|
|
const MediaEnginePrefs& aPrefs) {
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(
|
2019-10-02 13:23:02 +03:00
|
|
|
mTrack,
|
2018-10-17 16:05:51 +03:00
|
|
|
"ApplySetting is to be called only after SetTrack has been called");
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (mTrack) {
|
2018-02-20 23:23:09 +03:00
|
|
|
UpdateAGCSettings(aPrefs.mAgcOn,
|
|
|
|
static_cast<webrtc::GainControl::Mode>(aPrefs.mAgc));
|
|
|
|
UpdateNSSettings(
|
|
|
|
aPrefs.mNoiseOn,
|
|
|
|
static_cast<webrtc::NoiseSuppression::Level>(aPrefs.mNoise));
|
|
|
|
UpdateAECSettings(
|
|
|
|
aPrefs.mAecOn, aPrefs.mUseAecMobile,
|
2020-05-12 11:30:23 +03:00
|
|
|
static_cast<webrtc::EchoCancellation::SuppressionLevel>(aPrefs.mAec),
|
|
|
|
static_cast<webrtc::EchoControlMobile::RoutingMode>(
|
2020-07-17 12:40:27 +03:00
|
|
|
aPrefs.mRoutingMode));
|
2020-04-10 13:29:21 +03:00
|
|
|
UpdateHPFSettings(aPrefs.mHPFOn);
|
2018-10-17 16:05:51 +03:00
|
|
|
|
2020-07-17 12:40:27 +03:00
|
|
|
UpdateAPMExtraOptions(mExtendedFilter, mDelayAgnostic);
|
2018-10-17 16:05:51 +03:00
|
|
|
}
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2016-07-16 22:33:54 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-10-02 13:23:02 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction(__func__, [that, track = mTrack, prefs = aPrefs] {
|
2018-10-17 16:05:51 +03:00
|
|
|
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
|
|
|
|
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
|
|
|
|
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
|
|
|
|
that->mSettings->mChannelCount.Value() = prefs.mChannels;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-11-08 16:10:45 +03:00
|
|
|
class Message : public ControlMessage {
|
2018-10-17 16:05:59 +03:00
|
|
|
public:
|
2020-11-05 19:42:20 +03:00
|
|
|
Message(MediaTrack* aTrack, AudioInputProcessing* aInputProcessing,
|
|
|
|
bool aPassThrough, uint32_t aRequestedInputChannelCount)
|
|
|
|
: ControlMessage(aTrack),
|
2018-09-07 17:53:23 +03:00
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mPassThrough(aPassThrough),
|
|
|
|
mRequestedInputChannelCount(aRequestedInputChannelCount) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void Run() override {
|
2020-11-05 19:42:41 +03:00
|
|
|
mInputProcessing->SetPassThrough(mTrack->GraphImpl(), mPassThrough);
|
2018-09-07 17:53:23 +03:00
|
|
|
mInputProcessing->SetRequestedInputChannelCount(
|
2020-11-05 19:42:20 +03:00
|
|
|
mTrack->GraphImpl(), mRequestedInputChannelCount);
|
2018-11-19 16:25:37 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
2018-10-17 16:05:51 +03:00
|
|
|
bool mPassThrough;
|
|
|
|
uint32_t mRequestedInputChannelCount;
|
2018-11-19 16:25:37 +03:00
|
|
|
};
|
|
|
|
|
2020-04-10 13:29:21 +03:00
|
|
|
// The high-pass filter is not taken into account when activating the
|
|
|
|
// pass through, since it's not controllable from content.
|
2018-10-17 16:05:51 +03:00
|
|
|
bool passThrough = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn);
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
2019-08-29 16:33:08 +03:00
|
|
|
return;
|
2017-11-08 16:10:45 +03:00
|
|
|
}
|
2019-08-29 16:33:08 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(MakeUnique<Message>(
|
2020-11-05 19:42:20 +03:00
|
|
|
track, that->mInputProcessing, passThrough, prefs.mChannels));
|
2016-07-16 22:33:54 +03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::Allocate(
|
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
2019-12-04 18:39:41 +03:00
|
|
|
const MediaEnginePrefs& aPrefs, uint64_t aWindowID,
|
2019-07-30 19:28:44 +03:00
|
|
|
const char** aOutBadConstraint) {
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
mState = kAllocated;
|
|
|
|
|
|
|
|
NormalizedConstraints normalized(aConstraints);
|
|
|
|
MediaEnginePrefs outputPrefs;
|
|
|
|
nsresult rv =
|
|
|
|
EvaluateSettings(normalized, aPrefs, &outputPrefs, aOutBadConstraint);
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-02-23 12:20:01 +03:00
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction(__func__, [that, prefs = outputPrefs] {
|
|
|
|
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
|
|
|
|
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
|
|
|
|
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
|
|
|
|
that->mSettings->mChannelCount.Value() = prefs.mChannels;
|
|
|
|
}));
|
2018-02-23 12:20:01 +03:00
|
|
|
|
2018-10-31 14:57:38 +03:00
|
|
|
mCurrentPrefs = outputPrefs;
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
return rv;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
}
|
|
|
|
|
2019-03-27 17:10:24 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::Deallocate() {
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-07-16 02:55:59 +03:00
|
|
|
|
2019-02-11 12:05:08 +03:00
|
|
|
MOZ_ASSERT(mState == kStopped || mState == kAllocated);
|
2018-05-31 17:44:00 +03:00
|
|
|
|
2018-10-12 16:57:49 +03:00
|
|
|
class EndTrackMessage : public ControlMessage {
|
|
|
|
public:
|
2020-11-05 19:42:20 +03:00
|
|
|
EndTrackMessage(AudioInputTrack* aTrack,
|
2019-10-02 13:22:53 +03:00
|
|
|
AudioInputProcessing* aAudioInputProcessing)
|
2020-11-05 19:42:20 +03:00
|
|
|
: ControlMessage(aTrack),
|
|
|
|
mInputProcessing(aAudioInputProcessing),
|
|
|
|
mInputTrack(aTrack) {}
|
2018-10-12 16:57:49 +03:00
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
void Run() override { mInputProcessing->End(); }
|
2018-10-12 16:57:49 +03:00
|
|
|
|
|
|
|
protected:
|
2019-10-02 13:22:53 +03:00
|
|
|
const RefPtr<AudioInputProcessing> mInputProcessing;
|
2020-11-05 19:42:20 +03:00
|
|
|
AudioInputTrack const* mInputTrack;
|
2018-10-12 16:57:49 +03:00
|
|
|
};
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
if (mTrack) {
|
2018-10-12 16:57:49 +03:00
|
|
|
RefPtr<AudioInputProcessing> inputProcessing = mInputProcessing;
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
2019-10-02 13:23:02 +03:00
|
|
|
__func__, [track = std::move(mTrack),
|
2019-10-02 13:22:53 +03:00
|
|
|
audioInputProcessing = std::move(inputProcessing)] {
|
2019-10-02 13:23:02 +03:00
|
|
|
if (track->IsDestroyed()) {
|
|
|
|
// This track has already been destroyed on main thread by its
|
2018-11-23 18:03:39 +03:00
|
|
|
// DOMMediaStream. No cleanup left to do.
|
2019-03-27 21:05:56 +03:00
|
|
|
return;
|
2018-10-01 18:12:14 +03:00
|
|
|
}
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(
|
|
|
|
MakeUnique<EndTrackMessage>(track, audioInputProcessing));
|
2018-10-01 18:12:14 +03:00
|
|
|
}));
|
2018-02-05 12:48:23 +03:00
|
|
|
}
|
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
// Reset all state. This is not strictly necessary, this instance will get
|
|
|
|
// destroyed soon.
|
2019-10-02 13:23:02 +03:00
|
|
|
mTrack = nullptr;
|
2018-09-05 17:00:33 +03:00
|
|
|
mPrincipal = PRINCIPAL_HANDLE_NONE;
|
2016-07-16 02:55:59 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
// If empty, no callbacks to deliver data should be occuring
|
|
|
|
MOZ_ASSERT(mState != kReleased, "Source not allocated");
|
|
|
|
MOZ_ASSERT(mState != kStarted, "Source not stopped");
|
|
|
|
|
|
|
|
mState = kReleased;
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG("Mic source %p Audio device %s deallocated", this,
|
|
|
|
NS_ConvertUTF16toUTF8(mDeviceName).get());
|
2012-07-12 15:53:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-04 09:39:40 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::SetTrack(
|
2020-11-05 19:42:07 +03:00
|
|
|
const RefPtr<MediaTrack>& aTrack, const PrincipalHandle& aPrincipal) {
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-02 13:23:02 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
2020-11-05 19:42:20 +03:00
|
|
|
MOZ_ASSERT(aTrack->AsAudioInputTrack());
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
MOZ_ASSERT(!mTrack);
|
2018-09-05 17:00:33 +03:00
|
|
|
MOZ_ASSERT(mPrincipal == PRINCIPAL_HANDLE_NONE);
|
2020-11-05 19:42:20 +03:00
|
|
|
mTrack = aTrack->AsAudioInputTrack();
|
2018-09-05 17:00:33 +03:00
|
|
|
mPrincipal = aPrincipal;
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2019-10-02 13:22:53 +03:00
|
|
|
mInputProcessing =
|
2020-11-05 19:42:20 +03:00
|
|
|
MakeAndAddRef<AudioInputProcessing>(mDeviceMaxChannelCount, mPrincipal);
|
2019-01-14 18:09:34 +03:00
|
|
|
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
2020-11-05 19:42:20 +03:00
|
|
|
__func__, [track = mTrack, processing = mInputProcessing]() mutable {
|
|
|
|
track->SetInputProcessing(std::move(processing));
|
|
|
|
track->Resume(); // Suspended by MediaManager
|
2019-03-27 21:05:56 +03:00
|
|
|
}));
|
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG("Mic source %p Track %p registered for microphone capture", this,
|
|
|
|
aTrack.get());
|
2017-12-18 18:19:33 +03:00
|
|
|
}
|
2013-01-01 03:12:12 +04:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
class StartStopMessage : public ControlMessage {
|
|
|
|
public:
|
2018-10-03 15:58:28 +03:00
|
|
|
enum StartStop { Start, Stop };
|
|
|
|
|
|
|
|
StartStopMessage(AudioInputProcessing* aInputProcessing, StartStop aAction)
|
|
|
|
: ControlMessage(nullptr),
|
|
|
|
mInputProcessing(aInputProcessing),
|
|
|
|
mAction(aAction) {}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
void Run() override {
|
2018-10-03 15:58:28 +03:00
|
|
|
if (mAction == StartStopMessage::Start) {
|
2018-09-07 17:53:23 +03:00
|
|
|
mInputProcessing->Start();
|
2018-10-03 15:58:28 +03:00
|
|
|
} else if (mAction == StartStopMessage::Stop) {
|
2018-09-07 17:53:23 +03:00
|
|
|
mInputProcessing->Stop();
|
2018-10-03 15:58:28 +03:00
|
|
|
} else {
|
|
|
|
MOZ_CRASH("Invalid enum value");
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
2018-10-03 15:58:28 +03:00
|
|
|
StartStop mAction;
|
2018-09-07 17:53:23 +03:00
|
|
|
};
|
|
|
|
|
2019-03-27 17:10:24 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::Start() {
|
2017-12-18 18:19:33 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-09-05 17:00:33 +03:00
|
|
|
|
|
|
|
// This spans setting both the enabled state and mState.
|
2018-04-30 16:37:18 +03:00
|
|
|
if (mState == kStarted) {
|
|
|
|
return NS_OK;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
}
|
|
|
|
|
2018-04-30 16:37:18 +03:00
|
|
|
MOZ_ASSERT(mState == kAllocated || mState == kStopped);
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2020-08-04 19:30:40 +03:00
|
|
|
// This check is unreliable due to potential in-flight device updates.
|
|
|
|
// Multiple input devices are reliably excluded in OpenAudioInputImpl(),
|
|
|
|
// but the check here provides some error reporting most of the
|
|
|
|
// time.
|
2018-04-30 16:37:18 +03:00
|
|
|
CubebUtils::AudioDeviceID deviceID = mDeviceInfo->DeviceID();
|
2019-10-02 13:23:02 +03:00
|
|
|
if (mTrack->GraphImpl()->InputDeviceID() &&
|
|
|
|
mTrack->GraphImpl()->InputDeviceID() != deviceID) {
|
2018-04-30 16:37:18 +03:00
|
|
|
// For now, we only allow opening a single audio input device per document,
|
2019-10-02 13:23:02 +03:00
|
|
|
// because we can only have one MTG per document.
|
2019-05-10 19:06:09 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-10-02 13:22:53 +03:00
|
|
|
NS_DispatchToMainThread(
|
2019-10-02 13:23:02 +03:00
|
|
|
NS_NewRunnableFunction(__func__, [that, deviceID, track = mTrack] {
|
|
|
|
if (track->IsDestroyed()) {
|
2019-03-27 21:05:56 +03:00
|
|
|
return;
|
2018-10-03 15:58:28 +03:00
|
|
|
}
|
2018-10-01 18:12:14 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(MakeUnique<StartStopMessage>(
|
2019-01-08 13:06:11 +03:00
|
|
|
that->mInputProcessing, StartStopMessage::Start));
|
2019-10-02 13:23:02 +03:00
|
|
|
track->OpenAudioInput(deviceID, that->mInputProcessing);
|
2018-10-03 15:58:28 +03:00
|
|
|
}));
|
2017-12-18 18:19:33 +03:00
|
|
|
|
2018-10-31 14:57:38 +03:00
|
|
|
ApplySettings(mCurrentPrefs);
|
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
MOZ_ASSERT(mState != kReleased);
|
|
|
|
mState = kStarted;
|
2016-02-17 21:19:02 +03:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-27 17:10:24 +03:00
|
|
|
nsresult MediaEngineWebRTCMicrophoneSource::Stop() {
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2013-01-10 20:52:53 +04:00
|
|
|
|
2018-12-12 08:22:49 +03:00
|
|
|
LOG("Mic source %p Stop()", this);
|
2019-10-02 13:23:02 +03:00
|
|
|
MOZ_ASSERT(mTrack, "SetTrack must have been called before ::Stop");
|
2013-01-10 20:52:53 +04:00
|
|
|
|
2018-10-03 15:58:28 +03:00
|
|
|
if (mState == kStopped) {
|
2018-09-07 17:53:23 +03:00
|
|
|
// Already stopped - this is allowed
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-09-05 17:00:33 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
2019-03-27 21:05:56 +03:00
|
|
|
NS_DispatchToMainThread(
|
2019-10-02 13:23:02 +03:00
|
|
|
NS_NewRunnableFunction(__func__, [that, track = mTrack] {
|
|
|
|
if (track->IsDestroyed()) {
|
2019-03-27 21:05:56 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
track->GraphImpl()->AppendMessage(MakeUnique<StartStopMessage>(
|
2019-03-27 21:05:56 +03:00
|
|
|
that->mInputProcessing, StartStopMessage::Stop));
|
|
|
|
CubebUtils::AudioDeviceID deviceID = that->mDeviceInfo->DeviceID();
|
|
|
|
Maybe<CubebUtils::AudioDeviceID> id = Some(deviceID);
|
2019-10-02 13:23:02 +03:00
|
|
|
track->CloseAudioInput(id);
|
2019-03-27 21:05:56 +03:00
|
|
|
}));
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mState == kStarted, "Should be started when stopping");
|
|
|
|
mState = kStopped;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-26 11:41:20 +03:00
|
|
|
void MediaEngineWebRTCMicrophoneSource::GetSettings(
|
|
|
|
dom::MediaTrackSettings& aOutSettings) const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
aOutSettings = *mSettings;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::AudioInputProcessing(
|
2020-11-05 19:42:20 +03:00
|
|
|
uint32_t aMaxChannelCount, const PrincipalHandle& aPrincipalHandle)
|
|
|
|
: mAudioProcessing(AudioProcessing::Create()),
|
2018-09-07 17:53:23 +03:00
|
|
|
mRequestedInputChannelCount(aMaxChannelCount),
|
|
|
|
mSkipProcessing(false),
|
2020-11-05 19:59:51 +03:00
|
|
|
mInputDownmixBuffer(MAX_SAMPLING_FREQ * MAX_CHANNELS / 100),
|
2018-09-07 17:53:23 +03:00
|
|
|
mLiveFramesAppended(false),
|
2020-11-05 19:59:51 +03:00
|
|
|
mLiveBufferingAppended(0),
|
2018-09-07 17:53:23 +03:00
|
|
|
mPrincipal(aPrincipalHandle),
|
2018-10-01 18:12:14 +03:00
|
|
|
mEnabled(false),
|
2020-11-05 19:59:51 +03:00
|
|
|
mEnded(false) {}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioInputProcessing::Disconnect(MediaTrackGraphImpl* aGraph) {
|
2018-09-07 17:53:23 +03:00
|
|
|
// This method is just for asserts.
|
2019-03-06 23:12:25 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaEngineWebRTCMicrophoneSource::Shutdown() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mState == kStarted) {
|
2019-03-27 17:10:24 +03:00
|
|
|
Stop();
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mState == kStopped);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mState == kAllocated || mState == kStopped);
|
2019-03-27 17:10:24 +03:00
|
|
|
Deallocate();
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mState == kReleased);
|
|
|
|
}
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
bool AudioInputProcessing::PassThrough(MediaTrackGraphImpl* aGraph) const {
|
2019-03-06 23:12:25 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2018-09-07 17:53:23 +03:00
|
|
|
return mSkipProcessing;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:42:41 +03:00
|
|
|
void AudioInputProcessing::SetPassThrough(MediaTrackGraphImpl* aGraph,
|
|
|
|
bool aPassThrough) {
|
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2020-11-05 19:59:51 +03:00
|
|
|
if (!mSkipProcessing && aPassThrough && mPacketizerInput) {
|
|
|
|
MOZ_ASSERT(mPacketizerInput->PacketsAvailable() == 0);
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME(
|
|
|
|
"AudioInputProcessing %p Appending %u frames of null data for data "
|
|
|
|
"discarded in the packetizer",
|
|
|
|
this, mPacketizerInput->FramesAvailable());
|
2020-11-05 19:59:51 +03:00
|
|
|
mSegment.AppendNullData(mPacketizerInput->FramesAvailable());
|
|
|
|
mPacketizerInput->Clear();
|
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
mSkipProcessing = aPassThrough;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
uint32_t AudioInputProcessing::GetRequestedInputChannelCount() {
|
2018-09-07 17:53:23 +03:00
|
|
|
return mRequestedInputChannelCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputProcessing::SetRequestedInputChannelCount(
|
2020-11-05 19:42:20 +03:00
|
|
|
MediaTrackGraphImpl* aGraph, uint32_t aRequestedInputChannelCount) {
|
2018-09-07 17:53:23 +03:00
|
|
|
mRequestedInputChannelCount = aRequestedInputChannelCount;
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
aGraph->ReevaluateInputDevice();
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This does an early return in case of error.
|
|
|
|
#define HANDLE_APM_ERROR(fn) \
|
|
|
|
do { \
|
|
|
|
int rv = fn; \
|
|
|
|
if (rv != AudioProcessing::kNoError) { \
|
|
|
|
MOZ_ASSERT_UNREACHABLE("APM error in " #fn); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void AudioInputProcessing::UpdateAECSettings(
|
2020-05-12 11:30:23 +03:00
|
|
|
bool aEnable, bool aUseAecMobile, EchoCancellation::SuppressionLevel aLevel,
|
2020-07-17 12:40:27 +03:00
|
|
|
EchoControlMobile::RoutingMode aRoutingMode) {
|
2018-02-20 23:23:09 +03:00
|
|
|
if (aUseAecMobile) {
|
2018-09-07 17:53:23 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->echo_control_mobile()->Enable(aEnable));
|
2020-05-12 11:30:23 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->echo_control_mobile()->set_routing_mode(
|
|
|
|
aRoutingMode));
|
2018-02-20 23:23:09 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->echo_cancellation()->Enable(false));
|
2018-09-07 17:53:23 +03:00
|
|
|
} else {
|
2018-02-20 23:23:09 +03:00
|
|
|
if (aLevel != EchoCancellation::SuppressionLevel::kLowSuppression &&
|
|
|
|
aLevel != EchoCancellation::SuppressionLevel::kModerateSuppression &&
|
|
|
|
aLevel != EchoCancellation::SuppressionLevel::kHighSuppression) {
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_ERROR(
|
|
|
|
"AudioInputProcessing %p Attempt to set invalid AEC suppression "
|
|
|
|
"level %d",
|
|
|
|
this, static_cast<int>(aLevel));
|
2018-02-20 23:23:09 +03:00
|
|
|
|
|
|
|
aLevel = EchoCancellation::SuppressionLevel::kModerateSuppression;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->echo_control_mobile()->Enable(false));
|
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->echo_cancellation()->Enable(aEnable));
|
2018-02-20 23:23:09 +03:00
|
|
|
HANDLE_APM_ERROR(
|
|
|
|
mAudioProcessing->echo_cancellation()->set_suppression_level(aLevel));
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void AudioInputProcessing::UpdateAGCSettings(bool aEnable,
|
|
|
|
GainControl::Mode aMode) {
|
|
|
|
if (aMode != GainControl::Mode::kAdaptiveAnalog &&
|
|
|
|
aMode != GainControl::Mode::kAdaptiveDigital &&
|
|
|
|
aMode != GainControl::Mode::kFixedDigital) {
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_ERROR("AudioInputProcessing %p Attempt to set invalid AGC mode %d",
|
|
|
|
this, static_cast<int>(aMode));
|
2018-02-20 23:23:09 +03:00
|
|
|
|
|
|
|
aMode = GainControl::Mode::kAdaptiveDigital;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
#if defined(WEBRTC_IOS) || defined(ATA) || defined(WEBRTC_ANDROID)
|
2018-02-20 23:23:09 +03:00
|
|
|
if (aMode == GainControl::Mode::kAdaptiveAnalog) {
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_ERROR(
|
|
|
|
"AudioInputProcessing %p Invalid AGC mode kAgcAdaptiveAnalog on "
|
|
|
|
"mobile",
|
|
|
|
this);
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Bad pref set in all.js or in about:config"
|
|
|
|
" for the auto gain, on mobile.");
|
2018-07-27 16:20:00 +03:00
|
|
|
aMode = GainControl::Mode::kFixedDigital;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
#endif
|
2018-02-20 23:23:09 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->gain_control()->set_mode(aMode));
|
2018-09-07 17:53:23 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->gain_control()->Enable(aEnable));
|
|
|
|
}
|
|
|
|
|
2020-04-10 13:29:21 +03:00
|
|
|
void AudioInputProcessing::UpdateHPFSettings(bool aEnable) {
|
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->high_pass_filter()->Enable(aEnable));
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:23:09 +03:00
|
|
|
void AudioInputProcessing::UpdateNSSettings(
|
|
|
|
bool aEnable, webrtc::NoiseSuppression::Level aLevel) {
|
|
|
|
if (aLevel != NoiseSuppression::Level::kLow &&
|
|
|
|
aLevel != NoiseSuppression::Level::kModerate &&
|
|
|
|
aLevel != NoiseSuppression::Level::kHigh &&
|
|
|
|
aLevel != NoiseSuppression::Level::kVeryHigh) {
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_ERROR(
|
|
|
|
"AudioInputProcessing %p Attempt to set invalid noise suppression "
|
|
|
|
"level %d",
|
|
|
|
this, static_cast<int>(aLevel));
|
2018-02-20 23:23:09 +03:00
|
|
|
|
|
|
|
aLevel = NoiseSuppression::Level::kModerate;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2018-02-20 23:23:09 +03:00
|
|
|
|
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->noise_suppression()->set_level(aLevel));
|
2018-09-07 17:53:23 +03:00
|
|
|
HANDLE_APM_ERROR(mAudioProcessing->noise_suppression()->Enable(aEnable));
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef HANDLE_APM_ERROR
|
|
|
|
|
|
|
|
void AudioInputProcessing::UpdateAPMExtraOptions(bool aExtendedFilter,
|
|
|
|
bool aDelayAgnostic) {
|
|
|
|
webrtc::Config config;
|
|
|
|
config.Set<webrtc::ExtendedFilter>(
|
|
|
|
new webrtc::ExtendedFilter(aExtendedFilter));
|
|
|
|
config.Set<webrtc::DelayAgnostic>(new webrtc::DelayAgnostic(aDelayAgnostic));
|
|
|
|
|
|
|
|
mAudioProcessing->SetExtraOptions(config);
|
|
|
|
}
|
|
|
|
|
2019-01-14 18:09:34 +03:00
|
|
|
void AudioInputProcessing::Start() {
|
|
|
|
mEnabled = true;
|
|
|
|
mLiveFramesAppended = false;
|
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
void AudioInputProcessing::Stop() { mEnabled = false; }
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
void AudioInputProcessing::Pull(MediaTrackGraphImpl* aGraph, GraphTime aFrom,
|
|
|
|
GraphTime aTo, GraphTime aTrackEnd,
|
2020-11-05 19:59:51 +03:00
|
|
|
AudioSegment* aSegment,
|
|
|
|
bool aLastPullThisIteration, bool* aEnded) {
|
2020-11-05 19:42:20 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2018-03-01 00:45:40 +03:00
|
|
|
|
2018-10-12 16:57:49 +03:00
|
|
|
if (mEnded) {
|
2020-11-05 19:42:20 +03:00
|
|
|
*aEnded = true;
|
2018-10-12 16:57:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
TrackTime delta = aTo - aTrackEnd;
|
2020-11-05 19:59:51 +03:00
|
|
|
MOZ_ASSERT(delta >= 0, "We shouldn't append more than requested");
|
|
|
|
TrackTime buffering = 0;
|
2018-08-02 13:25:05 +03:00
|
|
|
|
2020-11-05 19:59:51 +03:00
|
|
|
// Add the amount of buffering required to not underrun and glitch.
|
|
|
|
|
|
|
|
// Make sure there's at least one extra block buffered until audio callbacks
|
|
|
|
// come in, since we round graph iteration durations up to the nearest block.
|
|
|
|
buffering += WEBAUDIO_BLOCK_SIZE;
|
|
|
|
|
|
|
|
// If we're supposed to be packetizing but there's no packetizer yet,
|
|
|
|
// there must not have been any live frames appended yet.
|
|
|
|
MOZ_ASSERT_IF(!PassThrough(aGraph) && !mPacketizerInput,
|
|
|
|
mSegment.GetDuration() == 0);
|
|
|
|
|
|
|
|
if (!PassThrough(aGraph) && mPacketizerInput) {
|
|
|
|
// Processing is active and is processed in chunks of 10ms through the
|
|
|
|
// input packetizer. We allow for 10ms of silence on the track to
|
|
|
|
// accomodate the buffering worst-case.
|
|
|
|
buffering += mPacketizerInput->mPacketSize;
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2017-11-22 16:30:00 +03:00
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
if (delta <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:59:51 +03:00
|
|
|
if (MOZ_LIKELY(mLiveFramesAppended)) {
|
|
|
|
if (MOZ_UNLIKELY(buffering > mLiveBufferingAppended)) {
|
2021-02-18 00:48:33 +03:00
|
|
|
// We need to buffer more data. This could happen the first time we pull
|
|
|
|
// input data, or the first iteration after starting to use the
|
2020-11-05 19:59:51 +03:00
|
|
|
// packetizer.
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Inserting %" PRId64
|
|
|
|
" frames of silence due to buffer increase",
|
|
|
|
this, buffering - mLiveBufferingAppended);
|
2020-11-05 19:59:51 +03:00
|
|
|
mSegment.InsertNullDataAtStart(buffering - mLiveBufferingAppended);
|
|
|
|
mLiveBufferingAppended = buffering;
|
|
|
|
} else if (MOZ_UNLIKELY(buffering < mLiveBufferingAppended)) {
|
|
|
|
// We need to clear some buffered data to reduce latency now that the
|
|
|
|
// packetizer is no longer used.
|
|
|
|
MOZ_ASSERT(PassThrough(aGraph), "Must have turned on passthrough");
|
|
|
|
MOZ_ASSERT(mSegment.GetDuration() >=
|
|
|
|
(mLiveBufferingAppended - buffering));
|
|
|
|
TrackTime frames =
|
|
|
|
std::min(mSegment.GetDuration(), mLiveBufferingAppended - buffering);
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Removing %" PRId64
|
|
|
|
" frames of silence due to buffer decrease",
|
|
|
|
this, frames);
|
2020-11-05 19:59:51 +03:00
|
|
|
mLiveBufferingAppended -= frames;
|
|
|
|
mSegment.RemoveLeading(frames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSegment.GetDuration() > 0) {
|
|
|
|
MOZ_ASSERT(buffering == mLiveBufferingAppended);
|
2020-11-05 19:42:20 +03:00
|
|
|
TrackTime frames = std::min(mSegment.GetDuration(), delta);
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Appending %" PRId64
|
|
|
|
" frames of real data for %u channels.",
|
|
|
|
this, frames, mRequestedInputChannelCount);
|
2020-11-05 19:42:20 +03:00
|
|
|
aSegment->AppendSlice(mSegment, 0, frames);
|
|
|
|
mSegment.RemoveLeading(frames);
|
|
|
|
delta -= frames;
|
2020-11-05 19:59:51 +03:00
|
|
|
|
|
|
|
// Assert that the amount of data buffered doesn't grow unboundedly.
|
|
|
|
MOZ_ASSERT_IF(aLastPullThisIteration, mSegment.GetDuration() <= buffering);
|
2020-11-05 19:42:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (delta <= 0) {
|
2020-11-05 19:59:51 +03:00
|
|
|
if (mSegment.GetDuration() == 0) {
|
|
|
|
mLiveBufferingAppended = -delta;
|
|
|
|
}
|
2020-11-05 19:42:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Pulling %" PRId64
|
|
|
|
" frames of silence for %u channels.",
|
|
|
|
this, delta, mRequestedInputChannelCount);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2020-11-05 19:59:51 +03:00
|
|
|
// This assertion fails if we append silence here after having appended live
|
|
|
|
// frames. Before appending live frames we should add sufficient buffering to
|
|
|
|
// not have to glitch (aka append silence). Failing this meant the buffering
|
|
|
|
// was not sufficient.
|
|
|
|
MOZ_ASSERT_IF(mEnabled, !mLiveFramesAppended);
|
|
|
|
mLiveBufferingAppended = 0;
|
2017-12-21 21:01:17 +03:00
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
aSegment->AppendNullData(delta);
|
2012-10-17 13:46:40 +04:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioInputProcessing::NotifyOutputData(MediaTrackGraphImpl* aGraph,
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames, TrackRate aRate,
|
|
|
|
uint32_t aChannels) {
|
2019-03-06 23:12:25 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2018-10-01 18:12:14 +03:00
|
|
|
MOZ_ASSERT(mEnabled);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2020-11-05 19:42:28 +03:00
|
|
|
if (!mPacketizerOutput || mPacketizerOutput->mPacketSize != aRate / 100u ||
|
|
|
|
mPacketizerOutput->mChannels != aChannels) {
|
2018-01-05 20:10:23 +03:00
|
|
|
// It's ok to drop the audio still in the packetizer here: if this changes,
|
|
|
|
// we changed devices or something.
|
2020-02-22 01:44:00 +03:00
|
|
|
mPacketizerOutput = MakeUnique<AudioPacketizer<AudioDataValue, float>>(
|
|
|
|
aRate / 100, aChannels);
|
2017-10-31 20:25:41 +03:00
|
|
|
}
|
|
|
|
|
2018-01-05 20:10:23 +03:00
|
|
|
mPacketizerOutput->Input(aBuffer, aFrames);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : d2245037e8ee7145af7eef528dcee50817b69d83
extra : histedit_source : 79443c35b82d3bc8833d140dd5afc882b85b4c12
2017-12-04 15:34:14 +03:00
|
|
|
|
2018-01-05 20:10:23 +03:00
|
|
|
while (mPacketizerOutput->PacketsAvailable()) {
|
|
|
|
uint32_t samplesPerPacket =
|
2020-11-05 19:42:28 +03:00
|
|
|
mPacketizerOutput->mPacketSize * mPacketizerOutput->mChannels;
|
2018-01-05 20:10:23 +03:00
|
|
|
if (mOutputBuffer.Length() < samplesPerPacket) {
|
|
|
|
mOutputBuffer.SetLength(samplesPerPacket);
|
|
|
|
}
|
|
|
|
if (mDeinterleavedBuffer.Length() < samplesPerPacket) {
|
|
|
|
mDeinterleavedBuffer.SetLength(samplesPerPacket);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
}
|
2018-01-05 20:10:23 +03:00
|
|
|
float* packet = mOutputBuffer.Data();
|
|
|
|
mPacketizerOutput->Output(packet);
|
|
|
|
|
2017-12-07 18:22:28 +03:00
|
|
|
AutoTArray<float*, MAX_CHANNELS> deinterleavedPacketDataChannelPointers;
|
2018-01-05 20:10:23 +03:00
|
|
|
float* interleavedFarend = nullptr;
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
uint32_t channelCountFarend = 0;
|
|
|
|
uint32_t framesPerPacketFarend = 0;
|
|
|
|
|
2018-01-05 20:10:23 +03:00
|
|
|
// Downmix from aChannels to MAX_CHANNELS if needed. We always have floats
|
|
|
|
// here, the packetized performed the conversion.
|
|
|
|
if (aChannels > MAX_CHANNELS) {
|
|
|
|
AudioConverter converter(
|
|
|
|
AudioConfig(aChannels, 0, AudioConfig::FORMAT_FLT),
|
|
|
|
AudioConfig(MAX_CHANNELS, 0, AudioConfig::FORMAT_FLT));
|
2020-11-05 19:42:28 +03:00
|
|
|
framesPerPacketFarend = mPacketizerOutput->mPacketSize;
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
framesPerPacketFarend =
|
|
|
|
converter.Process(mInputDownmixBuffer, packet, framesPerPacketFarend);
|
|
|
|
interleavedFarend = mInputDownmixBuffer.Data();
|
|
|
|
channelCountFarend = MAX_CHANNELS;
|
|
|
|
deinterleavedPacketDataChannelPointers.SetLength(MAX_CHANNELS);
|
|
|
|
} else {
|
2018-01-05 20:10:23 +03:00
|
|
|
interleavedFarend = packet;
|
|
|
|
channelCountFarend = aChannels;
|
2020-11-05 19:42:28 +03:00
|
|
|
framesPerPacketFarend = mPacketizerOutput->mPacketSize;
|
2018-01-05 20:10:23 +03:00
|
|
|
deinterleavedPacketDataChannelPointers.SetLength(aChannels);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(interleavedFarend &&
|
|
|
|
(channelCountFarend == 1 || channelCountFarend == 2) &&
|
|
|
|
framesPerPacketFarend);
|
|
|
|
|
2017-12-07 18:22:28 +03:00
|
|
|
if (mInputBuffer.Length() < framesPerPacketFarend * channelCountFarend) {
|
|
|
|
mInputBuffer.SetLength(framesPerPacketFarend * channelCountFarend);
|
|
|
|
}
|
|
|
|
|
2018-01-05 20:10:23 +03:00
|
|
|
size_t offset = 0;
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
for (size_t i = 0; i < deinterleavedPacketDataChannelPointers.Length();
|
|
|
|
++i) {
|
2017-12-07 18:22:28 +03:00
|
|
|
deinterleavedPacketDataChannelPointers[i] = mInputBuffer.Data() + offset;
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
offset += framesPerPacketFarend;
|
|
|
|
}
|
|
|
|
|
2017-12-07 18:22:28 +03:00
|
|
|
// Deinterleave, prepare a channel pointers array, with enough storage for
|
|
|
|
// the frames.
|
|
|
|
DeinterleaveAndConvertBuffer(
|
|
|
|
interleavedFarend, framesPerPacketFarend, channelCountFarend,
|
|
|
|
deinterleavedPacketDataChannelPointers.Elements());
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
|
|
|
|
// Having the same config for input and output means we potentially save
|
2017-12-07 18:22:28 +03:00
|
|
|
// some CPU.
|
2018-01-05 20:10:23 +03:00
|
|
|
StreamConfig inputConfig(aRate, channelCountFarend, false);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
StreamConfig outputConfig = inputConfig;
|
|
|
|
|
|
|
|
// Passing the same pointers here saves a copy inside this function.
|
2017-12-07 18:22:28 +03:00
|
|
|
DebugOnly<int> err = mAudioProcessing->ProcessReverseStream(
|
|
|
|
deinterleavedPacketDataChannelPointers.Elements(), inputConfig,
|
|
|
|
outputConfig, deinterleavedPacketDataChannelPointers.Elements());
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
|
2018-01-05 20:10:23 +03:00
|
|
|
MOZ_ASSERT(!err, "Could not process the reverse stream.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only called if we're not in passthrough mode
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioInputProcessing::PacketizeAndProcess(MediaTrackGraphImpl* aGraph,
|
2018-09-07 17:53:23 +03:00
|
|
|
const AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames, TrackRate aRate,
|
|
|
|
uint32_t aChannels) {
|
2018-04-30 16:37:18 +03:00
|
|
|
MOZ_ASSERT(!PassThrough(aGraph),
|
|
|
|
"This should be bypassed when in PassThrough mode.");
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mEnabled);
|
2018-01-05 20:10:23 +03:00
|
|
|
size_t offset = 0;
|
|
|
|
|
2020-11-05 19:42:28 +03:00
|
|
|
if (!mPacketizerInput || mPacketizerInput->mPacketSize != aRate / 100u ||
|
|
|
|
mPacketizerInput->mChannels != aChannels) {
|
2018-01-05 20:10:23 +03:00
|
|
|
// It's ok to drop the audio still in the packetizer here.
|
2020-02-22 01:44:00 +03:00
|
|
|
mPacketizerInput = MakeUnique<AudioPacketizer<AudioDataValue, float>>(
|
|
|
|
aRate / 100, aChannels);
|
2018-01-05 20:10:23 +03:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Appending %zu frames to packetizer", this,
|
|
|
|
aFrames);
|
|
|
|
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
// Packetize our input data into 10ms chunks, deinterleave into planar channel
|
|
|
|
// buffers, process, and append to the right MediaStreamTrack.
|
2018-01-05 19:19:22 +03:00
|
|
|
mPacketizerInput->Input(aBuffer, static_cast<uint32_t>(aFrames));
|
2016-01-21 19:51:36 +03:00
|
|
|
|
2018-01-05 19:19:22 +03:00
|
|
|
while (mPacketizerInput->PacketsAvailable()) {
|
|
|
|
uint32_t samplesPerPacket =
|
2020-11-05 19:42:28 +03:00
|
|
|
mPacketizerInput->mPacketSize * mPacketizerInput->mChannels;
|
2016-05-30 16:24:17 +03:00
|
|
|
if (mInputBuffer.Length() < samplesPerPacket) {
|
|
|
|
mInputBuffer.SetLength(samplesPerPacket);
|
2017-12-07 18:22:28 +03:00
|
|
|
}
|
|
|
|
if (mDeinterleavedBuffer.Length() < samplesPerPacket) {
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
mDeinterleavedBuffer.SetLength(samplesPerPacket);
|
2017-12-07 18:22:28 +03:00
|
|
|
}
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
float* packet = mInputBuffer.Data();
|
2018-01-05 19:19:22 +03:00
|
|
|
mPacketizerInput->Output(packet);
|
2016-02-17 21:19:01 +03:00
|
|
|
|
2020-07-17 14:36:59 +03:00
|
|
|
// Downmix from aChannels to mono if needed. We always have floats
|
|
|
|
// here, the packetizer performed the conversion. This handles sound cards
|
|
|
|
// with multiple physical jacks exposed as a single device with _n_
|
|
|
|
// discrete channels, where only a single mic is plugged in. Those channels
|
|
|
|
// are not correlated temporaly since they are discrete channels, mixing is
|
|
|
|
// just a sum.
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
AutoTArray<float*, 8> deinterleavedPacketizedInputDataChannelPointers;
|
2020-07-17 14:36:59 +03:00
|
|
|
uint32_t channelCountInput = 0;
|
|
|
|
if (aChannels > MAX_CHANNELS) {
|
|
|
|
channelCountInput = MONO;
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers.SetLength(
|
|
|
|
channelCountInput);
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers[0] =
|
|
|
|
mDeinterleavedBuffer.Data();
|
|
|
|
// Downmix to mono (and effectively have a planar buffer) by summing all
|
|
|
|
// channels in the first channel.
|
|
|
|
size_t readIndex = 0;
|
2020-11-05 19:42:28 +03:00
|
|
|
for (size_t i = 0; i < mPacketizerInput->mPacketSize; i++) {
|
2020-07-17 14:36:59 +03:00
|
|
|
mDeinterleavedBuffer.Data()[i] = 0.;
|
|
|
|
for (size_t j = 0; j < aChannels; j++) {
|
|
|
|
mDeinterleavedBuffer.Data()[i] += packet[readIndex++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channelCountInput = aChannels;
|
|
|
|
// Deinterleave the input data
|
|
|
|
// Prepare an array pointing to deinterleaved channels.
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers.SetLength(
|
|
|
|
channelCountInput);
|
|
|
|
offset = 0;
|
|
|
|
for (size_t i = 0;
|
|
|
|
i < deinterleavedPacketizedInputDataChannelPointers.Length(); ++i) {
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers[i] =
|
|
|
|
mDeinterleavedBuffer.Data() + offset;
|
2020-11-05 19:42:28 +03:00
|
|
|
offset += mPacketizerInput->mPacketSize;
|
2020-07-17 14:36:59 +03:00
|
|
|
}
|
|
|
|
// Deinterleave to mInputBuffer, pointed to by inputBufferChannelPointers.
|
2020-11-05 19:42:28 +03:00
|
|
|
Deinterleave(packet, mPacketizerInput->mPacketSize, channelCountInput,
|
2020-07-17 14:36:59 +03:00
|
|
|
deinterleavedPacketizedInputDataChannelPointers.Elements());
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
}
|
|
|
|
|
2020-07-17 14:36:59 +03:00
|
|
|
StreamConfig inputConfig(aRate, channelCountInput,
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
false /* we don't use typing detection*/);
|
|
|
|
StreamConfig outputConfig = inputConfig;
|
|
|
|
|
2020-07-17 12:40:27 +03:00
|
|
|
// Bug 1404965: Get the right delay here, it saves some work down the line.
|
|
|
|
mAudioProcessing->set_stream_delay_ms(0);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
|
|
|
|
// Bug 1414837: find a way to not allocate here.
|
2020-02-11 19:58:33 +03:00
|
|
|
CheckedInt<size_t> bufferSize(sizeof(float));
|
2020-11-05 19:42:28 +03:00
|
|
|
bufferSize *= mPacketizerInput->mPacketSize;
|
2020-07-17 14:36:59 +03:00
|
|
|
bufferSize *= channelCountInput;
|
2020-02-11 19:58:33 +03:00
|
|
|
RefPtr<SharedBuffer> buffer = SharedBuffer::Create(bufferSize);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
|
|
|
|
// Prepare channel pointers to the SharedBuffer created above.
|
|
|
|
AutoTArray<float*, 8> processedOutputChannelPointers;
|
|
|
|
AutoTArray<const float*, 8> processedOutputChannelPointersConst;
|
2020-07-17 14:36:59 +03:00
|
|
|
processedOutputChannelPointers.SetLength(channelCountInput);
|
|
|
|
processedOutputChannelPointersConst.SetLength(channelCountInput);
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
for (size_t i = 0; i < processedOutputChannelPointers.Length(); ++i) {
|
|
|
|
processedOutputChannelPointers[i] =
|
|
|
|
static_cast<float*>(buffer->Data()) + offset;
|
|
|
|
processedOutputChannelPointersConst[i] =
|
|
|
|
static_cast<float*>(buffer->Data()) + offset;
|
2020-11-05 19:42:28 +03:00
|
|
|
offset += mPacketizerInput->mPacketSize;
|
Bug 1397793 - Move to APM - Part 2 - Actual processing. r=pehrsons
This also is long, but simple.
First, we switch to floats everywhere. This allows to work with any rate, is
more flexible with channel layout, and is a stable API (see audio_processing.h
in webrtc.org).
Then, 10ms worth of audio (already at the graph rate) are poped from the
lock-free queue (fed on the other end by the MSG mixer), and does the following:
- Down mixing to stereo (if needed)
- De-interleaving into planar buffer
- Prepare input and output config
- Actually make the API call
- Free the data
Now, first, we should use a ring buffer, and not have to free any data. Then we
also should not use a lock-free queue, and synchronously process the
reverse-stream, but this is enough code already.
Then, the actual mic data processing:
- Pop a packet from the packetizer (that gives us 10ms worth of audio, note that
we switch from int16_t to float, i.e. we don't do this conversion anymore).
- We convert to planar buffers, deinterleaving
- Prepare input and output config
- Allocate a SharedBuffer of the right size
- Process the data with the processing algorithm selected in UpdateSingleSource
- Append to the a MediaSegment, and append to the right MediaStreamTrack for the
correct SourceMediaStream (the data is already planar and all well).
MozReview-Commit-ID: 2IjgHP0GAmw
--HG--
extra : rebase_source : 1e08c4a781db8778e0532f9ef1a8e369513a2c66
extra : source : 0107b3feb84bbe0e643f505ec58e303dfd94e1a7
2017-12-04 15:34:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mAudioProcessing->ProcessStream(
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers.Elements(), inputConfig,
|
|
|
|
outputConfig, processedOutputChannelPointers.Elements());
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
if (mEnded) {
|
2018-08-29 20:00:28 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-14 18:46:46 +03:00
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Appending %u frames of packetized audio",
|
|
|
|
this, mPacketizerInput->mPacketSize);
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
// We already have planar audio data of the right format. Insert into the
|
2019-10-02 13:23:02 +03:00
|
|
|
// MTG.
|
2020-07-17 14:36:59 +03:00
|
|
|
MOZ_ASSERT(processedOutputChannelPointers.Length() == channelCountInput);
|
2018-08-29 20:00:28 +03:00
|
|
|
RefPtr<SharedBuffer> other = buffer;
|
2020-11-05 19:42:20 +03:00
|
|
|
mSegment.AppendFrames(other.forget(), processedOutputChannelPointersConst,
|
2020-11-05 19:42:28 +03:00
|
|
|
mPacketizerInput->mPacketSize, mPrincipal);
|
2016-01-21 19:51:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 16:24:19 +03:00
|
|
|
template <typename T>
|
2020-11-05 19:42:20 +03:00
|
|
|
void AudioInputProcessing::InsertInGraph(MediaTrackGraphImpl* aGraph,
|
|
|
|
const T* aBuffer, size_t aFrames,
|
2018-09-07 17:53:23 +03:00
|
|
|
uint32_t aChannels) {
|
2020-11-05 19:42:20 +03:00
|
|
|
if (mEnded) {
|
2018-08-29 20:00:28 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-03-14 18:46:46 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
MOZ_ASSERT(aChannels >= 1 && aChannels <= 8, "Support up to 8 channels");
|
|
|
|
|
2020-02-11 19:58:33 +03:00
|
|
|
CheckedInt<size_t> bufferSize(sizeof(T));
|
|
|
|
bufferSize *= aFrames;
|
|
|
|
bufferSize *= aChannels;
|
|
|
|
RefPtr<SharedBuffer> buffer = SharedBuffer::Create(bufferSize);
|
2018-08-29 20:00:28 +03:00
|
|
|
AutoTArray<const T*, 8> channels;
|
|
|
|
if (aChannels == 1) {
|
|
|
|
PodCopy(static_cast<T*>(buffer->Data()), aBuffer, aFrames);
|
|
|
|
channels.AppendElement(static_cast<T*>(buffer->Data()));
|
|
|
|
} else {
|
|
|
|
channels.SetLength(aChannels);
|
|
|
|
AutoTArray<T*, 8> write_channels;
|
|
|
|
write_channels.SetLength(aChannels);
|
|
|
|
T* samples = static_cast<T*>(buffer->Data());
|
2017-06-02 09:12:08 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
size_t offset = 0;
|
|
|
|
for (uint32_t i = 0; i < aChannels; ++i) {
|
|
|
|
channels[i] = write_channels[i] = samples + offset;
|
|
|
|
offset += aFrames;
|
2017-06-02 09:12:08 +03:00
|
|
|
}
|
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
DeinterleaveAndConvertBuffer(aBuffer, aFrames, aChannels,
|
|
|
|
write_channels.Elements());
|
|
|
|
}
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2020-11-05 19:44:38 +03:00
|
|
|
LOG_FRAME("AudioInputProcessing %p Appending %zu frames of raw audio", this,
|
|
|
|
aFrames);
|
2016-05-30 16:24:19 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
MOZ_ASSERT(aChannels == channels.Length());
|
2020-11-05 19:42:20 +03:00
|
|
|
mSegment.AppendFrames(buffer.forget(), channels, aFrames, mPrincipal);
|
2016-05-30 16:24:19 +03:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:43:24 +03:00
|
|
|
void AudioInputProcessing::NotifyInputStopped(MediaTrackGraphImpl* aGraph) {
|
2019-12-19 01:53:37 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
|
|
|
// This is called when an AudioCallbackDriver switch has happened for any
|
|
|
|
// reason, including other reasons than starting this audio input stream. We
|
|
|
|
// reset state when this happens, as a fallback driver may have fiddled with
|
|
|
|
// the amount of buffered silence during the switch.
|
|
|
|
mLiveFramesAppended = false;
|
2020-11-05 19:42:20 +03:00
|
|
|
mSegment.Clear();
|
2020-11-18 12:20:56 +03:00
|
|
|
if (mPacketizerInput) {
|
|
|
|
mPacketizerInput->Clear();
|
|
|
|
}
|
2019-12-19 01:53:37 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 16:24:19 +03:00
|
|
|
// Called back on GraphDriver thread!
|
|
|
|
// Note this can be called back after ::Shutdown()
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioInputProcessing::NotifyInputData(MediaTrackGraphImpl* aGraph,
|
2018-09-07 17:53:23 +03:00
|
|
|
const AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames, TrackRate aRate,
|
2020-11-05 19:44:00 +03:00
|
|
|
uint32_t aChannels,
|
|
|
|
uint32_t aAlreadyBuffered) {
|
2019-03-06 23:12:25 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2020-04-07 13:45:52 +03:00
|
|
|
TRACE();
|
2018-04-30 16:37:18 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mEnabled);
|
|
|
|
|
2020-11-05 19:44:00 +03:00
|
|
|
if (!mLiveFramesAppended) {
|
|
|
|
// First time we see live frames getting added. Use what's already buffered
|
|
|
|
// in the driver's scratch buffer as a starting point.
|
2021-02-18 00:48:33 +03:00
|
|
|
mLiveFramesAppended = true;
|
2020-11-05 19:44:00 +03:00
|
|
|
mLiveBufferingAppended = aAlreadyBuffered;
|
|
|
|
}
|
|
|
|
|
2016-05-30 16:24:19 +03:00
|
|
|
// If some processing is necessary, packetize and insert in the WebRTC.org
|
2019-10-02 13:23:02 +03:00
|
|
|
// code. Otherwise, directly insert the mic data in the MTG, bypassing all
|
2018-09-07 17:53:23 +03:00
|
|
|
// processing.
|
2018-04-30 16:37:18 +03:00
|
|
|
if (PassThrough(aGraph)) {
|
2020-11-05 19:42:20 +03:00
|
|
|
InsertInGraph<AudioDataValue>(aGraph, aBuffer, aFrames, aChannels);
|
2016-05-30 16:24:19 +03:00
|
|
|
} else {
|
|
|
|
PacketizeAndProcess(aGraph, aBuffer, aFrames, aRate, aChannels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 17:24:17 +03:00
|
|
|
#define ResetProcessingIfNeeded(_processing) \
|
|
|
|
do { \
|
2017-10-31 20:25:41 +03:00
|
|
|
bool enabled = mAudioProcessing->_processing()->is_enabled(); \
|
2016-04-22 17:24:17 +03:00
|
|
|
\
|
|
|
|
if (enabled) { \
|
2017-10-31 20:25:41 +03:00
|
|
|
int rv = mAudioProcessing->_processing()->Enable(!enabled); \
|
2016-04-22 17:24:17 +03:00
|
|
|
if (rv) { \
|
|
|
|
NS_WARNING("Could not reset the status of the " #_processing \
|
|
|
|
" on device change."); \
|
|
|
|
return; \
|
|
|
|
} \
|
2017-10-31 20:25:41 +03:00
|
|
|
rv = mAudioProcessing->_processing()->Enable(enabled); \
|
2016-04-22 17:24:17 +03:00
|
|
|
if (rv) { \
|
|
|
|
NS_WARNING("Could not reset the status of the " #_processing \
|
|
|
|
" on device change."); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioInputProcessing::DeviceChanged(MediaTrackGraphImpl* aGraph) {
|
2019-03-06 23:12:25 +03:00
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
2016-04-22 17:24:17 +03:00
|
|
|
// Reset some processing
|
2017-10-31 20:25:41 +03:00
|
|
|
ResetProcessingIfNeeded(gain_control);
|
|
|
|
ResetProcessingIfNeeded(echo_cancellation);
|
|
|
|
ResetProcessingIfNeeded(noise_suppression);
|
2017-12-11 13:34:23 +03:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
void AudioInputProcessing::End() {
|
|
|
|
mEnded = true;
|
|
|
|
mSegment.Clear();
|
|
|
|
}
|
|
|
|
|
2021-02-18 00:48:33 +03:00
|
|
|
TrackTime AudioInputProcessing::NumBufferedFrames(
|
|
|
|
MediaTrackGraphImpl* aGraph) const {
|
|
|
|
MOZ_ASSERT(aGraph->OnGraphThread());
|
|
|
|
return mSegment.GetDuration();
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:42:20 +03:00
|
|
|
void AudioInputTrack::Destroy() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
Maybe<CubebUtils::AudioDeviceID> id = Nothing();
|
|
|
|
CloseAudioInput(id);
|
|
|
|
|
|
|
|
MediaTrack::Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputTrack::SetInputProcessing(
|
|
|
|
RefPtr<AudioInputProcessing> aInputProcessing) {
|
|
|
|
class Message : public ControlMessage {
|
|
|
|
RefPtr<AudioInputTrack> mTrack;
|
|
|
|
RefPtr<AudioInputProcessing> mProcessing;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Message(RefPtr<AudioInputTrack> aTrack,
|
|
|
|
RefPtr<AudioInputProcessing> aProcessing)
|
|
|
|
: ControlMessage(aTrack),
|
|
|
|
mTrack(std::move(aTrack)),
|
|
|
|
mProcessing(std::move(aProcessing)) {}
|
|
|
|
void Run() override {
|
|
|
|
mTrack->SetInputProcessingImpl(std::move(mProcessing));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (IsDestroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GraphImpl()->AppendMessage(
|
|
|
|
MakeUnique<Message>(std::move(this), std::move(aInputProcessing)));
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioInputTrack* AudioInputTrack::Create(MediaTrackGraph* aGraph) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
AudioInputTrack* track = new AudioInputTrack(aGraph->GraphRate());
|
|
|
|
aGraph->AddTrack(track);
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputTrack::DestroyImpl() {
|
|
|
|
ProcessedMediaTrack::DestroyImpl();
|
2021-02-17 17:02:42 +03:00
|
|
|
if (mInputProcessing) {
|
|
|
|
mInputProcessing->End();
|
|
|
|
}
|
2020-11-05 19:42:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputTrack::ProcessInput(GraphTime aFrom, GraphTime aTo,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
TRACE_COMMENT("AudioInputTrack %p", this);
|
|
|
|
bool ended = false;
|
2020-11-05 19:59:51 +03:00
|
|
|
mInputProcessing->Pull(
|
|
|
|
GraphImpl(), aFrom, aTo, TrackTimeToGraphTime(GetEnd()),
|
|
|
|
GetData<AudioSegment>(), aTo == GraphImpl()->mStateComputedTime, &ended);
|
2020-11-18 11:52:32 +03:00
|
|
|
ApplyTrackDisabling(mSegment.get());
|
2020-11-05 19:42:20 +03:00
|
|
|
if (ended && (aFlags & ALLOW_END)) {
|
|
|
|
mEnded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputTrack::SetInputProcessingImpl(
|
|
|
|
RefPtr<AudioInputProcessing> aInputProcessing) {
|
|
|
|
MOZ_ASSERT(GraphImpl()->OnGraphThread());
|
|
|
|
mInputProcessing = std::move(aInputProcessing);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AudioInputTrack::OpenAudioInput(CubebUtils::AudioDeviceID aId,
|
|
|
|
AudioDataListener* aListener) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(GraphImpl());
|
|
|
|
MOZ_ASSERT(!mInputListener);
|
|
|
|
mInputListener = aListener;
|
|
|
|
return GraphImpl()->OpenAudioInput(aId, aListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioInputTrack::CloseAudioInput(Maybe<CubebUtils::AudioDeviceID>& aId) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(GraphImpl());
|
|
|
|
if (!mInputListener) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GraphImpl()->CloseAudioInput(aId, mInputListener);
|
|
|
|
mInputListener = nullptr;
|
|
|
|
}
|
2018-10-12 16:57:49 +03:00
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsString MediaEngineWebRTCAudioCaptureSource::GetName() const {
|
|
|
|
return u"AudioCapture"_ns;
|
2015-07-24 15:28:16 +03:00
|
|
|
}
|
2016-01-21 19:51:36 +03:00
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsCString MediaEngineWebRTCAudioCaptureSource::GetUUID() const {
|
2020-07-17 12:40:27 +03:00
|
|
|
nsID uuid;
|
2015-07-24 15:28:16 +03:00
|
|
|
char uuidBuffer[NSID_LENGTH];
|
|
|
|
nsCString asciiString;
|
|
|
|
ErrorResult rv;
|
|
|
|
|
|
|
|
rv = nsContentUtils::GenerateUUIDInPlace(uuid);
|
|
|
|
if (rv.Failed()) {
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
return ""_ns;
|
2015-07-24 15:28:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uuid.ToProvidedString(uuidBuffer);
|
|
|
|
asciiString.AssignASCII(uuidBuffer);
|
|
|
|
|
|
|
|
// Remove {} and the null terminator
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
return nsCString(Substring(asciiString, 1, NSID_LENGTH - 3));
|
2015-07-24 15:28:16 +03:00
|
|
|
}
|
|
|
|
|
2019-03-08 14:51:59 +03:00
|
|
|
nsString MediaEngineWebRTCAudioCaptureSource::GetGroupId() const {
|
|
|
|
return u"AudioCaptureGroup"_ns;
|
|
|
|
}
|
|
|
|
|
2019-01-04 09:39:40 +03:00
|
|
|
void MediaEngineWebRTCAudioCaptureSource::SetTrack(
|
2020-11-05 19:42:07 +03:00
|
|
|
const RefPtr<MediaTrack>& aTrack, const PrincipalHandle& aPrincipalHandle) {
|
2017-12-18 18:19:33 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-02 13:23:02 +03:00
|
|
|
// Nothing to do here. aTrack is a placeholder dummy and not exposed.
|
2017-12-18 18:19:33 +03:00
|
|
|
}
|
|
|
|
|
2019-03-27 17:10:24 +03:00
|
|
|
nsresult MediaEngineWebRTCAudioCaptureSource::Start() {
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-07-24 15:28:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-27 17:10:24 +03:00
|
|
|
nsresult MediaEngineWebRTCAudioCaptureSource::Stop() {
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-07-24 15:28:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
nsresult MediaEngineWebRTCAudioCaptureSource::Reconfigure(
|
2015-09-21 01:45:57 +03:00
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
2019-08-28 11:39:57 +03:00
|
|
|
const MediaEnginePrefs& aPrefs, const char** aOutBadConstraint) {
|
2015-09-21 01:45:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-31 13:54:56 +03:00
|
|
|
void MediaEngineWebRTCAudioCaptureSource::GetSettings(
|
2019-05-31 17:47:47 +03:00
|
|
|
dom::MediaTrackSettings& aOutSettings) const {
|
|
|
|
aOutSettings.mAutoGainControl.Construct(false);
|
|
|
|
aOutSettings.mEchoCancellation.Construct(false);
|
|
|
|
aOutSettings.mNoiseSuppression.Construct(false);
|
|
|
|
aOutSettings.mChannelCount.Construct(1);
|
|
|
|
}
|
2019-05-31 13:54:56 +03:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
} // namespace mozilla
|