Bug 1344649 - part 3: rename DurationMap and turn it into a generic class. r=jya a=gchang
authorJohn Lin <jolin@mozilla.com>
Tue, 07 Mar 2017 19:49:08 +0800
changeset 395230 28d1b6af43b76327a0fd0c8e76e0ed57d204c70b
parent 395229 2ce9976ffff3f4acea9cfa1fe03c73445145fed7
child 395231 3facbb51731c2953b8235a65e679d59f9881e059
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, gchang
bugs1344649
milestone54.0a2
Bug 1344649 - part 3: rename DurationMap and turn it into a generic class. r=jya a=gchang MozReview-Commit-ID: AMMxMPkuYXk
dom/media/platforms/DurationMap.h
dom/media/platforms/SimpleMap.h
dom/media/platforms/android/RemoteDataDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
dom/media/platforms/moz.build
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
@@ -1,16 +1,16 @@
 /* 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/. */
 
 #include "AndroidBridge.h"
 #include "AndroidDecoderModule.h"
 #include "AndroidSurfaceTexture.h"
-#include "DurationMap.h"
+#include "SimpleMap.h"
 #include "FennecJNINatives.h"
 #include "GLImages.h"
 #include "MediaData.h"
 #include "MediaInfo.h"
 #include "VPXDecoder.h"
 #include "VideoUtils.h"
 #include "mozilla/Mutex.h"
 #include "nsIGfxInfo.h"
@@ -280,17 +280,17 @@ public:
     MOZ_ASSERT(aConfig.GetAsVideoInfo());
     MutexAutoLock lock(mMutex);
     mConfig = *aConfig.GetAsVideoInfo();
   }
 
 private:
   layers::ImageContainer* mImageContainer;
   RefPtr<AndroidSurfaceTexture> mSurfaceTexture;
-  DurationMap mInputDurations;
+  SimpleMap<int64_t> mInputDurations;
   bool mIsCodecSupportAdaptivePlayback = false;
   Mutex mMutex; // Protects mConfig
   VideoInfo mConfig;
 };
 
 class RemoteAudioDecoder : public RemoteDataDecoder
 {
 public:
--- 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,
                      const VideoInfo& aConfig,
                      ImageContainer* aImageContainer,
                      bool aLowLatency);
   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/H264Converter.h',
     'wrappers/MediaDataDecoderProxy.h'
 
 ]
 
 UNIFIED_SOURCES += [
     'agnostic/AgnosticDecoderModule.cpp',
     'agnostic/BlankDecoderModule.cpp',