Bug 1240478 - Remove Mutex from MediaStreamSizeListener. r?jesup
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3051,63 +3051,57 @@ private:
/**
* This listener observes the first video frame to arrive with a non-empty size,
* and calls HTMLMediaElement::ReceivedMediaStreamInitialSize() with that size.
*/
class HTMLMediaElement::StreamSizeListener : public MediaStreamListener {
public:
explicit StreamSizeListener(HTMLMediaElement* aElement) :
mElement(aElement),
- mMutex("HTMLMediaElement::StreamSizeListener")
+ mInitialSizeFound(false)
{}
void Forget() { mElement = nullptr; }
- void ReceivedSize()
+ void ReceivedSize(gfx::IntSize aSize)
{
if (!mElement) {
return;
}
- gfx::IntSize size;
- {
- MutexAutoLock lock(mMutex);
- size = mInitialSize;
- }
RefPtr<HTMLMediaElement> deathGrip = mElement;
- mElement->UpdateInitialMediaSize(size);
- }
- virtual void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
- StreamTime aTrackOffset,
- uint32_t aTrackEvents,
- const MediaSegment& aQueuedMedia,
- MediaStream* aInputStream,
- TrackID aInputTrackID) override
+ mElement->UpdateInitialMediaSize(aSize);
+ }
+
+ void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
+ StreamTime aTrackOffset,
+ uint32_t aTrackEvents,
+ const MediaSegment& aQueuedMedia,
+ MediaStream* aInputStream,
+ TrackID aInputTrackID) override
{
- MutexAutoLock lock(mMutex);
- if (mInitialSize != gfx::IntSize(0,0) ||
- aQueuedMedia.GetType() != MediaSegment::VIDEO) {
+ if (mInitialSizeFound || aQueuedMedia.GetType() != MediaSegment::VIDEO) {
return;
}
const VideoSegment& video = static_cast<const VideoSegment&>(aQueuedMedia);
for (VideoSegment::ConstChunkIterator c(video); !c.IsEnded(); c.Next()) {
if (c->mFrame.GetIntrinsicSize() != gfx::IntSize(0,0)) {
- mInitialSize = c->mFrame.GetIntrinsicSize();
nsCOMPtr<nsIRunnable> event =
- NS_NewRunnableMethod(this, &StreamSizeListener::ReceivedSize);
+ NS_NewRunnableMethodWithArgs<gfx::IntSize>(
+ this, &StreamSizeListener::ReceivedSize,
+ c->mFrame.GetIntrinsicSize());
aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget());
}
}
}
private:
// These fields may only be accessed on the main thread
HTMLMediaElement* mElement;
- // mMutex protects the fields below; they can be accessed on any thread
- Mutex mMutex;
- gfx::IntSize mInitialSize;
+ // These fields may only be accessed on the MSG thread
+ bool mInitialSizeFound;
};
class HTMLMediaElement::MediaStreamTracksAvailableCallback:
public DOMMediaStream::OnTracksAvailableCallback
{
public:
explicit MediaStreamTracksAvailableCallback(HTMLMediaElement* aElement):
DOMMediaStream::OnTracksAvailableCallback(),