tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 5085c13ae34cc39743b3c23dfb00e8af4c849a2b
parent cefcc4a840eab813b8a4c436b7358562a7d8f313
Author: az <azebrowski@mozilla.com>
Date:   Mon,  1 Dec 2025 17:07:04 +0000

Bug 1993541 - Part 1: Add function in MediaExtendedMIMEType to return the total number of parameters. r=pehrsons

Differential Revision: https://phabricator.services.mozilla.com/D273763

Diffstat:
Mdom/media/MediaMIMETypes.cpp | 11+++++++++++
Mdom/media/MediaMIMETypes.h | 10+++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/dom/media/MediaMIMETypes.cpp b/dom/media/MediaMIMETypes.cpp @@ -7,6 +7,7 @@ #include "MediaMIMETypes.h" #include "mozilla/dom/MediaCapabilitiesBinding.h" +#include "mozilla/dom/MimeType.h" #include "nsContentTypeParser.h" namespace mozilla { @@ -245,6 +246,16 @@ Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType( aConfig.mBitrate.WasPassed() ? aConfig.mBitrate.Value() : 131072)); } +size_t MediaExtendedMIMEType::GetParameterCount() const { + if (mNumParamsCached) { + return mNumParams; + } + mNumParamsCached = true; + RefPtr<CMimeType> parsed = CMimeType::Parse(mOriginalString); + mNumParams = parsed ? parsed->GetParameterCount() : 0; + return mNumParams; +} + size_t MediaExtendedMIMEType::SizeOfExcludingThis( MallocSizeOf aMallocSizeOf) const { return mOriginalString.SizeOfExcludingThisIfUnshared(aMallocSizeOf) + diff --git a/dom/media/MediaMIMETypes.h b/dom/media/MediaMIMETypes.h @@ -166,8 +166,13 @@ class MediaExtendedMIMEType { Maybe<int32_t> GetChannels() const { return GetMaybeNumber(mChannels); } Maybe<int32_t> GetSamplerate() const { return GetMaybeNumber(mSamplerate); } + // Total number of parameters, including non-media parameters. Lazily init'd - + // mutates mNumParams and numParamsCached on first use. Callable from any + // thread, not thread safe. + size_t GetParameterCount() const; + // Original string. Note that "type/subtype" may not be lowercase, - // use Type().AsString() instead to get the normalized "type/subtype". + // use Type().AsString() instead to get the normalized "type/subtype" const nsCString& OriginalString() const { return mOriginalString; } size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; @@ -207,6 +212,9 @@ class MediaExtendedMIMEType { int32_t mSamplerate = -1; // -1 if not provided. // For both audio and video. int32_t mBitrate = -1; // -1 if not provided. + // General parameter information + mutable size_t mNumParams = 0; // lazily init'd since counting params + mutable bool mNumParamsCached = false; // needs additional parser (CMimeType) }; Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType);