2013-06-21 03:14:42 +00: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-27 05:22:37 +00:00
|
|
|
#include "MediaSourceDecoder.h"
|
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2013-06-21 03:14:42 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-01 06:13:50 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-06-21 03:14:42 +00:00
|
|
|
#include "mozilla/dom/MediaSourceBinding.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2013-06-21 03:14:42 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsISupports.h"
|
2013-06-21 03:14:42 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
|
|
|
class nsPIDOMWindow;
|
2013-09-06 17:50:24 +00:00
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
namespace mozilla {
|
2013-09-27 05:22:37 +00:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
template <typename T> class AsyncEventRunner;
|
|
|
|
|
2015-01-16 12:49:02 +00:00
|
|
|
enum MSRangeRemovalAction: uint8_t {
|
|
|
|
RUN = 0,
|
|
|
|
SKIP = 1
|
|
|
|
};
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
namespace dom {
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
class GlobalObject;
|
2013-06-21 03:14:42 +00:00
|
|
|
class SourceBuffer;
|
2013-09-27 05:22:37 +00:00
|
|
|
class SourceBufferList;
|
|
|
|
template <typename T> class Optional;
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2013-06-21 03:15:15 +00:00
|
|
|
#define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \
|
|
|
|
{ 0x3839d699, 0x22c5, 0x439f, \
|
|
|
|
{ 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } }
|
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
class MediaSource MOZ_FINAL : public DOMEventTargetHelper
|
2013-06-21 03:14:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** WebIDL Methods. */
|
2013-08-23 05:17:08 +00:00
|
|
|
static already_AddRefed<MediaSource>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
2013-06-21 03:14:42 +00: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-05 03:35:47 +00:00
|
|
|
static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
|
2015-01-08 16:57:10 +00:00
|
|
|
|
|
|
|
static bool Enabled(JSContext* cx, JSObject* aGlobal);
|
2013-06-21 03:14:42 +00:00
|
|
|
/** End WebIDL Methods. */
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper)
|
2013-06-21 03:15:15 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
|
2013-06-21 03:14:42 +00:00
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() const;
|
|
|
|
|
2014-04-08 22:27:18 +00:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
// Attach this MediaSource to Decoder aDecoder. Returns false if already attached.
|
|
|
|
bool Attach(MediaSourceDecoder* aDecoder);
|
|
|
|
void Detach();
|
2013-06-21 03:14:42 +00:00
|
|
|
|
|
|
|
// Set mReadyState to aState and fire the required events at the MediaSource.
|
|
|
|
void SetReadyState(MediaSourceReadyState aState);
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
// Used by SourceBuffer to call CreateSubDecoder.
|
|
|
|
MediaSourceDecoder* GetDecoder()
|
|
|
|
{
|
|
|
|
return mDecoder;
|
|
|
|
}
|
|
|
|
|
2014-10-15 01:17:03 +00:00
|
|
|
nsIPrincipal* GetPrincipal()
|
|
|
|
{
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
2014-02-28 00:54:48 +00: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);
|
|
|
|
|
2014-09-05 00:04:54 +00:00
|
|
|
// Queue InitializationEvent to run on the main thread. Called when a
|
|
|
|
// SourceBuffer has an initialization segment appended, but only
|
2014-09-19 03:55:58 +00:00
|
|
|
// dispatched the first time (using mFirstSourceBufferInitialized).
|
2014-09-05 00:04:54 +00:00
|
|
|
// Demarcates the point in time at which only currently registered
|
|
|
|
// TrackBuffers are treated as essential by the MediaSourceReader for
|
|
|
|
// initialization.
|
|
|
|
void QueueInitializationEvent();
|
|
|
|
|
2014-09-11 22:47:06 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
// Dump the contents of each SourceBuffer to a series of files under aPath.
|
|
|
|
// aPath must exist. Debug only, invoke from your favourite debugger.
|
|
|
|
void Dump(const char* aPath);
|
|
|
|
#endif
|
|
|
|
|
2015-01-29 02:35:55 +00:00
|
|
|
// Returns a string describing the state of the MediaSource internal
|
|
|
|
// buffered data. Used for debugging purposes.
|
|
|
|
void GetMozDebugReaderData(nsAString& aString);
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
private:
|
2014-09-16 03:15:55 +00:00
|
|
|
// MediaSourceDecoder uses DurationChange to set the duration
|
|
|
|
// without hitting the checks in SetDuration.
|
|
|
|
friend class mozilla::MediaSourceDecoder;
|
2015-01-09 01:34:41 +00:00
|
|
|
// SourceBuffer uses SetDuration
|
|
|
|
friend class mozilla::dom::SourceBuffer;
|
2014-09-16 03:15:55 +00:00
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
~MediaSource();
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
explicit MediaSource(nsPIDOMWindow* aWindow);
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
friend class AsyncEventRunner<MediaSource>;
|
2013-06-21 03:14:42 +00:00
|
|
|
void DispatchSimpleEvent(const char* aName);
|
|
|
|
void QueueAsyncSimpleEvent(const char* aName);
|
|
|
|
|
2014-11-12 04:11:33 +00:00
|
|
|
void DurationChange(double aOldDuration, double aNewDuration);
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2014-09-05 00:04:54 +00:00
|
|
|
void InitializationEvent();
|
|
|
|
|
2015-01-09 01:34:41 +00:00
|
|
|
// SetDuration with no checks.
|
2015-01-16 12:49:02 +00:00
|
|
|
void SetDuration(double aDuration, MSRangeRemovalAction aAction);
|
2015-01-09 01:34:41 +00:00
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
nsRefPtr<SourceBufferList> mSourceBuffers;
|
|
|
|
nsRefPtr<SourceBufferList> mActiveSourceBuffers;
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
nsRefPtr<MediaSourceDecoder> mDecoder;
|
2014-12-29 03:18:41 +00:00
|
|
|
// Ensures the media element remains alive to dispatch progress and
|
|
|
|
// durationchanged events.
|
|
|
|
nsRefPtr<HTMLMediaElement> mMediaElement;
|
2013-06-21 03:14:42 +00:00
|
|
|
|
2014-10-15 01:17:03 +00:00
|
|
|
nsRefPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
2013-06-21 03:14:42 +00:00
|
|
|
MediaSourceReadyState mReadyState;
|
2014-09-05 00:04:54 +00:00
|
|
|
|
2014-09-19 03:55:58 +00:00
|
|
|
bool mFirstSourceBufferInitialized;
|
2013-06-21 03:14:42 +00:00
|
|
|
};
|
|
|
|
|
2013-06-21 03:15:15 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
|
|
|
|
|
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
|
|
|
|
#endif /* mozilla_dom_MediaSource_h_ */
|