2014-09-11 22:47:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-06-21 03:14:42 +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 "SourceBuffer.h"
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "AsyncEventRunner.h"
|
2015-01-26 15:01:09 +00:00
|
|
|
#include "MediaData.h"
|
2015-07-22 01:09:21 +00:00
|
|
|
#include "MediaSourceDemuxer.h"
|
2014-08-20 08:07:00 +00:00
|
|
|
#include "MediaSourceUtils.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/FloatingPoint.h"
|
2014-09-04 01:57:06 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "mozilla/dom/MediaSourceBinding.h"
|
|
|
|
#include "mozilla/dom/TimeRanges.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2015-01-26 10:33:56 +00:00
|
|
|
#include <time.h>
|
2015-03-03 04:38:45 +00:00
|
|
|
#include "TimeUnits.h"
|
2014-08-19 05:13:27 +00:00
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
|
|
|
|
2014-08-11 01:21:17 +00:00
|
|
|
extern PRLogModuleInfo* GetMediaSourceLog();
|
|
|
|
extern PRLogModuleInfo* GetMediaSourceAPILog();
|
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
|
|
|
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
|
|
|
#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
2013-06-21 03:14:42 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2015-07-22 01:09:21 +00:00
|
|
|
using media::TimeUnit;
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
namespace dom {
|
|
|
|
|
2015-06-11 05:49:50 +00:00
|
|
|
class BufferAppendRunnable : public nsRunnable {
|
2015-01-26 10:33:56 +00:00
|
|
|
public:
|
2015-06-11 05:49:50 +00:00
|
|
|
BufferAppendRunnable(SourceBuffer* aSourceBuffer,
|
|
|
|
uint32_t aUpdateID)
|
2015-01-26 10:33:56 +00:00
|
|
|
: mSourceBuffer(aSourceBuffer)
|
2015-02-04 09:20:16 +00:00
|
|
|
, mUpdateID(aUpdateID)
|
2015-01-26 10:33:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override final {
|
2015-01-26 10:33:56 +00:00
|
|
|
|
2015-06-11 05:49:50 +00:00
|
|
|
mSourceBuffer->BufferAppend(mUpdateID);
|
2015-01-26 10:33:56 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<SourceBuffer> mSourceBuffer;
|
2015-02-04 09:20:16 +00:00
|
|
|
uint32_t mUpdateID;
|
2015-01-26 10:33:56 +00:00
|
|
|
};
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv)
|
|
|
|
{
|
2015-06-11 05:55:20 +00:00
|
|
|
typedef mozilla::SourceBufferContentManager::AppendState AppendState;
|
|
|
|
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("SetMode(aMode=%d)", aMode);
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached() || mUpdating) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-14 07:52:30 +00:00
|
|
|
if (mAttributes->mGenerateTimestamps &&
|
2015-06-11 05:55:20 +00:00
|
|
|
aMode == SourceBufferAppendMode::Segments) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-27 05:22:37 +00:00
|
|
|
MOZ_ASSERT(mMediaSource->ReadyState() != MediaSourceReadyState::Closed);
|
2013-06-21 03:14:42 +00:00
|
|
|
if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
|
|
|
|
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
|
|
|
|
}
|
2015-09-14 07:52:30 +00:00
|
|
|
if (mContentManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
|
2015-06-11 05:55:20 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-14 07:52:30 +00:00
|
|
|
if (aMode == SourceBufferAppendMode::Sequence) {
|
2015-06-11 05:55:20 +00:00
|
|
|
// Will set GroupStartTimestamp to GroupEndTimestamp.
|
|
|
|
mContentManager->RestartGroupStartTimestamp();
|
|
|
|
}
|
|
|
|
|
2015-08-04 03:25:47 +00:00
|
|
|
mAttributes->SetAppendMode(aMode);
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv)
|
|
|
|
{
|
2015-06-11 05:55:20 +00:00
|
|
|
typedef mozilla::SourceBufferContentManager::AppendState AppendState;
|
|
|
|
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("SetTimestampOffset(aTimestampOffset=%f)", aTimestampOffset);
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached() || mUpdating) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-27 05:22:37 +00:00
|
|
|
MOZ_ASSERT(mMediaSource->ReadyState() != MediaSourceReadyState::Closed);
|
2013-06-21 03:14:42 +00:00
|
|
|
if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
|
|
|
|
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
|
|
|
|
}
|
2015-09-14 07:52:30 +00:00
|
|
|
if (mContentManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
|
2015-06-11 05:55:20 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
mAttributes->SetApparentTimestampOffset(aTimestampOffset);
|
2015-09-14 07:52:30 +00:00
|
|
|
if (mAttributes->GetAppendMode() == SourceBufferAppendMode::Sequence) {
|
2015-08-04 03:25:47 +00:00
|
|
|
mContentManager->SetGroupStartTimestamp(mAttributes->GetTimestampOffset());
|
2015-06-11 05:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
already_AddRefed<TimeRanges>
|
|
|
|
SourceBuffer::GetBuffered(ErrorResult& aRv)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached()) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-22 01:09:21 +00:00
|
|
|
media::TimeIntervals ranges = mContentManager->Buffered();
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUGV("ranges=%s", DumpTimeRanges(ranges).get());
|
2015-05-18 06:15:47 +00:00
|
|
|
nsRefPtr<dom::TimeRanges> tr = new dom::TimeRanges();
|
|
|
|
ranges.ToTimeRanges(tr);
|
|
|
|
return tr.forget();
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 21:22:10 +00:00
|
|
|
media::TimeIntervals
|
|
|
|
SourceBuffer::GetTimeIntervals()
|
|
|
|
{
|
|
|
|
return mContentManager->Buffered();
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("SetAppendWindowStart(aAppendWindowStart=%f)", aAppendWindowStart);
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached() || mUpdating) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
if (aAppendWindowStart < 0 ||
|
|
|
|
aAppendWindowStart >= mAttributes->GetAppendWindowEnd()) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
mAttributes->SetAppendWindowStart(aAppendWindowStart);
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("SetAppendWindowEnd(aAppendWindowEnd=%f)", aAppendWindowEnd);
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached() || mUpdating) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
if (IsNaN(aAppendWindowEnd) ||
|
|
|
|
aAppendWindowEnd <= mAttributes->GetAppendWindowStart()) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
mAttributes->SetAppendWindowEnd(aAppendWindowEnd);
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-05 17:40:01 +00:00
|
|
|
SourceBuffer::AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv)
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("AppendBuffer(ArrayBuffer)");
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-27 21:32:41 +00:00
|
|
|
aData.ComputeLengthAndData();
|
2013-06-21 03:14:42 +00:00
|
|
|
AppendData(aData.Data(), aData.Length(), aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-05 17:40:01 +00:00
|
|
|
SourceBuffer::AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv)
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("AppendBuffer(ArrayBufferView)");
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-27 21:32:41 +00:00
|
|
|
aData.ComputeLengthAndData();
|
2013-06-21 03:14:42 +00:00
|
|
|
AppendData(aData.Data(), aData.Length(), aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::Abort(ErrorResult& aRv)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("Abort()");
|
2013-09-27 05:22:37 +00:00
|
|
|
if (!IsAttached()) {
|
2013-06-21 03:14:42 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mMediaSource->ReadyState() != MediaSourceReadyState::Open) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-04 09:20:16 +00:00
|
|
|
AbortBufferAppend();
|
2015-06-05 01:52:57 +00:00
|
|
|
mContentManager->ResetParserState();
|
2015-08-04 03:25:47 +00:00
|
|
|
mAttributes->SetAppendWindowStart(0);
|
|
|
|
mAttributes->SetAppendWindowEnd(PositiveInfinity<double>());
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2015-01-24 10:45:55 +00:00
|
|
|
void
|
2015-02-04 09:20:16 +00:00
|
|
|
SourceBuffer::AbortBufferAppend()
|
2015-01-24 10:45:55 +00:00
|
|
|
{
|
|
|
|
if (mUpdating) {
|
2015-02-04 09:20:16 +00:00
|
|
|
mPendingAppend.DisconnectIfExists();
|
2015-06-11 05:55:20 +00:00
|
|
|
// TODO: Abort stream append loop algorithms.
|
2015-02-04 09:20:16 +00:00
|
|
|
// cancel any pending buffer append.
|
2015-06-05 01:52:57 +00:00
|
|
|
mContentManager->AbortAppendData();
|
2015-01-24 10:45:55 +00:00
|
|
|
AbortUpdating();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::Remove(double aStart, double aEnd, ErrorResult& aRv)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("Remove(aStart=%f, aEnd=%f)", aStart, aEnd);
|
2014-08-27 02:24:01 +00:00
|
|
|
if (!IsAttached()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-25 09:35:44 +00:00
|
|
|
if (mUpdating) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-13 13:41:00 +00:00
|
|
|
if (IsNaN(mMediaSource->Duration()) ||
|
|
|
|
aStart < 0 || aStart > mMediaSource->Duration() ||
|
|
|
|
aEnd <= aStart || IsNaN(aEnd)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-19 04:16:41 +00:00
|
|
|
if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
|
|
|
|
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
|
|
|
|
}
|
2015-02-12 07:52:12 +00:00
|
|
|
|
2015-06-11 05:55:12 +00:00
|
|
|
RangeRemoval(aStart, aEnd);
|
2014-11-19 04:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::RangeRemoval(double aStart, double aEnd)
|
|
|
|
{
|
2013-06-21 03:14:42 +00:00
|
|
|
StartUpdating();
|
2015-01-24 10:45:58 +00:00
|
|
|
|
2015-06-11 05:55:12 +00:00
|
|
|
nsRefPtr<SourceBuffer> self = this;
|
|
|
|
mContentManager->RangeRemoval(TimeUnit::FromSeconds(aStart),
|
|
|
|
TimeUnit::FromSeconds(aEnd))
|
|
|
|
->Then(AbstractThread::MainThread(), __func__,
|
|
|
|
[self] (bool) { self->StopUpdating(); },
|
|
|
|
[]() { MOZ_ASSERT(false); });
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-27 05:22:37 +00:00
|
|
|
SourceBuffer::Detach()
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("Detach");
|
2015-06-11 23:26:57 +00:00
|
|
|
if (!mMediaSource) {
|
|
|
|
MSE_DEBUG("Already detached");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-04 09:20:16 +00:00
|
|
|
AbortBufferAppend();
|
2015-06-05 01:52:57 +00:00
|
|
|
if (mContentManager) {
|
|
|
|
mContentManager->Detach();
|
2015-09-14 07:52:30 +00:00
|
|
|
mMediaSource->GetDecoder()->GetDemuxer()->DetachSourceBuffer(
|
|
|
|
static_cast<mozilla::TrackBuffersManager*>(mContentManager.get()));
|
2014-09-04 01:57:06 +00:00
|
|
|
}
|
2015-06-05 01:52:57 +00:00
|
|
|
mContentManager = nullptr;
|
2013-09-27 05:22:37 +00:00
|
|
|
mMediaSource = nullptr;
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-27 05:22:37 +00:00
|
|
|
SourceBuffer::Ended()
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-04 01:57:06 +00:00
|
|
|
MOZ_ASSERT(IsAttached());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("Ended");
|
2015-06-05 01:52:57 +00:00
|
|
|
mContentManager->Ended();
|
2015-06-11 23:26:58 +00:00
|
|
|
// We want the MediaSourceReader to refresh its buffered range as it may
|
|
|
|
// have been modified (end lined up).
|
2015-06-19 20:45:09 +00:00
|
|
|
mMediaSource->GetDecoder()->NotifyDataArrived(1, mReportedOffset++, /* aThrottleUpdates = */ false);
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
|
2014-04-01 06:13:50 +00:00
|
|
|
: DOMEventTargetHelper(aMediaSource->GetParentObject())
|
2013-06-21 03:14:42 +00:00
|
|
|
, mMediaSource(aMediaSource)
|
|
|
|
, mUpdating(false)
|
2015-03-18 03:10:56 +00:00
|
|
|
, mActive(false)
|
2015-02-04 09:20:16 +00:00
|
|
|
, mUpdateID(0)
|
2015-06-11 23:26:57 +00:00
|
|
|
, mReportedOffset(0)
|
2015-02-12 07:52:13 +00:00
|
|
|
, mType(aType)
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 03:14:42 +00:00
|
|
|
MOZ_ASSERT(aMediaSource);
|
2014-09-09 09:39:00 +00:00
|
|
|
mEvictionThreshold = Preferences::GetUint("media.mediasource.eviction_threshold",
|
2015-06-22 21:23:38 +00:00
|
|
|
100 * (1 << 20));
|
2015-08-04 03:25:47 +00:00
|
|
|
bool generateTimestamps = false;
|
|
|
|
if (aType.LowerCaseEqualsLiteral("audio/mpeg") ||
|
|
|
|
aType.LowerCaseEqualsLiteral("audio/aac")) {
|
|
|
|
generateTimestamps = true;
|
|
|
|
}
|
|
|
|
mAttributes = new SourceBufferAttributes(generateTimestamps);
|
|
|
|
|
2015-06-11 05:55:20 +00:00
|
|
|
mContentManager =
|
2015-08-04 03:25:47 +00:00
|
|
|
SourceBufferContentManager::CreateManager(mAttributes,
|
2015-06-11 05:55:20 +00:00
|
|
|
aMediaSource->GetDecoder(),
|
|
|
|
aType);
|
2015-06-05 01:52:57 +00:00
|
|
|
MSE_DEBUG("Create mContentManager=%p",
|
|
|
|
mContentManager.get());
|
2015-08-04 03:25:47 +00:00
|
|
|
|
2015-06-11 05:55:20 +00:00
|
|
|
ErrorResult dummy;
|
2015-08-04 03:25:47 +00:00
|
|
|
if (mAttributes->mGenerateTimestamps) {
|
2015-06-11 05:55:20 +00:00
|
|
|
SetMode(SourceBufferAppendMode::Sequence, dummy);
|
|
|
|
} else {
|
|
|
|
SetMode(SourceBufferAppendMode::Segments, dummy);
|
|
|
|
}
|
2015-09-14 07:52:30 +00:00
|
|
|
mMediaSource->GetDecoder()->GetDemuxer()->AttachSourceBuffer(
|
|
|
|
static_cast<mozilla::TrackBuffersManager*>(mContentManager.get()));
|
2014-04-21 13:31:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
SourceBuffer::~SourceBuffer()
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-04 01:57:06 +00:00
|
|
|
MOZ_ASSERT(!mMediaSource);
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("");
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaSource*
|
|
|
|
SourceBuffer::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mMediaSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
SourceBuffer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return SourceBufferBinding::Wrap(aCx, this, aGivenProto);
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::DispatchSimpleEvent(const char* aName)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_API("Dispatch event '%s'", aName);
|
2013-06-21 03:14:42 +00:00
|
|
|
DispatchTrustedEvent(NS_ConvertUTF8toUTF16(aName));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::QueueAsyncSimpleEvent(const char* aName)
|
|
|
|
{
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("Queuing event '%s'", aName);
|
2013-09-27 05:22:37 +00:00
|
|
|
nsCOMPtr<nsIRunnable> event = new AsyncEventRunner<SourceBuffer>(this, aName);
|
2013-06-21 03:14:42 +00:00
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::StartUpdating()
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 03:14:42 +00:00
|
|
|
MOZ_ASSERT(!mUpdating);
|
|
|
|
mUpdating = true;
|
2015-02-04 09:20:16 +00:00
|
|
|
mUpdateID++;
|
2013-06-21 03:14:42 +00:00
|
|
|
QueueAsyncSimpleEvent("updatestart");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::StopUpdating()
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-23 03:47:30 +00:00
|
|
|
if (!mUpdating) {
|
|
|
|
// The buffer append algorithm has been interrupted by abort().
|
|
|
|
//
|
|
|
|
// If the sequence appendBuffer(), abort(), appendBuffer() occurs before
|
|
|
|
// the first StopUpdating() runnable runs, then a second StopUpdating()
|
|
|
|
// runnable will be scheduled, but still only one (the first) will queue
|
|
|
|
// events.
|
|
|
|
return;
|
|
|
|
}
|
2013-06-21 03:14:42 +00:00
|
|
|
mUpdating = false;
|
|
|
|
QueueAsyncSimpleEvent("update");
|
|
|
|
QueueAsyncSimpleEvent("updateend");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::AbortUpdating()
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-06-21 03:14:42 +00:00
|
|
|
MOZ_ASSERT(mUpdating);
|
|
|
|
mUpdating = false;
|
|
|
|
QueueAsyncSimpleEvent("abort");
|
|
|
|
QueueAsyncSimpleEvent("updateend");
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:34:41 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::CheckEndTime()
|
|
|
|
{
|
2015-02-04 09:20:15 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-09 01:34:41 +00:00
|
|
|
// Check if we need to update mMediaSource duration
|
2015-06-24 20:30:15 +00:00
|
|
|
double endTime = mContentManager->GroupEndTimestamp().ToSeconds();
|
2015-02-04 09:20:15 +00:00
|
|
|
double duration = mMediaSource->Duration();
|
|
|
|
if (endTime > duration) {
|
2015-01-16 12:49:02 +00:00
|
|
|
mMediaSource->SetDuration(endTime, MSRangeRemovalAction::SKIP);
|
2015-01-09 01:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
|
|
|
|
{
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("AppendData(aLength=%u)", aLength);
|
2015-01-26 15:01:09 +00:00
|
|
|
|
2015-06-15 04:37:13 +00:00
|
|
|
nsRefPtr<MediaByteBuffer> data = PrepareAppend(aData, aLength, aRv);
|
2015-01-26 15:01:09 +00:00
|
|
|
if (!data) {
|
2013-06-21 03:14:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-08-04 03:25:47 +00:00
|
|
|
mContentManager->AppendData(data, mAttributes->GetTimestampOffset());
|
2015-06-11 05:49:50 +00:00
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
StartUpdating();
|
2014-09-17 06:33:00 +00:00
|
|
|
|
2015-06-11 05:49:50 +00:00
|
|
|
nsCOMPtr<nsIRunnable> task = new BufferAppendRunnable(this, mUpdateID);
|
2015-01-26 10:33:56 +00:00
|
|
|
NS_DispatchToMainThread(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-06-11 05:49:50 +00:00
|
|
|
SourceBuffer::BufferAppend(uint32_t aUpdateID)
|
2015-01-26 10:33:56 +00:00
|
|
|
{
|
2015-02-04 09:20:16 +00:00
|
|
|
if (!mUpdating || aUpdateID != mUpdateID) {
|
2015-01-26 10:33:56 +00:00
|
|
|
// The buffer append algorithm has been interrupted by abort().
|
|
|
|
//
|
|
|
|
// If the sequence appendBuffer(), abort(), appendBuffer() occurs before
|
|
|
|
// the first StopUpdating() runnable runs, then a second StopUpdating()
|
|
|
|
// runnable will be scheduled, but still only one (the first) will queue
|
|
|
|
// events.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mMediaSource);
|
2015-02-04 09:20:16 +00:00
|
|
|
MOZ_ASSERT(!mPendingAppend.Exists());
|
2015-01-26 10:33:56 +00:00
|
|
|
|
2015-06-11 05:49:50 +00:00
|
|
|
mPendingAppend.Begin(mContentManager->BufferAppend()
|
2015-05-22 19:28:20 +00:00
|
|
|
->Then(AbstractThread::MainThread(), __func__, this,
|
|
|
|
&SourceBuffer::AppendDataCompletedWithSuccess,
|
|
|
|
&SourceBuffer::AppendDataErrored));
|
2015-02-04 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-06-05 01:52:57 +00:00
|
|
|
SourceBuffer::AppendDataCompletedWithSuccess(bool aHasActiveTracks)
|
2015-02-04 09:20:15 +00:00
|
|
|
{
|
2015-02-04 09:20:16 +00:00
|
|
|
mPendingAppend.Complete();
|
2015-02-04 09:20:15 +00:00
|
|
|
if (!mUpdating) {
|
|
|
|
// The buffer append algorithm has been interrupted by abort().
|
|
|
|
return;
|
|
|
|
}
|
2015-01-16 12:48:24 +00:00
|
|
|
|
2015-06-05 01:52:57 +00:00
|
|
|
if (aHasActiveTracks) {
|
2015-03-18 03:10:56 +00:00
|
|
|
if (!mActive) {
|
|
|
|
mActive = true;
|
|
|
|
mMediaSource->SourceBufferIsActive(this);
|
|
|
|
}
|
2015-06-16 05:57:22 +00:00
|
|
|
}
|
2015-09-14 07:52:30 +00:00
|
|
|
if (mActive) {
|
2015-06-11 23:26:57 +00:00
|
|
|
// Tell our parent decoder that we have received new data.
|
|
|
|
// The information provided do not matter much so long as it is monotonically
|
|
|
|
// increasing.
|
2015-06-19 20:45:09 +00:00
|
|
|
mMediaSource->GetDecoder()->NotifyDataArrived(1, mReportedOffset++, /* aThrottleUpdates = */ false);
|
2015-06-20 14:36:39 +00:00
|
|
|
// Send progress event.
|
|
|
|
mMediaSource->GetDecoder()->NotifyBytesDownloaded();
|
2015-02-04 09:20:15 +00:00
|
|
|
}
|
2015-01-16 12:48:24 +00:00
|
|
|
|
2015-06-05 01:52:57 +00:00
|
|
|
CheckEndTime();
|
2014-09-10 04:54:20 +00:00
|
|
|
|
2015-01-26 10:33:56 +00:00
|
|
|
StopUpdating();
|
2015-02-04 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::AppendDataErrored(nsresult aError)
|
|
|
|
{
|
2015-02-04 09:20:16 +00:00
|
|
|
mPendingAppend.Complete();
|
2015-02-04 09:20:16 +00:00
|
|
|
switch (aError) {
|
|
|
|
case NS_ERROR_ABORT:
|
2015-02-04 09:20:16 +00:00
|
|
|
// Nothing further to do as the trackbuffer has been shutdown.
|
|
|
|
// or append was aborted and abort() has handled all the events.
|
2015-02-04 09:20:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AppendError(true);
|
|
|
|
break;
|
|
|
|
}
|
2015-02-04 09:20:15 +00:00
|
|
|
}
|
2014-09-10 04:54:20 +00:00
|
|
|
|
2015-01-16 12:48:25 +00:00
|
|
|
void
|
|
|
|
SourceBuffer::AppendError(bool aDecoderError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!mUpdating) {
|
|
|
|
// The buffer append algorithm has been interrupted by abort().
|
|
|
|
return;
|
|
|
|
}
|
2015-06-05 01:52:57 +00:00
|
|
|
mContentManager->ResetParserState();
|
2015-01-16 12:48:25 +00:00
|
|
|
|
|
|
|
mUpdating = false;
|
|
|
|
|
|
|
|
QueueAsyncSimpleEvent("error");
|
|
|
|
QueueAsyncSimpleEvent("updateend");
|
|
|
|
|
|
|
|
if (aDecoderError) {
|
|
|
|
Optional<MediaSourceEndOfStreamError> decodeError(
|
|
|
|
MediaSourceEndOfStreamError::Decode);
|
|
|
|
ErrorResult dummy;
|
|
|
|
mMediaSource->EndOfStream(decodeError, dummy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 04:37:13 +00:00
|
|
|
already_AddRefed<MediaByteBuffer>
|
2015-01-26 15:01:09 +00:00
|
|
|
SourceBuffer::PrepareAppend(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
|
2014-09-10 04:54:20 +00:00
|
|
|
{
|
2015-06-05 01:52:57 +00:00
|
|
|
typedef SourceBufferContentManager::EvictDataResult Result;
|
|
|
|
|
2014-09-10 04:54:20 +00:00
|
|
|
if (!IsAttached() || mUpdating) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2015-01-26 15:01:09 +00:00
|
|
|
return nullptr;
|
2014-09-10 04:54:20 +00:00
|
|
|
}
|
2015-08-14 02:01:15 +00:00
|
|
|
|
|
|
|
// If the HTMLMediaElement.error attribute is not null, then throw an
|
|
|
|
// InvalidStateError exception and abort these steps.
|
|
|
|
if (!mMediaSource->GetDecoder() ||
|
|
|
|
mMediaSource->GetDecoder()->IsEndedOrShutdown()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-10 04:54:20 +00:00
|
|
|
if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
|
|
|
|
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
|
|
|
|
}
|
|
|
|
|
2014-02-28 00:54:48 +00:00
|
|
|
// Eviction uses a byte threshold. If the buffer is greater than the
|
|
|
|
// number of bytes then data is evicted. The time range for this
|
|
|
|
// eviction is reported back to the media source. It will then
|
2014-08-11 01:21:17 +00:00
|
|
|
// evict data before that range across all SourceBuffers it knows
|
2014-02-28 00:54:48 +00:00
|
|
|
// about.
|
2014-08-11 02:05:09 +00:00
|
|
|
// TODO: Make the eviction threshold smaller for audio-only streams.
|
|
|
|
// TODO: Drive evictions off memory pressure notifications.
|
2014-09-09 09:12:00 +00:00
|
|
|
// TODO: Consider a global eviction threshold rather than per TrackBuffer.
|
2015-06-05 01:53:05 +00:00
|
|
|
TimeUnit newBufferStartTime;
|
2015-01-26 15:01:09 +00:00
|
|
|
// Attempt to evict the amount of data we are about to add by lowering the
|
|
|
|
// threshold.
|
|
|
|
uint32_t toEvict =
|
|
|
|
(mEvictionThreshold > aLength) ? mEvictionThreshold - aLength : aLength;
|
2015-06-05 01:52:57 +00:00
|
|
|
Result evicted =
|
2015-06-05 01:53:05 +00:00
|
|
|
mContentManager->EvictData(TimeUnit::FromSeconds(mMediaSource->GetDecoder()->GetCurrentTime()),
|
2015-06-05 01:52:57 +00:00
|
|
|
toEvict, &newBufferStartTime);
|
|
|
|
if (evicted == Result::DATA_EVICTED) {
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("AppendData Evict; current buffered start=%f",
|
|
|
|
GetBufferedStart());
|
2014-08-11 01:21:17 +00:00
|
|
|
|
2014-02-28 00:54:48 +00:00
|
|
|
// We notify that we've evicted from the time range 0 through to
|
|
|
|
// the current start point.
|
2015-06-05 01:53:05 +00:00
|
|
|
mMediaSource->NotifyEvicted(0.0, newBufferStartTime.ToSeconds());
|
2014-02-28 00:54:48 +00:00
|
|
|
}
|
2014-09-08 22:29:41 +00:00
|
|
|
|
2015-02-20 01:19:13 +00:00
|
|
|
// See if we have enough free space to append our new data.
|
|
|
|
// As we can only evict once we have playable data, we must give a chance
|
|
|
|
// to the DASH player to provide a complete media segment.
|
2015-09-14 07:52:30 +00:00
|
|
|
if (aLength > mEvictionThreshold || evicted == Result::BUFFER_FULL) {
|
2015-02-20 01:19:13 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-15 04:37:13 +00:00
|
|
|
nsRefPtr<MediaByteBuffer> data = new MediaByteBuffer();
|
2015-05-28 18:07:43 +00:00
|
|
|
if (!data->AppendElements(aData, aLength, fallible)) {
|
2015-01-26 15:01:09 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return data.forget();
|
2014-02-28 00:54:48 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 04:32:21 +00:00
|
|
|
double
|
|
|
|
SourceBuffer::GetBufferedStart()
|
2014-02-28 00:54:48 +00:00
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-04-14 11:24:00 +00:00
|
|
|
ErrorResult dummy;
|
|
|
|
nsRefPtr<TimeRanges> ranges = GetBuffered(dummy);
|
2014-08-11 04:32:21 +00:00
|
|
|
return ranges->Length() > 0 ? ranges->GetStartTime() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
SourceBuffer::GetBufferedEnd()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ErrorResult dummy;
|
|
|
|
nsRefPtr<TimeRanges> ranges = GetBuffered(dummy);
|
|
|
|
return ranges->Length() > 0 ? ranges->GetEndTime() : 0;
|
2014-02-28 00:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SourceBuffer::Evict(double aStart, double aEnd)
|
|
|
|
{
|
2014-08-11 01:21:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-02-12 07:52:13 +00:00
|
|
|
MSE_DEBUG("Evict(aStart=%f, aEnd=%f)", aStart, aEnd);
|
2014-08-11 02:05:09 +00:00
|
|
|
double currentTime = mMediaSource->GetDecoder()->GetCurrentTime();
|
|
|
|
double evictTime = aEnd;
|
|
|
|
const double safety_threshold = 5;
|
|
|
|
if (currentTime + safety_threshold >= evictTime) {
|
|
|
|
evictTime -= safety_threshold;
|
2014-02-28 00:54:48 +00:00
|
|
|
}
|
2015-06-05 01:53:05 +00:00
|
|
|
mContentManager->EvictBefore(TimeUnit::FromSeconds(evictTime));
|
2013-06-21 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 22:47:06 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void
|
|
|
|
SourceBuffer::Dump(const char* aPath)
|
|
|
|
{
|
2015-06-05 01:52:57 +00:00
|
|
|
if (mContentManager) {
|
|
|
|
mContentManager->Dump(aPath);
|
2014-09-11 22:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-15 04:02:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SourceBuffer)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(SourceBuffer)
|
|
|
|
// Tell the TrackBuffer to end its current SourceBufferResource.
|
2015-06-05 01:52:57 +00:00
|
|
|
SourceBufferContentManager* manager = tmp->mContentManager;
|
|
|
|
if (manager) {
|
|
|
|
manager->Detach();
|
2014-10-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SourceBuffer,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SourceBuffer, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SourceBuffer, DOMEventTargetHelper)
|
2013-06-21 03:14:42 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SourceBuffer)
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2015-02-12 07:52:13 +00:00
|
|
|
#undef MSE_DEBUG
|
|
|
|
#undef MSE_DEBUGV
|
|
|
|
#undef MSE_API
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
} // namespace dom
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
} // namespace mozilla
|