b=477899 Calls to liboggplay to get the duration of a media resource should be cached r+sr=roc

This commit is contained in:
Chris Double 2009-02-20 15:37:06 +13:00
Родитель 7cd5fc5f1f
Коммит fe03af3974
4 изменённых файлов: 34 добавлений и 4 удалений

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

@ -73,6 +73,11 @@ public:
// Resume any downloads that have been suspended.
void Resume();
// Set the duration of the media resource. Call with decoder lock
// obtained so that the decoder thread does not request the duration
// while it is changing.
void SetDuration(PRInt64 aDuration);
nsIPrincipal* GetCurrentPrincipal();
// Implementation of OggPlay Reader API.
@ -81,9 +86,13 @@ public:
size_t io_read(char* aBuffer, size_t aCount);
int io_seek(long aOffset, int aWhence);
long io_tell();
ogg_int64_t duration();
public:
nsMediaStream mStream;
// Duration of the media resource. -1 if not known.
PRInt64 mDuration;
};
#endif

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

@ -69,6 +69,11 @@ void nsChannelReader::Resume()
mStream.Resume();
}
void nsChannelReader::SetDuration(PRInt64 aDuration)
{
mDuration = aDuration;
}
size_t nsChannelReader::io_read(char* aBuffer, size_t aCount)
{
PRUint32 bytes = 0;
@ -93,6 +98,11 @@ long nsChannelReader::io_tell()
return mStream.Tell();
}
ogg_int64_t nsChannelReader::duration()
{
return mDuration;
}
static OggPlayErrorCode oggplay_channel_reader_initialise(OggPlayReader* aReader, int aBlock)
{
nsChannelReader * me = static_cast<nsChannelReader*>(aReader);
@ -127,6 +137,12 @@ static long oggplay_channel_reader_io_tell(void* aReader)
return me->io_tell();
}
static ogg_int64_t oggplay_channel_reader_duration(struct _OggPlayReader *aReader)
{
nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
return me->duration();
}
nsresult nsChannelReader::Init(nsMediaDecoder* aDecoder, nsIURI* aURI,
nsIChannel* aChannel,
nsIStreamListener** aStreamListener)
@ -139,7 +155,8 @@ nsChannelReader::~nsChannelReader()
MOZ_COUNT_DTOR(nsChannelReader);
}
nsChannelReader::nsChannelReader()
nsChannelReader::nsChannelReader() :
mDuration(-1)
{
MOZ_COUNT_CTOR(nsChannelReader);
OggPlayReader* reader = this;
@ -149,7 +166,7 @@ nsChannelReader::nsChannelReader()
reader->io_read = &oggplay_channel_reader_io_read;
reader->io_seek = &oggplay_channel_reader_io_seek;
reader->io_tell = &oggplay_channel_reader_io_tell;
reader->duration = nsnull;
reader->duration = &oggplay_channel_reader_duration;
}
nsIPrincipal*

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

@ -653,7 +653,6 @@ private:
nsresult nsHttpStreamStrategy::Seek(PRInt32 aWhence, PRInt64 aOffset)
{
PRInt64 totalBytes = mDecoder->GetStatistics().mTotalBytes;
{
nsAutoLock lock(mLock);
if (!mChannel || !mPipeInput)
@ -719,7 +718,6 @@ nsresult nsHttpStreamStrategy::Seek(PRInt32 aWhence, PRInt64 aOffset)
nsAutoArrayPtr<char> data(new char[bytesAhead]);
if (!data)
return NS_ERROR_OUT_OF_MEMORY;
// Read until the read cursor reaches new seek point. If Cancel() is
// called then the read will fail with an error so we can bail out of
// the blocking call.

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

@ -675,6 +675,7 @@ void nsOggDecodeStateMachine::PlayFrame() {
// Reset the play start time.
mPlayStartTime = PR_IntervalNow();
mPauseDuration = 0;
frame->mState = OGGPLAY_STREAM_INITIALISED;
}
double time = (PR_IntervalToMilliseconds(PR_IntervalNow()-mPlayStartTime-mPauseDuration)/1000.0);
@ -1235,6 +1236,7 @@ void nsOggDecodeStateMachine::LoadOggHeaders()
// and blocks until these are completed.
mon.Exit();
PRInt64 d = oggplay_get_duration(mPlayer);
oggplay_seek(mPlayer, 0);
mon.Enter();
mDuration = d;
mDecoder->StartProgressUpdates();
@ -1958,6 +1960,10 @@ void nsOggDecoder::SetDuration(PRInt64 aDuration)
if (mDecodeStateMachine) {
nsAutoMonitor mon(mMonitor);
mDecodeStateMachine->SetDuration(mDuration);
if (mReader) {
mReader->SetDuration(mDuration);
}
}
}