bug 1037488 - MediaEngineTabVideoSource should set width, height and framerate based on constraints and prefs passed to Allocate() r=jesup
authorBrad Lassey <blassey@mozilla.com>
Fri, 11 Jul 2014 11:55:23 -0400
changeset 216118 37c80d91bed8ba3426049e90eeaabc981a5c31de
parent 216117 62c58a6ce205799eb0044df3944e1c7dc2205fb4
child 216119 6d8b7bbf1228800bbf7a9f57e001663587fd98b6
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1037488
milestone33.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 1037488 - MediaEngineTabVideoSource should set width, height and framerate based on constraints and prefs passed to Allocate() r=jesup
content/media/webrtc/MediaEngineTabVideoSource.cpp
modules/libpref/src/init/all.js
--- a/content/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/content/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -17,20 +17,22 @@
 #include "ImageContainer.h"
 #include "Layers.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIDOMDocument.h"
 #include "nsITabSource.h"
 #include "VideoUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIPrefService.h"
+#include "MediaTrackConstraints.h"
 
 namespace mozilla {
 
 using namespace mozilla::gfx;
+using dom::ConstrainLongRange;
 
 NS_IMPL_ISUPPORTS(MediaEngineTabVideoSource, nsIDOMEventListener, nsITimerCallback)
 
 MediaEngineTabVideoSource::MediaEngineTabVideoSource()
 : mMonitor("MediaEngineTabVideoSource")
 {
 }
 
@@ -71,31 +73,24 @@ MediaEngineTabVideoSource::HandleEvent(n
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MediaEngineTabVideoSource::Notify(nsITimer*) {
   Draw();
   return NS_OK;
 }
+#define LOGTAG "TabVideo"
 
 nsresult
 MediaEngineTabVideoSource::InitRunnable::Run()
 {
-  nsresult rv;
-  nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
-  if (!branch)
-    return NS_OK;
-  branch->GetIntPref("media.tabstreaming.width", &mVideoSource->mBufW);
-  branch->GetIntPref("media.tabstreaming.height", &mVideoSource->mBufH);
-  branch->GetIntPref("media.tabstreaming.time_per_frame", &mVideoSource->mTimePerFrame);
   mVideoSource->mData = (unsigned char*)malloc(mVideoSource->mBufW * mVideoSource->mBufH * 4);
 
+  nsresult rv;
   mVideoSource->mTabSource = do_GetService(NS_TABSOURCESERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMWindow> win;
   rv = mVideoSource->mTabSource->GetTabToStream(getter_AddRefs(win));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!win)
     return NS_OK;
@@ -114,19 +109,51 @@ MediaEngineTabVideoSource::GetName(nsASt
 
 void
 MediaEngineTabVideoSource::GetUUID(nsAString_internal& aUuid)
 {
   aUuid.AssignLiteral(MOZ_UTF16("uuid"));
 }
 
 nsresult
-MediaEngineTabVideoSource::Allocate(const VideoTrackConstraintsN&,
-                                    const MediaEnginePrefs&)
+MediaEngineTabVideoSource::Allocate(const VideoTrackConstraintsN& aConstraints,
+                                    const MediaEnginePrefs& aPrefs)
 {
+
+  ConstrainLongRange cWidth(aConstraints.mRequired.mWidth);
+  ConstrainLongRange cHeight(aConstraints.mRequired.mHeight);
+
+  if (aConstraints.mAdvanced.WasPassed()) {
+    const auto& advanced = aConstraints.mAdvanced.Value();
+    for (uint32_t i = 0; i < advanced.Length(); i++) {
+      if (cWidth.mMax >= advanced[i].mWidth.mMin && cWidth.mMin <= advanced[i].mWidth.mMax &&
+	  cHeight.mMax >= advanced[i].mHeight.mMin && cHeight.mMin <= advanced[i].mHeight.mMax) {
+	cWidth.mMin = std::max(cWidth.mMin, advanced[i].mWidth.mMin);
+	cHeight.mMin = std::max(cHeight.mMin, advanced[i].mHeight.mMin);
+      }
+    }
+  }
+
+  mBufW = aPrefs.GetWidth(false);
+  mBufH = aPrefs.GetHeight(false);
+
+  if (cWidth.mMin > mBufW) {
+    mBufW = cWidth.mMin;
+  } else if (cWidth.mMax < mBufW) {
+    mBufW = cWidth.mMax;
+  }
+
+  if (cHeight.mMin > mBufH) {
+    mBufH = cHeight.mMin;
+  } else if (cHeight.mMax < mBufH) {
+    mBufH = cHeight.mMax;
+  }
+
+  mTimePerFrame = aPrefs.mFPS ? 1000 / aPrefs.mFPS : aPrefs.mFPS;
+
   return NS_OK;
 }
 
 nsresult
 MediaEngineTabVideoSource::Deallocate()
 {
   return NS_OK;
 }
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -352,20 +352,16 @@ pref("media.peerconnection.capture_delay
 pref("media.getusermedia.playout_delay", 50);
 #endif
 #else
 #ifdef ANDROID
 pref("media.navigator.enabled", true);
 #endif
 #endif
 
-pref("media.tabstreaming.width", 320);
-pref("media.tabstreaming.height", 240);
-pref("media.tabstreaming.time_per_frame", 40);
-
 // TextTrack support
 pref("media.webvtt.enabled", true);
 pref("media.webvtt.regions.enabled", false);
 
 // AudioTrack and VideoTrack support
 pref("media.track.enabled", false);
 
 // Whether to enable MediaSource support