Bug 1329568 - MediaMIMEType - r=jya
☠☠ backed out by 4caa61eee820 ☠ ☠
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 01 Dec 2016 16:57:31 +1100
changeset 374173 2ce9dcf0c27412fbb5cff17f9f6e13fe36d4bdda
parent 374172 644f206d06d6d2c01bac8c87a6e275817a3651b3
child 374174 99758b5f7918a50d35bdecbe339371072df325ad
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 - MediaMIMEType - r=jya MediaMIMEType factors out the main MIME "type/subtype" string from MediaExtendedMIMEType, as it is often useful to deal with just that part. Like MediaContentType and MediaExtendedMIMEType, MediaMIMEType is always valid once constructed. MozReview-Commit-ID: 5Urlk6OLo5q
dom/media/MediaContentType.h
dom/media/MediaMIMETypes.cpp
dom/media/MediaMIMETypes.h
--- a/dom/media/MediaContentType.h
+++ b/dom/media/MediaContentType.h
@@ -12,29 +12,36 @@
 #include "nsString.h"
 
 namespace mozilla {
 
 // Class containing media type information for containers.
 class MediaContentType
 {
 public:
+  explicit MediaContentType(const MediaMIMEType& aType)
+    : mExtendedMIMEType(aType)
+  {}
+  explicit MediaContentType(MediaMIMEType&& aType)
+    : mExtendedMIMEType(Move(aType))
+  {}
   explicit MediaContentType(const MediaExtendedMIMEType& aType)
     : mExtendedMIMEType(aType)
   {
   }
   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(); }
+  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.GetCodecs(); }
 
   // Sizes and rates.
   Maybe<int32_t> GetWidth() const { return mExtendedMIMEType.GetWidth(); }
