Bug 1344649 - part 3: rename DurationMap and turn it into a generic class. r?jya draft
authorJohn Lin <jolin@mozilla.com>
Tue, 07 Mar 2017 19:49:08 +0800
changeset 497993 286ac701c9221872329bf601adb70344d3cf0e21
parent 497992 625093bc6c8db1a106cb6f6b5f722d757e9493db
child 497994 7b7dcc98d0d855d35d127712fd080a0bc4ef5796
push id49080
push userbmo:jolin@mozilla.com
push dateTue, 14 Mar 2017 04:52:48 +0000
reviewersjya
bugs1344649
milestone55.0a1
Bug 1344649 - part 3: rename DurationMap and turn it into a generic class. r?jya 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',