Bug 1761851 - Replace WebMBufferedState's ReentrantMonitor with a Mutex. r=media-playback-reviewers,bryce

WebMBufferedState doesn't use the reentrancy or wait/notify features of a monitor, so use a simple Mutex instead.

Differential Revision: https://phabricator.services.mozilla.com/D142277
This commit is contained in:
Matthew Gregan 2022-03-28 23:11:54 +00:00
Родитель 5fabd3fe72
Коммит 47637cdee0
2 изменённых файлов: 13 добавлений и 14 удалений

Просмотреть файл

@ -313,7 +313,7 @@ bool WebMBufferedState::CalculateBufferedForRange(int64_t aStartOffset,
int64_t aEndOffset,
uint64_t* aStartTime,
uint64_t* aEndTime) {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
// Find the first WebMTimeDataOffset at or after aStartOffset.
uint32_t start = mTimeMapping.IndexOfFirstElementGt(aStartOffset - 1,
@ -360,7 +360,7 @@ bool WebMBufferedState::CalculateBufferedForRange(int64_t aStartOffset,
}
bool WebMBufferedState::GetOffsetForTime(uint64_t aTime, int64_t* aOffset) {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
if (mTimeMapping.IsEmpty()) {
return false;
@ -412,7 +412,7 @@ void WebMBufferedState::NotifyDataArrived(const unsigned char* aBuffer,
}
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
mRangeParsers[idx].Append(aBuffer, aLength, mTimeMapping);
}
@ -432,12 +432,12 @@ void WebMBufferedState::NotifyDataArrived(const unsigned char* aBuffer,
return;
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
mLastBlockOffset = mRangeParsers.LastElement().mBlockEndOffset;
}
void WebMBufferedState::Reset() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
mRangeParsers.Clear();
mTimeMapping.Clear();
}
@ -500,13 +500,13 @@ int64_t WebMBufferedState::GetInitEndOffset() {
}
int64_t WebMBufferedState::GetLastBlockOffset() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
return mLastBlockOffset;
}
bool WebMBufferedState::GetStartTime(uint64_t* aTime) {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
if (mTimeMapping.IsEmpty()) {
return false;
@ -523,7 +523,7 @@ bool WebMBufferedState::GetStartTime(uint64_t* aTime) {
bool WebMBufferedState::GetNextKeyframeTime(uint64_t aTime,
uint64_t* aKeyframeTime) {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
MutexAutoLock lock(mMutex);
int64_t offset = 0;
bool rv = GetOffsetForTime(aTime, &offset);
if (!rv) {

Просмотреть файл

@ -8,7 +8,7 @@
# include "nsISupportsImpl.h"
# include "nsTArray.h"
# include "mozilla/ReentrantMonitor.h"
# include "mozilla/Mutex.h"
# include "MediaResource.h"
namespace mozilla {
@ -261,8 +261,7 @@ class WebMBufferedState final {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebMBufferedState)
public:
WebMBufferedState()
: mReentrantMonitor("WebMBufferedState"), mLastBlockOffset(-1) {
WebMBufferedState() : mMutex("WebMBufferedState"), mLastBlockOffset(-1) {
MOZ_COUNT_CTOR(WebMBufferedState);
}
@ -296,13 +295,13 @@ class WebMBufferedState final {
MOZ_COUNTED_DTOR(WebMBufferedState)
// Synchronizes access to the mTimeMapping array and mLastBlockOffset.
ReentrantMonitor mReentrantMonitor;
Mutex mMutex;
// Sorted (by offset) map of data offsets to timecodes. Populated
// on the main thread as data is received and parsed by WebMBufferedParsers.
nsTArray<WebMTimeDataOffset> mTimeMapping GUARDED_BY(mReentrantMonitor);
nsTArray<WebMTimeDataOffset> mTimeMapping GUARDED_BY(mMutex);
// The last complete block parsed. -1 if not set.
int64_t mLastBlockOffset GUARDED_BY(mReentrantMonitor);
int64_t mLastBlockOffset GUARDED_BY(mMutex);
// Sorted (by offset) live parser instances. Main thread only.
nsTArray<WebMBufferedParser> mRangeParsers;