Bug 1389980 - Remove MP4Decoder::IsVideoAccelerated() as it is unused. r?mattwoodrow draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 15 Aug 2017 10:15:43 +1200
changeset 648541 c631ca2f486938a6cb948eb43c753edc8ac534bb
parent 648398 4659a73a3f86121689ae71a6e9d25335d63fcd74
child 648542 d3c430b295f0193cd1efdb9bb17170c29b926ba3
push id74785
push userbmo:cpearce@mozilla.com
push dateThu, 17 Aug 2017 22:39:47 +0000
reviewersmattwoodrow
bugs1389980
milestone57.0a1
Bug 1389980 - Remove MP4Decoder::IsVideoAccelerated() as it is unused. r?mattwoodrow MozReview-Commit-ID: Eg0ggufsqDt
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -23,19 +23,16 @@
 #include "mozilla/dom/Touch.h"
 #include "mozilla/PendingAnimationTracker.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsFrame.h"
 #include "mozilla/layers/ShadowLayers.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
 #include "ClientLayerManager.h"
 #include "nsQueryObject.h"
-#ifdef MOZ_FMP4
-#include "MP4Decoder.h"
-#endif
 #include "CubebUtils.h"
 
 #include "nsIScrollableFrame.h"
 
 #include "nsContentUtils.h"
 
 #include "nsIFrame.h"
 #include "nsIWidget.h"
