Bug 1316205: P2. Remove wave duplicated code. r=kaku
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 09 Nov 2016 13:08:56 +1100
changeset 351901 133477f27fe6a4aa490cded021cbcb5dd025793d
parent 351900 c61363a3c27106bc7f27929969d87348d84b591e
child 351902 60bf1293eabf295bef0dd400ebde9668af3bd9ae
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1316205
milestone52.0a1
Bug 1316205: P2. Remove wave duplicated code. r=kaku MozReview-Commit-ID: 5s7eeMa9DU9
dom/media/DecoderTraits.cpp
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -59,55 +59,27 @@ CodecListContains(char const *const * aC
     if (aCodec.EqualsASCII(aCodecs[i]))
       return true;
   }
   return false;
 }
 
 static bool
 IsOggSupportedType(const nsACString& aType,
-                    const nsAString& aCodecs = EmptyString())
+                   const nsAString& aCodecs = EmptyString())
 {
   return OggDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
 static bool
 IsOggTypeAndEnabled(const nsACString& aType)
 {
   return IsOggSupportedType(aType);
 }
 
-// See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
-// of WAVE media types and codec types. However, the audio/vnd.wave
-// MIME type described there is not used.
-static const char* const gWaveTypes[5] = {
-  "audio/x-wav",
-  "audio/wav",
-  "audio/wave",
-  "audio/x-pn-wav",
-  nullptr
-};
-
-static char const *const gWaveCodecs[4] = {
-  "1", // Microsoft PCM Format
-  "6", // aLaw Encoding
-  "7", // uLaw Encoding
-  nullptr
-};
-
-static bool
-IsWaveType(const nsACString& aType)
-{
-  if (!MediaDecoder::IsWaveEnabled()) {
-    return false;
-  }
-
-  return CodecListContains(gWaveTypes, aType);
-}
-
 static bool
 IsWebMSupportedType(const nsACString& aType,
                     const nsAString& aCodecs = EmptyString())
 {
   return WebMDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
 /* static */ bool
@@ -198,18 +170,18 @@ 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())
+IsWaveSupportedType(const nsACString& aType,
+                    const nsAString& aCodecs = EmptyString())
 {
   return WaveDecoder::CanHandleMediaType(aType, aCodecs);
 }
 
 static bool
 IsFlacSupportedType(const nsACString& aType,
                    const nsAString& aCodecs = EmptyString())
 {
@@ -230,18 +202,24 @@ CanHandleCodecsType(const MediaContentTy
     if (IsOggSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
       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 (IsWaveType(aType.GetMIMEType())) {
-    codecList = gWaveCodecs;
+  if (IsWaveSupportedType(aType.GetMIMEType())) {
+    if (IsWaveSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+      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)
   if (DecoderTraits::IsWebMTypeAndEnabled(aType.GetMIMEType())) {
     if (IsWebMSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
       return CANPLAY_YES;
     } else {
       // We can only reach this position if a particular codec was requested,
       // webm is supported and working: the codec must be invalid.
@@ -317,17 +295,17 @@ CanHandleMediaType(const MediaContentTyp
     CanPlayStatus result = CanHandleCodecsType(aType, aDiagnostics);
     if (result == CANPLAY_NO || result == CANPLAY_YES) {
       return result;
     }
   }
   if (IsOggTypeAndEnabled(aType.GetMIMEType())) {
     return CANPLAY_MAYBE;
   }
-  if (IsWaveType(aType.GetMIMEType())) {
+  if (IsWaveSupportedType(aType.GetMIMEType())) {
     return CANPLAY_MAYBE;
   }
   if (DecoderTraits::IsMP4TypeAndEnabled(aType.GetMIMEType(), aDiagnostics)) {
     return CANPLAY_MAYBE;
   }
 #if !defined(MOZ_OMX_WEBM_DECODER)
   if (DecoderTraits::IsWebMTypeAndEnabled(aType.GetMIMEType())) {
     return CANPLAY_MAYBE;
@@ -367,17 +345,17 @@ DecoderTraits::CanHandleContentType(cons
 
   return CanHandleMediaType(aContentType, aDiagnostics);
 }
 
 /* static */
 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
                                           DecoderDoctorDiagnostics* aDiagnostics)
 {
-  if (IsWaveType(nsDependentCString(aMIMEType))) {
+  if (IsWaveSupportedType(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
     // means.
     return false;
   }
 
@@ -420,17 +398,17 @@ InstantiateDecoder(const nsACString& aTy
   if (IsAACSupportedType(aType)) {
     decoder = new ADTSDecoder(aOwner);
     return decoder.forget();
   }
   if (IsOggSupportedType(aType)) {
     decoder = new OggDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsWaveType(aType)) {
+  if (IsWaveSupportedType(aType)) {
     decoder = new WaveDecoder(aOwner);
     return decoder.forget();
   }
   if (IsFlacSupportedType(aType)) {
     decoder = new FlacDecoder(aOwner);
     return decoder.forget();
   }
 #ifdef MOZ_ANDROID_OMX
@@ -488,17 +466,17 @@ 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)) {
+  if (IsWaveSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
   } else
   if (IsFlacSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
   } else
   if (IsOggSupportedType(aType)) {
     decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
   } else