2013-01-18 09:43:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
#include "MediaDecoder.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2008-11-10 04:38:02 +03:00
|
|
|
#include <limits>
|
2008-07-30 10:50:14 +04:00
|
|
|
#include "nsIObserver.h"
|
2008-10-19 11:39:21 +04:00
|
|
|
#include "nsTArray.h"
|
2010-04-27 12:53:44 +04:00
|
|
|
#include "VideoUtils.h"
|
2012-11-14 23:46:40 +04:00
|
|
|
#include "MediaDecoderStateMachine.h"
|
2012-08-21 08:06:46 +04:00
|
|
|
#include "ImageContainer.h"
|
2012-11-14 23:45:13 +04:00
|
|
|
#include "MediaResource.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2013-11-26 04:01:31 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2013-12-18 07:59:11 +04:00
|
|
|
#include "MediaShutdownManager.h"
|
2014-04-10 21:39:20 +04:00
|
|
|
#include "AudioChannelService.h"
|
2014-07-04 07:55:06 +04:00
|
|
|
#include "mozilla/dom/AudioTrack.h"
|
|
|
|
#include "mozilla/dom/AudioTrackList.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
|
|
|
#include "mozilla/dom/VideoTrack.h"
|
|
|
|
#include "mozilla/dom/VideoTrackList.h"
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2012-11-16 07:25:26 +04:00
|
|
|
using namespace mozilla::dom;
|
2015-05-28 22:13:56 +03:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::media;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
// Default timeout msecs until try to enter dormant state by heuristic.
|
|
|
|
static const int DEFAULT_HEURISTIC_DORMANT_TIMEOUT_MSECS = 60000;
|
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Number of estimated seconds worth of data we need to have buffered
|
|
|
|
// ahead of the current playback position before we allow the media decoder
|
|
|
|
// to report that it can play through the entire media without the decode
|
|
|
|
// catching up with the download. Having this margin make the
|
2012-11-14 23:46:40 +04:00
|
|
|
// MediaDecoder::CanPlayThrough() calculation more stable in the case of
|
2012-11-14 23:45:13 +04:00
|
|
|
// fluctuating bitrates.
|
2013-05-06 03:59:05 +04:00
|
|
|
static const int64_t CAN_PLAY_THROUGH_MARGIN = 1;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2015-06-03 01:29:50 +03:00
|
|
|
// The amount of instability we tollerate in calls to
|
|
|
|
// MediaDecoder::UpdateEstimatedMediaDuration(); changes of duration
|
|
|
|
// less than this are ignored, as they're assumed to be the result of
|
|
|
|
// instability in the duration estimation.
|
|
|
|
static const uint64_t ESTIMATED_DURATION_FUZZ_FACTOR_USECS = USECS_PER_S / 2;
|
|
|
|
|
2014-04-23 13:29:04 +04:00
|
|
|
// avoid redefined macro in unified build
|
|
|
|
#undef DECODER_LOG
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
PRLogModuleInfo* gMediaDecoderLog;
|
2014-08-21 04:13:00 +04:00
|
|
|
#define DECODER_LOG(x, ...) \
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, ("Decoder=%p " x, this, ##__VA_ARGS__))
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2015-06-30 10:58:05 +03:00
|
|
|
static const char*
|
|
|
|
ToPlayStateStr(MediaDecoder::PlayState aState)
|
|
|
|
{
|
|
|
|
switch (aState) {
|
|
|
|
case MediaDecoder::PLAY_STATE_START: return "START";
|
|
|
|
case MediaDecoder::PLAY_STATE_LOADING: return "LOADING";
|
|
|
|
case MediaDecoder::PLAY_STATE_PAUSED: return "PAUSED";
|
|
|
|
case MediaDecoder::PLAY_STATE_PLAYING: return "PLAYING";
|
|
|
|
case MediaDecoder::PLAY_STATE_ENDED: return "ENDED";
|
|
|
|
case MediaDecoder::PLAY_STATE_SHUTDOWN: return "SHUTDOWN";
|
|
|
|
default: MOZ_ASSERT_UNREACHABLE("Invalid playState.");
|
|
|
|
}
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2014-08-21 04:13:00 +04:00
|
|
|
|
2013-12-08 09:39:47 +04:00
|
|
|
class MediaMemoryTracker : public nsIMemoryReporter
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2014-06-24 20:36:43 +04:00
|
|
|
virtual ~MediaMemoryTracker();
|
|
|
|
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2013-11-26 04:01:31 +04:00
|
|
|
|
2014-03-06 01:31:04 +04:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf);
|
|
|
|
|
2013-01-18 09:43:20 +04:00
|
|
|
MediaMemoryTracker();
|
2013-11-07 09:35:30 +04:00
|
|
|
void InitMemoryReporter();
|
|
|
|
|
2013-11-26 04:01:31 +04:00
|
|
|
static StaticRefPtr<MediaMemoryTracker> sUniqueInstance;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2013-01-18 09:43:20 +04:00
|
|
|
static MediaMemoryTracker* UniqueInstance() {
|
2012-11-14 23:45:13 +04:00
|
|
|
if (!sUniqueInstance) {
|
2013-01-18 09:43:20 +04:00
|
|
|
sUniqueInstance = new MediaMemoryTracker();
|
2013-11-07 09:35:30 +04:00
|
|
|
sUniqueInstance->InitMemoryReporter();
|
2012-11-14 23:45:13 +04:00
|
|
|
}
|
|
|
|
return sUniqueInstance;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
typedef nsTArray<MediaDecoder*> DecodersArray;
|
2012-11-14 23:45:13 +04:00
|
|
|
static DecodersArray& Decoders() {
|
|
|
|
return UniqueInstance()->mDecoders;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecodersArray mDecoders;
|
|
|
|
|
|
|
|
public:
|
2013-01-18 09:43:20 +04:00
|
|
|
static void AddMediaDecoder(MediaDecoder* aDecoder)
|
|
|
|
{
|
2012-11-14 23:45:13 +04:00
|
|
|
Decoders().AppendElement(aDecoder);
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:43:20 +04:00
|
|
|
static void RemoveMediaDecoder(MediaDecoder* aDecoder)
|
|
|
|
{
|
2012-11-14 23:45:13 +04:00
|
|
|
DecodersArray& decoders = Decoders();
|
|
|
|
decoders.RemoveElement(aDecoder);
|
|
|
|
if (decoders.IsEmpty()) {
|
|
|
|
sUniqueInstance = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-26 04:01:31 +04:00
|
|
|
StaticRefPtr<MediaMemoryTracker> MediaMemoryTracker::sUniqueInstance;
|
|
|
|
|
2015-05-01 05:04:59 +03:00
|
|
|
PRLogModuleInfo* gStateWatchingLog;
|
2015-07-16 21:06:49 +03:00
|
|
|
PRLogModuleInfo* gMozPromiseLog;
|
2015-05-01 05:04:59 +03:00
|
|
|
PRLogModuleInfo* gMediaTimerLog;
|
2015-05-14 05:15:05 +03:00
|
|
|
PRLogModuleInfo* gMediaSampleLog;
|
2015-05-01 05:04:59 +03:00
|
|
|
|
2015-04-07 20:59:44 +03:00
|
|
|
void
|
|
|
|
MediaDecoder::InitStatics()
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-07 20:59:44 +03:00
|
|
|
AbstractThread::InitStatics();
|
2015-06-25 02:01:15 +03:00
|
|
|
SharedThreadPool::InitStatics();
|
2015-05-01 05:04:59 +03:00
|
|
|
|
|
|
|
// Log modules.
|
|
|
|
gMediaDecoderLog = PR_NewLogModule("MediaDecoder");
|
2015-07-16 21:06:49 +03:00
|
|
|
gMozPromiseLog = PR_NewLogModule("MozPromise");
|
2015-05-01 05:04:59 +03:00
|
|
|
gStateWatchingLog = PR_NewLogModule("StateWatching");
|
|
|
|
gMediaTimerLog = PR_NewLogModule("MediaTimer");
|
2015-05-14 05:15:05 +03:00
|
|
|
gMediaSampleLog = PR_NewLogModule("MediaSample");
|
2015-04-07 20:59:44 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MediaMemoryTracker, nsIMemoryReporter)
|
2013-01-18 09:43:20 +04:00
|
|
|
|
2015-07-01 06:46:38 +03:00
|
|
|
NS_IMPL_ISUPPORTS0(MediaDecoder)
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-01-22 07:01:12 +03:00
|
|
|
void MediaDecoder::NotifyOwnerActivityChanged()
|
2013-06-10 16:22:05 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
if (!mOwner) {
|
|
|
|
NS_WARNING("MediaDecoder without a decoder owner, can't update dormant");
|
2015-01-27 11:39:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
UpdateDormantState(false /* aDormantTimeout */, false /* aActivity */);
|
|
|
|
// Start dormant timer if necessary
|
|
|
|
StartDormantTimer();
|
|
|
|
}
|
|
|
|
|
2015-07-14 03:17:07 +03:00
|
|
|
bool
|
|
|
|
MediaDecoder::IsHeuristicDormantSupported() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
#if defined(MOZ_EME) && defined(RELEASE_BUILD)
|
|
|
|
// We disallow dormant for encrypted media on Beta and Release until
|
|
|
|
// bug 1181864 is fixed.
|
|
|
|
mInfo &&
|
|
|
|
!mInfo->IsEncrypted() &&
|
|
|
|
#endif
|
|
|
|
mIsHeuristicDormantSupported;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
|
|
|
|
if (!mDecoderStateMachine ||
|
|
|
|
mPlayState == PLAY_STATE_SHUTDOWN ||
|
|
|
|
!mOwner->GetVideoFrameContainer() ||
|
2015-02-13 08:02:35 +03:00
|
|
|
(mOwner->GetMediaElement() && mOwner->GetMediaElement()->IsBeingDestroyed()) ||
|
2015-06-30 01:01:50 +03:00
|
|
|
!mDormantSupported)
|
2015-01-28 17:31:31 +03:00
|
|
|
{
|
2015-01-28 06:00:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-05 04:32:54 +03:00
|
|
|
DECODER_LOG("UpdateDormantState aTimeout=%d aActivity=%d mIsDormant=%d "
|
2015-07-14 03:17:07 +03:00
|
|
|
"ownerActive=%d ownerHidden=%d mIsHeuristicDormant=%d "
|
|
|
|
"mPlayState=%s encrypted=%s",
|
2015-03-05 04:32:54 +03:00
|
|
|
aDormantTimeout, aActivity, mIsDormant, mOwner->IsActive(),
|
2015-07-14 03:17:07 +03:00
|
|
|
mOwner->IsHidden(), mIsHeuristicDormant, PlayStateStr(),
|
|
|
|
(!mInfo ? "Unknown" : (mInfo->IsEncrypted() ? "1" : "0")));
|
2015-03-05 04:32:54 +03:00
|
|
|
|
2015-01-22 07:01:12 +03:00
|
|
|
bool prevDormant = mIsDormant;
|
|
|
|
mIsDormant = false;
|
2015-01-28 17:31:31 +03:00
|
|
|
if (!mOwner->IsActive()) {
|
2015-01-22 07:01:12 +03:00
|
|
|
mIsDormant = true;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-01-28 17:31:31 +03:00
|
|
|
if (mOwner->IsHidden()) {
|
2015-01-22 07:01:12 +03:00
|
|
|
mIsDormant = true;
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-14 03:17:07 +03:00
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
// Try to enable dormant by idle heuristic, when the owner is hidden.
|
|
|
|
bool prevHeuristicDormant = mIsHeuristicDormant;
|
|
|
|
mIsHeuristicDormant = false;
|
2015-07-14 03:17:07 +03:00
|
|
|
if (IsHeuristicDormantSupported() && mOwner->IsHidden()) {
|
2015-01-28 17:31:31 +03:00
|
|
|
if (aDormantTimeout && !aActivity &&
|
2015-03-05 04:33:40 +03:00
|
|
|
(mPlayState == PLAY_STATE_PAUSED || IsEnded())) {
|
2015-01-28 17:31:31 +03:00
|
|
|
// Enable heuristic dormant
|
|
|
|
mIsHeuristicDormant = true;
|
|
|
|
} else if(prevHeuristicDormant && !aActivity) {
|
|
|
|
// Continue heuristic dormant
|
|
|
|
mIsHeuristicDormant = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsHeuristicDormant) {
|
|
|
|
mIsDormant = true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-22 07:01:12 +03:00
|
|
|
|
|
|
|
if (prevDormant == mIsDormant) {
|
|
|
|
// No update to dormant state
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsDormant) {
|
2015-03-05 04:32:54 +03:00
|
|
|
DECODER_LOG("UpdateDormantState() entering DORMANT state");
|
2015-03-05 04:34:46 +03:00
|
|
|
// enter dormant state
|
2015-03-10 19:59:30 +03:00
|
|
|
RefPtr<nsRunnable> event =
|
2015-03-05 04:34:46 +03:00
|
|
|
NS_NewRunnableMethodWithArg<bool>(
|
|
|
|
mDecoderStateMachine,
|
|
|
|
&MediaDecoderStateMachine::SetDormant,
|
|
|
|
true);
|
2015-07-16 21:31:21 +03:00
|
|
|
mDecoderStateMachine->OwnerThread()->Dispatch(event.forget());
|
2015-03-05 04:34:46 +03:00
|
|
|
|
2015-03-05 04:33:40 +03:00
|
|
|
if (IsEnded()) {
|
|
|
|
mWasEndedWhenEnteredDormant = true;
|
|
|
|
}
|
2013-06-10 16:22:05 +04:00
|
|
|
mNextState = mPlayState;
|
|
|
|
ChangeState(PLAY_STATE_LOADING);
|
2014-12-13 04:29:24 +03:00
|
|
|
} else {
|
2015-03-05 04:32:54 +03:00
|
|
|
DECODER_LOG("UpdateDormantState() leaving DORMANT state");
|
2015-03-05 04:34:46 +03:00
|
|
|
// exit dormant state
|
|
|
|
// trigger to state machine.
|
2015-03-10 19:59:30 +03:00
|
|
|
RefPtr<nsRunnable> event =
|
2015-03-05 04:34:46 +03:00
|
|
|
NS_NewRunnableMethodWithArg<bool>(
|
|
|
|
mDecoderStateMachine,
|
|
|
|
&MediaDecoderStateMachine::SetDormant,
|
|
|
|
false);
|
2015-07-16 21:31:21 +03:00
|
|
|
mDecoderStateMachine->OwnerThread()->Dispatch(event.forget());
|
2013-06-10 16:22:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
void MediaDecoder::DormantTimerExpired(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-28 17:31:31 +03:00
|
|
|
MOZ_ASSERT(aClosure);
|
|
|
|
MediaDecoder* decoder = static_cast<MediaDecoder*>(aClosure);
|
|
|
|
ReentrantMonitorAutoEnter mon(decoder->GetReentrantMonitor());
|
|
|
|
decoder->UpdateDormantState(true /* aDormantTimeout */,
|
|
|
|
false /* aActivity */);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaDecoder::StartDormantTimer()
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-14 03:17:07 +03:00
|
|
|
if (!IsHeuristicDormantSupported()) {
|
2015-01-28 17:31:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsHeuristicDormant ||
|
|
|
|
mShuttingDown ||
|
|
|
|
!mOwner ||
|
|
|
|
!mOwner->IsHidden() ||
|
|
|
|
(mPlayState != PLAY_STATE_PAUSED &&
|
2015-03-05 04:33:40 +03:00
|
|
|
!IsEnded()))
|
2015-01-28 17:31:31 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDormantTimer) {
|
|
|
|
mDormantTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
}
|
|
|
|
mDormantTimer->InitWithFuncCallback(&MediaDecoder::DormantTimerExpired,
|
|
|
|
this,
|
|
|
|
mHeuristicDormantTimeout,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaDecoder::CancelDormantTimer()
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-28 17:31:31 +03:00
|
|
|
if (mDormantTimer) {
|
|
|
|
mDormantTimer->Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::Pause()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2014-12-13 04:29:24 +03:00
|
|
|
if (mPlayState == PLAY_STATE_LOADING ||
|
2015-03-05 04:33:40 +03:00
|
|
|
IsEnded()) {
|
2008-10-19 11:39:21 +04:00
|
|
|
mNextState = PLAY_STATE_PAUSED;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
ChangeState(PLAY_STATE_PAUSED);
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::SetVolume(double aVolume)
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-30 03:27:32 +03:00
|
|
|
mVolume = aVolume;
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream,
|
2013-01-30 08:19:03 +04:00
|
|
|
bool aFinishWhenEnded)
|
2012-04-30 07:12:42 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-28 09:16:29 +03:00
|
|
|
MOZ_ASSERT(mDecoderStateMachine, "Must be called after Load().");
|
2015-05-28 09:17:30 +03:00
|
|
|
mDecoderStateMachine->AddOutputStream(aStream, aFinishWhenEnded);
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
double MediaDecoder::GetDuration()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-06-09 21:40:03 +03:00
|
|
|
return mDuration;
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2015-06-09 22:41:24 +03:00
|
|
|
AbstractCanonical<media::NullableTimeUnit>*
|
|
|
|
MediaDecoder::CanonicalDurationOrNull()
|
2012-11-19 19:11:21 +04:00
|
|
|
{
|
2015-06-09 22:41:24 +03:00
|
|
|
MOZ_ASSERT(mDecoderStateMachine);
|
|
|
|
return mDecoderStateMachine->CanonicalDuration();
|
2012-11-19 19:11:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::SetInfinite(bool aInfinite)
|
2011-08-01 22:11:20 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-08-01 22:11:20 +04:00
|
|
|
mInfiniteStream = aInfinite;
|
2015-06-10 01:16:27 +03:00
|
|
|
DurationChanged();
|
2011-08-01 22:11:20 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
bool MediaDecoder::IsInfinite()
|
2011-08-01 22:11:20 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-08-01 22:11:20 +04:00
|
|
|
return mInfiniteStream;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::MediaDecoder() :
|
2015-05-01 02:21:14 +03:00
|
|
|
mWatchManager(this, AbstractThread::MainThread()),
|
2015-06-30 01:01:50 +03:00
|
|
|
mDormantSupported(false),
|
2009-02-05 11:02:21 +03:00
|
|
|
mDecoderPosition(0),
|
|
|
|
mPlaybackPosition(0),
|
2015-05-08 03:04:22 +03:00
|
|
|
mLogicalPosition(0.0),
|
2015-06-09 21:40:03 +03:00
|
|
|
mDuration(std::numeric_limits<double>::quiet_NaN()),
|
2012-11-30 17:17:54 +04:00
|
|
|
mMediaSeekable(true),
|
2013-07-24 13:55:23 +04:00
|
|
|
mSameOriginMedia(false),
|
2011-04-29 23:21:57 +04:00
|
|
|
mReentrantMonitor("media.decoder"),
|
2011-09-30 03:34:37 +04:00
|
|
|
mIgnoreProgressData(false),
|
2012-07-31 16:17:22 +04:00
|
|
|
mInfiniteStream(false),
|
2012-11-14 23:45:13 +04:00
|
|
|
mOwner(nullptr),
|
2014-06-22 08:43:00 +04:00
|
|
|
mPlaybackStatistics(new MediaChannelStatistics()),
|
2012-11-14 23:45:13 +04:00
|
|
|
mPinnedForSeek(false),
|
2012-11-16 07:25:26 +04:00
|
|
|
mShuttingDown(false),
|
2013-02-27 23:38:11 +04:00
|
|
|
mPausedForPlaybackRateNull(false),
|
2014-07-04 07:55:06 +04:00
|
|
|
mMinimizePreroll(false),
|
2015-01-22 07:01:12 +03:00
|
|
|
mMediaTracksConstructed(false),
|
2015-06-10 01:16:27 +03:00
|
|
|
mFiredMetadataLoaded(false),
|
2015-01-28 17:31:31 +03:00
|
|
|
mIsDormant(false),
|
2015-03-05 04:33:40 +03:00
|
|
|
mWasEndedWhenEnteredDormant(false),
|
2015-01-28 17:31:31 +03:00
|
|
|
mIsHeuristicDormantSupported(
|
|
|
|
Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false)),
|
|
|
|
mHeuristicDormantTimeout(
|
|
|
|
Preferences::GetInt("media.decoder.heuristic.dormant.timeout",
|
|
|
|
DEFAULT_HEURISTIC_DORMANT_TIMEOUT_MSECS)),
|
2015-07-17 08:00:26 +03:00
|
|
|
mIsHeuristicDormant(false),
|
|
|
|
mStateMachineIsShutdown(AbstractThread::MainThread(), true,
|
|
|
|
"MediaDecoder::mStateMachineIsShutdown (Mirror)"),
|
|
|
|
mBuffered(AbstractThread::MainThread(), TimeIntervals(),
|
|
|
|
"MediaDecoder::mBuffered (Mirror)"),
|
|
|
|
mNextFrameStatus(AbstractThread::MainThread(),
|
|
|
|
MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED,
|
|
|
|
"MediaDecoder::mNextFrameStatus (Mirror)"),
|
|
|
|
mCurrentPosition(AbstractThread::MainThread(), 0,
|
|
|
|
"MediaDecoder::mCurrentPosition (Mirror)"),
|
|
|
|
mStateMachineDuration(AbstractThread::MainThread(), NullableTimeUnit(),
|
|
|
|
"MediaDecoder::mStateMachineDuration (Mirror)"),
|
|
|
|
mVolume(AbstractThread::MainThread(), 0.0,
|
|
|
|
"MediaDecoder::mVolume (Canonical)"),
|
|
|
|
mPlaybackRate(AbstractThread::MainThread(), 1.0,
|
|
|
|
"MediaDecoder::mPlaybackRate (Canonical)"),
|
|
|
|
mPreservesPitch(AbstractThread::MainThread(), true,
|
|
|
|
"MediaDecoder::mPreservesPitch (Canonical)"),
|
|
|
|
mEstimatedDuration(AbstractThread::MainThread(), NullableTimeUnit(),
|
|
|
|
"MediaDecoder::mEstimatedDuration (Canonical)"),
|
|
|
|
mExplicitDuration(AbstractThread::MainThread(), Maybe<double>(),
|
|
|
|
"MediaDecoder::mExplicitDuration (Canonical)"),
|
|
|
|
mPlayState(AbstractThread::MainThread(), PLAY_STATE_LOADING,
|
|
|
|
"MediaDecoder::mPlayState (Canonical)"),
|
|
|
|
mNextState(AbstractThread::MainThread(), PLAY_STATE_PAUSED,
|
|
|
|
"MediaDecoder::mNextState (Canonical)"),
|
|
|
|
mLogicallySeeking(AbstractThread::MainThread(), false,
|
|
|
|
"MediaDecoder::mLogicallySeeking (Canonical)")
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-14 23:46:40 +04:00
|
|
|
MOZ_COUNT_CTOR(MediaDecoder);
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-18 09:43:20 +04:00
|
|
|
MediaMemoryTracker::AddMediaDecoder(this);
|
2015-04-01 04:44:36 +03:00
|
|
|
|
2014-04-10 21:39:20 +04:00
|
|
|
mAudioChannel = AudioChannelService::GetDefaultAudioChannel();
|
2015-03-19 05:01:12 +03:00
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
//
|
2015-04-25 06:35:06 +03:00
|
|
|
// Initialize watchers.
|
2015-05-08 03:04:22 +03:00
|
|
|
//
|
|
|
|
|
2015-06-10 01:31:46 +03:00
|
|
|
// mDuration
|
|
|
|
mWatchManager.Watch(mStateMachineDuration, &MediaDecoder::DurationChanged);
|
|
|
|
|
2015-06-30 00:27:16 +03:00
|
|
|
// mStateMachineIsShutdown
|
|
|
|
mWatchManager.Watch(mStateMachineIsShutdown, &MediaDecoder::ShutdownBitChanged);
|
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
// readyState
|
2015-04-29 05:02:31 +03:00
|
|
|
mWatchManager.Watch(mPlayState, &MediaDecoder::UpdateReadyState);
|
|
|
|
mWatchManager.Watch(mNextFrameStatus, &MediaDecoder::UpdateReadyState);
|
2015-05-08 03:04:22 +03:00
|
|
|
|
|
|
|
// mLogicalPosition
|
|
|
|
mWatchManager.Watch(mCurrentPosition, &MediaDecoder::UpdateLogicalPosition);
|
|
|
|
mWatchManager.Watch(mPlayState, &MediaDecoder::UpdateLogicalPosition);
|
|
|
|
mWatchManager.Watch(mLogicallySeeking, &MediaDecoder::UpdateLogicalPosition);
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
bool MediaDecoder::Init(MediaDecoderOwner* aOwner)
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-14 23:45:13 +04:00
|
|
|
mOwner = aOwner;
|
|
|
|
mVideoFrameContainer = aOwner->GetVideoFrameContainer();
|
2013-12-18 07:59:11 +04:00
|
|
|
MediaShutdownManager::Instance().Register(this);
|
2011-09-30 03:34:37 +04:00
|
|
|
return true;
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::Shutdown()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-07 02:33:02 +04:00
|
|
|
|
2009-05-19 03:08:08 +04:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
mShuttingDown = true;
|
2008-12-09 03:43:56 +03:00
|
|
|
|
2009-05-19 03:08:08 +04: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 12:53:44 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2015-03-25 01:12:08 +03:00
|
|
|
mDecoderStateMachine->DispatchShutdown();
|
2009-05-19 03:08:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Force any outstanding seek and byterange requests to complete
|
|
|
|
// to prevent shutdown from deadlocking.
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Close();
|
2009-09-22 04:03:42 +04:00
|
|
|
}
|
2009-05-19 03:08:08 +04:00
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
CancelDormantTimer();
|
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
ChangeState(PLAY_STATE_SHUTDOWN);
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
mOwner = nullptr;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2013-12-18 07:59:11 +04:00
|
|
|
MediaShutdownManager::Instance().Unregister(this);
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::~MediaDecoder()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-18 09:43:20 +04:00
|
|
|
MediaMemoryTracker::RemoveMediaDecoder(this);
|
2010-08-05 11:40:35 +04:00
|
|
|
UnpinForSeek();
|
2012-11-14 23:46:40 +04:00
|
|
|
MOZ_COUNT_DTOR(MediaDecoder);
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
nsresult MediaDecoder::OpenResource(nsIStreamListener** aStreamListener)
|
2008-09-07 03:47:28 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-09-15 06:30:44 +04:00
|
|
|
if (aStreamListener) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aStreamListener = nullptr;
|
2009-09-15 06:30:44 +04:00
|
|
|
}
|
2009-09-15 06:28:08 +04:00
|
|
|
|
2009-04-01 04:52:56 +04: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
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2009-09-11 05:44:21 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
nsresult rv = mResource->Open(aStreamListener);
|
2014-08-21 04:13:00 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
2012-09-18 00:45:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
nsresult MediaDecoder::Load(nsIStreamListener** aStreamListener,
|
|
|
|
MediaDecoder* aCloneDonor)
|
2012-09-18 00:45:38 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-20 09:29:10 +03:00
|
|
|
MOZ_ASSERT(mResource, "Can't load without a MediaResource");
|
2012-09-18 00:45:38 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
nsresult rv = OpenResource(aStreamListener);
|
2012-09-18 00:45:38 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-04-02 20:49:01 +03:00
|
|
|
SetStateMachine(CreateStateMachine());
|
|
|
|
NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE);
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
return InitializeStateMachine(aCloneDonor);
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
nsresult MediaDecoder::InitializeStateMachine(MediaDecoder* aCloneDonor)
|
2012-09-18 00:45:38 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-13 23:42:45 +04:00
|
|
|
NS_ASSERTION(mDecoderStateMachine, "Cannot initialize null state machine!");
|
2012-09-18 00:45:38 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder* cloneDonor = static_cast<MediaDecoder*>(aCloneDonor);
|
2014-08-21 04:13:00 +04:00
|
|
|
nsresult rv = mDecoderStateMachine->Init(
|
|
|
|
cloneDonor ? cloneDonor->mDecoderStateMachine : nullptr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-08-05 18:55:02 +04:00
|
|
|
|
|
|
|
// If some parameters got set before the state machine got created,
|
|
|
|
// set them now
|
|
|
|
SetStateMachineParameters();
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-05-06 04:17:51 +03:00
|
|
|
return ScheduleStateMachine();
|
2010-08-25 12:45:45 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 18:55:02 +04:00
|
|
|
void MediaDecoder::SetStateMachineParameters()
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-08-05 18:55:02 +04:00
|
|
|
if (mMinimizePreroll) {
|
2015-05-02 02:34:57 +03:00
|
|
|
mDecoderStateMachine->DispatchMinimizePrerollUntilPlaybackStarts();
|
2014-08-05 18:55:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 07:43:57 +04:00
|
|
|
void MediaDecoder::SetMinimizePrerollUntilPlaybackStarts()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-01 00:39:41 +03:00
|
|
|
DECODER_LOG("SetMinimizePrerollUntilPlaybackStarts()");
|
2014-04-01 07:43:57 +04:00
|
|
|
mMinimizePreroll = true;
|
2015-05-02 02:34:57 +03:00
|
|
|
|
|
|
|
// This needs to be called before we init the state machine, otherwise it will
|
|
|
|
// have no effect.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mDecoderStateMachine);
|
2014-04-01 07:43:57 +04:00
|
|
|
}
|
|
|
|
|
2015-05-06 04:17:51 +03:00
|
|
|
nsresult MediaDecoder::ScheduleStateMachine()
|
2010-08-25 12:45:45 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-08-25 12:45:45 +04:00
|
|
|
NS_ASSERTION(mDecoderStateMachine,
|
|
|
|
"Must have state machine to start state machine thread");
|
2012-01-19 22:29:12 +04:00
|
|
|
NS_ENSURE_STATE(mDecoderStateMachine);
|
2011-07-12 07:39:32 +04:00
|
|
|
|
|
|
|
if (mShuttingDown)
|
|
|
|
return NS_OK;
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2015-05-06 04:17:51 +03:00
|
|
|
mDecoderStateMachine->ScheduleStateMachineCrossThread();
|
2015-03-10 19:59:30 +03:00
|
|
|
return NS_OK;
|
2008-09-07 03:47:28 +04:00
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
nsresult MediaDecoder::Play()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2015-01-28 17:31:31 +03:00
|
|
|
UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine.");
|
2014-09-01 08:52:39 +04:00
|
|
|
if (mPausedForPlaybackRateNull) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-05-06 04:17:51 +03:00
|
|
|
ScheduleStateMachine();
|
2015-03-05 04:33:40 +03:00
|
|
|
if (IsEnded()) {
|
|
|
|
return Seek(0, SeekTarget::PrevSyncPoint);
|
2015-05-07 18:19:46 +03:00
|
|
|
} else if (mPlayState == PLAY_STATE_LOADING) {
|
2008-10-19 11:39:21 +04:00
|
|
|
mNextState = PLAY_STATE_PLAYING;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChangeState(PLAY_STATE_PLAYING);
|
|
|
|
return NS_OK;
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
nsresult MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType)
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2015-05-07 18:19:46 +03:00
|
|
|
NS_ENSURE_TRUE(!mShuttingDown, NS_ERROR_FAILURE);
|
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aTime >= 0.0, "Cannot seek to a negative value.");
|
2011-08-09 14:10:48 +04:00
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
int64_t timeUsecs = 0;
|
|
|
|
nsresult rv = SecondsToUsecs(aTime, timeUsecs);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-03-28 16:31:29 +04:00
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
mLogicalPosition = aTime;
|
2015-03-05 04:33:40 +03:00
|
|
|
mWasEndedWhenEnteredDormant = false;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-05-07 18:19:46 +03:00
|
|
|
mLogicallySeeking = true;
|
|
|
|
SeekTarget target = SeekTarget(timeUsecs, aSeekType);
|
|
|
|
CallSeek(target);
|
|
|
|
|
|
|
|
if (mPlayState == PLAY_STATE_ENDED) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool paused = false;
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
|
|
|
paused = mOwner->GetPaused();
|
2009-04-01 05:07:10 +04:00
|
|
|
}
|
2010-08-05 11:40:35 +04:00
|
|
|
PinForSeek();
|
2015-05-07 18:19:46 +03:00
|
|
|
ChangeState(paused ? PLAY_STATE_PAUSED : PLAY_STATE_PLAYING);
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2015-05-07 18:19:46 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-05-07 18:19:46 +03:00
|
|
|
void MediaDecoder::CallSeek(const SeekTarget& aTarget)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-07 18:19:46 +03:00
|
|
|
mSeekRequest.DisconnectIfExists();
|
2015-07-16 21:31:21 +03:00
|
|
|
mSeekRequest.Begin(ProxyMediaCall(mDecoderStateMachine->OwnerThread(),
|
2015-05-07 18:19:46 +03:00
|
|
|
mDecoderStateMachine.get(), __func__,
|
|
|
|
&MediaDecoderStateMachine::Seek, aTarget)
|
2015-05-22 22:28:20 +03:00
|
|
|
->Then(AbstractThread::MainThread(), __func__, this,
|
|
|
|
&MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected));
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
double MediaDecoder::GetCurrentTime()
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-08 03:04:22 +03:00
|
|
|
return mLogicalPosition;
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
already_AddRefed<nsIPrincipal> MediaDecoder::GetCurrentPrincipal()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-07-30 18:20:58 +04:00
|
|
|
return mResource ? mResource->GetCurrentPrincipal() : nullptr;
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 17:17:54 +04:00
|
|
|
void MediaDecoder::QueueMetadata(int64_t aPublishTime,
|
2014-11-06 11:17:05 +03:00
|
|
|
nsAutoPtr<MediaInfo> aInfo,
|
|
|
|
nsAutoPtr<MetadataTags> aTags)
|
2012-11-30 17:17:54 +04:00
|
|
|
{
|
2015-03-18 01:33:24 +03:00
|
|
|
MOZ_ASSERT(OnDecodeTaskQueue());
|
2012-11-30 17:17:54 +04:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2014-07-04 07:54:54 +04:00
|
|
|
mDecoderStateMachine->QueueMetadata(aPublishTime, aInfo, aTags);
|
2012-11-30 17:17:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-29 06:34:28 +04:00
|
|
|
bool
|
2014-11-12 07:50:20 +03:00
|
|
|
MediaDecoder::IsExpectingMoreData()
|
2013-01-29 06:34:28 +04:00
|
|
|
{
|
2013-09-04 15:13:06 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2014-11-12 07:50:20 +03:00
|
|
|
|
|
|
|
// If there's no resource, we're probably just getting set up.
|
|
|
|
if (!mResource) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we've downloaded anything, we're not waiting for anything.
|
|
|
|
if (mResource->IsDataCachedToEndOfResource(mDecoderPosition)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we should be getting data unless the stream is suspended.
|
|
|
|
return !mResource->IsSuspended();
|
2013-01-29 06:34:28 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 11:17:05 +03:00
|
|
|
void MediaDecoder::MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
|
2015-01-16 18:56:19 +03:00
|
|
|
nsAutoPtr<MetadataTags> aTags,
|
2015-03-05 04:33:40 +03:00
|
|
|
MediaDecoderEventVisibility aEventVisibility)
|
2010-08-25 17:10:00 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-06 11:17:05 +03:00
|
|
|
|
2010-08-25 17:10:00 +04:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:13:00 +04:00
|
|
|
DECODER_LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d",
|
|
|
|
aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
|
|
|
|
aInfo->HasAudio(), aInfo->HasVideo());
|
|
|
|
|
2014-11-06 11:17:05 +03:00
|
|
|
mInfo = aInfo.forget();
|
2014-07-04 07:55:06 +04:00
|
|
|
ConstructMediaTracks();
|
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
2009-01-28 12:33:37 +03:00
|
|
|
// Make sure the element and the frame (if any) are told about
|
|
|
|
// our new size.
|
|
|
|
Invalidate();
|
2015-03-05 04:33:40 +03:00
|
|
|
if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
|
2015-06-10 01:16:27 +03:00
|
|
|
mFiredMetadataLoaded = true;
|
2015-01-16 18:56:19 +03:00
|
|
|
mOwner->MetadataLoaded(mInfo, nsAutoPtr<const MetadataTags>(aTags.forget()));
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
2014-11-06 12:52:44 +03:00
|
|
|
}
|
|
|
|
|
2015-03-05 04:32:54 +03:00
|
|
|
const char*
|
|
|
|
MediaDecoder::PlayStateStr()
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-03-05 04:32:54 +03:00
|
|
|
switch (mPlayState) {
|
|
|
|
case PLAY_STATE_START: return "PLAY_STATE_START";
|
|
|
|
case PLAY_STATE_LOADING: return "PLAY_STATE_LOADING";
|
|
|
|
case PLAY_STATE_PAUSED: return "PLAY_STATE_PAUSED";
|
|
|
|
case PLAY_STATE_PLAYING: return "PLAY_STATE_PLAYING";
|
|
|
|
case PLAY_STATE_ENDED: return "PLAY_STATE_ENDED";
|
|
|
|
case PLAY_STATE_SHUTDOWN: return "PLAY_STATE_SHUTDOWN";
|
|
|
|
default: return "INVALID_PLAY_STATE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 18:56:19 +03:00
|
|
|
void MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
|
2015-03-05 04:33:40 +03:00
|
|
|
MediaDecoderEventVisibility aEventVisibility)
|
2014-11-06 12:52:44 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-06 11:17:05 +03:00
|
|
|
|
2014-11-06 12:52:44 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-05 04:32:54 +03:00
|
|
|
DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d",
|
2014-11-06 12:52:44 +03:00
|
|
|
aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
|
2015-03-05 04:32:54 +03:00
|
|
|
aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant);
|
2014-11-06 12:52:44 +03:00
|
|
|
|
2014-11-06 11:17:05 +03:00
|
|
|
mInfo = aInfo.forget();
|
2009-01-15 23:26:51 +03:00
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
2014-11-06 12:56:56 +03:00
|
|
|
Invalidate();
|
2015-03-05 04:33:40 +03:00
|
|
|
if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
|
2015-01-16 18:56:19 +03:00
|
|
|
mOwner->FirstFrameLoaded();
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2011-11-30 09:05:49 +04:00
|
|
|
// This can run cache callbacks.
|
2012-02-15 08:35:01 +04:00
|
|
|
mResource->EnsureCacheUpToDate();
|
2011-11-30 09:05:49 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// The element can run javascript via events
|
2010-04-02 07:03:07 +04:00
|
|
|
// before reaching here, so only change the
|
2008-10-19 11:39:21 +04:00
|
|
|
// state if we're still set to the original
|
|
|
|
// loading state.
|
2015-03-05 04:32:54 +03:00
|
|
|
if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) {
|
2015-05-07 18:19:46 +03:00
|
|
|
ChangeState(mNextState);
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2009-01-15 23:26:51 +03:00
|
|
|
|
2011-11-30 09:05:49 +04:00
|
|
|
// Run NotifySuspendedStatusChanged now to give us a chance to notice
|
|
|
|
// that autoplay should run.
|
|
|
|
NotifySuspendedStatusChanged();
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 07:08:10 +04:00
|
|
|
void MediaDecoder::ResetConnectionState()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mOwner) {
|
|
|
|
// Notify the media element that connection gets lost.
|
|
|
|
mOwner->ResetConnectionState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we have notified the media element the connection
|
|
|
|
// lost event, the decoder will be reloaded when user tries
|
|
|
|
// to play the Rtsp streaming next time.
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::NetworkError()
|
2008-11-06 23:53:20 +03:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-05-19 03:08:08 +04:00
|
|
|
if (mShuttingDown)
|
2008-12-09 03:43:56 +03:00
|
|
|
return;
|
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner)
|
|
|
|
mOwner->NetworkError();
|
2009-05-19 03:08:08 +04:00
|
|
|
|
|
|
|
Shutdown();
|
2008-11-06 23:53:20 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::DecodeError()
|
2009-09-22 04:08:13 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-09-22 04:08:13 +04:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner)
|
|
|
|
mOwner->DecodeError();
|
2009-09-22 04:08:13 +04:00
|
|
|
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
void MediaDecoder::UpdateSameOriginStatus(bool aSameOrigin)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-07-24 13:55:23 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
|
|
|
mSameOriginMedia = aSameOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaDecoder::IsSameOriginMedia()
|
|
|
|
{
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return mSameOriginMedia;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
bool MediaDecoder::IsSeeking() const
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-07 18:19:46 +03:00
|
|
|
return mLogicallySeeking;
|
2008-12-14 21:02:54 +03:00
|
|
|
}
|
|
|
|
|
2015-03-05 04:33:40 +03:00
|
|
|
bool MediaDecoder::IsEndedOrShutdown() const
|
2008-12-14 21:02:54 +03:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-03-05 04:33:40 +03:00
|
|
|
return IsEnded() || mPlayState == PLAY_STATE_SHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaDecoder::IsEnded() const
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-03-05 04:33:40 +03:00
|
|
|
return mPlayState == PLAY_STATE_ENDED ||
|
|
|
|
(mWasEndedWhenEnteredDormant && (mPlayState != PLAY_STATE_SHUTDOWN));
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::PlaybackEnded()
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-07-31 16:17:22 +04:00
|
|
|
|
2014-09-02 22:07:00 +04:00
|
|
|
if (mShuttingDown ||
|
2015-05-07 18:19:46 +03:00
|
|
|
mLogicallySeeking ||
|
2014-12-23 10:04:20 +03:00
|
|
|
mPlayState == PLAY_STATE_LOADING) {
|
2008-12-09 03:43:56 +03:00
|
|
|
return;
|
2014-09-02 22:07:00 +04:00
|
|
|
}
|
2008-12-09 03:43:56 +03:00
|
|
|
|
2009-04-01 05:07:10 +04:00
|
|
|
ChangeState(PLAY_STATE_ENDED);
|
2013-10-02 07:05:34 +04:00
|
|
|
InvalidateWithFlags(VideoFrameContainer::INVALIDATE_FORCE);
|
2009-04-01 05:07:10 +04:00
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
|
|
|
mOwner->PlaybackEnded();
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
2011-08-01 22:11:20 +04:00
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
// This must be called after |mOwner->PlaybackEnded()| call above, in order
|
2011-08-01 22:11:20 +04:00
|
|
|
// to fire the required durationchange.
|
|
|
|
if (IsInfinite()) {
|
2011-09-30 03:34:37 +04:00
|
|
|
SetInfinite(false);
|
2011-08-01 22:11:20 +04:00
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::Statistics
|
|
|
|
MediaDecoder::GetStatistics()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2009-02-05 11:02:21 +03:00
|
|
|
Statistics result;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mResource) {
|
2012-11-07 02:33:02 +04:00
|
|
|
result.mDownloadRate =
|
2012-02-15 08:35:01 +04:00
|
|
|
mResource->GetDownloadRate(&result.mDownloadRateReliable);
|
2009-04-01 04:52:56 +04:00
|
|
|
result.mDownloadPosition =
|
2012-02-15 08:35:01 +04:00
|
|
|
mResource->GetCachedDataEnd(mDecoderPosition);
|
|
|
|
result.mTotalBytes = mResource->GetLength();
|
2009-04-01 04:52:56 +04:00
|
|
|
result.mPlaybackRate = ComputePlaybackRate(&result.mPlaybackRateReliable);
|
|
|
|
result.mDecoderPosition = mDecoderPosition;
|
|
|
|
result.mPlaybackPosition = mPlaybackPosition;
|
2010-04-27 12:53:44 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-04-01 04:52:56 +04:00
|
|
|
result.mDownloadRate = 0;
|
2011-09-30 03:34:37 +04:00
|
|
|
result.mDownloadRateReliable = true;
|
2009-04-01 04:52:56 +04:00
|
|
|
result.mPlaybackRate = 0;
|
2011-09-30 03:34:37 +04:00
|
|
|
result.mPlaybackRateReliable = true;
|
2009-04-01 04:52:56 +04:00
|
|
|
result.mDecoderPosition = 0;
|
|
|
|
result.mPlaybackPosition = 0;
|
|
|
|
result.mDownloadPosition = 0;
|
|
|
|
result.mTotalBytes = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-05 11:02:21 +03:00
|
|
|
return result;
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
double MediaDecoder::ComputePlaybackRate(bool* aReliable)
|
2009-02-05 11:02:21 +03:00
|
|
|
{
|
2011-04-29 23:21:57 +04:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2015-03-18 01:33:24 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread() || OnStateMachineTaskQueue() || OnDecodeTaskQueue());
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t length = mResource ? mResource->GetLength() : -1;
|
2015-06-09 21:40:03 +03:00
|
|
|
if (!IsNaN(mDuration) && !mozilla::IsInfinite<double>(mDuration) && length >= 0) {
|
2011-09-30 03:34:37 +04:00
|
|
|
*aReliable = true;
|
2015-07-02 02:57:25 +03:00
|
|
|
return length / mDuration;
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
2014-06-22 08:43:00 +04:00
|
|
|
return mPlaybackStatistics->GetRateAtLastStop(aReliable);
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
2009-02-05 11:02:21 +03:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::UpdatePlaybackRate()
|
2009-04-01 04:52:56 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-04-29 23:21:57 +04:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2012-02-15 08:35:01 +04:00
|
|
|
if (!mResource)
|
2009-04-01 04:52:56 +04:00
|
|
|
return;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool reliable;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rate = uint32_t(ComputePlaybackRate(&reliable));
|
2009-05-19 03:05:13 +04:00
|
|
|
if (reliable) {
|
|
|
|
// Avoid passing a zero rate
|
2013-01-15 16:22:03 +04:00
|
|
|
rate = std::max(rate, 1u);
|
2010-04-27 12:53:44 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-04-01 04:52:56 +04:00
|
|
|
// Set a minimum rate of 10,000 bytes per second ... sometimes we just
|
|
|
|
// don't have good data
|
2013-01-15 16:22:03 +04:00
|
|
|
rate = std::max(rate, 10000u);
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
2012-02-15 08:35:01 +04:00
|
|
|
mResource->SetPlaybackRate(rate);
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::NotifySuspendedStatusChanged()
|
2009-02-05 11:02:21 +03:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-24 11:25:00 +04:00
|
|
|
if (mResource && mOwner) {
|
|
|
|
bool suspended = mResource->IsSuspendedByCache();
|
2012-11-09 09:52:53 +04:00
|
|
|
mOwner->NotifySuspendedByCache(suspended);
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::NotifyBytesDownloaded()
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-13 23:42:45 +04:00
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
|
|
|
UpdatePlaybackRate();
|
|
|
|
}
|
2014-11-28 02:17:18 +03:00
|
|
|
if (mOwner) {
|
|
|
|
mOwner->DownloadProgressed();
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::NotifyDownloadEnded(nsresult aStatus)
|
2008-07-30 10:50:14 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2014-08-21 04:13:00 +04:00
|
|
|
DECODER_LOG("NotifyDownloadEnded, status=%x", aStatus);
|
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
if (aStatus == NS_BINDING_ABORTED) {
|
|
|
|
// Download has been cancelled by user.
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
|
|
|
mOwner->LoadAborted();
|
2011-09-23 08:27:18 +04:00
|
|
|
}
|
2008-12-09 03:43:56 +03:00
|
|
|
return;
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
2008-12-09 03:43:56 +03:00
|
|
|
|
2009-02-05 11:02:21 +03:00
|
|
|
{
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2009-04-01 04:52:56 +04:00
|
|
|
UpdatePlaybackRate();
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
2009-02-05 11:02:21 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
2014-09-24 11:25:00 +04:00
|
|
|
// A final progress event will be fired by the MediaResource calling
|
|
|
|
// DownloadSuspended on the element.
|
2014-09-24 11:25:00 +04:00
|
|
|
// Also NotifySuspendedStatusChanged() will be called to update readyState
|
|
|
|
// if download ended with success.
|
2014-09-24 11:25:00 +04:00
|
|
|
} else if (aStatus != NS_BASE_STREAM_CLOSED) {
|
2009-02-05 11:02:21 +03:00
|
|
|
NetworkError();
|
|
|
|
}
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::NotifyPrincipalChanged()
|
2012-04-30 07:12:42 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
|
|
|
mOwner->NotifyDecoderPrincipalChanged();
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:37:23 +04:00
|
|
|
void MediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset)
|
2009-02-05 11:02:21 +03:00
|
|
|
{
|
2014-05-12 03:20:00 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2014-05-12 03:20:00 +04:00
|
|
|
MOZ_ASSERT(mDecoderStateMachine);
|
2013-09-18 07:37:23 +04:00
|
|
|
if (mIgnoreProgressData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aOffset >= mDecoderPosition) {
|
2014-06-22 08:43:00 +04:00
|
|
|
mPlaybackStatistics->AddBytes(aBytes);
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
2013-09-18 07:37:23 +04:00
|
|
|
mDecoderPosition = aOffset + aBytes;
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 00:00:41 +03:00
|
|
|
void MediaDecoder::OnSeekResolved(SeekResolveValue aVal)
|
2009-05-31 14:02:17 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-16 00:00:41 +03:00
|
|
|
mSeekRequest.Complete();
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2009-05-31 14:02:17 +04:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool fireEnded = false;
|
2009-05-31 14:02:17 +04:00
|
|
|
{
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2009-05-31 14:02:17 +04:00
|
|
|
|
|
|
|
// An additional seek was requested while the current seek was
|
|
|
|
// in operation.
|
2015-05-07 18:19:46 +03:00
|
|
|
UnpinForSeek();
|
|
|
|
fireEnded = aVal.mAtEnd;
|
|
|
|
if (aVal.mAtEnd) {
|
|
|
|
ChangeState(PLAY_STATE_ENDED);
|
2009-05-31 14:02:17 +04:00
|
|
|
}
|
2015-05-07 18:19:46 +03:00
|
|
|
mLogicallySeeking = false;
|
2009-05-31 14:02:17 +04:00
|
|
|
}
|
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
UpdateLogicalPosition(aVal.mEventVisibility);
|
2014-04-01 07:39:04 +04:00
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
2015-05-07 18:19:46 +03:00
|
|
|
if (aVal.mEventVisibility != MediaDecoderEventVisibility::Suppressed) {
|
2012-11-09 09:52:53 +04:00
|
|
|
mOwner->SeekCompleted();
|
2011-02-01 05:57:13 +03:00
|
|
|
if (fireEnded) {
|
2012-11-09 09:52:53 +04:00
|
|
|
mOwner->PlaybackEnded();
|
2011-02-01 05:57:13 +03:00
|
|
|
}
|
2009-05-31 14:02:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 04:33:40 +03:00
|
|
|
void MediaDecoder::SeekingStarted(MediaDecoderEventVisibility aEventVisibility)
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2008-12-09 03:43:56 +03:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-11-09 09:52:53 +04:00
|
|
|
if (mOwner) {
|
2015-03-05 04:33:40 +03:00
|
|
|
if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
|
|
|
|
mOwner->SeekStarted();
|
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::ChangeState(PlayState aState)
|
2008-10-19 11:39:21 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
if (mNextState == aState) {
|
|
|
|
mNextState = PLAY_STATE_PAUSED;
|
|
|
|
}
|
|
|
|
|
2014-12-13 04:29:24 +03:00
|
|
|
if (mPlayState == PLAY_STATE_SHUTDOWN) {
|
2012-09-18 00:45:38 +04:00
|
|
|
GetReentrantMonitor().NotifyAll();
|
2008-10-19 11:39:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:13:00 +04:00
|
|
|
DECODER_LOG("ChangeState %s => %s",
|
2015-06-30 10:58:05 +03:00
|
|
|
ToPlayStateStr(mPlayState), ToPlayStateStr(aState));
|
2008-10-19 11:39:21 +04:00
|
|
|
mPlayState = aState;
|
2013-09-23 13:53:36 +04:00
|
|
|
|
2014-07-04 07:55:06 +04:00
|
|
|
if (mPlayState == PLAY_STATE_PLAYING) {
|
|
|
|
ConstructMediaTracks();
|
2015-03-05 04:33:40 +03:00
|
|
|
} else if (IsEnded()) {
|
2014-07-04 07:55:06 +04:00
|
|
|
RemoveMediaTracks();
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:17:51 +03:00
|
|
|
ScheduleStateMachine();
|
2013-06-10 16:22:05 +04:00
|
|
|
|
2015-01-28 17:31:31 +03:00
|
|
|
CancelDormantTimer();
|
|
|
|
// Start dormant timer if necessary
|
|
|
|
StartDormantTimer();
|
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
GetReentrantMonitor().NotifyAll();
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2008-10-23 12:02:18 +04:00
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
void MediaDecoder::UpdateLogicalPosition(MediaDecoderEventVisibility aEventVisibility)
|
2008-10-23 12:02:18 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2008-12-09 03:43:56 +03:00
|
|
|
if (mShuttingDown)
|
|
|
|
return;
|
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
// Per spec, offical position remains stable during pause and seek.
|
|
|
|
if (mPlayState == PLAY_STATE_PAUSED || IsSeeking()) {
|
|
|
|
return;
|
2008-10-23 12:02:18 +04:00
|
|
|
}
|
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
double currentPosition = static_cast<double>(CurrentPosition()) / static_cast<double>(USECS_PER_S);
|
|
|
|
bool logicalPositionChanged = mLogicalPosition != currentPosition;
|
|
|
|
mLogicalPosition = currentPosition;
|
|
|
|
|
2008-10-23 12:02:18 +04: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();
|
|
|
|
|
2015-05-08 03:04:22 +03:00
|
|
|
if (mOwner && logicalPositionChanged &&
|
|
|
|
aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
|
2010-09-10 09:49:26 +04:00
|
|
|
FireTimeUpdate();
|
2008-10-23 12:02:18 +04:00
|
|
|
}
|
|
|
|
}
|
2008-11-10 04:38:02 +03:00
|
|
|
|
2015-06-10 01:16:27 +03:00
|
|
|
void MediaDecoder::DurationChanged()
|
2010-04-02 07:03:07 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-09-18 00:45:38 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2015-06-10 01:16:27 +03:00
|
|
|
|
2015-06-09 21:40:03 +03:00
|
|
|
double oldDuration = mDuration;
|
2015-06-10 01:16:27 +03:00
|
|
|
if (IsInfinite()) {
|
|
|
|
mDuration = std::numeric_limits<double>::infinity();
|
|
|
|
} else if (mExplicitDuration.Ref().isSome()) {
|
|
|
|
mDuration = mExplicitDuration.Ref().ref();
|
|
|
|
} else if (mStateMachineDuration.Ref().isSome()) {
|
|
|
|
mDuration = mStateMachineDuration.Ref().ref().ToSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDuration == oldDuration || IsNaN(mDuration)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DECODER_LOG("Duration changed to %f", mDuration);
|
|
|
|
|
2010-07-20 05:29:27 +04:00
|
|
|
// Duration has changed so we should recompute playback rate
|
|
|
|
UpdatePlaybackRate();
|
|
|
|
|
2015-06-10 01:16:27 +03:00
|
|
|
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=28822 for a discussion
|
|
|
|
// of whether we should fire durationchange on explicit infinity.
|
|
|
|
if (mOwner && mFiredMetadataLoaded &&
|
|
|
|
(!mozilla::IsInfinite<double>(mDuration) || mExplicitDuration.Ref().isSome())) {
|
2015-01-19 07:11:43 +03:00
|
|
|
mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
|
2010-04-02 07:03:07 +04:00
|
|
|
}
|
2015-06-04 21:08:48 +03:00
|
|
|
|
2015-06-10 01:16:27 +03:00
|
|
|
if (CurrentPosition() > TimeUnit::FromSeconds(mDuration).ToMicroseconds()) {
|
|
|
|
Seek(mDuration, SeekTarget::Accurate);
|
2015-06-04 21:08:48 +03:00
|
|
|
}
|
2010-04-02 07:03:07 +04:00
|
|
|
}
|
|
|
|
|
2013-09-10 04:45:33 +04:00
|
|
|
void MediaDecoder::UpdateEstimatedMediaDuration(int64_t aDuration)
|
2013-05-03 11:48:37 +04:00
|
|
|
{
|
2015-06-17 02:11:06 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-10 04:45:33 +04:00
|
|
|
if (mPlayState <= PLAY_STATE_LOADING) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-03 01:29:50 +03:00
|
|
|
|
|
|
|
// The duration is only changed if its significantly different than the
|
|
|
|
// the current estimate, as the incoming duration is an estimate and so
|
|
|
|
// often is unstable as more data is read and the estimate is updated.
|
|
|
|
// Can result in a durationchangeevent. aDuration is in microseconds.
|
|
|
|
if (mEstimatedDuration.Ref().isSome() &&
|
|
|
|
mozilla::Abs(mEstimatedDuration.Ref().ref().ToMicroseconds() - aDuration) < ESTIMATED_DURATION_FUZZ_FACTOR_USECS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEstimatedDuration = Some(TimeUnit::FromMicroseconds(aDuration));
|
2013-05-03 11:48:37 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 17:17:54 +04:00
|
|
|
void MediaDecoder::SetMediaSeekable(bool aMediaSeekable) {
|
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
|
|
|
mMediaSeekable = aMediaSeekable;
|
|
|
|
}
|
|
|
|
|
2014-06-23 14:08:34 +04:00
|
|
|
bool
|
|
|
|
MediaDecoder::IsTransportSeekable()
|
2008-11-10 04:38:02 +03:00
|
|
|
{
|
2013-03-01 22:55:01 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2014-06-23 14:08:34 +04:00
|
|
|
return GetResource()->IsTransportSeekable();
|
2008-11-10 04:38:02 +03:00
|
|
|
}
|
2009-01-07 06:33:42 +03:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
bool MediaDecoder::IsMediaSeekable()
|
|
|
|
{
|
2012-12-13 23:42:45 +04:00
|
|
|
NS_ENSURE_TRUE(GetStateMachine(), false);
|
2012-11-30 17:17:54 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
|
|
|
return mMediaSeekable;
|
2012-11-19 19:11:21 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals MediaDecoder::GetSeekable()
|
2011-08-09 14:10:48 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-30 17:17:54 +04:00
|
|
|
// We can seek in buffered range if the media is seekable. Also, we can seek
|
|
|
|
// in unbuffered ranges if the transport level is seekable (local file or the
|
|
|
|
// server supports range requests, etc.)
|
|
|
|
if (!IsMediaSeekable()) {
|
2015-05-18 09:15:47 +03:00
|
|
|
return media::TimeIntervals();
|
2012-12-07 17:30:03 +04:00
|
|
|
} else if (!IsTransportSeekable()) {
|
2015-05-18 09:15:47 +03:00
|
|
|
return GetBuffered();
|
2012-11-30 17:17:54 +04:00
|
|
|
} else {
|
2015-05-18 09:15:47 +03:00
|
|
|
return media::TimeIntervals(
|
|
|
|
media::TimeInterval(media::TimeUnit::FromMicroseconds(0),
|
|
|
|
IsInfinite() ?
|
|
|
|
media::TimeUnit::FromInfinity() :
|
|
|
|
media::TimeUnit::FromSeconds(GetDuration())));
|
2011-08-09 14:10:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
void MediaDecoder::SetFragmentEndTime(double aTime)
|
2011-08-25 03:42:23 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-08-25 03:42:23 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2015-06-29 22:00:03 +03:00
|
|
|
mDecoderStateMachine->DispatchSetFragmentEndTime(static_cast<int64_t>(aTime * USECS_PER_S));
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::Suspend()
|
2009-01-22 02:54:40 +03:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Suspend(true);
|
2009-01-22 02:54:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::Resume(bool aForceBuffering)
|
2009-01-22 02:54:40 +03:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mResource) {
|
|
|
|
mResource->Resume();
|
2009-01-22 02:54:40 +03:00
|
|
|
}
|
2010-07-23 02:48:32 +04:00
|
|
|
if (aForceBuffering) {
|
2012-01-19 22:29:12 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2015-03-25 03:12:54 +03:00
|
|
|
mDecoderStateMachine->DispatchStartBuffering();
|
2012-01-19 22:29:12 +04:00
|
|
|
}
|
2010-07-23 02:48:32 +04:00
|
|
|
}
|
2009-01-22 02:54:40 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::StopProgressUpdates()
|
2009-01-15 23:26:51 +03:00
|
|
|
{
|
2015-03-18 01:33:24 +03:00
|
|
|
MOZ_ASSERT(OnStateMachineTaskQueue() || OnDecodeTaskQueue());
|
2011-07-12 07:39:23 +04:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-09-30 03:34:37 +04:00
|
|
|
mIgnoreProgressData = true;
|
2009-01-15 23:26:51 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::StartProgressUpdates()
|
2009-01-15 23:26:51 +03:00
|
|
|
{
|
2015-03-18 01:33:24 +03:00
|
|
|
MOZ_ASSERT(OnStateMachineTaskQueue() || OnDecodeTaskQueue());
|
2011-07-12 07:39:23 +04:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-09-30 03:34:37 +04:00
|
|
|
mIgnoreProgressData = false;
|
2009-01-15 23:26:51 +03:00
|
|
|
}
|
2009-04-10 05:28:24 +04:00
|
|
|
|
2014-12-23 04:16:05 +03:00
|
|
|
void MediaDecoder::SetLoadInBackground(bool aLoadInBackground)
|
2009-04-10 05:28:24 +04:00
|
|
|
{
|
2012-11-17 05:37:46 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mResource) {
|
2014-12-23 04:16:05 +03:00
|
|
|
mResource->SetLoadInBackground(aLoadInBackground);
|
2009-04-10 05:28:24 +04:00
|
|
|
}
|
|
|
|
}
|
2010-04-27 12:53:45 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::UpdatePlaybackOffset(int64_t aOffset)
|
2010-04-27 12:53:45 +04:00
|
|
|
{
|
2015-04-08 02:10:51 +03:00
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
2015-03-09 02:16:58 +03:00
|
|
|
mPlaybackPosition = aOffset;
|
2010-04-27 12:53:45 +04:00
|
|
|
}
|
2011-07-12 07:39:34 +04:00
|
|
|
|
2015-03-18 00:23:12 +03:00
|
|
|
bool MediaDecoder::OnStateMachineTaskQueue() const
|
2011-11-22 04:34:21 +04:00
|
|
|
{
|
2015-03-18 00:23:12 +03:00
|
|
|
return mDecoderStateMachine->OnTaskQueue();
|
2011-07-12 07:39:34 +04:00
|
|
|
}
|
2011-11-22 04:34:21 +04:00
|
|
|
|
2012-11-22 14:38:28 +04:00
|
|
|
void MediaDecoder::SetPlaybackRate(double aPlaybackRate)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-01 21:39:42 +03:00
|
|
|
mPlaybackRate = aPlaybackRate;
|
|
|
|
if (mPlaybackRate == 0.0) {
|
2012-11-22 14:38:28 +04:00
|
|
|
mPausedForPlaybackRateNull = true;
|
|
|
|
Pause();
|
|
|
|
} else if (mPausedForPlaybackRateNull) {
|
2014-09-01 08:52:39 +04:00
|
|
|
// Play() uses mPausedForPlaybackRateNull value, so must reset it first
|
|
|
|
mPausedForPlaybackRateNull = false;
|
2012-11-22 14:38:28 +04:00
|
|
|
// If the playbackRate is no longer null, restart the playback, iff the
|
|
|
|
// media was playing.
|
|
|
|
if (mOwner && !mOwner->GetPaused()) {
|
|
|
|
Play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaDecoder::SetPreservesPitch(bool aPreservesPitch)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-02 00:27:29 +03:00
|
|
|
mPreservesPitch = aPreservesPitch;
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
2015-03-18 01:33:24 +03:00
|
|
|
bool MediaDecoder::OnDecodeTaskQueue() const {
|
2013-01-31 00:14:43 +04:00
|
|
|
NS_WARN_IF_FALSE(mDecoderStateMachine, "mDecoderStateMachine is null");
|
2015-03-18 01:14:56 +03:00
|
|
|
return mDecoderStateMachine ? mDecoderStateMachine->OnDecodeTaskQueue() : false;
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
|
2015-04-02 20:49:01 +03:00
|
|
|
void
|
|
|
|
MediaDecoder::SetStateMachine(MediaDecoderStateMachine* aStateMachine)
|
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-02 20:49:01 +03:00
|
|
|
MOZ_ASSERT_IF(aStateMachine, !mDecoderStateMachine);
|
|
|
|
mDecoderStateMachine = aStateMachine;
|
2015-04-01 04:44:36 +03:00
|
|
|
|
|
|
|
if (mDecoderStateMachine) {
|
2015-06-09 22:16:18 +03:00
|
|
|
mStateMachineDuration.Connect(mDecoderStateMachine->CanonicalDuration());
|
2015-06-18 00:22:10 +03:00
|
|
|
mBuffered.Connect(mDecoderStateMachine->CanonicalBuffered());
|
2015-06-30 00:27:16 +03:00
|
|
|
mStateMachineIsShutdown.Connect(mDecoderStateMachine->CanonicalIsShutdown());
|
2015-04-01 04:44:36 +03:00
|
|
|
mNextFrameStatus.Connect(mDecoderStateMachine->CanonicalNextFrameStatus());
|
2015-05-08 03:04:22 +03:00
|
|
|
mCurrentPosition.Connect(mDecoderStateMachine->CanonicalCurrentPosition());
|
2015-04-01 04:44:36 +03:00
|
|
|
} else {
|
2015-06-09 22:16:18 +03:00
|
|
|
mStateMachineDuration.DisconnectIfConnected();
|
2015-06-18 00:22:10 +03:00
|
|
|
mBuffered.DisconnectIfConnected();
|
2015-06-30 00:27:16 +03:00
|
|
|
mStateMachineIsShutdown.DisconnectIfConnected();
|
2015-04-01 04:44:36 +03:00
|
|
|
mNextFrameStatus.DisconnectIfConnected();
|
2015-05-08 03:04:22 +03:00
|
|
|
mCurrentPosition.DisconnectIfConnected();
|
2015-04-01 04:44:36 +03:00
|
|
|
}
|
2015-04-02 20:49:01 +03:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitor& MediaDecoder::GetReentrantMonitor() {
|
2015-02-10 01:59:20 +03:00
|
|
|
return mReentrantMonitor;
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
ImageContainer* MediaDecoder::GetImageContainer()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return mVideoFrameContainer ? mVideoFrameContainer->GetImageContainer() : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-02 07:05:34 +04:00
|
|
|
void MediaDecoder::InvalidateWithFlags(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
if (mVideoFrameContainer) {
|
|
|
|
mVideoFrameContainer->InvalidateWithFlags(aFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::Invalidate()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
if (mVideoFrameContainer) {
|
|
|
|
mVideoFrameContainer->Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 02:33:02 +04:00
|
|
|
// Constructs the time ranges representing what segments of the media
|
|
|
|
// are buffered and playable.
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals MediaDecoder::GetBuffered() {
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-06-18 00:22:10 +03:00
|
|
|
return mBuffered.Ref();
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
|
2014-03-20 01:33:12 +04:00
|
|
|
size_t MediaDecoder::SizeOfVideoQueue() {
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-07 02:33:02 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2014-03-20 01:33:12 +04:00
|
|
|
return mDecoderStateMachine->SizeOfVideoQueue();
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-23 07:14:45 +04:00
|
|
|
size_t MediaDecoder::SizeOfAudioQueue() {
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-07 02:33:02 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2014-01-23 07:14:45 +04:00
|
|
|
return mDecoderStateMachine->SizeOfAudioQueue();
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-19 23:45:09 +03:00
|
|
|
void MediaDecoder::NotifyDataArrived(uint32_t aLength, int64_t aOffset, bool aThrottleUpdates) {
|
2015-06-18 00:22:10 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-11-07 02:33:02 +04:00
|
|
|
if (mDecoderStateMachine) {
|
2015-06-19 23:45:09 +03:00
|
|
|
mDecoderStateMachine->DispatchNotifyDataArrived(aLength, aOffset, aThrottleUpdates);
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
2015-04-28 19:21:48 +03:00
|
|
|
|
|
|
|
// ReadyState computation depends on MediaDecoder::CanPlayThrough, which
|
|
|
|
// depends on the download rate.
|
2015-04-29 05:02:31 +03:00
|
|
|
UpdateReadyState();
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provide access to the state machine object
|
2012-11-19 19:11:21 +04:00
|
|
|
MediaDecoderStateMachine* MediaDecoder::GetStateMachine() const {
|
2012-11-07 02:33:02 +04:00
|
|
|
return mDecoderStateMachine;
|
|
|
|
}
|
|
|
|
|
2014-03-11 07:44:09 +04:00
|
|
|
void
|
|
|
|
MediaDecoder::NotifyWaitingForResourcesStatusChanged()
|
|
|
|
{
|
|
|
|
if (mDecoderStateMachine) {
|
2015-03-22 02:32:40 +03:00
|
|
|
RefPtr<nsRunnable> task =
|
|
|
|
NS_NewRunnableMethod(mDecoderStateMachine,
|
|
|
|
&MediaDecoderStateMachine::NotifyWaitingForResourcesStatusChanged);
|
2015-07-16 21:31:21 +03:00
|
|
|
mDecoderStateMachine->OwnerThread()->Dispatch(task.forget());
|
2014-03-11 07:44:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
bool MediaDecoder::IsShutdown() const {
|
2015-06-30 00:27:16 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-13 23:42:45 +04:00
|
|
|
NS_ENSURE_TRUE(GetStateMachine(), true);
|
2015-06-30 00:27:16 +03:00
|
|
|
return mStateMachineIsShutdown;
|
2012-11-19 19:11:21 +04:00
|
|
|
}
|
|
|
|
|
2012-11-07 02:33:02 +04:00
|
|
|
// Drop reference to state machine. Only called during shutdown dance.
|
2014-06-18 09:07:02 +04:00
|
|
|
void MediaDecoder::BreakCycles() {
|
2015-04-02 20:49:01 +03:00
|
|
|
SetStateMachine(nullptr);
|
2012-11-07 02:33:02 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoderOwner* MediaDecoder::GetMediaOwner() const
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::FireTimeUpdate()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-14 23:45:13 +04:00
|
|
|
if (!mOwner)
|
|
|
|
return;
|
|
|
|
mOwner->FireTimeUpdate(true);
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::PinForSeek()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-14 23:45:13 +04:00
|
|
|
MediaResource* resource = GetResource();
|
|
|
|
if (!resource || mPinnedForSeek) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPinnedForSeek = true;
|
|
|
|
resource->Pin();
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
void MediaDecoder::UnpinForSeek()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2015-07-01 00:39:41 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-11-14 23:45:13 +04:00
|
|
|
MediaResource* resource = GetResource();
|
|
|
|
if (!resource || !mPinnedForSeek) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPinnedForSeek = false;
|
|
|
|
resource->Unpin();
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
bool MediaDecoder::CanPlayThrough()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
Statistics stats = GetStatistics();
|
2015-03-19 05:01:12 +03:00
|
|
|
NS_ENSURE_TRUE(mDecoderStateMachine, false);
|
2015-01-06 04:58:04 +03:00
|
|
|
|
|
|
|
if (mDecoderStateMachine->IsRealTime() ||
|
|
|
|
(stats.mTotalBytes < 0 && stats.mDownloadRateReliable) ||
|
2014-12-17 10:05:40 +03:00
|
|
|
(stats.mTotalBytes >= 0 && stats.mTotalBytes == stats.mDownloadPosition)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-14 23:45:13 +04:00
|
|
|
if (!stats.mDownloadRateReliable || !stats.mPlaybackRateReliable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int64_t bytesToDownload = stats.mTotalBytes - stats.mDownloadPosition;
|
|
|
|
int64_t bytesToPlayback = stats.mTotalBytes - stats.mPlaybackPosition;
|
|
|
|
double timeToDownload = bytesToDownload / stats.mDownloadRate;
|
|
|
|
double timeToPlay = bytesToPlayback / stats.mPlaybackRate;
|
|
|
|
|
|
|
|
if (timeToDownload > timeToPlay) {
|
|
|
|
// Estimated time to download is greater than the estimated time to play.
|
|
|
|
// We probably can't play through without having to stop to buffer.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Estimated time to download is less than the estimated time to play.
|
|
|
|
// We can probably play through without having to buffer, but ensure that
|
|
|
|
// we've got a reasonable amount of data buffered after the current
|
|
|
|
// playback position, so that if the bitrate of the media fluctuates, or if
|
|
|
|
// our download rate or decode rate estimation is otherwise inaccurate,
|
|
|
|
// we don't suddenly discover that we need to buffer. This is particularly
|
|
|
|
// required near the start of the media, when not much data is downloaded.
|
|
|
|
int64_t readAheadMargin =
|
|
|
|
static_cast<int64_t>(stats.mPlaybackRate * CAN_PLAY_THROUGH_MARGIN);
|
2014-12-17 10:05:40 +03:00
|
|
|
return stats.mDownloadPosition > stats.mPlaybackPosition + readAheadMargin;
|
2012-11-14 23:45:13 +04:00
|
|
|
}
|
|
|
|
|
2014-08-08 06:44:04 +04:00
|
|
|
#ifdef MOZ_EME
|
2014-07-30 10:53:34 +04:00
|
|
|
nsresult
|
|
|
|
MediaDecoder::SetCDMProxy(CDMProxy* aProxy)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-01 00:39:41 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
|
2014-07-30 10:53:34 +04:00
|
|
|
mProxy = aProxy;
|
|
|
|
// Awaken any readers waiting for the proxy.
|
|
|
|
NotifyWaitingForResourcesStatusChanged();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDMProxy*
|
|
|
|
MediaDecoder::GetCDMProxy()
|
|
|
|
{
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return mProxy;
|
|
|
|
}
|
2014-08-08 06:44:04 +04:00
|
|
|
#endif
|
2014-07-30 10:53:34 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsRawEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.raw.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsOpusEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.opus.enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsOggEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.ogg.enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsWaveEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.wave.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsWebMEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.webm.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-12 02:52:33 +04:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 13:53:36 +04:00
|
|
|
bool
|
|
|
|
MediaDecoder::IsRtspEnabled()
|
|
|
|
{
|
|
|
|
//Currently the Rtsp decoded by omx.
|
|
|
|
return (Preferences::GetBool("media.rtsp.enabled", false) && IsOmxEnabled());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsGStreamerEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.gstreamer.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2012-11-14 23:45:13 +04:00
|
|
|
bool
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder::IsOmxEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.omx.enabled", false);
|
|
|
|
}
|
2014-07-16 11:40:05 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
MediaDecoder::IsOmxAsyncEnabled()
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= 16
|
|
|
|
return Preferences::GetBool("media.omx.async.enabled", false);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2012-11-14 23:45:13 +04:00
|
|
|
#endif
|
|
|
|
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2012-11-14 23:45:13 +04:00
|
|
|
bool
|
2014-07-17 05:32:56 +04:00
|
|
|
MediaDecoder::IsAndroidMediaEnabled()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.plugins.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-14 05:14:42 +04:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
bool
|
|
|
|
MediaDecoder::IsAppleMP3Enabled()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.apple.mp3.enabled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 10:06:54 +04:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-01-18 09:43:20 +04:00
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
int64_t video = 0, audio = 0;
|
2014-03-06 01:31:04 +04:00
|
|
|
size_t resources = 0;
|
2013-11-07 09:35:30 +04:00
|
|
|
DecodersArray& decoders = Decoders();
|
|
|
|
for (size_t i = 0; i < decoders.Length(); ++i) {
|
2014-03-06 01:31:04 +04:00
|
|
|
MediaDecoder* decoder = decoders[i];
|
2014-03-20 01:33:12 +04:00
|
|
|
video += decoder->SizeOfVideoQueue();
|
2014-03-06 01:31:04 +04:00
|
|
|
audio += decoder->SizeOfAudioQueue();
|
|
|
|
|
|
|
|
if (decoder->GetResource()) {
|
|
|
|
resources += decoder->GetResource()->SizeOfIncludingThis(MallocSizeOf);
|
|
|
|
}
|
2013-11-07 09:35:30 +04:00
|
|
|
}
|
2013-01-18 09:43:20 +04:00
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
nsresult rv; \
|
|
|
|
rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
|
|
|
|
KIND_HEAP, UNITS_BYTES, _amount, \
|
|
|
|
NS_LITERAL_CSTRING(_desc), aData); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} while (0)
|
2013-01-18 09:43:20 +04:00
|
|
|
|
2014-03-06 01:31:04 +04:00
|
|
|
REPORT("explicit/media/decoded/video", video,
|
2013-11-07 09:35:30 +04:00
|
|
|
"Memory used by decoded video frames.");
|
2013-01-18 09:43:20 +04:00
|
|
|
|
2014-03-06 01:31:04 +04:00
|
|
|
REPORT("explicit/media/decoded/audio", audio,
|
2013-11-07 09:35:30 +04:00
|
|
|
"Memory used by decoded audio chunks.");
|
2013-11-28 05:05:00 +04:00
|
|
|
|
2014-03-06 01:31:04 +04:00
|
|
|
REPORT("explicit/media/resources", resources,
|
|
|
|
"Memory used by media resources including streaming buffers, caches, "
|
|
|
|
"etc.");
|
|
|
|
|
2014-04-13 22:08:10 +04:00
|
|
|
#undef REPORT
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-18 09:43:20 +04:00
|
|
|
|
2013-05-04 14:12:41 +04:00
|
|
|
MediaDecoderOwner*
|
|
|
|
MediaDecoder::GetOwner()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2014-07-04 07:55:06 +04:00
|
|
|
void
|
|
|
|
MediaDecoder::ConstructMediaTracks()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mMediaTracksConstructed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOwner || !mInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* element = mOwner->GetMediaElement();
|
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMediaTracksConstructed = true;
|
|
|
|
|
|
|
|
AudioTrackList* audioList = element->AudioTracks();
|
|
|
|
if (audioList && mInfo->HasAudio()) {
|
2015-04-14 08:15:46 +03:00
|
|
|
const TrackInfo& info = mInfo->mAudio;
|
2014-07-04 07:55:06 +04:00
|
|
|
nsRefPtr<AudioTrack> track = MediaTrackList::CreateAudioTrack(
|
|
|
|
info.mId, info.mKind, info.mLabel, info.mLanguage, info.mEnabled);
|
|
|
|
|
|
|
|
audioList->AddTrack(track);
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoTrackList* videoList = element->VideoTracks();
|
|
|
|
if (videoList && mInfo->HasVideo()) {
|
2015-04-14 08:15:46 +03:00
|
|
|
const TrackInfo& info = mInfo->mVideo;
|
2014-07-04 07:55:06 +04:00
|
|
|
nsRefPtr<VideoTrack> track = MediaTrackList::CreateVideoTrack(
|
|
|
|
info.mId, info.mKind, info.mLabel, info.mLanguage);
|
|
|
|
|
|
|
|
videoList->AddTrack(track);
|
|
|
|
track->SetEnabledInternal(info.mEnabled, MediaTrack::FIRE_NO_EVENTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaDecoder::RemoveMediaTracks()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* element = mOwner->GetMediaElement();
|
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioTrackList* audioList = element->AudioTracks();
|
|
|
|
if (audioList) {
|
|
|
|
audioList->RemoveTracks();
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoTrackList* videoList = element->VideoTracks();
|
|
|
|
if (videoList) {
|
|
|
|
videoList->RemoveTracks();
|
|
|
|
}
|
|
|
|
|
|
|
|
mMediaTracksConstructed = false;
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:43:20 +04:00
|
|
|
MediaMemoryTracker::MediaMemoryTracker()
|
2013-11-07 09:35:30 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaMemoryTracker::InitMemoryReporter()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterWeakMemoryReporter(this);
|
2012-11-14 23:45:13 +04:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:43:20 +04:00
|
|
|
MediaMemoryTracker::~MediaMemoryTracker()
|
2012-11-14 23:45:13 +04:00
|
|
|
{
|
2013-11-07 09:35:30 +04:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2012-11-14 23:45:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2012-11-14 23:45:33 +04:00
|
|
|
|
2014-04-23 13:29:04 +04:00
|
|
|
// avoid redefined macro in unified build
|
|
|
|
#undef DECODER_LOG
|