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"
|
|
|
|
|
2014-03-08 21:18:50 -08:00
|
|
|
#include "MediaEngineWrapper.h"
|
2014-07-07 00:46:00 -07:00
|
|
|
#include "mozilla/dom/MediaStreamTrackBinding.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
// WebRTC library includes follow
|
2014-07-07 00:46:00 -07:00
|
|
|
#include "webrtc/common.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
// Audio Engine
|
2013-08-29 23:08:57 -07:00
|
|
|
#include "webrtc/voice_engine/include/voe_base.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_codec.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_hardware.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_network.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_audio_processing.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_volume_control.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_external_media.h"
|
|
|
|
#include "webrtc/voice_engine/include/voe_audio_processing.h"
|
2014-04-02 10:58:20 -07:00
|
|
|
#include "webrtc/voice_engine/include/voe_call_report.h"
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// Video Engine
|
2014-05-29 14:05:14 -07:00
|
|
|
// conflicts with #include of scoped_ptr.h
|
|
|
|
#undef FF
|
2013-08-29 23:08:57 -07:00
|
|
|
#include "webrtc/video_engine/include/vie_base.h"
|
|
|
|
#include "webrtc/video_engine/include/vie_codec.h"
|
|
|
|
#include "webrtc/video_engine/include/vie_render.h"
|
|
|
|
#include "webrtc/video_engine/include/vie_capture.h"
|
2013-05-04 08:00:35 -07:00
|
|
|
#ifdef MOZ_B2G_CAMERA
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "CameraControlListener.h"
|
|
|
|
#include "ICameraControl.h"
|
2013-05-02 05:00:12 -07:00
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "prprf.h"
|
2014-02-24 23:22:36 -08:00
|
|
|
#include "mozilla/Hal.h"
|
2013-05-02 05:00:12 -07:00
|
|
|
#endif
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2012-11-15 14:58:40 -08:00
|
|
|
#include "NullTransport.h"
|
2014-04-02 10:58:19 -07:00
|
|
|
#include "AudioOutputObserver.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,
|
2014-03-19 10:30:27 -07:00
|
|
|
* mImageContainer, mSources, mState, mImage
|
2013-05-02 05:00:12 -07:00
|
|
|
*
|
|
|
|
* MainThread:
|
2014-03-19 10:30:27 -07:00
|
|
|
* mCaptureIndex, mLastCapture, mState, mWidth, mHeight,
|
2013-05-02 05:00:12 -07:00
|
|
|
*
|
|
|
|
* Where mWidth, mHeight, mImage are protected by mMonitor
|
2014-03-19 10:30:27 -07:00
|
|
|
* mState is protected by mCallbackMonitor
|
2013-05-02 05:00:12 -07:00
|
|
|
* 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
|
2014-02-14 14:41:07 -08:00
|
|
|
, public CameraControlListener
|
2014-02-24 23:22:36 -08:00
|
|
|
, public mozilla::hal::ScreenConfigurationObserver
|
2013-05-02 05:00:12 -07:00
|
|
|
#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
|
2014-07-07 00:46:00 -07:00
|
|
|
MediaEngineWebRTCVideoSource(int aIndex,
|
2014-07-17 19:23:00 -07:00
|
|
|
MediaSourceType aMediaSource = MediaSourceType::Camera)
|
2014-02-14 14:41:07 -08:00
|
|
|
: mCameraControl(nullptr)
|
2013-05-02 05:00:12 -07:00
|
|
|
, mCallbackMonitor("WebRTCCamera.CallbackMonitor")
|
2014-02-24 23:22:36 -08:00
|
|
|
, mRotation(0)
|
|
|
|
, mBackCamera(false)
|
2013-05-02 05:00:12 -07:00
|
|
|
, mCaptureIndex(aIndex)
|
2014-07-07 00:46:00 -07:00
|
|
|
, mMediaSource(aMediaSource)
|
2013-05-02 05:00:12 -07:00
|
|
|
, mMonitor("WebRTCCamera.Monitor")
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2014-07-13 22:48:02 -07:00
|
|
|
, mHasDirectListeners(false)
|
2013-05-02 05:00:12 -07:00
|
|
|
, mInitDone(false)
|
|
|
|
, mInSnapshotMode(false)
|
|
|
|
, mSnapshotPath(nullptr)
|
|
|
|
{
|
|
|
|
mState = kReleased;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
#else
|
2012-07-12 04:53:08 -07:00
|
|
|
// ViEExternalRenderer.
|
|
|
|
virtual int FrameSizeChange(unsigned int, unsigned int, unsigned int);
|
2013-11-07 17:07:47 -08:00
|
|
|
virtual int DeliverFrame(unsigned char*,int, uint32_t , int64_t,
|
|
|
|
void *handle);
|
|
|
|
/**
|
|
|
|
* Does DeliverFrame() support a null buffer and non-null handle
|
|
|
|
* (video texture)?
|
|
|
|
* XXX Investigate! Especially for Android/B2G
|
|
|
|
*/
|
|
|
|
virtual bool IsTextureSupported() { return false; }
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2014-07-07 00:46:00 -07:00
|
|
|
MediaEngineWebRTCVideoSource(webrtc::VideoEngine* aVideoEnginePtr, int aIndex,
|
2014-07-17 19:23:00 -07:00
|
|
|
MediaSourceType aMediaSource = MediaSourceType::Camera)
|
2012-10-16 17:53:55 -07:00
|
|
|
: mVideoEngine(aVideoEnginePtr)
|
|
|
|
, mCaptureIndex(aIndex)
|
2013-03-04 13:02:17 -08:00
|
|
|
, mFps(-1)
|
|
|
|
, mMinFps(-1)
|
2014-07-07 00:46:00 -07:00
|
|
|
, mMediaSource(aMediaSource)
|
2012-10-16 17:53:55 -07:00
|
|
|
, mMonitor("WebRTCCamera.Monitor")
|
2013-05-02 05:00:12 -07:00
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
2014-07-13 22:48:02 -07:00
|
|
|
, mHasDirectListeners(false)
|
2012-10-16 17:53:55 -07:00
|
|
|
, mInitDone(false)
|
|
|
|
, mInSnapshotMode(false)
|
2013-10-23 13:34:10 -07:00
|
|
|
, mSnapshotPath(nullptr) {
|
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-07-12 04:53:08 -07:00
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
2014-04-18 12:15:10 -07:00
|
|
|
virtual nsresult Allocate(const VideoTrackConstraintsN &aConstraints,
|
|
|
|
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);
|
2014-07-13 22:48:02 -07:00
|
|
|
virtual void SetDirectListeners(bool aHasListeners);
|
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,
|
2014-04-02 10:58:19 -07:00
|
|
|
bool aNoiseOn, uint32_t aNoise,
|
|
|
|
int32_t aPlayoutDelay) { 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
|
|
|
|
2013-07-04 22:53:10 -07:00
|
|
|
virtual bool IsFake() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-17 19:23:00 -07:00
|
|
|
virtual const MediaSourceType GetMediaSource() {
|
2014-07-07 00:46:00 -07:00
|
|
|
return mMediaSource;
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:18:50 -08:00
|
|
|
#ifndef MOZ_B2G_CAMERA
|
2013-07-18 19:21:19 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2014-02-19 20:18:50 -08:00
|
|
|
#else
|
|
|
|
// We are subclassed from CameraControlListener, which implements a
|
|
|
|
// threadsafe reference-count for us.
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnHardwareStateChange(HardwareState aState);
|
2014-05-15 16:17:40 -07:00
|
|
|
void GetRotation();
|
2014-02-14 14:41:07 -08:00
|
|
|
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
2014-04-25 13:28:15 -07:00
|
|
|
void OnUserError(UserContext aContext, nsresult aError);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
|
2013-05-02 05:00:12 -07:00
|
|
|
|
|
|
|
void AllocImpl();
|
|
|
|
void DeallocImpl();
|
|
|
|
void StartImpl(webrtc::CaptureCapability aCapability);
|
|
|
|
void StopImpl();
|
|
|
|
void SnapshotImpl();
|
2014-02-24 23:22:36 -08:00
|
|
|
void RotateImage(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
|
|
|
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration);
|
2013-05-02 05:00:12 -07:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2014-06-24 09:36:43 -07:00
|
|
|
protected:
|
|
|
|
~MediaEngineWebRTCVideoSource() { Shutdown(); }
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
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
|
|
|
mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling
|
2014-05-15 16:17:40 -07:00
|
|
|
// This is only modified on MainThread (AllocImpl and DeallocImpl)
|
|
|
|
nsRefPtr<ICameraControl> mCameraControl;
|
2014-06-26 09:47:44 -07:00
|
|
|
nsCOMPtr<nsIDOMFile> mLastCapture;
|
2014-05-15 16:17:40 -07:00
|
|
|
|
|
|
|
// These are protected by mMonitor below
|
2014-02-24 23:22:36 -08:00
|
|
|
int mRotation;
|
|
|
|
int mCameraAngle; // See dom/base/ScreenOrientation.h
|
|
|
|
bool mBackCamera;
|
2013-05-02 05:00:12 -07:00
|
|
|
#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
|
2014-07-17 19:23:00 -07:00
|
|
|
MediaSourceType mMediaSource; // source of media (camera | application | screen)
|
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;
|
2014-07-13 22:48:02 -07:00
|
|
|
bool mHasDirectListeners;
|
2013-05-02 05:00:12 -07:00
|
|
|
|
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;
|
|
|
|
|
2013-09-06 06:14:15 -07:00
|
|
|
nsString mDeviceName;
|
|
|
|
nsString mUniqueId;
|
2012-10-04 09:09:35 -07:00
|
|
|
|
2014-04-18 12:15:10 -07:00
|
|
|
void ChooseCapability(const VideoTrackConstraintsN &aConstraints,
|
|
|
|
const MediaEnginePrefs &aPrefs);
|
2014-04-18 12:15:37 -07:00
|
|
|
|
|
|
|
void GuessCapability(const VideoTrackConstraintsN &aConstraints,
|
|
|
|
const MediaEnginePrefs &aPrefs);
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class MediaEngineWebRTCAudioSource : public MediaEngineAudioSource,
|
|
|
|
public webrtc::VoEMediaProcess
|
|
|
|
{
|
|
|
|
public:
|
2014-07-08 12:02:40 -07:00
|
|
|
MediaEngineWebRTCAudioSource(nsIThread *aThread, webrtc::VoiceEngine* aVoiceEnginePtr,
|
|
|
|
int aIndex, const char* name, const char* uuid)
|
2014-06-15 11:57:30 -07:00
|
|
|
: mSamples(0)
|
|
|
|
, mVoiceEngine(aVoiceEnginePtr)
|
2012-07-12 04:53:08 -07:00
|
|
|
, mMonitor("WebRTCMic.Monitor")
|
2014-07-08 12:02:40 -07:00
|
|
|
, mThread(aThread)
|
2012-07-12 04:53:08 -07:00
|
|
|
, mCapIndex(aIndex)
|
|
|
|
, mChannel(-1)
|
2012-11-15 14:58:40 -08:00
|
|
|
, mInitDone(false)
|
2014-04-02 10:58:19 -07:00
|
|
|
, mStarted(false)
|
2013-01-29 08:55:09 -08:00
|
|
|
, mEchoOn(false), mAgcOn(false), mNoiseOn(false)
|
|
|
|
, mEchoCancel(webrtc::kEcDefault)
|
|
|
|
, mAGC(webrtc::kAgcDefault)
|
|
|
|
, mNoiseSuppress(webrtc::kNsDefault)
|
2014-04-02 10:58:19 -07:00
|
|
|
, mPlayoutDelay(0)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetName(nsAString&);
|
|
|
|
virtual void GetUUID(nsAString&);
|
|
|
|
|
2014-04-18 12:15:10 -07:00
|
|
|
virtual nsresult Allocate(const AudioTrackConstraintsN &aConstraints,
|
|
|
|
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);
|
2014-07-13 22:48:02 -07:00
|
|
|
virtual void SetDirectListeners(bool aHasDirectListeners) {};
|
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,
|
2014-04-02 10:58:19 -07:00
|
|
|
bool aNoiseOn, uint32_t aNoise,
|
|
|
|
int32_t aPlayoutDelay);
|
2013-01-29 08:55:09 -08:00
|
|
|
|
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
|
|
|
|
2013-07-04 22:53:10 -07:00
|
|
|
virtual bool IsFake() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-17 19:23:00 -07:00
|
|
|
virtual const MediaSourceType GetMediaSource() {
|
|
|
|
return MediaSourceType::Microphone;
|
|
|
|
}
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
// VoEMediaProcess.
|
2013-08-29 23:08:57 -07:00
|
|
|
void Process(int channel, webrtc::ProcessingTypes type,
|
|
|
|
int16_t audio10ms[], int length,
|
|
|
|
int samplingFreq, bool isStereo);
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2013-07-18 19:21:19 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-12 04:53:08 -07:00
|
|
|
|
2014-06-15 11:57:30 -07:00
|
|
|
protected:
|
2014-06-24 09:36:43 -07:00
|
|
|
~MediaEngineWebRTCAudioSource() { Shutdown(); }
|
|
|
|
|
2014-06-15 11:57:30 -07:00
|
|
|
// mSamples is an int to avoid conversions when comparing/etc to
|
|
|
|
// samplingFreq & length. Making mSamples protected instead of private is a
|
|
|
|
// silly way to avoid -Wunused-private-field warnings when PR_LOGGING is not
|
|
|
|
// #defined. mSamples is not actually expected to be used by a derived class.
|
|
|
|
int mSamples;
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
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;
|
2014-03-08 21:18:50 -08:00
|
|
|
ScopedCustomReleasePtr<webrtc::VoEBase> mVoEBase;
|
|
|
|
ScopedCustomReleasePtr<webrtc::VoEExternalMedia> mVoERender;
|
|
|
|
ScopedCustomReleasePtr<webrtc::VoENetwork> mVoENetwork;
|
|
|
|
ScopedCustomReleasePtr<webrtc::VoEAudioProcessing> mVoEProcessing;
|
2014-04-02 10:58:20 -07:00
|
|
|
ScopedCustomReleasePtr<webrtc::VoECallReport> mVoECallReport;
|
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
|
2014-07-08 12:02:40 -07:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
2012-07-12 04:53:08 -07:00
|
|
|
int mCapIndex;
|
|
|
|
int mChannel;
|
|
|
|
TrackID mTrackID;
|
|
|
|
bool mInitDone;
|
2014-04-02 10:58:19 -07:00
|
|
|
bool mStarted;
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
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;
|
2014-04-02 10:58:19 -07:00
|
|
|
int32_t mPlayoutDelay;
|
2013-01-29 08:55:09 -08:00
|
|
|
|
2012-11-15 14:58:40 -08:00
|
|
|
NullTransport *mNullTransport;
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
2014-06-08 18:54:47 -07:00
|
|
|
class MediaEngineWebRTC : public MediaEngine
|
2012-07-12 04:53:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-12-06 11:34:40 -08:00
|
|
|
MediaEngineWebRTC(MediaEnginePrefs &aPrefs);
|
2012-07-12 04:53:08 -07:00
|
|
|
|
|
|
|
// Clients should ensure to clean-up sources video/audio sources
|
|
|
|
// before invoking Shutdown on this class.
|
|
|
|
void Shutdown();
|
|
|
|
|
2014-07-17 19:23:00 -07:00
|
|
|
virtual void EnumerateVideoDevices(MediaSourceType,
|
2014-07-07 00:46:00 -07:00
|
|
|
nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
|
2014-07-17 19:23:00 -07:00
|
|
|
virtual void EnumerateAudioDevices(MediaSourceType,
|
2014-07-07 00:46:00 -07:00
|
|
|
nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
2012-07-12 04:53:08 -07:00
|
|
|
private:
|
2014-04-11 08:35:34 -07:00
|
|
|
~MediaEngineWebRTC() {
|
|
|
|
Shutdown();
|
|
|
|
#ifdef MOZ_B2G_CAMERA
|
|
|
|
AsyncLatencyLogger::Get()->Release();
|
|
|
|
#endif
|
|
|
|
// XXX
|
|
|
|
gFarendObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:02:40 -07:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
|
2012-10-18 11:03:00 -07:00
|
|
|
Mutex mMutex;
|
|
|
|
|
2014-07-07 00:46:00 -07:00
|
|
|
// protected with mMutex:
|
|
|
|
webrtc::VideoEngine* mScreenEngine;
|
2014-07-17 19:23:00 -07:00
|
|
|
webrtc::VideoEngine* mWinEngine;
|
2014-07-07 00:46:00 -07:00
|
|
|
webrtc::VideoEngine* mAppEngine;
|
2012-07-12 04:53:08 -07:00
|
|
|
webrtc::VideoEngine* mVideoEngine;
|
|
|
|
webrtc::VoiceEngine* mVoiceEngine;
|
|
|
|
|
2014-07-07 00:46:00 -07:00
|
|
|
// specialized configurations
|
|
|
|
webrtc::Config mAppEngineConfig;
|
2014-07-17 19:23:00 -07:00
|
|
|
webrtc::Config mWinEngineConfig;
|
2014-07-07 00:46:00 -07:00
|
|
|
webrtc::Config mScreenEngineConfig;
|
|
|
|
|
2012-07-12 04:53:08 -07:00
|
|
|
// Need this to avoid unneccesary WebRTC calls while enumerating.
|
|
|
|
bool mVideoEngineInit;
|
|
|
|
bool mAudioEngineInit;
|
2014-07-07 00:46:00 -07:00
|
|
|
bool mScreenEngineInit;
|
2014-07-17 19:23:00 -07:00
|
|
|
bool mWinEngineInit;
|
2014-07-07 00:46:00 -07:00
|
|
|
bool mAppEngineInit;
|
2013-10-17 13:48:30 -07:00
|
|
|
bool mHasTabVideoSource;
|
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;
|
2012-07-12 04:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NSMEDIAENGINEWEBRTC_H_ */
|