Bug 1299172 - HTMLMediaElement::StreamSizeListener spring cleaning. r=jesup

MozReview-Commit-ID: 25lt1j8t1Xh

--HG--
extra : rebase_source : e972d008c5e80059dd10031df38cf400cc6c9650
This commit is contained in:
Andreas Pehrson 2016-08-31 14:32:13 +02:00
Родитель 864bcdc3c4
Коммит a91bec92ad
1 изменённых файлов: 15 добавлений и 3 удалений

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

@ -279,7 +279,7 @@ public:
/** /**
* This listener observes the first video frame to arrive with a non-empty size, * This listener observes the first video frame to arrive with a non-empty size,
* and calls HTMLMediaElement::ReceivedMediaStreamInitialSize() with that size. * and calls HTMLMediaElement::UpdateInitialMediaSize() with that size.
*/ */
class HTMLMediaElement::StreamSizeListener : public DirectMediaStreamTrackListener { class HTMLMediaElement::StreamSizeListener : public DirectMediaStreamTrackListener {
public: public:
@ -287,13 +287,17 @@ public:
mElement(aElement), mElement(aElement),
mInitialSizeFound(false) mInitialSizeFound(false)
{} {}
void Forget() { mElement = nullptr; } void Forget() { mElement = nullptr; }
void ReceivedSize(gfx::IntSize aSize) void ReceivedSize(gfx::IntSize aSize)
{ {
MOZ_ASSERT(NS_IsMainThread());
if (!mElement) { if (!mElement) {
return; return;
} }
RefPtr<HTMLMediaElement> deathGrip = mElement; RefPtr<HTMLMediaElement> deathGrip = mElement;
mElement->UpdateInitialMediaSize(aSize); mElement->UpdateInitialMediaSize(aSize);
} }
@ -302,9 +306,15 @@ public:
StreamTime aTrackOffset, StreamTime aTrackOffset,
const MediaSegment& aMedia) override const MediaSegment& aMedia) override
{ {
if (mInitialSizeFound || aMedia.GetType() != MediaSegment::VIDEO) { if (mInitialSizeFound) {
return; return;
} }
if (aMedia.GetType() != MediaSegment::VIDEO) {
MOZ_ASSERT(false, "Should only lock on to a video track");
return;
}
const VideoSegment& video = static_cast<const VideoSegment&>(aMedia); const VideoSegment& video = static_cast<const VideoSegment&>(aMedia);
for (VideoSegment::ConstChunkIterator c(video); !c.IsEnded(); c.Next()) { for (VideoSegment::ConstChunkIterator c(video); !c.IsEnded(); c.Next()) {
if (c->mFrame.GetIntrinsicSize() != gfx::IntSize(0,0)) { if (c->mFrame.GetIntrinsicSize() != gfx::IntSize(0,0)) {
@ -326,7 +336,9 @@ private:
// These fields may only be accessed on the main thread // These fields may only be accessed on the main thread
HTMLMediaElement* mElement; HTMLMediaElement* mElement;
// These fields may only be accessed on the MSG thread // These fields may only be accessed on the MSG's appending thread.
// (this is a direct listener so we get called by whoever is producing
// this track's data)
bool mInitialSizeFound; bool mInitialSizeFound;
}; };