Bug 1347439 - part 6: rename DurationMap and turn it into a generic class. r?jya
Cherry-picked from
bug 1344649 part 3 for
bug 1336431
MozReview-Commit-ID: CYwwfBka11S
deleted file mode 100644
--- a/dom/media/platforms/DurationMap.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* 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
new file mode 100644
--- /dev/null
+++ b/dom/media/platforms/SimpleMap.h
@@ -0,0 +1,57 @@
+/* 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_SimpleMap_h
+#define mozilla_SimpleMap_h
+
+#include "mozilla/Pair.h"
+#include "nsTArray.h"
+
+namespace mozilla {
+
+template<typename T>
+class SimpleMap
+{
+public:
+ typedef Pair<int64_t, T> Element;
+
+ SimpleMap() : mMutex("SimpleMap") { }
+
+ // Insert Key and Value pair at the end of our map.
+ void Insert(int64_t aKey, const T& aValue)
+ {
+ MutexAutoLock lock(mMutex);
+ mMap.AppendElement(MakePair(aKey, aValue));
+ }
+ // Sets aValue 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, T& aValue)
+ {
+ MutexAutoLock lock(mMutex);
+ for (uint32_t i = 0; i < mMap.Length(); i++) {
+ Element& element = mMap[i];
+ if (element.first() == aKey) {
+ aValue = 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<Element, 16> mMap;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_SimpleMap_h
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -5,26 +5,26 @@
#include "AndroidDecoderModule.h"
#include "AndroidBridge.h"
#include "AndroidSurfaceTexture.h"
#include "FennecJNINatives.h"
#include "GLImages.h"
#include "MediaData.h"
#include "MediaInfo.h"
+#include "SimpleMap.h"
#include "VideoUtils.h"
#include "VPXDecoder.h"
#include "nsThreadUtils.h"
#include "nsPromiseFlatString.h"
#include "nsIGfxInfo.h"
#include "prlog.h"
-#include "DurationMap.h"
#include <jni.h>
#undef LOG
#define LOG(arg, ...) MOZ_LOG(sAndroidDecoderModuleLog, \
mozilla::LogLevel::Debug, ("RemoteDataDecoder(%p)::%s: " arg, \
this, __func__, ##__VA_ARGS__))
using namespace mozilla;
@@ -260,17 +260,17 @@ public:
}
bool SupportDecoderRecycling() const override { return mIsCodecSupportAdaptivePlayback; }
private:
layers::ImageContainer* mImageContainer;
const VideoInfo& mConfig;
RefPtr<AndroidSurfaceTexture> mSurfaceTexture;
- DurationMap mInputDurations;
+ SimpleMap<int64_t> mInputDurations;
bool mIsCodecSupportAdaptivePlayback = false;
};
class RemoteEMEVideoDecoder : public RemoteVideoDecoder {
public:
RemoteEMEVideoDecoder(const VideoInfo& aConfig,
MediaFormat::Param aFormat,
MediaDataDecoderCallback* aCallback,
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
@@ -4,31 +4,32 @@
* 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 "DurationMap.h"
+#include "SimpleMap.h"
namespace mozilla
{
template <int V>
class FFmpegVideoDecoder : public FFmpegDataDecoder<V>
{
};
template <>
class FFmpegVideoDecoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
{
typedef mozilla::layers::Image Image;
typedef mozilla::layers::ImageContainer ImageContainer;
+ typedef SimpleMap<int64_t> DurationMap;
public:
FFmpegVideoDecoder(FFmpegLibWrapper* aLib, TaskQueue* aTaskQueue,
MediaDataDecoderCallback* aCallback,
const VideoInfo& aConfig,
ImageContainer* aImageContainer);
virtual ~FFmpegVideoDecoder();
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -5,20 +5,20 @@
# 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',
+ 'SimpleMap.h',
'wrappers/FuzzingWrapper.h',
'wrappers/H264Converter.h'
]
UNIFIED_SOURCES += [
'agnostic/AgnosticDecoderModule.cpp',
'agnostic/BlankDecoderModule.cpp',
'agnostic/OpusDecoder.cpp',