2008-07-30 06:50:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2010-03-15 01:44:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2008-07-30 06:50:14 +00:00
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Chris Double <chris.double@double.co.nz>
|
2010-04-02 03:03:07 +00:00
|
|
|
* Chris Pearce <chris@pearce.org.nz>
|
2008-07-30 06:50:14 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2009-09-29 21:32:44 +00:00
|
|
|
|
2008-11-10 01:38:02 +00:00
|
|
|
#include <limits>
|
2008-07-30 06:50:14 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsAudioStream.h"
|
|
|
|
#include "nsHTMLVideoElement.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
2008-10-19 07:39:21 +00:00
|
|
|
#include "nsTArray.h"
|
2010-04-27 08:53:44 +00:00
|
|
|
#include "VideoUtils.h"
|
|
|
|
#include "nsBuiltinDecoder.h"
|
2011-07-12 03:39:34 +00:00
|
|
|
#include "nsBuiltinDecoderStateMachine.h"
|
2011-08-09 10:10:48 +00:00
|
|
|
#include "nsTimeRanges.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsContentUtils.h"
|
2010-04-27 08:53:44 +00:00
|
|
|
|
2010-05-06 02:31:02 +00:00
|
|
|
using namespace mozilla;
|
2009-04-11 09:39:24 +00:00
|
|
|
|
2009-09-29 21:32:44 +00:00
|
|
|
#ifdef PR_LOGGING
|
2010-04-27 08:53:44 +00:00
|
|
|
PRLogModuleInfo* gBuiltinDecoderLog;
|
|
|
|
#define LOG(type, msg) PR_LOG(gBuiltinDecoderLog, type, msg)
|
2009-09-29 21:32:44 +00:00
|
|
|
#else
|
|
|
|
#define LOG(type, msg)
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsBuiltinDecoder, nsIObserver)
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::Pause()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-05-28 03:49:22 +00:00
|
|
|
if (mPlayState == PLAY_STATE_SEEKING || mPlayState == PLAY_STATE_ENDED) {
|
2008-10-19 07:39:21 +00:00
|
|
|
mNextState = PLAY_STATE_PAUSED;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(PLAY_STATE_PAUSED);
|
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
void nsBuiltinDecoder::SetVolume(double aVolume)
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-01-17 03:03:00 +00:00
|
|
|
mInitialVolume = aVolume;
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mDecoderStateMachine) {
|
2011-01-17 03:03:00 +00:00
|
|
|
mDecoderStateMachine->SetVolume(aVolume);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 03:12:42 +00:00
|
|
|
void nsBuiltinDecoder::SetAudioCaptured(bool aCaptured)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
mInitialAudioCaptured = aCaptured;
|
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
mDecoderStateMachine->SetAudioCaptured(aCaptured);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBuiltinDecoder::AddOutputStream(SourceMediaStream* aStream, bool aFinishWhenEnded)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
OutputMediaStream* ms = mOutputStreams.AppendElement();
|
|
|
|
ms->Init(PRInt64(mCurrentTime*USECS_PER_S), aStream, aFinishWhenEnded);
|
|
|
|
}
|
|
|
|
|
2012-04-30 03:13:09 +00:00
|
|
|
// This can be called before Load(), in which case our mDecoderStateMachine
|
|
|
|
// won't have been created yet and we can rely on Load() to schedule it
|
|
|
|
// once it is created.
|
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
// Make sure the state machine thread runs so that any buffered data
|
|
|
|
// is fed into our stream.
|
|
|
|
ScheduleStateMachineThread();
|
|
|
|
}
|
2012-04-30 03:12:42 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
double nsBuiltinDecoder::GetDuration()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-08-01 18:11:20 +00:00
|
|
|
if (mInfiniteStream) {
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
2008-11-10 01:38:02 +00:00
|
|
|
if (mDuration >= 0) {
|
2011-04-13 22:12:23 +00:00
|
|
|
return static_cast<double>(mDuration) / static_cast<double>(USECS_PER_S);
|
2008-11-10 01:38:02 +00:00
|
|
|
}
|
2011-01-17 03:03:00 +00:00
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsBuiltinDecoder::SetInfinite(bool aInfinite)
|
2011-08-01 18:11:20 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
mInfiniteStream = aInfinite;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsBuiltinDecoder::IsInfinite()
|
2011-08-01 18:11:20 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
return mInfiniteStream;
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
nsBuiltinDecoder::nsBuiltinDecoder() :
|
2009-02-05 08:02:21 +00:00
|
|
|
mDecoderPosition(0),
|
|
|
|
mPlaybackPosition(0),
|
2008-10-23 08:02:18 +00:00
|
|
|
mCurrentTime(0.0),
|
2008-10-19 07:39:21 +00:00
|
|
|
mInitialVolume(0.0),
|
|
|
|
mRequestedSeekTime(-1.0),
|
2009-02-23 00:51:06 +00:00
|
|
|
mDuration(-1),
|
2011-09-29 23:34:37 +00:00
|
|
|
mSeekable(true),
|
2011-04-29 19:21:57 +00:00
|
|
|
mReentrantMonitor("media.decoder"),
|
2008-10-19 07:39:21 +00:00
|
|
|
mPlayState(PLAY_STATE_PAUSED),
|
2009-01-15 20:26:51 +00:00
|
|
|
mNextState(PLAY_STATE_PAUSED),
|
2011-09-29 23:34:37 +00:00
|
|
|
mResourceLoaded(false),
|
|
|
|
mIgnoreProgressData(false),
|
|
|
|
mInfiniteStream(false)
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-27 08:53:44 +00:00
|
|
|
MOZ_COUNT_CTOR(nsBuiltinDecoder);
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-09-29 21:32:44 +00:00
|
|
|
#ifdef PR_LOGGING
|
2010-04-27 08:53:44 +00:00
|
|
|
if (!gBuiltinDecoderLog) {
|
|
|
|
gBuiltinDecoderLog = PR_NewLogModule("nsBuiltinDecoder");
|
2009-09-29 21:32:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsBuiltinDecoder::Init(nsHTMLMediaElement* aElement)
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-09-11 01:44:21 +00:00
|
|
|
if (!nsMediaDecoder::Init(aElement))
|
2011-09-29 23:34:37 +00:00
|
|
|
return false;
|
2009-09-11 01:44:21 +00:00
|
|
|
|
2010-02-24 19:14:14 +00:00
|
|
|
nsContentUtils::RegisterShutdownObserver(this);
|
2011-09-29 23:34:37 +00:00
|
|
|
return true;
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::Shutdown()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-05-18 23:08:08 +00:00
|
|
|
|
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-09-29 23:34:37 +00:00
|
|
|
mShuttingDown = true;
|
2008-12-09 00:43:56 +00:00
|
|
|
|
2009-05-18 23:08:08 +00:00
|
|
|
// This changes the decoder state to SHUTDOWN and does other things
|
|
|
|
// necessary to unblock the state machine thread if it's blocked, so
|
|
|
|
// the asynchronous shutdown in nsDestroyStateMachine won't deadlock.
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
mDecoderStateMachine->Shutdown();
|
2009-05-18 23:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Force any outstanding seek and byterange requests to complete
|
|
|
|
// to prevent shutdown from deadlocking.
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Close();
|
2009-09-22 00:03:42 +00:00
|
|
|
}
|
2009-05-18 23:08:08 +00:00
|
|
|
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(PLAY_STATE_SHUTDOWN);
|
|
|
|
nsMediaDecoder::Shutdown();
|
|
|
|
|
2010-02-24 19:14:14 +00:00
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
nsBuiltinDecoder::~nsBuiltinDecoder()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2010-08-05 07:40:35 +00:00
|
|
|
UnpinForSeek();
|
2010-04-27 08:53:44 +00:00
|
|
|
MOZ_COUNT_DTOR(nsBuiltinDecoder);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
nsresult nsBuiltinDecoder::Load(MediaResource* aResource,
|
2011-07-12 03:39:34 +00:00
|
|
|
nsIStreamListener** aStreamListener,
|
|
|
|
nsMediaDecoder* aCloneDonor)
|
2008-09-06 23:47:28 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-09-15 02:30:44 +00:00
|
|
|
if (aStreamListener) {
|
|
|
|
*aStreamListener = nsnull;
|
|
|
|
}
|
2009-09-15 02:28:08 +00:00
|
|
|
|
2009-04-01 00:52:56 +00:00
|
|
|
{
|
|
|
|
// Hold the lock while we do this to set proper lock ordering
|
|
|
|
// expectations for dynamic deadlock detectors: decoder lock(s)
|
|
|
|
// should be grabbed before the cache lock
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-09-11 01:44:21 +00:00
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
nsresult rv = aResource->Open(aStreamListener);
|
2009-09-15 02:30:43 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-01-19 18:30:29 +00:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Failed to open stream!", this));
|
2012-02-15 04:35:01 +00:00
|
|
|
delete aResource;
|
2009-04-01 00:52:56 +00:00
|
|
|
return rv;
|
2009-09-15 02:30:43 +00:00
|
|
|
}
|
2009-09-15 02:30:43 +00:00
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
mResource = aResource;
|
2009-04-01 00:52:56 +00:00
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
mDecoderStateMachine = CreateStateMachine();
|
|
|
|
if (!mDecoderStateMachine) {
|
2012-01-10 22:58:43 +00:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Failed to create state machine!", this));
|
2010-04-27 08:53:44 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-09-21 00:49:50 +00:00
|
|
|
nsBuiltinDecoder* cloneDonor = static_cast<nsBuiltinDecoder*>(aCloneDonor);
|
|
|
|
if (NS_FAILED(mDecoderStateMachine->Init(cloneDonor ?
|
|
|
|
cloneDonor->mDecoderStateMachine : nsnull))) {
|
2012-01-10 22:58:43 +00:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Failed to init state machine!", this));
|
2010-04-02 03:03:07 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-11-10 01:38:02 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
mDecoderStateMachine->SetSeekable(mSeekable);
|
|
|
|
mDecoderStateMachine->SetDuration(mDuration);
|
2012-02-16 04:17:36 +00:00
|
|
|
mDecoderStateMachine->SetVolume(mInitialVolume);
|
2012-05-07 03:45:06 +00:00
|
|
|
mDecoderStateMachine->SetAudioCaptured(mInitialAudioCaptured);
|
2011-04-11 21:15:45 +00:00
|
|
|
|
|
|
|
if (mFrameBufferLength > 0) {
|
|
|
|
// The valid mFrameBufferLength value was specified earlier
|
|
|
|
mDecoderStateMachine->SetFrameBufferLength(mFrameBufferLength);
|
|
|
|
}
|
2008-11-10 01:38:02 +00:00
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
ChangeState(PLAY_STATE_LOADING);
|
|
|
|
|
2011-07-12 03:39:34 +00:00
|
|
|
return ScheduleStateMachineThread();
|
2010-08-25 08:45:45 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 21:15:45 +00:00
|
|
|
nsresult nsBuiltinDecoder::RequestFrameBufferLength(PRUint32 aLength)
|
|
|
|
{
|
|
|
|
nsresult res = nsMediaDecoder::RequestFrameBufferLength(aLength);
|
|
|
|
NS_ENSURE_SUCCESS(res,res);
|
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2011-04-11 21:15:45 +00:00
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
mDecoderStateMachine->SetFrameBufferLength(aLength);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-07-12 03:39:34 +00:00
|
|
|
nsresult nsBuiltinDecoder::ScheduleStateMachineThread()
|
2010-08-25 08:45:45 +00:00
|
|
|
{
|
2011-07-12 03:39:34 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2010-08-25 08:45:45 +00:00
|
|
|
NS_ASSERTION(mDecoderStateMachine,
|
|
|
|
"Must have state machine to start state machine thread");
|
2012-01-19 18:29:12 +00:00
|
|
|
NS_ENSURE_STATE(mDecoderStateMachine);
|
2011-07-12 03:39:32 +00:00
|
|
|
|
|
|
|
if (mShuttingDown)
|
|
|
|
return NS_OK;
|
2011-07-12 03:39:34 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
nsBuiltinDecoderStateMachine* m =
|
|
|
|
static_cast<nsBuiltinDecoderStateMachine*>(mDecoderStateMachine.get());
|
|
|
|
return m->ScheduleStateMachine();
|
2008-09-06 23:47:28 +00:00
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
nsresult nsBuiltinDecoder::Play()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-01-19 18:30:29 +00:00
|
|
|
NS_ASSERTION(mDecoderStateMachine != nsnull, "Should have state machine.");
|
2011-07-12 03:39:34 +00:00
|
|
|
nsresult res = ScheduleStateMachineThread();
|
2010-08-25 08:45:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(res,res);
|
2008-10-19 07:39:21 +00:00
|
|
|
if (mPlayState == PLAY_STATE_SEEKING) {
|
|
|
|
mNextState = PLAY_STATE_PLAYING;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-04-01 01:07:10 +00:00
|
|
|
if (mPlayState == PLAY_STATE_ENDED)
|
|
|
|
return Seek(0);
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
ChangeState(PLAY_STATE_PLAYING);
|
|
|
|
return NS_OK;
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 10:10:48 +00:00
|
|
|
/**
|
2011-09-29 23:34:37 +00:00
|
|
|
* Returns true if aValue is inside a range of aRanges, and put the range
|
2011-08-09 10:10:48 +00:00
|
|
|
* index in aIntervalIndex if it is not null.
|
2011-09-29 23:34:37 +00:00
|
|
|
* If aValue is not inside a range, false is returned, and aIntervalIndex, if
|
2012-01-06 06:40:51 +00:00
|
|
|
* not null, is set to the index of the range which ends immediately before aValue
|
2011-08-09 10:10:48 +00:00
|
|
|
* (and can be -1 if aValue is before aRanges.Start(0)).
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool IsInRanges(nsTimeRanges& aRanges, double aValue, PRInt32& aIntervalIndex) {
|
2011-08-09 10:10:48 +00:00
|
|
|
PRUint32 length;
|
|
|
|
aRanges.GetLength(&length);
|
|
|
|
for (PRUint32 i = 0; i < length; i++) {
|
|
|
|
double start, end;
|
|
|
|
aRanges.Start(i, &start);
|
|
|
|
if (start > aValue) {
|
|
|
|
aIntervalIndex = i - 1;
|
2011-09-29 23:34:37 +00:00
|
|
|
return false;
|
2011-08-09 10:10:48 +00:00
|
|
|
}
|
|
|
|
aRanges.End(i, &end);
|
|
|
|
if (aValue <= end) {
|
|
|
|
aIntervalIndex = i;
|
2011-09-29 23:34:37 +00:00
|
|
|
return true;
|
2011-08-09 10:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
aIntervalIndex = length - 1;
|
2011-09-29 23:34:37 +00:00
|
|
|
return false;
|
2011-08-09 10:10:48 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
nsresult nsBuiltinDecoder::Seek(double aTime)
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2011-08-09 10:10:48 +00:00
|
|
|
NS_ABORT_IF_FALSE(aTime >= 0.0, "Cannot seek to a negative value.");
|
|
|
|
|
|
|
|
nsTimeRanges seekable;
|
|
|
|
nsresult res;
|
|
|
|
PRUint32 length = 0;
|
|
|
|
res = GetSeekable(&seekable);
|
|
|
|
NS_ENSURE_SUCCESS(res, NS_OK);
|
|
|
|
|
|
|
|
seekable.GetLength(&length);
|
|
|
|
if (!length) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the position we want to seek to is not in a seekable range, we seek
|
2012-01-06 06:40:51 +00:00
|
|
|
// to the closest position in the seekable ranges instead. If two positions
|
|
|
|
// are equally close, we seek to the closest position from the currentTime.
|
2011-08-09 10:10:48 +00:00
|
|
|
// See seeking spec, point 7 :
|
2012-01-06 06:40:51 +00:00
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#seeking
|
2011-08-09 10:10:48 +00:00
|
|
|
PRInt32 range = 0;
|
|
|
|
if (!IsInRanges(seekable, aTime, range)) {
|
|
|
|
if (range != -1) {
|
2012-02-21 09:34:01 +00:00
|
|
|
// |range + 1| can't be negative, because the only possible negative value
|
|
|
|
// for |range| is -1.
|
|
|
|
if (PRUint32(range + 1) < length) {
|
2012-01-06 06:40:51 +00:00
|
|
|
double leftBound, rightBound;
|
|
|
|
res = seekable.End(range, &leftBound);
|
|
|
|
NS_ENSURE_SUCCESS(res, NS_OK);
|
|
|
|
res = seekable.Start(range + 1, &rightBound);
|
|
|
|
NS_ENSURE_SUCCESS(res, NS_OK);
|
|
|
|
double distanceLeft = NS_ABS(leftBound - aTime);
|
|
|
|
double distanceRight = NS_ABS(rightBound - aTime);
|
|
|
|
if (distanceLeft == distanceRight) {
|
|
|
|
distanceLeft = NS_ABS(leftBound - mCurrentTime);
|
|
|
|
distanceRight = NS_ABS(rightBound - mCurrentTime);
|
|
|
|
}
|
|
|
|
aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
|
|
|
|
} else {
|
|
|
|
// Seek target is after the end last range in seekable data.
|
|
|
|
// Clamp the seek target to the end of the last seekable range.
|
|
|
|
res = seekable.End(length - 1, &aTime);
|
2011-08-09 10:10:48 +00:00
|
|
|
NS_ENSURE_SUCCESS(res, NS_OK);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// aTime is before the first range in |seekable|, the closest point we can
|
|
|
|
// seek to is the start of the first range.
|
|
|
|
seekable.Start(0, &aTime);
|
|
|
|
}
|
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
mRequestedSeekTime = aTime;
|
2011-02-01 02:57:13 +00:00
|
|
|
mCurrentTime = aTime;
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
// If we are already in the seeking state, then setting mRequestedSeekTime
|
|
|
|
// above will result in the new seek occurring when the current seek
|
|
|
|
// completes.
|
|
|
|
if (mPlayState != PLAY_STATE_SEEKING) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool paused = false;
|
2011-09-27 02:22:09 +00:00
|
|
|
if (mElement) {
|
|
|
|
mElement->GetPaused(&paused);
|
2009-04-01 01:07:10 +00:00
|
|
|
}
|
2011-09-27 02:22:09 +00:00
|
|
|
mNextState = paused ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING;
|
2010-08-05 07:40:35 +00:00
|
|
|
PinForSeek();
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(PLAY_STATE_SEEKING);
|
|
|
|
}
|
|
|
|
|
2011-07-12 03:39:34 +00:00
|
|
|
return ScheduleStateMachineThread();
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
nsresult nsBuiltinDecoder::PlaybackRateChanged()
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-10-19 07:39:21 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
double nsBuiltinDecoder::GetCurrentTime()
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-10-23 08:02:18 +00:00
|
|
|
return mCurrentTime;
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
already_AddRefed<nsIPrincipal> nsBuiltinDecoder::GetCurrentPrincipal()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
return mResource ? mResource->GetCurrentPrincipal() : nsnull;
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 13:10:00 +00:00
|
|
|
void nsBuiltinDecoder::AudioAvailable(float* aFrameBuffer,
|
|
|
|
PRUint32 aFrameBufferLength,
|
2010-10-06 22:58:36 +00:00
|
|
|
float aTime)
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-09-06 02:14:50 +00:00
|
|
|
// Auto manage the frame buffer's memory. If we return due to an error
|
|
|
|
// here, this ensures we free the memory. Otherwise, we pass off ownership
|
|
|
|
// to HTMLMediaElement::NotifyAudioAvailable().
|
|
|
|
nsAutoArrayPtr<float> frameBuffer(aFrameBuffer);
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-11-22 00:34:21 +00:00
|
|
|
if (mShuttingDown || !mElement) {
|
2010-08-17 13:40:00 +00:00
|
|
|
return;
|
2010-08-25 13:10:00 +00:00
|
|
|
}
|
2010-09-06 02:14:50 +00:00
|
|
|
mElement->NotifyAudioAvailable(frameBuffer.forget(), aFrameBufferLength, aTime);
|
2010-08-25 13:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBuiltinDecoder::MetadataLoaded(PRUint32 aChannels,
|
2012-04-28 15:01:10 +00:00
|
|
|
PRUint32 aRate,
|
|
|
|
bool aHasAudio)
|
2010-08-25 13:10:00 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-10 01:38:02 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
|
2010-07-20 01:29:27 +00:00
|
|
|
// Duration has changed so we should recompute playback rate
|
|
|
|
UpdatePlaybackRate();
|
2008-11-10 01:38:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-01 18:11:20 +00:00
|
|
|
if (mDuration == -1) {
|
2011-09-29 23:34:37 +00:00
|
|
|
SetInfinite(true);
|
2011-08-01 18:11:20 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 05:57:23 +00:00
|
|
|
if (mElement) {
|
2009-01-28 09:33:37 +00:00
|
|
|
// Make sure the element and the frame (if any) are told about
|
|
|
|
// our new size.
|
|
|
|
Invalidate();
|
2012-04-28 15:01:10 +00:00
|
|
|
mElement->MetadataLoaded(aChannels, aRate, aHasAudio);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
2009-01-15 20:26:51 +00:00
|
|
|
|
|
|
|
if (!mResourceLoaded) {
|
|
|
|
StartProgress();
|
2011-09-23 04:27:18 +00:00
|
|
|
} else if (mElement) {
|
2009-01-15 20:26:51 +00:00
|
|
|
// Resource was loaded during metadata loading, when progress
|
|
|
|
// events are being ignored. Fire the final progress event.
|
2010-09-10 03:29:06 +00:00
|
|
|
mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
|
2009-01-15 20:26:51 +00:00
|
|
|
}
|
2010-04-02 03:03:07 +00:00
|
|
|
|
2008-12-10 14:23:23 +00:00
|
|
|
// Only inform the element of FirstFrameLoaded if not doing a load() in order
|
|
|
|
// to fulfill a seek, otherwise we'll get multiple loadedfirstframe events.
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-02-15 04:35:01 +00:00
|
|
|
bool resourceIsLoaded = !mResourceLoaded && mResource &&
|
|
|
|
mResource->IsDataCachedToEndOfResource(mDecoderPosition);
|
2012-05-15 05:57:23 +00:00
|
|
|
if (mElement) {
|
2009-05-18 23:06:10 +00:00
|
|
|
mElement->FirstFrameLoaded(resourceIsLoaded);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2011-11-30 05:05:49 +00:00
|
|
|
// This can run cache callbacks.
|
2012-02-15 04:35:01 +00:00
|
|
|
mResource->EnsureCacheUpToDate();
|
2011-11-30 05:05:49 +00:00
|
|
|
|
2008-10-19 07:39:21 +00:00
|
|
|
// The element can run javascript via events
|
2010-04-02 03:03:07 +00:00
|
|
|
// before reaching here, so only change the
|
2008-10-19 07:39:21 +00:00
|
|
|
// state if we're still set to the original
|
|
|
|
// loading state.
|
|
|
|
if (mPlayState == PLAY_STATE_LOADING) {
|
|
|
|
if (mRequestedSeekTime >= 0.0) {
|
|
|
|
ChangeState(PLAY_STATE_SEEKING);
|
2010-04-27 08:53:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(mNextState);
|
|
|
|
}
|
|
|
|
}
|
2009-01-15 20:26:51 +00:00
|
|
|
|
2009-05-18 23:06:10 +00:00
|
|
|
if (resourceIsLoaded) {
|
2009-01-15 20:26:51 +00:00
|
|
|
ResourceLoaded();
|
|
|
|
}
|
2011-11-30 05:05:49 +00:00
|
|
|
|
|
|
|
// Run NotifySuspendedStatusChanged now to give us a chance to notice
|
|
|
|
// that autoplay should run.
|
|
|
|
NotifySuspendedStatusChanged();
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::ResourceLoaded()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
2009-01-15 20:26:51 +00:00
|
|
|
// 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).
|
2009-01-07 03:33:42 +00:00
|
|
|
if (mShuttingDown)
|
2008-12-09 00:43:56 +00:00
|
|
|
return;
|
|
|
|
|
2009-01-15 20:26:51 +00:00
|
|
|
{
|
|
|
|
// 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.
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-02-05 08:02:21 +00:00
|
|
|
if (mIgnoreProgressData || mResourceLoaded || mPlayState == PLAY_STATE_LOADING)
|
2009-01-15 20:26:51 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-29 23:34:37 +00:00
|
|
|
Progress(false);
|
2009-01-15 20:26:51 +00:00
|
|
|
|
2011-09-29 23:34:37 +00:00
|
|
|
mResourceLoaded = true;
|
2009-02-05 08:02:21 +00:00
|
|
|
StopProgress();
|
|
|
|
}
|
2009-02-05 10:51:24 +00:00
|
|
|
|
2009-01-15 20:26:51 +00:00
|
|
|
// Ensure the final progress event gets fired
|
2008-07-30 06:50:14 +00:00
|
|
|
if (mElement) {
|
|
|
|
mElement->ResourceLoaded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NetworkError()
|
2008-11-06 20:53:20 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-05-18 23:08:08 +00:00
|
|
|
if (mShuttingDown)
|
2008-12-09 00:43:56 +00:00
|
|
|
return;
|
|
|
|
|
2008-11-06 20:53:20 +00:00
|
|
|
if (mElement)
|
|
|
|
mElement->NetworkError();
|
2009-05-18 23:08:08 +00:00
|
|
|
|
|
|
|
Shutdown();
|
2008-11-06 20:53:20 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::DecodeError()
|
2009-09-22 00:08:13 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-09-22 00:08:13 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mElement)
|
|
|
|
mElement->DecodeError();
|
|
|
|
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsBuiltinDecoder::IsSeeking() const
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2012-05-15 05:57:17 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-05-15 05:57:23 +00:00
|
|
|
return mPlayState == PLAY_STATE_SEEKING;
|
2008-12-14 18:02:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsBuiltinDecoder::IsEnded() const
|
2008-12-14 18:02:54 +00:00
|
|
|
{
|
2012-05-15 05:57:17 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-12-14 18:02:54 +00:00
|
|
|
return mPlayState == PLAY_STATE_ENDED || mPlayState == PLAY_STATE_SHUTDOWN;
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::PlaybackEnded()
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mShuttingDown || mPlayState == nsBuiltinDecoder::PLAY_STATE_SEEKING)
|
2008-12-09 00:43:56 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-01 21:54:16 +00:00
|
|
|
PlaybackPositionChanged();
|
2009-04-01 01:07:10 +00:00
|
|
|
ChangeState(PLAY_STATE_ENDED);
|
|
|
|
|
2008-10-19 07:39:21 +00:00
|
|
|
if (mElement) {
|
2009-05-18 22:44:17 +00:00
|
|
|
UpdateReadyStateForData();
|
2008-10-19 07:39:21 +00:00
|
|
|
mElement->PlaybackEnded();
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
2011-08-01 18:11:20 +00:00
|
|
|
|
|
|
|
// This must be called after |mElement->PlaybackEnded()| call above, in order
|
|
|
|
// to fire the required durationchange.
|
|
|
|
if (IsInfinite()) {
|
2011-09-29 23:34:37 +00:00
|
|
|
SetInfinite(false);
|
2011-08-01 18:11:20 +00:00
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
NS_IMETHODIMP nsBuiltinDecoder::Observe(nsISupports *aSubjet,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-07-30 06:50:14 +00:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:02:21 +00:00
|
|
|
nsMediaDecoder::Statistics
|
2010-04-27 08:53:44 +00:00
|
|
|
nsBuiltinDecoder::GetStatistics()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-07-22 22:48:32 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread() || OnStateMachineThread(),
|
|
|
|
"Should be on main or state machine thread.");
|
2009-02-05 08:02:21 +00:00
|
|
|
Statistics result;
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mDownloadRate =
|
2012-02-15 04:35:01 +00:00
|
|
|
mResource->GetDownloadRate(&result.mDownloadRateReliable);
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mDownloadPosition =
|
2012-02-15 04:35:01 +00:00
|
|
|
mResource->GetCachedDataEnd(mDecoderPosition);
|
|
|
|
result.mTotalBytes = mResource->GetLength();
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mPlaybackRate = ComputePlaybackRate(&result.mPlaybackRateReliable);
|
|
|
|
result.mDecoderPosition = mDecoderPosition;
|
|
|
|
result.mPlaybackPosition = mPlaybackPosition;
|
2010-04-27 08:53:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mDownloadRate = 0;
|
2011-09-29 23:34:37 +00:00
|
|
|
result.mDownloadRateReliable = true;
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mPlaybackRate = 0;
|
2011-09-29 23:34:37 +00:00
|
|
|
result.mPlaybackRateReliable = true;
|
2009-04-01 00:52:56 +00:00
|
|
|
result.mDecoderPosition = 0;
|
|
|
|
result.mPlaybackPosition = 0;
|
|
|
|
result.mDownloadPosition = 0;
|
|
|
|
result.mTotalBytes = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-05 08:02:21 +00:00
|
|
|
return result;
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
double nsBuiltinDecoder::ComputePlaybackRate(bool* aReliable)
|
2009-02-05 08:02:21 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-07-12 03:39:34 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread() || OnStateMachineThread(),
|
2010-04-02 03:03:07 +00:00
|
|
|
"Should be on main or state machine thread.");
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
PRInt64 length = mResource ? mResource->GetLength() : -1;
|
2009-04-01 00:52:56 +00:00
|
|
|
if (mDuration >= 0 && length >= 0) {
|
2011-09-29 23:34:37 +00:00
|
|
|
*aReliable = true;
|
2011-04-13 22:12:23 +00:00
|
|
|
return length * static_cast<double>(USECS_PER_S) / mDuration;
|
2009-04-01 00:52:56 +00:00
|
|
|
}
|
|
|
|
return mPlaybackStatistics.GetRateAtLastStop(aReliable);
|
|
|
|
}
|
2009-02-05 08:02:21 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::UpdatePlaybackRate()
|
2009-04-01 00:52:56 +00:00
|
|
|
{
|
2011-07-12 03:39:34 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread() || OnStateMachineThread(),
|
2010-04-02 03:03:07 +00:00
|
|
|
"Should be on main or state machine thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2012-02-15 04:35:01 +00:00
|
|
|
if (!mResource)
|
2009-04-01 00:52:56 +00:00
|
|
|
return;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool reliable;
|
2009-04-01 00:52:56 +00:00
|
|
|
PRUint32 rate = PRUint32(ComputePlaybackRate(&reliable));
|
2009-05-18 23:05:13 +00:00
|
|
|
if (reliable) {
|
|
|
|
// Avoid passing a zero rate
|
2010-04-02 03:03:07 +00:00
|
|
|
rate = NS_MAX(rate, 1u);
|
2010-04-27 08:53:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-04-01 00:52:56 +00:00
|
|
|
// Set a minimum rate of 10,000 bytes per second ... sometimes we just
|
|
|
|
// don't have good data
|
2010-04-02 03:03:07 +00:00
|
|
|
rate = NS_MAX(rate, 10000u);
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
2012-02-15 04:35:01 +00:00
|
|
|
mResource->SetPlaybackRate(rate);
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NotifySuspendedStatusChanged()
|
2009-02-05 08:02:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
if (!mResource)
|
2009-04-01 00:52:56 +00:00
|
|
|
return;
|
2012-02-15 04:35:01 +00:00
|
|
|
MediaResource* activeStream;
|
|
|
|
bool suspended = mResource->IsSuspendedByCache(&activeStream);
|
2011-12-09 04:48:40 +00:00
|
|
|
|
2011-12-01 03:59:00 +00:00
|
|
|
if (suspended && mElement) {
|
2009-04-01 00:52:56 +00:00
|
|
|
// if this is an autoplay element, we need to kick off its autoplaying
|
|
|
|
// now so we consume data and hopefully free up cache space
|
|
|
|
mElement->NotifyAutoplayDataReady();
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NotifyBytesDownloaded()
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2009-04-01 00:52:56 +00:00
|
|
|
UpdateReadyStateForData();
|
2011-09-29 23:34:37 +00:00
|
|
|
Progress(false);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NotifyDownloadEnded(nsresult aStatus)
|
2008-07-30 06:50:14 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
2010-09-03 00:03:03 +00:00
|
|
|
if (aStatus == NS_BINDING_ABORTED) {
|
|
|
|
// Download has been cancelled by user.
|
2011-09-23 04:27:18 +00:00
|
|
|
if (mElement) {
|
|
|
|
mElement->LoadAborted();
|
|
|
|
}
|
2008-12-09 00:43:56 +00:00
|
|
|
return;
|
2010-09-03 00:03:03 +00:00
|
|
|
}
|
2008-12-09 00:43:56 +00:00
|
|
|
|
2009-02-05 08:02:21 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-04-01 00:52:56 +00:00
|
|
|
UpdatePlaybackRate();
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
2009-02-05 08:02:21 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
ResourceLoaded();
|
2010-04-27 08:53:44 +00:00
|
|
|
}
|
|
|
|
else if (aStatus != NS_BASE_STREAM_CLOSED) {
|
2009-02-05 08:02:21 +00:00
|
|
|
NetworkError();
|
|
|
|
}
|
|
|
|
UpdateReadyStateForData();
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 03:12:42 +00:00
|
|
|
void nsBuiltinDecoder::NotifyPrincipalChanged()
|
|
|
|
{
|
|
|
|
if (mElement) {
|
|
|
|
mElement->NotifyDecoderPrincipalChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NotifyBytesConsumed(PRInt64 aBytes)
|
2009-02-05 08:02:21 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
NS_ASSERTION(OnStateMachineThread() || mDecoderStateMachine->OnDecodeThread(),
|
2010-04-02 03:03:07 +00:00
|
|
|
"Should be on play state machine or decode thread.");
|
2009-02-05 08:02:21 +00:00
|
|
|
if (!mIgnoreProgressData) {
|
|
|
|
mDecoderPosition += aBytes;
|
2011-01-18 00:53:18 +00:00
|
|
|
mPlaybackStatistics.AddBytes(aBytes);
|
2009-02-05 08:02:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NextFrameUnavailableBuffering()
|
2010-03-14 23:46:38 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
|
2010-04-27 08:53:44 +00:00
|
|
|
if (!mElement || mShuttingDown || !mDecoderStateMachine)
|
2010-03-14 23:46:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mElement->UpdateReadyStateForData(nsHTMLMediaElement::NEXT_FRAME_UNAVAILABLE_BUFFERING);
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NextFrameAvailable()
|
2010-03-14 23:46:38 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
|
2010-04-27 08:53:44 +00:00
|
|
|
if (!mElement || mShuttingDown || !mDecoderStateMachine)
|
2010-03-14 23:46:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mElement->UpdateReadyStateForData(nsHTMLMediaElement::NEXT_FRAME_AVAILABLE);
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::NextFrameUnavailable()
|
2010-03-14 23:46:38 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
|
2010-04-27 08:53:44 +00:00
|
|
|
if (!mElement || mShuttingDown || !mDecoderStateMachine)
|
2010-03-14 23:46:38 +00:00
|
|
|
return;
|
|
|
|
mElement->UpdateReadyStateForData(nsHTMLMediaElement::NEXT_FRAME_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::UpdateReadyStateForData()
|
2009-02-05 08:02:21 +00:00
|
|
|
{
|
2010-03-14 23:46:38 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
|
2010-04-27 08:53:44 +00:00
|
|
|
if (!mElement || mShuttingDown || !mDecoderStateMachine)
|
2008-12-09 00:43:56 +00:00
|
|
|
return;
|
2010-03-14 23:46:38 +00:00
|
|
|
nsHTMLMediaElement::NextFrameStatus frameStatus =
|
2010-04-27 08:53:44 +00:00
|
|
|
mDecoderStateMachine->GetNextFrameStatus();
|
2009-02-11 01:43:45 +00:00
|
|
|
mElement->UpdateReadyStateForData(frameStatus);
|
2008-07-30 06:50:14 +00:00
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::SeekingStopped()
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
2008-12-09 00:43:56 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool seekWasAborted = false;
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
// An additional seek was requested while the current seek was
|
|
|
|
// in operation.
|
2010-08-05 07:40:35 +00:00
|
|
|
if (mRequestedSeekTime >= 0.0) {
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(PLAY_STATE_SEEKING);
|
2011-09-29 23:34:37 +00:00
|
|
|
seekWasAborted = true;
|
2010-08-05 07:40:35 +00:00
|
|
|
} else {
|
|
|
|
UnpinForSeek();
|
2008-10-19 07:39:21 +00:00
|
|
|
ChangeState(mNextState);
|
2010-08-05 07:40:35 +00:00
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mElement) {
|
2009-02-05 08:02:21 +00:00
|
|
|
UpdateReadyStateForData();
|
2011-02-01 02:57:13 +00:00
|
|
|
if (!seekWasAborted) {
|
|
|
|
mElement->SeekCompleted();
|
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-31 10:02:17 +00:00
|
|
|
// This is called when seeking stopped *and* we're at the end of the
|
|
|
|
// media.
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::SeekingStoppedAtEnd()
|
2009-05-31 10:02:17 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
2009-05-31 10:02:17 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool fireEnded = false;
|
|
|
|
bool seekWasAborted = false;
|
2009-05-31 10:02:17 +00:00
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2009-05-31 10:02:17 +00:00
|
|
|
|
|
|
|
// An additional seek was requested while the current seek was
|
|
|
|
// in operation.
|
|
|
|
if (mRequestedSeekTime >= 0.0) {
|
|
|
|
ChangeState(PLAY_STATE_SEEKING);
|
2011-09-29 23:34:37 +00:00
|
|
|
seekWasAborted = true;
|
2010-08-05 07:40:35 +00:00
|
|
|
} else {
|
|
|
|
UnpinForSeek();
|
2011-09-29 23:34:37 +00:00
|
|
|
fireEnded = true;
|
2011-08-29 01:35:52 +00:00
|
|
|
ChangeState(PLAY_STATE_ENDED);
|
2009-05-31 10:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mElement) {
|
|
|
|
UpdateReadyStateForData();
|
2011-02-01 02:57:13 +00:00
|
|
|
if (!seekWasAborted) {
|
|
|
|
mElement->SeekCompleted();
|
|
|
|
if (fireEnded) {
|
|
|
|
mElement->PlaybackEnded();
|
|
|
|
}
|
2009-05-31 10:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::SeekingStarted()
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-12-09 00:43:56 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
if (mElement) {
|
2009-05-18 22:44:17 +00:00
|
|
|
UpdateReadyStateForData();
|
2008-10-19 07:39:21 +00:00
|
|
|
mElement->SeekStarted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::ChangeState(PlayState aState)
|
2008-10-19 07:39:21 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2008-10-19 07:39:21 +00:00
|
|
|
|
|
|
|
if (mNextState == aState) {
|
|
|
|
mNextState = PLAY_STATE_PAUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPlayState == PLAY_STATE_SHUTDOWN) {
|
2011-04-29 19:21:57 +00:00
|
|
|
mReentrantMonitor.NotifyAll();
|
2008-10-19 07:39:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPlayState = aState;
|
2012-01-19 18:29:12 +00:00
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
switch (aState) {
|
|
|
|
case PLAY_STATE_PLAYING:
|
|
|
|
mDecoderStateMachine->Play();
|
|
|
|
break;
|
|
|
|
case PLAY_STATE_SEEKING:
|
|
|
|
mDecoderStateMachine->Seek(mRequestedSeekTime);
|
|
|
|
mRequestedSeekTime = -1.0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* No action needed */
|
|
|
|
break;
|
|
|
|
}
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
2011-04-29 19:21:57 +00:00
|
|
|
mReentrantMonitor.NotifyAll();
|
2008-10-19 07:39:21 +00:00
|
|
|
}
|
2008-10-23 08:02:18 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::PlaybackPositionChanged()
|
2008-10-23 08:02:18 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-12-09 00:43:56 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-01-17 03:03:00 +00:00
|
|
|
double lastTime = mCurrentTime;
|
2008-10-23 08:02:18 +00:00
|
|
|
|
|
|
|
// Control the scope of the monitor so it is not
|
|
|
|
// held while the timeupdate and the invalidate is run.
|
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mDecoderStateMachine) {
|
2012-02-14 08:48:16 +00:00
|
|
|
if (!IsSeeking()) {
|
|
|
|
// Only update the current playback position if we're not seeking.
|
|
|
|
// If we are seeking, the update could have been scheduled on the
|
|
|
|
// state machine thread while we were playing but after the seek
|
|
|
|
// algorithm set the current playback position on the main thread,
|
|
|
|
// and we don't want to override the seek algorithm and change the
|
|
|
|
// current time after the seek has started but before it has
|
|
|
|
// completed.
|
|
|
|
mCurrentTime = mDecoderStateMachine->GetCurrentTime();
|
|
|
|
}
|
2010-04-27 08:53:44 +00:00
|
|
|
mDecoderStateMachine->ClearPositionChangeFlag();
|
2008-10-23 08:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate the frame so any video data is displayed.
|
|
|
|
// Do this before the timeupdate event so that if that
|
|
|
|
// event runs JavaScript that queries the media size, the
|
|
|
|
// frame has reflowed and the size updated beforehand.
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
if (mElement && lastTime != mCurrentTime) {
|
2010-09-10 05:49:26 +00:00
|
|
|
FireTimeUpdate();
|
2008-10-23 08:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-10 01:38:02 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::DurationChanged()
|
2010-04-02 03:03:07 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-02 03:03:07 +00:00
|
|
|
PRInt64 oldDuration = mDuration;
|
2010-04-27 08:53:44 +00:00
|
|
|
mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1;
|
2010-07-20 01:29:27 +00:00
|
|
|
// Duration has changed so we should recompute playback rate
|
|
|
|
UpdatePlaybackRate();
|
|
|
|
|
2011-08-01 18:11:20 +00:00
|
|
|
if (mElement && oldDuration != mDuration && !IsInfinite()) {
|
2011-04-13 22:12:23 +00:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p duration changed to %lld", this, mDuration));
|
2010-09-10 03:29:06 +00:00
|
|
|
mElement->DispatchEvent(NS_LITERAL_STRING("durationchange"));
|
2010-04-02 03:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 22:12:23 +00:00
|
|
|
void nsBuiltinDecoder::SetDuration(double aDuration)
|
2009-02-07 10:10:34 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2011-04-13 22:12:23 +00:00
|
|
|
mDuration = static_cast<PRInt64>(NS_round(aDuration * static_cast<double>(USECS_PER_S)));
|
2010-07-20 01:29:27 +00:00
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
mDecoderStateMachine->SetDuration(mDuration);
|
2009-02-07 10:10:34 +00:00
|
|
|
}
|
2010-07-20 01:29:27 +00:00
|
|
|
|
|
|
|
// Duration has changed so we should recompute playback rate
|
|
|
|
UpdatePlaybackRate();
|
2009-02-07 10:10:34 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsBuiltinDecoder::SetSeekable(bool aSeekable)
|
2008-11-10 01:38:02 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-11-10 01:38:02 +00:00
|
|
|
mSeekable = aSeekable;
|
2010-04-27 08:53:44 +00:00
|
|
|
if (mDecoderStateMachine) {
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:44 +00:00
|
|
|
mDecoderStateMachine->SetSeekable(aSeekable);
|
2008-11-10 01:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsBuiltinDecoder::IsSeekable()
|
2008-11-10 01:38:02 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2008-11-10 01:38:02 +00:00
|
|
|
return mSeekable;
|
|
|
|
}
|
2009-01-07 03:33:42 +00:00
|
|
|
|
2011-08-09 10:10:48 +00:00
|
|
|
nsresult nsBuiltinDecoder::GetSeekable(nsTimeRanges* aSeekable)
|
|
|
|
{
|
|
|
|
//TODO : change 0.0 to GetInitialTime() when available
|
|
|
|
double initialTime = 0.0;
|
|
|
|
|
|
|
|
if (IsSeekable()) {
|
|
|
|
double end = IsInfinite() ? std::numeric_limits<double>::infinity()
|
|
|
|
: initialTime + GetDuration();
|
|
|
|
aSeekable->Add(initialTime, end);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetBuffered(aSeekable);
|
|
|
|
}
|
|
|
|
|
2011-08-24 23:42:23 +00:00
|
|
|
void nsBuiltinDecoder::SetEndTime(double aTime)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
mDecoderStateMachine->SetFragmentEndTime(static_cast<PRInt64>(aTime * USECS_PER_S));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::Suspend()
|
2009-01-21 23:54:40 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Suspend(true);
|
2009-01-21 23:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsBuiltinDecoder::Resume(bool aForceBuffering)
|
2009-01-21 23:54:40 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Resume();
|
2009-01-21 23:54:40 +00:00
|
|
|
}
|
2010-07-22 22:48:32 +00:00
|
|
|
if (aForceBuffering) {
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-01-19 18:29:12 +00:00
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
mDecoderStateMachine->StartBuffering();
|
|
|
|
}
|
2010-07-22 22:48:32 +00:00
|
|
|
}
|
2009-01-21 23:54:40 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::StopProgressUpdates()
|
2009-01-15 20:26:51 +00:00
|
|
|
{
|
2011-07-12 03:39:23 +00:00
|
|
|
NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(),
|
|
|
|
"Should be on state machine or decode thread.");
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-09-29 23:34:37 +00:00
|
|
|
mIgnoreProgressData = true;
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->SetReadMode(nsMediaCacheStream::MODE_METADATA);
|
2009-04-01 00:52:56 +00:00
|
|
|
}
|
2009-01-15 20:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::StartProgressUpdates()
|
2009-01-15 20:26:51 +00:00
|
|
|
{
|
2011-07-12 03:39:23 +00:00
|
|
|
NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(),
|
|
|
|
"Should be on state machine or decode thread.");
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-09-29 23:34:37 +00:00
|
|
|
mIgnoreProgressData = false;
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->SetReadMode(nsMediaCacheStream::MODE_PLAYBACK);
|
|
|
|
mDecoderPosition = mPlaybackPosition = mResource->Tell();
|
2009-04-01 00:52:56 +00:00
|
|
|
}
|
2009-01-15 20:26:51 +00:00
|
|
|
}
|
2009-04-10 01:28:24 +00:00
|
|
|
|
2010-04-27 08:53:44 +00:00
|
|
|
void nsBuiltinDecoder::MoveLoadsToBackground()
|
2009-04-10 01:28:24 +00:00
|
|
|
{
|
2010-04-02 03:03:07 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2012-02-15 04:35:01 +00:00
|
|
|
if (mResource) {
|
|
|
|
mResource->MoveLoadsToBackground();
|
2009-04-10 01:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-27 08:53:45 +00:00
|
|
|
|
|
|
|
void nsBuiltinDecoder::UpdatePlaybackOffset(PRInt64 aOffset)
|
|
|
|
{
|
2011-04-29 19:21:57 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2010-04-27 08:53:45 +00:00
|
|
|
mPlaybackPosition = NS_MAX(aOffset, mPlaybackPosition);
|
|
|
|
}
|
2011-07-12 03:39:34 +00:00
|
|
|
|
2011-11-22 00:34:21 +00:00
|
|
|
bool nsBuiltinDecoder::OnStateMachineThread() const
|
|
|
|
{
|
2011-07-12 03:39:34 +00:00
|
|
|
return IsCurrentThread(nsBuiltinDecoderStateMachine::GetStateMachineThread());
|
|
|
|
}
|
2011-11-22 00:34:21 +00:00
|
|
|
|
|
|
|
void nsBuiltinDecoder::NotifyAudioAvailableListener()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
if (mDecoderStateMachine) {
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
mDecoderStateMachine->NotifyAudioAvailableListener();
|
|
|
|
}
|
|
|
|
}
|