Bug 792188: Add hints to MediaStreams to help with generating signaling r=jesup
authorAnant Narayanan <anant@kix.in>
Sun, 07 Oct 2012 01:34:30 -0400
changeset 109561 2b08abdcc8a9de9e9b03d5e6f8961d1103376225
parent 109560 a8fac69129b0bac8b55e33574f4c4338d494b150
child 109562 b40fe6bb9b908ff260091f0c5703645ee8944f4c
push id23632
push userphilringnalda@gmail.com
push dateSun, 07 Oct 2012 19:14:37 +0000
treeherdermozilla-central@83d38854c21e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs792188
milestone18.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 792188: Add hints to MediaStreams to help with generating signaling r=jesup
content/media/nsDOMMediaStream.h
dom/media/MediaManager.cpp
--- a/content/media/nsDOMMediaStream.h
+++ b/content/media/nsDOMMediaStream.h
@@ -21,17 +21,17 @@
 /**
  * DOM wrapper for MediaStreams.
  */
 class nsDOMMediaStream : public nsIDOMMediaStream
 {
   typedef mozilla::MediaStream MediaStream;
 
 public:
-  nsDOMMediaStream() : mStream(nullptr) {}
+  nsDOMMediaStream() : mStream(nullptr), mHintContents(0) {}
   virtual ~nsDOMMediaStream();
 
   NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMMediaStream)
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   NS_DECL_NSIDOMMEDIASTREAM
 
   MediaStream* GetStream() { return mStream; }
@@ -48,25 +48,38 @@ public:
    * of this stream can only be accessed by principals that subsume aPrincipal.
    * Returns true if the stream's principal changed.
    */
   bool CombineWithPrincipal(nsIPrincipal* aPrincipal);
 
   /**
    * Create an nsDOMMediaStream whose underlying stream is a SourceMediaStream.
    */
-  static already_AddRefed<nsDOMMediaStream> CreateInputStream();
+  static already_AddRefed<nsDOMMediaStream> CreateInputStream(uint32_t aHintContents);
+
+  // 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; }
 
   /**
    * Create an nsDOMMediaStream whose underlying stream is a TrackUnionStream.
    */
   static already_AddRefed<nsDOMMediaStream> CreateTrackUnionStream();
 
 protected:
   // 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;
+
+  // tells the SDP generator about whether this
+  // MediaStream probably has audio and/or video
+  uint32_t mHintContents;
 };
 
 #endif /* NSDOMMEDIASTREAM_H_ */
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -21,16 +21,23 @@
 /* Using WebRTC backend on Desktops (Mac, Windows, Linux), otherwise default */
 #include "MediaEngineDefault.h"
 #if defined(MOZ_WEBRTC)
 #include "MediaEngineWebRTC.h"
 #endif
 
 namespace mozilla {
 
+// We only support 1 audio and 1 video track for now.
+enum {
+  kVideoTrack = 1,
+  kAudioTrack = 2
+};
+
+
 /**
  * Send an error back to content. The error is the form a string.
  * Do this only on the main thread. The success callback is also passed here
  * so it can be released correctly.
  */
 class ErrorCallbackRunnable : public nsRunnable
 {
 public:
@@ -214,17 +221,26 @@ public:
   ~GetUserMediaStreamRunnable() {}
 
   NS_IMETHOD
   Run()
   {
     NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
     // Create a media stream.
-    nsCOMPtr<nsDOMMediaStream> stream = nsDOMMediaStream::CreateInputStream();
+    nsCOMPtr<nsDOMMediaStream> stream;
+    if (mTrackID == kVideoTrack) {
+      stream = nsDOMMediaStream::CreateInputStream(
+        nsDOMMediaStream::HINT_CONTENTS_VIDEO
+      );
+    } else {
+      stream = nsDOMMediaStream::CreateInputStream(
+        nsDOMMediaStream::HINT_CONTENTS_AUDIO
+      );
+    }
 
     nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
       (nsGlobalWindow::GetInnerWindowWithId(mWindowID));
 
     if (window && window->GetExtantDoc()) {
       stream->CombineWithPrincipal(window->GetExtantDoc()->NodePrincipal());
     }
 
@@ -324,22 +340,16 @@ public:
     , mBackend(aBackend) {}
 
   ~GetUserMediaRunnable() {
     if (mBackendChosen) {
       delete mBackend;
     }
   }
 
-  // We only support 1 audio and 1 video track for now.
-  enum {
-    kVideoTrack = 1,
-    kAudioTrack = 2
-  };
-
   NS_IMETHOD
   Run()
   {
     NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
 
     mManager = MediaManager::Get();
 
     // Was a backend provided?