mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1205351 - Replace nsBaseHashtable::Enumerate() calls in dom/media/ with iterators r=cpearce
This commit is contained in:
parent
165270a482
commit
34a6dca7cc
@ -59,42 +59,12 @@ MediaKeys::MediaKeys(nsPIDOMWindow* aParent,
|
||||
this, NS_ConvertUTF16toUTF8(mKeySystem).get());
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
RejectPromises(const uint32_t& aKey,
|
||||
nsRefPtr<dom::DetailedPromise>& aPromise,
|
||||
void* aClosure)
|
||||
{
|
||||
aPromise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
|
||||
NS_LITERAL_CSTRING("Promise still outstanding at MediaKeys shutdown"));
|
||||
((MediaKeys*)aClosure)->Release();
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
MediaKeys::~MediaKeys()
|
||||
{
|
||||
Shutdown();
|
||||
EME_LOG("MediaKeys[%p] destroyed", this);
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
CopySessions(const nsAString& aKey,
|
||||
nsRefPtr<MediaKeySession>& aSession,
|
||||
void* aClosure)
|
||||
{
|
||||
KeySessionHashMap* p = static_cast<KeySessionHashMap*>(aClosure);
|
||||
p->Put(aSession->GetSessionId(), aSession);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
CloseSessions(const nsAString& aKey,
|
||||
nsRefPtr<MediaKeySession>& aSession,
|
||||
void* aClosure)
|
||||
{
|
||||
aSession->OnClosed();
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
MediaKeys::Terminated()
|
||||
{
|
||||
@ -102,8 +72,14 @@ MediaKeys::Terminated()
|
||||
|
||||
KeySessionHashMap keySessions;
|
||||
// Remove entries during iteration will screw it. Make a copy first.
|
||||
mKeySessions.Enumerate(&CopySessions, &keySessions);
|
||||
keySessions.Enumerate(&CloseSessions, nullptr);
|
||||
for (auto iter = mKeySessions.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsRefPtr<MediaKeySession>& session = iter.Data();
|
||||
keySessions.Put(session->GetSessionId(), session);
|
||||
}
|
||||
for (auto iter = keySessions.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsRefPtr<MediaKeySession>& session = iter.Data();
|
||||
session->OnClosed();
|
||||
}
|
||||
keySessions.Clear();
|
||||
MOZ_ASSERT(mKeySessions.Count() == 0);
|
||||
|
||||
@ -125,7 +101,12 @@ MediaKeys::Shutdown()
|
||||
|
||||
nsRefPtr<MediaKeys> kungFuDeathGrip = this;
|
||||
|
||||
mPromises.Enumerate(&RejectPromises, this);
|
||||
for (auto iter = mPromises.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsRefPtr<dom::DetailedPromise>& promise = iter.Data();
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
|
||||
NS_LITERAL_CSTRING("Promise still outstanding at MediaKeys shutdown"));
|
||||
Release();
|
||||
}
|
||||
mPromises.Clear();
|
||||
}
|
||||
|
||||
|
@ -311,20 +311,16 @@ GMPServiceChild::GetBridgedGMPContentParent(ProcessId aOtherPid,
|
||||
mContentParents.Get(aOtherPid, aGMPContentParent);
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
FindAndRemoveGMPContentParent(const uint64_t& aKey,
|
||||
nsRefPtr<GMPContentParent>& aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
return aData == aUserArg ?
|
||||
(PLDHashOperator)(PL_DHASH_STOP | PL_DHASH_REMOVE) :
|
||||
PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
GMPServiceChild::RemoveGMPContentParent(GMPContentParent* aGMPContentParent)
|
||||
{
|
||||
mContentParents.Enumerate(FindAndRemoveGMPContentParent, aGMPContentParent);
|
||||
for (auto iter = mContentParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsRefPtr<GMPContentParent>& parent = iter.Data();
|
||||
if (parent == aGMPContentParent) {
|
||||
iter.Remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
|
@ -847,32 +847,6 @@ MediaCodecReader::WaitFenceAndReleaseOutputBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
MediaCodecReader::ReleaseTextureClient(TextureClient* aClient,
|
||||
size_t& aIndex,
|
||||
void* aUserArg)
|
||||
{
|
||||
nsRefPtr<MediaCodecReader> reader = static_cast<MediaCodecReader*>(aUserArg);
|
||||
MOZ_ASSERT(reader, "reader should not be nullptr in ReleaseTextureClient()");
|
||||
|
||||
return reader->ReleaseTextureClient(aClient, aIndex);
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
MediaCodecReader::ReleaseTextureClient(TextureClient* aClient,
|
||||
size_t& aIndex)
|
||||
{
|
||||
MOZ_ASSERT(aClient, "TextureClient should be a valid pointer");
|
||||
|
||||
aClient->ClearRecycleCallback();
|
||||
|
||||
if (mVideoTrack.mCodec != nullptr) {
|
||||
mVideoTrack.mCodec->releaseOutputBuffer(aIndex);
|
||||
}
|
||||
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
MediaCodecReader::ReleaseAllTextureClients()
|
||||
{
|
||||
@ -884,7 +858,17 @@ MediaCodecReader::ReleaseAllTextureClients()
|
||||
}
|
||||
printf_stderr("All TextureClients should be released already");
|
||||
|
||||
mTextureClientIndexes.Enumerate(MediaCodecReader::ReleaseTextureClient, this);
|
||||
for (auto iter = mTextureClientIndexes.Iter(); !iter.Done(); iter.Next()) {
|
||||
TextureClient* client = iter.Key();
|
||||
size_t& index = iter.Data();
|
||||
|
||||
client->ClearRecycleCallback();
|
||||
|
||||
if (mVideoTrack.mCodec != nullptr) {
|
||||
mVideoTrack.mCodec->releaseOutputBuffer(index);
|
||||
}
|
||||
iter.Remove();
|
||||
}
|
||||
mTextureClientIndexes.Clear();
|
||||
}
|
||||
|
||||
|
@ -397,11 +397,6 @@ private:
|
||||
void WaitFenceAndReleaseOutputBuffer();
|
||||
|
||||
void ReleaseRecycledTextureClients();
|
||||
static PLDHashOperator ReleaseTextureClient(TextureClient* aClient,
|
||||
size_t& aIndex,
|
||||
void* aUserArg);
|
||||
PLDHashOperator ReleaseTextureClient(TextureClient* aClient,
|
||||
size_t& aIndex);
|
||||
|
||||
void ReleaseAllTextureClients();
|
||||
|
||||
|
@ -19,15 +19,6 @@ namespace mozilla {
|
||||
|
||||
typedef MozPromiseRequestHolder<CDMProxy::DecryptPromise> DecryptPromiseRequestHolder;
|
||||
|
||||
static PLDHashOperator
|
||||
DropDecryptPromises(MediaRawData* aKey,
|
||||
nsAutoPtr<DecryptPromiseRequestHolder>& aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
aData->DisconnectIfExists();
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
class EMEDecryptor : public MediaDataDecoder {
|
||||
|
||||
public:
|
||||
@ -107,7 +98,11 @@ public:
|
||||
nsresult Flush() override {
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
MOZ_ASSERT(!mIsShutdown);
|
||||
mDecrypts.Enumerate(&DropDecryptPromises, nullptr);
|
||||
for (auto iter = mDecrypts.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsAutoPtr<DecryptPromiseRequestHolder>& holder = iter.Data();
|
||||
holder->DisconnectIfExists();
|
||||
iter.Remove();
|
||||
}
|
||||
nsresult rv = mDecoder->Flush();
|
||||
unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
mSamplesWaitingForKey->Flush();
|
||||
@ -117,7 +112,11 @@ public:
|
||||
nsresult Drain() override {
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
MOZ_ASSERT(!mIsShutdown);
|
||||
mDecrypts.Enumerate(&DropDecryptPromises, nullptr);
|
||||
for (auto iter = mDecrypts.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsAutoPtr<DecryptPromiseRequestHolder>& holder = iter.Data();
|
||||
holder->DisconnectIfExists();
|
||||
iter.Remove();
|
||||
}
|
||||
nsresult rv = mDecoder->Drain();
|
||||
unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
return rv;
|
||||
|
@ -83,26 +83,21 @@ class OriginKeyStore : public nsISupports
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
HashCleaner(const nsACString& aOrigin, nsAutoPtr<OriginKey>& aOriginKey,
|
||||
void *aUserArg)
|
||||
{
|
||||
OriginKey* since = static_cast<OriginKey*>(aUserArg);
|
||||
|
||||
LOG((((aOriginKey->mSecondsStamp >= since->mSecondsStamp)?
|
||||
"%s: REMOVE %lld >= %lld" :
|
||||
"%s: KEEP %lld < %lld"),
|
||||
__FUNCTION__, aOriginKey->mSecondsStamp, since->mSecondsStamp));
|
||||
|
||||
return (aOriginKey->mSecondsStamp >= since->mSecondsStamp)?
|
||||
PL_DHASH_REMOVE : PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void Clear(int64_t aSinceWhen)
|
||||
{
|
||||
// Avoid int64_t* <-> void* casting offset
|
||||
OriginKey since(nsCString(), aSinceWhen / PR_USEC_PER_SEC);
|
||||
mKeys.Enumerate(HashCleaner, &since);
|
||||
for (auto iter = mKeys.Iter(); !iter.Done(); iter.Next()) {
|
||||
nsAutoPtr<OriginKey>& originKey = iter.Data();
|
||||
LOG((((originKey->mSecondsStamp >= since.mSecondsStamp)?
|
||||
"%s: REMOVE %lld >= %lld" :
|
||||
"%s: KEEP %lld < %lld"),
|
||||
__FUNCTION__, originKey->mSecondsStamp, since.mSecondsStamp));
|
||||
|
||||
if (originKey->mSecondsStamp >= since.mSecondsStamp) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
mPersistCount = 0;
|
||||
}
|
||||
|
||||
|
@ -141,25 +141,6 @@ MediaSystemResourceService::ReleaseResource(media::MediaSystemResourceManagerPar
|
||||
UpdateRequests(aResourceType);
|
||||
}
|
||||
|
||||
struct ReleaseResourceData
|
||||
{
|
||||
MediaSystemResourceService* mSelf;
|
||||
media::MediaSystemResourceManagerParent* mParent;
|
||||
};
|
||||
|
||||
/*static*/PLDHashOperator
|
||||
MediaSystemResourceService::ReleaseResourceForKey(const uint32_t& aKey,
|
||||
nsAutoPtr<MediaSystemResource>& aData,
|
||||
void* aClosure)
|
||||
{
|
||||
ReleaseResourceData* closure = static_cast<ReleaseResourceData*>(aClosure);
|
||||
|
||||
closure->mSelf->RemoveRequests(closure->mParent, static_cast<MediaSystemResourceType>(aKey));
|
||||
closure->mSelf->UpdateRequests(static_cast<MediaSystemResourceType>(aKey));
|
||||
|
||||
return PLDHashOperator::PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
MediaSystemResourceService::ReleaseResource(media::MediaSystemResourceManagerParent* aParent)
|
||||
{
|
||||
@ -169,8 +150,11 @@ MediaSystemResourceService::ReleaseResource(media::MediaSystemResourceManagerPar
|
||||
return;
|
||||
}
|
||||
|
||||
ReleaseResourceData data = { this, aParent };
|
||||
mResources.Enumerate(ReleaseResourceForKey, &data);
|
||||
for (auto iter = mResources.Iter(); !iter.Done(); iter.Next()) {
|
||||
const uint32_t& key = iter.Key();
|
||||
RemoveRequests(aParent, static_cast<MediaSystemResourceType>(key));
|
||||
UpdateRequests(static_cast<MediaSystemResourceType>(key));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -77,10 +77,6 @@ private:
|
||||
|
||||
void UpdateRequests(MediaSystemResourceType aResourceType);
|
||||
|
||||
static PLDHashOperator ReleaseResourceForKey(const uint32_t& aKey,
|
||||
nsAutoPtr<MediaSystemResource>& aData,
|
||||
void* aClosure);
|
||||
|
||||
bool mDestroyed;
|
||||
|
||||
nsClassHashtable<nsUint32HashKey, MediaSystemResource> mResources;
|
||||
|
@ -501,40 +501,8 @@ nsPicoService::GetServiceType(SpeechServiceType* aServiceType)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
struct VoiceTraverserData
|
||||
{
|
||||
nsPicoService* mService;
|
||||
nsSynthVoiceRegistry* mRegistry;
|
||||
};
|
||||
|
||||
// private methods
|
||||
|
||||
static PLDHashOperator
|
||||
PicoAddVoiceTraverser(const nsAString& aUri,
|
||||
nsRefPtr<PicoVoice>& aVoice,
|
||||
void* aUserArg)
|
||||
{
|
||||
// If we are missing either a language or a voice resource, it is invalid.
|
||||
if (aVoice->mTaFile.IsEmpty() || aVoice->mSgFile.IsEmpty()) {
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
VoiceTraverserData* data = static_cast<VoiceTraverserData*>(aUserArg);
|
||||
|
||||
nsAutoString name;
|
||||
name.AssignLiteral("Pico ");
|
||||
name.Append(aVoice->mLanguage);
|
||||
|
||||
// This service is multi-threaded and can handle more than one utterance at a
|
||||
// time before previous utterances end. So, aQueuesUtterances == false
|
||||
DebugOnly<nsresult> rv =
|
||||
data->mRegistry->AddVoice(
|
||||
data->mService, aUri, name, aVoice->mLanguage, true, false);
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to add voice");
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
nsPicoService::Init()
|
||||
{
|
||||
@ -617,8 +585,28 @@ nsPicoService::Init()
|
||||
void
|
||||
nsPicoService::RegisterVoices()
|
||||
{
|
||||
VoiceTraverserData data = { this, nsSynthVoiceRegistry::GetInstance() };
|
||||
mVoices.Enumerate(PicoAddVoiceTraverser, &data);
|
||||
nsSynthVoiceRegistry* registry = nsSynthVoiceRegistry::GetInstance();
|
||||
|
||||
for (auto iter = mVoices.Iter(); !iter.Done(); iter.Next()) {
|
||||
const nsAString& uri = iter.Key();
|
||||
nsRefPtr<PicoVoice>& voice = iter.Data();
|
||||
|
||||
// If we are missing either a language or a voice resource, it is invalid.
|
||||
if (voice->mTaFile.IsEmpty() || voice->mSgFile.IsEmpty()) {
|
||||
iter.Remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
name.AssignLiteral("Pico ");
|
||||
name.Append(voice->mLanguage);
|
||||
|
||||
// This service is multi-threaded and can handle more than one utterance at a
|
||||
// time before previous utterances end. So, aQueuesUtterances == false
|
||||
DebugOnly<nsresult> rv =
|
||||
registry->AddVoice(this, uri, name, voice->mLanguage, true, false);
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to add voice");
|
||||
}
|
||||
|
||||
mInitialized = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user