Bug 462957 - Pin media stream while seeking. r=roc a=blocking2.0

This commit is contained in:
Chris Pearce 2010-08-05 19:40:35 +12:00
parent 6c349be715
commit 3a5db791b8
4 changed files with 43 additions and 4 deletions

View File

@ -178,6 +178,7 @@ void nsBuiltinDecoder::Shutdown()
nsBuiltinDecoder::~nsBuiltinDecoder()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
UnpinForSeek();
MOZ_COUNT_DTOR(nsBuiltinDecoder);
}
@ -262,6 +263,7 @@ nsresult nsBuiltinDecoder::Seek(float aTime)
else {
mNextState = mPlayState;
}
PinForSeek();
ChangeState(PLAY_STATE_SEEKING);
}
@ -608,10 +610,12 @@ void nsBuiltinDecoder::SeekingStopped()
// An additional seek was requested while the current seek was
// in operation.
if (mRequestedSeekTime >= 0.0)
if (mRequestedSeekTime >= 0.0) {
ChangeState(PLAY_STATE_SEEKING);
else
} else {
UnpinForSeek();
ChangeState(mNextState);
}
}
if (mElement) {
@ -637,8 +641,8 @@ void nsBuiltinDecoder::SeekingStoppedAtEnd()
// in operation.
if (mRequestedSeekTime >= 0.0) {
ChangeState(PLAY_STATE_SEEKING);
}
else {
} else {
UnpinForSeek();
fireEnded = mNextState != PLAY_STATE_PLAYING;
ChangeState(fireEnded ? PLAY_STATE_ENDED : mNextState);
}

View File

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsMediaDecoder.h"
#include "nsMediaStream.h"
#include "prlog.h"
#include "prmem.h"
@ -72,6 +73,7 @@ nsMediaDecoder::nsMediaDecoder() :
mDataTime(),
mVideoUpdateLock(nsnull),
mPixelAspectRatio(1.0),
mPinnedForSeek(PR_FALSE),
mSizeChanged(PR_FALSE),
mShuttingDown(PR_FALSE)
{
@ -232,6 +234,26 @@ void nsMediaDecoder::SetVideoData(const gfxIntSize& aSize,
}
}
void nsMediaDecoder::PinForSeek()
{
nsMediaStream* stream = GetCurrentStream();
if (!stream || mPinnedForSeek) {
return;
}
mPinnedForSeek = PR_TRUE;
stream->Pin();
}
void nsMediaDecoder::UnpinForSeek()
{
nsMediaStream* stream = GetCurrentStream();
if (!stream || !mPinnedForSeek) {
return;
}
mPinnedForSeek = PR_FALSE;
stream->Unpin();
}
// Number of bytes to add to the download size when we're computing
// when the download will finish --- a safety margin in case bandwidth
// or other conditions are worse than expected

View File

@ -253,6 +253,12 @@ protected:
// Stop progress information timer.
nsresult StopProgress();
// Ensures our media stream has been pinned.
void PinForSeek();
// Ensures our media stream has been unpinned.
void UnpinForSeek();
protected:
// Timer used for updating progress events
nsCOMPtr<nsITimer> mProgressTimer;
@ -292,6 +298,10 @@ protected:
// Pixel aspect ratio (ratio of the pixel width to pixel height)
float mPixelAspectRatio;
// PR_TRUE when our media stream has been pinned. We pin the stream
// while seeking.
PRPackedBool mPinnedForSeek;
// Has our size changed since the last repaint?
PRPackedBool mSizeChanged;

View File

@ -1218,6 +1218,7 @@ nsWaveDecoder::nsWaveDecoder()
nsWaveDecoder::~nsWaveDecoder()
{
MOZ_COUNT_DTOR(nsWaveDecoder);
UnpinForSeek();
}
PRBool
@ -1260,6 +1261,7 @@ nsresult
nsWaveDecoder::Seek(float aTime)
{
if (mPlaybackStateMachine) {
PinForSeek();
mPlaybackStateMachine->Seek(aTime);
return NS_OK;
}
@ -1587,6 +1589,7 @@ nsWaveDecoder::SeekingStarted()
void
nsWaveDecoder::SeekingStopped()
{
UnpinForSeek();
if (mShuttingDown) {
return;
}