Bug 834835. Part 3: Implement DOMMediaStream::GetAudio/VideoTracks. r=jesup
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 17 Apr 2013 17:18:37 +1200
changeset 140676 fed72d279071f52843a91437c948eb895f81f4b8
parent 140675 86a8ca51e8471f77a0f3d6c52d5d06d8a6f76ed3
child 140677 1065d2c7fd37106d09b5aab55a8eda530903c792
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 3: Implement DOMMediaStream::GetAudio/VideoTracks. r=jesup
content/media/DOMMediaStream.cpp
content/media/DOMMediaStream.h
dom/webidl/MediaStream.webidl
--- a/content/media/DOMMediaStream.cpp
+++ b/content/media/DOMMediaStream.cpp
@@ -124,16 +124,38 @@ DOMMediaStream::WrapObject(JSContext* aC
 }
 
 double
 DOMMediaStream::CurrentTime()
 {
   return mStream ? MediaTimeToSeconds(mStream->GetCurrentTime()) : 0.0;
 }
 
+void
+DOMMediaStream::GetAudioTracks(nsTArray<nsRefPtr<AudioStreamTrack> >& aTracks)
+{
+  for (uint32_t i = 0; i < mTracks.Length(); ++i) {
+    AudioStreamTrack* t = mTracks[i]->AsAudioStreamTrack();
+    if (t) {
+      aTracks.AppendElement(t);
+    }
+  }
+}
+
+void
+DOMMediaStream::GetVideoTracks(nsTArray<nsRefPtr<VideoStreamTrack> >& aTracks)
+{
+  for (uint32_t i = 0; i < mTracks.Length(); ++i) {
+    VideoStreamTrack* t = mTracks[i]->AsVideoStreamTrack();
+    if (t) {
+      aTracks.AppendElement(t);
+    }
+  }
+}
+
 bool
 DOMMediaStream::IsFinished()
 {
   return !mStream || mStream->IsFinished();
 }
 
 void
 DOMMediaStream::InitSourceStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
--- a/content/media/DOMMediaStream.h
+++ b/content/media/DOMMediaStream.h
@@ -28,41 +28,49 @@ class nsXPCClassInfo;
 #endif
 
 namespace mozilla {
 
 class MediaStream;
 
 namespace dom {
 class MediaStreamTrack;
+class AudioStreamTrack;
+class VideoStreamTrack;
 }
 
 /**
  * DOM wrapper for MediaStreams.
  */
 class DOMMediaStream : public nsIDOMMediaStream,
                        public nsWrapperCache
 {
   friend class DOMLocalMediaStream;
   typedef dom::MediaStreamTrack MediaStreamTrack;
+  typedef dom::AudioStreamTrack AudioStreamTrack;
+  typedef dom::VideoStreamTrack VideoStreamTrack;
 
 public:
   DOMMediaStream();
   virtual ~DOMMediaStream();
 
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMMediaStream)
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   nsIDOMWindow* GetParentObject() const
   {
     return mWindow;
   }
   virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
 
+  // WebIDL
   double CurrentTime();
+  void GetAudioTracks(nsTArray<nsRefPtr<AudioStreamTrack> >& aTracks);
+  void GetVideoTracks(nsTArray<nsRefPtr<VideoStreamTrack> >& aTracks);
+
   MediaStream* GetStream() { return mStream; }
   bool IsFinished();
   /**
    * 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; }
 
--- a/dom/webidl/MediaStream.webidl
+++ b/dom/webidl/MediaStream.webidl
@@ -7,18 +7,18 @@
  * 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 MediaStream {
     // readonly attribute DOMString    id;
-    // sequence<MediaStreamTrack> getAudioTracks ();
-    // sequence<MediaStreamTrack> getVideoTracks ();
+    sequence<AudioStreamTrack> getAudioTracks ();
+    sequence<VideoStreamTrack> getVideoTracks ();
     // MediaStreamTrack           getTrackById (DOMString trackId);
     // void                       addTrack (MediaStreamTrack track);
     // void                       removeTrack (MediaStreamTrack track);
     //         attribute boolean      ended;
     //         attribute EventHandler onended;
     //         attribute EventHandler onaddtrack;
     //         attribute EventHandler onremovetrack;
 	readonly attribute double currentTime;