Bug 1336792 - part 1: extract DurationMap and make it thread safe. r?jya
MozReview-Commit-ID: EGSc5sMfxvL
new file mode 100644
--- /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<int64_t, int64_t> 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<DurationElement, 16> mMap;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_DurationMap_h
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
@@ -4,18 +4,17 @@
* 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 __FFmpegVideoDecoder_h__
#define __FFmpegVideoDecoder_h__
#include "FFmpegLibWrapper.h"
#include "FFmpegDataDecoder.h"
-#include "mozilla/Pair.h"
-#include "nsTArray.h"
+#include "DurationMap.h"
namespace mozilla
{
template <int V>
class FFmpegVideoDecoder : public FFmpegDataDecoder<V>
{
};
@@ -82,49 +81,14 @@ private:
int64_t mNumFaultyDts; /// Number of incorrect DTS values so far
int64_t mLastPts; /// PTS of the last frame
int64_t mLastDts; /// DTS of the last frame
};
PtsCorrectionContext mPtsContext;
int64_t mLastInputDts;
- class DurationMap
- {
- public:
- typedef Pair<int64_t, int64_t> 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<DurationElement, 16> mMap;
- };
-
DurationMap mDurationMap;
};
} // namespace mozilla
#endif // __FFmpegVideoDecoder_h__
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -5,16 +5,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS += [
'agnostic/AgnosticDecoderModule.h',
'agnostic/OpusDecoder.h',
'agnostic/TheoraDecoder.h',
'agnostic/VorbisDecoder.h',
'agnostic/VPXDecoder.h',
+ 'DurationMap.h',
'MediaTelemetryConstants.h',
'PDMFactory.h',
'PlatformDecoderModule.h',
'wrappers/H264Converter.h'
]
UNIFIED_SOURCES += [
'agnostic/AgnosticDecoderModule.cpp',