2012-06-03 00:34:02 -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 MEDIAENGINE_H_
|
|
|
|
#define MEDIAENGINE_H_
|
|
|
|
|
|
|
|
#include "nsIDOMFile.h"
|
|
|
|
#include "nsDOMMediaStream.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract interface for managing audio and video devices. Each platform
|
|
|
|
* must implement a concrete class that will map these classes and methods
|
|
|
|
* to the appropriate backend. For example, on Desktop platforms, these will
|
|
|
|
* correspond to equivalent webrtc (GIPS) calls, and on B2G they will map to
|
|
|
|
* a Gonk interface.
|
|
|
|
*/
|
|
|
|
class MediaEngineVideoSource;
|
|
|
|
class MediaEngineAudioSource;
|
|
|
|
|
2012-09-28 15:26:00 -07:00
|
|
|
enum MediaEngineState {
|
|
|
|
kAllocated,
|
|
|
|
kStarted,
|
|
|
|
kStopped,
|
|
|
|
kReleased
|
|
|
|
};
|
|
|
|
|
2012-12-31 15:12:12 -08:00
|
|
|
// We only support 1 audio and 1 video track for now.
|
|
|
|
enum {
|
|
|
|
kVideoTrack = 1,
|
|
|
|
kAudioTrack = 2
|
|
|
|
};
|
|
|
|
|
2012-06-03 00:34:02 -07:00
|
|
|
class MediaEngine
|
|
|
|
{
|
|
|
|
public:
|
2012-12-09 09:23:19 -08:00
|
|
|
virtual ~MediaEngine() {}
|
2012-06-03 00:34:02 -07:00
|
|
|
|
|
|
|
/* Populate an array of video sources in the nsTArray. Also include devices
|
|
|
|
* that are currently unavailable. */
|
|
|
|
virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*) = 0;
|
|
|
|
|
|
|
|
/* Populate an array of audio sources in the nsTArray. Also include devices
|
|
|
|
* that are currently unavailable. */
|
|
|
|
virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common abstract base class for audio and video sources.
|
|
|
|
*/
|
|
|
|
class MediaEngineSource : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
2012-12-09 09:23:19 -08:00
|
|
|
virtual ~MediaEngineSource() {}
|
2012-06-03 00:34:02 -07:00
|
|
|
|
|
|
|
/* Populate the human readable name of this device in the nsAString */
|
|
|
|
virtual void GetName(nsAString&) = 0;
|
|
|
|
|
|
|
|
/* Populate the UUID of this device in the nsAString */
|
|
|
|
virtual void GetUUID(nsAString&) = 0;
|
|
|
|
|
|
|
|
/* This call reserves but does not start the device. */
|
2012-06-19 17:29:43 -07:00
|
|
|
virtual nsresult Allocate() = 0;
|
2012-06-03 00:34:02 -07:00
|
|
|
|
|
|
|
/* Release the device back to the system. */
|
|
|
|
virtual nsresult Deallocate() = 0;
|
|
|
|
|
|
|
|
/* Start the device and add the track to the provided SourceMediaStream, with
|
|
|
|
* the provided TrackID. You may start appending data to the track
|
|
|
|
* immediately after. */
|
|
|
|
virtual nsresult Start(SourceMediaStream*, TrackID) = 0;
|
|
|
|
|
|
|
|
/* Take a snapshot from this source. In the case of video this is a single
|
|
|
|
* image, and for audio, it is a snippet lasting aDuration milliseconds. The
|
|
|
|
* duration argument is ignored for a MediaEngineVideoSource.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult Snapshot(uint32_t aDuration, nsIDOMFile** aFile) = 0;
|
2012-06-03 00:34:02 -07:00
|
|
|
|
2012-10-17 02:46:40 -07:00
|
|
|
/* Called when the stream wants more data */
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual void NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aId,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
TrackTicks &aLastEndTime) = 0;
|
2012-10-17 02:46:40 -07:00
|
|
|
|
2012-06-03 00:34:02 -07:00
|
|
|
/* Stop the device and release the corresponding MediaStream */
|
2012-12-31 15:12:12 -08:00
|
|
|
virtual nsresult Stop(SourceMediaStream *aSource, TrackID aID) = 0;
|
2012-06-03 00:34:02 -07:00
|
|
|
|
2013-01-29 08:55:09 -08:00
|
|
|
/* Change device configuration. */
|
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
|
|
|
bool aNoiseOn, uint32_t aNoise) = 0;
|
|
|
|
|
2012-10-16 17:53:55 -07:00
|
|
|
/* Return false if device is currently allocated or started */
|
|
|
|
bool IsAvailable() {
|
|
|
|
if (mState == kAllocated || mState == kStarted) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-03 00:34:02 -07:00
|
|
|
/* It is an error to call Start() before an Allocate(), and Stop() before
|
|
|
|
* a Start(). Only Allocate() may be called after a Deallocate(). */
|
2012-10-16 17:53:55 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MediaEngineState mState;
|
2012-06-03 00:34:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Video source and friends.
|
|
|
|
*/
|
|
|
|
enum MediaEngineVideoCodecType {
|
|
|
|
kVideoCodecH263,
|
|
|
|
kVideoCodecVP8,
|
|
|
|
kVideoCodecI420
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MediaEngineVideoOptions {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
uint32_t mMaxFPS;
|
2012-06-03 00:34:02 -07:00
|
|
|
MediaEngineVideoCodecType codecType;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MediaEngineVideoSource : public MediaEngineSource
|
|
|
|
{
|
|
|
|
public:
|
2012-12-09 09:23:19 -08:00
|
|
|
virtual ~MediaEngineVideoSource() {}
|
2012-06-03 00:34:02 -07:00
|
|
|
|
|
|
|
/* Return a MediaEngineVideoOptions struct with appropriate values for all
|
|
|
|
* fields. */
|
2012-10-04 09:09:35 -07:00
|
|
|
virtual const MediaEngineVideoOptions *GetOptions() = 0;
|
2012-06-03 00:34:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio source and friends.
|
|
|
|
*/
|
|
|
|
class MediaEngineAudioSource : public MediaEngineSource
|
|
|
|
{
|
|
|
|
public:
|
2012-12-09 09:23:19 -08:00
|
|
|
virtual ~MediaEngineAudioSource() {}
|
2012-06-03 00:34:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MEDIAENGINE_H_ */
|