2015-05-03 22:32:37 +03: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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2013-03-19 16:23:54 +04:00
|
|
|
#ifndef mozilla_dom_HTMLMediaElement_h
|
|
|
|
#define mozilla_dom_HTMLMediaElement_h
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsIDOMHTMLMediaElement.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-11-09 09:52:53 +04:00
|
|
|
#include "MediaDecoderOwner.h"
|
2009-03-08 23:59:08 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-02-24 22:14:14 +03:00
|
|
|
#include "nsIObserver.h"
|
2012-03-10 20:13:51 +04:00
|
|
|
#include "mozilla/CORSMode.h"
|
2012-11-22 07:10:41 +04:00
|
|
|
#include "DecoderTraits.h"
|
2013-10-22 01:23:33 +04:00
|
|
|
#include "nsIAudioChannelAgent.h"
|
2013-03-19 16:25:19 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-07-17 00:54:00 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-10-23 22:45:00 +04:00
|
|
|
#include "mozilla/dom/TextTrackManager.h"
|
2016-06-29 02:42:07 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2014-04-01 07:39:04 +04:00
|
|
|
#include "MediaDecoder.h"
|
2014-06-07 00:52:15 +04:00
|
|
|
#include "mozilla/dom/MediaKeys.h"
|
2015-07-16 21:52:43 +03:00
|
|
|
#include "mozilla/StateWatching.h"
|
2014-10-01 22:43:26 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2016-01-26 10:36:52 +03:00
|
|
|
#include "PrincipalChangeObserver.h"
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2014-08-25 17:27:25 +04:00
|
|
|
// X.h on Linux #defines CurrentTime as 0L, so we have to #undef it here.
|
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
|
|
|
|
2014-06-07 00:52:15 +04:00
|
|
|
#include "mozilla/dom/HTMLMediaElementBinding.h"
|
2010-08-25 17:10:00 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Define to output information on decoding and painting framerate
|
|
|
|
/* #define DEBUG_FRAME_RATE 1 */
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef uint16_t nsMediaNetworkState;
|
|
|
|
typedef uint16_t nsMediaReadyState;
|
2016-05-03 04:52:38 +03:00
|
|
|
typedef uint32_t SuspendTypes;
|
2016-06-01 05:26:10 +03:00
|
|
|
typedef uint32_t AudibleChangedReasons;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
namespace mozilla {
|
2016-04-19 10:36:19 +03:00
|
|
|
class DecoderDoctorDiagnostics;
|
2016-01-23 18:20:28 +03:00
|
|
|
class DOMMediaStream;
|
2013-10-22 01:23:33 +04:00
|
|
|
class ErrorResult;
|
2012-04-30 07:12:28 +04:00
|
|
|
class MediaResource;
|
2012-11-14 23:46:40 +04:00
|
|
|
class MediaDecoder;
|
2013-10-22 01:23:33 +04:00
|
|
|
class VideoFrameContainer;
|
|
|
|
namespace dom {
|
2014-06-07 00:52:15 +04:00
|
|
|
class MediaKeys;
|
2013-10-22 01:23:33 +04:00
|
|
|
class TextTrack;
|
|
|
|
class TimeRanges;
|
2014-01-07 16:16:07 +04:00
|
|
|
class WakeLock;
|
2014-05-23 13:34:14 +04:00
|
|
|
class MediaTrack;
|
2016-06-29 13:27:13 +03:00
|
|
|
class MediaStreamTrack;
|
|
|
|
class VideoStreamTrack;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2015-08-31 19:50:20 +03:00
|
|
|
class AutoNotifyAudioChannelAgent;
|
|
|
|
class nsIChannel;
|
|
|
|
class nsIHttpChannel;
|
|
|
|
class nsILoadGroup;
|
|
|
|
class nsIRunnable;
|
2013-05-28 21:30:17 +04:00
|
|
|
class nsITimer;
|
2013-06-07 08:26:55 +04:00
|
|
|
class nsRange;
|
2013-05-28 21:30:17 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-08 19:29:07 +04:00
|
|
|
// Number of milliseconds between timeupdate events as defined by spec
|
|
|
|
#define TIMEUPDATE_MS 250
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
class MediaError;
|
2013-06-21 07:15:47 +04:00
|
|
|
class MediaSource;
|
2013-10-23 22:45:00 +04:00
|
|
|
class TextTrackList;
|
2014-05-23 13:34:14 +04:00
|
|
|
class AudioTrackList;
|
|
|
|
class VideoTrackList;
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
class HTMLMediaElement : public nsGenericHTMLElement,
|
2014-07-13 06:20:42 +04:00
|
|
|
public nsIDOMHTMLMediaElement,
|
2013-03-19 16:23:54 +04:00
|
|
|
public MediaDecoderOwner,
|
2016-01-26 10:36:52 +03:00
|
|
|
public nsIAudioChannelAgentCallback,
|
2016-06-29 02:42:07 +03:00
|
|
|
public PrincipalChangeObserver<DOMMediaStream>,
|
|
|
|
public SupportsWeakPtr<HTMLMediaElement>
|
2008-07-09 12:22:20 +04:00
|
|
|
{
|
2015-08-31 19:50:20 +03:00
|
|
|
friend AutoNotifyAudioChannelAgent;
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
public:
|
2010-11-24 21:34:57 +03:00
|
|
|
typedef mozilla::TimeStamp TimeStamp;
|
2012-02-15 08:35:01 +04:00
|
|
|
typedef mozilla::layers::ImageContainer ImageContainer;
|
|
|
|
typedef mozilla::VideoFrameContainer VideoFrameContainer;
|
2012-04-30 07:12:28 +04:00
|
|
|
typedef mozilla::MediaStream MediaStream;
|
|
|
|
typedef mozilla::MediaResource MediaResource;
|
2012-11-14 23:45:31 +04:00
|
|
|
typedef mozilla::MediaDecoderOwner MediaDecoderOwner;
|
|
|
|
typedef mozilla::MetadataTags MetadataTags;
|
2010-11-24 21:34:57 +03:00
|
|
|
|
2016-06-29 02:42:07 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLMediaElement)
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
CORSMode GetCORSMode() {
|
2012-01-26 02:31:30 +04:00
|
|
|
return mCORSMode;
|
|
|
|
}
|
|
|
|
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2008-10-30 08:20:08 +03:00
|
|
|
/**
|
|
|
|
* This is used when the browser is constructing a video element to play
|
|
|
|
* a channel that we've already started loading. The src attribute and
|
2009-11-06 10:34:00 +03:00
|
|
|
* <source> children are ignored.
|
2008-10-30 08:20:08 +03:00
|
|
|
* @param aChannel the channel to use
|
|
|
|
* @param aListener returns a stream listener that should receive
|
|
|
|
* notifications for the stream
|
2009-11-06 10:34:00 +03:00
|
|
|
*/
|
2008-10-30 08:20:08 +03:00
|
|
|
nsresult LoadWithChannel(nsIChannel *aChannel, nsIStreamListener **aListener);
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// nsIDOMHTMLMediaElement
|
|
|
|
NS_DECL_NSIDOMHTMLMEDIAELEMENT
|
|
|
|
|
2012-12-06 19:25:18 +04:00
|
|
|
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-03-19 16:23:54 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLMediaElement,
|
2009-03-08 23:59:08 +03:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
2013-03-19 16:25:19 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2008-07-09 12:22:20 +04:00
|
|
|
// SetAttr override. C++ is stupid, so have to override both
|
|
|
|
// overloaded methods.
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsAString& aValue, bool aNotify)
|
2008-07-09 12:22:20 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2008-07-09 12:22:20 +04:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNotify) override;
|
2015-05-26 13:36:04 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
bool aNotify) override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aCompileEventHandlers) override;
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aNullParent = true) override;
|
|
|
|
virtual void DoneCreatingElement() override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-02-12 08:56:03 +04:00
|
|
|
virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t *aTabIndex) override;
|
|
|
|
virtual int32_t TabIndexDefault() override;
|
2013-02-12 08:56:03 +04:00
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
/**
|
|
|
|
* Call this to reevaluate whether we should start/stop due to our owner
|
2012-12-04 23:46:07 +04:00
|
|
|
* document being active, inactive, visible or hidden.
|
2009-10-01 18:10:13 +04:00
|
|
|
*/
|
2016-08-29 13:56:38 +03:00
|
|
|
virtual void NotifyOwnerDocumentActivityChanged();
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
// Called by the video decoder object, on the main thread,
|
|
|
|
// when it has read the metadata containing video dimensions,
|
|
|
|
// etc.
|
2014-07-04 07:54:54 +04:00
|
|
|
virtual void MetadataLoaded(const MediaInfo* aInfo,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAutoPtr<const MetadataTags> aTags) final override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-09-24 11:25:00 +04:00
|
|
|
// Called by the decoder object, on the main thread,
|
|
|
|
// when it has read the first frame of the video or audio.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void FirstFrameLoaded() final override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
// Called by the video decoder object, on the main thread,
|
|
|
|
// when the resource has a network error during loading.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void NetworkError() final override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2009-09-22 04:08:13 +04:00
|
|
|
// Called by the video decoder object, on the main thread, when the
|
|
|
|
// resource has a decode error during metadata loading or decoding.
|
2016-09-10 17:56:09 +03:00
|
|
|
virtual void DecodeError(const MediaResult& aError) final override;
|
2016-02-08 07:27:14 +03:00
|
|
|
|
|
|
|
// Return true if error attribute is not null.
|
|
|
|
virtual bool HasError() const final override;
|
2009-09-22 04:08:13 +04:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
// Called by the video decoder object, on the main thread, when the
|
|
|
|
// resource load has been cancelled.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void LoadAborted() final override;
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Called by the video decoder object, on the main thread,
|
|
|
|
// when the video playback has ended.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PlaybackEnded() final override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Called by the video decoder object, on the main thread,
|
|
|
|
// when the resource has started seeking.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SeekStarted() final override;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
// Called by the video decoder object, on the main thread,
|
|
|
|
// when the resource has completed seeking.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SeekCompleted() final override;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2009-05-18 06:03:37 +04:00
|
|
|
// Called by the media stream, on the main thread, when the download
|
|
|
|
// has been suspended by the cache or because the element itself
|
|
|
|
// asked the decoder to suspend the download.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DownloadSuspended() final override;
|
2009-05-18 06:03:37 +04:00
|
|
|
|
|
|
|
// Called by the media stream, on the main thread, when the download
|
|
|
|
// has been resumed by the cache or because the element itself
|
|
|
|
// asked the decoder to resumed the download.
|
2012-05-31 06:30:23 +04:00
|
|
|
// If aForceNetworkLoading is True, ignore the fact that the download has
|
|
|
|
// previously finished. We are downloading the middle of the media after
|
|
|
|
// having downloaded the end, we need to notify the element a download in
|
|
|
|
// ongoing.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DownloadResumed(bool aForceNetworkLoading = false) final override;
|
2009-05-18 06:03:37 +04:00
|
|
|
|
2014-09-24 11:26:00 +04:00
|
|
|
// Called to indicate the download is progressing.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DownloadProgressed() final override;
|
2014-09-24 11:26:00 +04:00
|
|
|
|
2012-05-28 02:40:06 +04:00
|
|
|
// Called by the media decoder to indicate whether the media cache has
|
|
|
|
// suspended the channel.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void NotifySuspendedByCache(bool aIsSuspended) final override;
|
2012-05-28 02:40:06 +04:00
|
|
|
|
2015-11-23 14:35:14 +03:00
|
|
|
virtual bool IsActive() const final override;
|
2015-01-22 07:01:12 +03:00
|
|
|
|
2015-11-23 14:35:14 +03:00
|
|
|
virtual bool IsHidden() const final override;
|
2015-01-22 07:01:12 +03:00
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
// Called by the media decoder and the video frame to get the
|
|
|
|
// ImageContainer containing the video data.
|
2016-04-07 19:50:01 +03:00
|
|
|
virtual VideoFrameContainer* GetVideoFrameContainer() final override;
|
2013-03-19 16:23:54 +04:00
|
|
|
layers::ImageContainer* GetImageContainer();
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
// From PrincipalChangeObserver<DOMMediaStream>.
|
|
|
|
void PrincipalChanged(DOMMediaStream* aStream) override;
|
|
|
|
|
2016-02-04 04:27:09 +03:00
|
|
|
void UpdateSrcStreamVideoPrincipal(const PrincipalHandle& aPrincipalHandle);
|
|
|
|
|
|
|
|
// Called after the MediaStream we're playing rendered a frame to aContainer
|
|
|
|
// with a different principalHandle than the previous frame.
|
|
|
|
void PrincipalHandleChangedForVideoFrameContainer(VideoFrameContainer* aContainer,
|
|
|
|
const PrincipalHandle& aNewPrincipalHandle);
|
2016-01-26 10:36:52 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Dispatch events
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult DispatchAsyncEvent(const nsAString& aName) final override;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2015-04-29 05:02:31 +03:00
|
|
|
// Triggers a recomputation of readyState.
|
|
|
|
void UpdateReadyState() override { UpdateReadyStateInternal(); }
|
|
|
|
|
2010-09-10 08:20:10 +04:00
|
|
|
// Dispatch events that were raised while in the bfcache
|
|
|
|
nsresult DispatchPendingMediaEvents();
|
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
// Return true if we can activate autoplay assuming enough data has arrived.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CanActivateAutoplay();
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2013-03-20 15:11:48 +04:00
|
|
|
// Notify that state has changed that might cause an autoplay element to
|
|
|
|
// start playing.
|
2009-04-01 04:52:56 +04:00
|
|
|
// If the element is 'autoplay' and is ready to play back (not paused,
|
|
|
|
// autoplay pref enabled, etc), it should start playing back.
|
2013-03-20 15:11:48 +04:00
|
|
|
void CheckAutoplayDataReady();
|
2009-04-01 04:52:56 +04:00
|
|
|
|
2012-01-26 02:31:30 +04:00
|
|
|
// Check if the media element had crossorigin set when loading started
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldCheckAllowOrigin();
|
2009-01-24 14:00:17 +03:00
|
|
|
|
2015-01-29 10:30:38 +03:00
|
|
|
// Returns true if the currently loaded resource is CORS same-origin with
|
|
|
|
// respect to the document.
|
|
|
|
bool IsCORSSameOrigin();
|
|
|
|
|
2008-12-15 06:38:16 +03:00
|
|
|
// Is the media element potentially playing as defined by the HTML 5 specification.
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/#potentially-playing
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPotentiallyPlaying() const;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
// Has playback ended as defined by the HTML 5 specification.
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/#ended
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPlaybackEnded() const;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
// principal of the currently playing resource. Anything accessing the contents
|
|
|
|
// of this element must have a principal that subsumes this principal.
|
|
|
|
// Returns null if nothing is playing.
|
2009-04-01 04:52:56 +04:00
|
|
|
already_AddRefed<nsIPrincipal> GetCurrentPrincipal();
|
2008-09-07 03:47:28 +04:00
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
// Principal of the currently playing video resource. Anything accessing the
|
|
|
|
// image container of this element must have a principal that subsumes this
|
|
|
|
// principal. If there are no live video tracks but content has been rendered
|
|
|
|
// to the image container, we return the last video principal we had. Should
|
|
|
|
// the image container be empty with no live video tracks, we return nullptr.
|
|
|
|
already_AddRefed<nsIPrincipal> GetCurrentVideoPrincipal();
|
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
// called to notify that the principal of the decoder's media resource has changed.
|
2016-01-14 06:38:08 +03:00
|
|
|
void NotifyDecoderPrincipalChanged() final override;
|
|
|
|
|
|
|
|
// An interface for observing principal changes on the media elements
|
2016-01-05 05:16:27 +03:00
|
|
|
// MediaDecoder. This will also be notified if the active CORSMode changes.
|
2016-01-14 06:38:08 +03:00
|
|
|
class DecoderPrincipalChangeObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void NotifyDecoderPrincipalChanged() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a DecoderPrincipalChangeObserver to this media element.
|
|
|
|
*
|
|
|
|
* Ownership of the DecoderPrincipalChangeObserver remains with the caller,
|
|
|
|
* and it's the caller's responsibility to remove the observer before it dies.
|
|
|
|
*/
|
|
|
|
void AddDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an added DecoderPrincipalChangeObserver from this media element.
|
|
|
|
*
|
|
|
|
* Returns true if it was successfully removed.
|
|
|
|
*/
|
|
|
|
bool RemoveDecoderPrincipalChangeObserver(DecoderPrincipalChangeObserver* aObserver);
|
2012-04-30 07:12:42 +04:00
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
class StreamCaptureTrackSource;
|
2016-07-06 13:15:27 +03:00
|
|
|
class DecoderCaptureTrackSource;
|
2016-01-14 13:34:39 +03:00
|
|
|
class CaptureStreamTrackSourceGetter;
|
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Update the visual size of the media. Called from the decoder on the
|
|
|
|
// main thread when/if the size changes.
|
2015-04-08 08:51:21 +03:00
|
|
|
void UpdateMediaSize(const nsIntSize& aSize);
|
|
|
|
// Like UpdateMediaSize, but only updates the size if no size has yet
|
|
|
|
// been set.
|
|
|
|
void UpdateInitialMediaSize(const nsIntSize& aSize);
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2010-06-09 03:31:27 +04:00
|
|
|
// Returns the CanPlayStatus indicating if we can handle the
|
|
|
|
// full MIME type including the optional codecs parameter.
|
2016-04-19 10:36:19 +03:00
|
|
|
static CanPlayStatus GetCanPlay(const nsAString& aType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics);
|
2012-09-30 03:29:04 +04:00
|
|
|
|
2009-02-16 04:05:28 +03:00
|
|
|
/**
|
|
|
|
* Called when a child source element is added to this media element. This
|
2010-09-03 04:03:03 +04:00
|
|
|
* may queue a task to run the select resource algorithm if appropriate.
|
2009-02-16 04:05:28 +03:00
|
|
|
*/
|
|
|
|
void NotifyAddedSource();
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
|
|
|
* Called when there's been an error fetching the resource. This decides
|
|
|
|
* whether it's appropriate to fire an error event.
|
|
|
|
*/
|
|
|
|
void NotifyLoadError();
|
|
|
|
|
2016-08-24 11:58:04 +03:00
|
|
|
/**
|
|
|
|
* Called by one of our associated MediaTrackLists (audio/video) when an
|
|
|
|
* AudioTrack is enabled or a VideoTrack is selected.
|
|
|
|
*/
|
2014-05-23 13:34:14 +04:00
|
|
|
void NotifyMediaTrackEnabled(MediaTrack* aTrack);
|
|
|
|
|
2016-08-24 11:58:04 +03:00
|
|
|
/**
|
|
|
|
* Called by one of our associated MediaTrackLists (audio/video) when an
|
|
|
|
* AudioTrack is disabled or a VideoTrack is unselected.
|
|
|
|
*/
|
|
|
|
void NotifyMediaTrackDisabled(MediaTrack* aTrack);
|
|
|
|
|
2014-10-10 13:34:57 +04:00
|
|
|
/**
|
|
|
|
* Called when tracks become available to the source media stream.
|
|
|
|
*/
|
|
|
|
void NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsNodeOfType(uint32_t aFlags) const override;
|
2009-02-16 04:05:28 +03:00
|
|
|
|
|
|
|
/**
|
2009-03-08 23:59:08 +03:00
|
|
|
* Returns the current load ID. Asynchronous events store the ID that was
|
|
|
|
* current when they were enqueued, and if it has changed when they come to
|
|
|
|
* fire, they consider themselves cancelled, and don't fire.
|
2009-02-16 04:05:28 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetCurrentLoadID() { return mCurrentLoadID; }
|
2009-02-16 04:05:28 +03:00
|
|
|
|
2009-04-10 05:28:24 +04:00
|
|
|
/**
|
|
|
|
* Returns the load group for this media element's owner document.
|
|
|
|
* XXX XBL2 issue.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsILoadGroup> GetDocumentLoadGroup();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2009-11-06 10:34:00 +03:00
|
|
|
/**
|
2011-09-30 03:34:37 +04:00
|
|
|
* Returns true if the media has played or completed a seek.
|
2009-06-26 11:25:17 +04:00
|
|
|
* Used by video frame to determine whether to paint the poster.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetPlayedOrSeeked() const { return mHasPlayedOrSeeked; }
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
nsresult CopyInnerTo(Element* aDest);
|
2010-07-29 08:58:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Accept header on the HTTP channel to the required
|
|
|
|
* video or audio MIME types.
|
|
|
|
*/
|
|
|
|
virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel) = 0;
|
|
|
|
|
2010-09-16 21:36:23 +04:00
|
|
|
/**
|
|
|
|
* Sets the required request headers on the HTTP channel for
|
|
|
|
* video or audio requests.
|
|
|
|
*/
|
|
|
|
void SetRequestHeaders(nsIHttpChannel* aChannel);
|
|
|
|
|
2013-06-28 05:05:03 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously awaits a stable state, whereupon aRunnable runs on the main
|
|
|
|
* thread. This adds an event which run aRunnable to the appshell's list of
|
|
|
|
* sections synchronous the next time control returns to the event loop.
|
|
|
|
*/
|
|
|
|
void RunInStableState(nsIRunnable* aRunnable);
|
|
|
|
|
2010-11-24 21:34:57 +03:00
|
|
|
/**
|
2011-09-30 03:34:37 +04:00
|
|
|
* Fires a timeupdate event. If aPeriodic is true, the event will only
|
2010-11-24 21:34:57 +03:00
|
|
|
* be fired if we've not fired a timeupdate event (for any reason) in the
|
|
|
|
* last 250ms, as required by the spec when the current time is periodically
|
|
|
|
* increasing during playback.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void FireTimeUpdate(bool aPeriodic) final override;
|
2010-11-24 21:34:57 +03:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
/**
|
|
|
|
* This will return null if mSrcStream is null, or if mSrcStream is not
|
2015-09-30 04:31:54 +03:00
|
|
|
* null but its GetPlaybackStream() returns null --- which can happen during
|
2015-08-31 14:33:53 +03:00
|
|
|
* cycle collection unlinking!
|
|
|
|
*/
|
2016-06-29 13:27:13 +03:00
|
|
|
MediaStream* GetSrcMediaStream() const;
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
// WebIDL
|
|
|
|
|
|
|
|
MediaError* GetError() const
|
|
|
|
{
|
|
|
|
return mError;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XPCOM GetSrc() is OK
|
|
|
|
void SetSrc(const nsAString& aSrc, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::src, aSrc, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XPCOM GetCurrentSrc() is OK
|
|
|
|
|
2014-09-06 06:42:33 +04:00
|
|
|
void GetCrossOrigin(nsAString& aResult)
|
2013-03-19 16:25:19 +04:00
|
|
|
{
|
2014-09-06 06:42:33 +04:00
|
|
|
// Null for both missing and invalid defaults is ok, since we
|
|
|
|
// always parse to an enum value, so we don't need an invalid
|
|
|
|
// default, and we _want_ the missing default to be null.
|
|
|
|
GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aResult);
|
|
|
|
}
|
|
|
|
void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t NetworkState() const
|
|
|
|
{
|
|
|
|
return mNetworkState;
|
|
|
|
}
|
|
|
|
|
2016-07-27 05:26:21 +03:00
|
|
|
void NotifyXPCOMShutdown() final override;
|
|
|
|
|
2016-05-03 12:59:32 +03:00
|
|
|
// Called by media decoder when the audible state changed or when input is
|
|
|
|
// a media stream.
|
2016-05-03 12:59:43 +03:00
|
|
|
virtual void SetAudibleState(bool aAudible) final override;
|
2016-01-21 05:27:38 +03:00
|
|
|
|
2016-05-03 12:59:32 +03:00
|
|
|
// Notify agent when the MediaElement changes its audible state.
|
2016-06-01 05:26:10 +03:00
|
|
|
void NotifyAudioPlaybackChanged(AudibleChangedReasons aReason);
|
2016-05-03 12:59:32 +03:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
// XPCOM GetPreload() is OK
|
|
|
|
void SetPreload(const nsAString& aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLAttr(nsGkAtoms::preload, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> Buffered() const;
|
|
|
|
|
|
|
|
// XPCOM Load() is OK
|
|
|
|
|
|
|
|
// XPCOM CanPlayType() is OK
|
|
|
|
|
|
|
|
uint16_t ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Seeking() const;
|
|
|
|
|
|
|
|
double CurrentTime() const;
|
|
|
|
|
|
|
|
void SetCurrentTime(double aCurrentTime, ErrorResult& aRv);
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
void FastSeek(double aTime, ErrorResult& aRv);
|
|
|
|
|
2016-06-09 22:27:39 +03:00
|
|
|
already_AddRefed<Promise> SeekToNextFrame(ErrorResult& aRv);
|
2016-05-24 18:05:35 +03:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
double Duration() const;
|
|
|
|
|
2015-02-09 09:51:17 +03:00
|
|
|
bool HasAudio() const
|
|
|
|
{
|
|
|
|
return mMediaInfo.HasAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasVideo() const
|
|
|
|
{
|
|
|
|
return mMediaInfo.HasVideo();
|
|
|
|
}
|
|
|
|
|
2015-01-27 09:10:11 +03:00
|
|
|
bool IsEncrypted() const
|
|
|
|
{
|
|
|
|
return mIsEncrypted;
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
bool Paused() const
|
|
|
|
{
|
|
|
|
return mPaused;
|
|
|
|
}
|
|
|
|
|
|
|
|
double DefaultPlaybackRate() const
|
|
|
|
{
|
|
|
|
return mDefaultPlaybackRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDefaultPlaybackRate(double aDefaultPlaybackRate, ErrorResult& aRv);
|
|
|
|
|
|
|
|
double PlaybackRate() const
|
|
|
|
{
|
|
|
|
return mPlaybackRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPlaybackRate(double aPlaybackRate, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> Played();
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> Seekable() const;
|
|
|
|
|
|
|
|
bool Ended();
|
|
|
|
|
|
|
|
bool Autoplay() const
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::autoplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAutoplay(bool aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::autoplay, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Loop() const
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLoop(bool aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::loop, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Play(ErrorResult& aRv);
|
|
|
|
|
|
|
|
void Pause(ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool Controls() const
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::controls);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetControls(bool aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::controls, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
double Volume() const
|
|
|
|
{
|
|
|
|
return mVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetVolume(double aVolume, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool Muted() const
|
|
|
|
{
|
2013-05-21 21:49:17 +04:00
|
|
|
return mMuted & MUTED_BY_CONTENT;
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XPCOM SetMuted() is OK
|
|
|
|
|
|
|
|
bool DefaultMuted() const
|
|
|
|
{
|
|
|
|
return GetBoolAttr(nsGkAtoms::muted);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDefaultMuted(bool aMuted, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::muted, aMuted, aRv);
|
|
|
|
}
|
|
|
|
|
2014-06-15 01:01:55 +04:00
|
|
|
bool MozAllowCasting() const
|
|
|
|
{
|
|
|
|
return mAllowCasting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMozAllowCasting(bool aShow)
|
|
|
|
{
|
|
|
|
mAllowCasting = aShow;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MozIsCasting() const
|
|
|
|
{
|
|
|
|
return mIsCasting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMozIsCasting(bool aShow)
|
|
|
|
{
|
|
|
|
mIsCasting = aShow;
|
|
|
|
}
|
|
|
|
|
2015-01-29 05:35:55 +03:00
|
|
|
already_AddRefed<MediaSource> GetMozMediaSourceObject() const;
|
2016-01-18 07:34:48 +03:00
|
|
|
// Returns a string describing the state of the media player internal
|
|
|
|
// data. Used for debugging purposes.
|
|
|
|
void GetMozDebugReaderData(nsAString& aString);
|
|
|
|
|
2016-04-11 07:02:43 +03:00
|
|
|
void MozDumpDebugInfo();
|
|
|
|
|
2016-07-28 11:09:02 +03:00
|
|
|
void SetVisible(bool aVisible);
|
|
|
|
|
2015-07-14 07:04:14 +03:00
|
|
|
already_AddRefed<DOMMediaStream> GetSrcObject() const;
|
|
|
|
void SetSrcObject(DOMMediaStream& aValue);
|
|
|
|
void SetSrcObject(DOMMediaStream* aValue);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2015-07-14 07:04:14 +03:00
|
|
|
// TODO: remove prefixed versions soon (1183495).
|
|
|
|
already_AddRefed<DOMMediaStream> GetMozSrcObject() const;
|
2013-03-19 16:25:19 +04:00
|
|
|
void SetMozSrcObject(DOMMediaStream& aValue);
|
2014-10-03 12:18:00 +04:00
|
|
|
void SetMozSrcObject(DOMMediaStream* aValue);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
|
|
|
bool MozPreservesPitch() const
|
|
|
|
{
|
|
|
|
return mPreservesPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XPCOM MozPreservesPitch() is OK
|
|
|
|
|
2014-06-07 00:52:15 +04:00
|
|
|
MediaKeys* GetMediaKeys() const;
|
|
|
|
|
|
|
|
already_AddRefed<Promise> SetMediaKeys(MediaKeys* mediaKeys,
|
|
|
|
ErrorResult& aRv);
|
2014-09-24 11:25:00 +04:00
|
|
|
|
2014-08-27 12:46:56 +04:00
|
|
|
mozilla::dom::EventHandlerNonNull* GetOnencrypted();
|
2016-09-22 07:25:38 +03:00
|
|
|
void SetOnencrypted(mozilla::dom::EventHandlerNonNull* aCallback);
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2016-09-21 05:10:26 +03:00
|
|
|
mozilla::dom::EventHandlerNonNull* GetOnwaitingforkey();
|
|
|
|
void SetOnwaitingforkey(mozilla::dom::EventHandlerNonNull* aCallback);
|
|
|
|
|
2014-08-27 12:46:56 +04:00
|
|
|
void DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsAString& aInitDataType) override;
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool IsEventAttributeName(nsIAtom* aName) override;
|
2014-10-13 02:53:43 +04:00
|
|
|
|
|
|
|
// Returns the principal of the "top level" document; the origin displayed
|
|
|
|
// in the URL bar of the browser window.
|
|
|
|
already_AddRefed<nsIPrincipal> GetTopLevelPrincipal();
|
|
|
|
|
2014-10-28 03:21:12 +03:00
|
|
|
bool ContainsRestrictedContent();
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2016-08-21 23:51:01 +03:00
|
|
|
void CannotDecryptWaitingForKey();
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
bool MozAutoplayEnabled() const
|
|
|
|
{
|
|
|
|
return mAutoplayEnabled;
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
already_AddRefed<DOMMediaStream> CaptureAudio(ErrorResult& aRv,
|
2016-09-07 16:14:15 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
2016-09-07 16:14:15 +03:00
|
|
|
already_AddRefed<DOMMediaStream> MozCaptureStream(ErrorResult& aRv);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2016-09-07 16:14:15 +03:00
|
|
|
already_AddRefed<DOMMediaStream> MozCaptureStreamUntilEnded(ErrorResult& aRv);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
|
|
|
bool MozAudioCaptured() const
|
|
|
|
{
|
|
|
|
return mAudioCaptured;
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void MozGetMetadata(JSContext* aCx, JS::MutableHandle<JSObject*> aResult,
|
|
|
|
ErrorResult& aRv);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
|
|
|
double MozFragmentEnd();
|
|
|
|
|
2014-04-10 21:39:20 +04:00
|
|
|
AudioChannel MozAudioChannelType() const
|
|
|
|
{
|
|
|
|
return mAudioChannel;
|
|
|
|
}
|
|
|
|
|
2013-10-29 04:08:14 +04:00
|
|
|
void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv);
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
AudioTrackList* AudioTracks();
|
|
|
|
|
|
|
|
VideoTrackList* VideoTracks();
|
|
|
|
|
2015-01-12 14:07:38 +03:00
|
|
|
TextTrackList* GetTextTracks();
|
2013-05-21 20:14:00 +04:00
|
|
|
|
|
|
|
already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
|
|
|
const nsAString& aLanguage);
|
|
|
|
|
|
|
|
void AddTextTrack(TextTrack* aTextTrack) {
|
2014-03-24 19:48:37 +04:00
|
|
|
GetOrCreateTextTrackManager()->AddTextTrack(aTextTrack);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly = false) {
|
2013-10-23 22:45:00 +04:00
|
|
|
if (mTextTrackManager) {
|
2013-10-25 08:14:36 +04:00
|
|
|
mTextTrackManager->RemoveTextTrack(aTextTrack, aPendingListOnly);
|
2013-06-24 19:35:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 11:08:32 +03:00
|
|
|
void NotifyCueAdded(TextTrackCue& aCue) {
|
2014-01-06 22:03:50 +04:00
|
|
|
if (mTextTrackManager) {
|
2016-06-02 11:08:32 +03:00
|
|
|
mTextTrackManager->NotifyCueAdded(aCue);
|
2014-01-06 22:03:50 +04:00
|
|
|
}
|
|
|
|
}
|
2016-06-01 08:35:58 +03:00
|
|
|
void NotifyCueRemoved(TextTrackCue& aCue) {
|
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->NotifyCueRemoved(aCue);
|
|
|
|
}
|
|
|
|
}
|
2016-06-08 11:53:30 +03:00
|
|
|
void NotifyCueUpdated(TextTrackCue *aCue) {
|
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->NotifyCueUpdated(aCue);
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 22:03:50 +04:00
|
|
|
|
2016-08-09 11:43:07 +03:00
|
|
|
void NotifyCueDisplayStatesChanged();
|
|
|
|
|
2016-06-30 08:31:56 +03:00
|
|
|
bool GetHasUserInteraction()
|
|
|
|
{
|
|
|
|
return mHasUserInteraction;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A method to check whether we are currently playing.
|
|
|
|
bool IsCurrentlyPlaying() const;
|
|
|
|
|
2015-02-13 08:02:35 +03:00
|
|
|
// Returns true if the media element is being destroyed. Used in
|
|
|
|
// dormancy checks to prevent dormant processing for an element
|
|
|
|
// that will soon be gone.
|
|
|
|
bool IsBeingDestroyed();
|
|
|
|
|
2015-07-16 21:34:30 +03:00
|
|
|
IMPL_EVENT_HANDLER(mozinterruptbegin)
|
|
|
|
IMPL_EVENT_HANDLER(mozinterruptend)
|
|
|
|
|
2016-05-03 04:52:53 +03:00
|
|
|
// These are used for testing only
|
2015-07-16 21:34:30 +03:00
|
|
|
float ComputedVolume() const;
|
|
|
|
bool ComputedMuted() const;
|
2016-05-03 04:52:53 +03:00
|
|
|
nsSuspendedTypes ComputedSuspended() const;
|
2015-07-16 21:34:30 +03:00
|
|
|
|
2016-09-05 07:23:23 +03:00
|
|
|
void SetMediaInfo(const MediaInfo& aInfo);
|
2016-08-29 13:56:32 +03:00
|
|
|
|
2016-09-02 11:52:44 +03:00
|
|
|
// Telemetry: to record the usage of a {visible / invisible} video element as
|
|
|
|
// the source of {drawImage(), createPattern(), createImageBitmap() and
|
|
|
|
// captureStream()} APIs.
|
|
|
|
enum class CallerAPI {
|
|
|
|
DRAW_IMAGE,
|
|
|
|
CREATE_PATTERN,
|
|
|
|
CREATE_IMAGEBITMAP,
|
|
|
|
CAPTURE_STREAM,
|
|
|
|
};
|
|
|
|
void MarkAsContentSource(CallerAPI aAPI);
|
|
|
|
|
2008-07-30 08:55:27 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLMediaElement();
|
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
class ChannelLoader;
|
2009-02-20 05:49:00 +03:00
|
|
|
class MediaLoadListener;
|
2014-10-10 13:34:57 +04:00
|
|
|
class MediaStreamTracksAvailableCallback;
|
2015-09-30 04:32:06 +03:00
|
|
|
class MediaStreamTrackListener;
|
2012-04-30 07:12:28 +04:00
|
|
|
class StreamListener;
|
2015-04-08 08:51:21 +03:00
|
|
|
class StreamSizeListener;
|
2016-05-22 16:39:55 +03:00
|
|
|
class ShutdownObserver;
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2015-04-01 04:44:36 +03:00
|
|
|
MediaDecoderOwner::NextFrameStatus NextFrameStatus();
|
2015-05-28 05:23:27 +03:00
|
|
|
void SetDecoder(MediaDecoder* aDecoder) {
|
|
|
|
MOZ_ASSERT(aDecoder); // Use ShutdownDecoder() to clear.
|
|
|
|
mDecoder = aDecoder;
|
|
|
|
}
|
2015-03-19 05:01:12 +03:00
|
|
|
|
2012-11-01 16:47:51 +04:00
|
|
|
class WakeLockBoolWrapper {
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit WakeLockBoolWrapper(bool val = false)
|
2013-05-02 20:45:35 +04:00
|
|
|
: mValue(val), mCanPlay(true), mOuter(nullptr) {}
|
|
|
|
|
2013-05-28 21:30:17 +04:00
|
|
|
~WakeLockBoolWrapper();
|
|
|
|
|
2013-05-02 20:44:49 +04:00
|
|
|
void SetOuter(HTMLMediaElement* outer) { mOuter = outer; }
|
2013-05-02 20:45:35 +04:00
|
|
|
void SetCanPlay(bool aCanPlay);
|
|
|
|
|
2015-04-11 06:05:46 +03:00
|
|
|
MOZ_IMPLICIT operator bool() const { return mValue; }
|
2013-05-02 20:45:35 +04:00
|
|
|
|
2012-11-01 16:47:51 +04:00
|
|
|
WakeLockBoolWrapper& operator=(bool val);
|
2013-05-02 20:45:35 +04:00
|
|
|
|
2012-11-01 16:47:51 +04:00
|
|
|
bool operator !() const { return !mValue; }
|
2013-05-02 20:45:35 +04:00
|
|
|
|
2013-05-28 21:30:17 +04:00
|
|
|
static void TimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2012-11-01 16:47:51 +04:00
|
|
|
private:
|
2013-05-02 20:45:35 +04:00
|
|
|
void UpdateWakeLock();
|
|
|
|
|
2012-11-01 16:47:51 +04:00
|
|
|
bool mValue;
|
2013-05-02 20:45:35 +04:00
|
|
|
bool mCanPlay;
|
2013-05-02 20:44:49 +04:00
|
|
|
HTMLMediaElement* mOuter;
|
2013-05-28 21:30:17 +04:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2012-11-01 16:47:51 +04:00
|
|
|
};
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
// Holds references to the DOM wrappers for the MediaStreams that we're
|
|
|
|
// writing to.
|
|
|
|
struct OutputMediaStream {
|
|
|
|
OutputMediaStream();
|
|
|
|
~OutputMediaStream();
|
|
|
|
|
|
|
|
RefPtr<DOMMediaStream> mStream;
|
|
|
|
bool mFinishWhenEnded;
|
|
|
|
bool mCapturingAudioOnly;
|
|
|
|
bool mCapturingDecoder;
|
|
|
|
bool mCapturingMediaStream;
|
|
|
|
|
|
|
|
// The following members are keeping state for a captured MediaStream.
|
|
|
|
TrackID mNextAvailableTrackID;
|
|
|
|
nsTArray<Pair<nsString, RefPtr<MediaInputPort>>> mTrackPorts;
|
|
|
|
};
|
|
|
|
|
2016-08-29 05:42:10 +03:00
|
|
|
nsresult PlayInternal();
|
2015-10-20 00:45:18 +03:00
|
|
|
|
2014-09-24 11:25:00 +04:00
|
|
|
/** Use this method to change the mReadyState member, so required
|
|
|
|
* events can be fired.
|
|
|
|
*/
|
|
|
|
void ChangeReadyState(nsMediaReadyState aState);
|
|
|
|
|
2014-09-24 11:26:00 +04:00
|
|
|
/**
|
|
|
|
* Use this method to change the mNetworkState member, so required
|
|
|
|
* actions will be taken during the transition.
|
|
|
|
*/
|
|
|
|
void ChangeNetworkState(nsMediaNetworkState aState);
|
|
|
|
|
2013-05-10 16:42:39 +04:00
|
|
|
/**
|
|
|
|
* These two methods are called by the WakeLockBoolWrapper when the wakelock
|
|
|
|
* has to be created or released.
|
|
|
|
*/
|
|
|
|
virtual void WakeLockCreate();
|
|
|
|
virtual void WakeLockRelease();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WakeLock> mWakeLock;
|
2013-05-10 16:42:39 +04:00
|
|
|
|
2011-12-22 03:33:39 +04:00
|
|
|
/**
|
|
|
|
* Logs a warning message to the web console to report various failures.
|
|
|
|
* aMsg is the localized message identifier, aParams is the parameters to
|
|
|
|
* be substituted into the localized message, and aParamCount is the number
|
|
|
|
* of parameters in aParams.
|
|
|
|
*/
|
|
|
|
void ReportLoadError(const char* aMsg,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t** aParams = nullptr,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aParamCount = 0);
|
2011-12-22 03:33:39 +04:00
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
/**
|
|
|
|
* Changes mHasPlayedOrSeeked to aValue. If mHasPlayedOrSeeked changes
|
|
|
|
* we'll force a reflow so that the video frame gets reflowed to reflect
|
|
|
|
* the poster hiding or showing immediately.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetPlayedOrSeeked(bool aValue);
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
/**
|
2012-09-25 07:25:43 +04:00
|
|
|
* Initialize the media element for playback of aStream
|
2012-04-30 07:12:28 +04:00
|
|
|
*/
|
2013-02-15 12:01:58 +04:00
|
|
|
void SetupSrcMediaStreamPlayback(DOMMediaStream* aStream);
|
2012-04-30 07:12:28 +04:00
|
|
|
/**
|
2012-08-20 08:52:59 +04:00
|
|
|
* Stop playback on mSrcStream.
|
2012-04-30 07:12:28 +04:00
|
|
|
*/
|
2012-08-20 08:52:59 +04:00
|
|
|
void EndSrcMediaStreamPlayback();
|
2015-08-31 14:33:53 +03:00
|
|
|
/**
|
|
|
|
* Ensure we're playing mSrcStream if and only if we're not paused.
|
|
|
|
*/
|
|
|
|
enum { REMOVING_SRC_STREAM = 0x1 };
|
|
|
|
void UpdateSrcMediaStreamPlaying(uint32_t aFlags = 0);
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
/**
|
|
|
|
* Called by our DOMMediaStream::TrackListener when a new MediaStreamTrack has
|
|
|
|
* been added to the playback stream of |mSrcStream|.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyMediaStreamTrackAdded(const RefPtr<MediaStreamTrack>& aTrack);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by our DOMMediaStream::TrackListener when a MediaStreamTrack in
|
|
|
|
* |mSrcStream|'s playback stream has ended.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyMediaStreamTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
/**
|
2016-08-23 18:51:50 +03:00
|
|
|
* Enables or disables all tracks forwarded from mSrcStream to all
|
|
|
|
* OutputMediaStreams. We do this for muting the tracks when pausing,
|
|
|
|
* and unmuting when playing the media element again.
|
|
|
|
*
|
|
|
|
* If mSrcStream is unset, this does nothing.
|
|
|
|
*/
|
|
|
|
void SetCapturedOutputStreamsEnabled(bool aEnabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new MediaStreamTrack for aTrack and add it to the DOMMediaStream
|
|
|
|
* in aOutputStream. This automatically sets the output track to enabled or
|
|
|
|
* disabled depending on our current playing state.
|
|
|
|
*/
|
|
|
|
void AddCaptureMediaTrackToOutputStream(MediaTrack* aTrack,
|
|
|
|
OutputMediaStream& aOutputStream,
|
|
|
|
bool aAsyncAddtrack = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an DOMMediaStream containing the played contents of this
|
2012-04-30 07:12:42 +04:00
|
|
|
* element. When aFinishWhenEnded is true, when this element ends playback
|
|
|
|
* we will finish the stream and not play any more into it.
|
|
|
|
* When aFinishWhenEnded is false, ending playback does not finish the stream.
|
|
|
|
* The stream will never finish.
|
2016-08-23 18:51:50 +03:00
|
|
|
*
|
|
|
|
* When aCaptureAudio is true, we stop playout of audio and instead route it
|
|
|
|
* to the DOMMediaStream. Volume and mute state will be applied to the audio
|
|
|
|
* reaching the stream. No video tracks will be captured in this case.
|
2012-04-30 07:12:42 +04:00
|
|
|
*/
|
2015-03-31 05:14:00 +03:00
|
|
|
already_AddRefed<DOMMediaStream> CaptureStreamInternal(bool aFinishWhenEnded,
|
2016-08-23 18:51:50 +03:00
|
|
|
bool aCaptureAudio,
|
2016-09-07 16:14:15 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
2012-04-30 07:12:42 +04:00
|
|
|
|
2009-09-15 06:30:44 +04:00
|
|
|
/**
|
|
|
|
* Initialize a decoder as a clone of an existing decoder in another
|
|
|
|
* element.
|
2011-11-25 06:06:22 +04:00
|
|
|
* mLoadingSrc must already be set.
|
2009-09-15 06:30:44 +04:00
|
|
|
*/
|
2012-11-14 23:46:40 +04:00
|
|
|
nsresult InitializeDecoderAsClone(MediaDecoder* aOriginal);
|
2009-09-15 06:30:44 +04:00
|
|
|
|
2008-10-30 08:20:08 +03:00
|
|
|
/**
|
|
|
|
* Initialize a decoder to load the given channel. The decoder's stream
|
|
|
|
* listener is returned via aListener.
|
2011-11-25 06:06:22 +04:00
|
|
|
* mLoadingSrc must already be set.
|
2008-10-30 08:20:08 +03:00
|
|
|
*/
|
|
|
|
nsresult InitializeDecoderForChannel(nsIChannel *aChannel,
|
|
|
|
nsIStreamListener **aListener);
|
2009-03-08 23:59:08 +03:00
|
|
|
|
2009-09-15 06:30:44 +04:00
|
|
|
/**
|
|
|
|
* Finish setting up the decoder after Load() has been called on it.
|
2011-11-25 06:06:22 +04:00
|
|
|
* Called by InitializeDecoderForChannel/InitializeDecoderAsClone.
|
2009-09-15 06:30:44 +04:00
|
|
|
*/
|
2012-11-14 23:46:40 +04:00
|
|
|
nsresult FinishDecoderSetup(MediaDecoder* aDecoder,
|
2012-04-30 07:12:28 +04:00
|
|
|
MediaResource* aStream,
|
2015-10-14 06:46:27 +03:00
|
|
|
nsIStreamListener **aListener);
|
2009-09-15 06:30:44 +04:00
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
/**
|
|
|
|
* Call this after setting up mLoadingSrc and mDecoder.
|
|
|
|
*/
|
|
|
|
void AddMediaElementToURITable();
|
|
|
|
/**
|
2015-09-10 10:01:44 +03:00
|
|
|
* Call this before modifying mLoadingSrc.
|
2011-11-25 06:06:22 +04:00
|
|
|
*/
|
|
|
|
void RemoveMediaElementFromURITable();
|
|
|
|
/**
|
|
|
|
* Call this to find a media element with the same NodePrincipal and mLoadingSrc
|
|
|
|
* set to aURI, and with a decoder on which Load() has been called.
|
|
|
|
*/
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* LookupMediaElementURITable(nsIURI* aURI);
|
2011-11-25 06:06:22 +04:00
|
|
|
|
2012-04-30 07:13:09 +04:00
|
|
|
/**
|
|
|
|
* Shutdown and clear mDecoder and maintain associated invariants.
|
|
|
|
*/
|
|
|
|
void ShutdownDecoder();
|
2008-12-16 06:32:03 +03:00
|
|
|
/**
|
|
|
|
* Execute the initial steps of the load algorithm that ensure existing
|
2009-03-08 23:59:08 +03:00
|
|
|
* loads are aborted, the element is emptied, and a new load ID is
|
|
|
|
* created.
|
2008-12-16 06:32:03 +03:00
|
|
|
*/
|
2009-03-08 23:59:08 +03:00
|
|
|
void AbortExistingLoads();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2009-02-15 19:26:32 +03:00
|
|
|
/**
|
2009-09-22 04:08:13 +04:00
|
|
|
* Called when all potential resources are exhausted. Changes network
|
2009-03-08 23:59:08 +03:00
|
|
|
* state to NETWORK_NO_SOURCE, and sends error event with code
|
2009-09-22 04:08:13 +04:00
|
|
|
* MEDIA_ERR_SRC_NOT_SUPPORTED.
|
2009-02-15 19:26:32 +03:00
|
|
|
*/
|
2016-09-15 09:17:10 +03:00
|
|
|
void NoSupportedMediaSourceError(const nsACString& aErrorDetails = nsCString());
|
2009-02-15 19:26:32 +03:00
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
|
|
|
* Attempts to load resources from the <source> children. This is a
|
2010-09-03 04:03:03 +04:00
|
|
|
* substep of the resource selection algorithm. Do not call this directly,
|
2009-03-08 23:59:08 +03:00
|
|
|
* call QueueLoadFromSourceTask() instead.
|
|
|
|
*/
|
|
|
|
void LoadFromSourceChildren();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
2010-09-03 04:03:03 +04:00
|
|
|
* Asynchronously awaits a stable state, and then causes
|
|
|
|
* LoadFromSourceChildren() to be called on the main threads' event loop.
|
2009-03-08 23:59:08 +03:00
|
|
|
*/
|
|
|
|
void QueueLoadFromSourceTask();
|
2009-11-06 10:34:00 +03:00
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
2010-09-03 04:03:03 +04:00
|
|
|
* Runs the media resource selection algorithm.
|
2009-03-08 23:59:08 +03:00
|
|
|
*/
|
|
|
|
void SelectResource();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2012-02-20 01:02:08 +04:00
|
|
|
/**
|
|
|
|
* A wrapper function that allows us to cleanly reset flags after a call
|
|
|
|
* to SelectResource()
|
|
|
|
*/
|
|
|
|
void SelectResourceWrapper();
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
2010-09-03 04:03:03 +04:00
|
|
|
* Asynchronously awaits a stable state, and then causes SelectResource()
|
|
|
|
* to be run on the main thread's event loop.
|
2009-03-08 23:59:08 +03:00
|
|
|
*/
|
|
|
|
void QueueSelectResourceTask();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2012-12-27 19:21:30 +04:00
|
|
|
/**
|
|
|
|
* When loading a new source on an existing media element, make sure to reset
|
|
|
|
* everything that is accessible using the media element API.
|
|
|
|
*/
|
|
|
|
void ResetState();
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
/**
|
|
|
|
* The resource-fetch algorithm step of the load algorithm.
|
|
|
|
*/
|
2011-11-25 06:06:22 +04:00
|
|
|
nsresult LoadResource();
|
2009-03-08 23:59:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects the next <source> child from which to load a resource. Called
|
2010-09-03 04:03:03 +04:00
|
|
|
* during the resource selection algorithm. Stores the return value in
|
|
|
|
* mSourceLoadCandidate before returning.
|
2009-03-08 23:59:08 +03:00
|
|
|
*/
|
2010-09-03 04:03:03 +04:00
|
|
|
nsIContent* GetNextSource();
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2009-03-09 00:01:03 +03:00
|
|
|
/**
|
|
|
|
* Changes mDelayingLoadEvent, and will call BlockOnLoad()/UnblockOnLoad()
|
|
|
|
* on the owning document, so it can delay the load event firing.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void ChangeDelayLoadStatus(bool aDelay);
|
2009-03-09 00:01:03 +03:00
|
|
|
|
2009-05-18 06:00:44 +04:00
|
|
|
/**
|
|
|
|
* If we suspended downloading after the first frame, unsuspend now.
|
|
|
|
*/
|
|
|
|
void StopSuspendingAfterFirstFrame();
|
|
|
|
|
2009-05-18 02:20:37 +04:00
|
|
|
/**
|
|
|
|
* Called when our channel is redirected to another channel.
|
|
|
|
* Updates our mChannel reference to aNewChannel.
|
|
|
|
*/
|
|
|
|
nsresult OnChannelRedirect(nsIChannel *aChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags);
|
2009-05-18 02:20:37 +04:00
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
/**
|
|
|
|
* Call this to reevaluate whether we should be holding a self-reference.
|
|
|
|
*/
|
|
|
|
void AddRemoveSelfReference();
|
|
|
|
|
|
|
|
/**
|
2010-02-24 22:14:14 +03:00
|
|
|
* Called asynchronously to release a self-reference to this element.
|
2009-10-01 18:10:13 +04:00
|
|
|
*/
|
2010-02-24 22:14:14 +03:00
|
|
|
void DoRemoveSelfReference();
|
2012-11-16 07:25:26 +04:00
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
/**
|
|
|
|
* Called when "xpcom-shutdown" event is received.
|
|
|
|
*/
|
|
|
|
void NotifyShutdownEvent();
|
|
|
|
|
2010-08-20 02:50:37 +04:00
|
|
|
/**
|
|
|
|
* Possible values of the 'preload' attribute.
|
|
|
|
*/
|
2016-09-07 05:20:17 +03:00
|
|
|
enum PreloadAttrValue : uint8_t {
|
2010-08-20 02:50:37 +04:00
|
|
|
PRELOAD_ATTR_EMPTY, // set to ""
|
|
|
|
PRELOAD_ATTR_NONE, // set to "none"
|
|
|
|
PRELOAD_ATTR_METADATA, // set to "metadata"
|
|
|
|
PRELOAD_ATTR_AUTO // set to "auto"
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-16 07:25:26 +04:00
|
|
|
* The preloading action to perform. These dictate how we react to the
|
2010-08-20 02:50:37 +04:00
|
|
|
* preload attribute. See mPreloadAction.
|
|
|
|
*/
|
|
|
|
enum PreloadAction {
|
|
|
|
PRELOAD_UNDEFINED = 0, // not determined - used only for initialization
|
|
|
|
PRELOAD_NONE = 1, // do not preload
|
|
|
|
PRELOAD_METADATA = 2, // preload only the metadata (and first frame)
|
|
|
|
PRELOAD_ENOUGH = 3 // preload enough data to allow uninterrupted
|
|
|
|
// playback
|
|
|
|
};
|
|
|
|
|
2015-06-17 03:02:51 +03:00
|
|
|
/**
|
|
|
|
* The guts of Load(). Load() acts as a wrapper around this which sets
|
|
|
|
* mIsDoingExplicitLoad to true so that when script calls 'load()'
|
|
|
|
* preload-none will be automatically upgraded to preload-metadata.
|
|
|
|
*/
|
|
|
|
void DoLoad();
|
|
|
|
|
2010-08-20 02:50:37 +04:00
|
|
|
/**
|
2011-11-25 06:06:22 +04:00
|
|
|
* Suspends the load of mLoadingSrc, so that it can be resumed later
|
2010-08-20 02:50:37 +04:00
|
|
|
* by ResumeLoad(). This is called when we have a media with a 'preload'
|
|
|
|
* attribute value of 'none', during the resource selection algorithm.
|
|
|
|
*/
|
2011-11-25 06:06:22 +04:00
|
|
|
void SuspendLoad();
|
2010-08-20 02:50:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resumes a previously suspended load (suspended by SuspendLoad(uri)).
|
|
|
|
* Will continue running the resource selection algorithm.
|
|
|
|
* Sets mPreloadAction to aAction.
|
|
|
|
*/
|
|
|
|
void ResumeLoad(PreloadAction aAction);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a change to the preload attribute. Should be called whenever the
|
2012-11-16 07:25:26 +04:00
|
|
|
* value (or presence) of the preload attribute changes. The change in
|
2010-08-20 02:50:37 +04:00
|
|
|
* attribute value may cause a change in the mPreloadAction of this
|
|
|
|
* element. If there is a change then this method will initiate any
|
|
|
|
* behaviour that is necessary to implement the action.
|
|
|
|
*/
|
|
|
|
void UpdatePreloadAction();
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2014-11-28 02:17:18 +03:00
|
|
|
/**
|
|
|
|
* Fire progress events if needed according to the time and byte constraints
|
|
|
|
* outlined in the specification. aHaveNewProgress is true if progress has
|
|
|
|
* just been detected. Otherwise the method is called as a result of the
|
|
|
|
* progress timer.
|
|
|
|
*/
|
|
|
|
void CheckProgress(bool aHaveNewProgress);
|
|
|
|
static void ProgressTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
/**
|
|
|
|
* Start timer to update download progress.
|
|
|
|
*/
|
2014-11-28 07:07:15 +03:00
|
|
|
void StartProgressTimer();
|
2014-11-28 02:17:18 +03:00
|
|
|
/**
|
2014-11-28 07:07:15 +03:00
|
|
|
* Start sending progress and/or stalled events.
|
2014-11-28 02:17:18 +03:00
|
|
|
*/
|
2014-11-28 07:07:15 +03:00
|
|
|
void StartProgress();
|
|
|
|
/**
|
|
|
|
* Stop progress information timer and events.
|
|
|
|
*/
|
|
|
|
void StopProgress();
|
2014-11-28 02:17:18 +03:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
/**
|
|
|
|
* Dispatches an error event to a child source element.
|
|
|
|
*/
|
|
|
|
void DispatchAsyncSourceError(nsIContent* aSourceElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the media element for an error condition as per aErrorCode.
|
|
|
|
* aErrorCode must be one of nsIDOMHTMLMediaError codes.
|
|
|
|
*/
|
2016-09-15 09:17:10 +03:00
|
|
|
void Error(uint16_t aErrorCode, const nsACString& aErrorDetails = nsCString());
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2011-08-25 03:42:23 +04:00
|
|
|
/**
|
|
|
|
* Returns the URL spec of the currentSrc.
|
|
|
|
**/
|
|
|
|
void GetCurrentSpec(nsCString& aString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process any media fragment entries in the URI
|
|
|
|
*/
|
|
|
|
void ProcessMediaFragmentURI();
|
|
|
|
|
2012-11-22 14:38:28 +04:00
|
|
|
/**
|
2013-05-21 21:49:17 +04:00
|
|
|
* Mute or unmute the audio and change the value that the |muted| map.
|
2012-11-22 14:38:28 +04:00
|
|
|
*/
|
2013-05-21 21:49:17 +04:00
|
|
|
void SetMutedInternal(uint32_t aMuted);
|
2013-05-27 09:13:05 +04:00
|
|
|
/**
|
|
|
|
* Update the volume of the output audio stream to match the element's
|
2013-09-02 13:45:44 +04:00
|
|
|
* current mMuted/mVolume/mAudioChannelFaded state.
|
2013-05-27 09:13:05 +04:00
|
|
|
*/
|
|
|
|
void SetVolumeInternal();
|
2012-11-22 14:38:28 +04:00
|
|
|
|
2012-12-12 05:58:07 +04:00
|
|
|
/**
|
|
|
|
* Suspend (if aPauseForInactiveDocument) or resume element playback and
|
|
|
|
* resource download. If aSuspendEvents is true, event delivery is
|
|
|
|
* suspended (and events queued) until the element is resumed.
|
|
|
|
*/
|
|
|
|
void SuspendOrResumeElement(bool aPauseElement, bool aSuspendEvents);
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
// Get the HTMLMediaElement object if the decoder is being used from an
|
2012-11-09 09:52:53 +04:00
|
|
|
// HTML media element, and null otherwise.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual HTMLMediaElement* GetMediaElement() final override
|
2012-11-09 09:52:53 +04:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if decoding should be paused
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool GetPaused() final override
|
2012-11-09 09:52:53 +04:00
|
|
|
{
|
|
|
|
bool isPaused = false;
|
|
|
|
GetPaused(&isPaused);
|
|
|
|
return isPaused;
|
|
|
|
}
|
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
/**
|
|
|
|
* Video has been playing while hidden and, if feature was enabled, would
|
|
|
|
* trigger suspending decoder.
|
|
|
|
* Used to track hidden-video-decode-suspend telemetry.
|
|
|
|
*/
|
|
|
|
static void VideoDecodeSuspendTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
/**
|
|
|
|
* Video is now both: playing and hidden.
|
|
|
|
* Used to track hidden-video telemetry.
|
|
|
|
*/
|
|
|
|
void HiddenVideoStart();
|
|
|
|
/**
|
|
|
|
* Video is not playing anymore and/or has become visible.
|
|
|
|
* Used to track hidden-video telemetry.
|
|
|
|
*/
|
|
|
|
void HiddenVideoStop();
|
|
|
|
|
2015-03-27 02:21:20 +03:00
|
|
|
void ReportEMETelemetry();
|
2016-09-08 13:06:20 +03:00
|
|
|
|
2016-05-05 22:48:45 +03:00
|
|
|
void ReportTelemetry();
|
2015-02-13 08:02:35 +03:00
|
|
|
|
2012-12-04 23:46:07 +04:00
|
|
|
// Check the permissions for audiochannel.
|
|
|
|
bool CheckAudioChannelPermissions(const nsAString& aType);
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
// Seeks to aTime seconds. aSeekType can be Exact to seek to exactly the
|
|
|
|
// seek target, or PrevSyncPoint if a quicker but less precise seek is
|
|
|
|
// desired, and we'll seek to the sync point (keyframe and/or start of the
|
|
|
|
// next block of audio samples) preceeding seek target.
|
2016-06-09 22:27:39 +03:00
|
|
|
already_AddRefed<Promise> Seek(double aTime, SeekTarget::Type aSeekType, ErrorResult& aRv);
|
2014-09-24 11:25:00 +04:00
|
|
|
|
2015-10-15 01:59:00 +03:00
|
|
|
// A method to check if we are playing through the AudioChannel.
|
|
|
|
bool IsPlayingThroughTheAudioChannel() const;
|
|
|
|
|
2012-12-04 23:46:07 +04:00
|
|
|
// Update the audio channel playing state
|
2014-04-03 01:53:39 +04:00
|
|
|
void UpdateAudioChannelPlayingState();
|
2012-12-04 23:46:07 +04:00
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
// Adds to the element's list of pending text tracks each text track
|
|
|
|
// in the element's list of text tracks whose text track mode is not disabled
|
|
|
|
// and whose text track readiness state is loading.
|
|
|
|
void PopulatePendingTextTrackList();
|
|
|
|
|
2014-03-24 19:48:37 +04:00
|
|
|
// Gets a reference to the MediaElement's TextTrackManager. If the
|
|
|
|
// MediaElement doesn't yet have one then it will create it.
|
|
|
|
TextTrackManager* GetOrCreateTextTrackManager();
|
|
|
|
|
2015-03-19 05:01:12 +03:00
|
|
|
// Recomputes ready state and fires events as necessary based on current state.
|
|
|
|
void UpdateReadyStateInternal();
|
|
|
|
|
2015-07-06 01:36:49 +03:00
|
|
|
// Notifies the audio channel agent when the element starts or stops playing.
|
|
|
|
void NotifyAudioChannelAgent(bool aPlaying);
|
|
|
|
|
2015-08-31 19:50:20 +03:00
|
|
|
// Creates the audio channel agent if needed. Returns true if the audio
|
|
|
|
// channel agent is ready to be used.
|
|
|
|
bool MaybeCreateAudioChannelAgent();
|
|
|
|
|
2016-08-29 11:34:26 +03:00
|
|
|
// Determine if the element should be paused because of suspend conditions.
|
|
|
|
bool ShouldElementBePaused();
|
|
|
|
|
2016-08-29 13:56:32 +03:00
|
|
|
// Create or destroy the captured stream depend on mAudioCapturedByWindow.
|
|
|
|
void AudioCaptureStreamChangeIfNeeded();
|
|
|
|
|
2016-05-03 04:52:38 +03:00
|
|
|
/**
|
|
|
|
* We have different kinds of suspended cases,
|
|
|
|
* - SUSPENDED_PAUSE
|
|
|
|
* It's used when we temporary lost platform audio focus. MediaElement can
|
|
|
|
* only be resumed when we gain the audio focus again.
|
|
|
|
*
|
|
|
|
* - SUSPENDED_PAUSE_DISPOSABLE
|
|
|
|
* It's used when user press the pause botton on the remote media-control.
|
|
|
|
* MediaElement can be resumed by reomte media-control or via play().
|
|
|
|
*
|
|
|
|
* - SUSPENDED_BLOCK
|
|
|
|
* It's used to reduce the power comsuption, we won't play the auto-play
|
|
|
|
* audio/video in the page we have never visited before. MediaElement would
|
|
|
|
* be resumed when the page is active. See bug647429 for more details.
|
|
|
|
*
|
|
|
|
* - SUSPENDED_STOP_DISPOSABLE
|
|
|
|
* When we permanently lost platform audio focus, we shuold stop playing
|
|
|
|
* and stop the audio channel agent. MediaElement can only be restarted by
|
|
|
|
* play().
|
|
|
|
*/
|
|
|
|
void PauseByAudioChannel(SuspendTypes aSuspend);
|
|
|
|
void BlockByAudioChannel();
|
|
|
|
|
|
|
|
void ResumeFromAudioChannel();
|
|
|
|
void ResumeFromAudioChannelPaused(SuspendTypes aSuspend);
|
|
|
|
void ResumeFromAudioChannelBlocked();
|
|
|
|
|
|
|
|
bool IsSuspendedByAudioChannel() const;
|
|
|
|
void SetAudioChannelSuspended(SuspendTypes aSuspend);
|
|
|
|
|
|
|
|
bool IsAllowedToPlay();
|
|
|
|
|
2016-06-01 05:26:10 +03:00
|
|
|
bool IsAudible() const;
|
2016-07-06 05:34:29 +03:00
|
|
|
bool HaveFailedWithSourceNotSupportedError() const;
|
|
|
|
|
|
|
|
void OpenUnsupportedMediaWithExtenalAppIfNeeded();
|
2016-06-01 05:26:10 +03:00
|
|
|
|
2015-01-19 07:11:43 +03:00
|
|
|
class nsAsyncEventRunner;
|
|
|
|
using nsGenericHTMLElement::DispatchEvent;
|
|
|
|
// For nsAsyncEventRunner.
|
|
|
|
nsresult DispatchEvent(const nsAString& aName);
|
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
// The current decoder. Load() has been called on this decoder.
|
2012-08-20 08:52:59 +04:00
|
|
|
// At most one of mDecoder and mSrcStream can be non-null.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaDecoder> mDecoder;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-01-14 06:38:08 +03:00
|
|
|
// Observers listening to changes to the mDecoder principal.
|
|
|
|
// Used by streams captured from this element.
|
|
|
|
nsTArray<DecoderPrincipalChangeObserver*> mDecoderPrincipalChangeObservers;
|
|
|
|
|
2015-04-29 05:02:31 +03:00
|
|
|
// State-watching manager.
|
|
|
|
WatchManager<HTMLMediaElement> mWatchManager;
|
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
// A reference to the VideoFrameContainer which contains the current frame
|
2010-03-02 02:41:49 +03:00
|
|
|
// of video to display.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VideoFrameContainer> mVideoFrameContainer;
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
// Holds a reference to the DOM wrapper for the MediaStream that has been
|
|
|
|
// set in the src attribute.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMediaStream> mSrcAttrStream;
|
2012-04-30 07:12:28 +04:00
|
|
|
|
|
|
|
// Holds a reference to the DOM wrapper for the MediaStream that we're
|
|
|
|
// actually playing.
|
2012-08-20 08:52:59 +04:00
|
|
|
// At most one of mDecoder and mSrcStream can be non-null.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMediaStream> mSrcStream;
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2016-08-19 14:41:48 +03:00
|
|
|
// True once mSrcStream's initial set of tracks are known.
|
|
|
|
bool mSrcStreamTracksAvailable;
|
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
// If non-negative, the time we should return for currentTime while playing
|
|
|
|
// mSrcStream.
|
|
|
|
double mSrcStreamPausedCurrentTime;
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2015-07-24 15:28:17 +03:00
|
|
|
// Holds a reference to the stream connecting this stream to the capture sink.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaInputPort> mCaptureStreamPort;
|
2015-07-24 15:28:17 +03:00
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
// Holds references to the DOM wrappers for the MediaStreams that we're
|
|
|
|
// writing to.
|
|
|
|
nsTArray<OutputMediaStream> mOutputStreams;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// Holds a reference to the MediaStreamListener attached to mSrcStream's
|
|
|
|
// playback stream.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<StreamListener> mMediaStreamListener;
|
2015-04-08 08:51:21 +03:00
|
|
|
// Holds a reference to the size-getting MediaStreamListener attached to
|
|
|
|
// mSrcStream.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<StreamSizeListener> mMediaStreamSizeListener;
|
2016-05-10 12:02:15 +03:00
|
|
|
// The selected video stream track which contained mMediaStreamSizeListener.
|
|
|
|
RefPtr<VideoStreamTrack> mSelectedVideoStreamTrack;
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
const RefPtr<ShutdownObserver> mShutdownObserver;
|
|
|
|
|
2015-05-26 13:36:04 +03:00
|
|
|
// Holds a reference to the MediaSource, if any, referenced by the src
|
|
|
|
// attribute on the media element.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaSource> mSrcMediaSource;
|
2015-05-26 13:36:04 +03:00
|
|
|
|
|
|
|
// Holds a reference to the MediaSource supplying data for playback. This
|
|
|
|
// may either match mSrcMediaSource or come from Source element children.
|
2015-05-28 05:38:34 +03:00
|
|
|
// This is set when and only when mLoadingSrc corresponds to an object url
|
|
|
|
// that resolved to a MediaSource.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaSource> mMediaSource;
|
2013-06-21 07:15:47 +04:00
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
RefPtr<ChannelLoader> mChannelLoader;
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Error attribute
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaError> mError;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
// The current media load ID. This is incremented every time we start a
|
|
|
|
// new load. Async events note the ID when they're first sent, and only fire
|
|
|
|
// if the ID is unchanged when they come to fire.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCurrentLoadID;
|
2009-03-08 23:59:08 +03:00
|
|
|
|
|
|
|
// Points to the child source elements, used to iterate through the children
|
|
|
|
// when selecting a resource to load.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> mSourcePointer;
|
2009-02-16 04:05:28 +03:00
|
|
|
|
2009-03-09 00:01:03 +03:00
|
|
|
// Points to the document whose load we're blocking. This is the document
|
|
|
|
// we're bound to when loading starts.
|
|
|
|
nsCOMPtr<nsIDocument> mLoadBlockedDoc;
|
|
|
|
|
2010-09-10 08:20:10 +04:00
|
|
|
// Contains names of events that have been raised while in the bfcache.
|
|
|
|
// These events get re-dispatched when the bfcache is exited.
|
|
|
|
nsTArray<nsString> mPendingEvents;
|
|
|
|
|
2009-11-06 10:34:00 +03:00
|
|
|
// Media loading flags. See:
|
2008-07-09 12:22:20 +04:00
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/#video)
|
|
|
|
nsMediaNetworkState mNetworkState;
|
2015-03-19 05:01:12 +03:00
|
|
|
Watchable<nsMediaReadyState> mReadyState;
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
enum LoadAlgorithmState {
|
2010-09-03 04:03:03 +04:00
|
|
|
// No load algorithm instance is waiting for a source to be added to the
|
|
|
|
// media in order to continue loading.
|
2009-03-08 23:59:08 +03:00
|
|
|
NOT_WAITING,
|
2012-11-16 07:25:26 +04:00
|
|
|
// We've run the load algorithm, and we tried all source children of the
|
2010-09-03 04:03:03 +04:00
|
|
|
// media element, and failed to load any successfully. We're waiting for
|
|
|
|
// another source element to be added to the media element, and will try
|
|
|
|
// to load any such element when its added.
|
2009-11-06 10:34:00 +03:00
|
|
|
WAITING_FOR_SOURCE
|
2009-03-08 23:59:08 +03:00
|
|
|
};
|
2009-11-06 10:34:00 +03:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
// Denotes the waiting state of a load algorithm instance. When the load
|
|
|
|
// algorithm is waiting for a source element child to be added, this is set
|
|
|
|
// to WAITING_FOR_SOURCE, otherwise it's NOT_WAITING.
|
2009-03-08 23:59:08 +03:00
|
|
|
LoadAlgorithmState mLoadWaitStatus;
|
|
|
|
|
2009-02-25 13:59:00 +03:00
|
|
|
// Current audio volume
|
2011-01-17 06:03:00 +03:00
|
|
|
double mVolume;
|
2008-09-30 03:05:06 +04:00
|
|
|
|
2012-11-29 02:08:53 +04:00
|
|
|
nsAutoPtr<const MetadataTags> mTags;
|
2012-07-31 04:14:29 +04:00
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
// URI of the resource we're attempting to load. This stores the value we
|
|
|
|
// return in the currentSrc attribute. Use GetCurrentSrc() to access the
|
|
|
|
// currentSrc attribute.
|
|
|
|
// This is always the original URL we're trying to load --- before
|
|
|
|
// redirects etc.
|
2010-09-03 04:03:03 +04:00
|
|
|
nsCOMPtr<nsIURI> mLoadingSrc;
|
2012-11-14 23:45:33 +04:00
|
|
|
|
2010-08-20 02:50:37 +04:00
|
|
|
// Stores the current preload action for this element. Initially set to
|
|
|
|
// PRELOAD_UNDEFINED, its value is changed by calling
|
|
|
|
// UpdatePreloadAction().
|
|
|
|
PreloadAction mPreloadAction;
|
|
|
|
|
2010-11-24 21:34:57 +03:00
|
|
|
// Time that the last timeupdate event was fired. Read/Write from the
|
|
|
|
// main thread only.
|
|
|
|
TimeStamp mTimeUpdateTime;
|
|
|
|
|
2014-11-28 02:17:18 +03:00
|
|
|
// Time that the last progress event was fired. Read/Write from the
|
|
|
|
// main thread only.
|
|
|
|
TimeStamp mProgressTime;
|
|
|
|
|
|
|
|
// Time that data was last read from the media resource. Used for
|
|
|
|
// computing if the download has stalled and to rate limit progress events
|
2014-11-28 07:07:15 +03:00
|
|
|
// when data is arriving slower than PROGRESS_MS.
|
|
|
|
// Read/Write from the main thread only.
|
2014-11-28 02:17:18 +03:00
|
|
|
TimeStamp mDataTime;
|
|
|
|
|
2010-11-24 21:34:57 +03:00
|
|
|
// Media 'currentTime' value when the last timeupdate event occurred.
|
|
|
|
// Read/Write from the main thread only.
|
2011-01-17 06:03:00 +03:00
|
|
|
double mLastCurrentTime;
|
2010-11-24 21:34:57 +03:00
|
|
|
|
2011-08-25 03:42:23 +04:00
|
|
|
// Logical start time of the media resource in seconds as obtained
|
|
|
|
// from any media fragments. A negative value indicates that no
|
|
|
|
// fragment time has been set. Read/Write from the main thread only.
|
|
|
|
double mFragmentStart;
|
|
|
|
|
|
|
|
// Logical end time of the media resource in seconds as obtained
|
|
|
|
// from any media fragments. A negative value indicates that no
|
|
|
|
// fragment time has been set. Read/Write from the main thread only.
|
|
|
|
double mFragmentEnd;
|
|
|
|
|
2012-11-22 14:38:28 +04:00
|
|
|
// The defaultPlaybackRate attribute gives the desired speed at which the
|
|
|
|
// media resource is to play, as a multiple of its intrinsic speed.
|
|
|
|
double mDefaultPlaybackRate;
|
|
|
|
|
|
|
|
// The playbackRate attribute gives the speed at which the media resource
|
|
|
|
// plays, as a multiple of its intrinsic speed. If it is not equal to the
|
|
|
|
// defaultPlaybackRate, then the implication is that the user is using a
|
|
|
|
// feature such as fast forward or slow motion playback.
|
|
|
|
double mPlaybackRate;
|
|
|
|
|
|
|
|
// True if pitch correction is applied when playbackRate is set to a
|
|
|
|
// non-intrinsic value.
|
|
|
|
bool mPreservesPitch;
|
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
// Reference to the source element last returned by GetNextSource().
|
|
|
|
// This is the child source element which we're trying to load from.
|
|
|
|
nsCOMPtr<nsIContent> mSourceLoadCandidate;
|
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
// Range of time played.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TimeRanges> mPlayed;
|
2012-05-01 04:29:24 +04:00
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
// Timer used for updating progress events.
|
2014-11-28 02:17:18 +03:00
|
|
|
nsCOMPtr<nsITimer> mProgressTimer;
|
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
// Timer used to simulate video-suspend.
|
|
|
|
nsCOMPtr<nsITimer> mVideoDecodeSuspendTimer;
|
|
|
|
|
2014-06-07 00:52:15 +04:00
|
|
|
// Encrypted Media Extension media keys.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaKeys> mMediaKeys;
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
// Stores the time at the start of the current 'played' range.
|
|
|
|
double mCurrentPlayRangeStart;
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// If true then we have begun downloading the media content.
|
|
|
|
// Set to false when completed, or not yet started.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mBegun;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-09-24 11:25:00 +04:00
|
|
|
// True if loadeddata has been fired.
|
|
|
|
bool mLoadedDataFired;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
|
|
|
// Indicates whether current playback is a result of user action
|
|
|
|
// (ie. calling of the Play method), or automatic playback due to
|
2009-11-06 10:34:00 +03:00
|
|
|
// the 'autoplay' attribute being set. A true value indicates the
|
2008-07-09 12:22:20 +04:00
|
|
|
// latter case.
|
|
|
|
// The 'autoplay' HTML attribute indicates that the video should
|
|
|
|
// start playing when loaded. The 'autoplay' attribute of the object
|
|
|
|
// is a mirror of the HTML attribute. These are different from this
|
|
|
|
// 'mAutoplaying' flag, which indicates whether the current playback
|
|
|
|
// is a result of the autoplay attribute.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAutoplaying;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2009-11-06 10:34:00 +03:00
|
|
|
// Indicates whether |autoplay| will actually autoplay based on the pref
|
2009-02-20 07:05:07 +03:00
|
|
|
// media.autoplay.enabled
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAutoplayEnabled;
|
2009-02-20 07:05:07 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
// Playback of the video is paused either due to calling the
|
|
|
|
// 'Pause' method, or playback not yet having started.
|
2012-11-01 16:47:51 +04:00
|
|
|
WakeLockBoolWrapper mPaused;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-05-21 21:49:17 +04:00
|
|
|
enum MutedReasons {
|
|
|
|
MUTED_BY_CONTENT = 0x01,
|
|
|
|
MUTED_BY_INVALID_PLAYBACK_RATE = 0x02,
|
2014-05-23 13:34:14 +04:00
|
|
|
MUTED_BY_AUDIO_CHANNEL = 0x04,
|
|
|
|
MUTED_BY_AUDIO_TRACK = 0x08
|
2013-05-21 21:49:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t mMuted;
|
2016-05-03 04:52:38 +03:00
|
|
|
SuspendTypes mAudioChannelSuspended;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-06-06 20:33:50 +04:00
|
|
|
// True if the media statistics are currently being shown by the builtin
|
|
|
|
// video controls
|
|
|
|
bool mStatsShowing;
|
|
|
|
|
2014-06-15 01:01:55 +04:00
|
|
|
// The following two fields are here for the private storage of the builtin
|
|
|
|
// video controls, and control 'casting' of the video to external devices
|
|
|
|
// (TVs, projectors etc.)
|
|
|
|
// True if casting is currently allowed
|
|
|
|
bool mAllowCasting;
|
|
|
|
// True if currently casting this video
|
|
|
|
bool mIsCasting;
|
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
// True if the sound is being captured.
|
|
|
|
bool mAudioCaptured;
|
|
|
|
|
2015-07-24 15:28:17 +03:00
|
|
|
// True if the sound is being captured by the window.
|
|
|
|
bool mAudioCapturedByWindow;
|
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// If TRUE then the media element was actively playing before the currently
|
|
|
|
// in progress seeking. If FALSE then the media element is either not seeking
|
|
|
|
// or was not actively playing before the current seek. Used to decide whether
|
|
|
|
// to raise the 'waiting' event as per 4.7.1.8 in HTML 5 specification.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mPlayingBeforeSeek;
|
2008-10-28 21:48:39 +03:00
|
|
|
|
2014-08-28 12:07:00 +04:00
|
|
|
// if TRUE then the seek started while content was in active playing state
|
|
|
|
// if FALSE then the seek started while the content was not playing.
|
|
|
|
bool mPlayingThroughTheAudioChannelBeforeSeek;
|
|
|
|
|
2012-12-12 05:58:07 +04:00
|
|
|
// True iff this element is paused because the document is inactive or has
|
|
|
|
// been suspended by the audio channel service.
|
|
|
|
bool mPausedForInactiveDocumentOrChannel;
|
|
|
|
|
|
|
|
// True iff event delivery is suspended (mPausedForInactiveDocumentOrChannel must also be true).
|
|
|
|
bool mEventDeliveryPaused;
|
2009-11-06 10:34:00 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we're running the "load()" method.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsRunningLoadMethod;
|
2009-03-08 23:59:08 +03:00
|
|
|
|
2015-06-17 03:02:51 +03:00
|
|
|
// True if we're running or waiting to run queued tasks due to an explicit
|
|
|
|
// call to "load()".
|
|
|
|
bool mIsDoingExplicitLoad;
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we're loading the resource from the child source elements.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsLoadingFromSourceChildren;
|
2009-03-09 00:01:03 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we're delaying the "load" event. They are delayed until either
|
2009-03-09 00:01:03 +03:00
|
|
|
// an error occurs, or the first frame is loaded.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDelayingLoadEvent;
|
2009-03-09 00:01:03 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True when we've got a task queued to call SelectResource(),
|
2009-03-09 00:01:03 +03:00
|
|
|
// or while we're running SelectResource().
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsRunningSelectResource;
|
2009-05-18 06:00:44 +04:00
|
|
|
|
2012-02-20 01:02:08 +04:00
|
|
|
// True when we already have select resource call queued
|
|
|
|
bool mHaveQueuedSelectResource;
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we suspended the decoder because we were paused,
|
2010-08-20 02:50:37 +04:00
|
|
|
// preloading metadata is enabled, autoplay was not enabled, and we loaded
|
|
|
|
// the first frame.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSuspendedAfterFirstFrame;
|
2009-05-18 06:00:44 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we are allowed to suspend the decoder because we were paused,
|
2010-08-20 02:50:37 +04:00
|
|
|
// preloading metdata was enabled, autoplay was not enabled, and we loaded
|
|
|
|
// the first frame.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAllowSuspendAfterFirstFrame;
|
2009-06-26 11:25:17 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we've played or completed a seek. We use this to determine
|
2009-06-26 11:25:17 +04:00
|
|
|
// when the poster frame should be shown.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasPlayedOrSeeked;
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we've added a reference to ourselves to keep the element
|
2009-10-01 18:10:13 +04:00
|
|
|
// alive while no-one is referencing it but the element may still fire
|
|
|
|
// events of its own accord.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasSelfReference;
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we've received a notification that the engine is shutting
|
2010-02-24 22:14:14 +03:00
|
|
|
// down.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mShuttingDown;
|
2010-02-24 22:14:14 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if we've suspended a load in the resource selection algorithm
|
|
|
|
// due to loading a preload:none media. When true, the resource we'll
|
2010-08-20 02:50:37 +04:00
|
|
|
// load when the user initiates either playback or an explicit load is
|
|
|
|
// stored in mPreloadURI.
|
2012-05-28 02:40:06 +04:00
|
|
|
bool mSuspendedForPreloadNone;
|
2010-08-25 17:10:00 +04:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
// True if we've connected mSrcStream to the media element output.
|
|
|
|
bool mSrcStreamIsPlaying;
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if a same-origin check has been done for the media element and resource.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mMediaSecurityVerified;
|
2012-01-26 02:31:30 +04:00
|
|
|
|
|
|
|
// The CORS mode when loading the media element
|
2013-03-19 16:23:54 +04:00
|
|
|
CORSMode mCORSMode;
|
2012-04-28 19:01:10 +04:00
|
|
|
|
2015-02-09 09:51:17 +03:00
|
|
|
// Info about the played media.
|
|
|
|
MediaInfo mMediaInfo;
|
2014-10-01 19:39:10 +04:00
|
|
|
|
2015-01-27 09:10:11 +03:00
|
|
|
// True if the media has encryption information.
|
|
|
|
bool mIsEncrypted;
|
|
|
|
|
2016-08-21 23:51:01 +03:00
|
|
|
// True when the CDM cannot decrypt the current block, and the
|
|
|
|
// waitingforkey event has been fired. Back to false when keys have become
|
|
|
|
// available and we can advance the current playback position.
|
|
|
|
bool mWaitingForKey;
|
|
|
|
|
|
|
|
// Listens for waitingForKey events from the owned decoder.
|
|
|
|
MediaEventListener mWaitingForKeyListener;
|
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
// Init Data that needs to be sent in 'encrypted' events in MetadataLoaded().
|
|
|
|
EncryptionInfo mPendingEncryptedInitData;
|
|
|
|
|
2012-05-28 02:40:06 +04:00
|
|
|
// True if the media's channel's download has been suspended.
|
2015-03-19 05:01:12 +03:00
|
|
|
Watchable<bool> mDownloadSuspendedByCache;
|
2012-09-05 04:49:46 +04:00
|
|
|
|
2014-04-10 21:39:20 +04:00
|
|
|
// Audio Channel.
|
|
|
|
AudioChannel mAudioChannel;
|
2012-12-04 23:46:07 +04:00
|
|
|
|
2015-07-10 19:38:44 +03:00
|
|
|
// The audio channel volume
|
|
|
|
float mAudioChannelVolume;
|
2013-09-02 13:45:44 +04:00
|
|
|
|
2012-12-04 23:46:07 +04:00
|
|
|
// Is this media element playing?
|
|
|
|
bool mPlayingThroughTheAudioChannel;
|
2012-12-06 19:25:18 +04:00
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
// Disable the video playback by track selection. This flag might not be
|
|
|
|
// enough if we ever expand the ability of supporting multi-tracks video
|
|
|
|
// playback.
|
|
|
|
bool mDisableVideo;
|
|
|
|
|
2012-12-06 19:25:18 +04:00
|
|
|
// An agent used to join audio channel service.
|
|
|
|
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextTrackManager> mTextTrackManager;
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioTrackList> mAudioTrackList;
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VideoTrackList> mVideoTrackList;
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2016-01-05 05:16:28 +03:00
|
|
|
nsAutoPtr<MediaStreamTrackListener> mMediaStreamTrackListener;
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
// The principal guarding mVideoFrameContainer access when playing a
|
|
|
|
// MediaStream.
|
|
|
|
nsCOMPtr<nsIPrincipal> mSrcStreamVideoPrincipal;
|
|
|
|
|
2014-12-15 10:34:28 +03:00
|
|
|
enum ElementInTreeState {
|
|
|
|
// The MediaElement is not in the DOM tree now.
|
|
|
|
ELEMENT_NOT_INTREE,
|
|
|
|
// The MediaElement is in the DOM tree now.
|
|
|
|
ELEMENT_INTREE,
|
|
|
|
// The MediaElement is not in the DOM tree now but had been binded to the
|
|
|
|
// tree before.
|
|
|
|
ELEMENT_NOT_INTREE_HAD_INTREE
|
|
|
|
};
|
|
|
|
|
|
|
|
ElementInTreeState mElementInTreeState;
|
|
|
|
|
2015-02-24 06:11:43 +03:00
|
|
|
public:
|
|
|
|
// Helper class to measure times for MSE telemetry stats
|
2016-07-19 10:46:38 +03:00
|
|
|
class TimeDurationAccumulator
|
|
|
|
{
|
2015-02-24 06:11:43 +03:00
|
|
|
public:
|
|
|
|
TimeDurationAccumulator()
|
|
|
|
: mCount(0)
|
2016-07-19 10:46:38 +03:00
|
|
|
{}
|
|
|
|
void Start()
|
2015-02-24 06:11:43 +03:00
|
|
|
{
|
|
|
|
if (IsStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mStartTime = TimeStamp::Now();
|
|
|
|
}
|
2016-07-19 10:46:38 +03:00
|
|
|
void Pause()
|
|
|
|
{
|
2015-02-24 06:11:43 +03:00
|
|
|
if (!IsStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mSum += (TimeStamp::Now() - mStartTime);
|
|
|
|
mCount++;
|
|
|
|
mStartTime = TimeStamp();
|
|
|
|
}
|
2016-07-19 10:46:38 +03:00
|
|
|
bool IsStarted() const
|
|
|
|
{
|
2015-02-24 06:11:43 +03:00
|
|
|
return !mStartTime.IsNull();
|
|
|
|
}
|
2016-07-19 10:46:38 +03:00
|
|
|
double Total() const
|
|
|
|
{
|
|
|
|
if (!IsStarted()) {
|
|
|
|
return mSum.ToSeconds();
|
|
|
|
}
|
|
|
|
// Add current running time until now, but keep it running.
|
|
|
|
return (mSum + (TimeStamp::Now() - mStartTime)).ToSeconds();
|
2015-02-24 06:11:43 +03:00
|
|
|
}
|
2016-07-19 10:46:38 +03:00
|
|
|
uint32_t Count() const
|
|
|
|
{
|
|
|
|
if (!IsStarted()) {
|
|
|
|
return mCount;
|
|
|
|
}
|
|
|
|
// Count current run in this report, without increasing the stored count.
|
|
|
|
return mCount + 1;
|
2015-02-24 06:11:43 +03:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
TimeStamp mStartTime;
|
|
|
|
TimeDuration mSum;
|
|
|
|
uint32_t mCount;
|
|
|
|
};
|
|
|
|
private:
|
2016-04-22 00:39:10 +03:00
|
|
|
// Total time a video has spent playing.
|
2015-02-24 06:11:43 +03:00
|
|
|
TimeDurationAccumulator mPlayTime;
|
|
|
|
|
2016-07-08 09:40:31 +03:00
|
|
|
// Total time a video has spent playing while hidden.
|
|
|
|
TimeDurationAccumulator mHiddenPlayTime;
|
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
// Total time a video has (or would have) spent in video-decode-suspend mode.
|
|
|
|
TimeDurationAccumulator mVideoDecodeSuspendTime;
|
|
|
|
|
2015-07-24 16:56:00 +03:00
|
|
|
// Indicates if user has interacted with the element.
|
|
|
|
// Used to block autoplay when disabled.
|
|
|
|
bool mHasUserInteraction;
|
2015-10-22 10:46:27 +03:00
|
|
|
|
|
|
|
// True if the first frame has been successfully loaded.
|
|
|
|
bool mFirstFrameLoaded;
|
2015-10-26 12:36:16 +03:00
|
|
|
|
|
|
|
// Media elements also have a default playback start position, which must
|
|
|
|
// initially be set to zero seconds. This time is used to allow the element to
|
|
|
|
// be seeked even before the media is loaded.
|
|
|
|
double mDefaultPlaybackStartPosition;
|
2016-01-21 05:27:38 +03:00
|
|
|
|
2016-06-01 05:26:10 +03:00
|
|
|
// True if the audio track is not silent.
|
2016-01-21 05:27:38 +03:00
|
|
|
bool mIsAudioTrackAudible;
|
2016-06-01 05:26:10 +03:00
|
|
|
|
|
|
|
// True if media element is audible for users.
|
|
|
|
bool mAudible;
|
2016-09-02 11:52:44 +03:00
|
|
|
|
|
|
|
Visibility mVisibilityState;
|
2008-07-09 12:22:20 +04:00
|
|
|
};
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLMediaElement_h
|