mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 804875 - Reset media element when loading a new src. r=kinetik
This commit is contained in:
parent
d9b9b3a737
commit
7712541f3b
@ -120,6 +120,7 @@ public:
|
||||
virtual void MetadataLoaded(int aChannels,
|
||||
int aRate,
|
||||
bool aHasAudio,
|
||||
bool aHasVideo,
|
||||
const MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
|
||||
|
||||
// Called by the video decoder object, on the main thread,
|
||||
@ -475,6 +476,12 @@ protected:
|
||||
*/
|
||||
void QueueSelectResourceTask();
|
||||
|
||||
/**
|
||||
* When loading a new source on an existing media element, make sure to reset
|
||||
* everything that is accessible using the media element API.
|
||||
*/
|
||||
void ResetState();
|
||||
|
||||
/**
|
||||
* The resource-fetch algorithm step of the load algorithm.
|
||||
*/
|
||||
|
@ -123,7 +123,7 @@ nsHTMLAudioElement::MozSetup(uint32_t aChannels, uint32_t aRate)
|
||||
return rv;
|
||||
}
|
||||
|
||||
MetadataLoaded(aChannels, aRate, true, nullptr);
|
||||
MetadataLoaded(aChannels, aRate, true, false, nullptr);
|
||||
mAudioStream->SetVolume(mVolume);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -733,10 +733,20 @@ NS_IMETHODIMP nsHTMLMediaElement::Load()
|
||||
AbortExistingLoads();
|
||||
SetPlaybackRate(mDefaultPlaybackRate);
|
||||
QueueSelectResourceTask();
|
||||
ResetState();
|
||||
mIsRunningLoadMethod = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsHTMLMediaElement::ResetState()
|
||||
{
|
||||
mMediaSize = nsIntSize(-1, -1);
|
||||
VideoFrameContainer* container = GetVideoFrameContainer();
|
||||
if (container) {
|
||||
container->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
static bool HasSourceChildren(nsIContent *aElement)
|
||||
{
|
||||
for (nsIContent* child = aElement->GetFirstChild();
|
||||
@ -2598,6 +2608,7 @@ void nsHTMLMediaElement::ProcessMediaFragmentURI()
|
||||
void nsHTMLMediaElement::MetadataLoaded(int aChannels,
|
||||
int aRate,
|
||||
bool aHasAudio,
|
||||
bool aHasVideo,
|
||||
const MetadataTags* aTags)
|
||||
{
|
||||
mChannels = aChannels;
|
||||
@ -2611,6 +2622,13 @@ void nsHTMLMediaElement::MetadataLoaded(int aChannels,
|
||||
ProcessMediaFragmentURI();
|
||||
mDecoder->SetFragmentEndTime(mFragmentEnd);
|
||||
}
|
||||
|
||||
// If this element had a video track, but consists only of an audio track now,
|
||||
// delete the VideoFrameContainer. This happens when the src is changed to an
|
||||
// audio only file.
|
||||
if (!aHasVideo) {
|
||||
mVideoFrameContainer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void nsHTMLMediaElement::FirstFrameLoaded(bool aResourceFullyLoaded)
|
||||
@ -2954,6 +2972,14 @@ void nsHTMLMediaElement::NotifyAutoplayDataReady()
|
||||
|
||||
VideoFrameContainer* nsHTMLMediaElement::GetVideoFrameContainer()
|
||||
{
|
||||
// If we have loaded the metadata, and the size of the video is still
|
||||
// (-1, -1), the media has no video. Don't go a create a video frame
|
||||
// container.
|
||||
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA &&
|
||||
mMediaSize == nsIntSize(-1, -1)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mVideoFrameContainer)
|
||||
return mVideoFrameContainer;
|
||||
|
||||
|
@ -85,8 +85,8 @@ public:
|
||||
// Return true if the transport layer supports seeking.
|
||||
virtual bool IsMediaSeekable() = 0;
|
||||
|
||||
virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags) = 0;
|
||||
virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags) = 0;
|
||||
virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0;
|
||||
virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0;
|
||||
|
||||
// Set the media end time in microseconds
|
||||
virtual void SetMediaEndTime(int64_t aTime) = 0;
|
||||
@ -123,23 +123,25 @@ class AudioMetadataEventRunner : public nsRunnable
|
||||
private:
|
||||
nsRefPtr<AbstractMediaDecoder> mDecoder;
|
||||
public:
|
||||
AudioMetadataEventRunner(AbstractMediaDecoder* aDecoder, int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags)
|
||||
AudioMetadataEventRunner(AbstractMediaDecoder* aDecoder, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
|
||||
: mDecoder(aDecoder),
|
||||
mChannels(aChannels),
|
||||
mRate(aRate),
|
||||
mHasAudio(aHasAudio),
|
||||
mHasVideo(aHasVideo),
|
||||
mTags(aTags)
|
||||
{}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
mDecoder->MetadataLoaded(mChannels, mRate, mHasAudio, mTags);
|
||||
mDecoder->MetadataLoaded(mChannels, mRate, mHasAudio, mHasVideo, mTags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int mChannels;
|
||||
int mRate;
|
||||
bool mHasAudio;
|
||||
bool mHasVideo;
|
||||
MetadataTags* mTags;
|
||||
};
|
||||
|
||||
|
@ -656,7 +656,7 @@ void MediaDecoder::QueueMetadata(int64_t aPublishTime,
|
||||
{
|
||||
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
|
||||
GetReentrantMonitor().AssertCurrentThreadIn();
|
||||
mDecoderStateMachine->QueueMetadata(aPublishTime, aChannels, aRate, aHasAudio, aTags);
|
||||
mDecoderStateMachine->QueueMetadata(aPublishTime, aChannels, aRate, aHasAudio, aHasVideo, aTags);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -669,7 +669,7 @@ MediaDecoder::IsDataCachedToEndOfResource()
|
||||
mResource->IsDataCachedToEndOfResource(mDecoderPosition));
|
||||
}
|
||||
|
||||
void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags)
|
||||
void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (mShuttingDown) {
|
||||
@ -691,7 +691,7 @@ void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, Meta
|
||||
// Make sure the element and the frame (if any) are told about
|
||||
// our new size.
|
||||
Invalidate();
|
||||
mOwner->MetadataLoaded(aChannels, aRate, aHasAudio, aTags);
|
||||
mOwner->MetadataLoaded(aChannels, aRate, aHasAudio, aHasVideo, aTags);
|
||||
}
|
||||
|
||||
if (!mCalledResourceLoaded) {
|
||||
|
@ -654,6 +654,7 @@ public:
|
||||
int aChannels,
|
||||
int aRate,
|
||||
bool aHasAudio,
|
||||
bool aHasVideo,
|
||||
MetadataTags* aTags);
|
||||
|
||||
/******
|
||||
@ -672,7 +673,7 @@ public:
|
||||
|
||||
// Called when the metadata from the media file has been loaded by the
|
||||
// state machine. Call on the main thread only.
|
||||
void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags);
|
||||
void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags);
|
||||
|
||||
// Called when the first frame has been loaded.
|
||||
// Call on the main thread only.
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
virtual void MetadataLoaded(int aChannels,
|
||||
int aRate,
|
||||
bool aHasAudio,
|
||||
bool aHasVideo,
|
||||
const MetadataTags* aTags) = 0;
|
||||
|
||||
// Called by the video decoder object, on the main thread,
|
||||
|
@ -1855,6 +1855,7 @@ nsresult MediaDecoderStateMachine::DecodeMetadata()
|
||||
mInfo.mAudioChannels,
|
||||
mInfo.mAudioRate,
|
||||
HasAudio(),
|
||||
HasVideo(),
|
||||
tags);
|
||||
NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL);
|
||||
|
||||
@ -2780,7 +2781,12 @@ bool MediaDecoderStateMachine::IsShutdown()
|
||||
return GetState() == DECODER_STATE_SHUTDOWN;
|
||||
}
|
||||
|
||||
void MediaDecoderStateMachine::QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags)
|
||||
void MediaDecoderStateMachine::QueueMetadata(int64_t aPublishTime,
|
||||
int aChannels,
|
||||
int aRate,
|
||||
bool aHasAudio,
|
||||
bool aHasVideo,
|
||||
MetadataTags* aTags)
|
||||
{
|
||||
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
|
||||
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
||||
|
@ -319,7 +319,7 @@ public:
|
||||
// shutting down. The decoder monitor must be held while calling this.
|
||||
bool IsShutdown();
|
||||
|
||||
void QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, MetadataTags* aTags);
|
||||
void QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags);
|
||||
|
||||
protected:
|
||||
virtual uint32_t GetAmpleVideoFrames() { return mAmpleVideoFrames; }
|
||||
|
@ -28,6 +28,8 @@ namespace mozilla {
|
||||
int mChannels;
|
||||
// True if this media has an audio track.
|
||||
bool mHasAudio;
|
||||
// True if this media has a video track.
|
||||
bool mHasVideo;
|
||||
};
|
||||
|
||||
// This class encapsulate the logic to give the metadata from the reader to
|
||||
@ -53,6 +55,7 @@ namespace mozilla {
|
||||
metadata->mChannels,
|
||||
metadata->mRate,
|
||||
metadata->mHasAudio,
|
||||
metadata->mHasVideo,
|
||||
metadata->mTags.forget());
|
||||
NS_DispatchToMainThread(metadataUpdatedEvent, NS_DISPATCH_NORMAL);
|
||||
mMetadataQueue.popFirst();
|
||||
|
@ -67,7 +67,15 @@ void VideoFrameContainer::SetCurrentFrame(const gfxIntSize& aIntrinsicSize,
|
||||
mPaintTarget = aTargetTime;
|
||||
}
|
||||
|
||||
void VideoFrameContainer::ClearCurrentFrame()
|
||||
void VideoFrameContainer::Reset()
|
||||
{
|
||||
ClearCurrentFrame(true);
|
||||
Invalidate();
|
||||
mPaintDelay = TimeDuration();
|
||||
mImageContainer->ResetPaintCount();
|
||||
}
|
||||
|
||||
void VideoFrameContainer::ClearCurrentFrame(bool aResetSize)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
|
||||
@ -78,6 +86,7 @@ void VideoFrameContainer::ClearCurrentFrame()
|
||||
mImageContainer->UnlockCurrentImage();
|
||||
|
||||
mImageContainer->SetCurrentImage(nullptr);
|
||||
mImageSizeChanged = aResetSize;
|
||||
|
||||
// We removed the current image so we will have to invalidate once
|
||||
// again to setup the ImageContainer <-> Compositor pair.
|
||||
|
@ -46,7 +46,9 @@ public:
|
||||
// Call on any thread
|
||||
void SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage,
|
||||
TimeStamp aTargetTime);
|
||||
void ClearCurrentFrame();
|
||||
void ClearCurrentFrame(bool aResetSize = false);
|
||||
// Reset the VideoFrameContainer
|
||||
void Reset();
|
||||
// Time in seconds by which the last painted video frame was late by.
|
||||
// E.g. if the last painted frame should have been painted at time t,
|
||||
// but was actually painted at t+n, this returns n in seconds. Threadsafe.
|
||||
|
@ -732,6 +732,7 @@ bool OggReader::ReadOggChain()
|
||||
channels,
|
||||
rate,
|
||||
HasAudio(),
|
||||
HasVideo(),
|
||||
tags);
|
||||
}
|
||||
return true;
|
||||
|
@ -443,6 +443,15 @@ public:
|
||||
return mPaintCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the paint count to zero.
|
||||
* Can be called from any thread.
|
||||
*/
|
||||
void ResetPaintCount() {
|
||||
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
||||
mPaintCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments mPaintCount if this is the first time aPainted has been
|
||||
* painted, and sets mPaintTime if the painted image is the current image.
|
||||
|
Loading…
Reference in New Issue
Block a user