2012-07-12 04:53:08 -07: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/. */
|
|
|
|
|
|
|
|
#ifndef MEDIAENGINEWEBRTC_H_
|
|
|
|
#define MEDIAENGINEWEBRTC_H_
|
|
|
|
|
|
|
|
#include "prcvar.h"
|
|
|
|
#include "prthread.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
|
2012-10-18 11:03:00 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2013-03-13 08:42:18 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMFile.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-02-15 00:01:58 -08:00
|
|
|
#include "DOMMediaStream.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
#include "VideoUtils.h"
|
|
|
|
#include "MediaEngine.h"
|
|
|
|
#include "VideoSegment.h"
|
|
|
|
#include "AudioSegment.h"
|
|
|
|
#include "StreamBuffer.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
|
|
|
|
|
|
|
// WebRTC library includes follow
|
|
|
|
|
|
|
|
// Audio Engine
|
2012-10-04 09:09:35 -07:00
|
|
|
#include "voice_engine/include/voe_base.h"
|
|
|
|
#include "voice_engine/include/voe_codec.h"
|
|
|
|
#include "voice_engine/include/voe_hardware.h"
|
2012-11-15 14:58:40 -08:00
|
|
|
#include "voice_engine/include/voe_network.h"
|
2012-10-04 09:09:35 -07:00
|
|
|
#include "voice_engine/include/voe_audio_processing.h"
|
|
|
|
#include "voice_engine/include/voe_volume_control.h"
|
|
|
|
#include "voice_engine/include/voe_external_media.h"
|
2013-01-29 08:55:09 -08:00
|
|
|
#include "voice_engine/include/voe_audio_processing.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// Video Engine
|
|
|
|
#include "video_engine/include/vie_base.h"
|
|
|
|
#include "video_engine/include/vie_codec.h"
|
|
|
|
#include "video_engine/include/vie_render.h"
|
|
|
|
#include "video_engine/include/vie_capture.h"
|
|
|
|
#include "video_engine/include/vie_file.h"
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
#include "CameraPreviewMediaStream.h"
|
|
|
|
#include "DOMCameraManager.h"
|
|
|
|
#include "GonkCameraControl.h"
|
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2012-11-15 14:58:40 -08:00
|
|
|
#include "NullTransport.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
class CameraAllocateRunnable;
|
|
|
|
class GetCameraNameRunnable;
|
|
|
|
#endif
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
/**
|
|
|
|
* The WebRTC implementation of the MediaEngine interface.
|
2013-05-02 05:00:12 -07:00
|
|
|
*
|
|
|
|
* On B2G platform, member data may accessed from different thread after construction:
|
|
|
|
*
|
|
|
|
* MediaThread:
|
|
|
|
* mState, mImage, mWidth, mHeight, mCapability, mPrefs, mDeviceName, mUniqueId, mInitDone,
|
|
|
|
* mSources, mImageContainer, mSources, mState, mImage, mLastCapture
|
|
|
|
*
|
|
|
|
* MainThread:
|
|
|
|
* mDOMCameraControl, mCaptureIndex, mCameraThread, mWindowId, mCameraManager,
|
|
|
|
* mNativeCameraControl, mPreviewStream, mState, mLastCapture, mWidth, mHeight
|
|
|
|
*
|
|
|
|
* Where mWidth, mHeight, mImage are protected by mMonitor
|
|
|
|
* mState, mLastCapture is protected by mCallbackMonitor
|
|
|
|
* Other variable is accessed only from single thread
|
2012-07-12 04:53:08 -07:00
|
|
|
*/
|
2013-05-02 05:00:12 -07:00
|
|
|
class MediaEngineWebRTCVideoSource : public MediaEngineVideoSource
|
|
|
|
, public nsRunnable
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
, public nsICameraGetCameraCallback
|
|
|
|
, public nsICameraPreviewStreamCallback
|
|
|
|
, public nsICameraTakePictureCallback
|
|
|
|
, public nsICameraReleaseCallback
|
|
|
|
, public nsICameraErrorCallback
|
|
|
|
, public CameraPreviewFrameCallback
|
|
|
|
#else
|
|
|
|
, public webrtc::ExternalRenderer
|
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
MediaEngineWebRTCVideoSource(nsDOMCameraManager* aCameraManager,
|
|
|
|
int aIndex, uint64_t aWindowId)
|
|
|
|
: mCameraManager(aCameraManager)
|
|
|
|
, mNativeCameraControl(nullptr)
|
|
|
|
, mPreviewStream(nullptr)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
, mCallbackMonitor("WebRTCCamera.CallbackMonitor")
|
|
|
|
, mCaptureIndex(aIndex)
|
|
|
|
, mMonitor("WebRTCCamera.Monitor")
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
|
|
|
, mInitDone(false)
|
|
|
|
, mInSnapshotMode(false)
|
|
|
|
, mSnapshotPath(nullptr)
|
|
|
|
{
|
|
|
|
mState = kReleased;
|
|
|
|
NS_NewNamedThread("CameraThread", getter_AddRefs(mCameraThread), nullptr);
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
#else
|
2012-07-12 04:53:08 -07:00
|
|
|
// ViEExternalRenderer.
|
|
|
|
virtual int FrameSizeChange(unsigned int, unsigned int, unsigned int);
|
|
|
|
virtual int DeliverFrame(unsigned char*, int, uint32_t, int64_t);
|
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
MediaEngineWebRTCVideoSource(webrtc::VideoEngine* aVideoEnginePtr, int aIndex)
|
2012-10-16 17:53:55 -07:00
|
|
|
: mVideoEngine(aVideoEnginePtr)
|
|
|
|
, mCaptureIndex(aIndex)
|
2013-03-04 13:02:17 -08:00
|
|
|
, mFps(-1)
|
|
|
|
, mMinFps(-1)
|
2012-10-16 17:53:55 -07:00
|
|
|
, mMonitor("WebRTCCamera.Monitor")
|
2013-05-02 05:00:12 -07:00
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2012-10-16 17:53:55 -07:00
|
|
|
, mInitDone(false)
|
|
|
|
, mInSnapshotMode(false)
|
|
|
|
, mSnapshotPath(NULL) {
|
2012-11-28 19:30:31 -08:00
|
|
|
MOZ_ASSERT(aVideoEnginePtr);
|
2012-10-16 17:53:55 -07:00
|
|
|
mState = kReleased;
|
|
|
|
Init();
|
|
|
|
}
|
2013-05-02 05:00:12 -07:00
|
|
|
#endif
|
|
|
|
|
2012-10-16 17:53:55 -07:00
|
|
|
~MediaEngineWebRTCVideoSource() { Shutdown(); }
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
2013-03-04 13:02:17 -08:00
|
|
|
virtual nsresult Allocate(const MediaEnginePrefs &aPrefs);
|
2012-07-12 04:53:08 -07:00
|
|
|
virtual nsresult Deallocate();
|
|
|
|
virtual nsresult Start(SourceMediaStream*, TrackID);
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual nsresult Stop(SourceMediaStream*, TrackID);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
|
2013-01-29 08:55:09 -08:00
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
|
|
|
bool aNoiseOn, uint32_t aNoise) { return NS_OK; };
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual void NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aId,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
TrackTicks &aLastEndTime);
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
NS_DECL_NSICAMERAGETCAMERACALLBACK
|
|
|
|
NS_DECL_NSICAMERAPREVIEWSTREAMCALLBACK
|
|
|
|
NS_DECL_NSICAMERATAKEPICTURECALLBACK
|
|
|
|
NS_DECL_NSICAMERARELEASECALLBACK
|
|
|
|
NS_DECL_NSICAMERAERRORCALLBACK
|
|
|
|
|
|
|
|
void AllocImpl();
|
|
|
|
void DeallocImpl();
|
|
|
|
void StartImpl(webrtc::CaptureCapability aCapability);
|
|
|
|
void StopImpl();
|
|
|
|
void SnapshotImpl();
|
|
|
|
|
|
|
|
virtual void OnNewFrame(const gfxIntSize& aIntrinsicSize, layers::Image* aImage);
|
|
|
|
|
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// This runnable is for creating a temporary file on the main thread.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> tmp;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
tmp->Append(NS_LITERAL_STRING("webrtc_snapshot.jpeg"));
|
|
|
|
rv = tmp->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mSnapshotPath = new nsString();
|
|
|
|
rv = tmp->GetPath(*mSnapshotPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-10-04 09:09:35 -07:00
|
|
|
static const unsigned int KMaxDeviceNameLength = 128;
|
|
|
|
static const unsigned int KMaxUniqueIdLength = 256;
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// Initialize the needed Video engine interfaces.
|
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Engine variables.
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
// MediaEngine hold this DOM object, and the MediaEngine is hold by Navigator
|
|
|
|
// Their life time is always much longer than this object. Use a raw-pointer
|
|
|
|
// here should be safe.
|
|
|
|
// We need raw pointer here since such DOM-object should not addref/release on
|
|
|
|
// any thread other than main thread, but we must use this object for now. To
|
|
|
|
// avoid any bad thing do to addref/release DOM-object on other thread, we use
|
|
|
|
// raw-pointer for now.
|
|
|
|
nsDOMCameraManager* mCameraManager;
|
|
|
|
nsRefPtr<nsDOMCameraControl> mDOMCameraControl;
|
|
|
|
nsRefPtr<nsGonkCameraControl> mNativeCameraControl;
|
|
|
|
nsRefPtr<DOMCameraPreview> mPreviewStream;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling
|
|
|
|
nsRefPtr<nsIThread> mCameraThread;
|
|
|
|
nsRefPtr<nsIDOMFile> mLastCapture;
|
|
|
|
#else
|
2012-07-12 04:53:08 -07:00
|
|
|
webrtc::VideoEngine* mVideoEngine; // Weak reference, don't free.
|
|
|
|
webrtc::ViEBase* mViEBase;
|
|
|
|
webrtc::ViECapture* mViECapture;
|
|
|
|
webrtc::ViERender* mViERender;
|
2013-05-02 05:00:12 -07:00
|
|
|
#endif
|
2012-10-04 09:09:35 -07:00
|
|
|
webrtc::CaptureCapability mCapability; // Doesn't work on OS X.
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2012-10-04 09:09:35 -07:00
|
|
|
int mCaptureIndex;
|
2013-03-04 13:02:17 -08:00
|
|
|
int mFps; // Track rate (30 fps by default)
|
|
|
|
int mMinFps; // Min rate we want to accept
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2013-01-10 08:52:53 -08:00
|
|
|
// mMonitor protects mImage access/changes, and transitions of mState
|
|
|
|
// from kStarted to kStopped (which are combined with EndTrack() and
|
|
|
|
// image changes). Note that mSources is not accessed from other threads
|
|
|
|
// for video and is not protected.
|
2013-03-13 08:42:18 -07:00
|
|
|
Monitor mMonitor; // Monitor for processing WebRTC frames.
|
2013-05-02 05:00:12 -07:00
|
|
|
int mWidth, mHeight;
|
|
|
|
nsRefPtr<layers::Image> mImage;
|
|
|
|
nsRefPtr<layers::ImageContainer> mImageContainer;
|
|
|
|
|
2012-12-31 15:12:12 -08:00
|
|
|
nsTArray<SourceMediaStream *> mSources; // When this goes empty, we shut down HW
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
bool mInitDone;
|
|
|
|
bool mInSnapshotMode;
|
|
|
|
nsString* mSnapshotPath;
|
|
|
|
|
2012-10-04 09:09:35 -07:00
|
|
|
// These are in UTF-8 but webrtc api uses char arrays
|
|
|
|
char mDeviceName[KMaxDeviceNameLength];
|
|
|
|
char mUniqueId[KMaxUniqueIdLength];
|
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
void ChooseCapability(const MediaEnginePrefs &aPrefs);
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class MediaEngineWebRTCAudioSource : public MediaEngineAudioSource,
|
|
|
|
public webrtc::VoEMediaProcess
|
|
|
|
{
|
|
|
|
public:
|
2012-11-28 19:30:31 -08:00
|
|
|
MediaEngineWebRTCAudioSource(webrtc::VoiceEngine* aVoiceEnginePtr, int aIndex,
|
2012-10-04 09:09:35 -07:00
|
|
|
const char* name, const char* uuid)
|
2012-11-28 19:30:31 -08:00
|
|
|
: mVoiceEngine(aVoiceEnginePtr)
|
2012-07-12 04:53:08 -07:00
|
|
|
, mMonitor("WebRTCMic.Monitor")
|
|
|
|
, mCapIndex(aIndex)
|
|
|
|
, mChannel(-1)
|
2012-11-15 14:58:40 -08:00
|
|
|
, mInitDone(false)
|
2013-01-29 08:55:09 -08:00
|
|
|
, mEchoOn(false), mAgcOn(false), mNoiseOn(false)
|
|
|
|
, mEchoCancel(webrtc::kEcDefault)
|
|
|
|
, mAGC(webrtc::kAgcDefault)
|
|
|
|
, mNoiseSuppress(webrtc::kNsDefault)
|
2012-11-15 14:58:40 -08:00
|
|
|
, mNullTransport(nullptr) {
|
2012-11-28 19:30:31 -08:00
|
|
|
MOZ_ASSERT(aVoiceEnginePtr);
|
2012-10-16 17:53:55 -07:00
|
|
|
mState = kReleased;
|
2012-10-04 09:09:35 -07:00
|
|
|
mDeviceName.Assign(NS_ConvertUTF8toUTF16(name));
|
|
|
|
mDeviceUUID.Assign(NS_ConvertUTF8toUTF16(uuid));
|
2012-10-16 17:53:55 -07:00
|
|
|
Init();
|
2012-07-12 04:53:08 -07:00
|
|
|
}
|
|
|
|
~MediaEngineWebRTCAudioSource() { Shutdown(); }
|
|
|
|
|
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
virtual nsresult Allocate(const MediaEnginePrefs &aPrefs);
|
2012-07-12 04:53:08 -07:00
|
|
|
virtual nsresult Deallocate();
|
|
|
|
virtual nsresult Start(SourceMediaStream*, TrackID);
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual nsresult Stop(SourceMediaStream*, TrackID);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile);
|
2013-01-29 08:55:09 -08:00
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
|
|
|
bool aNoiseOn, uint32_t aNoise);
|
|
|
|
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual void NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aId,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
TrackTicks &aLastEndTime);
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// VoEMediaProcess.
|
|
|
|
void Process(const int channel, const webrtc::ProcessingTypes type,
|
|
|
|
WebRtc_Word16 audio10ms[], const int length,
|
|
|
|
const int samplingFreq, const bool isStereo);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
private:
|
2012-10-04 09:09:35 -07:00
|
|
|
static const unsigned int KMaxDeviceNameLength = 128;
|
|
|
|
static const unsigned int KMaxUniqueIdLength = 256;
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
webrtc::VoiceEngine* mVoiceEngine;
|
|
|
|
webrtc::VoEBase* mVoEBase;
|
|
|
|
webrtc::VoEExternalMedia* mVoERender;
|
2012-11-15 14:58:40 -08:00
|
|
|
webrtc::VoENetwork* mVoENetwork;
|
2013-01-29 08:55:09 -08:00
|
|
|
webrtc::VoEAudioProcessing *mVoEProcessing;
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2013-01-10 08:52:53 -08:00
|
|
|
// mMonitor protects mSources[] access/changes, and transitions of mState
|
|
|
|
// from kStarted to kStopped (which are combined with EndTrack()).
|
|
|
|
// mSources[] is accessed from webrtc threads.
|
2013-03-13 08:42:18 -07:00
|
|
|
Monitor mMonitor;
|
2012-12-31 15:12:12 -08:00
|
|
|
nsTArray<SourceMediaStream *> mSources; // When this goes empty, we shut down HW
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
int mCapIndex;
|
|
|
|
int mChannel;
|
|
|
|
TrackID mTrackID;
|
|
|
|
bool mInitDone;
|
|
|
|
|
|
|
|
nsString mDeviceName;
|
|
|
|
nsString mDeviceUUID;
|
|
|
|
|
2013-01-29 08:55:09 -08:00
|
|
|
bool mEchoOn, mAgcOn, mNoiseOn;
|
|
|
|
webrtc::EcModes mEchoCancel;
|
|
|
|
webrtc::AgcModes mAGC;
|
|
|
|
webrtc::NsModes mNoiseSuppress;
|
|
|
|
|
2012-11-15 14:58:40 -08:00
|
|
|
NullTransport *mNullTransport;
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class MediaEngineWebRTC : public MediaEngine
|
|
|
|
{
|
|
|
|
public:
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
MediaEngineWebRTC(nsDOMCameraManager* aCameraManager, uint64_t aWindowId)
|
|
|
|
: mMutex("mozilla::MediaEngineWebRTC")
|
|
|
|
, mVideoEngine(nullptr)
|
|
|
|
, mVoiceEngine(nullptr)
|
|
|
|
, mVideoEngineInit(false)
|
|
|
|
, mAudioEngineInit(false)
|
|
|
|
, mCameraManager(aCameraManager)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{
|
|
|
|
mVideoSources.Init();
|
|
|
|
mAudioSources.Init();
|
|
|
|
}
|
|
|
|
#else
|
2012-07-12 04:53:08 -07:00
|
|
|
MediaEngineWebRTC()
|
2013-05-02 05:00:12 -07:00
|
|
|
: mMutex("mozilla::MediaEngineWebRTC")
|
|
|
|
, mVideoEngine(nullptr)
|
|
|
|
, mVoiceEngine(nullptr)
|
|
|
|
, mVideoEngineInit(false)
|
|
|
|
, mAudioEngineInit(false)
|
2012-10-18 11:03:00 -07:00
|
|
|
{
|
2012-10-16 17:53:55 -07:00
|
|
|
mVideoSources.Init();
|
|
|
|
mAudioSources.Init();
|
|
|
|
}
|
2013-05-02 05:00:12 -07:00
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
~MediaEngineWebRTC() { Shutdown(); }
|
|
|
|
|
|
|
|
// Clients should ensure to clean-up sources video/audio sources
|
|
|
|
// before invoking Shutdown on this class.
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
|
|
|
|
virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
|
|
|
|
|
|
|
private:
|
2012-10-18 11:03:00 -07:00
|
|
|
Mutex mMutex;
|
|
|
|
// protected with mMutex:
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
webrtc::VideoEngine* mVideoEngine;
|
|
|
|
webrtc::VoiceEngine* mVoiceEngine;
|
|
|
|
|
|
|
|
// Need this to avoid unneccesary WebRTC calls while enumerating.
|
|
|
|
bool mVideoEngineInit;
|
|
|
|
bool mAudioEngineInit;
|
2012-10-16 17:53:55 -07:00
|
|
|
|
|
|
|
// Store devices we've already seen in a hashtable for quick return.
|
|
|
|
// Maps UUID to MediaEngineSource (one set for audio, one for video).
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineWebRTCVideoSource > mVideoSources;
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineWebRTCAudioSource > mAudioSources;
|
2013-05-02 05:00:12 -07:00
|
|
|
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2013-05-02 05:00:12 -07:00
|
|
|
// MediaEngine hold this DOM object, and the MediaEngine is hold by Navigator
|
|
|
|
// Their life time is always much longer than this object. Use a raw-pointer
|
|
|
|
// here should be safe.
|
|
|
|
// We need raw pointer here since such DOM-object should not addref/release on
|
|
|
|
// any thread other than main thread, but we must use this object for now. To
|
|
|
|
// avoid any bad thing do to addref/release DOM-object on other thread, we use
|
|
|
|
// raw-pointer for now.
|
|
|
|
nsDOMCameraManager* mCameraManager;
|
|
|
|
uint64_t mWindowId;
|
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NSMEDIAENGINEWEBRTC_H_ */
|