2014-04-14 11:24:00 +00:00
|
|
|
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-09-27 05:22:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
#include "MediaSourceDecoder.h"
|
|
|
|
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2014-08-13 12:22:00 +00:00
|
|
|
#include "MediaDecoderStateMachine.h"
|
2017-03-02 10:03:20 +00:00
|
|
|
#include "MediaShutdownManager.h"
|
2013-10-05 08:04:39 +00:00
|
|
|
#include "MediaSource.h"
|
2017-08-15 04:13:00 +00:00
|
|
|
#include "MediaSourceDemuxer.h"
|
2014-08-20 08:07:00 +00:00
|
|
|
#include "MediaSourceUtils.h"
|
2017-11-29 08:00:53 +00:00
|
|
|
#include "SourceBuffer.h"
|
2015-07-22 01:09:21 +00:00
|
|
|
#include "SourceBufferList.h"
|
2017-08-15 04:13:00 +00:00
|
|
|
#include "VideoUtils.h"
|
2015-12-02 04:09:47 +00:00
|
|
|
#include <algorithm>
|
2014-07-22 08:20:00 +00:00
|
|
|
|
2015-11-15 13:49:01 +00:00
|
|
|
extern mozilla::LogModule* GetMediaSourceLog();
|
2014-08-11 01:21:17 +00:00
|
|
|
|
2017-10-13 05:31:59 +00:00
|
|
|
#define MSE_DEBUG(arg, ...) \
|
|
|
|
DDMOZ_LOG(GetMediaSourceLog(), \
|
|
|
|
mozilla::LogLevel::Debug, \
|
|
|
|
"::%s: " arg, \
|
|
|
|
__func__, \
|
|
|
|
##__VA_ARGS__)
|
|
|
|
#define MSE_DEBUGV(arg, ...) \
|
|
|
|
DDMOZ_LOG(GetMediaSourceLog(), \
|
|
|
|
mozilla::LogLevel::Verbose, \
|
|
|
|
"::%s: " arg, \
|
|
|
|
__func__, \
|
|
|
|
##__VA_ARGS__)
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2015-06-03 21:46:08 +00:00
|
|
|
using namespace mozilla::media;
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-06-07 04:14:11 +00:00
|
|
|
MediaSourceDecoder::MediaSourceDecoder(MediaDecoderInit& aInit)
|
|
|
|
: MediaDecoder(aInit)
|
2015-10-15 03:39:45 +00:00
|
|
|
, mMediaSource(nullptr)
|
2015-06-11 23:26:57 +00:00
|
|
|
, mEnded(false)
|
2013-09-27 05:22:37 +00:00
|
|
|
{
|
2017-08-01 07:06:13 +00:00
|
|
|
mExplicitDuration.emplace(UnspecifiedNaN<double>());
|
2013-09-27 05:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaDecoderStateMachine*
|
|
|
|
MediaSourceDecoder::CreateStateMachine()
|
|
|
|
{
|
2015-09-29 22:55:21 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-11-29 05:03:36 +00:00
|
|
|
mDemuxer = new MediaSourceDemuxer(AbstractMainThread());
|
2017-07-13 07:13:12 +00:00
|
|
|
MediaFormatReaderInit init;
|
2017-07-06 08:59:22 +00:00
|
|
|
init.mVideoFrameContainer = GetVideoFrameContainer();
|
2017-07-12 07:37:02 +00:00
|
|
|
init.mKnowsCompositor = GetCompositor();
|
2017-07-13 02:19:36 +00:00
|
|
|
init.mCrashHelper = GetOwner()->CreateGMPCrashHelper();
|
2017-07-07 03:05:03 +00:00
|
|
|
init.mFrameStats = mFrameStats;
|
2017-08-31 09:31:51 +00:00
|
|
|
init.mMediaDecoderOwnerID = mOwner;
|
2017-07-06 08:59:22 +00:00
|
|
|
mReader = new MediaFormatReader(init, mDemuxer);
|
2016-01-17 23:21:59 +00:00
|
|
|
return new MediaDecoderStateMachine(this, mReader);
|
2013-09-27 05:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-06-23 07:39:57 +00:00
|
|
|
MediaSourceDecoder::Load(nsIPrincipal* aPrincipal)
|
2013-09-27 05:22:37 +00:00
|
|
|
{
|
2015-09-29 22:55:21 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-02 17:49:01 +00:00
|
|
|
MOZ_ASSERT(!GetStateMachine());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-03-02 10:03:20 +00:00
|
|
|
|
2017-08-24 09:13:03 +00:00
|
|
|
mPrincipal = aPrincipal;
|
2017-06-23 07:39:57 +00:00
|
|
|
|
2017-03-02 10:03:20 +00:00
|
|
|
nsresult rv = MediaShutdownManager::Instance().Register(this);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:49:01 +00:00
|
|
|
SetStateMachine(CreateStateMachine());
|
|
|
|
if (!GetStateMachine()) {
|
2014-02-17 22:53:51 +00:00
|
|
|
NS_WARNING("Failed to create state machine!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:03:20 +00:00
|
|
|
rv = GetStateMachine()->Init(this);
|
2014-08-05 14:55:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-12-06 08:00:20 +00:00
|
|
|
GetStateMachine()->DispatchIsLiveStream(!mEnded);
|
2014-08-05 14:55:02 +00:00
|
|
|
SetStateMachineParameters();
|
2015-07-23 10:39:09 +00:00
|
|
|
return NS_OK;
|
2013-09-27 05:22:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 06:15:47 +00:00
|
|
|
media::TimeIntervals
|
|
|
|
MediaSourceDecoder::GetSeekable()
|
2013-10-05 08:04:39 +00:00
|
|
|
{
|
2014-08-25 04:09:44 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2014-08-25 04:09:44 +00:00
|
|
|
if (!mMediaSource) {
|
2015-05-18 06:15:47 +00:00
|
|
|
NS_WARNING("MediaSource element isn't attached");
|
|
|
|
return media::TimeIntervals::Invalid();
|
2014-08-25 04:09:44 +00:00
|
|
|
}
|
2014-09-16 03:15:55 +00:00
|
|
|
|
2015-05-18 06:15:47 +00:00
|
|
|
media::TimeIntervals seekable;
|
2013-10-05 08:04:39 +00:00
|
|
|
double duration = mMediaSource->Duration();
|
|
|
|
if (IsNaN(duration)) {
|
|
|
|
// Return empty range.
|
|
|
|
} else if (duration > 0 && mozilla::IsInfinite(duration)) {
|
2015-06-17 21:22:10 +00:00
|
|
|
media::TimeIntervals buffered = GetBuffered();
|
2016-07-14 04:34:45 +00:00
|
|
|
|
|
|
|
// 1. If live seekable range is not empty:
|
|
|
|
if (mMediaSource->HasLiveSeekableRange()) {
|
|
|
|
// 1. Let union ranges be the union of live seekable range and the
|
|
|
|
// HTMLMediaElement.buffered attribute.
|
|
|
|
media::TimeIntervals unionRanges =
|
|
|
|
buffered + mMediaSource->LiveSeekableRange();
|
|
|
|
// 2. Return a single range with a start time equal to the earliest start
|
|
|
|
// time in union ranges and an end time equal to the highest end time in
|
|
|
|
// union ranges and abort these steps.
|
|
|
|
seekable +=
|
|
|
|
media::TimeInterval(unionRanges.GetStart(), unionRanges.GetEnd());
|
|
|
|
return seekable;
|
|
|
|
}
|
|
|
|
|
2015-05-18 06:15:47 +00:00
|
|
|
if (buffered.Length()) {
|
2017-04-17 08:35:04 +00:00
|
|
|
seekable += media::TimeInterval(TimeUnit::Zero(), buffered.GetEnd());
|
2015-05-18 06:15:47 +00:00
|
|
|
}
|
2013-10-05 08:04:39 +00:00
|
|
|
} else {
|
2017-04-17 08:35:04 +00:00
|
|
|
seekable += media::TimeInterval(TimeUnit::Zero(),
|
|
|
|
TimeUnit::FromSeconds(duration));
|
2013-10-05 08:04:39 +00:00
|
|
|
}
|
2015-05-18 06:15:47 +00:00
|
|
|
MSE_DEBUG("ranges=%s", DumpTimeRanges(seekable).get());
|
|
|
|
return seekable;
|
2013-10-05 08:04:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 21:22:10 +00:00
|
|
|
media::TimeIntervals
|
|
|
|
MediaSourceDecoder::GetBuffered()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-06-17 21:22:10 +00:00
|
|
|
|
2016-08-12 10:56:45 +00:00
|
|
|
if (!mMediaSource) {
|
|
|
|
NS_WARNING("MediaSource element isn't attached");
|
|
|
|
return media::TimeIntervals::Invalid();
|
|
|
|
}
|
2015-06-17 21:22:10 +00:00
|
|
|
dom::SourceBufferList* sourceBuffers = mMediaSource->ActiveSourceBuffers();
|
2015-12-02 01:59:18 +00:00
|
|
|
if (!sourceBuffers) {
|
|
|
|
// Media source object is shutting down.
|
|
|
|
return TimeIntervals();
|
|
|
|
}
|
2017-04-17 08:35:04 +00:00
|
|
|
TimeUnit highestEndTime;
|
2015-06-17 21:22:10 +00:00
|
|
|
nsTArray<media::TimeIntervals> activeRanges;
|
|
|
|
media::TimeIntervals buffered;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sourceBuffers->Length(); i++) {
|
|
|
|
bool found;
|
|
|
|
dom::SourceBuffer* sb = sourceBuffers->IndexedGetter(i, found);
|
|
|
|
MOZ_ASSERT(found);
|
|
|
|
|
|
|
|
activeRanges.AppendElement(sb->GetTimeIntervals());
|
|
|
|
highestEndTime =
|
|
|
|
std::max(highestEndTime, activeRanges.LastElement().GetEnd());
|
|
|
|
}
|
|
|
|
|
2017-04-17 08:35:04 +00:00
|
|
|
buffered += media::TimeInterval(TimeUnit::Zero(), highestEndTime);
|
2015-06-17 21:22:10 +00:00
|
|
|
|
|
|
|
for (auto& range : activeRanges) {
|
|
|
|
if (mEnded && range.Length()) {
|
|
|
|
// Set the end time on the last range to highestEndTime by adding a
|
|
|
|
// new range spanning the current end time to highestEndTime, which
|
|
|
|
// Normalize() will then merge with the old last range.
|
|
|
|
range +=
|
|
|
|
media::TimeInterval(range.GetEnd(), highestEndTime);
|
|
|
|
}
|
|
|
|
buffered.Intersection(range);
|
|
|
|
}
|
|
|
|
|
|
|
|
MSE_DEBUG("ranges=%s", DumpTimeRanges(buffered).get());
|
|
|
|
return buffered;
|
|
|
|
}
|
|
|
|
|
2016-05-04 08:13:25 +00:00
|
|
|
void
|
2014-08-25 04:09:44 +00:00
|
|
|
MediaSourceDecoder::Shutdown()
|
|
|
|
{
|
2015-09-29 22:55:21 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("Shutdown");
|
2014-11-04 04:24:52 +00:00
|
|
|
// Detach first so that TrackBuffers are unused on the main thread when
|
|
|
|
// shut down on the decode task queue.
|
2014-08-28 03:44:58 +00:00
|
|
|
if (mMediaSource) {
|
|
|
|
mMediaSource->Detach();
|
|
|
|
}
|
2015-07-14 03:12:29 +00:00
|
|
|
mDemuxer = nullptr;
|
2014-11-04 04:24:52 +00:00
|
|
|
|
2016-05-04 08:13:25 +00:00
|
|
|
MediaDecoder::Shutdown();
|
2014-08-25 04:09:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
void
|
2013-11-18 04:22:47 +00:00
|
|
|
MediaSourceDecoder::AttachMediaSource(dom::MediaSource* aMediaSource)
|
2013-09-27 05:22:37 +00:00
|
|
|
{
|
2015-04-02 17:49:01 +00:00
|
|
|
MOZ_ASSERT(!mMediaSource && !GetStateMachine() && NS_IsMainThread());
|
2013-09-27 05:22:37 +00:00
|
|
|
mMediaSource = aMediaSource;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 06:55:27 +00:00
|
|
|
DDLINKCHILD("mediasource", aMediaSource);
|
2013-09-27 05:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaSourceDecoder::DetachMediaSource()
|
|
|
|
{
|
2014-08-25 04:09:44 +00:00
|
|
|
MOZ_ASSERT(mMediaSource && NS_IsMainThread());
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 06:55:27 +00:00
|
|
|
DDUNLINKCHILD(mMediaSource);
|
2013-09-27 05:22:37 +00:00
|
|
|
mMediaSource = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-26 07:25:09 +00:00
|
|
|
void
|
2015-03-23 10:08:05 +00:00
|
|
|
MediaSourceDecoder::Ended(bool aEnded)
|
2014-08-26 07:25:09 +00:00
|
|
|
{
|
2015-09-29 22:55:21 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-08-08 03:56:38 +00:00
|
|
|
if (aEnded) {
|
|
|
|
// We want the MediaSourceReader to refresh its buffered range as it may
|
|
|
|
// have been modified (end lined up).
|
|
|
|
NotifyDataArrived();
|
|
|
|
}
|
|
|
|
mEnded = aEnded;
|
2017-12-06 08:00:20 +00:00
|
|
|
GetStateMachine()->DispatchIsLiveStream(!mEnded);
|
2014-08-26 07:25:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 22:10:33 +00:00
|
|
|
void
|
|
|
|
MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-08-20 22:10:33 +00:00
|
|
|
if (GetDemuxer()) {
|
|
|
|
GetDemuxer()->AddSizeOfResources(aSizes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 04:11:33 +00:00
|
|
|
void
|
2015-02-04 09:20:15 +00:00
|
|
|
MediaSourceDecoder::SetInitialDuration(int64_t aDuration)
|
2014-11-12 04:11:33 +00:00
|
|
|
{
|
2015-06-02 21:18:47 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2014-11-12 04:11:33 +00:00
|
|
|
// Only use the decoded duration if one wasn't already
|
|
|
|
// set.
|
2015-06-02 21:44:26 +00:00
|
|
|
if (!mMediaSource || !IsNaN(ExplicitDuration())) {
|
2014-08-25 04:09:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-12 04:11:33 +00:00
|
|
|
double duration = aDuration;
|
2015-01-16 12:49:01 +00:00
|
|
|
// A duration of -1 is +Infinity.
|
|
|
|
if (aDuration >= 0) {
|
|
|
|
duration /= USECS_PER_S;
|
|
|
|
}
|
2016-07-15 13:38:33 +00:00
|
|
|
SetMediaSourceDuration(duration);
|
2014-11-12 04:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-15 13:38:33 +00:00
|
|
|
MediaSourceDecoder::SetMediaSourceDuration(double aDuration)
|
2014-11-12 04:11:33 +00:00
|
|
|
{
|
2015-06-02 21:18:47 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-07-28 07:52:30 +00:00
|
|
|
MOZ_ASSERT(!IsShutdown());
|
2015-01-16 12:49:01 +00:00
|
|
|
if (aDuration >= 0) {
|
2015-02-12 07:52:12 +00:00
|
|
|
int64_t checkedDuration;
|
|
|
|
if (NS_FAILED(SecondsToUsecs(aDuration, checkedDuration))) {
|
|
|
|
// INT64_MAX is used as infinity by the state machine.
|
|
|
|
// We want a very bigger number, but not infinity.
|
|
|
|
checkedDuration = INT64_MAX - 1;
|
|
|
|
}
|
2015-06-02 21:44:26 +00:00
|
|
|
SetExplicitDuration(aDuration);
|
2015-01-16 12:49:01 +00:00
|
|
|
} else {
|
2015-06-02 21:44:26 +00:00
|
|
|
SetExplicitDuration(PositiveInfinity<double>());
|
2015-01-16 12:49:01 +00:00
|
|
|
}
|
2014-08-25 04:09:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 02:35:58 +00:00
|
|
|
void
|
2017-01-18 08:51:31 +00:00
|
|
|
MediaSourceDecoder::GetMozDebugReaderData(nsACString& aString)
|
2015-01-29 02:35:58 +00:00
|
|
|
{
|
2017-09-04 20:47:36 +00:00
|
|
|
aString += NS_LITERAL_CSTRING("Container Type: MediaSource\n");
|
2016-01-18 04:34:07 +00:00
|
|
|
if (mReader && mDemuxer) {
|
2017-07-19 09:01:32 +00:00
|
|
|
mReader->GetMozDebugReaderData(aString);
|
2016-01-18 04:34:07 +00:00
|
|
|
mDemuxer->GetMozDebugReaderData(aString);
|
|
|
|
}
|
2015-01-29 02:35:58 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 07:52:12 +00:00
|
|
|
double
|
|
|
|
MediaSourceDecoder::GetDuration()
|
|
|
|
{
|
2015-09-29 22:55:21 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-06-02 21:44:26 +00:00
|
|
|
return ExplicitDuration();
|
2015-02-12 07:52:12 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 02:01:40 +00:00
|
|
|
MediaDecoderOwner::NextFrameStatus
|
|
|
|
MediaSourceDecoder::NextFrameBufferedStatus()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-02-10 06:06:18 +00:00
|
|
|
|
2017-09-04 09:27:43 +00:00
|
|
|
if (!mMediaSource ||
|
|
|
|
mMediaSource->ReadyState() == dom::MediaSourceReadyState::Closed) {
|
2016-02-10 06:06:18 +00:00
|
|
|
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-12-02 02:01:40 +00:00
|
|
|
// Next frame hasn't been decoded yet.
|
|
|
|
// Use the buffered range to consider if we have the next frame available.
|
2017-04-17 09:04:39 +00:00
|
|
|
auto currentPosition = CurrentPosition();
|
2016-08-27 10:27:22 +00:00
|
|
|
TimeIntervals buffered = GetBuffered();
|
|
|
|
buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
|
|
|
|
TimeInterval interval(
|
|
|
|
currentPosition,
|
2017-04-17 08:58:44 +00:00
|
|
|
currentPosition + DEFAULT_NEXT_FRAME_AVAILABLE_BUFFERED);
|
2017-08-16 17:35:27 +00:00
|
|
|
return buffered.ContainsWithStrictEnd(ClampIntervalToEnd(interval))
|
2017-01-27 12:20:37 +00:00
|
|
|
? MediaDecoderOwner::NEXT_FRAME_AVAILABLE
|
|
|
|
: MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
|
2015-12-02 02:01:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 04:09:47 +00:00
|
|
|
bool
|
2017-08-04 09:38:20 +00:00
|
|
|
MediaSourceDecoder::CanPlayThroughImpl()
|
2015-12-02 04:09:47 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-03-21 23:34:30 +00:00
|
|
|
|
|
|
|
if (NextFrameBufferedStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:09:47 +00:00
|
|
|
if (IsNaN(mMediaSource->Duration())) {
|
|
|
|
// Don't have any data yet.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TimeUnit duration = TimeUnit::FromSeconds(mMediaSource->Duration());
|
2017-04-17 09:04:39 +00:00
|
|
|
auto currentPosition = CurrentPosition();
|
2017-10-10 14:14:24 +00:00
|
|
|
if (duration <= currentPosition) {
|
2015-12-02 04:09:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-07-20 18:49:06 +00:00
|
|
|
// If we have data up to the mediasource's duration or 10s ahead, we can
|
2015-12-02 04:09:47 +00:00
|
|
|
// assume that we can play without interruption.
|
2016-08-27 10:27:22 +00:00
|
|
|
TimeIntervals buffered = GetBuffered();
|
|
|
|
buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
|
2015-12-02 04:09:47 +00:00
|
|
|
TimeUnit timeAhead =
|
2017-07-20 18:49:06 +00:00
|
|
|
std::min(duration, currentPosition + TimeUnit::FromSeconds(10));
|
2016-08-27 10:27:22 +00:00
|
|
|
TimeInterval interval(currentPosition, timeAhead);
|
2017-08-16 17:35:27 +00:00
|
|
|
return buffered.ContainsWithStrictEnd(ClampIntervalToEnd(interval));
|
2016-05-02 05:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeInterval
|
|
|
|
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
|
|
|
|
{
|
2016-08-08 03:56:38 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-08-08 03:56:38 +00:00
|
|
|
|
2016-05-02 05:21:40 +00:00
|
|
|
if (!mEnded) {
|
|
|
|
return aInterval;
|
|
|
|
}
|
2016-08-27 10:27:22 +00:00
|
|
|
TimeUnit duration = TimeUnit::FromSeconds(GetDuration());
|
|
|
|
if (duration < aInterval.mStart) {
|
|
|
|
return aInterval;
|
|
|
|
}
|
|
|
|
return TimeInterval(aInterval.mStart,
|
|
|
|
std::min(aInterval.mEnd, duration),
|
|
|
|
aInterval.mFuzz);
|
2015-12-02 04:09:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 17:53:53 +00:00
|
|
|
void
|
|
|
|
MediaSourceDecoder::NotifyInitDataArrived()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-31 21:29:07 +00:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-04-27 17:53:53 +00:00
|
|
|
|
|
|
|
if (mDemuxer) {
|
|
|
|
mDemuxer->NotifyInitDataArrived();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 03:07:13 +00:00
|
|
|
void
|
|
|
|
MediaSourceDecoder::NotifyDataArrived()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-11-30 03:21:14 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
|
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-11-30 03:07:13 +00:00
|
|
|
NotifyReaderDataArrived();
|
2017-11-30 03:21:14 +00:00
|
|
|
GetOwner()->DownloadProgressed();
|
2017-11-30 03:07:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:58:06 +00:00
|
|
|
already_AddRefed<nsIPrincipal>
|
|
|
|
MediaSourceDecoder::GetCurrentPrincipal()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-24 09:13:03 +00:00
|
|
|
return do_AddRef(mPrincipal);
|
2017-08-24 08:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 07:52:13 +00:00
|
|
|
#undef MSE_DEBUG
|
|
|
|
#undef MSE_DEBUGV
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
} // namespace mozilla
|