diff --git a/dom/media/platforms/DurationMap.h b/dom/media/platforms/DurationMap.h new file mode 100644 index 000000000000..64dd7812a76e --- /dev/null +++ b/dom/media/platforms/DurationMap.h @@ -0,0 +1,56 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_DurationMap_h +#define mozilla_DurationMap_h + +#include "mozilla/Pair.h" +#include "nsTArray.h" + +namespace mozilla { + +class DurationMap +{ +public: + typedef Pair DurationElement; + + DurationMap() : mMutex("DurationMap") { } + + // Insert Key and Duration pair at the end of our map. + void Insert(int64_t aKey, int64_t aDuration) + { + MutexAutoLock lock(mMutex); + mMap.AppendElement(MakePair(aKey, aDuration)); + } + // Sets aDuration matching aKey and remove it from the map if found. + // The element returned is the first one found. + // Returns true if found, false otherwise. + bool Find(int64_t aKey, int64_t& aDuration) + { + MutexAutoLock lock(mMutex); + for (uint32_t i = 0; i < mMap.Length(); i++) { + DurationElement& element = mMap[i]; + if (element.first() == aKey) { + aDuration = element.second(); + mMap.RemoveElementAt(i); + return true; + } + } + return false; + } + // Remove all elements of the map. + void Clear() + { + MutexAutoLock lock(mMutex); + mMap.Clear(); + } + +private: + Mutex mMutex; // To protect mMap. + AutoTArray mMap; +}; + +} // namespace mozilla + +#endif // mozilla_DurationMap_h diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h index 6f9f858b75d0..2946e47ec557 100644 --- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h +++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h @@ -9,8 +9,7 @@ #include "FFmpegLibWrapper.h" #include "FFmpegDataDecoder.h" -#include "mozilla/Pair.h" -#include "nsTArray.h" +#include "DurationMap.h" namespace mozilla { @@ -87,41 +86,6 @@ private: PtsCorrectionContext mPtsContext; int64_t mLastInputDts; - class DurationMap - { - public: - typedef Pair DurationElement; - - // Insert Key and Duration pair at the end of our map. - void Insert(int64_t aKey, int64_t aDuration) - { - mMap.AppendElement(MakePair(aKey, aDuration)); - } - // Sets aDuration matching aKey and remove it from the map if found. - // The element returned is the first one found. - // Returns true if found, false otherwise. - bool Find(int64_t aKey, int64_t& aDuration) - { - for (uint32_t i = 0; i < mMap.Length(); i++) { - DurationElement& element = mMap[i]; - if (element.first() == aKey) { - aDuration = element.second(); - mMap.RemoveElementAt(i); - return true; - } - } - return false; - } - // Remove all elements of the map. - void Clear() - { - mMap.Clear(); - } - - private: - AutoTArray mMap; - }; - DurationMap mDurationMap; }; diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build index eae28fb3de5b..ca521d20d452 100644 --- a/dom/media/platforms/moz.build +++ b/dom/media/platforms/moz.build @@ -10,6 +10,7 @@ EXPORTS += [ 'agnostic/TheoraDecoder.h', 'agnostic/VorbisDecoder.h', 'agnostic/VPXDecoder.h', + 'DurationMap.h', 'MediaTelemetryConstants.h', 'PDMFactory.h', 'PlatformDecoderModule.h',