2013-06-20 20:14:42 -07: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_
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "MediaDecoderReader.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "MediaSource.h"
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/SourceBufferBinding.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
class JSObject;
|
|
|
|
struct JSContext;
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-09-26 22:22:37 -07:00
|
|
|
|
2014-04-21 06:31:00 -07:00
|
|
|
class ContainerParser;
|
2013-09-26 22:22:37 -07:00
|
|
|
class ErrorResult;
|
|
|
|
class SourceBufferResource;
|
|
|
|
class SubBufferDecoder;
|
2013-09-26 22:22:37 -07:00
|
|
|
template <typename T> class AsyncEventRunner;
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
class TimeRanges;
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper
|
2013-06-20 20:14:42 -07: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 10:40:01 -07:00
|
|
|
void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv);
|
|
|
|
void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv);
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
void Abort(ErrorResult& aRv);
|
|
|
|
|
|
|
|
void Remove(double aStart, double aEnd, ErrorResult& aRv);
|
|
|
|
/** End WebIDL Methods. */
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper)
|
2013-06-20 20:14:42 -07:00
|
|
|
|
2014-04-21 06:31:00 -07:00
|
|
|
static already_AddRefed<SourceBuffer> Create(MediaSource* aMediaSource, const nsACString& aType);
|
2013-09-26 22:22:37 -07:00
|
|
|
~SourceBuffer();
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
MediaSource* GetParentObject() const;
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-06-20 20:14:42 -07:00
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
// Notify the SourceBuffer that it has been detached from the
|
|
|
|
// MediaSource's sourceBuffer list.
|
2013-06-20 20:14:42 -07:00
|
|
|
void Detach();
|
2013-09-26 22:22:37 -07:00
|
|
|
bool IsAttached() const
|
|
|
|
{
|
|
|
|
return mMediaSource != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ended();
|
2013-06-20 20:14:42 -07:00
|
|
|
|
2014-02-27 16:54:48 -08:00
|
|
|
// Evict data in the source buffer in the given time range.
|
|
|
|
void Evict(double aStart, double aEnd);
|
|
|
|
|
2014-04-23 00:45:00 -07:00
|
|
|
// Returns true if the data in the source buffer contains the given time.
|
|
|
|
bool ContainsTime(double aTime);
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
private:
|
2014-04-21 06:31:00 -07:00
|
|
|
SourceBuffer(MediaSource* aMediaSource, const nsACString& aType);
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
friend class AsyncEventRunner<SourceBuffer>;
|
2013-06-20 20:14:42 -07:00
|
|
|
void DispatchSimpleEvent(const char* aName);
|
|
|
|
void QueueAsyncSimpleEvent(const char* aName);
|
|
|
|
|
2014-04-14 04:24:00 -07:00
|
|
|
// Create a new decoder for mType, add it to mDecoders and update mCurrentDecoder.
|
|
|
|
bool InitNewDecoder();
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
// Update mUpdating and fire the appropriate events.
|
|
|
|
void StartUpdating();
|
|
|
|
void StopUpdating();
|
|
|
|
void AbortUpdating();
|
|
|
|
|
|
|
|
// Shared implementation of AppendBuffer overloads.
|
|
|
|
void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv);
|
|
|
|
|
2014-02-27 16:54:48 -08:00
|
|
|
// Provide the minimum start time and maximum end time that is available
|
|
|
|
// in the data buffered by this SourceBuffer.
|
|
|
|
void GetBufferedStartEndTime(double* aStart, double* aEnd);
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
nsRefPtr<MediaSource> mMediaSource;
|
|
|
|
|
2014-04-14 04:24:00 -07:00
|
|
|
const nsAutoCString mType;
|
|
|
|
|
2014-04-21 06:31:00 -07:00
|
|
|
nsAutoPtr<ContainerParser> mParser;
|
|
|
|
|
2014-04-14 04:24:00 -07:00
|
|
|
// XXX: We only want to keep the current decoder alive, but need a way to
|
|
|
|
// query @buffered for everything this SourceBuffer is responsible for.
|
|
|
|
nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;
|
|
|
|
nsRefPtr<SubBufferDecoder> mCurrentDecoder;
|
2013-09-26 22:22:37 -07:00
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
double mAppendWindowStart;
|
|
|
|
double mAppendWindowEnd;
|
|
|
|
|
|
|
|
double mTimestampOffset;
|
|
|
|
|
|
|
|
SourceBufferAppendMode mAppendMode;
|
|
|
|
bool mUpdating;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
2013-09-26 22:22:37 -07:00
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
#endif /* mozilla_dom_SourceBuffer_h_ */
|