Bug 1444976 - Decide how many threads to use in the threadpool using the number of threads the machine can run. DO NOT LAND
MozReview-Commit-ID: LlLCKjeJ6Ez
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -1,14 +1,16 @@
/* 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 "VideoUtils.h"
+#include <unistd.h>
+
#include "ImageContainer.h"
#include "MediaContainerType.h"
#include "MediaPrefs.h"
#include "MediaResource.h"
#include "TimeUnits.h"
#include "VorbisUtils.h"
#include "mozilla/Base64.h"
#include "mozilla/SharedThreadPool.h"
@@ -211,17 +213,33 @@ already_AddRefed<SharedThreadPool> GetMe
break;
default:
MOZ_FALLTHROUGH_ASSERT("Unexpected MediaThreadType");
case MediaThreadType::PLAYBACK:
name = "MediaPlayback";
break;
}
- static const uint32_t kMediaThreadPoolDefaultCount = 4;
+
+ static uint32_t ncpus = 0;
+
+ if (ncpus == 0) {
+#if defined(_SC_NPROCESSORS_CONF)
+ long n = sysconf(_SC_NPROCESSORS_CONF);
+ ncpus = (n > 0) ? uint32_t(n) : 1;
+#elif defined(_SC_NPROCESSORS_ONLN)
+ long n = sysconf(_SC_NPROCESSORS_ONLN);
+ ncpus = (n > 0) ? uint32_t(n) : 1;
+#else
+ ncpus = 1;
+#endif
+ }
+
+ // - 1 for main thread - 1 for audio thread
+ static const uint32_t kMediaThreadPoolDefaultCount = ncpus - 2;
return SharedThreadPool::
Get(nsDependentCString(name), kMediaThreadPoolDefaultCount);
}
bool
ExtractVPXCodecDetails(const nsAString& aCodec,
uint8_t& aProfile,
uint8_t& aLevel,