mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 464376. Fire progress events more consistently, especially being sure to fire a progress event at the end of a load. r+sr=roc
This commit is contained in:
parent
9d520538f7
commit
9e493d5b6d
@ -1064,8 +1064,10 @@ nsresult nsHTMLMediaElement::DispatchProgressEvent(const nsAString& aName)
|
||||
|
||||
nsCOMPtr<nsIDOMProgressEvent> progressEvent(do_QueryInterface(event));
|
||||
NS_ENSURE_TRUE(progressEvent, NS_ERROR_FAILURE);
|
||||
|
||||
rv = progressEvent->InitProgressEvent(aName, PR_TRUE, PR_TRUE, PR_FALSE, mDecoder->GetBytesLoaded(), mDecoder->GetTotalBytes());
|
||||
|
||||
PRInt64 length = mDecoder->GetTotalBytes();
|
||||
rv = progressEvent->InitProgressEvent(aName, PR_TRUE, PR_TRUE,
|
||||
length >= 0, mDecoder->GetBytesLoaded(), length);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool dummy;
|
||||
|
@ -68,8 +68,11 @@ class nsChannelToPipeListener : public nsIStreamListener
|
||||
|
||||
public:
|
||||
// If aSeeking is PR_TRUE then this listener was created as part of a
|
||||
// seek request and is expecting a byte range partial result.
|
||||
nsChannelToPipeListener(nsMediaDecoder* aDecoder, PRBool aSeeking = PR_FALSE);
|
||||
// seek request and is expecting a byte range partial result. aOffset
|
||||
// is the offset in bytes that this listener started reading from.
|
||||
nsChannelToPipeListener(nsMediaDecoder* aDecoder,
|
||||
PRBool aSeeking = PR_FALSE,
|
||||
PRInt64 aOffset = 0);
|
||||
nsresult Init();
|
||||
nsresult GetInputStream(nsIInputStream** aStream);
|
||||
void Stop();
|
||||
@ -95,7 +98,12 @@ private:
|
||||
// bytes per second download rate.
|
||||
PRIntervalTime mIntervalEnd;
|
||||
|
||||
// Total bytes transferred so far
|
||||
// Offset from the beginning of the resource where the listener
|
||||
// started reading. This is used for computing the current file
|
||||
// position for progress events.
|
||||
PRInt64 mOffset;
|
||||
|
||||
// Total bytes transferred so far. Used for computing download rates.
|
||||
PRInt64 mTotalBytes;
|
||||
|
||||
// PR_TRUE if this listener is expecting a byte range request result
|
||||
|
@ -164,8 +164,11 @@ class nsMediaDecoder : public nsIObserver
|
||||
// Invalidate the frame.
|
||||
virtual void Invalidate();
|
||||
|
||||
// Update progress information.
|
||||
virtual void Progress();
|
||||
// Fire progress events if needed according to the time and byte
|
||||
// constraints outlined in the specification. aTimer is PR_TRUE
|
||||
// if the method is called as a result of the progress timer rather
|
||||
// than the result of downloaded data.
|
||||
virtual void Progress(PRBool aTimer);
|
||||
|
||||
// Keep track of the number of bytes downloaded
|
||||
virtual void UpdateBytesDownloaded(PRUint64 aBytes) = 0;
|
||||
@ -210,6 +213,16 @@ protected:
|
||||
PRInt32 mRGBWidth;
|
||||
PRInt32 mRGBHeight;
|
||||
|
||||
// Time that the last progress event was fired. Read/Write from the
|
||||
// main thread only.
|
||||
PRIntervalTime mProgressTime;
|
||||
|
||||
// Time that data was last read from the media resource. Used for
|
||||
// computing if the download has stalled. A value of 0 indicates that
|
||||
// a stall event has already fired and not to fire another one until
|
||||
// more data is received. Read/Write from the main thread only.
|
||||
PRIntervalTime mDataTime;
|
||||
|
||||
// Has our size changed since the last repaint?
|
||||
PRPackedBool mSizeChanged;
|
||||
|
||||
@ -239,6 +252,12 @@ protected:
|
||||
// waiting for the playback event loop to shutdown. Read/Write from the
|
||||
// main thread only.
|
||||
PRPackedBool mStopping;
|
||||
|
||||
// True when seeking or otherwise moving the play position around in
|
||||
// such a manner that progress event data is inaccurate. This is set
|
||||
// before a seek or during loading of metadata to prevent the progress indicator
|
||||
// from jumping around. Accessed on the main thread only.
|
||||
PRPackedBool mIgnoreProgressData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -512,6 +512,10 @@ private:
|
||||
// when writing to the state, or when reading from a non-main thread.
|
||||
// Any change to the state must call NotifyAll on the monitor.
|
||||
PlayState mNextState;
|
||||
|
||||
// True when the media resource has completely loaded. Accessed on
|
||||
// the main thread only.
|
||||
PRPackedBool mResourceLoaded;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -47,10 +47,12 @@
|
||||
|
||||
nsChannelToPipeListener::nsChannelToPipeListener(
|
||||
nsMediaDecoder* aDecoder,
|
||||
PRBool aSeeking) :
|
||||
PRBool aSeeking,
|
||||
PRInt64 aOffset) :
|
||||
mDecoder(aDecoder),
|
||||
mIntervalStart(0),
|
||||
mIntervalEnd(0),
|
||||
mOffset(aOffset),
|
||||
mTotalBytes(0),
|
||||
mSeeking(aSeeking)
|
||||
{
|
||||
@ -99,7 +101,7 @@ nsresult nsChannelToPipeListener::OnStartRequest(nsIRequest* aRequest, nsISuppor
|
||||
mIntervalStart = PR_IntervalNow();
|
||||
mIntervalEnd = mIntervalStart;
|
||||
mTotalBytes = 0;
|
||||
mDecoder->UpdateBytesDownloaded(mTotalBytes);
|
||||
mDecoder->UpdateBytesDownloaded(mOffset);
|
||||
nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(aRequest);
|
||||
if (hc) {
|
||||
PRUint32 responseStatus = 0;
|
||||
@ -150,6 +152,10 @@ nsresult nsChannelToPipeListener::OnStartRequest(nsIRequest* aRequest, nsISuppor
|
||||
}
|
||||
}
|
||||
|
||||
// Fires an initial progress event and sets up the stall counter so stall events
|
||||
// fire if no download occurs within the required time frame.
|
||||
mDecoder->Progress(PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -183,11 +189,16 @@ nsresult nsChannelToPipeListener::OnDataAvailable(nsIRequest* aRequest,
|
||||
|
||||
aCount -= bytes;
|
||||
mTotalBytes += bytes;
|
||||
mDecoder->UpdateBytesDownloaded(mTotalBytes);
|
||||
mDecoder->UpdateBytesDownloaded(mOffset + aOffset + bytes);
|
||||
} while (aCount) ;
|
||||
|
||||
nsresult rv = mOutput->Flush();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Fire a progress events according to the time and byte constraints outlined
|
||||
// in the spec.
|
||||
mDecoder->Progress(PR_FALSE);
|
||||
|
||||
mIntervalEnd = PR_IntervalNow();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -52,6 +52,12 @@
|
||||
#include "nsPresContext.h"
|
||||
#include "nsMediaDecoder.h"
|
||||
|
||||
// Number of milliseconds between progress events as defined by spec
|
||||
#define PROGRESS_MS 350
|
||||
|
||||
// Number of milliseconds of no data before a stall event is fired as defined by spec
|
||||
#define STALL_MS 3000
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
// Logging object for decoder
|
||||
PRLogModuleInfo* gVideoDecoderLog = nsnull;
|
||||
@ -61,11 +67,14 @@ nsMediaDecoder::nsMediaDecoder() :
|
||||
mElement(0),
|
||||
mRGBWidth(-1),
|
||||
mRGBHeight(-1),
|
||||
mProgressTime(0),
|
||||
mDataTime(0),
|
||||
mSizeChanged(PR_FALSE),
|
||||
mVideoUpdateLock(nsnull),
|
||||
mFramerate(0.0),
|
||||
mShuttingDown(PR_FALSE),
|
||||
mStopping(PR_FALSE)
|
||||
mStopping(PR_FALSE),
|
||||
mIgnoreProgressData(PR_TRUE)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsMediaDecoder);
|
||||
}
|
||||
@ -129,38 +138,55 @@ void nsMediaDecoder::Invalidate()
|
||||
static void ProgressCallback(nsITimer* aTimer, void* aClosure)
|
||||
{
|
||||
nsMediaDecoder* decoder = static_cast<nsMediaDecoder*>(aClosure);
|
||||
decoder->Progress();
|
||||
decoder->Progress(PR_TRUE);
|
||||
}
|
||||
|
||||
void nsMediaDecoder::Progress()
|
||||
void nsMediaDecoder::Progress(PRBool aTimer)
|
||||
{
|
||||
if (!mElement)
|
||||
if (!mElement || mIgnoreProgressData)
|
||||
return;
|
||||
|
||||
mElement->DispatchProgressEvent(NS_LITERAL_STRING("progress"));
|
||||
PRIntervalTime now = PR_IntervalNow();
|
||||
if (mProgressTime == 0 ||
|
||||
PR_IntervalToMilliseconds(PR_IntervalNow() - mProgressTime) >= PROGRESS_MS) {
|
||||
mElement->DispatchProgressEvent(NS_LITERAL_STRING("progress"));
|
||||
mProgressTime = now;
|
||||
}
|
||||
|
||||
// The test for aTimer is to ensure that we dispatch 'stalled'
|
||||
// only when we are not receiving data.
|
||||
if (aTimer &&
|
||||
mDataTime != 0 &&
|
||||
PR_IntervalToMilliseconds(now - mDataTime) >= STALL_MS) {
|
||||
mElement->DispatchProgressEvent(NS_LITERAL_STRING("stalled"));
|
||||
mDataTime = 0;
|
||||
}
|
||||
|
||||
if (!aTimer) {
|
||||
mDataTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsMediaDecoder::StartProgress()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mProgressTimer)
|
||||
return NS_OK;
|
||||
|
||||
if (!mProgressTimer) {
|
||||
mProgressTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
rv = mProgressTimer->InitWithFuncCallback(ProgressCallback,
|
||||
mProgressTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
return mProgressTimer->InitWithFuncCallback(ProgressCallback,
|
||||
this,
|
||||
350, // Number of milliseconds defined in spec
|
||||
PROGRESS_MS,
|
||||
nsITimer::TYPE_REPEATING_PRECISE);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMediaDecoder::StopProgress()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mProgressTimer) {
|
||||
rv = mProgressTimer->Cancel();
|
||||
mProgressTimer = nsnull;
|
||||
}
|
||||
if (!mProgressTimer)
|
||||
return NS_OK;
|
||||
|
||||
nsresult rv = mProgressTimer->Cancel();
|
||||
mProgressTimer = nsnull;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -270,6 +270,7 @@ nsresult nsFileStreamStrategy::Open(nsIStreamListener** aStreamListener)
|
||||
rv = mInput->Available(&size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mDecoder->SetTotalBytes(size);
|
||||
mDecoder->UpdateBytesDownloaded(size);
|
||||
}
|
||||
|
||||
/* Get our principal */
|
||||
@ -546,7 +547,7 @@ public:
|
||||
hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString, PR_FALSE);
|
||||
}
|
||||
|
||||
mListener = new nsChannelToPipeListener(mDecoder, PR_TRUE);
|
||||
mListener = new nsChannelToPipeListener(mDecoder, PR_TRUE, mOffset);
|
||||
NS_ENSURE_TRUE(mListener, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
mResult = mListener->Init();
|
||||
|
@ -1198,7 +1198,8 @@ nsOggDecoder::nsOggDecoder() :
|
||||
mReader(0),
|
||||
mMonitor(0),
|
||||
mPlayState(PLAY_STATE_PAUSED),
|
||||
mNextState(PLAY_STATE_PAUSED)
|
||||
mNextState(PLAY_STATE_PAUSED),
|
||||
mResourceLoaded(PR_FALSE)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsOggDecoder);
|
||||
}
|
||||
@ -1232,6 +1233,11 @@ nsresult nsOggDecoder::Load(nsIURI* aURI, nsIChannel* aChannel,
|
||||
// reusing decoder.
|
||||
mStopping = PR_FALSE;
|
||||
|
||||
// Reset progress member variables
|
||||
mIgnoreProgressData = PR_TRUE;
|
||||
mBytesDownloaded = 0;
|
||||
mResourceLoaded = PR_FALSE;
|
||||
|
||||
NS_ASSERTION(!mReader, "Didn't shutdown properly!");
|
||||
NS_ASSERTION(!mDecodeStateMachine, "Didn't shutdown properly!");
|
||||
NS_ASSERTION(!mDecodeThread, "Didn't shutdown properly!");
|
||||
@ -1254,8 +1260,6 @@ nsresult nsOggDecoder::Load(nsIURI* aURI, nsIChannel* aChannel,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
StartProgress();
|
||||
|
||||
RegisterShutdownObserver();
|
||||
|
||||
mReader = new nsChannelReader();
|
||||
@ -1365,6 +1369,7 @@ void nsOggDecoder::Stop()
|
||||
|
||||
ChangeState(PLAY_STATE_ENDED);
|
||||
|
||||
mIgnoreProgressData = PR_TRUE;
|
||||
StopProgress();
|
||||
|
||||
// Force any outstanding seek and byterange requests to complete
|
||||
@ -1441,6 +1446,11 @@ void nsOggDecoder::MetadataLoaded()
|
||||
if (mElement && notifyElement) {
|
||||
mElement->MetadataLoaded();
|
||||
}
|
||||
|
||||
if (!mResourceLoaded) {
|
||||
StartProgress();
|
||||
}
|
||||
mIgnoreProgressData = PR_FALSE;
|
||||
}
|
||||
|
||||
void nsOggDecoder::FirstFrameLoaded()
|
||||
@ -1477,13 +1487,39 @@ void nsOggDecoder::FirstFrameLoaded()
|
||||
|
||||
void nsOggDecoder::ResourceLoaded()
|
||||
{
|
||||
if (mShuttingDown)
|
||||
// Don't handle ResourceLoaded if we are shutting down, or if
|
||||
// we need to ignore progress data due to seeking (in the case
|
||||
// that the seek results in reaching end of file, we get a bogus call
|
||||
// to ResourceLoaded).
|
||||
if (mShuttingDown || mIgnoreProgressData)
|
||||
return;
|
||||
|
||||
Progress(PR_FALSE);
|
||||
{
|
||||
// If we are seeking or loading then the resource loaded notification we get
|
||||
// should be ignored, since it represents the end of the seek request.
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
if (mPlayState == PLAY_STATE_SEEKING || mPlayState == PLAY_STATE_LOADING)
|
||||
return;
|
||||
}
|
||||
|
||||
// If we know the content length, set the bytes downloaded to this
|
||||
// so the final progress event gets the correct final value.
|
||||
if (mContentLength >= 0) {
|
||||
mBytesDownloaded = mContentLength;
|
||||
}
|
||||
|
||||
mResourceLoaded = PR_TRUE;
|
||||
StopProgress();
|
||||
|
||||
// Ensure the final progress event gets fired
|
||||
if (mElement && !mIgnoreProgressData) {
|
||||
mElement->DispatchProgressEvent(NS_LITERAL_STRING("progress"));
|
||||
}
|
||||
|
||||
if (mElement) {
|
||||
mElement->ResourceLoaded();
|
||||
}
|
||||
StopProgress();
|
||||
}
|
||||
|
||||
void nsOggDecoder::NetworkError()
|
||||
@ -1549,7 +1585,11 @@ void nsOggDecoder::SetTotalBytes(PRInt64 aBytes)
|
||||
|
||||
void nsOggDecoder::UpdateBytesDownloaded(PRUint64 aBytes)
|
||||
{
|
||||
mBytesDownloaded = aBytes;
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
if (!mIgnoreProgressData) {
|
||||
mBytesDownloaded = aBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void nsOggDecoder::BufferingStopped()
|
||||
@ -1577,6 +1617,8 @@ void nsOggDecoder::SeekingStopped()
|
||||
if (mShuttingDown)
|
||||
return;
|
||||
|
||||
mIgnoreProgressData = PR_FALSE;
|
||||
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@ -1598,6 +1640,8 @@ void nsOggDecoder::SeekingStarted()
|
||||
if (mShuttingDown)
|
||||
return;
|
||||
|
||||
mIgnoreProgressData = PR_TRUE;
|
||||
|
||||
if (mElement) {
|
||||
mElement->SeekStarted();
|
||||
}
|
||||
@ -1731,4 +1775,3 @@ PRBool nsOggDecoder::GetSeekable()
|
||||
{
|
||||
return mSeekable;
|
||||
}
|
||||
|
||||
|
@ -1205,6 +1205,11 @@ nsWaveDecoder::ResourceLoaded()
|
||||
mPlaybackStateMachine->StreamEnded();
|
||||
}
|
||||
StopProgress();
|
||||
|
||||
// Ensure the final progress event gets fired
|
||||
if (mElement) {
|
||||
mElement->DispatchProgressEvent(NS_LITERAL_STRING("progress"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -67,6 +67,7 @@ _TEST_FILES += \
|
||||
test_ended1.html \
|
||||
test_ended2.html \
|
||||
test_onloadedmetadata.html \
|
||||
test_progress1.html \
|
||||
test_seek1.html \
|
||||
test_seek3.html \
|
||||
test_seek4.html \
|
||||
@ -90,10 +91,12 @@ endif
|
||||
|
||||
ifdef MOZ_WAVE
|
||||
_TEST_FILES += \
|
||||
big.wav \
|
||||
test_bug463162.xhtml \
|
||||
test_can_play_type_wave.html \
|
||||
test_wav_8bit.html \
|
||||
test_wav_ended1.html \
|
||||
test_progress2.html \
|
||||
test_wav_seek3.html \
|
||||
test_wav_seek4.html \
|
||||
test_wav_seek5.html \
|
||||
|
BIN
content/media/video/test/big.wav
Normal file
BIN
content/media/video/test/big.wav
Normal file
Binary file not shown.
36
content/media/video/test/test_progress1.html
Normal file
36
content/media/video/test/test_progress1.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Media test: progress events</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
var v = document.getElementById('v');
|
||||
var completed = false;
|
||||
|
||||
function do_progress(e) {
|
||||
if (completed)
|
||||
return false;
|
||||
|
||||
ok(e.lengthComputable, "Check progress lengthComputable");
|
||||
ok(e.loaded >= 0 && e.loaded <= e.total, "Check progress loaded: " + e.loaded);
|
||||
ok(e.total == 285310, "Check progress total: " + e.total);
|
||||
if (e.loaded == 285310) {
|
||||
completed = true;
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
</script>
|
||||
</pre>
|
||||
<<video id='v'
|
||||
src='seek.ogg'
|
||||
onprogress='do_progress(event)'>
|
||||
</video>
|
||||
</body>
|
||||
</html>
|
36
content/media/video/test/test_progress2.html
Normal file
36
content/media/video/test/test_progress2.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Media test: progress events</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
// Test progress events with wav backend
|
||||
var v = document.getElementById('v');
|
||||
var completed = false;
|
||||
|
||||
function do_progress(e) {
|
||||
if (completed)
|
||||
return false;
|
||||
|
||||
ok(e.lengthComputable, "Check progress lengthComputable");
|
||||
ok(e.loaded >= 0 && e.loaded <= e.total, "Check progress loaded: " + e.loaded);
|
||||
ok(e.total == 102444, "Check progress total: " + e.total);
|
||||
if (e.loaded == 102444) {
|
||||
completed = true;
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
</script>
|
||||
</pre>
|
||||
<video id='v' controls onprogress='do_progress(event)'>
|
||||
<source src='big.wav' type="audio/wav"></source>
|
||||
</video>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user