Bug 1330284 - Use MediaContentType in FlacDecoder - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 20 Dec 2016 19:24:17 +1100
changeset 374472 a8b342ba64a33bd4a5fec8906afb67644896e681
parent 374471 6437fa28aae1fe0a8d262fa5bed532ab1a4179d5
child 374473 540717f0dc54df66f71ecb40fe547a744d7bcb27
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 FlacDecoder - r=jya MozReview-Commit-ID: IwD2aXAmuQ4
dom/media/DecoderTraits.cpp
dom/media/flac/FlacDecoder.cpp
dom/media/flac/FlacDecoder.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -107,23 +107,16 @@ DecoderTraits::IsMP4SupportedType(const 
 {
 #ifdef MOZ_FMP4
   return MP4Decoder::IsSupportedType(aType, aDiagnostics);
 #else
   return false;
 #endif
 }
 
-static bool
-IsFlacSupportedType(const nsACString& aType,
-                   const nsAString& aCodecs = EmptyString())
-{
-  return FlacDecoder::CanHandleMediaType(aType, aCodecs);
-}
-
 static
 CanPlayStatus
 CanHandleCodecsType(const MediaContentType& aType,
                     DecoderDoctorDiagnostics* aDiagnostics)
 {
   // We should have been given a codecs string, though it may be empty.
   MOZ_ASSERT(aType.ExtendedType().HaveCodecs());
 
@@ -173,18 +166,17 @@ CanHandleCodecsType(const MediaContentTy
   }
 #endif
   if (MP3Decoder::IsSupportedType(aType)) {
     return CANPLAY_YES;
   }
   if (ADTSDecoder::IsSupportedType(aType)) {
     return CANPLAY_YES;
   }
-  if (IsFlacSupportedType(mimeType.Type().AsString(),
-                          aType.ExtendedType().Codecs().AsString())) {
+  if (FlacDecoder::IsSupportedType(aType)) {
     return CANPLAY_YES;
   }
 #ifdef MOZ_DIRECTSHOW
   DirectShowDecoder::GetSupportedCodecs(aType.Type().AsString(), &codecList);
 #endif
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled()) {
     EnsureAndroidMediaPluginHost()->FindDecoder(aType.Type().AsString(),
@@ -255,17 +247,17 @@ CanHandleMediaType(const MediaContentTyp
   }
 #endif
   if (MP3Decoder::IsSupportedType(mimeType)) {
     return CANPLAY_MAYBE;
   }
   if (ADTSDecoder::IsSupportedType(mimeType)) {
     return CANPLAY_MAYBE;
   }
-  if (IsFlacSupportedType(mimeType.Type().AsString())) {
+  if (FlacDecoder::IsSupportedType(mimeType)) {
     return CANPLAY_MAYBE;
   }
 #ifdef MOZ_DIRECTSHOW
   if (DirectShowDecoder::GetSupportedCodecs(mimeType.Type().AsString(), nullptr)) {
     return CANPLAY_MAYBE;
   }
 #endif
 #ifdef MOZ_ANDROID_OMX
@@ -344,17 +336,17 @@ InstantiateDecoder(const MediaContentTyp
   if (OggDecoder::IsSupportedType(aType)) {
     decoder = new OggDecoder(aOwner);
     return decoder.forget();
   }
   if (WaveDecoder::IsSupportedType(aType)) {
     decoder = new WaveDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsFlacSupportedType(aType.Type().AsString())) {
+  if (FlacDecoder::IsSupportedType(aType)) {
     decoder = new FlacDecoder(aOwner);
     return decoder.forget();
   }
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(aType.Type().AsString(),
                                                   nullptr)) {
     decoder = new AndroidMediaDecoder(aOwner, aType.Type().AsString());
@@ -422,17 +414,17 @@ MediaDecoderReader* DecoderTraits::Creat
     decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
   } else
   if (ADTSDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
   } else
   if (WaveDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
   } else
-  if (IsFlacSupportedType(aType)) {
+  if (FlacDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
   } else
   if (OggDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
   } else
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
@@ -475,16 +467,16 @@ bool DecoderTraits::IsSupportedInVideoDo
 #ifdef MOZ_ANDROID_OMX
     (MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) ||
 #endif
 #ifdef MOZ_FMP4
     MP4Decoder::IsSupportedType(*type, /* DecoderDoctorDiagnostics* */ nullptr) ||
 #endif
     MP3Decoder::IsSupportedType(*type) ||
     ADTSDecoder::IsSupportedType(*type) ||
-    IsFlacSupportedType(aType) ||
+    FlacDecoder::IsSupportedType(*type) ||
 #ifdef MOZ_DIRECTSHOW
     IsDirectShowSupportedType(aType) ||
 #endif
     false;
 }
 
 } // namespace mozilla
--- a/dom/media/flac/FlacDecoder.cpp
+++ b/dom/media/flac/FlacDecoder.cpp
@@ -1,27 +1,29 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "FlacDecoder.h"
 #include "FlacDemuxer.h"
+#include "MediaContentType.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "MediaPrefs.h"
 
 namespace mozilla {
 
 MediaDecoder*
 FlacDecoder::Clone(MediaDecoderOwner* aOwner)
 {
-  if (!IsEnabled())
+  if (!IsEnabled()) {
     return nullptr;
+  }
 
   return new FlacDecoder(aOwner);
 }
 
 MediaDecoderStateMachine*
 FlacDecoder::CreateStateMachine()
 {
   RefPtr<MediaDecoderReader> reader =
@@ -36,17 +38,17 @@ FlacDecoder::IsEnabled()
   return MediaPrefs::FlacEnabled();
 #else
   // Until bug 1295886 is fixed.
   return false;
 #endif
 }
 
 /* static */ bool
-FlacDecoder::CanHandleMediaType(const nsACString& aType,
-                                const nsAString& aCodecs)
+FlacDecoder::IsSupportedType(const MediaContentType& aContentType)
 {
-  return IsEnabled() &&
-    (aType.EqualsASCII("audio/flac") || aType.EqualsASCII("audio/x-flac") ||
-     aType.EqualsASCII("application/x-flac"));
+  return IsEnabled()
+         && (aContentType.Type() == MEDIAMIMETYPE("audio/flac")
+             || aContentType.Type() == MEDIAMIMETYPE("audio/x-flac")
+             || aContentType.Type() == MEDIAMIMETYPE("application/x-flac"));
 }
 
 } // namespace mozilla
--- a/dom/media/flac/FlacDecoder.h
+++ b/dom/media/flac/FlacDecoder.h
@@ -6,25 +6,27 @@
 
 #ifndef FLAC_DECODER_H_
 #define FLAC_DECODER_H_
 
 #include "MediaDecoder.h"
 
 namespace mozilla {
 
-class FlacDecoder : public MediaDecoder {
+class MediaContentType;
+
+class FlacDecoder : public MediaDecoder
+{
 public:
   // MediaDecoder interface.
   explicit FlacDecoder(MediaDecoderOwner* aOwner) : MediaDecoder(aOwner) {}
   MediaDecoder* Clone(MediaDecoderOwner* aOwner) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the Flac backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
-  static bool CanHandleMediaType(const nsACString& aType,
-                                 const nsAString& aCodecs);
+  static bool IsSupportedType(const MediaContentType& aContentType);
 };
 
 } // namespace mozilla
 
 #endif // !FLAC_DECODER_H_