2012-04-29 20:11:34 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* 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 NSDOMMEDIASTREAM_H_
|
|
|
|
#define NSDOMMEDIASTREAM_H_
|
|
|
|
|
|
|
|
#include "nsIDOMMediaStream.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2013-02-15 00:04:11 -08:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2013-04-16 22:18:24 -07:00
|
|
|
#include "StreamBuffer.h"
|
2012-04-29 20:11:34 -07:00
|
|
|
|
2012-10-24 16:21:32 -07:00
|
|
|
class nsXPCClassInfo;
|
|
|
|
|
2012-07-19 02:58:48 -07:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount() and conflicts with NS_DECL_NSIDOMMEDIASTREAM, containing
|
|
|
|
// currentTime getter.
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
2013-02-15 00:04:11 -08:00
|
|
|
// X11 has a #define for CurrentTime. Unbelievable :-(.
|
2013-03-14 18:01:02 -07:00
|
|
|
// See content/media/webaudio/AudioContext.h for more fun!
|
2013-02-15 00:04:11 -08:00
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
2012-07-19 02:58:48 -07:00
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
class MediaStream;
|
|
|
|
|
2013-04-16 22:18:24 -07:00
|
|
|
namespace dom {
|
|
|
|
class MediaStreamTrack;
|
2013-04-16 22:18:37 -07:00
|
|
|
class AudioStreamTrack;
|
|
|
|
class VideoStreamTrack;
|
2013-04-16 22:18:24 -07:00
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
/**
|
|
|
|
* DOM wrapper for MediaStreams.
|
|
|
|
*/
|
2013-02-15 00:04:11 -08:00
|
|
|
class DOMMediaStream : public nsIDOMMediaStream,
|
|
|
|
public nsWrapperCache
|
2012-04-29 20:11:34 -07:00
|
|
|
{
|
2013-02-15 00:01:58 -08:00
|
|
|
friend class DOMLocalMediaStream;
|
2013-04-16 22:18:24 -07:00
|
|
|
typedef dom::MediaStreamTrack MediaStreamTrack;
|
2013-04-16 22:18:37 -07:00
|
|
|
typedef dom::AudioStreamTrack AudioStreamTrack;
|
|
|
|
typedef dom::VideoStreamTrack VideoStreamTrack;
|
2012-04-29 20:11:34 -07:00
|
|
|
|
|
|
|
public:
|
2013-04-16 22:18:24 -07:00
|
|
|
DOMMediaStream();
|
2013-02-15 00:01:58 -08:00
|
|
|
virtual ~DOMMediaStream();
|
2012-04-29 20:11:34 -07:00
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMMediaStream)
|
2012-04-29 20:11:34 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2013-02-15 00:04:11 -08:00
|
|
|
nsIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
2013-03-11 16:03:47 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
|
2012-04-29 20:11:34 -07:00
|
|
|
|
2013-04-16 22:18:37 -07:00
|
|
|
// WebIDL
|
2013-02-15 00:04:11 -08:00
|
|
|
double CurrentTime();
|
2013-04-16 22:18:37 -07:00
|
|
|
void GetAudioTracks(nsTArray<nsRefPtr<AudioStreamTrack> >& aTracks);
|
|
|
|
void GetVideoTracks(nsTArray<nsRefPtr<VideoStreamTrack> >& aTracks);
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
MediaStream* GetStream() { return mStream; }
|
2013-02-15 00:04:11 -08:00
|
|
|
bool IsFinished();
|
2012-04-29 20:11:34 -07:00
|
|
|
/**
|
|
|
|
* Returns a principal indicating who may access this stream. The stream contents
|
|
|
|
* can only be accessed by principals subsuming this principal.
|
|
|
|
*/
|
|
|
|
nsIPrincipal* GetPrincipal() { return mPrincipal; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicate that data will be contributed to this stream from origin aPrincipal.
|
|
|
|
* If aPrincipal is null, this is ignored. Otherwise, from now on the contents
|
|
|
|
* of this stream can only be accessed by principals that subsume aPrincipal.
|
|
|
|
* Returns true if the stream's principal changed.
|
|
|
|
*/
|
|
|
|
bool CombineWithPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
2012-04-29 20:11:40 -07:00
|
|
|
/**
|
|
|
|
* Create an nsDOMMediaStream whose underlying stream is a SourceMediaStream.
|
|
|
|
*/
|
2013-02-15 00:04:11 -08:00
|
|
|
static already_AddRefed<DOMMediaStream>
|
|
|
|
CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
// Hints to tell the SDP generator about whether this
|
|
|
|
// MediaStream probably has audio and/or video
|
|
|
|
enum {
|
|
|
|
HINT_CONTENTS_AUDIO = 0x00000001U,
|
|
|
|
HINT_CONTENTS_VIDEO = 0x00000002U
|
|
|
|
};
|
|
|
|
uint32_t GetHintContents() const { return mHintContents; }
|
|
|
|
void SetHintContents(uint32_t aHintContents) { mHintContents = aHintContents; }
|
2012-04-29 20:11:40 -07:00
|
|
|
|
2012-07-31 05:17:22 -07:00
|
|
|
/**
|
|
|
|
* Create an nsDOMMediaStream whose underlying stream is a TrackUnionStream.
|
|
|
|
*/
|
2013-02-15 00:04:11 -08:00
|
|
|
static already_AddRefed<DOMMediaStream>
|
|
|
|
CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents = 0);
|
2012-07-31 05:17:22 -07:00
|
|
|
|
2013-04-16 22:18:24 -07:00
|
|
|
// Notifications from StreamListener
|
|
|
|
MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType);
|
|
|
|
MediaStreamTrack* GetDOMTrackFor(TrackID aTrackID);
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
protected:
|
2013-02-15 00:04:11 -08:00
|
|
|
void InitSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
|
|
|
void InitTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
2013-04-16 22:18:24 -07:00
|
|
|
void InitStreamCommon(MediaStream* aStream);
|
|
|
|
|
|
|
|
class StreamListener;
|
|
|
|
friend class StreamListener;
|
2013-02-15 00:04:11 -08:00
|
|
|
|
|
|
|
// We need this to track our parent object.
|
|
|
|
nsCOMPtr<nsIDOMWindow> mWindow;
|
2013-01-04 09:16:32 -08:00
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
// MediaStream is owned by the graph, but we tell it when to die, and it won't
|
|
|
|
// die until we let it.
|
|
|
|
MediaStream* mStream;
|
|
|
|
// Principal identifying who may access the contents of this stream.
|
|
|
|
// If null, this stream can be used by anyone because it has no content yet.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-04-16 22:18:24 -07:00
|
|
|
nsAutoTArray<nsRefPtr<MediaStreamTrack>,2> mTracks;
|
|
|
|
nsRefPtr<StreamListener> mListener;
|
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
// tells the SDP generator about whether this
|
|
|
|
// MediaStream probably has audio and/or video
|
|
|
|
uint32_t mHintContents;
|
2012-04-29 20:11:34 -07:00
|
|
|
};
|
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
class DOMLocalMediaStream : public DOMMediaStream,
|
|
|
|
public nsIDOMLocalMediaStream
|
2012-10-24 16:21:32 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-02-15 00:01:58 -08:00
|
|
|
DOMLocalMediaStream() {}
|
|
|
|
virtual ~DOMLocalMediaStream();
|
2012-10-24 16:21:32 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2013-03-11 16:03:47 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
|
2013-02-15 00:04:11 -08:00
|
|
|
|
|
|
|
virtual void Stop();
|
2012-10-24 16:21:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an nsDOMLocalMediaStream whose underlying stream is a SourceMediaStream.
|
|
|
|
*/
|
2013-02-15 00:04:11 -08:00
|
|
|
static already_AddRefed<DOMLocalMediaStream>
|
|
|
|
CreateSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents);
|
2012-10-24 16:21:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an nsDOMLocalMediaStream whose underlying stream is a TrackUnionStream.
|
|
|
|
*/
|
2013-02-15 00:04:11 -08:00
|
|
|
static already_AddRefed<DOMLocalMediaStream>
|
|
|
|
CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents = 0);
|
2012-10-24 16:21:32 -07:00
|
|
|
};
|
|
|
|
|
2013-02-15 00:01:58 -08:00
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:34 -07:00
|
|
|
#endif /* NSDOMMEDIASTREAM_H_ */
|