mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
0fd9123eac
This patch was generated by a script. Here's the source of the script for future reference: function convert() { echo "Converting $1 to $2..." find . ! -wholename "*nsprpub*" \ ! -wholename "*security/nss*" \ ! -wholename "*/.hg*" \ ! -wholename "obj-ff-dbg*" \ ! -name nsXPCOMCID.h \ ! -name prtypes.h \ -type f \ \( -iname "*.cpp" \ -o -iname "*.h" \ -o -iname "*.c" \ -o -iname "*.cc" \ -o -iname "*.idl" \ -o -iname "*.ipdl" \ -o -iname "*.ipdlh" \ -o -iname "*.mm" \) | \ xargs -n 1 sed -i -e "s/\b$1\b/$2/g" } convert PRInt8 int8_t convert PRUint8 uint8_t convert PRInt16 int16_t convert PRUint16 uint16_t convert PRInt32 int32_t convert PRUint32 uint32_t convert PRInt64 int64_t convert PRUint64 uint64_t convert PRIntn int convert PRUintn unsigned convert PRSize size_t convert PROffset32 int32_t convert PROffset64 int64_t convert PRPtrdiff ptrdiff_t convert PRFloat64 double
164 lines
4.3 KiB
C++
164 lines
4.3 KiB
C++
/* 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/. */
|
|
|
|
#include "MediaEngine.h"
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
#include "nsGlobalWindow.h"
|
|
#include "nsClassHashtable.h"
|
|
#include "nsObserverService.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
#include "nsIDOMNavigatorUserMedia.h"
|
|
#include "mozilla/Attributes.h"
|
|
|
|
namespace mozilla {
|
|
|
|
class GetUserMediaNotificationEvent: public nsRunnable
|
|
{
|
|
public:
|
|
enum GetUserMediaStatus {
|
|
STARTING,
|
|
STOPPING
|
|
};
|
|
GetUserMediaNotificationEvent(GetUserMediaStatus aStatus)
|
|
: mStatus(aStatus) {}
|
|
|
|
NS_IMETHOD
|
|
Run()
|
|
{
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
if (!obs) {
|
|
NS_WARNING("Could not get the Observer service for GetUserMedia recording notification.");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
if (mStatus) {
|
|
obs->NotifyObservers(nullptr,
|
|
"recording-device-events",
|
|
NS_LITERAL_STRING("starting").get());
|
|
} else {
|
|
obs->NotifyObservers(nullptr,
|
|
"recording-device-events",
|
|
NS_LITERAL_STRING("shutdown").get());
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
protected:
|
|
GetUserMediaStatus mStatus;
|
|
};
|
|
|
|
/**
|
|
* This class is an implementation of MediaStreamListener. This is used
|
|
* to Start() and Stop() the underlying MediaEngineSource when MediaStreams
|
|
* are assigned and deassigned in content.
|
|
*/
|
|
class GetUserMediaCallbackMediaStreamListener : public MediaStreamListener
|
|
{
|
|
public:
|
|
GetUserMediaCallbackMediaStreamListener(MediaEngineSource* aSource,
|
|
nsDOMMediaStream* aStream, TrackID aListenId)
|
|
: mSource(aSource)
|
|
, mStream(aStream)
|
|
, mID(aListenId)
|
|
, mValid(true) {}
|
|
|
|
void
|
|
Invalidate()
|
|
{
|
|
if (!mValid) {
|
|
return;
|
|
}
|
|
|
|
mValid = false;
|
|
mSource->Stop();
|
|
mSource->Deallocate();
|
|
|
|
nsCOMPtr<GetUserMediaNotificationEvent> event =
|
|
new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STOPPING);
|
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
}
|
|
|
|
void
|
|
NotifyConsumptionChanged(MediaStreamGraph* aGraph, Consumption aConsuming)
|
|
{
|
|
if (aConsuming == CONSUMED) {
|
|
SourceMediaStream* stream = mStream->GetStream()->AsSourceStream();
|
|
mSource->Start(stream, mID);
|
|
nsCOMPtr<GetUserMediaNotificationEvent> event =
|
|
new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STARTING);
|
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
return;
|
|
}
|
|
|
|
// NOT_CONSUMED
|
|
Invalidate();
|
|
return;
|
|
}
|
|
|
|
void NotifyBlockingChanged(MediaStreamGraph* aGraph, Blocking aBlocked) {}
|
|
void NotifyOutput(MediaStreamGraph* aGraph) {}
|
|
void NotifyFinished(MediaStreamGraph* aGraph) {}
|
|
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
|
|
TrackRate aTrackRate, TrackTicks aTrackOffset,
|
|
uint32_t aTrackEvents, const MediaSegment& aQueuedMedia) {}
|
|
|
|
private:
|
|
nsRefPtr<MediaEngineSource> mSource;
|
|
nsCOMPtr<nsDOMMediaStream> mStream;
|
|
TrackID mID;
|
|
bool mValid;
|
|
};
|
|
|
|
typedef nsTArray<nsRefPtr<GetUserMediaCallbackMediaStreamListener> > StreamListeners;
|
|
typedef nsClassHashtable<nsUint64HashKey, StreamListeners> WindowTable;
|
|
|
|
class MediaManager MOZ_FINAL : public nsIObserver {
|
|
public:
|
|
static MediaManager* Get() {
|
|
if (!sSingleton) {
|
|
sSingleton = new MediaManager();
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
obs->AddObserver(sSingleton, "xpcom-shutdown", false);
|
|
}
|
|
return sSingleton;
|
|
}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
MediaEngine* GetBackend();
|
|
WindowTable* GetActiveWindows();
|
|
|
|
nsresult GetUserMedia(nsPIDOMWindow* aWindow, nsIMediaStreamOptions* aParams,
|
|
nsIDOMGetUserMediaSuccessCallback* onSuccess,
|
|
nsIDOMGetUserMediaErrorCallback* onError);
|
|
void OnNavigation(uint64_t aWindowID);
|
|
|
|
private:
|
|
// Make private because we want only one instance of this class
|
|
MediaManager()
|
|
: mBackend(nullptr)
|
|
, mMediaThread(nullptr) {
|
|
mActiveWindows.Init();
|
|
};
|
|
MediaManager(MediaManager const&) {};
|
|
|
|
~MediaManager() {
|
|
delete mBackend;
|
|
};
|
|
|
|
MediaEngine* mBackend;
|
|
nsCOMPtr<nsIThread> mMediaThread;
|
|
WindowTable mActiveWindows;
|
|
|
|
static nsRefPtr<MediaManager> sSingleton;
|
|
};
|
|
|
|
} // namespace mozilla
|