Bug 1329568 - Media...Type::SizeOf... methods - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 22 Dec 2016 11:54:56 +1100
changeset 460524 46f42dcf95bdd67a7c4d8d2e06c7052064c82986
parent 460523 e378124fded2ec917c2306874ca06351d6b107b3
child 460525 58b6eb38da30fac3d139f447ce93bb61c0ad24e4
push id41406
push usergsquelart@mozilla.com
push dateFri, 13 Jan 2017 06:23:59 +0000
reviewersjya
bugs1329568
milestone53.0a1
Bug 1329568 - Media...Type::SizeOf... methods - r?jya When replacing strings with MediaContentType objects, some classes will want to know about their size. MozReview-Commit-ID: LNdaaUdJac3
dom/media/MediaContentType.cpp
dom/media/MediaContentType.h
dom/media/MediaMIMETypes.cpp
dom/media/MediaMIMETypes.h
--- a/dom/media/MediaContentType.cpp
+++ b/dom/media/MediaContentType.cpp
@@ -5,16 +5,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaContentType.h"
 
 #include "nsContentTypeParser.h"
 
 namespace mozilla {
 
+size_t
+MediaContentType::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return mExtendedMIMEType.SizeOfExcludingThis(aMallocSizeOf);
+}
+
 Maybe<MediaContentType>
 MakeMediaContentType(const nsAString& aType)
 {
   Maybe<MediaExtendedMIMEType> mime = MakeMediaExtendedMIMEType(aType);
   if (mime) {
     return Some(MediaContentType(Move(*mime)));
   }
   return Nothing();
--- a/dom/media/MediaContentType.h
+++ b/dom/media/MediaContentType.h
@@ -30,16 +30,18 @@ public:
   explicit MediaContentType(MediaExtendedMIMEType&& aType)
     : mExtendedMIMEType(Move(aType))
   {
   }
 
   const MediaMIMEType& Type() const { return mExtendedMIMEType.Type(); }
   const MediaExtendedMIMEType& ExtendedType() const { return mExtendedMIMEType; }
 
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 private:
   MediaExtendedMIMEType mExtendedMIMEType;
 };
 
 Maybe<MediaContentType> MakeMediaContentType(const nsAString& aType);
 Maybe<MediaContentType> MakeMediaContentType(const nsACString& aType);
 Maybe<MediaContentType> MakeMediaContentType(const char* aType);
 
--- a/dom/media/MediaMIMETypes.cpp
+++ b/dom/media/MediaMIMETypes.cpp
@@ -33,16 +33,22 @@ MediaMIMEType::HasAudioMajorType() const
 }
 
 bool
 MediaMIMEType::HasVideoMajorType() const
 {
   return StartsWith(mMIMEType, "video/");
 }
 
+size_t
+MediaMIMEType::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return mMIMEType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+}
+
 MediaMIMEType::MediaMIMEType(const nsACString& aType)
   : mMIMEType(aType)
 {
 }
 
 Maybe<MediaMIMEType>
 MakeMediaMIMEType(const nsAString& aType)
 {
@@ -96,16 +102,23 @@ MediaCodecs::ContainsAll(const MediaCode
   for (const auto& codecToTest : codecsToTest) {
     if (!Contains(codecToTest)) {
       return false;
     }
   }
   return true;
 }
 
+size_t
+MediaCodecs::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return mCodecs.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+}
+
+
 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)) {
@@ -170,16 +183,23 @@ MakeMediaExtendedMIMEType(const nsAStrin
   int32_t bitrate = GetParameterAsNumber(parser, "bitrate", -1);
 
   return Some(MediaExtendedMIMEType(mime8,
                                     haveCodecs, codecs,
                                     width, height,
                                     framerate, bitrate));
 }
 
+size_t
+MediaExtendedMIMEType::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  return mMIMEType.SizeOfExcludingThis(aMallocSizeOf)
+         + mCodecs.SizeOfExcludingThis(aMallocSizeOf);
+}
+
 Maybe<MediaExtendedMIMEType>
 MakeMediaExtendedMIMEType(const nsACString& aType)
 {
   return MakeMediaExtendedMIMEType(NS_ConvertUTF8toUTF16(aType));
 }
 
 Maybe<MediaExtendedMIMEType>
 MakeMediaExtendedMIMEType(const char* aType)
--- a/dom/media/MediaMIMETypes.h
+++ b/dom/media/MediaMIMETypes.h
@@ -82,16 +82,18 @@ public:
   // True if type starts with "audio/".
   // Note that some audio content could be stored in a "video/..." container!
   bool HasAudioMajorType() const;
   // True if type starts with "video/".
   // Note that this does not guarantee 100% that the content is actually video!
   // (e.g., "video/webm" could contain a vorbis audio track.)
   bool HasVideoMajorType() const;
 
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 private:
   friend Maybe<MediaMIMEType> MakeMediaMIMEType(const nsAString& aType);
   friend class MediaExtendedMIMEType;
   explicit MediaMIMEType(const nsACString& aType);
 
   nsCString mMIMEType; // UTF8 MIME "type/subtype".
 };
 
@@ -128,16 +130,18 @@ public:
   RangeType Range() const
   {
     return RangeType(mCodecs);
   };
 
   bool Contains(const nsAString& aCodec) const;
   bool ContainsAll(const MediaCodecs& aCodecs) const;
 
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 private:
   // UTF16 comma-separated list of codecs.
   // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
   // of the 'codecs' parameter.
   nsString mCodecs;
 };
 
 
@@ -158,16 +162,18 @@ public:
   const MediaCodecs& Codecs() const { return mCodecs; }
 
   // Sizes and rates.
   Maybe<int32_t> GetWidth() const { return GetMaybeNumber(mWidth); }
   Maybe<int32_t> GetHeight() const { return GetMaybeNumber(mHeight); }
   Maybe<int32_t> GetFramerate() const { return GetMaybeNumber(mFramerate); }
   Maybe<int32_t> GetBitrate() const { return GetMaybeNumber(mBitrate); }
 
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+
 private:
   friend Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType);
   MediaExtendedMIMEType(const nsACString& aMIMEType,
                         bool aHaveCodecs, const nsAString& aCodecs,
                         int32_t aWidth, int32_t aHeight,
                         int32_t aFramerate, int32_t aBitrate);
 
   Maybe<int32_t> GetMaybeNumber(int32_t aNumber) const