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_MediaSource_h_
|
|
|
|
#define mozilla_dom_MediaSource_h_
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
#include "MediaSourceDecoder.h"
|
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "mozilla/dom/MediaSourceBinding.h"
|
2013-09-26 22:22:37 -07:00
|
|
|
#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 "nsID.h"
|
|
|
|
#include "nsISupports.h"
|
2013-06-20 20:14:42 -07:00
|
|
|
#include "nscore.h"
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
|
|
|
class nsPIDOMWindow;
|
2013-09-06 10:50:24 -07:00
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
namespace mozilla {
|
2013-09-26 22:22:37 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
template <typename T> class AsyncEventRunner;
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
class GlobalObject;
|
2013-06-20 20:14:42 -07:00
|
|
|
class SourceBuffer;
|
2013-09-26 22:22:37 -07:00
|
|
|
class SourceBufferList;
|
|
|
|
template <typename T> class Optional;
|
2013-06-20 20:14:42 -07:00
|
|
|
|
2013-06-20 20:15:15 -07:00
|
|
|
#define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \
|
|
|
|
{ 0x3839d699, 0x22c5, 0x439f, \
|
|
|
|
{ 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } }
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class MediaSource MOZ_FINAL : public DOMEventTargetHelper
|
2013-06-20 20:14:42 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** WebIDL Methods. */
|
2013-08-22 22:17:08 -07:00
|
|
|
static already_AddRefed<MediaSource>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
SourceBufferList* SourceBuffers();
|
|
|
|
SourceBufferList* ActiveSourceBuffers();
|
|
|
|
MediaSourceReadyState ReadyState();
|
|
|
|
|
|
|
|
double Duration();
|
|
|
|
void SetDuration(double aDuration, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<SourceBuffer> AddSourceBuffer(const nsAString& aType, ErrorResult& aRv);
|
|
|
|
void RemoveSourceBuffer(SourceBuffer& aSourceBuffer, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void EndOfStream(const Optional<MediaSourceEndOfStreamError>& aError, ErrorResult& aRv);
|
2014-03-04 19:35:47 -08:00
|
|
|
static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
|
2013-06-20 20:14:42 -07:00
|
|
|
/** End WebIDL Methods. */
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper)
|
2013-06-20 20:15:15 -07:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() const;
|
|
|
|
|
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
// Attach this MediaSource to Decoder aDecoder. Returns false if already attached.
|
|
|
|
bool Attach(MediaSourceDecoder* aDecoder);
|
|
|
|
void Detach();
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
// Set mReadyState to aState and fire the required events at the MediaSource.
|
|
|
|
void SetReadyState(MediaSourceReadyState aState);
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
// Used by SourceBuffer to call CreateSubDecoder.
|
|
|
|
MediaSourceDecoder* GetDecoder()
|
|
|
|
{
|
|
|
|
return mDecoder;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:54:48 -08:00
|
|
|
// Called by SourceBuffers to notify this MediaSource that data has
|
|
|
|
// been evicted from the buffered data. The start and end times
|
|
|
|
// that were evicted are provided.
|
|
|
|
void NotifyEvicted(double aStart, double aEnd);
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
private:
|
|
|
|
explicit MediaSource(nsPIDOMWindow* aWindow);
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
friend class AsyncEventRunner<MediaSource>;
|
2013-06-20 20:14:42 -07:00
|
|
|
void DispatchSimpleEvent(const char* aName);
|
|
|
|
void QueueAsyncSimpleEvent(const char* aName);
|
|
|
|
|
|
|
|
void DurationChange(double aNewDuration, ErrorResult& aRv);
|
|
|
|
|
|
|
|
double mDuration;
|
|
|
|
|
|
|
|
nsRefPtr<SourceBufferList> mSourceBuffers;
|
|
|
|
nsRefPtr<SourceBufferList> mActiveSourceBuffers;
|
|
|
|
|
2013-09-26 22:22:37 -07:00
|
|
|
nsRefPtr<MediaSourceDecoder> mDecoder;
|
2013-06-20 20:14:42 -07:00
|
|
|
|
|
|
|
MediaSourceReadyState mReadyState;
|
|
|
|
};
|
|
|
|
|
2013-06-20 20:15:15 -07:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
|
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
} // namespace dom
|
2013-09-26 22:22:37 -07:00
|
|
|
|
2013-06-20 20:14:42 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
#endif /* mozilla_dom_MediaSource_h_ */
|