Bug 1329568 - Remove MediaContentType crutches - r=jya
☠☠ backed out by 4caa61eee820 ☠ ☠
authorGerald Squelart <gsquelart@mozilla.com>
Sun, 01 Jan 2017 09:24:24 +1100
changeset 374180 90a091e65db3ed3876bc8c51174cffb6a7f21bcd
parent 374179 da855d6a78bba7762df16d5e70383bd50ab80ee7
child 374181 c316c8d24d32836a198286faa93e5a5c8990d0e6
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
bugs1329568
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 1329568 - Remove MediaContentType crutches - r=jya Now that we have move all data-handling functions to MediaMIMEType and friends, we can remove direct accesses to data from MediaContentType, to better separate the context that MediaContentType represents, from the data it includes. Dependent code needs to be mechanically updated to now use the proper APIs. Note that in most places, we just extract MIME strings. Further work will take place in later bugs, to completely replace these strings with MediaContentType or more appropriate types... MozReview-Commit-ID: LoX8dhX7OlB
dom/media/DecoderTraits.cpp
dom/media/MediaContentType.h
dom/media/VideoUtils.cpp
dom/media/fmp4/MP4Decoder.cpp
dom/media/mediasource/MediaSource.cpp
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -192,83 +192,94 @@ IsFlacSupportedType(const nsACString& aT
 }
 
 static
 CanPlayStatus
 CanHandleCodecsType(const MediaContentType& aType,
                     DecoderDoctorDiagnostics* aDiagnostics)
 {
   // We should have been given a codecs string, though it may be empty.
-  MOZ_ASSERT(aType.HaveCodecs());
+  MOZ_ASSERT(aType.ExtendedType().HaveCodecs());
+
+  // Content type with the the MIME type, no codecs.
+  const MediaContentType mimeType(aType.Type());
 
   char const* const* codecList = nullptr;
-  if (IsOggTypeAndEnabled(aType.GetMIMEType())) {
-    if (IsOggSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+  if (IsOggTypeAndEnabled(mimeType.Type().AsString())) {
+    if (IsOggSupportedType(aType.Type().AsString(),
+                           aType.ExtendedType().Codecs().AsString())) {
       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 (IsWaveSupportedType(aType.GetMIMEType())) {
-    if (IsWaveSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+  if (IsWaveSupportedType(mimeType.Type().AsString())) {
+    if (IsWaveSupportedType(aType.Type().AsString(),
+                            aType.ExtendedType().Codecs().AsString())) {
       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())) {
+  if (DecoderTraits::IsWebMTypeAndEnabled(mimeType.Type().AsString())) {
+    if (IsWebMSupportedType(aType.Type().AsString(),
+                            aType.ExtendedType().Codecs().AsString())) {
       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.
       return CANPLAY_NO;
     }
   }
 #endif
 #ifdef MOZ_FMP4
-  if (DecoderTraits::IsMP4TypeAndEnabled(aType.GetMIMEType(), aDiagnostics)) {
+  if (DecoderTraits::IsMP4TypeAndEnabled(mimeType.Type().AsString(), aDiagnostics)) {
     if (IsMP4SupportedType(aType, aDiagnostics)) {
       return CANPLAY_YES;
     } else {
       // We can only reach this position if a particular codec was requested,
       // fmp4 is supported and working: the codec must be invalid.
       return CANPLAY_NO;
     }
   }
 #endif
-  if (IsMP3SupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+  if (IsMP3SupportedType(mimeType.Type().AsString(),
+                         aType.ExtendedType().Codecs().AsString())) {
     return CANPLAY_YES;
   }
-  if (IsAACSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+  if (IsAACSupportedType(mimeType.Type().AsString(),
+                         aType.ExtendedType().Codecs().AsString())) {
     return CANPLAY_YES;
   }
-  if (IsFlacSupportedType(aType.GetMIMEType(), aType.GetCodecs())) {
+  if (IsFlacSupportedType(mimeType.Type().AsString(),
+                          aType.ExtendedType().Codecs().AsString())) {
     return CANPLAY_YES;
   }
 #ifdef MOZ_DIRECTSHOW
-  DirectShowDecoder::GetSupportedCodecs(aType.GetMIMEType(), &codecList);
+  DirectShowDecoder::GetSupportedCodecs(aType.Type().AsString(), &codecList);
 #endif
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled()) {
-    EnsureAndroidMediaPluginHost()->FindDecoder(aType.GetMIMEType(), &codecList);
+    EnsureAndroidMediaPluginHost()->FindDecoder(aType.Type().AsString(),
+                                                &codecList);
   }
 #endif
   if (!codecList) {
     return CANPLAY_MAYBE;
   }
 
   // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
   // of the 'codecs' parameter
-  nsCharSeparatedTokenizer tokenizer(aType.GetCodecs(), ',');
+  nsCharSeparatedTokenizer
+    tokenizer(aType.ExtendedType().Codecs().AsString(), ',');
   bool expectMoreTokens = false;
   while (tokenizer.hasMoreTokens()) {
     const nsSubstring& token = tokenizer.nextToken();
 
     if (!CodecListContains(codecList, token)) {
       // Totally unsupported codec
       return CANPLAY_NO;
     }
@@ -284,57 +295,61 @@ CanHandleCodecsType(const MediaContentTy
 
 static
 CanPlayStatus
 CanHandleMediaType(const MediaContentType& aType,
                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (IsHttpLiveStreamingType(aType.GetMIMEType())) {
+  if (IsHttpLiveStreamingType(aType.Type().AsString())) {
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true);
   }
 
-  if (aType.HaveCodecs()) {
+  if (aType.ExtendedType().HaveCodecs()) {
     CanPlayStatus result = CanHandleCodecsType(aType, aDiagnostics);
     if (result == CANPLAY_NO || result == CANPLAY_YES) {
       return result;
     }
   }
-  if (IsOggTypeAndEnabled(aType.GetMIMEType())) {
+
+  // Content type with just the MIME type/subtype, no codecs.
+  const MediaContentType mimeType(aType.Type());
+
+  if (IsOggTypeAndEnabled(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
-  if (IsWaveSupportedType(aType.GetMIMEType())) {
+  if (IsWaveSupportedType(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
-  if (DecoderTraits::IsMP4TypeAndEnabled(aType.GetMIMEType(), aDiagnostics)) {
+  if (DecoderTraits::IsMP4TypeAndEnabled(mimeType.Type().AsString(), aDiagnostics)) {
     return CANPLAY_MAYBE;
   }
 #if !defined(MOZ_OMX_WEBM_DECODER)
-  if (DecoderTraits::IsWebMTypeAndEnabled(aType.GetMIMEType())) {
+  if (DecoderTraits::IsWebMTypeAndEnabled(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
 #endif
-  if (IsMP3SupportedType(aType.GetMIMEType())) {
+  if (IsMP3SupportedType(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
-  if (IsAACSupportedType(aType.GetMIMEType())) {
+  if (IsAACSupportedType(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
-  if (IsFlacSupportedType(aType.GetMIMEType())) {
+  if (IsFlacSupportedType(mimeType.Type().AsString())) {
     return CANPLAY_MAYBE;
   }
 #ifdef MOZ_DIRECTSHOW
-  if (DirectShowDecoder::GetSupportedCodecs(aType.GetMIMEType(), nullptr)) {
+  if (DirectShowDecoder::GetSupportedCodecs(mimeType.Type().AsString(), nullptr)) {
     return CANPLAY_MAYBE;
   }
 #endif
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
-      EnsureAndroidMediaPluginHost()->FindDecoder(aType.GetMIMEType(), nullptr)) {
+      EnsureAndroidMediaPluginHost()->FindDecoder(mimeType.Type().AsString(), nullptr)) {
     return CANPLAY_MAYBE;
   }
 #endif
   return CANPLAY_NO;
 }
 
 /* static */
 CanPlayStatus
--- a/dom/media/MediaContentType.h
+++ b/dom/media/MediaContentType.h
@@ -30,30 +30,16 @@ public:
   explicit MediaContentType(MediaExtendedMIMEType&& aType)
     : mExtendedMIMEType(Move(aType))
   {
   }
 
   const MediaMIMEType& Type() const { return mExtendedMIMEType.Type(); }
   const MediaExtendedMIMEType& ExtendedType() const { return mExtendedMIMEType; }
 
-  // MIME "type/subtype". Guaranteed not to be empty.
-  const nsACString& GetMIMEType() const { return mExtendedMIMEType.Type().AsString(); }
-
-  // Was there an explicit 'codecs' parameter provided?
-  bool HaveCodecs() const { return mExtendedMIMEType.HaveCodecs(); }
-  // Codecs. May be empty if not provided or explicitly provided as empty.
-  const nsAString& GetCodecs() const { return mExtendedMIMEType.Codecs().AsString(); }
-
-  // Sizes and rates.
-  Maybe<int32_t> GetWidth() const { return mExtendedMIMEType.GetWidth(); }
-  Maybe<int32_t> GetHeight() const { return mExtendedMIMEType.GetHeight(); }
-  Maybe<int32_t> GetFramerate() const { return mExtendedMIMEType.GetFramerate(); }
-  Maybe<int32_t> GetBitrate() const { return mExtendedMIMEType.GetBitrate(); }
-
 private:
   MediaExtendedMIMEType mExtendedMIMEType;
 };
 
 Maybe<MediaContentType> MakeMediaContentType(const nsAString& aType);
 Maybe<MediaContentType> MakeMediaContentType(const nsACString& aType);
 Maybe<MediaContentType> MakeMediaContentType(const char* aType);
 
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -505,21 +505,21 @@ UniquePtr<TrackInfo>
 CreateTrackInfoWithMIMETypeAndContentTypeExtraParameters(
   const nsACString& aCodecMIMEType,
   const MediaContentType& aContentType)
 {
   UniquePtr<TrackInfo> trackInfo = CreateTrackInfoWithMIMEType(aCodecMIMEType);
   if (trackInfo) {
     VideoInfo* videoInfo = trackInfo->GetAsVideoInfo();
     if (videoInfo) {
-      Maybe<int32_t> maybeWidth = aContentType.GetWidth();
+      Maybe<int32_t> maybeWidth = aContentType.ExtendedType().GetWidth();
       if (maybeWidth && *maybeWidth > 0) {
         videoInfo->mImage.width = *maybeWidth;
       }
-      Maybe<int32_t> maybeHeight = aContentType.GetHeight();
+      Maybe<int32_t> maybeHeight = aContentType.ExtendedType().GetHeight();
       if (maybeHeight && *maybeHeight > 0) {
         videoInfo->mImage.height = *maybeHeight;
       }
     }
   }
   return trackInfo;
 }
 
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -72,48 +72,48 @@ MP4Decoder::CanHandleMediaType(const Med
 {
   if (!IsEnabled()) {
     return false;
   }
 
   // Whitelist MP4 types, so they explicitly match what we encounter on
   // the web, as opposed to what we use internally (i.e. what our demuxers
   // etc output).
-  const bool isMP4Audio = aType.GetMIMEType().EqualsASCII("audio/mp4") ||
-                          aType.GetMIMEType().EqualsASCII("audio/x-m4a");
+  const bool isMP4Audio = aType.Type() == MEDIAMIMETYPE("audio/mp4") ||
+                          aType.Type() == MEDIAMIMETYPE("audio/x-m4a");
   const bool isMP4Video =
   // On B2G, treat 3GPP as MP4 when Gonk PDM is available.
 #ifdef MOZ_GONK_MEDIACODEC
-      aType.GetMIMEType().EqualsASCII(VIDEO_3GPP) ||
+      aType.Type() == MEDIAMIMETYPE(VIDEO_3GPP) ||
 #endif
-      aType.GetMIMEType().EqualsASCII("video/mp4") ||
-      aType.GetMIMEType().EqualsASCII("video/quicktime") ||
-      aType.GetMIMEType().EqualsASCII("video/x-m4v");
+      aType.Type() == MEDIAMIMETYPE("video/mp4") ||
+      aType.Type() == MEDIAMIMETYPE("video/quicktime") ||
+      aType.Type() == MEDIAMIMETYPE("video/x-m4v");
   if (!isMP4Audio && !isMP4Video) {
     return false;
   }
 
   nsTArray<UniquePtr<TrackInfo>> trackInfos;
-  if (aType.GetCodecs().IsEmpty()) {
+  if (aType.ExtendedType().Codecs().IsEmpty()) {
     // No codecs specified. Assume H.264
     if (isMP4Audio) {
       trackInfos.AppendElement(
         CreateTrackInfoWithMIMETypeAndContentTypeExtraParameters(
           NS_LITERAL_CSTRING("audio/mp4a-latm"), aType));
     } else {
       MOZ_ASSERT(isMP4Video);
       trackInfos.AppendElement(
         CreateTrackInfoWithMIMETypeAndContentTypeExtraParameters(
           NS_LITERAL_CSTRING("video/avc"), aType));
     }
   } else {
     // Verify that all the codecs specified are ones that we expect that
     // we can play.
     nsTArray<nsString> codecs;
-    if (!ParseCodecsString(aType.GetCodecs(), codecs)) {
+    if (!ParseCodecsString(aType.ExtendedType().Codecs().AsString(), codecs)) {
       return false;
     }
     for (const nsString& codec : codecs) {
       if (IsAACCodecString(codec)) {
         trackInfos.AppendElement(
           CreateTrackInfoWithMIMETypeAndContentTypeExtraParameters(
             NS_LITERAL_CSTRING("audio/mp4a-latm"), aType));
         continue;
--- a/dom/media/mediasource/MediaSource.cpp
+++ b/dom/media/mediasource/MediaSource.cpp
@@ -100,31 +100,32 @@ MediaSource::IsTypeSupported(const nsASt
 
   if (DecoderTraits::CanHandleContentType(*contentType, aDiagnostics)
       == CANPLAY_NO) {
     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
   // Now we know that this media type could be played.
   // MediaSource imposes extra restrictions, and some prefs.
-  const nsACString& mimeType = contentType->GetMIMEType();
-  if (mimeType.EqualsASCII("video/mp4") || mimeType.EqualsASCII("audio/mp4")) {
+  const MediaMIMEType& mimeType = contentType->Type();
+  if (mimeType == MEDIAMIMETYPE("video/mp4") ||
+      mimeType == MEDIAMIMETYPE("audio/mp4")) {
     if (!Preferences::GetBool("media.mediasource.mp4.enabled", false)) {
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
     return NS_OK;
   }
-  if (mimeType.EqualsASCII("video/webm")) {
+  if (mimeType == MEDIAMIMETYPE("video/webm")) {
     if (!(Preferences::GetBool("media.mediasource.webm.enabled", false) ||
           IsWebMForced(aDiagnostics))) {
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
     return NS_OK;
   }
-  if (mimeType.EqualsASCII("audio/webm")) {
+  if (mimeType == MEDIAMIMETYPE("audio/webm")) {
     if (!(Preferences::GetBool("media.mediasource.webm.enabled", false) ||
           Preferences::GetBool("media.mediasource.webm.audio.enabled", true))) {
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
     return NS_OK;
   }
 
   return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
@@ -237,17 +238,17 @@ MediaSource::AddSourceBuffer(const nsASt
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
   Maybe<MediaContentType> contentType = MakeMediaContentType(aType);
   if (!contentType) {
     aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
   }
-  const nsACString& mimeType = contentType->GetMIMEType();
+  const nsACString& mimeType = contentType->Type().AsString();
   RefPtr<SourceBuffer> sourceBuffer = new SourceBuffer(this, mimeType);
   if (!sourceBuffer) {
     aRv.Throw(NS_ERROR_FAILURE); // XXX need a better error here
     return nullptr;
   }
   mSourceBuffers->Append(sourceBuffer);
   MSE_DEBUG("sourceBuffer=%p", sourceBuffer.get());
   return sourceBuffer.forget();