2013-06-21 07:14:42 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_SourceBuffer_h_
|
|
|
|
#define mozilla_dom_SourceBuffer_h_
|
|
|
|
|
|
|
|
#include "MediaSource.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2013-06-21 07:14:42 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-09-04 05:57:06 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-06-21 07:14:42 +04:00
|
|
|
#include "mozilla/dom/SourceBufferBinding.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-06-21 07:14:42 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2013-06-21 07:14:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "nsISupports.h"
|
2014-08-20 12:14:00 +04:00
|
|
|
#include "nsString.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
class JSObject;
|
|
|
|
struct JSContext;
|
2013-06-21 07:14:42 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
class ErrorResult;
|
2014-09-04 05:57:06 +04:00
|
|
|
class TrackBuffer;
|
2013-09-27 09:22:37 +04:00
|
|
|
template <typename T> class AsyncEventRunner;
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
class TimeRanges;
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper
|
2013-06-21 07:14:42 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** WebIDL Methods. */
|
|
|
|
SourceBufferAppendMode Mode() const
|
|
|
|
{
|
|
|
|
return mAppendMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool Updating() const
|
|
|
|
{
|
|
|
|
return mUpdating;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> GetBuffered(ErrorResult& aRv);
|
|
|
|
|
|
|
|
double TimestampOffset() const
|
|
|
|
{
|
|
|
|
return mTimestampOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv);
|
|
|
|
|
|
|
|
double AppendWindowStart() const
|
|
|
|
{
|
|
|
|
return mAppendWindowStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv);
|
|
|
|
|
|
|
|
double AppendWindowEnd() const
|
|
|
|
{
|
|
|
|
return mAppendWindowEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv);
|
|
|
|
|
2013-08-05 21:40:01 +04:00
|
|
|
void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv);
|
|
|
|
void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv);
|
2013-06-21 07:14:42 +04:00
|
|
|
|
|
|
|
void Abort(ErrorResult& aRv);
|
2015-01-24 13:45:55 +03:00
|
|
|
void Abort();
|
2013-06-21 07:14:42 +04:00
|
|
|
|
|
|
|
void Remove(double aStart, double aEnd, ErrorResult& aRv);
|
|
|
|
/** End WebIDL Methods. */
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper)
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2014-08-19 09:13:27 +04:00
|
|
|
SourceBuffer(MediaSource* aMediaSource, const nsACString& aType);
|
2013-06-21 07:14:42 +04:00
|
|
|
|
|
|
|
MediaSource* GetParentObject() const;
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
// Notify the SourceBuffer that it has been detached from the
|
|
|
|
// MediaSource's sourceBuffer list.
|
2013-06-21 07:14:42 +04:00
|
|
|
void Detach();
|
2013-09-27 09:22:37 +04:00
|
|
|
bool IsAttached() const
|
|
|
|
{
|
|
|
|
return mMediaSource != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ended();
|
2013-06-21 07:14:42 +04:00
|
|
|
|
2014-02-28 04:54:48 +04:00
|
|
|
// Evict data in the source buffer in the given time range.
|
|
|
|
void Evict(double aStart, double aEnd);
|
|
|
|
|
2014-08-11 08:32:21 +04:00
|
|
|
double GetBufferedStart();
|
|
|
|
double GetBufferedEnd();
|
2014-08-11 05:21:18 +04:00
|
|
|
|
2014-11-19 07:16:41 +03:00
|
|
|
// Runs the range removal algorithm as defined by the MSE spec.
|
2015-01-24 13:45:58 +03:00
|
|
|
// RangeRemoval will queue a call to DoRangeRemoval.
|
2014-11-19 07:16:41 +03:00
|
|
|
void RangeRemoval(double aStart, double aEnd);
|
2015-01-24 13:45:58 +03:00
|
|
|
void DoRangeRemoval(double aStart, double aEnd);
|
2014-11-19 07:16:41 +03:00
|
|
|
|
2014-09-12 02:47:06 +04:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Dump(const char* aPath);
|
|
|
|
#endif
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
private:
|
2014-07-09 01:23:16 +04:00
|
|
|
~SourceBuffer();
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
friend class AsyncEventRunner<SourceBuffer>;
|
2013-06-21 07:14:42 +04:00
|
|
|
void DispatchSimpleEvent(const char* aName);
|
|
|
|
void QueueAsyncSimpleEvent(const char* aName);
|
|
|
|
|
|
|
|
// Update mUpdating and fire the appropriate events.
|
|
|
|
void StartUpdating();
|
|
|
|
void StopUpdating();
|
|
|
|
void AbortUpdating();
|
|
|
|
|
2015-01-09 04:34:41 +03:00
|
|
|
// If the media segment contains data beyond the current duration,
|
|
|
|
// then run the duration change algorithm with new duration set to the
|
|
|
|
// maximum of the current duration and the group end timestamp.
|
|
|
|
void CheckEndTime();
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
// Shared implementation of AppendBuffer overloads.
|
|
|
|
void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv);
|
|
|
|
|
2015-01-16 15:48:25 +03:00
|
|
|
// Implement the "Append Error Algorithm".
|
|
|
|
// Will call endOfStream() with "decode" error if aDecodeError is true.
|
|
|
|
// 3.5.3 Append Error Algorithm
|
|
|
|
// http://w3c.github.io/media-source/#sourcebuffer-append-error
|
|
|
|
void AppendError(bool aDecoderError);
|
|
|
|
|
2014-09-10 08:54:20 +04:00
|
|
|
// Implements the "Prepare Append Algorithm". Returns true if the append
|
|
|
|
// may continue, or false (with aRv set) on error.
|
|
|
|
bool PrepareAppend(ErrorResult& aRv);
|
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
nsRefPtr<MediaSource> mMediaSource;
|
|
|
|
|
2014-09-09 13:39:00 +04:00
|
|
|
uint32_t mEvictionThreshold;
|
|
|
|
|
2014-09-04 05:57:06 +04:00
|
|
|
nsRefPtr<TrackBuffer> mTrackBuffer;
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
double mAppendWindowStart;
|
|
|
|
double mAppendWindowEnd;
|
|
|
|
|
|
|
|
double mTimestampOffset;
|
|
|
|
|
|
|
|
SourceBufferAppendMode mAppendMode;
|
|
|
|
bool mUpdating;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2013-06-21 07:14:42 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
#endif /* mozilla_dom_SourceBuffer_h_ */
|