diff --git a/content/media/AudioStreamTrack.cpp b/content/media/AudioStreamTrack.cpp new file mode 100644 index 00000000000..1aa07d5f250 --- /dev/null +++ b/content/media/AudioStreamTrack.cpp @@ -0,0 +1,20 @@ +/* -*- 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/. */ + +#include "AudioStreamTrack.h" + +#include "mozilla/dom/AudioStreamTrackBinding.h" + +namespace mozilla { +namespace dom { + +JSObject* +AudioStreamTrack::WrapObject(JSContext* aCx, JSObject* aScope) +{ + return AudioStreamTrackBinding::Wrap(aCx, aScope, this); +} + +} +} diff --git a/content/media/AudioStreamTrack.h b/content/media/AudioStreamTrack.h new file mode 100644 index 00000000000..db99bcd9262 --- /dev/null +++ b/content/media/AudioStreamTrack.h @@ -0,0 +1,30 @@ +/* -*- 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 AUDIOSTREAMTRACK_H_ +#define AUDIOSTREAMTRACK_H_ + +#include "MediaStreamTrack.h" + +namespace mozilla { +namespace dom { + +class AudioStreamTrack : public MediaStreamTrack { +public: + AudioStreamTrack(DOMMediaStream* aStream, TrackID aTrackID) + : MediaStreamTrack(aStream, aTrackID) {} + + virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope); + + virtual AudioStreamTrack* AsAudioStreamTrack() { return this; } + + // WebIDL + virtual void GetKind(nsAString& aKind) { aKind.AssignLiteral("audio"); } +}; + +} +} + +#endif /* AUDIOSTREAMTRACK_H_ */ diff --git a/content/media/Makefile.in b/content/media/Makefile.in index 71e88e1dae7..763b1fc28e1 100644 --- a/content/media/Makefile.in +++ b/content/media/Makefile.in @@ -16,24 +16,27 @@ FAIL_ON_WARNINGS := 1 endif # !_MSC_VER CPPSRCS = \ + AudioAvailableEventManager.cpp \ AudioChannelFormat.cpp \ AudioNodeEngine.cpp \ AudioNodeStream.cpp \ AudioSegment.cpp \ AudioStream.cpp \ + AudioStreamTrack.cpp \ DecoderTraits.cpp \ DOMMediaStream.cpp \ FileBlockCache.cpp \ - MediaResource.cpp \ - MediaStreamGraph.cpp \ - AudioAvailableEventManager.cpp \ + MediaCache.cpp \ MediaDecoder.cpp \ MediaDecoderStateMachine.cpp \ MediaDecoderReader.cpp \ - MediaCache.cpp \ + MediaResource.cpp \ + MediaStreamGraph.cpp \ + MediaStreamTrack.cpp \ StreamBuffer.cpp \ VideoFrameContainer.cpp \ VideoSegment.cpp \ + VideoStreamTrack.cpp \ VideoUtils.cpp \ $(NULL) diff --git a/content/media/MediaStreamTrack.cpp b/content/media/MediaStreamTrack.cpp new file mode 100644 index 00000000000..01b108f3bc4 --- /dev/null +++ b/content/media/MediaStreamTrack.cpp @@ -0,0 +1,51 @@ +/* -*- 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/. */ + +#include "MediaStreamTrack.h" + +#include "DOMMediaStream.h" +#include "nsIUUIDGenerator.h" +#include "nsServiceManagerUtils.h" + +namespace mozilla { +namespace dom { + +MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID) + : mStream(aStream), mTrackID(aTrackID), mEnded(false) +{ + SetIsDOMBinding(); + + memset(&mID, 0, sizeof(mID)); + + nsresult rv; + nsCOMPtr uuidgen = + do_GetService("@mozilla.org/uuid-generator;1", &rv); + if (uuidgen) { + uuidgen->GenerateUUIDInPlace(&mID); + } +} + +MediaStreamTrack::~MediaStreamTrack() +{ +} + +NS_IMPL_CYCLE_COLLECTION_INHERITED_1(MediaStreamTrack, nsDOMEventTargetHelper, + mStream) + +NS_IMPL_ADDREF_INHERITED(MediaStreamTrack, nsDOMEventTargetHelper) +NS_IMPL_RELEASE_INHERITED(MediaStreamTrack, nsDOMEventTargetHelper) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamTrack) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) + +void +MediaStreamTrack::GetId(nsAString& aID) +{ + char chars[NSID_LENGTH]; + mID.ToProvidedString(chars); + aID = NS_ConvertASCIItoUTF16(chars); +} + +} +} diff --git a/content/media/MediaStreamTrack.h b/content/media/MediaStreamTrack.h new file mode 100644 index 00000000000..61416a988c7 --- /dev/null +++ b/content/media/MediaStreamTrack.h @@ -0,0 +1,63 @@ +/* -*- 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 MEDIASTREAMTRACK_H_ +#define MEDIASTREAMTRACK_H_ + +#include "nsDOMEventTargetHelper.h" +#include "nsID.h" +#include "StreamBuffer.h" + +namespace mozilla { + +class DOMMediaStream; + +namespace dom { + +class AudioStreamTrack; +class VideoStreamTrack; + +/** + * Class representing a track in a DOMMediaStream. + */ +class MediaStreamTrack : public nsDOMEventTargetHelper { +public: + /** + * aTrackID is the MediaStreamGraph track ID for the track in the + * MediaStream owned by aStream. + */ + MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID); + virtual ~MediaStreamTrack(); + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrack, nsDOMEventTargetHelper) + + DOMMediaStream* GetParentObject() const { return mStream; } + virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) = 0; + + DOMMediaStream* GetStream() const { return mStream; } + TrackID GetTrackID() const { return mTrackID; } + virtual AudioStreamTrack* AsAudioStreamTrack() { return nullptr; } + virtual VideoStreamTrack* AsVideoStreamTrack() { return nullptr; } + + // WebIDL + virtual void GetKind(nsAString& aKind) = 0; + void GetId(nsAString& aID); + void GetLabel(nsAString& aLabel) { aLabel.Truncate(); } + + // Notifications from the MediaStreamGraph + void NotifyEnded() { mEnded = true; } + +protected: + nsRefPtr mStream; + TrackID mTrackID; + nsID mID; + bool mEnded; +}; + +} +} + +#endif /* MEDIASTREAMTRACK_H_ */ diff --git a/content/media/VideoStreamTrack.cpp b/content/media/VideoStreamTrack.cpp new file mode 100644 index 00000000000..bacbad1045a --- /dev/null +++ b/content/media/VideoStreamTrack.cpp @@ -0,0 +1,20 @@ +/* -*- 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/. */ + +#include "VideoStreamTrack.h" + +#include "mozilla/dom/VideoStreamTrackBinding.h" + +namespace mozilla { +namespace dom { + +JSObject* +VideoStreamTrack::WrapObject(JSContext* aCx, JSObject* aScope) +{ + return VideoStreamTrackBinding::Wrap(aCx, aScope, this); +} + +} +} diff --git a/content/media/VideoStreamTrack.h b/content/media/VideoStreamTrack.h new file mode 100644 index 00000000000..9fcd4acad1d --- /dev/null +++ b/content/media/VideoStreamTrack.h @@ -0,0 +1,30 @@ +/* -*- 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 VIDEOSTREAMTRACK_H_ +#define VIDEOSTREAMTRACK_H_ + +#include "MediaStreamTrack.h" + +namespace mozilla { +namespace dom { + +class VideoStreamTrack : public MediaStreamTrack { +public: + VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID) + : MediaStreamTrack(aStream, aTrackID) {} + + virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope); + + virtual VideoStreamTrack* AsVideoStreamTrack() { return this; } + + // WebIDL + virtual void GetKind(nsAString& aKind) { aKind.AssignLiteral("video"); } +}; + +} +} + +#endif /* VIDEOSTREAMTRACK_H_ */ diff --git a/content/media/moz.build b/content/media/moz.build index 5f256159bd2..464766e849d 100644 --- a/content/media/moz.build +++ b/content/media/moz.build @@ -74,3 +74,9 @@ EXPORTS += [ 'VorbisUtils.h', ] +EXPORTS.mozilla.dom += [ + 'AudioStreamTrack.h', + 'MediaStreamTrack.h', + 'VideoStreamTrack.h', +] + diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index a7b2ae1a6d2..447ae15f541 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -126,6 +126,9 @@ DOMInterfaces = { 'nativeType': 'nsDOMBeforeUnloadEvent', }, +'AudioStreamTrack': { +}, + 'BiquadFilterNode': { 'resultNotAddRefed': [ 'frequency', 'q', 'gain' ], }, @@ -553,6 +556,11 @@ DOMInterfaces = { 'workers': True, }], +'LocalMediaStream': { + 'headerFile': 'DOMMediaStream.h', + 'nativeType': 'mozilla::DOMLocalMediaStream' +}, + 'Location': { # NOTE: Before you turn on codegen for Location, make sure all the # Unforgeable stuff is dealt with. @@ -571,11 +579,6 @@ DOMInterfaces = { 'skipGen': True }], -'LocalMediaStream': { - 'headerFile': 'DOMMediaStream.h', - 'nativeType': 'mozilla::DOMLocalMediaStream' -}, - 'MediaStreamList': { 'headerFile': 'MediaStreamList.h', 'wrapperCache': False, @@ -584,6 +587,10 @@ DOMInterfaces = { 'binaryNames': { '__indexedGetter': 'IndexedGetter' } }, +'MediaStreamTrack': { + 'concrete': False +}, + 'MessageEvent': { 'nativeType': 'nsDOMMessageEvent', }, @@ -1022,6 +1029,9 @@ DOMInterfaces = { 'workers': True, }], +'VideoStreamTrack': { +}, + 'WebGLActiveInfo': { 'nativeType': 'mozilla::WebGLActiveInfo', 'headerFile': 'WebGLContext.h', diff --git a/dom/webidl/AudioStreamTrack.webidl b/dom/webidl/AudioStreamTrack.webidl new file mode 100644 index 00000000000..9fff71cedc3 --- /dev/null +++ b/dom/webidl/AudioStreamTrack.webidl @@ -0,0 +1,16 @@ +/* -*- Mode: IDL; 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/. + * + * The origin of this IDL file is + * http://dev.w3.org/2011/webrtc/editor/getusermedia.html + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// [Constructor(optional MediaTrackConstraints audioConstraints)] +interface AudioStreamTrack : MediaStreamTrack { +// static sequence getSourceIds (); +}; diff --git a/dom/webidl/MediaStreamTrack.webidl b/dom/webidl/MediaStreamTrack.webidl new file mode 100644 index 00000000000..3daaa382768 --- /dev/null +++ b/dom/webidl/MediaStreamTrack.webidl @@ -0,0 +1,33 @@ +/* -*- Mode: IDL; 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/. + * + * The origin of this IDL file is + * http://dev.w3.org/2011/webrtc/editor/getusermedia.html + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +interface MediaStreamTrack { + readonly attribute DOMString kind; + readonly attribute DOMString id; + readonly attribute DOMString label; +// attribute boolean enabled; +// readonly attribute MediaStreamTrackState readyState; +// readonly attribute SourceTypeEnum sourceType; +// readonly attribute DOMString sourceId; +// attribute EventHandler onstarted; +// attribute EventHandler onmute; +// attribute EventHandler onunmute; +// attribute EventHandler onended; +// any getConstraint (DOMString constraintName, optional boolean mandatory = false); +// void setConstraint (DOMString constraintName, any constraintValue, optional boolean mandatory = false); +// MediaTrackConstraints? constraints (); +// void applyConstraints (MediaTrackConstraints constraints); +// void prependConstraint (DOMString constraintName, any constraintValue); +// void appendConstraint (DOMString constraintName, any constraintValue); +// attribute EventHandler onoverconstrained; +// void stop (); +}; diff --git a/dom/webidl/VideoStreamTrack.webidl b/dom/webidl/VideoStreamTrack.webidl new file mode 100644 index 00000000000..b194d5c9fae --- /dev/null +++ b/dom/webidl/VideoStreamTrack.webidl @@ -0,0 +1,19 @@ +/* -*- Mode: IDL; 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/. + * + * The origin of this IDL file is + * http://dev.w3.org/2011/webrtc/editor/getusermedia.html + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// [Constructor(optional MediaTrackConstraints videoConstraints)] +interface VideoStreamTrack : MediaStreamTrack { +// static sequence getSourceIds (); +// void takePhoto (); +// attribute EventHandler onphoto; +// attribute EventHandler onphotoerror; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index e3be80f1894..ff086114c60 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -20,6 +20,7 @@ webidl_files = \ AudioListener.webidl \ AudioNode.webidl \ AudioParam.webidl \ + AudioStreamTrack.webidl \ Attr.webidl \ BatteryManager.webidl \ BeforeUnloadEvent.webidl \ @@ -154,6 +155,7 @@ webidl_files = \ Location.webidl \ MediaError.webidl \ MediaStream.webidl \ + MediaStreamTrack.webidl \ MessageEvent.webidl \ MouseEvent.webidl \ MouseScrollEvent.webidl \ @@ -298,6 +300,7 @@ webidl_files = \ UndoManager.webidl \ URLUtils.webidl \ USSDReceivedEvent.webidl \ + VideoStreamTrack.webidl \ XMLDocument.webidl \ XMLHttpRequest.webidl \ XMLHttpRequestEventTarget.webidl \