Bug 1496529 - P10. Add to libvpx decoder low latency mode. r=bryce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 09 Oct 2018 22:59:47 +0000
changeset 496094 b3a1baa85807cc175fd2d2b49d21408ea55e5e21
parent 496093 ea2cd3e66c564ab1f64c33b3ea8ce5924b3b6a79
child 496095 2247311dfb80693ddcf1b9d62cb3448d91af198a
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1496529
milestone64.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 1496529 - P10. Add to libvpx decoder low latency mode. r=bryce Depends on D7909 Differential Revision: https://phabricator.services.mozilla.com/D7917
dom/media/platforms/agnostic/VPXDecoder.cpp
dom/media/platforms/agnostic/VPXDecoder.h
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -34,17 +34,18 @@ static VPXDecoder::Codec MimeTypeToCodec
     return VPXDecoder::Codec::VP9;
   }
   return VPXDecoder::Codec::Unknown;
 }
 
 static nsresult
 InitContext(vpx_codec_ctx_t* aCtx,
             const VideoInfo& aInfo,
-            const VPXDecoder::Codec aCodec)
+            const VPXDecoder::Codec aCodec,
+            bool aLowLatency)
 {
   int decode_threads = 2;
 
   vpx_codec_iface_t* dx = nullptr;
   if (aCodec == VPXDecoder::Codec::VP8) {
     dx = vpx_codec_vp8_dx();
   }
   else if (aCodec == VPXDecoder::Codec::VP9) {
@@ -54,31 +55,33 @@ InitContext(vpx_codec_ctx_t* aCtx,
     }
     else if (aInfo.mDisplay.width >= 1024) {
       decode_threads = 4;
     }
   }
   decode_threads = std::min(decode_threads, PR_GetNumberOfProcessors());
 
   vpx_codec_dec_cfg_t config;
-  config.threads = decode_threads;
+  config.threads = aLowLatency ? 1 : decode_threads;
   config.w = config.h = 0; // set after decode
 
   if (!dx || vpx_codec_dec_init(aCtx, dx, &config, 0)) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 VPXDecoder::VPXDecoder(const CreateDecoderParams& aParams)
   : mImageContainer(aParams.mImageContainer)
   , mImageAllocator(aParams.mKnowsCompositor)
   , mTaskQueue(aParams.mTaskQueue)
   , mInfo(aParams.VideoConfig())
   , mCodec(MimeTypeToCodec(aParams.VideoConfig().mMimeType))
+  , mLowLatency(
+      aParams.mOptions.contains(CreateDecoderParams::Option::LowLatency))
 {
   MOZ_COUNT_CTOR(VPXDecoder);
   PodZero(&mVPX);
   PodZero(&mVPXAlpha);
 }
 
 VPXDecoder::~VPXDecoder()
 {
@@ -94,22 +97,22 @@ VPXDecoder::Shutdown()
     vpx_codec_destroy(&self->mVPXAlpha);
     return ShutdownPromise::CreateAndResolve(true, __func__);
   });
 }
 
 RefPtr<MediaDataDecoder::InitPromise>
 VPXDecoder::Init()
 {
-  if (NS_FAILED(InitContext(&mVPX, mInfo, mCodec))) {
+  if (NS_FAILED(InitContext(&mVPX, mInfo, mCodec, mLowLatency))) {
     return VPXDecoder::InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                                                     __func__);
   }
   if (mInfo.HasAlpha()) {
-    if (NS_FAILED(InitContext(&mVPXAlpha, mInfo, mCodec))) {
+    if (NS_FAILED(InitContext(&mVPXAlpha, mInfo, mCodec, mLowLatency))) {
       return VPXDecoder::InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                                                       __func__);
     }
   }
   return VPXDecoder::InitPromise::CreateAndResolve(TrackInfo::kVideoTrack,
                                                    __func__);
 }
 
--- a/dom/media/platforms/agnostic/VPXDecoder.h
+++ b/dom/media/platforms/agnostic/VPXDecoder.h
@@ -73,13 +73,14 @@ private:
   vpx_codec_ctx_t mVPX;
 
   // VPx alpha decoder state
   vpx_codec_ctx_t mVPXAlpha;
 
   const VideoInfo& mInfo;
 
   const Codec mCodec;
+  const bool mLowLatency;
 };
 
 } // namespace mozilla
 
 #endif