Bug 1330284 - Use MediaContentType in WaveDecoder - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 20 Dec 2016 19:09:41 +1100
changeset 374471 6437fa28aae1fe0a8d262fa5bed532ab1a4179d5
parent 374470 7350253f2484b6593a0f3db861be937915c6daa1
child 374472 a8b342ba64a33bd4a5fec8906afb67644896e681
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1330284
milestone53.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 1330284 - Use MediaContentType in WaveDecoder - r=jya MozReview-Commit-ID: DD8upS1VpAq
dom/media/DecoderTraits.cpp
dom/media/wave/WaveDecoder.cpp
dom/media/wave/WaveDecoder.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -108,23 +108,16 @@ DecoderTraits::IsMP4SupportedType(const 
 #ifdef MOZ_FMP4
   return MP4Decoder::IsSupportedType(aType, aDiagnostics);
 #else
   return false;
 #endif
 }
 
 static bool
-IsWaveSupportedType(const nsACString& aType,
-                    const nsAString& aCodecs = EmptyString())
-{
-  return WaveDecoder::CanHandleMediaType(aType, aCodecs);
-}
-
-static bool
 IsFlacSupportedType(const nsACString& aType,
                    const nsAString& aCodecs = EmptyString())
 {
   return FlacDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
 static
 CanPlayStatus
@@ -142,19 +135,18 @@ CanHandleCodecsType(const MediaContentTy
     if (OggDecoder::IsSupportedType(aType)) {
       return CANPLAY_YES;
     } else {
       // We can only reach this position if a particular codec was requested,
       // ogg is supported and working: the codec must be invalid.
       return CANPLAY_NO;
     }
   }
-  if (IsWaveSupportedType(mimeType.Type().AsString())) {
-    if (IsWaveSupportedType(aType.Type().AsString(),
-                            aType.ExtendedType().Codecs().AsString())) {
+  if (WaveDecoder::IsSupportedType(MediaContentType(mimeType))) {
+    if (WaveDecoder::IsSupportedType(aType)) {
       return CANPLAY_YES;
     } else {
       // We can only reach this position if a particular codec was requested,
       // ogg is supported and working: the codec must be invalid.
       return CANPLAY_NO;
     }
   }
 #if !defined(MOZ_OMX_WEBM_DECODER)
@@ -244,17 +236,17 @@ CanHandleMediaType(const MediaContentTyp
   }
 
   // Content type with just the MIME type/subtype, no codecs.
   const MediaContentType mimeType(aType.Type());
 
   if (OggDecoder::IsSupportedType(mimeType)) {
     return CANPLAY_MAYBE;
   }
-  if (IsWaveSupportedType(mimeType.Type().AsString())) {
+  if (WaveDecoder::IsSupportedType(mimeType)) {
     return CANPLAY_MAYBE;
   }
 #ifdef MOZ_FMP4
   if (MP4Decoder::IsSupportedType(mimeType, aDiagnostics)) {
     return CANPLAY_MAYBE;
   }
 #endif
 #if !defined(MOZ_OMX_WEBM_DECODER)
@@ -297,17 +289,17 @@ DecoderTraits::CanHandleContentType(cons
 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
                                           DecoderDoctorDiagnostics* aDiagnostics)
 {
   Maybe<MediaContentType> contentType = MakeMediaContentType(aMIMEType);
   if (!contentType) {
     return false;
   }
 
-  if (IsWaveSupportedType(contentType->Type().AsString())) {
+  if (WaveDecoder::IsSupportedType(*contentType)) {
     // We should not return true for Wave types, since there are some
     // Wave codecs actually in use in the wild that we don't support, and
     // we should allow those to be handled by plugins or helper apps.
     // Furthermore people can play Wave files on most platforms by other
     // means.
     return false;
   }
 
@@ -348,17 +340,17 @@ InstantiateDecoder(const MediaContentTyp
   if (ADTSDecoder::IsSupportedType(aType)) {
     decoder = new ADTSDecoder(aOwner);
     return decoder.forget();
   }
   if (OggDecoder::IsSupportedType(aType)) {
     decoder = new OggDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsWaveSupportedType(aType.Type().AsString())) {
+  if (WaveDecoder::IsSupportedType(aType)) {
     decoder = new WaveDecoder(aOwner);
     return decoder.forget();
   }
   if (IsFlacSupportedType(aType.Type().AsString())) {
     decoder = new FlacDecoder(aOwner);
     return decoder.forget();
   }
 #ifdef MOZ_ANDROID_OMX
@@ -427,17 +419,17 @@ MediaDecoderReader* DecoderTraits::Creat
   } else
 #endif
   if (MP3Decoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
   } else
   if (ADTSDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
   } else
-  if (IsWaveSupportedType(aType)) {
+  if (WaveDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
   } else
   if (IsFlacSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
   } else
   if (OggDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
   } else
--- a/dom/media/wave/WaveDecoder.cpp
+++ b/dom/media/wave/WaveDecoder.cpp
@@ -1,15 +1,16 @@
 /* -*- 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 "WaveDemuxer.h"
+#include "MediaContentType.h"
 #include "MediaDecoderStateMachine.h"
 #include "WaveDecoder.h"
 #include "MediaFormatReader.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 MediaDecoder*
@@ -20,26 +21,28 @@ WaveDecoder::Clone(MediaDecoderOwner* aO
 
 MediaDecoderStateMachine*
 WaveDecoder::CreateStateMachine()
 {
   return new MediaDecoderStateMachine(
     this, new MediaFormatReader(this, new WAVDemuxer(GetResource())));
 }
 
-/* static */
-bool
-WaveDecoder::CanHandleMediaType(const nsACString& aType,
-                                const nsAString& aCodecs)
+/* static */ bool
+WaveDecoder::IsSupportedType(const MediaContentType& aContentType)
 {
   if (!IsWaveEnabled()) {
     return false;
   }
-  if (aType.EqualsASCII("audio/wave") || aType.EqualsASCII("audio/x-wav") ||
-      aType.EqualsASCII("audio/wav")  || aType.EqualsASCII("audio/x-pn-wav")) {
-    return (aCodecs.IsEmpty() || aCodecs.EqualsASCII("1") ||
-            aCodecs.EqualsASCII("6") || aCodecs.EqualsASCII("7"));
+  if (aContentType.Type() == MEDIAMIMETYPE("audio/wave")
+      || aContentType.Type() == MEDIAMIMETYPE("audio/x-wav")
+      || aContentType.Type() == MEDIAMIMETYPE("audio/wav")
+      || aContentType.Type() == MEDIAMIMETYPE("audio/x-pn-wav")) {
+    return (aContentType.ExtendedType().Codecs().IsEmpty()
+            || aContentType.ExtendedType().Codecs().AsString().EqualsASCII("1")
+            || aContentType.ExtendedType().Codecs().AsString().EqualsASCII("6")
+            || aContentType.ExtendedType().Codecs().AsString().EqualsASCII("7"));
   }
 
   return false;
 }
 
 } // namespace mozilla
--- a/dom/media/wave/WaveDecoder.h
+++ b/dom/media/wave/WaveDecoder.h
@@ -5,22 +5,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(WaveDecoder_h_)
 #define WaveDecoder_h_
 
 #include "MediaDecoder.h"
 
 namespace mozilla {
 
-class WaveDecoder : public MediaDecoder {
+class MediaContentType;
+
+class WaveDecoder : public MediaDecoder
+{
 public:
   // MediaDecoder interface.
   explicit WaveDecoder(MediaDecoderOwner* aOwner) : MediaDecoder(aOwner) {}
   MediaDecoder* Clone(MediaDecoderOwner* aOwner) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
-  static bool CanHandleMediaType(const nsACString& aType,
-                                 const nsAString& aCodecs);
+  // Returns true if the Wave backend is pref'ed on, and we're running on a
+  // platform that is likely to have decoders for the format.
+  static bool IsSupportedType(const MediaContentType& aContentType);
 };
 
 } // namespace mozilla
 
 #endif