Bug 1231793: Part 6 - Enabled the new Wave Data Decoder in DecoderTraits. r=jya draft
authorLouis Christie <lchristie@mozilla.com>
Fri, 12 Feb 2016 14:40:36 +1300
changeset 331191 77a2ce4af8a878031aab2d67e9f7f2df1a98f939
parent 331190 10c1895b054c2b9e5d4f579ac887ced386145ff4
child 331192 72dd22ee4116fd1eaab29fdc781e0f743eac836b
push id10927
push userbmo:jyavenard@mozilla.com
push dateTue, 16 Feb 2016 13:22:28 +0000
reviewersjya
bugs1231793
milestone47.0a1
Bug 1231793: Part 6 - Enabled the new Wave Data Decoder in DecoderTraits. r=jya MozReview-Commit-ID: EdW4JJM3nO6
dom/media/DecoderTraits.cpp
dom/media/wave/WaveDecoder.cpp
dom/media/wave/moz.build
modules/libpref/init/all.js
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -8,19 +8,16 @@
 #include "MediaDecoder.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsMimeTypes.h"
 #include "mozilla/Preferences.h"
 
 #include "OggDecoder.h"
 #include "OggReader.h"
 
-#include "WaveDecoder.h"
-#include "WaveReader.h"
-
 #include "WebMDecoder.h"
 #include "WebMDemuxer.h"
 
 #ifdef MOZ_RAW
 #include "RawDecoder.h"
 #include "RawReader.h"
 #endif
 #ifdef MOZ_ANDROID_OMX
@@ -46,16 +43,20 @@
 #include "MP4Decoder.h"
 #include "MP4Demuxer.h"
 #endif
 #include "MediaFormatReader.h"
 
 #include "MP3Decoder.h"
 #include "MP3Demuxer.h"
 
+#include "WaveDecoder.h"
+#include "WaveDemuxer.h"
+#include "WaveReader.h"
+
 #include "ADTSDecoder.h"
 #include "ADTSDemuxer.h"
 
 namespace mozilla
 {
 
 template <class String>
 static bool
@@ -328,16 +329,23 @@ IsMP3SupportedType(const nsACString& aTy
 
 static bool
 IsAACSupportedType(const nsACString& aType,
                    const nsAString& aCodecs = EmptyString())
 {
   return ADTSDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
+static bool
+IsWAVSupportedType(const nsACString& aType,
+                   const nsAString& aCodecs = EmptyString())
+{
+  return WaveDecoder::CanHandleMediaType(aType, aCodecs);
+}
+
 /* static */
 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
 {
   if (IsWaveType(nsDependentCString(aMIMEType))) {
     // 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
@@ -613,16 +621,19 @@ MediaDecoderReader* DecoderTraits::Creat
   } else
 #endif
   if (IsMP3SupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
   } else
   if (IsAACSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
   } else
+  if (IsWAVSupportedType(aType)) {
+    decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
+  } else
 #ifdef MOZ_RAW
   if (IsRawType(aType)) {
     decoderReader = new RawReader(aDecoder);
   } else
 #endif
   if (IsOggType(aType)) {
     decoderReader = new OggReader(aDecoder);
   } else
--- a/dom/media/wave/WaveDecoder.cpp
+++ b/dom/media/wave/WaveDecoder.cpp
@@ -12,38 +12,39 @@
 #include "MediaFormatReader.h"
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 MediaDecoder*
 WaveDecoder::Clone(MediaDecoderOwner* aOwner)
 {
-  if (!IsEnabled())
-    return nullptr;
-
   return new WaveDecoder(aOwner);
 }
 
 MediaDecoderStateMachine*
 WaveDecoder::CreateStateMachine()
 {
-  if (Preferences::GetBool("media.wave.decoder.enabled")) {
+  if (Preferences::GetBool("media.wave.decoder.enabled", false)) {
     RefPtr<MediaDecoderReader> reader =
         new MediaFormatReader(this, new WAVDemuxer(GetResource()));
     return new MediaDecoderStateMachine(this, reader);
   } else {
     return new MediaDecoderStateMachine(this, new WaveReader(this));
   }
 }
 
 /* static */
 bool
 WaveDecoder::IsEnabled()
 {
+  MOZ_ASSERT(NS_IsMainThread());
+  if (!Preferences::GetBool("media.wave.decoder.enabled", false)) {
+    return false;
+  }
   PDMFactory::Init();
   RefPtr<PDMFactory> platform = new PDMFactory();
   return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/x-wav"));
 }
 
 /* static */
 bool
 WaveDecoder::CanHandleMediaType(const nsACString& aType,
--- a/dom/media/wave/moz.build
+++ b/dom/media/wave/moz.build
@@ -1,16 +1,17 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 EXPORTS += [
     'WaveDecoder.h',
+    'WaveDemuxer.h',
     'WaveReader.h',
 ]
 
 UNIFIED_SOURCES += [
     'WaveDecoder.cpp',
     'WaveDemuxer.cpp',
     'WaveReader.cpp',
 ]
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -344,17 +344,17 @@ pref("media.gmp.decoder.enabled", false)
 pref("media.gmp.decoder.aac", 0);
 pref("media.gmp.decoder.h264", 0);
 #ifdef MOZ_RAW
 pref("media.raw.enabled", true);
 #endif
 pref("media.ogg.enabled", true);
 pref("media.opus.enabled", true);
 pref("media.wave.enabled", true);
-pref("media.wave.decoder.enabled", false);
+pref("media.wave.decoder.enabled", true);
 pref("media.webm.enabled", true);
 #if defined(MOZ_FMP4) && defined(MOZ_WMF)
 pref("media.webm.intel_decoder.enabled", false);
 #endif
 
 #ifdef MOZ_APPLEMEDIA
 #ifdef MOZ_WIDGET_UIKIT
 pref("media.mp3.enabled", true);