зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1336792 - part 1: extract DurationMap and make it thread safe. r=jya
MozReview-Commit-ID: EGSc5sMfxvL --HG-- extra : rebase_source : 465a09144b1ffe129761a64b17eb80aa3b938347
This commit is contained in:
Родитель
f0bfc53206
Коммит
286d9b45fd
|
@ -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
|
|
@ -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<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;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ EXPORTS += [
|
|||
'agnostic/TheoraDecoder.h',
|
||||
'agnostic/VorbisDecoder.h',
|
||||
'agnostic/VPXDecoder.h',
|
||||
'DurationMap.h',
|
||||
'MediaTelemetryConstants.h',
|
||||
'PDMFactory.h',
|
||||
'PlatformDecoderModule.h',
|
||||
|
|
Загрузка…
Ссылка в новой задаче