Bug 1213131 - [vpx] Configure libvpx decoder to use multi-threads decoding. r=kentuckyfriedtakahe, a=lizzard
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 09 Oct 2015 11:13:52 +1100
changeset 296544 e964dd4baeb916d0db9e1409ea2575df35868810
parent 296543 e74341409f6531e556fee406d6a0fe2e8b66ef1c
child 296545 d817942ac0b7394df73800914d5b02729468ca39
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe, lizzard
bugs1213131
milestone43.0a2
Bug 1213131 - [vpx] Configure libvpx decoder to use multi-threads decoding. r=kentuckyfriedtakahe, a=lizzard
dom/media/platforms/agnostic/VPXDecoder.cpp
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -4,16 +4,17 @@
  * 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 "VPXDecoder.h"
 #include "gfx2DGlue.h"
 #include "nsError.h"
 #include "TimeUnits.h"
 #include "mozilla/PodOperations.h"
+#include "prsystem.h"
 
 #include <algorithm>
 
 #undef LOG
 extern PRLogModuleInfo* GetPDMLog();
 #define LOG(arg, ...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, ("VPXDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
 namespace mozilla {
@@ -51,23 +52,36 @@ VPXDecoder::Shutdown()
 {
   vpx_codec_destroy(&mVPX);
   return NS_OK;
 }
 
 nsRefPtr<MediaDataDecoder::InitPromise>
 VPXDecoder::Init()
 {
+  int decode_threads = 2;
+
   vpx_codec_iface_t* dx = nullptr;
   if (mCodec == Codec::VP8) {
     dx = vpx_codec_vp8_dx();
   } else if (mCodec == Codec::VP9) {
     dx = vpx_codec_vp9_dx();
+    if (mInfo.mDisplay.width >= 2048) {
+      decode_threads = 8;
+    } else if (mInfo.mDisplay.width >= 1024) {
+      decode_threads = 4;
+    }
   }
-  if (!dx || vpx_codec_dec_init(&mVPX, dx, nullptr, 0)) {
+  decode_threads = std::min(decode_threads, PR_GetNumberOfProcessors());
+
+  vpx_codec_dec_cfg_t config;
+  config.threads = decode_threads;
+  config.w = config.h = 0; // set after decode
+
+  if (!dx || vpx_codec_dec_init(&mVPX, dx, &config, 0)) {
     return InitPromise::CreateAndReject(DecoderFailureReason::INIT_ERROR, __func__);
   }
   return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
 }
 
 nsresult
 VPXDecoder::Flush()
 {