2012-06-03 11:35:15 +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/. */
|
|
|
|
|
2014-10-01 03:17:53 +04:00
|
|
|
#ifndef MOZILLA_MEDIAMANAGER_H
|
|
|
|
#define MOZILLA_MEDIAMANAGER_H
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#include "MediaEngine.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 "MediaEnginePrefs.h"
|
2016-08-22 13:16:28 +03:00
|
|
|
#include "mozilla/media/DeviceChangeCallback.h"
|
2017-05-12 06:32:14 +03:00
|
|
|
#include "mozilla/dom/GetUserMediaRequest.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
#include "mozilla/Services.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2012-12-22 12:09:36 +04:00
|
|
|
#include "nsIMediaManager.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsClassHashtable.h"
|
2012-10-06 04:20:47 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2014-04-14 23:04:27 +04:00
|
|
|
#include "nsIObserver.h"
|
2013-03-05 01:02:17 +04:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
|
|
|
|
#include "nsIDOMNavigatorUserMedia.h"
|
2013-01-25 06:45:36 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-06-15 06:31:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-25 15:50:42 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-12-22 12:09:36 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2014-04-04 13:54:25 +04:00
|
|
|
#include "mozilla/dom/MediaStreamBinding.h"
|
2013-09-16 10:34:57 +04:00
|
|
|
#include "mozilla/dom/MediaStreamTrackBinding.h"
|
2014-10-27 22:42:56 +03:00
|
|
|
#include "mozilla/dom/MediaStreamError.h"
|
2018-07-28 07:40:26 +03:00
|
|
|
#include "mozilla/dom/NavigatorBinding.h"
|
2015-06-18 18:46:36 +03:00
|
|
|
#include "mozilla/media/MediaChild.h"
|
|
|
|
#include "mozilla/media/MediaParent.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2016-02-26 22:21:05 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-05-03 09:07:37 +04:00
|
|
|
#include "DOMMediaStream.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2013-01-29 20:55:09 +04:00
|
|
|
#ifdef MOZ_WEBRTC
|
|
|
|
#include "mtransport/runnable_utils.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-12 18:49:39 +04:00
|
|
|
// Note, these suck in Windows headers, unfortunately.
|
|
|
|
#include "base/thread.h"
|
|
|
|
#include "base/task.h"
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
namespace mozilla {
|
2013-09-16 10:34:57 +04:00
|
|
|
namespace dom {
|
2014-06-19 04:57:51 +04:00
|
|
|
struct MediaStreamConstraints;
|
2015-09-21 01:45:57 +03:00
|
|
|
struct MediaTrackConstraints;
|
2014-09-24 19:17:33 +04:00
|
|
|
struct MediaTrackConstraintSet;
|
2017-02-01 23:43:38 +03:00
|
|
|
enum class CallerType : uint32_t;
|
2018-07-16 12:29:12 +03:00
|
|
|
enum class MediaDeviceKind : uint8_t;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2017-01-28 20:29:13 +03:00
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
class AllocationHandle;
|
2017-05-03 14:14:18 +03:00
|
|
|
class GetUserMediaTask;
|
2017-04-26 12:13:40 +03:00
|
|
|
class GetUserMediaWindowListener;
|
|
|
|
class MediaManager;
|
|
|
|
class SourceListener;
|
2017-04-27 01:21: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
|
|
|
LogModule* GetMediaManagerLog();
|
|
|
|
|
2015-09-19 07:49:07 +03:00
|
|
|
class MediaDevice : public nsIMediaDevice {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEDIADEVICE
|
|
|
|
|
2018-10-12 11:48:22 +03:00
|
|
|
explicit MediaDevice(const RefPtr<MediaEngineSource>& aSource,
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
const nsString& aName, const nsString& aID,
|
2018-10-12 11:48:22 +03:00
|
|
|
const nsString& aRawID);
|
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-12 11:48:22 +03:00
|
|
|
explicit MediaDevice(const RefPtr<AudioDeviceInfo>& aAudioDeviceInfo,
|
2018-07-16 12:29:12 +03:00
|
|
|
const nsString& aID,
|
|
|
|
const nsString& aRawID = NS_LITERAL_STRING(""));
|
|
|
|
|
2018-10-12 11:48:22 +03:00
|
|
|
explicit MediaDevice(const RefPtr<MediaDevice>& aOther, const nsString& aID,
|
2018-07-16 12:29:12 +03:00
|
|
|
const nsString& aRawID);
|
|
|
|
|
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
|
|
|
uint32_t GetBestFitnessDistance(
|
2016-08-19 23:39:54 +03:00
|
|
|
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
|
|
|
|
bool aIsChrome);
|
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 Allocate(const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
2017-01-28 20:29:13 +03:00
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
2016-06-16 02:25:07 +03:00
|
|
|
const char** aOutBadConstraint);
|
2017-12-18 18:19:33 +03:00
|
|
|
nsresult SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
|
|
|
|
const PrincipalHandle& aPrincipal);
|
|
|
|
nsresult Start();
|
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 Reconfigure(const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const char** aOutBadConstraint);
|
2018-05-08 22:55:36 +03:00
|
|
|
nsresult FocusOnSelectedSource();
|
2017-12-18 18:19:33 +03:00
|
|
|
nsresult Stop();
|
2016-06-30 22:43:24 +03:00
|
|
|
nsresult Deallocate();
|
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
|
|
|
|
|
|
|
void Pull(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
|
|
|
|
StreamTime aDesiredTime, const PrincipalHandle& aPrincipal);
|
|
|
|
|
|
|
|
void GetSettings(dom::MediaTrackSettings& aOutSettings) const;
|
|
|
|
|
|
|
|
dom::MediaSourceEnum GetMediaSource() const;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-09-19 07:49:07 +03:00
|
|
|
protected:
|
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
|
|
|
virtual ~MediaDevice() = default;
|
2016-06-30 22:43:24 +03:00
|
|
|
|
2015-09-19 07:49:07 +03:00
|
|
|
static uint32_t FitnessDistance(
|
|
|
|
nsString aN,
|
|
|
|
const dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters&
|
|
|
|
aConstraint);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-09-19 07:49:07 +03:00
|
|
|
private:
|
|
|
|
static bool StringsContain(const dom::OwningStringOrStringSequence& aStrings,
|
|
|
|
nsString aN);
|
|
|
|
static uint32_t FitnessDistance(
|
|
|
|
nsString aN, const dom::ConstrainDOMStringParameters& aParams);
|
|
|
|
|
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
|
|
|
// Assigned on allocation on media thread, then read on the media thread and
|
|
|
|
// graph thread
|
|
|
|
RefPtr<AllocationHandle> mAllocationHandle;
|
2015-09-19 07:49:07 +03:00
|
|
|
|
|
|
|
public:
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
const RefPtr<MediaEngineSource> mSource;
|
2018-10-12 11:48:22 +03:00
|
|
|
const RefPtr<AudioDeviceInfo> mSinkInfo;
|
2018-07-16 12:29:12 +03:00
|
|
|
const dom::MediaDeviceKind mKind;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
const bool mScary;
|
|
|
|
const nsString mType;
|
|
|
|
const nsString mName;
|
|
|
|
const nsString mID;
|
|
|
|
const nsString mRawID;
|
2015-09-19 07:49:07 +03:00
|
|
|
};
|
|
|
|
|
2017-04-26 12:13:40 +03:00
|
|
|
typedef nsRefPtrHashtable<nsUint64HashKey, GetUserMediaWindowListener>
|
|
|
|
WindowTable;
|
2018-10-12 11:44:23 +03:00
|
|
|
typedef MozPromise<RefPtr<AudioDeviceInfo>, nsresult, true> SinkInfoPromise;
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MediaManager final : public nsIMediaManagerService,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIObserver,
|
2016-08-11 20:04:49 +03:00
|
|
|
public DeviceChangeCallback {
|
2017-04-26 12:13:40 +03:00
|
|
|
friend SourceListener;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
public:
|
2012-12-22 12:09:36 +04:00
|
|
|
static already_AddRefed<MediaManager> GetInstance();
|
|
|
|
|
2013-02-14 23:59:27 +04:00
|
|
|
// NOTE: never Dispatch(....,NS_DISPATCH_SYNC) to the MediaManager
|
|
|
|
// thread from the MainThread, as we NS_DISPATCH_SYNC to MainThread
|
|
|
|
// from MediaManager thread.
|
2013-03-05 01:02:17 +04:00
|
|
|
static MediaManager* Get();
|
2015-03-20 01:43:25 +03:00
|
|
|
static MediaManager* GetIfExists();
|
2016-01-07 22:57:42 +03:00
|
|
|
static void StartupInit();
|
2016-04-28 03:06:05 +03:00
|
|
|
static void PostTask(already_AddRefed<Runnable> task);
|
2018-02-15 17:18:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts an async operation to the media manager thread.
|
|
|
|
* FunctionType must be a function that takes a `MozPromiseHolder&`.
|
|
|
|
*
|
|
|
|
* The returned promise is resolved or rejected by aFunction on the media
|
|
|
|
* manager thread.
|
|
|
|
*/
|
|
|
|
template <typename MozPromiseType, typename FunctionType>
|
|
|
|
static RefPtr<MozPromiseType> PostTask(const char* aName,
|
|
|
|
FunctionType&& aFunction);
|
|
|
|
|
2015-03-03 17:51:05 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
static bool IsInMediaThread();
|
|
|
|
#endif
|
2013-03-05 01:02:17 +04:00
|
|
|
|
2014-09-06 00:02:54 +04:00
|
|
|
static bool Exists() { return !!sSingleton; }
|
|
|
|
|
2017-11-14 13:50:07 +03:00
|
|
|
static nsresult NotifyRecordingStatusChange(nsPIDOMWindowInner* aWindow);
|
2013-11-26 10:22:16 +04:00
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-03 11:35:15 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2012-12-22 12:09:36 +04:00
|
|
|
NS_DECL_NSIMEDIAMANAGERSERVICE
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2015-06-18 18:46:36 +03:00
|
|
|
media::Parent<media::NonE10s>* GetNonE10sParent();
|
2013-11-06 07:32:42 +04:00
|
|
|
MediaEngine* GetBackend(uint64_t aWindowId = 0);
|
2017-04-26 12:13:40 +03:00
|
|
|
|
|
|
|
WindowTable* GetActiveWindows() {
|
2017-04-26 12:13:40 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-04-26 12:13:40 +03:00
|
|
|
return &mActiveWindows;
|
2017-04-26 12:13:40 +03:00
|
|
|
}
|
2017-04-26 12:13:40 +03:00
|
|
|
GetUserMediaWindowListener* GetWindowListener(uint64_t aWindowId) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mActiveWindows.GetWeak(aWindowId);
|
|
|
|
}
|
|
|
|
void AddWindowID(uint64_t aWindowId, GetUserMediaWindowListener* aListener);
|
2014-08-22 14:21:48 +04:00
|
|
|
void RemoveWindowID(uint64_t aWindowId);
|
2017-05-12 06:32:14 +03:00
|
|
|
void SendPendingGUMRequest();
|
2012-11-14 01:55:02 +04:00
|
|
|
bool IsWindowStillActive(uint64_t aWindowId) {
|
2017-04-26 12:13:40 +03:00
|
|
|
return !!GetWindowListener(aWindowId);
|
2012-10-26 04:14:47 +04:00
|
|
|
}
|
2018-03-19 11:40:38 +03:00
|
|
|
bool IsWindowListenerStillActive(GetUserMediaWindowListener* aListener);
|
2013-01-07 06:31:32 +04:00
|
|
|
// Note: also calls aListener->Remove(), even if inactive
|
|
|
|
void RemoveFromWindowList(uint64_t aWindowID,
|
2017-04-26 12:13:40 +03:00
|
|
|
GetUserMediaWindowListener* aListener);
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2018-07-28 07:40:26 +03:00
|
|
|
typedef dom::CallbackObjectHolder<dom::NavigatorUserMediaSuccessCallback,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback>
|
|
|
|
GetUserMediaSuccessCallback;
|
|
|
|
typedef dom::CallbackObjectHolder<dom::NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback>
|
|
|
|
GetUserMediaErrorCallback;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult GetUserMedia(nsPIDOMWindowInner* aWindow,
|
2014-10-01 03:17:53 +04:00
|
|
|
const dom::MediaStreamConstraints& aConstraints,
|
2018-07-28 07:40:26 +03:00
|
|
|
GetUserMediaSuccessCallback&& onSuccess,
|
|
|
|
GetUserMediaErrorCallback&& onError,
|
2017-02-01 23:43:38 +03:00
|
|
|
dom::CallerType aCallerType);
|
2013-09-16 10:34:57 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult GetUserMediaDevices(
|
|
|
|
nsPIDOMWindowInner* aWindow,
|
2015-06-18 18:46:36 +03:00
|
|
|
const dom::MediaStreamConstraints& aConstraints,
|
2018-07-28 07:40:29 +03:00
|
|
|
dom::MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
|
2016-01-08 01:30:10 +03:00
|
|
|
uint64_t aInnerWindowID = 0, const nsAString& aCallID = nsString());
|
2015-03-03 17:51:05 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult EnumerateDevices(nsPIDOMWindowInner* aWindow,
|
2015-03-03 17:51:05 +03:00
|
|
|
nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
|
2017-09-18 04:52:06 +03:00
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnFailure,
|
|
|
|
dom::CallerType aCallerType);
|
2015-03-03 17:51:05 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult EnumerateDevices(nsPIDOMWindowInner* aWindow,
|
|
|
|
dom::Promise& aPromise);
|
2018-10-12 11:44:23 +03:00
|
|
|
|
|
|
|
// Get the sink that corresponds to the given device id.
|
|
|
|
// It is resposible to check if an application is
|
|
|
|
// authorized to play audio through the requested device.
|
|
|
|
// The returned promise will be resolved with the device
|
|
|
|
// information if the device id matches one and operation is
|
|
|
|
// allowed. The default device is always allowed. Non default
|
|
|
|
// devices are allowed only in secure context. It is pending to
|
|
|
|
// implement an user authorization model. The promise will be
|
|
|
|
// rejected in the following cases:
|
|
|
|
// NS_ERROR_NOT_AVAILABLE: Device id does not exist.
|
|
|
|
// NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR:
|
|
|
|
// The requested device exists but it is not allowed to be used.
|
|
|
|
// Currently, this happens only on non-default default devices
|
|
|
|
// and non https connections. TODO, authorization model to allow
|
|
|
|
// an application to play audio through the device (Bug 1493982).
|
|
|
|
// NS_ERROR_ABORT: General error.
|
|
|
|
RefPtr<SinkInfoPromise> GetSinkDevice(nsPIDOMWindowInner* aWindow,
|
|
|
|
const nsString& aDeviceId);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void OnNavigation(uint64_t aWindowID);
|
2015-07-10 06:07:42 +03:00
|
|
|
bool IsActivelyCapturingOrHasAPermission(uint64_t aWindowId);
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2013-03-05 01:02:17 +04:00
|
|
|
MediaEnginePrefs mPrefs;
|
|
|
|
|
2018-07-16 12:30:46 +03:00
|
|
|
typedef nsTArray<RefPtr<MediaDevice>> MediaDeviceSet;
|
2018-09-25 20:03:50 +03:00
|
|
|
typedef media::Refcountable<UniquePtr<MediaDeviceSet>> MediaDeviceSetRefCnt;
|
2016-08-11 20:04:49 +03:00
|
|
|
|
|
|
|
virtual int AddDeviceChangeCallback(DeviceChangeCallback* aCallback) override;
|
|
|
|
virtual void OnDeviceChange() override;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-07-03 01:01:52 +03:00
|
|
|
private:
|
|
|
|
static nsresult GenerateUUID(nsAString& aResult);
|
2015-06-18 18:46:36 +03:00
|
|
|
static nsresult AnonymizeId(nsAString& aId, const nsACString& aOriginKey);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-06-18 18:46:36 +03:00
|
|
|
public: // TODO: make private once we upgrade to GCC 4.8+ on linux.
|
2018-07-16 12:30:46 +03:00
|
|
|
static void AnonymizeDevices(MediaDeviceSet& aDevices,
|
|
|
|
const nsACString& aOriginKey);
|
|
|
|
static already_AddRefed<nsIWritableVariant> ToJSArray(
|
|
|
|
MediaDeviceSet& aDevices);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-06-18 18:46:36 +03:00
|
|
|
private:
|
2018-03-16 22:09:26 +03:00
|
|
|
enum class DeviceEnumerationType : uint8_t {
|
2018-02-13 00:55:45 +03:00
|
|
|
Normal, // Enumeration should not return loopback or fake devices
|
|
|
|
Fake, // Enumeration should return fake device(s)
|
|
|
|
Loopback /* Enumeration should return loopback device(s) (possibly in
|
|
|
|
addition to normal devices) */
|
|
|
|
};
|
2018-09-25 20:03:50 +03:00
|
|
|
|
|
|
|
typedef MozPromise<RefPtr<MediaDeviceSetRefCnt>,
|
|
|
|
RefPtr<dom::MediaStreamError>, true>
|
|
|
|
MediaDeviceSetPromise;
|
|
|
|
typedef MozPromise<const char*, nsresult, false> BadConstraintsPromise;
|
|
|
|
|
|
|
|
RefPtr<MediaDeviceSetPromise> EnumerateRawDevices(
|
2018-07-16 12:30:46 +03:00
|
|
|
uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType,
|
|
|
|
dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType,
|
|
|
|
DeviceEnumerationType aVideoInputEnumType = DeviceEnumerationType::Normal,
|
|
|
|
DeviceEnumerationType aAudioInputEnumType =
|
|
|
|
DeviceEnumerationType::Normal);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-25 20:03:50 +03:00
|
|
|
RefPtr<MediaDeviceSetPromise> EnumerateDevicesImpl(
|
2018-07-16 12:30:46 +03:00
|
|
|
uint64_t aWindowId, dom::MediaSourceEnum aVideoInputType,
|
|
|
|
dom::MediaSourceEnum aAudioInputType, MediaSinkEnum aAudioOutputType,
|
|
|
|
DeviceEnumerationType aVideoInputEnumType,
|
|
|
|
DeviceEnumerationType aAudioInputEnumType);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-09-25 20:03:50 +03:00
|
|
|
RefPtr<BadConstraintsPromise> SelectSettings(
|
2015-10-04 03:42:26 +03:00
|
|
|
dom::MediaStreamConstraints& aConstraints, bool aIsChrome,
|
2018-09-25 20:03:50 +03:00
|
|
|
const RefPtr<MediaDeviceSetRefCnt>& aSources);
|
2015-06-18 18:46:36 +03:00
|
|
|
|
2013-03-05 01:02:17 +04:00
|
|
|
void GetPref(nsIPrefBranch* aBranch, const char* aPref, const char* aData,
|
|
|
|
int32_t* aVal);
|
2013-12-06 23:34:40 +04:00
|
|
|
void GetPrefBool(nsIPrefBranch* aBranch, const char* aPref, const char* aData,
|
|
|
|
bool* aVal);
|
2013-03-05 01:02:17 +04:00
|
|
|
void GetPrefs(nsIPrefBranch* aBranch, const char* aData);
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
// Make private because we want only one instance of this class
|
2013-03-05 01:02:17 +04:00
|
|
|
MediaManager();
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
~MediaManager() {}
|
2015-10-15 06:54:39 +03:00
|
|
|
void Shutdown();
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2014-08-22 13:27:16 +04:00
|
|
|
void StopScreensharing(uint64_t aWindowID);
|
2018-02-23 17:50:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls aCallback with a GetUserMediaWindowListener argument once for
|
|
|
|
* each window listener associated with aWindow and its child windows.
|
|
|
|
*/
|
|
|
|
template <typename FunctionType>
|
2016-01-30 20:05:36 +03:00
|
|
|
void IterateWindowListeners(nsPIDOMWindowInner* aWindow,
|
2018-02-23 17:50:57 +03:00
|
|
|
const FunctionType& aCallback);
|
2014-08-22 13:27:16 +04:00
|
|
|
|
2013-09-13 12:51:48 +04:00
|
|
|
void StopMediaStreams();
|
2016-08-11 20:04:49 +03:00
|
|
|
void RemoveMediaDevicesCallback(uint64_t aWindowID);
|
2013-09-13 12:51:48 +04:00
|
|
|
|
2012-10-26 04:14:47 +04:00
|
|
|
// ONLY access from MainThread so we don't need to lock
|
|
|
|
WindowTable mActiveWindows;
|
2016-04-28 03:06:05 +03:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, GetUserMediaTask> mActiveCallbacks;
|
2014-01-09 01:51:33 +04:00
|
|
|
nsClassHashtable<nsUint64HashKey, nsTArray<nsString>> mCallIds;
|
2017-05-12 06:32:14 +03:00
|
|
|
nsTArray<RefPtr<dom::GetUserMediaRequest>> mPendingGUMRequest;
|
2015-02-23 19:50:48 +03:00
|
|
|
|
2012-10-26 04:14:47 +04:00
|
|
|
// Always exists
|
2014-09-12 18:49:39 +04:00
|
|
|
nsAutoPtr<base::Thread> mMediaThread;
|
2015-10-15 06:54:39 +03:00
|
|
|
nsCOMPtr<nsIAsyncShutdownBlocker> mShutdownBlocker;
|
2012-10-26 04:14:47 +04:00
|
|
|
|
2015-11-18 23:03:13 +03:00
|
|
|
// ONLY accessed from MediaManagerThread
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaEngine> mBackend;
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2012-12-22 12:09:36 +04:00
|
|
|
static StaticRefPtr<MediaManager> sSingleton;
|
2013-05-02 16:00:12 +04:00
|
|
|
|
2017-07-27 11:51:24 +03:00
|
|
|
nsTArray<nsString> mDeviceIDs;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-06-18 18:46:36 +03:00
|
|
|
public:
|
2016-11-01 14:44:02 +03:00
|
|
|
RefPtr<media::Parent<media::NonE10s>> mNonE10sParent;
|
2012-06-03 11:35:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-10-01 03:17:53 +04:00
|
|
|
|
|
|
|
#endif // MOZILLA_MEDIAMANAGER_H
|