--- a/dom/media/MediaMIMETypes.cpp
+++ b/dom/media/MediaMIMETypes.cpp
@@ -5,16 +5,54 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaMIMETypes.h"
 
 #include "nsContentTypeParser.h"
 
 namespace mozilla {
 
+MediaMIMEType::MediaMIMEType(const nsACString& aType)
+  : mMIMEType(aType)
+{
+}
+
+Maybe<MediaMIMEType>
+MakeMediaMIMEType(const nsAString& aType)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  nsContentTypeParser parser(aType);
+  nsAutoString mime;
+  nsresult rv = parser.GetType(mime);
+  if (!NS_SUCCEEDED(rv) || mime.IsEmpty()) {
+    return Nothing();
+  }
+
+  NS_ConvertUTF16toUTF8 mime8{mime};
+
+  return Some(MediaMIMEType(mime8));
+}
+
+Maybe<MediaMIMEType>
+MakeMediaMIMEType(const nsACString& aType)
+{
+  return MakeMediaMIMEType(NS_ConvertUTF8toUTF16(aType));
+}
+
+Maybe<MediaMIMEType>
+MakeMediaMIMEType(const char* aType)
+{
+  if (!aType) {
+    return Nothing();
+  }
+  return MakeMediaMIMEType(nsDependentCString(aType));
+}
+
+
 static int32_t
 GetParameterAsNumber(const nsContentTypeParser& aParser,
                      const char* aParameter,
                      const int32_t aErrorReturn)
 {
   nsAutoString parameterString;
   nsresult rv = aParser.GetParameter(aParameter, parameterString);
   if (NS_FAILED_impl(rv)) {
@@ -27,26 +65,36 @@ GetParameterAsNumber(const nsContentType
   return number;
 }
 
 MediaExtendedMIMEType::MediaExtendedMIMEType(const nsACString& aMIMEType,
                                              bool aHaveCodecs,
                                              const nsAString& aCodecs,
                                              int32_t aWidth, int32_t aHeight,
                                              int32_t aFramerate, int32_t aBitrate)
-  : mMIMEType(Move(aMIMEType))
+  : mMIMEType(aMIMEType)
   , mHaveCodecs(aHaveCodecs)
-  , mCodecs(Move(aCodecs))
+  , mCodecs(aCodecs)
   , mWidth(aWidth)
   , mHeight(aHeight)
   , mFramerate(aFramerate)
   , mBitrate(aBitrate)
 {
 }
 
+MediaExtendedMIMEType::MediaExtendedMIMEType(const MediaMIMEType& aType)
+  : mMIMEType(aType)
+{
+}
+
+MediaExtendedMIMEType::MediaExtendedMIMEType(MediaMIMEType&& aType)
+  : mMIMEType(Move(aType))
+{
+}
+
 Maybe<MediaExtendedMIMEType>
 MakeMediaExtendedMIMEType(const nsAString& aType)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsContentTypeParser parser(aType);
   nsAutoString mime;
   nsresult rv = parser.GetType(mime);
--- a/dom/media/MediaMIMETypes.h
+++ b/dom/media/MediaMIMETypes.h
@@ -7,23 +7,46 @@
 #ifndef MediaMIMETypes_h_
 #define MediaMIMETypes_h_
 
 #include "mozilla/Maybe.h"
 #include "nsString.h"
 
 namespace mozilla {
 
+// Class containing only pre-parsed lowercase media MIME type/subtype.
+class MediaMIMEType
+{
+public:
+  // MIME "type/subtype", always lowercase.
+  const nsACString& AsString() const { return mMIMEType; }
+
+private:
+  friend Maybe<MediaMIMEType> MakeMediaMIMEType(const nsAString& aType);
+  friend class MediaExtendedMIMEType;
+  explicit MediaMIMEType(const nsACString& aType);
+
+  nsCString mMIMEType; // UTF8 MIME "type/subtype".
+};
+
+Maybe<MediaMIMEType> MakeMediaMIMEType(const nsAString& aType);
+Maybe<MediaMIMEType> MakeMediaMIMEType(const nsACString& aType);
+Maybe<MediaMIMEType> MakeMediaMIMEType(const char* aType);
+
+
 // Class containing pre-parsed media MIME type parameters, e.g.:
 // MIME type/subtype, optional codecs, etc.
 class MediaExtendedMIMEType
 {
 public:
+  explicit MediaExtendedMIMEType(const MediaMIMEType& aType);
+  explicit MediaExtendedMIMEType(MediaMIMEType&& aType);
+
   // MIME "type/subtype".
-  const nsACString& Type() const { return mMIMEType; }
+  const MediaMIMEType& Type() const { return mMIMEType; }
 
   // Was there an explicit 'codecs' parameter provided?
   bool HaveCodecs() const { return mHaveCodecs; }
   // Codecs. May be empty if not provided or explicitly provided as empty.
   const nsAString& GetCodecs() const { return mCodecs; }
 
   // Sizes and rates.
   Maybe<int32_t> GetWidth() const { return GetMaybeNumber(mWidth); }
@@ -38,23 +61,23 @@ private:
                         int32_t aWidth, int32_t aHeight,
                         int32_t aFramerate, int32_t aBitrate);
 
   Maybe<int32_t> GetMaybeNumber(int32_t aNumber) const
   {
     return (aNumber < 0) ? Maybe<int32_t>(Nothing()) : Some(int32_t(aNumber));
   }
 
-  nsCString mMIMEType; // UTF8 MIME type.
-  bool mHaveCodecs; // If false, mCodecs must be empty.
+  MediaMIMEType mMIMEType; // MIME type/subtype.
+  bool mHaveCodecs = false; // If false, mCodecs must be empty.
   nsString mCodecs;
-  int32_t mWidth; // -1 if not provided.
-  int32_t mHeight; // -1 if not provided.
-  int32_t mFramerate; // -1 if not provided.
-  int32_t mBitrate; // -1 if not provided.
+  int32_t mWidth = -1; // -1 if not provided.
+  int32_t mHeight = -1; // -1 if not provided.
+  int32_t mFramerate = -1; // -1 if not provided.
+  int32_t mBitrate = -1; // -1 if not provided.
 };
 
 Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType);
 Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsACString& aType);
 Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const char* aType);
 
 } // namespace mozilla