2014-04-14 15:24:00 +04:00
|
|
|
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-09-27 09:22:37 +04: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 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2014-08-13 16:22:00 +04:00
|
|
|
#include "MediaDecoderStateMachine.h"
|
2017-03-02 13:03:20 +03:00
|
|
|
#include "MediaShutdownManager.h"
|
2013-10-05 12:04:39 +04:00
|
|
|
#include "MediaSource.h"
|
2017-08-15 07:13:00 +03:00
|
|
|
#include "MediaSourceDemuxer.h"
|
2014-08-13 16:22:00 +04:00
|
|
|
#include "MediaSourceResource.h"
|
2014-08-20 12:07:00 +04:00
|
|
|
#include "MediaSourceUtils.h"
|
2015-07-22 04:09:21 +03:00
|
|
|
#include "SourceBufferList.h"
|
2017-08-15 07:13:00 +03:00
|
|
|
#include "VideoUtils.h"
|
2015-12-02 07:09:47 +03:00
|
|
|
#include <algorithm>
|
2014-07-22 12:20:00 +04:00
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern mozilla::LogModule* GetMediaSourceLog();
|
2014-08-11 05:21:17 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSourceDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
|
|
|
|
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("MediaSourceDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2015-06-04 00:46:08 +03:00
|
|
|
using namespace mozilla::media;
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-06-07 07:14:11 +03:00
|
|
|
MediaSourceDecoder::MediaSourceDecoder(MediaDecoderInit& aInit)
|
|
|
|
: MediaDecoder(aInit)
|
2015-10-15 06:39:45 +03:00
|
|
|
, mMediaSource(nullptr)
|
2015-06-12 02:26:57 +03:00
|
|
|
, mEnded(false)
|
2013-09-27 09:22:37 +04:00
|
|
|
{
|
2017-08-01 10:06:13 +03:00
|
|
|
mExplicitDuration.emplace(UnspecifiedNaN<double>());
|
2013-09-27 09:22:37 +04:00
|
|
|
}
|
|
|
|
|
2017-08-03 10:38:28 +03:00
|
|
|
MediaResource*
|
|
|
|
MediaSourceDecoder::GetResource() const
|
|
|
|
{
|
|
|
|
return mResource;
|
|
|
|
}
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
MediaDecoderStateMachine*
|
|
|
|
MediaSourceDecoder::CreateStateMachine()
|
|
|
|
{
|
2015-09-30 01:55:21 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-11-29 08:03:36 +03:00
|
|
|
mDemuxer = new MediaSourceDemuxer(AbstractMainThread());
|
2017-07-13 10:13:12 +03:00
|
|
|
MediaFormatReaderInit init;
|
2017-07-06 11:59:22 +03:00
|
|
|
init.mVideoFrameContainer = GetVideoFrameContainer();
|
2017-07-12 10:37:02 +03:00
|
|
|
init.mKnowsCompositor = GetCompositor();
|
2017-07-13 05:19:36 +03:00
|
|
|
init.mCrashHelper = GetOwner()->CreateGMPCrashHelper();
|
2017-07-07 06:05:03 +03:00
|
|
|
init.mFrameStats = mFrameStats;
|
2017-07-06 11:59:22 +03:00
|
|
|
mReader = new MediaFormatReader(init, mDemuxer);
|
2016-01-18 02:21:59 +03:00
|
|
|
return new MediaDecoderStateMachine(this, mReader);
|
2013-09-27 09:22:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-06-23 10:39:57 +03:00
|
|
|
MediaSourceDecoder::Load(nsIPrincipal* aPrincipal)
|
2013-09-27 09:22:37 +04:00
|
|
|
{
|
2015-09-30 01:55:21 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-04-02 20:49:01 +03:00
|
|
|
MOZ_ASSERT(!GetStateMachine());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-03-02 13:03:20 +03:00
|
|
|
|
2017-06-23 10:39:57 +03:00
|
|
|
mResource = new MediaSourceResource(aPrincipal);
|
|
|
|
|
2017-03-02 13:03:20 +03:00
|
|
|
nsresult rv = MediaShutdownManager::Instance().Register(this);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-04-02 20:49:01 +03:00
|
|
|
SetStateMachine(CreateStateMachine());
|
|
|
|
if (!GetStateMachine()) {
|
2014-02-18 02:53:51 +04:00
|
|
|
NS_WARNING("Failed to create state machine!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:03:20 +03:00
|
|
|
rv = GetStateMachine()->Init(this);
|
2014-08-05 18:55:02 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
SetStateMachineParameters();
|
2015-07-23 13:39:09 +03:00
|
|
|
return NS_OK;
|
2013-09-27 09:22:37 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals
|
|
|
|
MediaSourceDecoder::GetSeekable()
|
2013-10-05 12:04:39 +04:00
|
|
|
{
|
2014-08-25 08:09:44 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2014-08-25 08:09:44 +04:00
|
|
|
if (!mMediaSource) {
|
2015-05-18 09:15:47 +03:00
|
|
|
NS_WARNING("MediaSource element isn't attached");
|
|
|
|
return media::TimeIntervals::Invalid();
|
2014-08-25 08:09:44 +04:00
|
|
|
}
|
2014-09-16 07:15:55 +04:00
|
|
|
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals seekable;
|
2013-10-05 12:04:39 +04:00
|
|
|
double duration = mMediaSource->Duration();
|
|
|
|
if (IsNaN(duration)) {
|
|
|
|
// Return empty range.
|
|
|
|
} else if (duration > 0 && mozilla::IsInfinite(duration)) {
|
2015-06-18 00:22:10 +03:00
|
|
|
media::TimeIntervals buffered = GetBuffered();
|
2016-07-14 07:34:45 +03: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 09:15:47 +03:00
|
|
|
if (buffered.Length()) {
|
2017-04-17 11:35:04 +03:00
|
|
|
seekable += media::TimeInterval(TimeUnit::Zero(), buffered.GetEnd());
|
2015-05-18 09:15:47 +03:00
|
|
|
}
|
2013-10-05 12:04:39 +04:00
|
|
|
} else {
|
2017-04-17 11:35:04 +03:00
|
|
|
seekable += media::TimeInterval(TimeUnit::Zero(),
|
|
|
|
TimeUnit::FromSeconds(duration));
|
2013-10-05 12:04:39 +04:00
|
|
|
}
|
2015-05-18 09:15:47 +03:00
|
|
|
MSE_DEBUG("ranges=%s", DumpTimeRanges(seekable).get());
|
|
|
|
return seekable;
|
2013-10-05 12:04:39 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 00:22:10 +03:00
|
|
|
media::TimeIntervals
|
|
|
|
MediaSourceDecoder::GetBuffered()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-06-18 00:22:10 +03:00
|
|
|
|
2016-08-12 13:56:45 +03:00
|
|
|
if (!mMediaSource) {
|
|
|
|
NS_WARNING("MediaSource element isn't attached");
|
|
|
|
return media::TimeIntervals::Invalid();
|
|
|
|
}
|
2015-06-18 00:22:10 +03:00
|
|
|
dom::SourceBufferList* sourceBuffers = mMediaSource->ActiveSourceBuffers();
|
2015-12-02 04:59:18 +03:00
|
|
|
if (!sourceBuffers) {
|
|
|
|
// Media source object is shutting down.
|
|
|
|
return TimeIntervals();
|
|
|
|
}
|
2017-04-17 11:35:04 +03:00
|
|
|
TimeUnit highestEndTime;
|
2015-06-18 00:22:10 +03: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 11:35:04 +03:00
|
|
|
buffered += media::TimeInterval(TimeUnit::Zero(), highestEndTime);
|
2015-06-18 00:22:10 +03: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 11:13:25 +03:00
|
|
|
void
|
2014-08-25 08:09:44 +04:00
|
|
|
MediaSourceDecoder::Shutdown()
|
|
|
|
{
|
2015-09-30 01:55:21 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-02-12 10:52:13 +03:00
|
|
|
MSE_DEBUG("Shutdown");
|
2014-11-04 07:24:52 +03:00
|
|
|
// Detach first so that TrackBuffers are unused on the main thread when
|
|
|
|
// shut down on the decode task queue.
|
2014-08-28 07:44:58 +04:00
|
|
|
if (mMediaSource) {
|
|
|
|
mMediaSource->Detach();
|
|
|
|
}
|
2015-07-14 06:12:29 +03:00
|
|
|
mDemuxer = nullptr;
|
2014-11-04 07:24:52 +03:00
|
|
|
|
2016-05-04 11:13:25 +03:00
|
|
|
MediaDecoder::Shutdown();
|
2014-08-25 08:09:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
void
|
2013-11-18 08:22:47 +04:00
|
|
|
MediaSourceDecoder::AttachMediaSource(dom::MediaSource* aMediaSource)
|
2013-09-27 09:22:37 +04:00
|
|
|
{
|
2015-04-02 20:49:01 +03:00
|
|
|
MOZ_ASSERT(!mMediaSource && !GetStateMachine() && NS_IsMainThread());
|
2013-09-27 09:22:37 +04:00
|
|
|
mMediaSource = aMediaSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaSourceDecoder::DetachMediaSource()
|
|
|
|
{
|
2014-08-25 08:09:44 +04:00
|
|
|
MOZ_ASSERT(mMediaSource && NS_IsMainThread());
|
2013-09-27 09:22:37 +04:00
|
|
|
mMediaSource = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-26 11:25:09 +04:00
|
|
|
void
|
2015-03-23 13:08:05 +03:00
|
|
|
MediaSourceDecoder::Ended(bool aEnded)
|
2014-08-26 11:25:09 +04:00
|
|
|
{
|
2015-09-30 01:55:21 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-08-04 22:33:53 +03:00
|
|
|
mResource->SetEnded(aEnded);
|
2016-08-08 06:56:38 +03:00
|
|
|
if (aEnded) {
|
|
|
|
// We want the MediaSourceReader to refresh its buffered range as it may
|
|
|
|
// have been modified (end lined up).
|
|
|
|
NotifyDataArrived();
|
|
|
|
}
|
|
|
|
mEnded = aEnded;
|
2014-08-26 11:25:09 +04:00
|
|
|
}
|
|
|
|
|
2015-08-21 01:10:33 +03:00
|
|
|
void
|
|
|
|
MediaSourceDecoder::AddSizeOfResources(ResourceSizes* aSizes)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-08-21 01:10:33 +03:00
|
|
|
if (GetDemuxer()) {
|
|
|
|
GetDemuxer()->AddSizeOfResources(aSizes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 07:11:33 +03:00
|
|
|
void
|
2015-02-04 12:20:15 +03:00
|
|
|
MediaSourceDecoder::SetInitialDuration(int64_t aDuration)
|
2014-11-12 07:11:33 +03:00
|
|
|
{
|
2015-06-03 00:18:47 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2014-11-12 07:11:33 +03:00
|
|
|
// Only use the decoded duration if one wasn't already
|
|
|
|
// set.
|
2015-06-03 00:44:26 +03:00
|
|
|
if (!mMediaSource || !IsNaN(ExplicitDuration())) {
|
2014-08-25 08:09:44 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-11-12 07:11:33 +03:00
|
|
|
double duration = aDuration;
|
2015-01-16 15:49:01 +03:00
|
|
|
// A duration of -1 is +Infinity.
|
|
|
|
if (aDuration >= 0) {
|
|
|
|
duration /= USECS_PER_S;
|
|
|
|
}
|
2016-07-15 16:38:33 +03:00
|
|
|
SetMediaSourceDuration(duration);
|
2014-11-12 07:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-15 16:38:33 +03:00
|
|
|
MediaSourceDecoder::SetMediaSourceDuration(double aDuration)
|
2014-11-12 07:11:33 +03:00
|
|
|
{
|
2015-06-03 00:18:47 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-07-28 10:52:30 +03:00
|
|
|
MOZ_ASSERT(!IsShutdown());
|
2015-01-16 15:49:01 +03:00
|
|
|
if (aDuration >= 0) {
|
2015-02-12 10:52:12 +03: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-03 00:44:26 +03:00
|
|
|
SetExplicitDuration(aDuration);
|
2015-01-16 15:49:01 +03:00
|
|
|
} else {
|
2015-06-03 00:44:26 +03:00
|
|
|
SetExplicitDuration(PositiveInfinity<double>());
|
2015-01-16 15:49:01 +03:00
|
|
|
}
|
2014-08-25 08:09:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-29 05:35:58 +03:00
|
|
|
void
|
2017-01-18 11:51:31 +03:00
|
|
|
MediaSourceDecoder::GetMozDebugReaderData(nsACString& aString)
|
2015-01-29 05:35:58 +03:00
|
|
|
{
|
2016-01-18 07:34:07 +03:00
|
|
|
if (mReader && mDemuxer) {
|
2017-07-19 12:01:32 +03:00
|
|
|
mReader->GetMozDebugReaderData(aString);
|
2016-01-18 07:34:07 +03:00
|
|
|
mDemuxer->GetMozDebugReaderData(aString);
|
|
|
|
}
|
2015-01-29 05:35:58 +03:00
|
|
|
}
|
|
|
|
|
2015-02-12 10:52:12 +03:00
|
|
|
double
|
|
|
|
MediaSourceDecoder::GetDuration()
|
|
|
|
{
|
2015-09-30 01:55:21 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2015-06-03 00:44:26 +03:00
|
|
|
return ExplicitDuration();
|
2015-02-12 10:52:12 +03:00
|
|
|
}
|
|
|
|
|
2015-12-02 05:01:40 +03:00
|
|
|
MediaDecoderOwner::NextFrameStatus
|
|
|
|
MediaSourceDecoder::NextFrameBufferedStatus()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-02-10 09:06:18 +03:00
|
|
|
|
2017-02-07 11:23:34 +03:00
|
|
|
if (!mMediaSource
|
|
|
|
|| mMediaSource->ReadyState() == dom::MediaSourceReadyState::Closed) {
|
2016-02-10 09:06:18 +03:00
|
|
|
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-12-02 05:01:40 +03:00
|
|
|
// Next frame hasn't been decoded yet.
|
|
|
|
// Use the buffered range to consider if we have the next frame available.
|
2017-04-17 12:04:39 +03:00
|
|
|
auto currentPosition = CurrentPosition();
|
2016-08-27 13:27:22 +03:00
|
|
|
TimeIntervals buffered = GetBuffered();
|
|
|
|
buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
|
|
|
|
TimeInterval interval(
|
|
|
|
currentPosition,
|
2017-04-17 11:58:44 +03:00
|
|
|
currentPosition + DEFAULT_NEXT_FRAME_AVAILABLE_BUFFERED);
|
2017-08-16 20:35:27 +03:00
|
|
|
return buffered.ContainsWithStrictEnd(ClampIntervalToEnd(interval))
|
2017-01-27 15:20:37 +03:00
|
|
|
? MediaDecoderOwner::NEXT_FRAME_AVAILABLE
|
|
|
|
: MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
|
2015-12-02 05:01:40 +03:00
|
|
|
}
|
|
|
|
|
2015-12-02 07:09:47 +03:00
|
|
|
bool
|
2017-08-04 12:38:20 +03:00
|
|
|
MediaSourceDecoder::CanPlayThroughImpl()
|
2015-12-02 07:09:47 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-03-22 02:34:30 +03:00
|
|
|
|
|
|
|
if (NextFrameBufferedStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-02 07:09:47 +03:00
|
|
|
if (IsNaN(mMediaSource->Duration())) {
|
|
|
|
// Don't have any data yet.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TimeUnit duration = TimeUnit::FromSeconds(mMediaSource->Duration());
|
2017-04-17 12:04:39 +03:00
|
|
|
auto currentPosition = CurrentPosition();
|
2015-12-02 07:09:47 +03:00
|
|
|
if (duration.IsInfinite()) {
|
2017-02-07 11:23:34 +03:00
|
|
|
// We can't make an informed decision and just assume that it's a live
|
|
|
|
// stream
|
2015-12-02 07:09:47 +03:00
|
|
|
return true;
|
|
|
|
} else if (duration <= currentPosition) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-07-20 21:49:06 +03:00
|
|
|
// If we have data up to the mediasource's duration or 10s ahead, we can
|
2015-12-02 07:09:47 +03:00
|
|
|
// assume that we can play without interruption.
|
2016-08-27 13:27:22 +03:00
|
|
|
TimeIntervals buffered = GetBuffered();
|
|
|
|
buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
|
2015-12-02 07:09:47 +03:00
|
|
|
TimeUnit timeAhead =
|
2017-07-20 21:49:06 +03:00
|
|
|
std::min(duration, currentPosition + TimeUnit::FromSeconds(10));
|
2016-08-27 13:27:22 +03:00
|
|
|
TimeInterval interval(currentPosition, timeAhead);
|
2017-08-16 20:35:27 +03:00
|
|
|
return buffered.ContainsWithStrictEnd(ClampIntervalToEnd(interval));
|
2016-05-02 08:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeInterval
|
|
|
|
MediaSourceDecoder::ClampIntervalToEnd(const TimeInterval& aInterval)
|
|
|
|
{
|
2016-08-08 06:56:38 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2016-08-08 06:56:38 +03:00
|
|
|
|
2016-05-02 08:21:40 +03:00
|
|
|
if (!mEnded) {
|
|
|
|
return aInterval;
|
|
|
|
}
|
2016-08-27 13:27:22 +03: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 07:09:47 +03:00
|
|
|
}
|
|
|
|
|
2017-04-27 20:53:53 +03:00
|
|
|
void
|
|
|
|
MediaSourceDecoder::NotifyInitDataArrived()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
2017-04-27 20:53:53 +03:00
|
|
|
|
|
|
|
if (mDemuxer) {
|
|
|
|
mDemuxer->NotifyInitDataArrived();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:52:13 +03:00
|
|
|
#undef MSE_DEBUG
|
|
|
|
#undef MSE_DEBUGV
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
} // namespace mozilla
|