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"
|
|
|
|
#include "MediaStreamGraphImpl.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"
|
2014-07-08 23:02:40 +04:00
|
|
|
#include "mtransport/runnable_utils.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.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
|
|
|
|
#define MAX_SAMPLING_FREQ 48000 // Hz - multiple of 100
|
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-11-18 06:31:46 +04:00
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
LogModule*
|
|
|
|
GetMediaManagerLog();
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG(msg) MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Debug, msg)
|
2018-10-17 16:05:59 +03:00
|
|
|
#define LOG_FRAMES(msg) \
|
|
|
|
MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Verbose, msg)
|
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,
|
|
|
|
const nsCString& aDeviceUUID,
|
|
|
|
uint32_t aMaxChannelCount,
|
|
|
|
bool aDelayAgnostic,
|
|
|
|
bool aExtendedFilter)
|
2018-09-05 17:00:33 +03:00
|
|
|
: mTrackID(TRACK_NONE)
|
|
|
|
, mPrincipal(PRINCIPAL_HANDLE_NONE)
|
|
|
|
, 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)
|
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))
|
2016-07-16 22:33:54 +03:00
|
|
|
{
|
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
|
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
|
|
|
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
|
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
|
|
|
return mDeviceUUID;
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 01:01:52 +03:00
|
|
|
// GetBestFitnessDistance returns the best distance the capture device can offer
|
|
|
|
// as a whole, given an accumulated number of ConstraintSets.
|
|
|
|
// Ideal values are considered in the first ConstraintSet only.
|
|
|
|
// Plain values are treated as Ideal in the first ConstraintSet.
|
|
|
|
// Plain values are treated as Exact in subsequent ConstraintSets.
|
|
|
|
// Infinity = UINT32_MAX e.g. device cannot satisfy accumulated ConstraintSets.
|
|
|
|
// A finite result may be used to calculate this device's ranking as a choice.
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
uint32_t
|
|
|
|
MediaEngineWebRTCMicrophoneSource::GetBestFitnessDistance(
|
|
|
|
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
|
|
|
|
const nsString& aDeviceId) const
|
2015-07-03 01:01:52 +03:00
|
|
|
{
|
|
|
|
uint32_t distance = 0;
|
|
|
|
|
2016-06-17 22:20:10 +03:00
|
|
|
for (const auto* cs : aConstraintSets) {
|
2018-10-17 16:05:59 +03:00
|
|
|
distance =
|
|
|
|
MediaConstraintsHelper::GetMinimumFitnessDistance(*cs, aDeviceId);
|
2015-07-03 01:01:52 +03:00
|
|
|
break; // distance is read from first entry only
|
|
|
|
}
|
|
|
|
return distance;
|
|
|
|
}
|
|
|
|
|
2016-01-23 00:46:38 +03:00
|
|
|
nsresult
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::EvaluateSettings(
|
2018-10-17 16:05:59 +03:00
|
|
|
const NormalizedConstraints& aConstraintsUpdate,
|
|
|
|
const MediaEnginePrefs& aInPrefs,
|
|
|
|
MediaEnginePrefs* aOutPrefs,
|
|
|
|
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
|
|
|
MediaEnginePrefs prefs = aInPrefs;
|
2018-08-29 20:00:28 +03:00
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
FlattenedConstraints c(aConstraintsUpdate);
|
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);
|
|
|
|
prefs.mAgcOn = c.mAutoGainControl.Get(aInPrefs.mAgcOn);
|
|
|
|
prefs.mNoiseOn = c.mNoiseSuppression.Get(aInPrefs.mNoiseOn);
|
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.
|
2018-10-17 16:05:59 +03:00
|
|
|
prefs.mChannels =
|
|
|
|
c.mChannelCount.Get(std::min(aInPrefs.mChannels, maxChannels));
|
2018-10-17 16:05:51 +03:00
|
|
|
prefs.mChannels = std::max(1, std::min(prefs.mChannels, maxChannels));
|
|
|
|
|
|
|
|
LOG(("Audio config: aec: %d, agc: %d, noise: %d, channels: %d",
|
|
|
|
prefs.mAecOn ? prefs.mAec : -1,
|
|
|
|
prefs.mAgcOn ? prefs.mAgc : -1,
|
|
|
|
prefs.mNoiseOn ? prefs.mNoise : -1,
|
|
|
|
prefs.mChannels));
|
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::Reconfigure(
|
|
|
|
const RefPtr<AllocationHandle>&,
|
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const nsString& /* aDeviceId */,
|
|
|
|
const char** aOutBadConstraint)
|
2016-01-23 00:46:38 +03:00
|
|
|
{
|
2016-07-16 02:55:59 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-09-05 17:00:33 +03:00
|
|
|
MOZ_ASSERT(mStream);
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-10-17 16:05:51 +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;
|
2018-10-17 16:05:59 +03:00
|
|
|
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);
|
|
|
|
LOG(("Mic source %p Reconfigure() failed unexpectedly. rv=%s",
|
2018-10-17 16:05:59 +03:00
|
|
|
this,
|
|
|
|
name.Data()));
|
2018-10-17 16:05:51 +03:00
|
|
|
Stop(nullptr);
|
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-10-17 16:05:59 +03:00
|
|
|
void
|
|
|
|
MediaEngineWebRTCMicrophoneSource::Pull(
|
|
|
|
const RefPtr<const AllocationHandle>&,
|
|
|
|
const RefPtr<SourceMediaStream>& aStream,
|
|
|
|
TrackID aTrackID,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2017-10-31 20:25:41 +03:00
|
|
|
{
|
2018-09-07 17:53:23 +03:00
|
|
|
// If pull is enabled, it means that the audio input is not open, and we
|
|
|
|
// should fill it out with silence. This is the only method called on the
|
|
|
|
// MSG thread.
|
2018-10-17 16:05:51 +03:00
|
|
|
mInputProcessing->Pull(aStream, aTrackID, aDesiredTime, aPrincipalHandle);
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::UpdateAECSettings(
|
2018-09-07 17:53:23 +03:00
|
|
|
bool aEnable,
|
2018-02-20 23:23:09 +03:00
|
|
|
bool aUseAecMobile,
|
|
|
|
EchoCancellation::SuppressionLevel aLevel)
|
2018-04-30 16:37:18 +03:00
|
|
|
{
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
2018-02-20 23:23:09 +03:00
|
|
|
[ that, graph = std::move(gripGraph), aEnable, aUseAecMobile,
|
|
|
|
aLevel ]() mutable {
|
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
|
|
|
bool aUseAecMobile,
|
|
|
|
EchoCancellation::SuppressionLevel aLevel)
|
2018-09-07 17:53:23 +03:00
|
|
|
: ControlMessage(nullptr)
|
|
|
|
, mInputProcessing(aInputProcessing)
|
|
|
|
, mEnable(aEnable)
|
2018-02-20 23:23:09 +03:00
|
|
|
, mUseAecMobile(aUseAecMobile)
|
|
|
|
, mLevel(aLevel)
|
2018-09-07 17:53:23 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run() override
|
|
|
|
{
|
2018-02-20 23:23:09 +03:00
|
|
|
mInputProcessing->UpdateAECSettings(mEnable,
|
|
|
|
mUseAecMobile,
|
|
|
|
mLevel);
|
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;
|
2018-09-07 17:53:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(
|
2018-02-20 23:23:09 +03:00
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable,
|
|
|
|
aUseAecMobile, aLevel));
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2018-04-30 16:37:18 +03:00
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::UpdateAGCSettings(
|
2018-09-07 17:53:23 +03:00
|
|
|
bool aEnable,
|
2018-02-20 23:23:09 +03:00
|
|
|
GainControl::Mode aMode)
|
2018-04-30 16:37:18 +03:00
|
|
|
{
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
2018-02-20 23:23:09 +03:00
|
|
|
[ that, graph = std::move(gripGraph), aEnable, aMode ]() mutable {
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run() override
|
|
|
|
{
|
2018-02-20 23:23:09 +03:00
|
|
|
mInputProcessing->UpdateAGCSettings(mEnable, mMode);
|
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-09-07 17:53:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(
|
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable, aMode));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::UpdateNSSettings(
|
2018-09-07 17:53:23 +03:00
|
|
|
bool aEnable,
|
2018-02-20 23:23:09 +03:00
|
|
|
webrtc::NoiseSuppression::Level aLevel)
|
2018-04-30 16:37:18 +03:00
|
|
|
{
|
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;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
2018-02-20 23:23:09 +03:00
|
|
|
[ that, graph = std::move(gripGraph), aEnable, aLevel ]() mutable {
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mEnable;
|
2018-02-20 23:23:09 +03:00
|
|
|
webrtc::NoiseSuppression::Level mLevel;
|
2018-09-07 17:53:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(
|
2018-02-20 23:23:09 +03:00
|
|
|
MakeUnique<Message>(that->mInputProcessing, aEnable, aLevel));
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::UpdateAPMExtraOptions(bool aExtendedFilter,
|
|
|
|
bool aDelayAgnostic)
|
2018-04-30 16:37:18 +03:00
|
|
|
{
|
2018-09-07 17:53:23 +03:00
|
|
|
AssertIsOnOwningThread();
|
2018-05-31 17:44:00 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
2018-10-17 16:05:59 +03:00
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom([that,
|
|
|
|
graph = std::move(gripGraph),
|
|
|
|
aExtendedFilter,
|
|
|
|
aDelayAgnostic]() mutable {
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run() override
|
|
|
|
{
|
|
|
|
mInputProcessing->UpdateAPMExtraOptions(mExtendedFilter,
|
|
|
|
mDelayAgnostic);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mExtendedFilter;
|
|
|
|
bool mDelayAgnostic;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(MakeUnique<Message>(
|
|
|
|
that->mInputProcessing, aExtendedFilter, aDelayAgnostic));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2018-04-30 16:37:18 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 22:33:54 +03:00
|
|
|
void
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs)
|
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
|
|
|
AssertIsOnOwningThread();
|
2018-10-17 16:05:51 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
mStream,
|
2018-10-17 16:05:51 +03:00
|
|
|
"ApplySetting is to be called only after SetTrack has been called");
|
|
|
|
|
|
|
|
if (mStream) {
|
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,
|
|
|
|
static_cast<webrtc::EchoCancellation::SuppressionLevel>(aPrefs.mAec));
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
UpdateAPMExtraOptions(mExtendedFilter, mDelayAgnostic);
|
|
|
|
}
|
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;
|
2018-10-17 16:05:51 +03:00
|
|
|
RefPtr<MediaStreamGraphImpl> graphImpl = mStream->GraphImpl();
|
2018-10-17 16:05:59 +03:00
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
|
|
|
[that, graph = std::move(graphImpl), prefs = aPrefs]() mutable {
|
|
|
|
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
|
|
|
|
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
|
|
|
|
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
|
|
|
|
that->mSettings->mChannelCount.Value() = prefs.mChannels;
|
2017-11-08 16:10:45 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
class Message : public ControlMessage
|
2017-11-08 16:10:45 +03:00
|
|
|
{
|
2018-10-17 16:05:59 +03:00
|
|
|
public:
|
|
|
|
Message(AudioInputProcessing* aInputProcessing,
|
|
|
|
bool aPassThrough,
|
|
|
|
uint32_t aRequestedInputChannelCount)
|
|
|
|
: ControlMessage(nullptr)
|
|
|
|
, mInputProcessing(aInputProcessing)
|
|
|
|
, mPassThrough(aPassThrough)
|
|
|
|
, mRequestedInputChannelCount(aRequestedInputChannelCount)
|
|
|
|
{
|
|
|
|
}
|
2017-11-08 16:10:45 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
void Run() override
|
|
|
|
{
|
|
|
|
mInputProcessing->SetPassThrough(mPassThrough);
|
|
|
|
mInputProcessing->SetRequestedInputChannelCount(
|
|
|
|
mRequestedInputChannelCount);
|
|
|
|
}
|
2017-11-08 16:10:45 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
bool mPassThrough;
|
|
|
|
uint32_t mRequestedInputChannelCount;
|
|
|
|
};
|
2017-11-08 16:10:45 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
bool passThrough = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn);
|
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(MakeUnique<Message>(
|
|
|
|
that->mInputProcessing, passThrough, prefs.mChannels));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2016-07-16 22:33:54 +03:00
|
|
|
}
|
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::Allocate(
|
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const nsString& aDeviceId,
|
|
|
|
const ipc::PrincipalInfo& aPrincipalInfo,
|
|
|
|
AllocationHandle** aOutHandle,
|
|
|
|
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();
|
|
|
|
MOZ_ASSERT(aOutHandle);
|
2018-10-17 16:05:51 +03:00
|
|
|
|
|
|
|
*aOutHandle = nullptr;
|
|
|
|
|
|
|
|
mState = kAllocated;
|
|
|
|
|
|
|
|
NormalizedConstraints normalized(aConstraints);
|
|
|
|
MediaEnginePrefs outputPrefs;
|
2018-10-17 16:05:59 +03:00
|
|
|
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;
|
2018-10-17 16:05:59 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
media::NewRunnableFrom([that, prefs = outputPrefs]() mutable {
|
|
|
|
that->mSettings->mEchoCancellation.Value() = prefs.mAecOn;
|
|
|
|
that->mSettings->mAutoGainControl.Value() = prefs.mAgcOn;
|
|
|
|
that->mSettings->mNoiseSuppression.Value() = prefs.mNoiseOn;
|
|
|
|
that->mSettings->mChannelCount.Value() = prefs.mChannels;
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
2018-02-23 12:20:01 +03:00
|
|
|
|
2018-10-31 14:57:38 +03:00
|
|
|
mCurrentPrefs = outputPrefs;
|
|
|
|
|
2018-10-17 16:05:59 +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
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::Deallocate(
|
|
|
|
const RefPtr<const AllocationHandle>&)
|
2012-07-12 15:53:08 +04:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-07-16 02:55:59 +03:00
|
|
|
|
2018-05-31 17:44:00 +03:00
|
|
|
MOZ_ASSERT(mState == kStopped);
|
|
|
|
|
2018-10-12 16:57:49 +03:00
|
|
|
class EndTrackMessage : public ControlMessage
|
|
|
|
{
|
2018-10-17 16:05:59 +03:00
|
|
|
public:
|
|
|
|
EndTrackMessage(MediaStream* aStream,
|
|
|
|
AudioInputProcessing* aAudioInputProcessing,
|
|
|
|
TrackID aTrackID)
|
2018-10-12 16:57:49 +03:00
|
|
|
: ControlMessage(aStream)
|
|
|
|
, mInputProcessing(aAudioInputProcessing)
|
|
|
|
, mTrackID(aTrackID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run() override
|
|
|
|
{
|
|
|
|
mInputProcessing->End();
|
|
|
|
mStream->AsSourceStream()->EndTrack(mTrackID);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefPtr<AudioInputProcessing> mInputProcessing;
|
|
|
|
TrackID mTrackID;
|
|
|
|
};
|
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
if (mStream && IsTrackIDExplicit(mTrackID)) {
|
2018-10-01 18:12:14 +03:00
|
|
|
RefPtr<MediaStream> sourceStream = mStream;
|
|
|
|
RefPtr<MediaStreamGraphImpl> graphImpl = mStream->GraphImpl();
|
2018-10-12 16:57:49 +03:00
|
|
|
RefPtr<AudioInputProcessing> inputProcessing = mInputProcessing;
|
2018-10-17 16:05:59 +03:00
|
|
|
NS_DispatchToMainThread(
|
|
|
|
media::NewRunnableFrom([graph = std::move(graphImpl),
|
|
|
|
stream = std::move(sourceStream),
|
|
|
|
audioInputProcessing = std::move(inputProcessing),
|
|
|
|
trackID = mTrackID]() mutable {
|
2018-10-01 18:12:14 +03:00
|
|
|
if (graph) {
|
2018-10-12 16:57:49 +03:00
|
|
|
graph->AppendMessage(
|
2018-10-17 16:05:59 +03:00
|
|
|
MakeUnique<EndTrackMessage>(stream, audioInputProcessing, trackID));
|
2018-10-01 18:12:14 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2018-10-17 16:05:59 +03:00
|
|
|
}));
|
2018-02-05 12:48:23 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
MOZ_ASSERT(mTrackID != TRACK_NONE, "Only deallocate once");
|
2018-09-05 17:00:33 +03:00
|
|
|
|
|
|
|
// Reset all state. This is not strictly necessary, this instance will get
|
|
|
|
// destroyed soon.
|
|
|
|
mStream = nullptr;
|
|
|
|
mTrackID = TRACK_NONE;
|
|
|
|
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;
|
2018-10-17 16:05:59 +03:00
|
|
|
LOG(
|
|
|
|
("Audio device %s deallocated", NS_ConvertUTF16toUTF8(mDeviceName).get()));
|
2018-02-05 12:50:47 +03:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::SetTrack(
|
|
|
|
const RefPtr<const AllocationHandle>&,
|
|
|
|
const RefPtr<SourceMediaStream>& aStream,
|
|
|
|
TrackID aTrackID,
|
|
|
|
const PrincipalHandle& aPrincipal)
|
2012-07-12 15:53:08 +04:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
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
|
|
|
MOZ_ASSERT(aStream);
|
|
|
|
MOZ_ASSERT(IsTrackIDExplicit(aTrackID));
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
if (mStream && mStream->Graph() != aStream->Graph()) {
|
2017-09-16 06:00:39 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
MOZ_ASSERT(!mStream);
|
|
|
|
MOZ_ASSERT(mTrackID == TRACK_NONE);
|
|
|
|
MOZ_ASSERT(mPrincipal == PRINCIPAL_HANDLE_NONE);
|
|
|
|
mStream = aStream;
|
|
|
|
mTrackID = aTrackID;
|
|
|
|
mPrincipal = aPrincipal;
|
2012-07-12 15:53:08 +04:00
|
|
|
|
|
|
|
AudioSegment* segment = new AudioSegment();
|
2018-01-16 20:26:29 +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
|
|
|
aStream->AddAudioTrack(aTrackID,
|
|
|
|
aStream->GraphRate(),
|
|
|
|
0,
|
|
|
|
segment,
|
|
|
|
SourceMediaStream::ADDTRACK_QUEUED);
|
2015-02-19 20:04:26 +03:00
|
|
|
|
2017-12-18 18:19:33 +03:00
|
|
|
LOG(("Stream %p registered for microphone capture", aStream.get()));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-01 03:12:12 +04:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
class StartStopMessage : public ControlMessage
|
|
|
|
{
|
2018-10-17 16:05:59 +03:00
|
|
|
public:
|
|
|
|
enum StartStop
|
|
|
|
{
|
|
|
|
Start,
|
|
|
|
Stop
|
|
|
|
};
|
2018-10-03 15:58:28 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
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-17 16:05:59 +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
|
|
|
};
|
|
|
|
|
2017-12-18 18:19:33 +03:00
|
|
|
nsresult
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::Start(const RefPtr<const AllocationHandle>&)
|
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
|
|
|
|
2018-04-30 16:37:18 +03:00
|
|
|
CubebUtils::AudioDeviceID deviceID = mDeviceInfo->DeviceID();
|
2018-09-05 17:00:33 +03:00
|
|
|
if (mStream->GraphImpl()->InputDeviceID() &&
|
|
|
|
mStream->GraphImpl()->InputDeviceID() != deviceID) {
|
2018-04-30 16:37:18 +03:00
|
|
|
// For now, we only allow opening a single audio input device per document,
|
|
|
|
// because we can only have one MSG per document.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-09-25 13:04:44 +03:00
|
|
|
|
2018-03-01 00:45:40 +03:00
|
|
|
|
2018-11-06 12:59:15 +03:00
|
|
|
mInputProcessing = new AudioInputProcessing(
|
|
|
|
mDeviceMaxChannelCount, mStream, mTrackID, mPrincipal);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
2018-10-17 16:05:59 +03:00
|
|
|
[that, graph = std::move(gripGraph), deviceID]() mutable {
|
2018-10-03 15:58:28 +03:00
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(MakeUnique<StartStopMessage>(
|
|
|
|
that->mInputProcessing, StartStopMessage::Start));
|
|
|
|
}
|
2018-10-01 18:12:14 +03:00
|
|
|
|
2018-10-03 15:58:28 +03:00
|
|
|
that->mStream->OpenAudioInput(deviceID, that->mInputProcessing);
|
2017-12-18 18:19:33 +03:00
|
|
|
|
2018-10-03 15:58:28 +03:00
|
|
|
return NS_OK;
|
|
|
|
}));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::Stop(const RefPtr<const AllocationHandle>&)
|
2012-07-12 15:53:08 +04:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2013-01-10 20:52:53 +04:00
|
|
|
|
2018-10-17 16:05:51 +03:00
|
|
|
LOG(("Mic source %p Stop()", this));
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
MOZ_ASSERT(mStream, "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-10-31 17:22:23 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
|
|
|
|
RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom(
|
2018-10-17 16:05:59 +03:00
|
|
|
[that, graph = std::move(gripGraph), stream = mStream]() mutable {
|
2018-10-03 15:58:28 +03:00
|
|
|
if (graph) {
|
|
|
|
graph->AppendMessage(MakeUnique<StartStopMessage>(
|
|
|
|
that->mInputProcessing, StartStopMessage::Stop));
|
|
|
|
}
|
2018-10-01 18:12:14 +03:00
|
|
|
|
2018-10-03 15:58:28 +03:00
|
|
|
CubebUtils::AudioDeviceID deviceID = that->mDeviceInfo->DeviceID();
|
|
|
|
Maybe<CubebUtils::AudioDeviceID> id = Some(deviceID);
|
|
|
|
stream->CloseAudioInput(id, that->mInputProcessing);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2018-10-03 15:58:28 +03:00
|
|
|
return NS_OK;
|
|
|
|
}));
|
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
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCMicrophoneSource::GetSettings(
|
|
|
|
dom::MediaTrackSettings& aOutSettings) const
|
2018-02-26 11:41:20 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
aOutSettings = *mSettings;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
AudioInputProcessing::AudioInputProcessing(
|
|
|
|
uint32_t aMaxChannelCount,
|
|
|
|
RefPtr<SourceMediaStream> aStream,
|
|
|
|
TrackID aTrackID,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2018-09-07 17:53:23 +03:00
|
|
|
: mStream(std::move(aStream))
|
|
|
|
, mAudioProcessing(AudioProcessing::Create())
|
|
|
|
, mRequestedInputChannelCount(aMaxChannelCount)
|
|
|
|
, mSkipProcessing(false)
|
|
|
|
, mInputDownmixBuffer(MAX_SAMPLING_FREQ * MAX_CHANNELS / 100)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mLastCallbackAppendTime(0)
|
|
|
|
#endif
|
|
|
|
, mLiveFramesAppended(false)
|
|
|
|
, mLiveSilenceAppended(false)
|
|
|
|
, mTrackID(aTrackID)
|
|
|
|
, mPrincipal(aPrincipalHandle)
|
2018-10-01 18:12:14 +03:00
|
|
|
, mEnabled(false)
|
2018-10-12 16:57:49 +03:00
|
|
|
, mEnded(false)
|
2018-09-07 17:53:23 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioInputProcessing::Disconnect(MediaStreamGraphImpl* aGraph)
|
|
|
|
{
|
|
|
|
// This method is just for asserts.
|
|
|
|
MOZ_ASSERT(aGraph->CurrentDriver()->OnThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineWebRTCMicrophoneSource::Shutdown()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mState == kStarted) {
|
2018-10-17 16:05:51 +03:00
|
|
|
Stop(nullptr);
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mState == kStopped);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mState == kAllocated || mState == kStopped);
|
2018-10-17 16:05:51 +03:00
|
|
|
Deallocate(nullptr);
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mState == kReleased);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AudioInputProcessing::PassThrough(MediaStreamGraphImpl* aGraph) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aGraph->CurrentDriver()->OnThread());
|
|
|
|
return mSkipProcessing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioInputProcessing::SetPassThrough(bool aPassThrough)
|
|
|
|
{
|
|
|
|
mSkipProcessing = aPassThrough;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
AudioInputProcessing::GetRequestedInputChannelCount(
|
|
|
|
MediaStreamGraphImpl* aGraphImpl)
|
|
|
|
{
|
|
|
|
return mRequestedInputChannelCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioInputProcessing::SetRequestedInputChannelCount(
|
|
|
|
uint32_t aRequestedInputChannelCount)
|
|
|
|
{
|
|
|
|
mRequestedInputChannelCount = aRequestedInputChannelCount;
|
|
|
|
|
|
|
|
mStream->GraphImpl()->ReevaluateInputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
AudioInputProcessing::UpdateAECSettings(bool aEnable,
|
|
|
|
bool aUseAecMobile,
|
|
|
|
EchoCancellation::SuppressionLevel aLevel)
|
2018-09-07 17:53:23 +03:00
|
|
|
{
|
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));
|
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) {
|
|
|
|
|
|
|
|
MOZ_LOG(GetMediaManagerLog(),
|
|
|
|
LogLevel::Error,
|
|
|
|
("Attempt to set invalid AEC suppression level %d",
|
|
|
|
static_cast<int>(aLevel)));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
AudioInputProcessing::UpdateAGCSettings(bool aEnable,
|
|
|
|
GainControl::Mode aMode)
|
2018-09-07 17:53:23 +03:00
|
|
|
{
|
2018-02-20 23:23:09 +03:00
|
|
|
if (aMode != GainControl::Mode::kAdaptiveAnalog &&
|
|
|
|
aMode != GainControl::Mode::kAdaptiveDigital &&
|
|
|
|
aMode != GainControl::Mode::kFixedDigital) {
|
|
|
|
|
|
|
|
MOZ_LOG(GetMediaManagerLog(),
|
|
|
|
LogLevel::Error,
|
|
|
|
("Attempt to set invalid AGC mode %d", static_cast<int>(aMode)));
|
|
|
|
|
|
|
|
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) {
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_LOG(GetMediaManagerLog(),
|
|
|
|
LogLevel::Error,
|
|
|
|
("Invalid AGC mode kAgcAdaptiveAnalog on mobile"));
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-02-20 23:23:09 +03:00
|
|
|
AudioInputProcessing::UpdateNSSettings(bool aEnable,
|
|
|
|
webrtc::NoiseSuppression::Level aLevel)
|
2018-09-07 17:53:23 +03:00
|
|
|
{
|
2018-02-20 23:23:09 +03:00
|
|
|
if (aLevel != NoiseSuppression::Level::kLow &&
|
|
|
|
aLevel != NoiseSuppression::Level::kModerate &&
|
|
|
|
aLevel != NoiseSuppression::Level::kHigh &&
|
|
|
|
aLevel != NoiseSuppression::Level::kVeryHigh) {
|
|
|
|
|
|
|
|
MOZ_LOG(GetMediaManagerLog(),
|
|
|
|
LogLevel::Error,
|
|
|
|
("Attempt to set invalid noise suppression level %d",
|
|
|
|
static_cast<int>(aLevel)));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioInputProcessing::Start()
|
|
|
|
{
|
|
|
|
mEnabled = true;
|
|
|
|
}
|
|
|
|
|
2012-10-17 13:46:40 +04:00
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::Stop()
|
|
|
|
{
|
|
|
|
mEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-10-17 16:05:51 +03:00
|
|
|
AudioInputProcessing::Pull(const RefPtr<SourceMediaStream>& aStream,
|
2018-09-07 17:53:23 +03:00
|
|
|
TrackID aTrackID,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2012-10-17 13:46:40 +04:00
|
|
|
{
|
2018-10-17 16:05:59 +03:00
|
|
|
TRACE_AUDIO_CALLBACK_COMMENT(
|
|
|
|
"SourceMediaStream %p track %i", aStream.get(), aTrackID);
|
2018-03-01 00:45:40 +03:00
|
|
|
StreamTime delta;
|
|
|
|
|
2018-10-12 16:57:49 +03:00
|
|
|
if (mEnded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
delta = aDesiredTime - aStream->GetEndOfAppendedData(aTrackID);
|
2018-03-01 00:45:40 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
if (delta < 0) {
|
|
|
|
LOG_FRAMES(
|
|
|
|
("Not appending silence; %" PRId64 " frames already buffered", -delta));
|
|
|
|
return;
|
|
|
|
}
|
2018-08-02 13:25:05 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
if (!mLiveFramesAppended || !mLiveSilenceAppended) {
|
2018-09-07 17:53:23 +03:00
|
|
|
// These are the iterations after starting or resuming audio capture.
|
|
|
|
// Make sure there's at least one extra block buffered until audio
|
|
|
|
// callbacks come in. We also allow appending silence one time after
|
|
|
|
// audio callbacks have started, to cover the case where audio callbacks
|
|
|
|
// start appending data immediately and there is no extra data buffered.
|
|
|
|
delta += 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.
|
|
|
|
// If there were live frames appended and we haven't appended the
|
|
|
|
// right amount of silence, we'll have to append silence once more,
|
|
|
|
// failing the other assert below.
|
|
|
|
MOZ_ASSERT_IF(!PassThrough(aStream->GraphImpl()) && !mPacketizerInput,
|
|
|
|
!mLiveFramesAppended);
|
|
|
|
|
|
|
|
if (!PassThrough(aStream->GraphImpl()) && 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.
|
|
|
|
delta += mPacketizerInput->PacketSize();
|
2018-03-01 00:45:40 +03:00
|
|
|
}
|
2018-09-07 17:53:23 +03:00
|
|
|
}
|
2017-11-22 16:30:00 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
LOG_FRAMES(("Pulling %" PRId64 " frames of silence.", delta));
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
// This assertion fails when we append silence here in the same iteration
|
|
|
|
// as there were real audio samples already appended by the audio callback.
|
|
|
|
// Note that this is exempted until live samples and a subsequent chunk of
|
|
|
|
// silence have been appended to the track. This will cover cases like:
|
|
|
|
// - After Start(), there is silence (maybe multiple times) appended before
|
|
|
|
// the first audio callback.
|
|
|
|
// - After Start(), there is real data (maybe multiple times) appended
|
|
|
|
// before the first graph iteration.
|
|
|
|
// And other combinations of order of audio sample sources.
|
2018-10-17 16:05:59 +03:00
|
|
|
MOZ_ASSERT_IF(mEnabled && mLiveFramesAppended && mLiveSilenceAppended,
|
|
|
|
aStream->GraphImpl()->IterationEnd() > mLastCallbackAppendTime);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
|
|
|
if (mLiveFramesAppended) {
|
|
|
|
mLiveSilenceAppended = true;
|
2018-03-01 00:45:40 +03:00
|
|
|
}
|
2017-12-21 21:01:17 +03:00
|
|
|
|
|
|
|
AudioSegment audio;
|
|
|
|
audio.AppendNullData(delta);
|
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
|
|
|
aStream->AppendToTrack(aTrackID, &audio);
|
2012-10-17 13:46:40 +04:00
|
|
|
}
|
|
|
|
|
2016-01-21 19:51:36 +03:00
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::NotifyOutputData(MediaStreamGraphImpl* aGraph,
|
|
|
|
AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames,
|
|
|
|
TrackRate aRate,
|
|
|
|
uint32_t aChannels)
|
2016-01-21 19:51:36 +03:00
|
|
|
{
|
2018-05-31 17:44:00 +03:00
|
|
|
MOZ_ASSERT(aGraph->CurrentDriver()->OnThread());
|
2018-10-01 18:12:14 +03:00
|
|
|
MOZ_ASSERT(mEnabled);
|
2018-09-07 17:53:23 +03:00
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
if (!mPacketizerOutput || mPacketizerOutput->PacketSize() != aRate / 100u ||
|
2018-01-05 20:10:23 +03:00
|
|
|
mPacketizerOutput->Channels() != aChannels) {
|
|
|
|
// It's ok to drop the audio still in the packetizer here: if this changes,
|
|
|
|
// we changed devices or something.
|
|
|
|
mPacketizerOutput =
|
2018-10-17 16:05:59 +03:00
|
|
|
new 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()) {
|
2018-10-17 16:05:59 +03:00
|
|
|
uint32_t samplesPerPacket =
|
|
|
|
mPacketizerOutput->PacketSize() * mPacketizerOutput->Channels();
|
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) {
|
2018-10-17 16:05:59 +03:00
|
|
|
AudioConverter converter(
|
|
|
|
AudioConfig(aChannels, 0, AudioConfig::FORMAT_FLT),
|
|
|
|
AudioConfig(MAX_CHANNELS, 0, AudioConfig::FORMAT_FLT));
|
2018-01-05 20:10:23 +03:00
|
|
|
framesPerPacketFarend = mPacketizerOutput->PacketSize();
|
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 =
|
2018-10-17 16:05:59 +03:00
|
|
|
converter.Process(mInputDownmixBuffer, packet, framesPerPacketFarend);
|
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
|
|
|
interleavedFarend = mInputDownmixBuffer.Data();
|
|
|
|
channelCountFarend = MAX_CHANNELS;
|
|
|
|
deinterleavedPacketDataChannelPointers.SetLength(MAX_CHANNELS);
|
|
|
|
} else {
|
2018-01-05 20:10:23 +03:00
|
|
|
interleavedFarend = packet;
|
|
|
|
channelCountFarend = aChannels;
|
|
|
|
framesPerPacketFarend = mPacketizerOutput->PacketSize();
|
|
|
|
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;
|
2018-10-17 16:05:59 +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.
|
2018-10-17 16:05:59 +03:00
|
|
|
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.
|
2018-10-17 16:05:59 +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
|
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::PacketizeAndProcess(MediaStreamGraphImpl* aGraph,
|
|
|
|
const AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames,
|
|
|
|
TrackRate aRate,
|
|
|
|
uint32_t aChannels)
|
2018-01-05 20:10:23 +03:00
|
|
|
{
|
2018-10-17 16:05:59 +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;
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
if (!mPacketizerInput || mPacketizerInput->PacketSize() != aRate / 100u ||
|
2018-01-05 20:10:23 +03:00
|
|
|
mPacketizerInput->Channels() != aChannels) {
|
|
|
|
// It's ok to drop the audio still in the packetizer here.
|
|
|
|
mPacketizerInput =
|
2018-10-17 16:05:59 +03:00
|
|
|
new AudioPacketizer<AudioDataValue, float>(aRate / 100, aChannels);
|
2018-01-05 20:10:23 +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
|
|
|
// 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()) {
|
2018-10-17 16:05:59 +03:00
|
|
|
uint32_t samplesPerPacket =
|
|
|
|
mPacketizerInput->PacketSize() * mPacketizerInput->Channels();
|
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
|
|
|
|
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
|
|
|
// Deinterleave the input data
|
|
|
|
// Prepare an array pointing to deinterleaved channels.
|
|
|
|
AutoTArray<float*, 8> deinterleavedPacketizedInputDataChannelPointers;
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers.SetLength(aChannels);
|
|
|
|
offset = 0;
|
2018-10-17 16:05:59 +03:00
|
|
|
for (size_t i = 0;
|
|
|
|
i < deinterleavedPacketizedInputDataChannelPointers.Length();
|
|
|
|
++i) {
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers[i] =
|
|
|
|
mDeinterleavedBuffer.Data() + offset;
|
2018-01-05 19:19:22 +03:00
|
|
|
offset += mPacketizerInput->PacketSize();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Deinterleave to mInputBuffer, pointed to by inputBufferChannelPointers.
|
2018-10-17 16:05:59 +03:00
|
|
|
Deinterleave(packet,
|
|
|
|
mPacketizerInput->PacketSize(),
|
|
|
|
aChannels,
|
|
|
|
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
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
StreamConfig inputConfig(
|
|
|
|
aRate, aChannels, false /* we don't use typing detection*/);
|
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;
|
|
|
|
|
|
|
|
// Bug 1404965: Get the right delay here, it saves some work down the line.
|
|
|
|
mAudioProcessing->set_stream_delay_ms(0);
|
|
|
|
|
|
|
|
// Bug 1414837: find a way to not allocate here.
|
2018-10-17 16:05:59 +03:00
|
|
|
RefPtr<SharedBuffer> buffer = SharedBuffer::Create(
|
|
|
|
mPacketizerInput->PacketSize() * aChannels * sizeof(float));
|
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;
|
|
|
|
processedOutputChannelPointers.SetLength(aChannels);
|
|
|
|
processedOutputChannelPointersConst.SetLength(aChannels);
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
for (size_t i = 0; i < processedOutputChannelPointers.Length(); ++i) {
|
2018-10-17 16:05:59 +03:00
|
|
|
processedOutputChannelPointers[i] =
|
|
|
|
static_cast<float*>(buffer->Data()) + offset;
|
|
|
|
processedOutputChannelPointersConst[i] =
|
|
|
|
static_cast<float*>(buffer->Data()) + offset;
|
2018-01-05 19:19:22 +03:00
|
|
|
offset += mPacketizerInput->PacketSize();
|
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-10-17 16:05:59 +03:00
|
|
|
mAudioProcessing->ProcessStream(
|
|
|
|
deinterleavedPacketizedInputDataChannelPointers.Elements(),
|
|
|
|
inputConfig,
|
|
|
|
outputConfig,
|
|
|
|
processedOutputChannelPointers.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
|
|
|
|
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
|
|
|
AudioSegment segment;
|
2018-09-05 17:00:33 +03:00
|
|
|
if (!mStream->GraphImpl()) {
|
|
|
|
// The DOMMediaStream that owns mStream has been cleaned up
|
2018-08-29 20:00:28 +03:00
|
|
|
// and MediaStream::DestroyImpl() has run in the MSG. This is fine and
|
|
|
|
// can happen before the MediaManager thread gets to stop capture for
|
2018-09-05 17:00:33 +03:00
|
|
|
// this MediaStream.
|
2018-08-29 20:00:28 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-14 18:46:46 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
LOG_FRAMES(("Appending %" PRIu32 " frames of packetized audio",
|
|
|
|
mPacketizerInput->PacketSize()));
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-03-01 00:45:40 +03:00
|
|
|
#ifdef DEBUG
|
2018-09-05 17:00:33 +03:00
|
|
|
mLastCallbackAppendTime = mStream->GraphImpl()->IterationEnd();
|
2018-03-01 00:45:40 +03:00
|
|
|
#endif
|
2018-09-05 17:00:33 +03:00
|
|
|
mLiveFramesAppended = true;
|
2018-08-29 20:00:28 +03:00
|
|
|
|
|
|
|
// We already have planar audio data of the right format. Insert into the
|
|
|
|
// MSG.
|
|
|
|
MOZ_ASSERT(processedOutputChannelPointers.Length() == aChannels);
|
|
|
|
RefPtr<SharedBuffer> other = buffer;
|
|
|
|
segment.AppendFrames(other.forget(),
|
|
|
|
processedOutputChannelPointersConst,
|
|
|
|
mPacketizerInput->PacketSize(),
|
2018-09-05 17:00:33 +03:00
|
|
|
mPrincipal);
|
|
|
|
mStream->AppendToTrack(mTrackID, &segment);
|
2016-01-21 19:51:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 16:24:19 +03:00
|
|
|
template<typename T>
|
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::InsertInGraph(const T* aBuffer,
|
|
|
|
size_t aFrames,
|
|
|
|
uint32_t aChannels)
|
2016-05-30 16:24:19 +03:00
|
|
|
{
|
2018-09-05 17:00:33 +03:00
|
|
|
if (!mStream->GraphImpl()) {
|
|
|
|
// The DOMMediaStream that owns mStream has been cleaned up
|
2018-08-29 20:00:28 +03:00
|
|
|
// and MediaStream::DestroyImpl() has run in the MSG. This is fine and
|
|
|
|
// can happen before the MediaManager thread gets to stop capture for
|
2018-09-05 17:00:33 +03:00
|
|
|
// this MediaStream.
|
2018-08-29 20:00:28 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-03-14 18:46:46 +03:00
|
|
|
|
2017-11-22 16:30:00 +03:00
|
|
|
#ifdef DEBUG
|
2018-09-05 17:00:33 +03:00
|
|
|
mLastCallbackAppendTime = mStream->GraphImpl()->IterationEnd();
|
2017-11-22 16:30:00 +03:00
|
|
|
#endif
|
2018-09-05 17:00:33 +03:00
|
|
|
mLiveFramesAppended = true;
|
2018-08-29 20:00:28 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(aChannels >= 1 && aChannels <= 8, "Support up to 8 channels");
|
|
|
|
|
|
|
|
AudioSegment segment;
|
|
|
|
RefPtr<SharedBuffer> buffer =
|
|
|
|
SharedBuffer::Create(aFrames * aChannels * sizeof(T));
|
|
|
|
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);
|
2018-10-17 16:05:59 +03:00
|
|
|
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;
|
2018-10-17 16:05:59 +03:00
|
|
|
for (uint32_t i = 0; i < aChannels; ++i) {
|
2018-08-29 20:00:28 +03:00
|
|
|
channels[i] = write_channels[i] = samples + offset;
|
|
|
|
offset += aFrames;
|
2017-06-02 09:12:08 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
DeinterleaveAndConvertBuffer(
|
|
|
|
aBuffer, aFrames, aChannels, write_channels.Elements());
|
2018-08-29 20:00:28 +03:00
|
|
|
}
|
2018-03-01 00:46:33 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
LOG_FRAMES(("Appending %zu frames of raw audio", aFrames));
|
2016-05-30 16:24:19 +03:00
|
|
|
|
2018-08-29 20:00:28 +03:00
|
|
|
MOZ_ASSERT(aChannels == channels.Length());
|
2018-10-17 16:05:59 +03:00
|
|
|
segment.AppendFrames(buffer.forget(), channels, aFrames, mPrincipal);
|
2018-08-29 20:00:28 +03:00
|
|
|
|
2018-09-05 17:00:33 +03:00
|
|
|
mStream->AppendToTrack(mTrackID, &segment);
|
2016-05-30 16:24:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called back on GraphDriver thread!
|
|
|
|
// Note this can be called back after ::Shutdown()
|
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::NotifyInputData(MediaStreamGraphImpl* aGraph,
|
|
|
|
const AudioDataValue* aBuffer,
|
|
|
|
size_t aFrames,
|
|
|
|
TrackRate aRate,
|
|
|
|
uint32_t aChannels)
|
2016-05-30 16:24:19 +03:00
|
|
|
{
|
2018-05-31 17:44:00 +03:00
|
|
|
MOZ_ASSERT(aGraph->CurrentDriver()->OnThread());
|
2018-04-12 18:51:35 +03:00
|
|
|
TRACE_AUDIO_CALLBACK();
|
2018-04-30 16:37:18 +03:00
|
|
|
|
2018-09-07 17:53:23 +03:00
|
|
|
MOZ_ASSERT(mEnabled);
|
|
|
|
|
2016-05-30 16:24:19 +03:00
|
|
|
// If some processing is necessary, packetize and insert in the WebRTC.org
|
2018-09-07 17:53:23 +03:00
|
|
|
// code. Otherwise, directly insert the mic data in the MSG, bypassing all
|
|
|
|
// processing.
|
2018-04-30 16:37:18 +03:00
|
|
|
if (PassThrough(aGraph)) {
|
2016-05-30 16:24:19 +03:00
|
|
|
InsertInGraph<AudioDataValue>(aBuffer, aFrames, aChannels);
|
|
|
|
} else {
|
|
|
|
PacketizeAndProcess(aGraph, aBuffer, aFrames, aRate, aChannels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:05:59 +03:00
|
|
|
#define ResetProcessingIfNeeded(_processing) \
|
|
|
|
do { \
|
|
|
|
bool enabled = mAudioProcessing->_processing()->is_enabled(); \
|
|
|
|
\
|
|
|
|
if (enabled) { \
|
|
|
|
int rv = mAudioProcessing->_processing()->Enable(!enabled); \
|
|
|
|
if (rv) { \
|
|
|
|
NS_WARNING("Could not reset the status of the " #_processing \
|
|
|
|
" on device change."); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
rv = mAudioProcessing->_processing()->Enable(enabled); \
|
|
|
|
if (rv) { \
|
|
|
|
NS_WARNING("Could not reset the status of the " #_processing \
|
|
|
|
" on device change."); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2016-04-22 17:24:17 +03:00
|
|
|
|
|
|
|
void
|
2018-09-07 17:53:23 +03:00
|
|
|
AudioInputProcessing::DeviceChanged(MediaStreamGraphImpl* aGraph)
|
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-05-31 17:44:00 +03:00
|
|
|
MOZ_ASSERT(aGraph->CurrentDriver()->OnThread());
|
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
|
|
|
}
|
|
|
|
|
2018-10-12 16:57:49 +03:00
|
|
|
void
|
|
|
|
AudioInputProcessing::End()
|
|
|
|
{
|
|
|
|
mEnded = true;
|
|
|
|
}
|
|
|
|
|
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
|
2015-07-24 15:28:16 +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
|
|
|
return NS_LITERAL_STRING(u"AudioCapture");
|
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
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
|
|
|
nsID uuid;
|
|
|
|
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_LITERAL_CSTRING("");
|
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
|
|
|
}
|
|
|
|
|
2017-12-18 18:19:33 +03:00
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCAudioCaptureSource::SetTrack(
|
|
|
|
const RefPtr<const AllocationHandle>&,
|
|
|
|
const RefPtr<SourceMediaStream>& aStream,
|
|
|
|
TrackID aTrackID,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2017-12-18 18:19:33 +03:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
// Nothing to do here. aStream is a placeholder dummy and not exposed.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
nsresult
|
2018-10-17 16:05:59 +03:00
|
|
|
MediaEngineWebRTCAudioCaptureSource::Start(
|
|
|
|
const RefPtr<const AllocationHandle>&)
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-07-24 15:28:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-10-17 16:05:51 +03:00
|
|
|
MediaEngineWebRTCAudioCaptureSource::Stop(const RefPtr<const AllocationHandle>&)
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-07-24 15:28:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
nsresult
|
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
|
|
|
MediaEngineWebRTCAudioCaptureSource::Reconfigure(
|
2018-10-17 16:05:59 +03:00
|
|
|
const RefPtr<AllocationHandle>&,
|
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const nsString& aDeviceId,
|
|
|
|
const char** aOutBadConstraint)
|
2015-09-21 01:45:57 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
uint32_t
|
|
|
|
MediaEngineWebRTCAudioCaptureSource::GetBestFitnessDistance(
|
2018-10-17 16:05:59 +03:00
|
|
|
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
|
|
|
|
const nsString& aDeviceId) const
|
2015-07-24 15:28:16 +03:00
|
|
|
{
|
|
|
|
// There is only one way of capturing audio for now, and it's always adequate.
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-21 19:51:36 +03:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|