Bug 834835. Part 1: Add initial AudioStreamTrack/VideoStreamTrack/MediaStreamTrack interfaces and implementations. r=jesup
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 27 Mar 2013 14:32:51 +1300
changeset 140674 925d5b6c917130f83634f3ea9d5ee71f98ce6c80
parent 140673 756845df58498845a082ff229a61c35d973265af
child 140675 86a8ca51e8471f77a0f3d6c52d5d06d8a6f76ed3
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs834835
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 834835. Part 1: Add initial AudioStreamTrack/VideoStreamTrack/MediaStreamTrack interfaces and implementations. r=jesup
content/media/AudioStreamTrack.cpp
content/media/AudioStreamTrack.h
content/media/Makefile.in
content/media/MediaStreamTrack.cpp
content/media/MediaStreamTrack.h
content/media/VideoStreamTrack.cpp
content/media/VideoStreamTrack.h
content/media/moz.build
dom/bindings/Bindings.conf
dom/webidl/AudioStreamTrack.webidl
dom/webidl/MediaStreamTrack.webidl
dom/webidl/VideoStreamTrack.webidl
dom/webidl/WebIDL.mk
new file mode 100644
--- /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);
+}
+
+}
+}
new file mode 100644
--- /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_ */
--- a/content/media/Makefile.in
+++ b/content/media/Makefile.in
@@ -11,34 +11,37 @@ include $(DEPTH)/config/autoconf.mk
 
 LIBRARY_NAME = gkconmedia_s
 LIBXUL_LIBRARY = 1
 ifndef _MSC_VER
 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)
 
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /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<nsIUUIDGenerator> 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);
+}
+
+}
+}
new file mode 100644
--- /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<DOMMediaStream> mStream;
+  TrackID mTrackID;
+  nsID mID;
+  bool mEnded;
+};
+
+}
+}
+
+#endif /* MEDIASTREAMTRACK_H_ */
new file mode 100644
--- /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);
+}
+
+}
+}
new file mode 100644
--- /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_ */
--- a/content/media/moz.build
+++ b/content/media/moz.build
@@ -69,8 +69,14 @@ EXPORTS += [
     'StreamBuffer.h',
     'TimeVarying.h',
     'VideoFrameContainer.h',
     'VideoSegment.h',
     'VideoUtils.h',
     'VorbisUtils.h',
 ]
 
+EXPORTS.mozilla.dom += [
+    'AudioStreamTrack.h',
+    'MediaStreamTrack.h',
+    'VideoStreamTrack.h',
+]
+
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -125,16 +125,19 @@ DOMInterfaces = {
 'AudioProcessingEvent' : {
     'resultNotAddRefed': [ 'inputBuffer', 'outputBuffer' ],
 },
 
 'BeforeUnloadEvent': {
     'nativeType': 'nsDOMBeforeUnloadEvent',
 },
 
+'AudioStreamTrack': {
+},
+
 'BiquadFilterNode': {
     'resultNotAddRefed': [ 'frequency', 'q', 'gain' ],
 },
 
 'Blob': [
 {
     'headerFile': 'nsIDOMFile.h',
 },
@@ -556,16 +559,21 @@ DOMInterfaces = {
 {
     'workers': True,
 }],
 
 'KeyEvent': {
     'nativeType': 'nsDOMKeyboardEvent',
 },
 
+'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.
     'nativeType': 'nsIDOMLocation',
     'skipGen': True,
     'register': False
 },
 
@@ -574,29 +582,28 @@ DOMInterfaces = {
     'nativeType': 'mozilla::DOMMediaStream'
 },
 {
     'nativeType': 'JSObject',
     'workers': True,
     'skipGen': True
 }],
 
-'LocalMediaStream': {
-    'headerFile': 'DOMMediaStream.h',
-    'nativeType': 'mozilla::DOMLocalMediaStream'
-},
-
 'MediaStreamList': {
     'headerFile': 'MediaStreamList.h',
     'wrapperCache': False,
     'nativeOwnership': 'owned',
     'resultNotAddRefed': [ '__indexedGetter' ],
     'binaryNames': { '__indexedGetter': 'IndexedGetter' }
 },
 
+'MediaStreamTrack': {
+    'concrete': False
+},
+
 'MessageEvent': {
     'nativeType': 'nsDOMMessageEvent',
 },
 
 'MouseEvent': {
     'nativeType': 'nsDOMMouseEvent',
     'hasXPConnectImpls': True,
 },
@@ -1040,16 +1047,19 @@ DOMInterfaces = {
 'URL' : [{
     'concrete': False,
 },
 {
     'implicitJSContext': [ 'createObjectURL', 'revokeObjectURL' ],
     'workers': True,
 }],
 
+'VideoStreamTrack': {
+},
+
 'WebGLActiveInfo': {
    'nativeType': 'mozilla::WebGLActiveInfo',
    'headerFile': 'WebGLContext.h',
    'wrapperCache': False
 },
 
 'WebGLBuffer': {
    'nativeType': 'mozilla::WebGLBuffer',
new file mode 100644
--- /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<DOMString> getSourceIds ();
+};
new file mode 100644
--- /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 ();
+};
new file mode 100644
--- /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<DOMString> getSourceIds ();
+//    void                       takePhoto ();
+//                attribute EventHandler onphoto;
+//                attribute EventHandler onphotoerror;
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -16,16 +16,17 @@ webidl_files = \
   Attr.webidl \
   AudioBuffer.webidl \
   AudioBufferSourceNode.webidl \
   AudioContext.webidl \
   AudioDestinationNode.webidl \
   AudioListener.webidl \
   AudioNode.webidl \
   AudioParam.webidl \
+  AudioStreamTrack.webidl \
   AudioProcessingEvent.webidl \
   BatteryManager.webidl \
   BeforeUnloadEvent.webidl \
   BiquadFilterNode.webidl \
   Blob.webidl \
   CanvasRenderingContext2D.webidl \
   CaretPosition.webidl \
   CDATASection.webidl \
@@ -152,16 +153,17 @@ webidl_files = \
   ImageData.webidl \
   InspectorUtils.webidl \
   KeyEvent.webidl \
   LinkStyle.webidl \
   LocalMediaStream.webidl \
   Location.webidl \
   MediaError.webidl \
   MediaStream.webidl \
+  MediaStreamTrack.webidl \
   MessageEvent.webidl \
   MouseEvent.webidl \
   MouseScrollEvent.webidl \
   MozActivity.webidl \
   MutationEvent.webidl \
   MutationObserver.webidl \
   NetDashboard.webidl \
   Node.webidl \
@@ -300,16 +302,17 @@ webidl_files = \
   URL.webidl \
   ValidityState.webidl \
   WebComponents.webidl \
   WebSocket.webidl \
   WheelEvent.webidl \
   UndoManager.webidl \
   URLUtils.webidl \
   USSDReceivedEvent.webidl \
+  VideoStreamTrack.webidl \
   XMLDocument.webidl \
   XMLHttpRequest.webidl \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \
   XMLStylesheetProcessingInstruction.webidl \
   XPathEvaluator.webidl \
   XULCommandEvent.webidl \