Bug 1330284 - Use MediaContentType in DecoderTraits:IsHttpLiveStreamingType - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 28 Dec 2016 09:26:42 +1100
changeset 374480 6f91f2f99c3c6a3f02cd7c8b95fc22afe13b43ed
parent 374479 cab900d5963eea7d601646d8f2afd9adeef8e691
child 374481 4374afb7411ed698716013a6b2c5f8a4235aeb3b
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 DecoderTraits:IsHttpLiveStreamingType - r=jya MozReview-Commit-ID: I0C3ulkYiGX
dom/media/DecoderTraits.cpp
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -45,41 +45,25 @@
 #include "FlacDemuxer.h"
 
 #include "nsPluginHost.h"
 #include "MediaPrefs.h"
 
 namespace mozilla
 {
 
-template <class String>
 static bool
-CodecListContains(char const *const * aCodecs, const String& aCodec)
+IsHttpLiveStreamingType(const MediaContentType& aType)
 {
-  for (int32_t i = 0; aCodecs[i]; ++i) {
-    if (aCodec.EqualsASCII(aCodecs[i]))
-      return true;
-  }
-  return false;
-}
-
-static char const *const gHttpLiveStreamingTypes[] = {
-  // For m3u8.
-  // https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
-  "application/vnd.apple.mpegurl",
-  // Some sites serve these as the informal m3u type.
-  "application/x-mpegurl",
-  "audio/x-mpegurl",
-  nullptr
-};
-
-static bool
-IsHttpLiveStreamingType(const nsACString& aType)
-{
-  return CodecListContains(gHttpLiveStreamingTypes, aType);
+  return // For m3u8.
+         // https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
+         aType.Type() == MEDIAMIMETYPE("application/vnd.apple.mpegurl")
+         // Some sites serve these as the informal m3u type.
+         || aType.Type() == MEDIAMIMETYPE("application/x-mpegurl")
+         || aType.Type() == MEDIAMIMETYPE("audio/x-mpegurl");
 }
 
 #ifdef MOZ_ANDROID_OMX
 static bool
 IsAndroidMediaType(const MediaContentType& aType)
 {
   if (!MediaDecoder::IsAndroidMediaPluginEnabled()) {
     return false;
@@ -188,17 +172,17 @@ CanHandleCodecsType(const MediaContentTy
 
 static
 CanPlayStatus
 CanHandleMediaType(const MediaContentType& aType,
                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (IsHttpLiveStreamingType(aType.Type().AsString())) {
+  if (IsHttpLiveStreamingType(aType)) {
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true);
   }
 
   if (aType.ExtendedType().HaveCodecs()) {
     CanPlayStatus result = CanHandleCodecsType(aType, aDiagnostics);
     if (result == CANPLAY_NO || result == CANPLAY_YES) {
       return result;
     }
@@ -339,17 +323,17 @@ InstantiateDecoder(const MediaContentTyp
   // Note: DirectShow should come before WMF, so that we prefer DirectShow's
   // MP3 support over WMF's.
   if (DirectShowDecoder::GetSupportedCodecs(aType, nullptr)) {
     decoder = new DirectShowDecoder(aOwner);
     return decoder.forget();
   }
 #endif
 
-  if (IsHttpLiveStreamingType(aType.Type().AsString())) {
+  if (IsHttpLiveStreamingType(aType)) {
     // We don't have an HLS decoder.
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
   }
 
   return nullptr;
 }
 
 /* static */