Bug 1187118 part 2 - [WIP] Integrated the GIFDecoder into DecoderTraits; draft
authorKaku Kuo <kaku@mozilla.com>
Thu, 23 Feb 2017 11:24:19 +0800
changeset 488566 e1acfc5fe5391f46cc19b91d85309aadc195fb0b
parent 488565 b125728f45ae6d1b6b707a548f97e88c1b174ac2
child 488567 4d506d9c2c7c08285b4628e307be26950f987abc
push id46579
push userbmo:kaku@mozilla.com
push dateThu, 23 Feb 2017 10:26:35 +0000
bugs1187118
milestone54.0a1
Bug 1187118 part 2 - [WIP] Integrated the GIFDecoder into DecoderTraits; MozReview-Commit-ID: Et7IHbBO2YT
dom/media/DecoderTraits.cpp
dom/media/VideoUtils.cpp
dom/media/VideoUtils.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -39,16 +39,19 @@
 #include "WaveDemuxer.h"
 
 #include "ADTSDecoder.h"
 #include "ADTSDemuxer.h"
 
 #include "FlacDecoder.h"
 #include "FlacDemuxer.h"
 
+#include "GIFDecoder.h"
+#include "GIFDemuxer.h"
+
 #include "nsPluginHost.h"
 #include "MediaPrefs.h"
 
 namespace mozilla
 {
 
 static bool
 IsHttpLiveStreamingType(const MediaContainerType& aType)
@@ -139,16 +142,19 @@ CanHandleCodecsType(const MediaContainer
     return CANPLAY_YES;
   }
   if (ADTSDecoder::IsSupportedType(aType)) {
     return CANPLAY_YES;
   }
   if (FlacDecoder::IsSupportedType(aType)) {
     return CANPLAY_YES;
   }
+  if (GIFDecoder::IsSupportedType(aType)) {
+    return CANPLAY_YES;
+  }
 
   MediaCodecs supportedCodecs;
 #ifdef MOZ_DIRECTSHOW
   DirectShowDecoder::GetSupportedCodecs(aType, &supportedCodecs);
 #endif
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled()) {
     EnsureAndroidMediaPluginHost()->FindDecoder(aType, &supportedCodecs);
@@ -217,16 +223,19 @@ CanHandleMediaType(const MediaContainerT
   }
 #endif
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(mimeType, nullptr)) {
     return CANPLAY_MAYBE;
   }
 #endif
+  if (GIFDecoder::IsSupportedType(mimeType)) {
+    return CANPLAY_MAYBE;
+  }
   return CANPLAY_NO;
 }
 
 /* static */
 CanPlayStatus
 DecoderTraits::CanHandleContainerType(const MediaContainerType& aContainerType,
                                       DecoderDoctorDiagnostics* aDiagnostics)
 {
@@ -318,16 +327,21 @@ InstantiateDecoder(const MediaContainerT
   // 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 (GIFDecoder::IsSupportedType(aType)) {
+    decoder = new GIFDecoder(aOwner);
+    return decoder.forget();
+  }
+
   if (IsHttpLiveStreamingType(aType)) {
     // We don't have an HLS decoder.
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
   }
 
   return nullptr;
 }
 
@@ -388,16 +402,20 @@ DecoderTraits::CreateReader(const MediaC
     decoderReader =
       new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()));
   } else
 #ifdef MOZ_DIRECTSHOW
   if (DirectShowDecoder::GetSupportedCodecs(aType, nullptr)) {
     decoderReader = new DirectShowReader(aDecoder);
   } else
 #endif
+  if (GIFDecoder::IsSupportedType(aType)) {
+    decoderReader =
+      new MediaFormatReader(aDecoder, new GIFDemuxer(aDecoder->GetResource()));
+  }
   if (false) {} // dummy if to take care of the dangling else
 
   return decoderReader;
 }
 
 /* static */
 bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
 {
@@ -424,12 +442,13 @@ bool DecoderTraits::IsSupportedInVideoDo
     MP4Decoder::IsSupportedType(*type, /* DecoderDoctorDiagnostics* */ nullptr) ||
 #endif
     MP3Decoder::IsSupportedType(*type) ||
     ADTSDecoder::IsSupportedType(*type) ||
     FlacDecoder::IsSupportedType(*type) ||
 #ifdef MOZ_DIRECTSHOW
     DirectShowDecoder::GetSupportedCodecs(*type, nullptr) ||
 #endif
+    GIFDecoder::IsSupportedType(*type) ||
     false;
 }
 
 } // namespace mozilla
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -491,16 +491,19 @@ CreateTrackInfoWithMIMEType(const nsACSt
 {
   UniquePtr<TrackInfo> trackInfo;
   if (StartsWith(aCodecMIMEType, "audio/")) {
     trackInfo.reset(new AudioInfo());
     trackInfo->mMimeType = aCodecMIMEType;
   } else if (StartsWith(aCodecMIMEType, "video/")) {
     trackInfo.reset(new VideoInfo());
     trackInfo->mMimeType = aCodecMIMEType;
+  } else if (StartsWith(aCodecMIMEType, "image/")) {
+    trackInfo.reset(new VideoInfo());
+    trackInfo->mMimeType = aCodecMIMEType;
   }
   return trackInfo;
 }
 
 UniquePtr<TrackInfo>
 CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
   const nsACString& aCodecMIMEType,
   const MediaContainerType& aContainerType)
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -404,17 +404,18 @@ IsMIMETypeWithMajor(const char* aString,
 // Simple MIME-type string checker.
 // Only accepts lowercase "{application,audio,video}/[a-z0-9\-\.]+".
 // Add more if necessary.
 constexpr bool
 IsMediaMIMEType(const char* aString, size_t aLength)
 {
   return detail::IsMIMETypeWithMajor(aString, aLength, "application")
          || detail::IsMIMETypeWithMajor(aString, aLength, "audio")
-         || detail::IsMIMETypeWithMajor(aString, aLength, "video");
+         || detail::IsMIMETypeWithMajor(aString, aLength, "video")
+         || detail::IsMIMETypeWithMajor(aString, aLength, "image");
 }
 
 // Simple MIME-type string literal checker.
 // Only accepts lowercase "{application,audio,video}/[a-z0-9\-\.]+".
 // Add more if necessary.
 template <size_t LengthPlus1>
 constexpr bool
 IsMediaMIMEType(const char (&aString)[LengthPlus1])