зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1320994 - Refactor MediaManager's window management. r=jib
This in large does the following: * Changes the model in MediaManager to align with that of chrome code, namely: - One GetUserMediaWindowListener *per window*, containing N SourceListeners for N gUM requests, and - GetUserMediaWindowListener replaces GetUserMediaStreamListener - So if two SourceListeners stop we can still send only one event * Breaks a special event specific to B2G chrome MozReview-Commit-ID: 3wbPFmc9yWj --HG-- extra : rebase_source : 4ad324f6bb1be637da584f323a3e039c5b4f664d
This commit is contained in:
Родитель
f246a81c6d
Коммит
edff555cf5
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -55,9 +55,10 @@ namespace ipc {
|
|||
class PrincipalInfo;
|
||||
}
|
||||
|
||||
class MediaManager;
|
||||
class GetUserMediaCallbackMediaStreamListener;
|
||||
class GetUserMediaTask;
|
||||
class GetUserMediaWindowListener;
|
||||
class MediaManager;
|
||||
class SourceListener;
|
||||
|
||||
extern LogModule* GetMediaManagerLog();
|
||||
#define MM_LOG(msg) MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Debug, msg)
|
||||
|
@ -136,34 +137,29 @@ class GetUserMediaNotificationEvent: public Runnable
|
|||
enum GetUserMediaStatus {
|
||||
STARTING,
|
||||
STOPPING,
|
||||
STOPPED_TRACK,
|
||||
};
|
||||
GetUserMediaNotificationEvent(GetUserMediaCallbackMediaStreamListener* aListener,
|
||||
GetUserMediaStatus aStatus,
|
||||
bool aIsAudio, bool aIsVideo, uint64_t aWindowID);
|
||||
GetUserMediaNotificationEvent(GetUserMediaStatus aStatus,
|
||||
uint64_t aWindowID);
|
||||
|
||||
GetUserMediaNotificationEvent(GetUserMediaStatus aStatus,
|
||||
already_AddRefed<DOMMediaStream> aStream,
|
||||
OnTracksAvailableCallback* aOnTracksAvailableCallback,
|
||||
bool aIsAudio, bool aIsVideo, uint64_t aWindowID,
|
||||
already_AddRefed<media::Refcountable<UniquePtr<OnTracksAvailableCallback>>> aOnTracksAvailableCallback,
|
||||
uint64_t aWindowID,
|
||||
already_AddRefed<nsIDOMGetUserMediaErrorCallback> aError);
|
||||
virtual ~GetUserMediaNotificationEvent();
|
||||
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
protected:
|
||||
RefPtr<GetUserMediaCallbackMediaStreamListener> mListener; // threadsafe
|
||||
RefPtr<GetUserMediaWindowListener> mListener; // threadsafe
|
||||
RefPtr<DOMMediaStream> mStream;
|
||||
nsAutoPtr<OnTracksAvailableCallback> mOnTracksAvailableCallback;
|
||||
RefPtr<media::Refcountable<UniquePtr<OnTracksAvailableCallback>>> mOnTracksAvailableCallback;
|
||||
GetUserMediaStatus mStatus;
|
||||
bool mIsAudio;
|
||||
bool mIsVideo;
|
||||
uint64_t mWindowID;
|
||||
RefPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
MEDIA_START,
|
||||
MEDIA_STOP,
|
||||
MEDIA_STOP_TRACK,
|
||||
MEDIA_DIRECT_LISTENERS,
|
||||
|
@ -172,30 +168,30 @@ typedef enum {
|
|||
class ReleaseMediaOperationResource : public Runnable
|
||||
{
|
||||
public:
|
||||
ReleaseMediaOperationResource(already_AddRefed<DOMMediaStream> aStream,
|
||||
OnTracksAvailableCallback* aOnTracksAvailableCallback):
|
||||
ReleaseMediaOperationResource(
|
||||
already_AddRefed<DOMMediaStream> aStream,
|
||||
already_AddRefed<media::Refcountable<UniquePtr<OnTracksAvailableCallback>>> aOnTracksAvailableCallback):
|
||||
mStream(aStream),
|
||||
mOnTracksAvailableCallback(aOnTracksAvailableCallback) {}
|
||||
NS_IMETHOD Run() override {return NS_OK;}
|
||||
private:
|
||||
RefPtr<DOMMediaStream> mStream;
|
||||
nsAutoPtr<OnTracksAvailableCallback> mOnTracksAvailableCallback;
|
||||
RefPtr<media::Refcountable<UniquePtr<OnTracksAvailableCallback>>> mOnTracksAvailableCallback;
|
||||
};
|
||||
|
||||
typedef nsTArray<RefPtr<GetUserMediaCallbackMediaStreamListener> > StreamListeners;
|
||||
typedef nsClassHashtable<nsUint64HashKey, StreamListeners> WindowTable;
|
||||
typedef nsRefPtrHashtable<nsUint64HashKey, GetUserMediaWindowListener> WindowTable;
|
||||
|
||||
// we could add MediaManager if needed
|
||||
typedef void (*WindowListenerCallback)(MediaManager *aThis,
|
||||
uint64_t aWindowID,
|
||||
StreamListeners *aListeners,
|
||||
GetUserMediaWindowListener *aListener,
|
||||
void *aData);
|
||||
|
||||
class MediaManager final : public nsIMediaManagerService,
|
||||
public nsIObserver
|
||||
,public DeviceChangeCallback
|
||||
{
|
||||
friend GetUserMediaCallbackMediaStreamListener;
|
||||
friend SourceListener;
|
||||
public:
|
||||
static already_AddRefed<MediaManager> GetInstance();
|
||||
|
||||
|
@ -216,9 +212,7 @@ public:
|
|||
}
|
||||
|
||||
static nsresult NotifyRecordingStatusChange(nsPIDOMWindowInner* aWindow,
|
||||
const nsString& aMsg,
|
||||
const bool& aIsAudio,
|
||||
const bool& aIsVideo);
|
||||
const nsString& aMsg);
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
@ -226,17 +220,23 @@ public:
|
|||
|
||||
media::Parent<media::NonE10s>* GetNonE10sParent();
|
||||
MediaEngine* GetBackend(uint64_t aWindowId = 0);
|
||||
StreamListeners *GetWindowListeners(uint64_t aWindowId) {
|
||||
|
||||
WindowTable *GetActiveWindows() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return mActiveWindows.Get(aWindowId);
|
||||
return &mActiveWindows;
|
||||
}
|
||||
GetUserMediaWindowListener *GetWindowListener(uint64_t aWindowId) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return mActiveWindows.GetWeak(aWindowId);
|
||||
}
|
||||
void AddWindowID(uint64_t aWindowId, GetUserMediaWindowListener *aListener);
|
||||
void RemoveWindowID(uint64_t aWindowId);
|
||||
bool IsWindowStillActive(uint64_t aWindowId) {
|
||||
return !!GetWindowListeners(aWindowId);
|
||||
return !!GetWindowListener(aWindowId);
|
||||
}
|
||||
// Note: also calls aListener->Remove(), even if inactive
|
||||
void RemoveFromWindowList(uint64_t aWindowID,
|
||||
GetUserMediaCallbackMediaStreamListener *aListener);
|
||||
GetUserMediaWindowListener *aListener);
|
||||
|
||||
nsresult GetUserMedia(
|
||||
nsPIDOMWindowInner* aWindow,
|
||||
|
@ -293,12 +293,6 @@ private:
|
|||
bool aIsChrome,
|
||||
RefPtr<media::Refcountable<UniquePtr<SourceSet>>>& aSources);
|
||||
|
||||
StreamListeners* AddWindowID(uint64_t aWindowId);
|
||||
WindowTable *GetActiveWindows() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return &mActiveWindows;
|
||||
}
|
||||
|
||||
void GetPref(nsIPrefBranch *aBranch, const char *aPref,
|
||||
const char *aData, int32_t *aVal);
|
||||
void GetPrefBool(nsIPrefBranch *aBranch, const char *aPref,
|
||||
|
|
Загрузка…
Ссылка в новой задаче