diff options
author | Moonchild <moonchild@palemoon.org> | 2023-10-25 03:59:10 +0200 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-10-25 03:59:10 +0200 |
commit | 782202963ef662aea5b51e182c4dcb3fd918c6d5 (patch) | |
tree | 19d678cf534faac6cca1fea1c43a50f68755d75e | |
parent | 6df4c1874704597159f84e7a8cedca6157f25ef8 (diff) | |
download | uxp-782202963ef662aea5b51e182c4dcb3fd918c6d5.tar.gz |
[media] Use RefPtr<TrackBuffersManager> instead of raw pointers
-rw-r--r-- | dom/media/mediasource/MediaSourceDemuxer.cpp | 39 | ||||
-rw-r--r-- | dom/media/mediasource/MediaSourceDemuxer.h | 10 | ||||
-rw-r--r-- | dom/media/mediasource/SourceBuffer.cpp | 4 |
3 files changed, 28 insertions, 25 deletions
diff --git a/dom/media/mediasource/MediaSourceDemuxer.cpp b/dom/media/mediasource/MediaSourceDemuxer.cpp index cace222167..4c8f1d0c94 100644 --- a/dom/media/mediasource/MediaSourceDemuxer.cpp +++ b/dom/media/mediasource/MediaSourceDemuxer.cpp @@ -62,7 +62,7 @@ MediaSourceDemuxer::AddSizeOfResources(MediaSourceDecoder::ResourceSizes* aSizes RefPtr<MediaSourceDecoder::ResourceSizes> sizes = aSizes; nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([self, sizes] () { - for (TrackBuffersManager* manager : self->mSourceBuffers) { + for (const RefPtr<TrackBuffersManager>& manager : self->mSourceBuffers) { manager->AddSizeOfResources(sizes); } }); @@ -171,42 +171,45 @@ MediaSourceDemuxer::GetCrypto() } void -MediaSourceDemuxer::AttachSourceBuffer(TrackBuffersManager* aSourceBuffer) +MediaSourceDemuxer::AttachSourceBuffer( + RefPtr<TrackBuffersManager>& aSourceBuffer) { - nsCOMPtr<nsIRunnable> task = - NewRunnableMethod<TrackBuffersManager*>( + nsCOMPtr<nsIRunnable> task = NewRunnableMethod<RefPtr<TrackBuffersManager>&&>( this, &MediaSourceDemuxer::DoAttachSourceBuffer, aSourceBuffer); GetTaskQueue()->Dispatch(task.forget()); } void -MediaSourceDemuxer::DoAttachSourceBuffer(mozilla::TrackBuffersManager* aSourceBuffer) +MediaSourceDemuxer::DoAttachSourceBuffer( + RefPtr<mozilla::TrackBuffersManager>&& aSourceBuffer) { MOZ_ASSERT(OnTaskQueue()); - mSourceBuffers.AppendElement(aSourceBuffer); + mSourceBuffers.AppendElement(Move(aSourceBuffer)); ScanSourceBuffersForContent(); } void -MediaSourceDemuxer::DetachSourceBuffer(TrackBuffersManager* aSourceBuffer) +MediaSourceDemuxer::DetachSourceBuffer( + RefPtr<TrackBuffersManager>& aSourceBuffer) { - nsCOMPtr<nsIRunnable> task = - NewRunnableMethod<TrackBuffersManager*>( - this, &MediaSourceDemuxer::DoDetachSourceBuffer, - aSourceBuffer); + RefPtr<MediaSourceDemuxer> self = this; + nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction( + [self, aSourceBuffer]() { + self->DoDetachSourceBuffer(aSourceBuffer); + }); GetTaskQueue()->Dispatch(task.forget()); } void -MediaSourceDemuxer::DoDetachSourceBuffer(TrackBuffersManager* aSourceBuffer) +MediaSourceDemuxer::DoDetachSourceBuffer( + const RefPtr<TrackBuffersManager>& aSourceBuffer) { MOZ_ASSERT(OnTaskQueue()); - for (uint32_t i = 0; i < mSourceBuffers.Length(); i++) { - if (mSourceBuffers[i].get() == aSourceBuffer) { - mSourceBuffers.RemoveElementAt(i); - } - } + mSourceBuffers.RemoveElementsBy( + [&aSourceBuffer](const RefPtr<TrackBuffersManager> aLinkedSourceBuffer) { + return aLinkedSourceBuffer == aSourceBuffer; + }); if (aSourceBuffer == mAudioTrack) { mAudioTrack = nullptr; } @@ -230,7 +233,7 @@ MediaSourceDemuxer::GetTrackInfo(TrackType aTrack) } } -TrackBuffersManager* +RefPtr<TrackBuffersManager> MediaSourceDemuxer::GetManager(TrackType aTrack) { MonitorAutoLock mon(mMonitor); diff --git a/dom/media/mediasource/MediaSourceDemuxer.h b/dom/media/mediasource/MediaSourceDemuxer.h index e9db46196c..1518364c33 100644 --- a/dom/media/mediasource/MediaSourceDemuxer.h +++ b/dom/media/mediasource/MediaSourceDemuxer.h @@ -45,8 +45,8 @@ public: void NotifyDataArrived() override; /* interface for TrackBuffersManager */ - void AttachSourceBuffer(TrackBuffersManager* aSourceBuffer); - void DetachSourceBuffer(TrackBuffersManager* aSourceBuffer); + void AttachSourceBuffer(RefPtr<TrackBuffersManager>& aSourceBuffer); + void DetachSourceBuffer(RefPtr<TrackBuffersManager>& aSourceBuffer); AutoTaskQueue* GetTaskQueue() { return mTaskQueue; } // Returns a string describing the state of the MediaSource internal @@ -64,10 +64,10 @@ private: // Scan source buffers and update information. bool ScanSourceBuffersForContent(); RefPtr<InitPromise> AttemptInit(); - TrackBuffersManager* GetManager(TrackInfo::TrackType aType); + RefPtr<TrackBuffersManager> GetManager(TrackInfo::TrackType aType); TrackInfo* GetTrackInfo(TrackInfo::TrackType); - void DoAttachSourceBuffer(TrackBuffersManager* aSourceBuffer); - void DoDetachSourceBuffer(TrackBuffersManager* aSourceBuffer); + void DoAttachSourceBuffer(RefPtr<TrackBuffersManager>&& aSourceBuffer); + void DoDetachSourceBuffer(const RefPtr<TrackBuffersManager>& aSourceBuffer); bool OnTaskQueue() { return !GetTaskQueue() || GetTaskQueue()->IsCurrentThreadIn(); diff --git a/dom/media/mediasource/SourceBuffer.cpp b/dom/media/mediasource/SourceBuffer.cpp index 26ea937077..0bdfbfcf23 100644 --- a/dom/media/mediasource/SourceBuffer.cpp +++ b/dom/media/mediasource/SourceBuffer.cpp @@ -281,7 +281,7 @@ SourceBuffer::Detach() if (mTrackBuffersManager) { mTrackBuffersManager->Detach(); mMediaSource->GetDecoder()->GetDemuxer()->DetachSourceBuffer( - mTrackBuffersManager.get()); + mTrackBuffersManager); } mTrackBuffersManager = nullptr; mMediaSource = nullptr; @@ -321,7 +321,7 @@ SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType) SetMode(SourceBufferAppendMode::Segments, dummy); } mMediaSource->GetDecoder()->GetDemuxer()->AttachSourceBuffer( - mTrackBuffersManager.get()); + mTrackBuffersManager); } SourceBuffer::~SourceBuffer() |