1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsIDOMFile.h"
9 #include "DOMMediaStream.h"
10 #include "MediaStreamGraph.h"
15 * Abstract interface for managing audio and video devices. Each platform
16 * must implement a concrete class that will map these classes and methods
17 * to the appropriate backend. For example, on Desktop platforms, these will
18 * correspond to equivalent webrtc (GIPS) calls, and on B2G they will map to
21 class MediaEngineVideoSource
;
22 class MediaEngineAudioSource
;
23 struct MediaEnginePrefs
;
25 enum MediaEngineState
{
32 // We only support 1 audio and 1 video track for now.
41 virtual ~MediaEngine() {}
43 static const int DEFAULT_VIDEO_FPS
= 30;
44 static const int DEFAULT_VIDEO_MIN_FPS
= 10;
45 static const int DEFAULT_VIDEO_WIDTH
= 640;
46 static const int DEFAULT_VIDEO_HEIGHT
= 480;
47 static const int DEFAULT_AUDIO_TIMER_MS
= 10;
48 static const bool DEFAULT_LOAD_ADAPT
= false;
50 /* Populate an array of video sources in the nsTArray. Also include devices
51 * that are currently unavailable. */
52 virtual void EnumerateVideoDevices(nsTArray
<nsRefPtr
<MediaEngineVideoSource
> >*) = 0;
54 /* Populate an array of audio sources in the nsTArray. Also include devices
55 * that are currently unavailable. */
56 virtual void EnumerateAudioDevices(nsTArray
<nsRefPtr
<MediaEngineAudioSource
> >*) = 0;
60 * Common abstract base class for audio and video sources.
62 class MediaEngineSource
: public nsISupports
65 virtual ~MediaEngineSource() {}
67 /* Populate the human readable name of this device in the nsAString */
68 virtual void GetName(nsAString
&) = 0;
70 /* Populate the UUID of this device in the nsAString */
71 virtual void GetUUID(nsAString
&) = 0;
73 /* This call reserves but does not start the device. */
74 virtual nsresult
Allocate(const MediaEnginePrefs
&aPrefs
) = 0;
76 /* Release the device back to the system. */
77 virtual nsresult
Deallocate() = 0;
79 /* Start the device and add the track to the provided SourceMediaStream, with
80 * the provided TrackID. You may start appending data to the track
81 * immediately after. */
82 virtual nsresult
Start(SourceMediaStream
*, TrackID
) = 0;
84 /* Take a snapshot from this source. In the case of video this is a single
85 * image, and for audio, it is a snippet lasting aDuration milliseconds. The
86 * duration argument is ignored for a MediaEngineVideoSource.
88 virtual nsresult
Snapshot(uint32_t aDuration
, nsIDOMFile
** aFile
) = 0;
90 /* Called when the stream wants more data */
91 virtual void NotifyPull(MediaStreamGraph
* aGraph
,
92 SourceMediaStream
*aSource
,
94 StreamTime aDesiredTime
,
95 TrackTicks
&aLastEndTime
) = 0;
97 /* Stop the device and release the corresponding MediaStream */
98 virtual nsresult
Stop(SourceMediaStream
*aSource
, TrackID aID
) = 0;
100 /* Change device configuration. */
101 virtual nsresult
Config(bool aEchoOn
, uint32_t aEcho
,
102 bool aAgcOn
, uint32_t aAGC
,
103 bool aNoiseOn
, uint32_t aNoise
) = 0;
105 /* Returns true if a source represents a fake capture device and
108 virtual bool IsFake() = 0;
110 /* Return false if device is currently allocated or started */
112 if (mState
== kAllocated
|| mState
== kStarted
) {
119 /* It is an error to call Start() before an Allocate(), and Stop() before
120 * a Start(). Only Allocate() may be called after a Deallocate(). */
123 MediaEngineState mState
;
127 * Video source and friends.
129 struct MediaEnginePrefs
{
137 class MediaEngineVideoSource
: public MediaEngineSource
140 virtual ~MediaEngineVideoSource() {}
144 * Audio source and friends.
146 class MediaEngineAudioSource
: public MediaEngineSource
149 virtual ~MediaEngineAudioSource() {}
154 #endif /* MEDIAENGINE_H_ */