@@ -2470,45 +2467,16 @@ nsDOMWindowUtils::GetUsingAdvancedLayers
   *retval = false;
   if (KnowsCompositor* fwd = mgr->AsKnowsCompositor()) {
     *retval = fwd->GetTextureFactoryIdentifier().mUsingAdvancedLayers;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::GetSupportsHardwareH264Decoding(JS::MutableHandle<JS::Value> aPromise)
-{
-  nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
-  NS_ENSURE_STATE(window);
-  nsCOMPtr<nsIGlobalObject> parentObject =
-    do_QueryInterface(window->GetCurrentInnerWindow());
-  NS_ENSURE_STATE(parentObject);
-#ifdef MOZ_FMP4
-  nsCOMPtr<nsIWidget> widget = GetWidget();
-  NS_ENSURE_STATE(widget);
-  LayerManager *mgr = widget->GetLayerManager();
-  NS_ENSURE_STATE(mgr);
-  RefPtr<Promise> promise =
-    MP4Decoder::IsVideoAccelerated(mgr->AsKnowsCompositor(), parentObject);
-  NS_ENSURE_STATE(promise);
-  aPromise.setObject(*promise->PromiseObj());
-#else
-  ErrorResult rv;
-  RefPtr<Promise> promise = Promise::Create(parentObject, rv);
-  if (rv.Failed()) {
-    return rv.StealNSResult();
-  }
-  promise->MaybeResolve(NS_LITERAL_STRING("No; Compiled without MP4 support."));
-  aPromise.setObject(*promise->PromiseObj());
-#endif
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentAudioBackend(nsAString& aBackend)
 {
   CubebUtils::GetCurrentBackend(aBackend);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentMaxAudioChannels(uint32_t* aChannels)
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1417,24 +1417,16 @@ interface nsIDOMWindowUtils : nsISupport
   readonly attribute boolean layerManagerRemote;
 
   /**
    * True if advanced layers is enabled on this window, false otherwise.
    */
   readonly attribute boolean usingAdvancedLayers;
 
   /**
-   * Returns a Promise that will be resolved with a string once the capabilities
-   * of the h264 decoder have been determined.
-   * Success does not mean that all h264 video decoding will be done
-   * in hardware.
-   */
-  readonly attribute jsval supportsHardwareH264Decoding;
-
-  /**
    * Returns the current audio backend as a free-form string.
    */
   readonly attribute AString currentAudioBackend;
 
   /**
    * Returns the max channel counts of the current audio device.
    */
   readonly attribute unsigned long currentMaxAudioChannels;
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -1,22 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "MP4Decoder.h"
 #include "MediaContainerType.h"
-#include "MediaFormatReader.h"
 #include "MP4Demuxer.h"
 #include "nsMimeTypes.h"
-#include "mozilla/SharedThreadPool.h"
 #include "VideoUtils.h"
-
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 static bool
 IsWhitelistedH264Codec(const nsAString& aCodec)
 {
   int16_t profile = 0, level = 0;
@@ -163,113 +160,9 @@ MP4Decoder::IsAAC(const nsACString& aMim
 
 /* static */
 bool
 MP4Decoder::IsEnabled()
 {
   return MediaPrefs::MP4Enabled();
 }
 
-// sTestH264ExtraData represents the content of the avcC atom found in
-// an AVC1 h264 video. It contains the H264 SPS and PPS NAL.
-// the structure of the avcC atom is as follow:
-// write(0x1);  // version, always 1
-// write(sps[0].data[1]); // profile
-// write(sps[0].data[2]); // compatibility
-// write(sps[0].data[3]); // level
-// write(0xFC | 3); // reserved (6 bits), NULA length size - 1 (2 bits)
-// write(0xE0 | 1); // reserved (3 bits), num of SPS (5 bits)
-// write_word(sps[0].size); // 2 bytes for length of SPS
-// for(size_t i=0 ; i < sps[0].size ; ++i)
-//   write(sps[0].data[i]); // data of SPS
-// write(&b, pps.size());  // num of PPS
-// for(size_t i=0 ; i < pps.size() ; ++i) {
-//   write_word(pps[i].size);  // 2 bytes for length of PPS
-//   for(size_t j=0 ; j < pps[i].size ; ++j)
-//     write(pps[i].data[j]);  // data of PPS
-//   }
-// }
-// here we have a h264 Baseline, 640x360
-// We use a 640x360 extradata, as some video framework (Apple VT) will never
-// attempt to use hardware decoding for small videos.
-static const uint8_t sTestH264ExtraData[] = {
-  0x01, 0x42, 0xc0, 0x1e, 0xff, 0xe1, 0x00, 0x17, 0x67, 0x42,
-  0xc0, 0x1e, 0xbb, 0x40, 0x50, 0x17, 0xfc, 0xb8, 0x08, 0x80,
-  0x00, 0x00, 0x32, 0x00, 0x00, 0x0b, 0xb5, 0x07, 0x8b, 0x17,
-  0x50, 0x01, 0x00, 0x04, 0x68, 0xce, 0x32, 0xc8
-};
-
-static already_AddRefed<MediaDataDecoder>
-CreateTestH264Decoder(layers::KnowsCompositor* aKnowsCompositor,
-                      VideoInfo& aConfig,
-                      TaskQueue* aTaskQueue)
-{
-  aConfig.mMimeType = "video/avc";
-  aConfig.mId = 1;
-  aConfig.mDuration = media::TimeUnit::FromMicroseconds(40000);
-  aConfig.mImage = aConfig.mDisplay = nsIntSize(640, 360);
-  aConfig.mExtraData = new MediaByteBuffer();
-  aConfig.mExtraData->AppendElements(sTestH264ExtraData,
-                                     MOZ_ARRAY_LENGTH(sTestH264ExtraData));
-
-  RefPtr<PDMFactory> platform = new PDMFactory();
-  RefPtr<MediaDataDecoder> decoder(platform->CreateDecoder({ aConfig, aTaskQueue, aKnowsCompositor }));
-
-  return decoder.forget();
-}
-
-/* static */ already_AddRefed<dom::Promise>
-MP4Decoder::IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  ErrorResult rv;
-  RefPtr<dom::Promise> promise;
-  promise = dom::Promise::Create(aParent, rv);
-  if (rv.Failed()) {
-    rv.SuppressException();
-    return nullptr;
-  }
-
-  RefPtr<TaskQueue> taskQueue = new TaskQueue(
-    GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
-    "MP4Decoder::IsVideoAccelerated::taskQueue");
-  VideoInfo config;
-  RefPtr<MediaDataDecoder> decoder(CreateTestH264Decoder(aKnowsCompositor, config, taskQueue));
-  if (!decoder) {
-    taskQueue->BeginShutdown();
-    taskQueue->AwaitShutdownAndIdle();
-    promise->MaybeResolve(NS_LITERAL_STRING("No; Failed to create H264 decoder"));
-    return promise.forget();
-  }
-
-  decoder->Init()
-    ->Then(aParent->AbstractMainThreadFor(TaskCategory::Other),
-           __func__,
-           [promise, decoder, taskQueue] (TrackInfo::TrackType aTrack) {
-             nsCString failureReason;
-             bool ok = decoder->IsHardwareAccelerated(failureReason);
-             nsAutoString result;
-             if (ok) {
-               result.AssignLiteral("Yes");
-             } else {
-               result.AssignLiteral("No");
-             }
-             if (failureReason.Length()) {
-               result.AppendLiteral("; ");
-               AppendUTF8toUTF16(failureReason, result);
-             }
-             decoder->Shutdown();
-             taskQueue->BeginShutdown();
-             taskQueue->AwaitShutdownAndIdle();
-             promise->MaybeResolve(result);
-           },
-           [promise, decoder, taskQueue] (MediaResult aError) {
-             decoder->Shutdown();
-             taskQueue->BeginShutdown();
-             taskQueue->AwaitShutdownAndIdle();
-             promise->MaybeResolve(NS_LITERAL_STRING("No; Failed to initialize H264 decoder"));
-           });
-
-  return promise.forget();
-}
-
 } // namespace mozilla
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -2,18 +2,16 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 #if !defined(MP4Decoder_h_)
 #define MP4Decoder_h_
 
 class nsACString;
-#include "mozilla/dom/Promise.h"
-#include "mozilla/layers/KnowsCompositor.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 class DecoderDoctorDiagnostics;
 
 // Decoder that uses a bundled MP4 demuxer and platform decoders to play MP4.
 class MP4Decoder
@@ -36,16 +34,13 @@ public:
   // Return true if aMimeType is a one of the strings used by our demuxers to
   // identify AAC. Does not parse general content type strings, i.e. white
   // space matters.
   static bool IsAAC(const nsACString& aMimeType);
 
   // Returns true if the MP4 backend is preffed on.
   static bool IsEnabled();
 
-  static already_AddRefed<dom::Promise>
-  IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent);
-
 };
 
 } // namespace mozilla
 
 #endif