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/. */
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "objbase.h"
|
|
|
|
// Some Windows header defines this, so undef it as it conflicts with our
|
|
|
|
// function of the same name.
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "AudioChannelService.h"
|
2018-10-12 12:39:30 +03:00
|
|
|
#include "AudioDeviceInfo.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "AudioStreamTrack.h"
|
|
|
|
#include "AutoplayPolicy.h"
|
|
|
|
#include "ChannelMediaDecoder.h"
|
|
|
|
#include "DOMMediaStream.h"
|
|
|
|
#include "DecoderDoctorDiagnostics.h"
|
|
|
|
#include "DecoderDoctorLogger.h"
|
|
|
|
#include "DecoderTraits.h"
|
|
|
|
#include "FrameStatistics.h"
|
|
|
|
#include "GMPCrashHelper.h"
|
|
|
|
#ifdef MOZ_ANDROID_HLS_SUPPORT
|
|
|
|
#include "HLSDecoder.h"
|
|
|
|
#endif
|
|
|
|
#include "HTMLMediaElement.h"
|
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "Layers.h"
|
|
|
|
#include "MP4Decoder.h"
|
|
|
|
#include "MediaContainerType.h"
|
|
|
|
#include "MediaError.h"
|
2018-10-12 12:39:30 +03:00
|
|
|
#include "MediaManager.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "MediaMetadataManager.h"
|
|
|
|
#include "MediaResource.h"
|
2018-12-13 23:06:03 +03:00
|
|
|
#include "MediaShutdownManager.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "MediaSourceDecoder.h"
|
|
|
|
#include "MediaStreamError.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
|
|
|
#include "MediaStreamListener.h"
|
|
|
|
#include "MediaTrackList.h"
|
|
|
|
#include "SVGObserverUtils.h"
|
|
|
|
#include "TimeRanges.h"
|
|
|
|
#include "VideoFrameContainer.h"
|
|
|
|
#include "VideoStreamTrack.h"
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "jsapi.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2014-06-07 00:52:15 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2018-12-13 23:04:46 +03:00
|
|
|
#include "mozilla/AutoplayPermissionManager.h"
|
2016-10-31 00:55:19 +03:00
|
|
|
#include "mozilla/EMEUtils.h"
|
2017-11-17 06:07:12 +03:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "mozilla/EventStateManager.h"
|
|
|
|
#include "mozilla/FloatingPoint.h"
|
2018-03-20 01:48:56 +03:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2017-10-17 05:55:11 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2018-03-20 01:48:56 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/dom/AudioTrack.h"
|
|
|
|
#include "mozilla/dom/AudioTrackList.h"
|
2018-06-02 16:51:42 +03:00
|
|
|
#include "mozilla/dom/BlobURLProtocolHandler.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
|
|
|
#include "mozilla/dom/HTMLAudioElement.h"
|
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElementBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLSourceElement.h"
|
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
|
|
|
#include "mozilla/dom/MediaEncryptedEvent.h"
|
|
|
|
#include "mozilla/dom/MediaErrorBinding.h"
|
|
|
|
#include "mozilla/dom/MediaSource.h"
|
|
|
|
#include "mozilla/dom/PlayPromise.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/TextTrack.h"
|
|
|
|
#include "mozilla/dom/VideoPlaybackQuality.h"
|
|
|
|
#include "mozilla/dom/VideoTrack.h"
|
|
|
|
#include "mozilla/dom/VideoTrackList.h"
|
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsDocShell.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2018-06-29 16:14:33 +03:00
|
|
|
#include "nsIAutoplay.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIClassOfService.h"
|
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2013-03-30 01:52:59 +04:00
|
|
|
#include "nsIDocShell.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFrame.h"
|
2016-10-27 04:59:55 +03:00
|
|
|
#include "nsIObserverService.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIScriptError.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIThreadInternal.h"
|
2008-07-09 12:22:20 +04:00
|
|
|
#include "nsITimer.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsJSUtils.h"
|
2009-12-11 07:02:13 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2011-08-25 03:42:23 +04:00
|
|
|
#include "nsMediaFragmentURIParser.h"
|
2018-03-06 19:43:57 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsQueryObject.h"
|
2013-08-22 22:32:52 +04:00
|
|
|
#include "nsRange.h"
|
2018-05-14 12:11:18 +03:00
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsVideoFrame.h"
|
|
|
|
#include "xpcpublic.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2015-08-01 17:31:04 +03:00
|
|
|
#include <cmath>
|
2018-05-14 12:11:18 +03:00
|
|
|
#include <limits>
|
2012-08-21 08:06:46 +04:00
|
|
|
|
2018-04-13 11:28:39 +03:00
|
|
|
mozilla::LazyLogModule gMediaElementLog("nsMediaElement");
|
2015-11-23 22:09:25 +03:00
|
|
|
static mozilla::LazyLogModule gMediaElementEventsLog("nsMediaElementEvents");
|
|
|
|
|
2018-08-02 03:30:59 +03:00
|
|
|
extern mozilla::LazyLogModule gAutoplayPermissionLog;
|
|
|
|
#define AUTOPLAY_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
|
2015-05-21 23:22:04 +03:00
|
|
|
#define LOG(type, msg) MOZ_LOG(gMediaElementLog, type, msg)
|
|
|
|
#define LOG_EVENT(type, msg) MOZ_LOG(gMediaElementEventsLog, type, msg)
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
using namespace mozilla::layers;
|
2012-12-21 05:04:50 +04:00
|
|
|
using mozilla::net::nsMediaFragmentURIParser;
|
2018-06-26 00:20:54 +03:00
|
|
|
using namespace mozilla::dom::HTMLMediaElement_Binding;
|
2012-11-14 23:45:33 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-11-28 02:17:18 +03:00
|
|
|
// Number of milliseconds between progress events as defined by spec
|
|
|
|
static const uint32_t PROGRESS_MS = 350;
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
// Number of milliseconds of no data before a stall event is fired as defined by
|
|
|
|
// spec
|
2014-11-28 02:17:18 +03:00
|
|
|
static const uint32_t STALL_MS = 3000;
|
|
|
|
|
2013-09-02 13:45:44 +04:00
|
|
|
// Used by AudioChannel for suppresssing the volume to this ratio.
|
|
|
|
#define FADED_VOLUME_RATIO 0.25
|
|
|
|
|
2012-11-22 14:38:28 +04:00
|
|
|
// These constants are arbitrary
|
|
|
|
// Minimum playbackRate for a media
|
2017-06-28 20:00:58 +03:00
|
|
|
static const double MIN_PLAYBACKRATE = 1.0 / 16;
|
2012-11-22 14:38:28 +04:00
|
|
|
// Maximum playbackRate for a media
|
2017-06-28 20:00:58 +03:00
|
|
|
static const double MAX_PLAYBACKRATE = 16.0;
|
2018-05-14 12:11:18 +03:00
|
|
|
// These are the limits beyonds which SoundTouch does not perform too well and
|
|
|
|
// when speech is hard to understand anyway. Threshold above which audio is
|
|
|
|
// muted
|
2012-11-22 14:38:28 +04:00
|
|
|
static const double THRESHOLD_HIGH_PLAYBACKRATE_AUDIO = 4.0;
|
|
|
|
// Threshold under which audio is muted
|
|
|
|
static const double THRESHOLD_LOW_PLAYBACKRATE_AUDIO = 0.5;
|
|
|
|
|
2018-11-07 16:56:25 +03:00
|
|
|
static double ClampPlaybackRate(double aPlaybackRate) {
|
|
|
|
MOZ_ASSERT(aPlaybackRate >= 0.0);
|
|
|
|
|
|
|
|
if (aPlaybackRate == 0.0) {
|
|
|
|
return aPlaybackRate;
|
|
|
|
}
|
|
|
|
if (aPlaybackRate < MIN_PLAYBACKRATE) {
|
|
|
|
return MIN_PLAYBACKRATE;
|
|
|
|
}
|
|
|
|
if (aPlaybackRate > MAX_PLAYBACKRATE) {
|
|
|
|
return MAX_PLAYBACKRATE;
|
|
|
|
}
|
|
|
|
return aPlaybackRate;
|
|
|
|
}
|
|
|
|
|
2016-09-15 18:41:35 +03:00
|
|
|
// Media error values. These need to match the ones in MediaError.webidl.
|
|
|
|
static const unsigned short MEDIA_ERR_ABORTED = 1;
|
|
|
|
static const unsigned short MEDIA_ERR_NETWORK = 2;
|
|
|
|
static const unsigned short MEDIA_ERR_DECODE = 3;
|
|
|
|
static const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
|
|
|
|
2018-04-13 11:28:39 +03:00
|
|
|
static void ResolvePromisesWithUndefined(
|
|
|
|
const nsTArray<RefPtr<PlayPromise>>& aPromises) {
|
2016-12-09 03:34:39 +03:00
|
|
|
for (auto& promise : aPromises) {
|
|
|
|
promise->MaybeResolveWithUndefined();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 11:28:39 +03:00
|
|
|
static void RejectPromises(const nsTArray<RefPtr<PlayPromise>>& aPromises,
|
|
|
|
nsresult aError) {
|
2016-12-09 03:34:39 +03:00
|
|
|
for (auto& promise : aPromises) {
|
|
|
|
promise->MaybeReject(aError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
// Under certain conditions there may be no-one holding references to
|
|
|
|
// a media element from script, DOM parent, etc, but the element may still
|
|
|
|
// fire meaningful events in the future so we can't destroy it yet:
|
|
|
|
// 1) If the element is delaying the load event (or would be, if it were
|
|
|
|
// in a document), then events up to loadeddata or error could be fired,
|
|
|
|
// so we need to stay alive.
|
|
|
|
// 2) If the element is not paused and playback has not ended, then
|
|
|
|
// we will (or might) play, sending timeupdate and ended events and possibly
|
|
|
|
// audio output, so we need to stay alive.
|
|
|
|
// 3) if the element is seeking then we will fire seeking events and possibly
|
|
|
|
// start playing afterward, so we need to stay alive.
|
|
|
|
// 4) If autoplay could start playback in this element (if we got enough data),
|
|
|
|
// then we need to stay alive.
|
2014-12-11 06:08:20 +03:00
|
|
|
// 5) if the element is currently loading, not suspended, and its source is
|
|
|
|
// not a MediaSource, then script might be waiting for progress events or a
|
|
|
|
// 'stalled' or 'suspend' event, so we need to stay alive.
|
|
|
|
// If we're already suspended then (all other conditions being met),
|
|
|
|
// it's OK to just disappear without firing any more events,
|
|
|
|
// since we have the freedom to remain suspended indefinitely. Note
|
2009-10-01 18:10:13 +04:00
|
|
|
// that we could use this 'suspended' loophole to garbage-collect a suspended
|
|
|
|
// element in case 4 even if it had 'autoplay' set, but we choose not to.
|
|
|
|
// If someone throws away all references to a loading 'autoplay' element
|
|
|
|
// sound should still eventually play.
|
2014-12-11 06:08:20 +03:00
|
|
|
// 6) If the source is a MediaSource, most loading events will not fire unless
|
|
|
|
// appendBuffer() is called on a SourceBuffer, in which case something is
|
|
|
|
// already referencing the SourceBuffer, which keeps the associated media
|
|
|
|
// element alive. Further, a MediaSource will never time out the resource
|
|
|
|
// fetch, and so should not keep the media element alive if it is
|
|
|
|
// unreferenced. A pending 'stalled' event keeps the media element alive.
|
2009-10-01 18:10:13 +04:00
|
|
|
//
|
2018-05-14 12:11:18 +03:00
|
|
|
// Media elements owned by inactive documents (i.e. documents not contained in
|
|
|
|
// any document viewer) should never hold a self-reference because none of the
|
2009-10-01 18:10:13 +04:00
|
|
|
// above conditions are allowed: the element will stop loading and playing
|
|
|
|
// and never resume loading or playing unless its owner document changes to
|
|
|
|
// an active document (which can only happen if there is an external reference
|
|
|
|
// to the element).
|
|
|
|
// Media elements with no owner doc should be able to hold a self-reference.
|
|
|
|
// Something native must have created the element and may expect it to
|
|
|
|
// stay alive to play.
|
|
|
|
|
|
|
|
// It's very important that any change in state which could change the value of
|
|
|
|
// needSelfReference in AddRemoveSelfReference be followed by a call to
|
|
|
|
// AddRemoveSelfReference before this element could die!
|
|
|
|
// It's especially important if needSelfReference would change to 'true',
|
|
|
|
// since if we neglect to add a self-reference, this element might be
|
|
|
|
// garbage collected while there are still event listeners that should
|
|
|
|
// receive events. If we neglect to remove the self-reference then the element
|
|
|
|
// just lives longer than it needs to.
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsMediaEvent : public Runnable {
|
2009-02-20 05:49:00 +03:00
|
|
|
public:
|
2017-07-07 05:36:13 +03:00
|
|
|
explicit nsMediaEvent(const char* aName, HTMLMediaElement* aElement)
|
|
|
|
: Runnable(aName),
|
2017-06-12 22:34:10 +03:00
|
|
|
mElement(aElement),
|
|
|
|
mLoadID(mElement->GetCurrentLoadID()) {}
|
2009-02-20 05:49:00 +03:00
|
|
|
~nsMediaEvent() {}
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Run() override = 0;
|
2009-02-20 05:49:00 +03:00
|
|
|
|
|
|
|
protected:
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsCancelled() { return mElement->GetCurrentLoadID() != mLoadID; }
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLMediaElement> mElement;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLoadID;
|
2009-02-20 05:49:00 +03:00
|
|
|
};
|
|
|
|
|
2015-01-19 07:11:43 +03:00
|
|
|
class HTMLMediaElement::nsAsyncEventRunner : public nsMediaEvent {
|
2008-07-09 12:22:20 +04:00
|
|
|
private:
|
|
|
|
nsString mName;
|
2009-11-06 10:32:52 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
public:
|
2018-05-14 12:11:18 +03:00
|
|
|
nsAsyncEventRunner(const nsAString& aName, HTMLMediaElement* aElement)
|
|
|
|
: nsMediaEvent("HTMLMediaElement::nsAsyncEventRunner", aElement),
|
|
|
|
mName(aName) {}
|
2009-11-06 10:32:52 +03:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2009-02-20 05:49:00 +03:00
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled()) return NS_OK;
|
2010-08-25 17:10:00 +04:00
|
|
|
|
2010-09-10 07:29:06 +04:00
|
|
|
return mElement->DispatchEvent(mName);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
/*
|
|
|
|
* If no error is passed while constructing an instance, the instance will
|
|
|
|
* resolve the passed promises with undefined; otherwise, the instance will
|
|
|
|
* reject the passed promises with the passed error.
|
|
|
|
*
|
|
|
|
* The constructor appends the constructed instance into the passed media
|
|
|
|
* element's mPendingPlayPromisesRunners member and once the the runner is run
|
|
|
|
* (whether fulfilled or canceled), it removes itself from
|
|
|
|
* mPendingPlayPromisesRunners.
|
|
|
|
*/
|
2018-05-14 12:11:18 +03:00
|
|
|
class HTMLMediaElement::nsResolveOrRejectPendingPlayPromisesRunner
|
|
|
|
: public nsMediaEvent {
|
2018-04-13 11:28:39 +03:00
|
|
|
nsTArray<RefPtr<PlayPromise>> mPromises;
|
2016-12-09 03:34:39 +03:00
|
|
|
nsresult mError;
|
|
|
|
|
|
|
|
public:
|
2018-04-13 11:28:39 +03:00
|
|
|
nsResolveOrRejectPendingPlayPromisesRunner(
|
|
|
|
HTMLMediaElement* aElement, nsTArray<RefPtr<PlayPromise>>&& aPromises,
|
|
|
|
nsresult aError = NS_OK)
|
|
|
|
: nsMediaEvent(
|
|
|
|
"HTMLMediaElement::nsResolveOrRejectPendingPlayPromisesRunner",
|
|
|
|
aElement),
|
2018-05-30 22:15:35 +03:00
|
|
|
mPromises(std::move(aPromises)),
|
2018-04-13 11:28:39 +03:00
|
|
|
mError(aError) {
|
2016-12-09 03:34:39 +03:00
|
|
|
mElement->mPendingPlayPromisesRunners.AppendElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResolveOrReject() {
|
|
|
|
if (NS_SUCCEEDED(mError)) {
|
|
|
|
ResolvePromisesWithUndefined(mPromises);
|
|
|
|
} else {
|
|
|
|
RejectPromises(mPromises, mError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
if (!IsCancelled()) {
|
|
|
|
ResolveOrReject();
|
|
|
|
}
|
|
|
|
|
|
|
|
mElement->mPendingPlayPromisesRunners.RemoveElement(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
class HTMLMediaElement::nsNotifyAboutPlayingRunner
|
|
|
|
: public nsResolveOrRejectPendingPlayPromisesRunner {
|
2016-12-09 03:34:39 +03:00
|
|
|
public:
|
2018-04-13 11:28:39 +03:00
|
|
|
nsNotifyAboutPlayingRunner(
|
|
|
|
HTMLMediaElement* aElement,
|
|
|
|
nsTArray<RefPtr<PlayPromise>>&& aPendingPlayPromises)
|
|
|
|
: nsResolveOrRejectPendingPlayPromisesRunner(
|
2018-05-30 22:15:35 +03:00
|
|
|
aElement, std::move(aPendingPlayPromises)) {}
|
2016-12-09 03:34:39 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
if (IsCancelled()) {
|
|
|
|
mElement->mPendingPlayPromisesRunners.RemoveElement(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mElement->DispatchEvent(NS_LITERAL_STRING("playing"));
|
|
|
|
return nsResolveOrRejectPendingPlayPromisesRunner::Run();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
class nsSourceErrorEventRunner : public nsMediaEvent {
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mSource;
|
2018-05-14 12:11:18 +03:00
|
|
|
|
2009-02-16 04:05:28 +03:00
|
|
|
public:
|
2018-05-14 12:11:18 +03:00
|
|
|
nsSourceErrorEventRunner(HTMLMediaElement* aElement, nsIContent* aSource)
|
|
|
|
: nsMediaEvent("dom::nsSourceErrorEventRunner", aElement),
|
|
|
|
mSource(aSource) {}
|
2009-02-16 04:05:28 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2010-09-03 04:03:03 +04:00
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled()) return NS_OK;
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG_EVENT(LogLevel::Debug,
|
|
|
|
("%p Dispatching simple event source error", mElement.get()));
|
|
|
|
return nsContentUtils::DispatchTrustedEvent(
|
2018-06-25 19:23:50 +03:00
|
|
|
mElement->OwnerDoc(), mSource, NS_LITERAL_STRING("error"),
|
|
|
|
CanBubble::eNo, Cancelable::eNo);
|
2009-02-20 05:49:00 +03:00
|
|
|
}
|
2009-02-16 04:05:28 +03:00
|
|
|
};
|
|
|
|
|
2016-05-10 12:02:15 +03:00
|
|
|
/**
|
|
|
|
* This listener observes the first video frame to arrive with a non-empty size,
|
2016-08-31 15:32:13 +03:00
|
|
|
* and calls HTMLMediaElement::UpdateInitialMediaSize() with that size.
|
2016-05-10 12:02:15 +03:00
|
|
|
*/
|
2018-11-23 18:00:43 +03:00
|
|
|
class HTMLMediaElement::VideoFrameListener
|
2018-05-14 12:11:18 +03:00
|
|
|
: public DirectMediaStreamTrackListener {
|
2016-05-10 12:02:15 +03:00
|
|
|
public:
|
2018-11-23 18:00:43 +03:00
|
|
|
explicit VideoFrameListener(HTMLMediaElement* aElement)
|
2018-05-14 12:11:18 +03:00
|
|
|
: mElement(aElement),
|
|
|
|
mMainThreadEventTarget(aElement->MainThreadEventTarget()),
|
|
|
|
mInitialSizeFound(false) {
|
2018-11-23 18:00:43 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-07 05:36:13 +03:00
|
|
|
MOZ_ASSERT(mElement);
|
|
|
|
MOZ_ASSERT(mMainThreadEventTarget);
|
|
|
|
}
|
2016-08-31 15:32:13 +03:00
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
void Forget() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mElement = nullptr;
|
|
|
|
}
|
2016-05-10 12:02:15 +03:00
|
|
|
|
|
|
|
void ReceivedSize(gfx::IntSize aSize) {
|
2016-08-31 15:32:13 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-05-10 12:02:15 +03:00
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-31 15:32:13 +03:00
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
mElement->UpdateInitialMediaSize(aSize);
|
2016-05-10 12:02:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyRealtimeTrackData(MediaStreamGraph* aGraph,
|
|
|
|
StreamTime aTrackOffset,
|
|
|
|
const MediaSegment& aMedia) override {
|
2016-08-31 15:32:13 +03:00
|
|
|
if (mInitialSizeFound) {
|
2016-05-10 12:02:15 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-08-31 15:32:13 +03:00
|
|
|
|
|
|
|
if (aMedia.GetType() != MediaSegment::VIDEO) {
|
|
|
|
MOZ_ASSERT(false, "Should only lock on to a video track");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-10 12:02:15 +03:00
|
|
|
const VideoSegment& video = static_cast<const VideoSegment&>(aMedia);
|
|
|
|
for (VideoSegment::ConstChunkIterator c(video); !c.IsEnded(); c.Next()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
if (c->mFrame.GetIntrinsicSize() != gfx::IntSize(0, 0)) {
|
2016-05-10 12:02:15 +03:00
|
|
|
mInitialSizeFound = true;
|
2016-08-31 15:31:28 +03:00
|
|
|
// This is fine to dispatch straight to main thread (instead of via
|
|
|
|
// ...AfterStreamUpdate()) since it reflects state of the element,
|
|
|
|
// not the stream. Events reflecting stream or track state should be
|
|
|
|
// dispatched so their order is preserved.
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(NewRunnableMethod<gfx::IntSize>(
|
2018-11-23 18:00:43 +03:00
|
|
|
"dom::HTMLMediaElement::VideoFrameListener::ReceivedSize", this,
|
|
|
|
&VideoFrameListener::ReceivedSize, c->mFrame.GetIntrinsicSize()));
|
2016-05-10 12:02:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// These fields may only be accessed on the main thread
|
2018-11-23 18:00:43 +03:00
|
|
|
WeakPtr<HTMLMediaElement> mElement;
|
2017-07-07 05:36:13 +03:00
|
|
|
// We hold mElement->MainThreadEventTarget() here because the mElement could
|
|
|
|
// be reset in Forget().
|
|
|
|
nsCOMPtr<nsISerialEventTarget> mMainThreadEventTarget;
|
2016-05-10 12:02:15 +03:00
|
|
|
|
2016-08-31 15:32:13 +03:00
|
|
|
// These fields may only be accessed on the MSG's appending thread.
|
|
|
|
// (this is a direct listener so we get called by whoever is producing
|
|
|
|
// this track's data)
|
2016-05-10 12:02:15 +03:00
|
|
|
bool mInitialSizeFound;
|
|
|
|
};
|
|
|
|
|
2018-11-23 17:59:56 +03:00
|
|
|
class HTMLMediaElement::StreamCaptureTrackSource
|
|
|
|
: public MediaStreamTrackSource,
|
|
|
|
public MediaStreamTrackSource::Sink {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StreamCaptureTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
|
|
|
|
StreamCaptureTrackSource(HTMLMediaElement* aElement,
|
|
|
|
MediaStreamTrackSource* aCapturedTrackSource,
|
|
|
|
DOMMediaStream* aOwningStream,
|
|
|
|
TrackID aDestinationTrackID)
|
|
|
|
: MediaStreamTrackSource(aCapturedTrackSource->GetPrincipal(),
|
|
|
|
nsString()),
|
|
|
|
mElement(aElement),
|
|
|
|
mCapturedTrackSource(aCapturedTrackSource),
|
|
|
|
mOwningStream(aOwningStream),
|
|
|
|
mDestinationTrackID(aDestinationTrackID) {
|
|
|
|
MOZ_ASSERT(mElement);
|
|
|
|
MOZ_ASSERT(mCapturedTrackSource);
|
|
|
|
MOZ_ASSERT(mOwningStream);
|
|
|
|
MOZ_ASSERT(IsTrackIDExplicit(mDestinationTrackID));
|
|
|
|
|
|
|
|
mCapturedTrackSource->RegisterSink(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy() override {
|
|
|
|
if (mCapturedTrackSource) {
|
|
|
|
mCapturedTrackSource->UnregisterSink(this);
|
|
|
|
mCapturedTrackSource = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaSourceEnum GetMediaSource() const override {
|
|
|
|
return MediaSourceEnum::Other;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode GetCORSMode() const override {
|
|
|
|
if (!mCapturedTrackSource) {
|
|
|
|
// This could happen during shutdown.
|
|
|
|
return CORS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCapturedTrackSource->GetCORSMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stop() override {
|
|
|
|
if (mElement && mElement->mSrcStream) {
|
|
|
|
// Only notify if we're still playing the source stream. GC might have
|
|
|
|
// cleared it before the track sources.
|
|
|
|
mElement->NotifyOutputTrackStopped(mOwningStream, mDestinationTrackID);
|
|
|
|
}
|
|
|
|
mElement = nullptr;
|
|
|
|
mOwningStream = nullptr;
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not keep the track source alive. The source lifetime is controlled by
|
|
|
|
* its associated tracks.
|
|
|
|
*/
|
|
|
|
bool KeepsSourceAlive() const override { return false; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not keep the track source on. It is controlled by its associated tracks.
|
|
|
|
*/
|
|
|
|
bool Enabled() const override { return false; }
|
|
|
|
|
|
|
|
void Disable() override {}
|
|
|
|
|
|
|
|
void Enable() override {}
|
|
|
|
|
|
|
|
void PrincipalChanged() override {
|
|
|
|
if (!mCapturedTrackSource) {
|
|
|
|
// This could happen during shutdown.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrincipal = mCapturedTrackSource->GetPrincipal();
|
|
|
|
MediaStreamTrackSource::PrincipalChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutedChanged(bool aNewState) override {
|
|
|
|
if (!mCapturedTrackSource) {
|
|
|
|
// This could happen during shutdown.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamTrackSource::MutedChanged(aNewState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~StreamCaptureTrackSource() = default;
|
|
|
|
|
|
|
|
RefPtr<HTMLMediaElement> mElement;
|
|
|
|
RefPtr<MediaStreamTrackSource> mCapturedTrackSource;
|
|
|
|
RefPtr<DOMMediaStream> mOwningStream;
|
|
|
|
TrackID mDestinationTrackID;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLMediaElement::StreamCaptureTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLMediaElement::StreamCaptureTrackSource,
|
|
|
|
MediaStreamTrackSource)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
|
|
|
|
HTMLMediaElement::StreamCaptureTrackSource)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MediaStreamTrackSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLMediaElement::StreamCaptureTrackSource,
|
|
|
|
MediaStreamTrackSource, mElement,
|
|
|
|
mCapturedTrackSource, mOwningStream)
|
|
|
|
|
2009-07-10 06:03:03 +04:00
|
|
|
/**
|
|
|
|
* There is a reference cycle involving this class: MediaLoadListener
|
2013-03-19 16:23:54 +04:00
|
|
|
* holds a reference to the HTMLMediaElement, which holds a reference
|
2009-07-10 06:03:03 +04:00
|
|
|
* to an nsIChannel, which holds a reference to this listener.
|
|
|
|
* We break the reference cycle in OnStartRequest by clearing mElement.
|
|
|
|
*/
|
2017-08-29 09:28:13 +03:00
|
|
|
class HTMLMediaElement::MediaLoadListener final
|
|
|
|
: public nsIStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsIThreadRetargetableStreamListener {
|
2014-06-25 06:09:15 +04:00
|
|
|
~MediaLoadListener() {}
|
|
|
|
|
2017-09-20 12:14:01 +03:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2008-12-16 06:32:03 +03:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2009-05-14 01:52:50 +04:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2010-02-24 22:14:14 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2009-05-14 01:52:50 +04:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2017-08-29 09:28:13 +03:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
2008-12-16 06:32:03 +03:00
|
|
|
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit MediaLoadListener(HTMLMediaElement* aElement)
|
2018-05-14 12:11:18 +03:00
|
|
|
: mElement(aElement), mLoadID(aElement->GetCurrentLoadID()) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mElement, "Must pass an element to call back");
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLMediaElement> mElement;
|
2008-12-16 06:32:03 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> mNextListener;
|
2016-06-23 12:09:42 +03:00
|
|
|
const uint32_t mLoadID;
|
2008-12-16 06:32:03 +03:00
|
|
|
};
|
|
|
|
|
2017-08-29 09:28:13 +03:00
|
|
|
NS_IMPL_ISUPPORTS(HTMLMediaElement::MediaLoadListener, nsIRequestObserver,
|
|
|
|
nsIStreamListener, nsIChannelEventSink, nsIInterfaceRequestor,
|
|
|
|
nsIObserver, nsIThreadRetargetableStreamListener)
|
2010-02-24 22:14:14 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement::MediaLoadListener::Observe(nsISupports* aSubject,
|
2016-06-23 12:09:42 +03:00
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData) {
|
2010-02-24 22:14:14 +03:00
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
|
|
|
|
// Clear mElement to break cycle so we don't leak on shutdown
|
2012-07-30 18:20:58 +04:00
|
|
|
mElement = nullptr;
|
2010-02-25 01:48:32 +03:00
|
|
|
return NS_OK;
|
2010-02-24 22:14:14 +03:00
|
|
|
}
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2016-06-23 12:09:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLMediaElement::MediaLoadListener::OnStartRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext) {
|
2010-02-24 22:14:14 +03:00
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
|
2012-01-06 10:40:51 +04:00
|
|
|
if (!mElement) {
|
|
|
|
// We've been notified by the shutdown observer, and are shutting down.
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2018-07-23 17:41:26 +03:00
|
|
|
// Media element playback is not currently supported when recording or
|
|
|
|
// replaying. See bug 1304146.
|
|
|
|
if (recordreplay::IsRecordingOrReplaying()) {
|
|
|
|
mElement->ReportLoadError("Media elements not available when recording",
|
|
|
|
nullptr, 0);
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2009-07-10 06:03:03 +04:00
|
|
|
// The element is only needed until we've had a chance to call
|
|
|
|
// InitializeDecoderForChannel. So make sure mElement is cleared here.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLMediaElement> element;
|
2009-07-10 06:03:03 +04:00
|
|
|
element.swap(mElement);
|
|
|
|
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(element->AbstractMainThread());
|
|
|
|
|
2011-05-04 06:43:48 +04:00
|
|
|
if (mLoadID != element->GetCurrentLoadID()) {
|
|
|
|
// The channel has been cancelled before we had a chance to create
|
|
|
|
// a decoder. Abort, don't dispatch an "error" event, as the new load
|
|
|
|
// may not be in an error state.
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2009-03-18 03:34:48 +03:00
|
|
|
// Don't continue to load if the request failed or has been canceled.
|
|
|
|
nsresult status;
|
2011-11-16 11:50:19 +04:00
|
|
|
nsresult rv = aRequest->GetStatus(&status);
|
2009-03-18 03:34:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (NS_FAILED(status)) {
|
2015-12-17 00:24:40 +03:00
|
|
|
if (element) {
|
|
|
|
// Handle media not loading error because source was a tracking URL.
|
|
|
|
// We make a note of this media node by including it in a dedicated
|
|
|
|
// array of blocked tracking nodes under its parent document.
|
|
|
|
if (status == NS_ERROR_TRACKING_URI) {
|
|
|
|
nsIDocument* ownerDoc = element->OwnerDoc();
|
|
|
|
if (ownerDoc) {
|
|
|
|
ownerDoc->AddBlockedTrackingNode(element);
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 05:46:33 +03:00
|
|
|
element->NotifyLoadError(
|
|
|
|
nsPrintfCString("%u: %s", uint32_t(status), "Request failed"));
|
2015-12-17 00:24:40 +03:00
|
|
|
}
|
2009-03-18 03:34:48 +03:00
|
|
|
return status;
|
|
|
|
}
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2011-12-22 03:33:39 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(aRequest);
|
|
|
|
bool succeeded;
|
|
|
|
if (hc && NS_SUCCEEDED(hc->GetRequestSucceeded(&succeeded)) && !succeeded) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t responseStatus = 0;
|
2016-12-20 06:49:32 +03:00
|
|
|
Unused << hc->GetResponseStatus(&responseStatus);
|
2017-07-14 10:17:32 +03:00
|
|
|
nsAutoCString statusText;
|
|
|
|
Unused << hc->GetResponseStatusText(statusText);
|
|
|
|
element->NotifyLoadError(
|
|
|
|
nsPrintfCString("%u: %s", responseStatus, statusText.get()));
|
|
|
|
|
2011-12-22 03:33:39 +04:00
|
|
|
nsAutoString code;
|
|
|
|
code.AppendInt(responseStatus);
|
|
|
|
nsAutoString src;
|
|
|
|
element->GetCurrentSrc(src);
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* params[] = {code.get(), src.get()};
|
2011-12-22 03:33:39 +04:00
|
|
|
element->ReportLoadError("MediaLoadHttpError", params, ArrayLength(params));
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2008-12-16 06:32:03 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
|
|
|
if (channel &&
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_SUCCEEDED(rv = element->InitializeDecoderForChannel(
|
|
|
|
channel, getter_AddRefs(mNextListener))) &&
|
2008-12-16 06:32:03 +03:00
|
|
|
mNextListener) {
|
|
|
|
rv = mNextListener->OnStartRequest(aRequest, aContext);
|
|
|
|
} else {
|
2016-06-23 12:09:42 +03:00
|
|
|
// If InitializeDecoderForChannel() returned an error, fire a network error.
|
2016-06-23 12:15:50 +03:00
|
|
|
if (NS_FAILED(rv) && !mNextListener) {
|
2009-02-20 05:49:00 +03:00
|
|
|
// Load failed, attempt to load the next candidate resource. If there
|
2009-09-22 04:08:13 +04:00
|
|
|
// are none, this will trigger a MEDIA_ERR_SRC_NOT_SUPPORTED error.
|
2017-11-17 05:46:33 +03:00
|
|
|
element->NotifyLoadError(NS_LITERAL_CSTRING("Failed to init decoder"));
|
2009-02-15 19:26:32 +03:00
|
|
|
}
|
|
|
|
// If InitializeDecoderForChannel did not return a listener (but may
|
|
|
|
// have otherwise succeeded), we abort the connection since we aren't
|
|
|
|
// interested in keeping the channel alive ourselves.
|
2008-12-16 06:32:03 +03:00
|
|
|
rv = NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-06-23 12:09:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLMediaElement::MediaLoadListener::OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus) {
|
2008-12-16 06:32:03 +03:00
|
|
|
if (mNextListener) {
|
|
|
|
return mNextListener->OnStopRequest(aRequest, aContext, aStatus);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:41:02 +04:00
|
|
|
NS_IMETHODIMP
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement::MediaLoadListener::OnDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aStream,
|
|
|
|
uint64_t aOffset,
|
|
|
|
uint32_t aCount) {
|
2009-05-05 10:13:26 +04:00
|
|
|
if (!mNextListener) {
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ERROR(
|
|
|
|
"Must have a chained listener; OnStartRequest should have "
|
|
|
|
"canceled this request");
|
2009-05-05 10:13:26 +04:00
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
return mNextListener->OnDataAvailable(aRequest, aContext, aStream, aOffset,
|
|
|
|
aCount);
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
|
|
|
|
2016-06-23 12:09:42 +03:00
|
|
|
NS_IMETHODIMP
|
2018-05-14 12:11:18 +03:00
|
|
|
HTMLMediaElement::MediaLoadListener::AsyncOnChannelRedirect(
|
|
|
|
nsIChannel* aOldChannel, nsIChannel* aNewChannel, uint32_t aFlags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* cb) {
|
2010-08-05 06:15:55 +04:00
|
|
|
// TODO is this really correct?? See bug #579329.
|
2016-06-23 12:09:42 +03:00
|
|
|
if (mElement) {
|
2009-05-18 02:20:37 +04:00
|
|
|
mElement->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
|
2016-06-23 12:09:42 +03:00
|
|
|
}
|
2009-05-14 01:52:50 +04:00
|
|
|
nsCOMPtr<nsIChannelEventSink> sink = do_QueryInterface(mNextListener);
|
2016-06-23 12:09:42 +03:00
|
|
|
if (sink) {
|
2010-08-05 06:15:55 +04:00
|
|
|
return sink->AsyncOnChannelRedirect(aOldChannel, aNewChannel, aFlags, cb);
|
2016-06-23 12:09:42 +03:00
|
|
|
}
|
2010-08-05 06:15:55 +04:00
|
|
|
cb->OnRedirectVerifyCallback(NS_OK);
|
2009-05-14 01:52:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:28:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLMediaElement::MediaLoadListener::CheckListenerChain() {
|
|
|
|
MOZ_ASSERT(mNextListener);
|
|
|
|
nsCOMPtr<nsIThreadRetargetableStreamListener> retargetable =
|
|
|
|
do_QueryInterface(mNextListener);
|
|
|
|
if (retargetable) {
|
|
|
|
return retargetable->CheckListenerChain();
|
|
|
|
}
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2016-06-23 12:09:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLMediaElement::MediaLoadListener::GetInterface(const nsIID& aIID,
|
|
|
|
void** aResult) {
|
2009-05-14 01:52:50 +04:00
|
|
|
return QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ReportLoadError(const char* aMsg,
|
|
|
|
const char16_t** aParams,
|
|
|
|
uint32_t aParamCount) {
|
2016-06-23 12:09:42 +03:00
|
|
|
nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"), OwnerDoc(),
|
|
|
|
nsContentUtils::eDOM_PROPERTIES, aMsg, aParams, aParamCount);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
class HTMLMediaElement::AudioChannelAgentCallback final
|
|
|
|
: public nsIAudioChannelAgentCallback {
|
2016-11-29 07:40:32 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(AudioChannelAgentCallback)
|
|
|
|
|
2017-08-10 04:00:08 +03:00
|
|
|
explicit AudioChannelAgentCallback(HTMLMediaElement* aOwner)
|
2016-11-29 07:40:32 +03:00
|
|
|
: mOwner(aOwner),
|
|
|
|
mAudioChannelVolume(1.0),
|
|
|
|
mPlayingThroughTheAudioChannel(false),
|
|
|
|
mAudioCapturedByWindow(false),
|
|
|
|
mSuspended(nsISuspendedTypes::NONE_SUSPENDED),
|
|
|
|
mIsOwnerAudible(IsOwnerAudible()),
|
2016-12-04 06:02:10 +03:00
|
|
|
mIsShutDown(false) {
|
2016-11-29 07:40:32 +03:00
|
|
|
MOZ_ASSERT(mOwner);
|
|
|
|
MaybeCreateAudioChannelAgent();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void UpdateAudioChannelPlayingState(bool aForcePlaying = false) {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
bool playingThroughTheAudioChannel =
|
|
|
|
aForcePlaying || IsPlayingThroughTheAudioChannel();
|
|
|
|
|
|
|
|
if (playingThroughTheAudioChannel != mPlayingThroughTheAudioChannel) {
|
|
|
|
if (!MaybeCreateAudioChannelAgent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPlayingThroughTheAudioChannel = playingThroughTheAudioChannel;
|
|
|
|
NotifyAudioChannelAgent(mPlayingThroughTheAudioChannel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool ShouldResetSuspend() const {
|
2017-01-23 05:52:06 +03:00
|
|
|
// The disposable-pause should be clear after media starts playing.
|
|
|
|
if (!mOwner->Paused() &&
|
|
|
|
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the blocked media is paused, we don't need to resume it. We reset the
|
|
|
|
// mSuspended in order to unregister the agent.
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mOwner->Paused() && mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
|
2017-01-23 05:52:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void NotifyPlayStateChanged() {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2017-01-23 05:52:06 +03:00
|
|
|
if (ShouldResetSuspend()) {
|
|
|
|
SetSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
2017-05-10 18:43:11 +03:00
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
|
2017-01-23 05:52:06 +03:00
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMETHODIMP WindowVolumeChanged(float aVolume, bool aMuted) override {
|
2016-11-29 07:40:32 +03:00
|
|
|
MOZ_ASSERT(mAudioChannelAgent);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, WindowVolumeChanged, "
|
|
|
|
"this = %p, aVolume = %f, aMuted = %s\n",
|
|
|
|
this, aVolume, aMuted ? "true" : "false"));
|
2016-11-29 07:40:32 +03:00
|
|
|
|
|
|
|
if (mAudioChannelVolume != aVolume) {
|
|
|
|
mAudioChannelVolume = aVolume;
|
|
|
|
mOwner->SetVolumeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t muted = mOwner->mMuted;
|
|
|
|
if (aMuted && !mOwner->ComputedMuted()) {
|
|
|
|
mOwner->SetMutedInternal(muted | MUTED_BY_AUDIO_CHANNEL);
|
|
|
|
} else if (!aMuted && mOwner->ComputedMuted()) {
|
|
|
|
mOwner->SetMutedInternal(muted & ~MUTED_BY_AUDIO_CHANNEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMETHODIMP WindowSuspendChanged(SuspendTypes aSuspend) override {
|
2016-11-29 07:40:32 +03:00
|
|
|
MOZ_ASSERT(mAudioChannelAgent);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, WindowSuspendChanged, "
|
|
|
|
"this = %p, aSuspend = %s\n",
|
|
|
|
this, SuspendTypeToStr(aSuspend)));
|
2016-11-29 07:40:32 +03:00
|
|
|
|
|
|
|
switch (aSuspend) {
|
|
|
|
case nsISuspendedTypes::NONE_SUSPENDED:
|
|
|
|
Resume();
|
|
|
|
break;
|
|
|
|
case nsISuspendedTypes::SUSPENDED_PAUSE:
|
|
|
|
case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
|
|
|
|
case nsISuspendedTypes::SUSPENDED_BLOCK:
|
|
|
|
Suspend(aSuspend);
|
|
|
|
break;
|
|
|
|
case nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE:
|
|
|
|
Stop();
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, "
|
|
|
|
"WindowSuspendChanged, "
|
|
|
|
"this = %p, Error : unknown suspended type!\n",
|
|
|
|
this));
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMETHODIMP WindowAudioCaptureChanged(bool aCapture) override {
|
2016-11-29 07:40:32 +03:00
|
|
|
MOZ_ASSERT(mAudioChannelAgent);
|
|
|
|
|
|
|
|
if (mAudioCapturedByWindow != aCapture) {
|
|
|
|
mAudioCapturedByWindow = aCapture;
|
|
|
|
AudioCaptureStreamChangeIfNeeded();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void AudioCaptureStreamChangeIfNeeded() {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
if (!IsPlayingStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOwner->HasAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOwner->AudioCaptureStreamChange(mAudioCapturedByWindow);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void NotifyAudioPlaybackChanged(AudibleChangedReasons aReason) {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
if (!IsPlayingStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:47:13 +03:00
|
|
|
AudibleState newAudibleState = IsOwnerAudible();
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mIsOwnerAudible == newAudibleState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsOwnerAudible = newAudibleState;
|
|
|
|
mAudioChannelAgent->NotifyStartedAudible(mIsOwnerAudible, aReason);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsPlaybackBlocked() {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
// If the tab hasn't been activated yet, the media element in that tab can't
|
2018-05-14 12:11:18 +03:00
|
|
|
// be playback now until the tab goes to foreground first time or user
|
|
|
|
// clicks the unblocking tab icon.
|
2016-11-29 07:40:32 +03:00
|
|
|
if (!IsTabActivated()) {
|
|
|
|
// Even we haven't start playing yet, we still need to notify the audio
|
|
|
|
// channe system because we need to receive the resume notification later.
|
|
|
|
UpdateAudioChannelPlayingState(true /* force to start */);
|
2016-11-30 11:01:36 +03:00
|
|
|
return true;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:01:36 +03:00
|
|
|
return false;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void Shutdown() {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
mAudioChannelAgent->NotifyStoppedPlaying();
|
|
|
|
mAudioChannelAgent = nullptr;
|
|
|
|
}
|
|
|
|
mIsShutDown = true;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
float GetEffectiveVolume() const {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
return mOwner->Volume() * mAudioChannelVolume;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
SuspendTypes GetSuspendType() const {
|
2016-12-04 06:02:10 +03:00
|
|
|
MOZ_ASSERT(!mIsShutDown);
|
2016-11-29 07:40:32 +03:00
|
|
|
return mSuspended;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-14 12:11:18 +03:00
|
|
|
~AudioChannelAgentCallback() { MOZ_ASSERT(mIsShutDown); };
|
2016-11-29 07:40:32 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool MaybeCreateAudioChannelAgent() {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mAudioChannelAgent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAudioChannelAgent = new AudioChannelAgent();
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult rv =
|
|
|
|
mAudioChannelAgent->Init(mOwner->OwnerDoc()->GetInnerWindow(), this);
|
2016-11-29 07:40:32 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mAudioChannelAgent = nullptr;
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, Fail to initialize "
|
|
|
|
"the audio channel agent, this = %p\n",
|
|
|
|
this));
|
2016-11-29 07:40:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void NotifyAudioChannelAgent(bool aPlaying) {
|
2016-11-29 07:40:32 +03:00
|
|
|
MOZ_ASSERT(mAudioChannelAgent);
|
|
|
|
|
|
|
|
if (aPlaying) {
|
|
|
|
AudioPlaybackConfig config;
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult rv =
|
|
|
|
mAudioChannelAgent->NotifyStartedPlaying(&config, IsOwnerAudible());
|
2016-11-29 07:40:32 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowVolumeChanged(config.mVolume, config.mMuted);
|
|
|
|
WindowSuspendChanged(config.mSuspend);
|
|
|
|
} else {
|
|
|
|
mAudioChannelAgent->NotifyStoppedPlaying();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void SetSuspended(SuspendTypes aSuspend) {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mSuspended == aSuspend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeNotifyMediaResumed(aSuspend);
|
|
|
|
mSuspended = aSuspend;
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, "
|
|
|
|
"SetAudioChannelSuspended, "
|
|
|
|
"this = %p, aSuspend = %s\n",
|
|
|
|
this, SuspendTypeToStr(aSuspend)));
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void Resume() {
|
2016-12-01 11:30:18 +03:00
|
|
|
if (!IsSuspended()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
|
|
|
("HTMLMediaElement::AudioChannelAgentCallback, "
|
|
|
|
"ResumeFromAudioChannel, "
|
|
|
|
"this = %p, don't need to be resumed!\n",
|
|
|
|
this));
|
2016-11-29 07:40:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
2016-12-13 11:04:45 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
RefPtr<Promise> toBeIgnored = mOwner->Play(rv);
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_ASSERT_IF(
|
|
|
|
toBeIgnored && toBeIgnored->State() == Promise::PromiseState::Rejected,
|
2016-12-13 11:04:45 +03:00
|
|
|
rv.Failed());
|
|
|
|
if (rv.Failed()) {
|
|
|
|
NS_WARNING("Not able to resume from AudioChannel.");
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
2017-03-27 05:59:44 +03:00
|
|
|
|
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void Suspend(SuspendTypes aSuspend) {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (IsSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSuspended(aSuspend);
|
|
|
|
if (aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
|
|
|
aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE) {
|
2018-05-14 12:11:18 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
mOwner->Pause(rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
2017-03-27 05:59:44 +03:00
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void Stop() {
|
2016-11-29 07:40:32 +03:00
|
|
|
SetSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
|
|
|
mOwner->Pause();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsPlayingStarted() {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (MaybeCreateAudioChannelAgent()) {
|
|
|
|
return mAudioChannelAgent->IsPlayingStarted();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void MaybeNotifyMediaResumed(SuspendTypes aSuspend) {
|
2016-11-29 07:40:32 +03:00
|
|
|
// In fennec, we should send the notification when media is resumed from the
|
|
|
|
// pause-disposable which was called by media control.
|
|
|
|
if (mSuspended != nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE &&
|
|
|
|
aSuspend != nsISuspendedTypes::NONE_SUSPENDED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsPlayingStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t windowID = mAudioChannelAgent->WindowID();
|
2017-07-07 05:36:13 +03:00
|
|
|
mOwner->MainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
|
2017-06-12 22:34:10 +03:00
|
|
|
"dom::HTMLMediaElement::AudioChannelAgentCallback::"
|
|
|
|
"MaybeNotifyMediaResumed",
|
|
|
|
[windowID]() -> void {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
services::GetObserverService();
|
|
|
|
if (NS_WARN_IF(!observerService)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsISupportsPRUint64> wrapper =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
|
|
|
|
if (NS_WARN_IF(!wrapper)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
wrapper->SetData(windowID);
|
|
|
|
observerService->NotifyObservers(wrapper, "media-playback-resumed",
|
|
|
|
u"active");
|
|
|
|
}));
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsTabActivated() {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (MaybeCreateAudioChannelAgent()) {
|
|
|
|
return !mAudioChannelAgent->ShouldBlockMedia();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsSuspended() const {
|
2016-11-29 07:40:32 +03:00
|
|
|
return (mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
|
|
|
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
|
|
|
|
mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
AudibleState IsOwnerAudible() const {
|
2016-11-29 07:40:32 +03:00
|
|
|
// Muted or the volume should not be ~0
|
2017-02-23 09:15:45 +03:00
|
|
|
if (mOwner->mMuted || (std::fabs(mOwner->Volume()) <= 1e-7)) {
|
2018-05-14 12:11:18 +03:00
|
|
|
return mOwner->HasAudio()
|
|
|
|
? AudioChannelService::AudibleState::eMaybeAudible
|
|
|
|
: AudioChannelService::AudibleState::eNotAudible;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:47:13 +03:00
|
|
|
// No audio track.
|
|
|
|
if (!mOwner->HasAudio()) {
|
|
|
|
return AudioChannelService::AudibleState::eNotAudible;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:47:13 +03:00
|
|
|
// Might be audible but not yet.
|
|
|
|
if (mOwner->HasAudio() && !mOwner->mIsAudioTrackAudible) {
|
|
|
|
return AudioChannelService::AudibleState::eMaybeAudible;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 05:59:07 +03:00
|
|
|
// Suspended or paused media doesn't produce any sound.
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mSuspended != nsISuspendedTypes::NONE_SUSPENDED || mOwner->mPaused) {
|
2017-02-24 12:15:22 +03:00
|
|
|
return AudioChannelService::AudibleState::eNotAudible;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:47:13 +03:00
|
|
|
return AudioChannelService::AudibleState::eAudible;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool IsPlayingThroughTheAudioChannel() const {
|
2016-11-29 07:40:32 +03:00
|
|
|
// If we have an error, we are not playing.
|
|
|
|
if (mOwner->GetError()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-21 19:04:24 +03:00
|
|
|
// We should consider any bfcached page or inactive document as non-playing.
|
|
|
|
if (!mOwner->IsActive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-29 07:40:32 +03:00
|
|
|
// It might be resumed from remote, we should keep the audio channel agent.
|
|
|
|
if (IsSuspended()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we paused
|
|
|
|
if (mOwner->mPaused) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-09 09:10:43 +03:00
|
|
|
// No audio track
|
|
|
|
if (!mOwner->HasAudio()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-29 07:40:32 +03:00
|
|
|
// A loop always is playing
|
|
|
|
if (mOwner->HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are actually playing...
|
|
|
|
if (mOwner->IsCurrentlyPlaying()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are playing an external stream.
|
|
|
|
if (mOwner->mSrcAttrStream) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<AudioChannelAgent> mAudioChannelAgent;
|
|
|
|
HTMLMediaElement* mOwner;
|
|
|
|
|
|
|
|
// The audio channel volume
|
|
|
|
float mAudioChannelVolume;
|
|
|
|
// Is this media element playing?
|
|
|
|
bool mPlayingThroughTheAudioChannel;
|
|
|
|
// True if the sound is being captured by the window.
|
|
|
|
bool mAudioCapturedByWindow;
|
|
|
|
// 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
|
2016-11-30 09:43:41 +03:00
|
|
|
// It's used when user press the pause button on the remote media-control.
|
|
|
|
// MediaElement can be resumed by remote media-control or via play().
|
2016-11-29 07:40:32 +03:00
|
|
|
// - SUSPENDED_BLOCK
|
2016-11-30 09:43:41 +03:00
|
|
|
// It's used to reduce the power consumption, we won't play the auto-play
|
2016-11-29 07:40:32 +03:00
|
|
|
// 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
|
2016-11-30 09:43:41 +03:00
|
|
|
// When we permanently lost platform audio focus, we should stop playing
|
2016-11-29 07:40:32 +03:00
|
|
|
// and stop the audio channel agent. MediaElement can only be restarted by
|
|
|
|
// play().
|
|
|
|
SuspendTypes mSuspended;
|
2016-12-13 17:47:13 +03:00
|
|
|
// Indicate whether media element is audible for users.
|
|
|
|
AudibleState mIsOwnerAudible;
|
2016-12-04 06:02:10 +03:00
|
|
|
bool mIsShutDown;
|
2016-11-29 07:40:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLMediaElement::AudioChannelAgentCallback)
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
|
|
|
|
HTMLMediaElement::AudioChannelAgentCallback)
|
2016-11-29 07:40:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelAgent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(
|
|
|
|
HTMLMediaElement::AudioChannelAgentCallback)
|
2016-11-29 07:40:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioChannelAgent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
|
|
|
|
HTMLMediaElement::AudioChannelAgentCallback)
|
2016-11-29 07:40:32 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAudioChannelAgentCallback)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(HTMLMediaElement::AudioChannelAgentCallback)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(HTMLMediaElement::AudioChannelAgentCallback)
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
class HTMLMediaElement::ChannelLoader final {
|
2016-06-24 05:41:43 +03:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ChannelLoader);
|
|
|
|
|
2016-06-24 08:45:01 +03:00
|
|
|
void LoadInternal(HTMLMediaElement* aElement) {
|
|
|
|
if (mCancelled) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 05:41:43 +03:00
|
|
|
|
|
|
|
// determine what security checks need to be performed in AsyncOpen2().
|
2018-05-14 12:11:18 +03:00
|
|
|
nsSecurityFlags securityFlags =
|
|
|
|
aElement->ShouldCheckAllowOrigin()
|
|
|
|
? nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS
|
|
|
|
: nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
|
2016-06-24 05:41:43 +03:00
|
|
|
|
|
|
|
if (aElement->GetCORSMode() == CORS_USE_CREDENTIALS) {
|
|
|
|
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
aElement->IsAnyOfHTMLElements(nsGkAtoms::audio, nsGkAtoms::video));
|
|
|
|
nsContentPolicyType contentPolicyType =
|
|
|
|
aElement->IsHTMLElement(nsGkAtoms::audio)
|
|
|
|
? nsIContentPolicy::TYPE_INTERNAL_AUDIO
|
|
|
|
: nsIContentPolicy::TYPE_INTERNAL_VIDEO;
|
2016-06-24 05:41:43 +03:00
|
|
|
|
2017-10-11 12:07:35 +03:00
|
|
|
// If aElement has 'triggeringprincipal' attribute, we will use the value as
|
2017-10-06 00:47:09 +03:00
|
|
|
// triggeringPrincipal for the channel, otherwise it will default to use
|
2017-09-15 13:47:44 +03:00
|
|
|
// aElement->NodePrincipal().
|
2017-10-11 12:07:35 +03:00
|
|
|
// This function returns true when aElement has 'triggeringprincipal', so if
|
2017-09-15 13:47:44 +03:00
|
|
|
// setAttrs is true we will override the origin attributes on the channel
|
|
|
|
// later.
|
2017-10-06 00:47:09 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
|
2018-05-14 12:11:18 +03:00
|
|
|
bool setAttrs = nsContentUtils::QueryTriggeringPrincipal(
|
|
|
|
aElement, aElement->mLoadingSrcTriggeringPrincipal,
|
|
|
|
getter_AddRefs(triggeringPrincipal));
|
2017-09-15 13:47:44 +03:00
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = aElement->GetDocumentLoadGroup();
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult rv = NS_NewChannelWithTriggeringPrincipal(
|
|
|
|
getter_AddRefs(channel), aElement->mLoadingSrc,
|
|
|
|
static_cast<Element*>(aElement), triggeringPrincipal, securityFlags,
|
|
|
|
contentPolicyType,
|
|
|
|
nullptr, // aPerformanceStorage
|
|
|
|
loadGroup,
|
|
|
|
nullptr, // aCallbacks
|
|
|
|
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
|
|
|
|
nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE |
|
|
|
|
nsIChannel::LOAD_CLASSIFY_URI |
|
|
|
|
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
|
2016-06-24 05:41:43 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2016-06-24 08:45:01 +03:00
|
|
|
// Notify load error so the element will try next resource candidate.
|
2017-11-17 05:46:33 +03:00
|
|
|
aElement->NotifyLoadError(NS_LITERAL_CSTRING("Fail to create channel"));
|
2016-06-24 08:45:01 +03:00
|
|
|
return;
|
2016-06-24 05:41:43 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 13:47:44 +03:00
|
|
|
if (setAttrs) {
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
|
|
|
if (loadInfo) {
|
|
|
|
// The function simply returns NS_OK, so we ignore the return value.
|
2018-05-14 12:11:18 +03:00
|
|
|
Unused << loadInfo->SetOriginAttributes(
|
|
|
|
triggeringPrincipal->OriginAttributesRef());
|
2017-09-15 13:47:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 05:38:00 +03:00
|
|
|
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
|
|
|
|
if (cos) {
|
|
|
|
if (aElement->mUseUrgentStartForChannel) {
|
|
|
|
cos->AddClassFlags(nsIClassOfService::UrgentStart);
|
|
|
|
|
|
|
|
// Reset the flag to avoid loading again without initiated by user
|
|
|
|
// interaction.
|
|
|
|
aElement->mUseUrgentStartForChannel = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unconditionally disable throttling since we want the media to fluently
|
|
|
|
// play even when we switch the tab to background.
|
|
|
|
cos->AddClassFlags(nsIClassOfService::DontThrottle);
|
2017-04-10 10:23:11 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
// The listener holds a strong reference to us. This creates a
|
|
|
|
// reference cycle, once we've set mChannel, which is manually broken
|
|
|
|
// in the listener's OnStartRequest method after it is finished with
|
|
|
|
// the element. The cycle will also be broken if we get a shutdown
|
|
|
|
// notification before OnStartRequest fires. Necko guarantees that
|
|
|
|
// OnStartRequest will eventually fire if we don't shut down first.
|
|
|
|
RefPtr<MediaLoadListener> loadListener = new MediaLoadListener(aElement);
|
|
|
|
|
|
|
|
channel->SetNotificationCallbacks(loadListener);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(channel);
|
|
|
|
if (hc) {
|
|
|
|
// Use a byte range request from the start of the resource.
|
|
|
|
// This enables us to detect if the stream supports byte range
|
|
|
|
// requests, and therefore seeking, early.
|
2018-05-14 12:11:18 +03:00
|
|
|
rv = hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"),
|
|
|
|
NS_LITERAL_CSTRING("bytes=0-"), false);
|
2016-12-20 06:49:32 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2016-06-24 05:41:43 +03:00
|
|
|
aElement->SetRequestHeaders(hc);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = channel->AsyncOpen2(loadListener);
|
|
|
|
if (NS_FAILED(rv)) {
|
2016-06-24 08:45:01 +03:00
|
|
|
// Notify load error so the element will try next resource candidate.
|
2017-11-17 05:46:33 +03:00
|
|
|
aElement->NotifyLoadError(NS_LITERAL_CSTRING("Failed to open channel"));
|
2016-06-24 08:45:01 +03:00
|
|
|
return;
|
2016-06-24 05:41:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else the channel must be open and starting to download. If it encounters
|
|
|
|
// a non-catastrophic failure, it will set a new task to continue loading
|
|
|
|
// another candidate. It's safe to set it as mChannel now.
|
|
|
|
mChannel = channel;
|
|
|
|
|
|
|
|
// loadListener will be unregistered either on shutdown or when
|
|
|
|
// OnStartRequest for the channel we just opened fires.
|
|
|
|
nsContentUtils::RegisterShutdownObserver(loadListener);
|
2016-06-24 08:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Load(HTMLMediaElement* aElement) {
|
2017-07-07 05:36:13 +03:00
|
|
|
MOZ_ASSERT(aElement);
|
2016-06-24 08:45:01 +03:00
|
|
|
// Per bug 1235183 comment 8, we can't spin the event loop from stable
|
|
|
|
// state. Defer NS_NewChannel() to a new regular runnable.
|
2017-07-07 05:36:13 +03:00
|
|
|
return aElement->MainThreadEventTarget()->Dispatch(
|
|
|
|
NewRunnableMethod<HTMLMediaElement*>("ChannelLoader::LoadInternal",
|
2018-05-14 12:11:18 +03:00
|
|
|
this, &ChannelLoader::LoadInternal,
|
|
|
|
aElement));
|
2016-06-24 05:41:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() {
|
2016-06-24 08:45:01 +03:00
|
|
|
mCancelled = true;
|
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
mChannel = nullptr;
|
|
|
|
}
|
2016-06-24 05:41:43 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void Done() {
|
2016-06-24 08:45:01 +03:00
|
|
|
MOZ_ASSERT(mChannel);
|
2016-06-24 05:41:43 +03:00
|
|
|
// Decoder successfully created, the decoder now owns the MediaResource
|
|
|
|
// which owns the channel.
|
|
|
|
mChannel = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Redirect(nsIChannel* aChannel, nsIChannel* aNewChannel,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
NS_ASSERTION(aChannel == mChannel, "Channels should match!");
|
|
|
|
mChannel = aNewChannel;
|
|
|
|
|
|
|
|
// Handle forwarding of Range header so that the intial detection
|
|
|
|
// of seeking support (via result code 206) works across redirects.
|
|
|
|
nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(aChannel);
|
|
|
|
NS_ENSURE_STATE(http);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeHdr, "Range");
|
|
|
|
|
|
|
|
nsAutoCString rangeVal;
|
|
|
|
if (NS_SUCCEEDED(http->GetRequestHeader(rangeHdr, rangeVal))) {
|
|
|
|
NS_ENSURE_STATE(!rangeVal.IsEmpty());
|
|
|
|
|
|
|
|
http = do_QueryInterface(aNewChannel);
|
|
|
|
NS_ENSURE_STATE(http);
|
|
|
|
|
|
|
|
nsresult rv = http->SetRequestHeader(rangeHdr, rangeVal, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-14 12:11:18 +03:00
|
|
|
~ChannelLoader() { MOZ_ASSERT(!mChannel); }
|
2016-06-24 05:41:43 +03:00
|
|
|
// Holds a reference to the first channel we open to the media resource.
|
|
|
|
// Once the decoder is created, control over the channel passes to the
|
|
|
|
// decoder, and we null out this reference. We must store this in case
|
|
|
|
// we need to cancel the channel before control of it passes to the decoder.
|
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2016-06-24 08:45:01 +03:00
|
|
|
|
|
|
|
bool mCancelled = false;
|
2016-06-24 05:41:43 +03:00
|
|
|
};
|
|
|
|
|
2016-11-24 05:24:04 +03:00
|
|
|
class HTMLMediaElement::ErrorSink {
|
|
|
|
public:
|
|
|
|
explicit ErrorSink(HTMLMediaElement* aOwner) : mOwner(aOwner) {
|
|
|
|
MOZ_ASSERT(mOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetError(uint16_t aErrorCode, const nsACString& aErrorDetails) {
|
|
|
|
// Since we have multiple paths calling into DecodeError, e.g.
|
|
|
|
// MediaKeys::Terminated and EMEH264Decoder::Error. We should take the 1st
|
|
|
|
// one only in order not to fire multiple 'error' events.
|
|
|
|
if (mError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsValidErrorCode(aErrorCode)) {
|
|
|
|
NS_ASSERTION(false, "Undefined MediaError codes!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-25 03:03:38 +03:00
|
|
|
mError = new MediaError(mOwner, aErrorCode, aErrorDetails);
|
|
|
|
mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("error"));
|
|
|
|
if (mOwner->ReadyState() == HAVE_NOTHING &&
|
|
|
|
aErrorCode == MEDIA_ERR_ABORTED) {
|
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#media-data-processing-steps-list
|
|
|
|
// "If the media data fetching process is aborted by the user"
|
|
|
|
mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("abort"));
|
|
|
|
mOwner->ChangeNetworkState(NETWORK_EMPTY);
|
|
|
|
mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
|
|
|
|
if (mOwner->mDecoder) {
|
|
|
|
mOwner->ShutdownDecoder();
|
|
|
|
}
|
|
|
|
} else if (aErrorCode == MEDIA_ERR_SRC_NOT_SUPPORTED) {
|
2018-02-15 06:23:32 +03:00
|
|
|
mOwner->ChangeNetworkState(NETWORK_NO_SOURCE);
|
2016-11-24 05:24:04 +03:00
|
|
|
} else {
|
2018-08-25 03:03:38 +03:00
|
|
|
mOwner->ChangeNetworkState(NETWORK_IDLE);
|
2016-11-24 05:24:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetError() { mError = nullptr; }
|
2016-11-24 05:24:08 +03:00
|
|
|
|
2016-11-24 05:24:04 +03:00
|
|
|
RefPtr<MediaError> mError;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsValidErrorCode(const uint16_t& aErrorCode) const {
|
2018-05-14 12:11:18 +03:00
|
|
|
return (aErrorCode == MEDIA_ERR_DECODE || aErrorCode == MEDIA_ERR_NETWORK ||
|
2016-11-24 05:24:04 +03:00
|
|
|
aErrorCode == MEDIA_ERR_ABORTED ||
|
|
|
|
aErrorCode == MEDIA_ERR_SRC_NOT_SUPPORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Media elememt's life cycle would be longer than error sink, so we use the
|
|
|
|
// raw pointer and this class would only be referenced by media element.
|
|
|
|
HTMLMediaElement* mOwner;
|
|
|
|
};
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLMediaElement)
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLMediaElement,
|
|
|
|
nsGenericHTMLElement)
|
2013-06-21 07:15:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaSource)
|
2015-05-26 13:36:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcMediaSource)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcStream)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcAttrStream)
|
2017-07-10 20:53:48 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourcePointer)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoadBlockedDoc)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceLoadCandidate)
|
2016-11-29 07:40:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelWrapper)
|
2016-11-24 05:24:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mErrorSink->mError)
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < tmp->mOutputStreams.Length(); ++i) {
|
2017-08-24 20:02:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputStreams[i].mStream)
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
2013-04-23 03:45:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlayed);
|
2013-10-23 22:45:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextTrackManager)
|
2014-05-23 13:34:14 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioTrackList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVideoTrackList)
|
2014-06-07 00:52:15 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeys)
|
2017-11-03 09:35:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIncomingMediaKeys)
|
2016-05-10 12:02:15 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelectedVideoStreamTrack)
|
2016-12-09 03:34:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingPlayPromises)
|
2017-04-17 13:40:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSeekDOMPromise)
|
2017-11-03 15:14:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSetMediaKeysDOMPromise)
|
2009-03-08 23:59:08 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement,
|
|
|
|
nsGenericHTMLElement)
|
2017-06-23 03:03:08 +03:00
|
|
|
tmp->RemoveMutationObserver(tmp);
|
2012-08-20 08:52:59 +04:00
|
|
|
if (tmp->mSrcStream) {
|
2018-05-14 12:11:18 +03:00
|
|
|
// Need to EndMediaStreamPlayback to clear mSrcStream and make sure
|
|
|
|
// everything gets unhooked correctly.
|
2012-08-20 08:52:59 +04:00
|
|
|
tmp->EndSrcMediaStreamPlayback();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSrcAttrStream)
|
2013-06-21 07:15:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaSource)
|
2015-05-26 13:36:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSrcMediaSource)
|
2017-07-10 20:53:48 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourcePointer)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoadBlockedDoc)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceLoadCandidate)
|
2016-12-04 06:02:10 +03:00
|
|
|
if (tmp->mAudioChannelWrapper) {
|
|
|
|
tmp->mAudioChannelWrapper->Shutdown();
|
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioChannelWrapper)
|
2016-11-24 05:24:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mErrorSink->mError)
|
2018-11-23 17:59:56 +03:00
|
|
|
for (OutputMediaStream& s : tmp->mOutputStreams) {
|
2018-11-23 18:02:03 +03:00
|
|
|
s.mStream->SetFinishedOnInactive(true);
|
2018-11-23 17:59:56 +03:00
|
|
|
}
|
2017-08-24 20:02:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOutputStreams)
|
2014-06-07 00:52:15 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPlayed)
|
2013-10-23 22:45:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextTrackManager)
|
2014-05-23 13:34:14 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioTrackList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVideoTrackList)
|
2014-06-07 00:52:15 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaKeys)
|
2017-11-03 09:35:32 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIncomingMediaKeys)
|
2016-05-10 12:02:15 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelectedVideoStreamTrack)
|
2016-12-09 03:34:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingPlayPromises)
|
2017-04-17 13:40:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSeekDOMPromise)
|
2017-11-03 15:14:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSetMediaKeysDOMPromise)
|
2009-03-08 23:59:08 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLMediaElement,
|
|
|
|
nsGenericHTMLElement)
|
2014-03-20 14:45:55 +04:00
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void HTMLMediaElement::ContentRemoved(nsIContent* aChild,
|
2017-07-27 16:49:52 +03:00
|
|
|
nsIContent* aPreviousSibling) {
|
2017-07-10 20:53:48 +03:00
|
|
|
if (aChild == mSourcePointer) {
|
|
|
|
mSourcePointer = aPreviousSibling;
|
2017-06-23 03:03:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-29 05:35:55 +03:00
|
|
|
already_AddRefed<MediaSource> HTMLMediaElement::GetMozMediaSourceObject()
|
|
|
|
const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaSource> source = mMediaSource;
|
2015-01-29 05:35:55 +03:00
|
|
|
return source.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-18 07:34:48 +03:00
|
|
|
void HTMLMediaElement::GetMozDebugReaderData(nsAString& aString) {
|
|
|
|
if (mDecoder && !mSrcStream) {
|
2017-01-18 11:51:31 +03:00
|
|
|
nsAutoCString result;
|
|
|
|
mDecoder->GetMozDebugReaderData(result);
|
2018-02-15 08:22:38 +03:00
|
|
|
CopyUTF8toUTF16(result, aString);
|
2016-01-18 07:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 11:14:57 +03:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::MozRequestDebugInfo(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<Promise> promise = CreateDOMPromise(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString result;
|
|
|
|
GetMozDebugReaderData(result);
|
2017-01-24 05:49:37 +03:00
|
|
|
|
2018-01-10 07:07:47 +03:00
|
|
|
if (mVideoFrameContainer) {
|
2018-05-14 12:11:18 +03:00
|
|
|
result.AppendPrintf(
|
|
|
|
"Compositor dropped frame(including when element's invisible): %u\n",
|
|
|
|
mVideoFrameContainer->GetDroppedImageCount());
|
2018-01-10 07:07:47 +03:00
|
|
|
}
|
|
|
|
|
2017-03-01 02:56:29 +03:00
|
|
|
if (mMediaKeys) {
|
|
|
|
nsString EMEInfo;
|
|
|
|
GetEMEInfo(EMEInfo);
|
|
|
|
result.AppendLiteral("EME Info: ");
|
|
|
|
result.Append(EMEInfo);
|
|
|
|
result.AppendLiteral("\n");
|
|
|
|
}
|
|
|
|
|
2017-01-24 05:49:37 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->RequestDebugInfo()->Then(
|
2018-05-14 12:11:18 +03:00
|
|
|
mAbstractMainThread, __func__,
|
|
|
|
[promise, result](const nsACString& aString) {
|
2017-01-24 05:49:37 +03:00
|
|
|
promise->MaybeResolve(result + NS_ConvertUTF8toUTF16(aString));
|
|
|
|
},
|
2018-05-14 12:11:18 +03:00
|
|
|
[promise, result]() { promise->MaybeResolve(result); });
|
2017-01-24 05:49:37 +03:00
|
|
|
} else {
|
|
|
|
promise->MaybeResolve(result);
|
|
|
|
}
|
|
|
|
|
2017-01-18 11:14:57 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2017-10-16 08:18:58 +03:00
|
|
|
/* static */ void HTMLMediaElement::MozEnableDebugLog(const GlobalObject&) {
|
|
|
|
DecoderDoctorLogger::EnableLogging();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> HTMLMediaElement::MozRequestDebugLog(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<Promise> promise = CreateDOMPromise(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecoderDoctorLogger::RetrieveMessages(this)->Then(
|
|
|
|
mAbstractMainThread, __func__,
|
|
|
|
[promise](const nsACString& aString) {
|
|
|
|
promise->MaybeResolve(NS_ConvertUTF8toUTF16(aString));
|
|
|
|
},
|
|
|
|
[promise](nsresult rv) { promise->MaybeReject(rv); });
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-04-11 07:02:43 +03:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::MozDumpDebugInfo() {
|
2017-11-03 05:33:27 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
RefPtr<Promise> promise = CreateDOMPromise(rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-22 09:18:26 +03:00
|
|
|
if (mDecoder) {
|
2017-11-03 05:46:02 +03:00
|
|
|
mDecoder->DumpDebugInfo()->Then(mAbstractMainThread, __func__,
|
|
|
|
promise.get(),
|
|
|
|
&Promise::MaybeResolveWithUndefined);
|
|
|
|
} else {
|
|
|
|
promise->MaybeResolveWithUndefined();
|
2016-04-22 09:18:26 +03:00
|
|
|
}
|
2017-11-03 05:33:27 +03:00
|
|
|
return promise.forget();
|
2016-04-11 07:02:43 +03:00
|
|
|
}
|
|
|
|
|
2016-07-28 11:09:02 +03:00
|
|
|
void HTMLMediaElement::SetVisible(bool aVisible) {
|
2018-02-27 07:33:41 +03:00
|
|
|
mForcedHidden = !aVisible;
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->SetForcedHidden(!aVisible);
|
2016-07-28 11:09:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 23:01:46 +03:00
|
|
|
bool HTMLMediaElement::IsVideoDecodingSuspended() const {
|
|
|
|
return mDecoder && mDecoder->IsVideoDecodingSuspended();
|
|
|
|
}
|
|
|
|
|
2018-12-21 09:40:10 +03:00
|
|
|
bool HTMLMediaElement::IsVisible() const {
|
|
|
|
return mVisibilityState == Visibility::APPROXIMATELY_VISIBLE;
|
|
|
|
}
|
|
|
|
|
2017-03-08 14:41:08 +03:00
|
|
|
already_AddRefed<layers::Image> HTMLMediaElement::GetCurrentImage() {
|
2017-03-22 09:46:09 +03:00
|
|
|
MarkAsTainted();
|
2017-03-08 14:41:08 +03:00
|
|
|
|
|
|
|
// TODO: In bug 1345404, handle case when video decoder is already suspended.
|
|
|
|
ImageContainer* container = GetImageContainer();
|
|
|
|
if (!container) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLockImage lockImage(container);
|
2018-05-04 19:21:56 +03:00
|
|
|
RefPtr<layers::Image> image = lockImage.GetImage(TimeStamp::Now());
|
2017-03-16 12:07:04 +03:00
|
|
|
return image.forget();
|
2017-03-08 14:41:08 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 15:22:05 +03:00
|
|
|
bool HTMLMediaElement::HasSuspendTaint() const {
|
|
|
|
MOZ_ASSERT(!mDecoder || (mDecoder->HasSuspendTaint() == mHasSuspendTaint));
|
|
|
|
return mHasSuspendTaint;
|
|
|
|
}
|
|
|
|
|
2015-07-14 07:04:14 +03:00
|
|
|
already_AddRefed<DOMMediaStream> HTMLMediaElement::GetSrcObject() const {
|
2015-09-30 04:31:54 +03:00
|
|
|
NS_ASSERTION(!mSrcAttrStream || mSrcAttrStream->GetPlaybackStream(),
|
2015-07-14 07:04:14 +03:00
|
|
|
"MediaStream should have been set up properly");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMediaStream> stream = mSrcAttrStream;
|
2015-07-14 07:04:14 +03:00
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::SetSrcObject(DOMMediaStream& aValue) {
|
2017-10-20 06:23:07 +03:00
|
|
|
SetSrcObject(&aValue);
|
2015-07-14 07:04:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::SetSrcObject(DOMMediaStream* aValue) {
|
|
|
|
mSrcAttrStream = aValue;
|
2015-11-23 14:35:14 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2015-07-14 07:04:14 +03:00
|
|
|
DoLoad();
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
bool HTMLMediaElement::Ended() {
|
2016-09-14 11:02:23 +03:00
|
|
|
return (mDecoder && mDecoder->IsEnded()) ||
|
2018-11-23 18:00:37 +03:00
|
|
|
(mSrcStream && mSrcStreamPlaybackEnded);
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::GetCurrentSrc(nsAString& aCurrentSrc) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString src;
|
2011-08-25 03:42:23 +04:00
|
|
|
GetCurrentSpec(src);
|
2018-02-15 08:22:38 +03:00
|
|
|
CopyUTF8toUTF16(src, aCurrentSrc);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
nsresult HTMLMediaElement::OnChannelRedirect(nsIChannel* aChannel,
|
|
|
|
nsIChannel* aNewChannel,
|
2013-03-19 16:23:54 +04:00
|
|
|
uint32_t aFlags) {
|
2016-06-24 05:41:43 +03:00
|
|
|
MOZ_ASSERT(mChannelLoader);
|
|
|
|
return mChannelLoader->Redirect(aChannel, aNewChannel, aFlags);
|
2009-05-18 02:20:37 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ShutdownDecoder() {
|
2014-09-12 12:39:46 +04:00
|
|
|
RemoveMediaElementFromURITable();
|
2012-04-30 07:13:09 +04:00
|
|
|
NS_ASSERTION(mDecoder, "Must have decoder to shut down");
|
2017-11-15 07:32:50 +03:00
|
|
|
|
2016-08-21 23:51:01 +03:00
|
|
|
mWaitingForKeyListener.DisconnectIfExists();
|
2017-05-09 13:23:11 +03:00
|
|
|
if (mMediaSource) {
|
|
|
|
mMediaSource->CompletePendingTransactions();
|
|
|
|
}
|
2018-11-23 18:02:03 +03:00
|
|
|
if (!mOutputStreams.IsEmpty()) {
|
|
|
|
mNextAvailableMediaDecoderOutputTrackID =
|
|
|
|
mDecoder->GetNextOutputStreamTrackID();
|
2018-05-29 11:21:51 +03:00
|
|
|
}
|
2012-04-30 07:13:09 +04:00
|
|
|
mDecoder->Shutdown();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDUNLINKCHILD(mDecoder.get());
|
2015-05-28 05:23:27 +03:00
|
|
|
mDecoder = nullptr;
|
2018-08-15 19:35:51 +03:00
|
|
|
ReportAudioTrackSilenceProportionTelemetry();
|
2012-04-30 07:13:09 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::AbortExistingLoads() {
|
2009-03-08 23:59:08 +03:00
|
|
|
// Abort any already-running instance of the resource selection algorithm.
|
|
|
|
mLoadWaitStatus = NOT_WAITING;
|
|
|
|
|
|
|
|
// Set a new load ID. This will cause events which were enqueued
|
2009-03-16 09:05:28 +03:00
|
|
|
// with a different load ID to silently be cancelled.
|
2009-03-08 23:59:08 +03:00
|
|
|
mCurrentLoadID++;
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2016-08-18 15:03:48 +03:00
|
|
|
// Immediately reject or resolve the already-dispatched
|
|
|
|
// nsResolveOrRejectPendingPlayPromisesRunners. These runners won't be
|
|
|
|
// executed again later since the mCurrentLoadID had been changed.
|
|
|
|
for (auto& runner : mPendingPlayPromisesRunners) {
|
|
|
|
runner->ResolveOrReject();
|
|
|
|
}
|
|
|
|
mPendingPlayPromisesRunners.Clear();
|
|
|
|
|
2016-06-29 02:50:33 +03:00
|
|
|
if (mChannelLoader) {
|
|
|
|
mChannelLoader->Cancel();
|
|
|
|
mChannelLoader = nullptr;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool fireTimeUpdate = false;
|
2011-11-25 06:06:22 +04:00
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
// We need to remove VideoFrameListener before VideoTracks get emptied.
|
|
|
|
if (mVideoFrameListener) {
|
|
|
|
mSelectedVideoStreamTrack->RemoveDirectListener(mVideoFrameListener);
|
|
|
|
mVideoFrameListener->Forget();
|
|
|
|
mVideoFrameListener = nullptr;
|
2016-05-10 12:02:15 +03:00
|
|
|
}
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
// When aborting the existing loads, empty the objects in audio track list and
|
|
|
|
// video track list, no events (in particular, no removetrack events) are
|
|
|
|
// fired as part of this. Ending MediaStream sends track ended notifications,
|
|
|
|
// so we empty the track lists prior.
|
2018-11-15 15:48:34 +03:00
|
|
|
if (AudioTracks()) {
|
|
|
|
AudioTracks()->EmptyTracks();
|
|
|
|
}
|
|
|
|
if (VideoTracks()) {
|
|
|
|
VideoTracks()->EmptyTracks();
|
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2008-12-16 06:32:03 +03:00
|
|
|
if (mDecoder) {
|
2010-07-26 02:45:41 +04:00
|
|
|
fireTimeUpdate = mDecoder->GetCurrentTime() != 0.0;
|
2012-04-30 07:13:09 +04:00
|
|
|
ShutdownDecoder();
|
2008-10-30 08:20:08 +03:00
|
|
|
}
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
|
|
|
EndSrcMediaStreamPlayback();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2012-08-21 09:06:55 +04:00
|
|
|
|
2015-09-10 10:01:44 +03:00
|
|
|
RemoveMediaElementFromURITable();
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadingSrc = nullptr;
|
2017-10-06 00:47:09 +03:00
|
|
|
mLoadingSrcTriggeringPrincipal = nullptr;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Property, "loading_src", "");
|
|
|
|
DDUNLINKCHILD(mMediaSource.get());
|
2015-05-28 05:23:27 +03:00
|
|
|
mMediaSource = nullptr;
|
2008-10-30 08:20:08 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mNetworkState == NETWORK_LOADING || mNetworkState == NETWORK_IDLE) {
|
2014-02-28 06:01:47 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("abort"));
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2016-11-24 05:24:04 +03:00
|
|
|
mErrorSink->ResetError();
|
2016-01-25 05:52:54 +03:00
|
|
|
mCurrentPlayRangeStart = -1.0;
|
2014-09-24 11:25:00 +04:00
|
|
|
mLoadedDataFired = false;
|
2011-09-30 03:34:37 +04:00
|
|
|
mAutoplaying = true;
|
|
|
|
mIsLoadingFromSourceChildren = false;
|
|
|
|
mSuspendedAfterFirstFrame = false;
|
|
|
|
mAllowSuspendAfterFirstFrame = true;
|
2012-02-20 01:02:08 +04:00
|
|
|
mHaveQueuedSelectResource = false;
|
2012-05-28 02:40:06 +04:00
|
|
|
mSuspendedForPreloadNone = false;
|
|
|
|
mDownloadSuspendedByCache = false;
|
2015-02-09 09:51:17 +03:00
|
|
|
mMediaInfo = MediaInfo();
|
2015-04-01 10:36:00 +03:00
|
|
|
mIsEncrypted = false;
|
2017-01-12 06:33:55 +03:00
|
|
|
mPendingEncryptedInitData.Reset();
|
2016-10-17 04:16:54 +03:00
|
|
|
mWaitingForKey = NOT_WAITING_FOR_KEY;
|
2017-07-10 20:53:48 +03:00
|
|
|
mSourcePointer = nullptr;
|
2018-08-23 01:50:54 +03:00
|
|
|
mBlockedAsWithoutMetadata = false;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2012-07-31 04:14:29 +04:00
|
|
|
mTags = nullptr;
|
2018-08-15 19:35:51 +03:00
|
|
|
mAudioTrackSilenceStartedTime = 0.0;
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState != NETWORK_EMPTY) {
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ASSERTION(!mDecoder && !mSrcStream,
|
|
|
|
"How did someone setup a new stream/decoder already?");
|
2015-03-09 10:41:51 +03:00
|
|
|
// ChangeNetworkState() will call UpdateAudioChannelPlayingState()
|
|
|
|
// indirectly which depends on mPaused. So we need to update mPaused first.
|
2016-08-18 15:03:48 +03:00
|
|
|
if (!mPaused) {
|
|
|
|
mPaused = true;
|
2018-05-16 08:27:01 +03:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
|
2016-08-18 15:03:48 +03:00
|
|
|
RejectPromises(TakePendingPlayPromises(), NS_ERROR_DOM_MEDIA_ABORT_ERR);
|
|
|
|
}
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_EMPTY);
|
|
|
|
ChangeReadyState(HAVE_NOTHING);
|
2009-03-08 23:59:08 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
// TODO: Apply the rules for text track cue rendering Bug 865407
|
2016-06-01 08:35:53 +03:00
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->GetTextTracks()->SetCuesInactive();
|
|
|
|
}
|
|
|
|
|
2010-07-26 02:45:41 +04:00
|
|
|
if (fireTimeUpdate) {
|
|
|
|
// Since we destroyed the decoder above, the current playback position
|
|
|
|
// will now be reported as 0. The playback position was non-zero when
|
|
|
|
// we destroyed the decoder, so fire a timeupdate event so that the
|
|
|
|
// change will be reflected in the controls.
|
2011-09-30 03:34:37 +04:00
|
|
|
FireTimeUpdate(false);
|
2010-07-26 02:45:41 +04:00
|
|
|
}
|
2014-02-28 06:01:47 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
|
2015-11-23 14:35:14 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2009-03-09 00:01:03 +03:00
|
|
|
|
2018-06-22 01:14:33 +03:00
|
|
|
// Disconnect requests for permission to play. We'll make a new request
|
|
|
|
// if required should the new media resource try to play.
|
|
|
|
mAutoplayPermissionRequest.DisconnectIfExists();
|
|
|
|
|
2014-12-31 06:34:56 +03:00
|
|
|
// We may have changed mPaused, mAutoplaying, and other
|
2009-10-01 18:10:13 +04:00
|
|
|
// things which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
mIsRunningSelectResource = false;
|
2016-06-20 10:58:58 +03:00
|
|
|
|
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->NotifyReset();
|
|
|
|
}
|
2016-08-29 11:34:28 +03:00
|
|
|
|
|
|
|
mEventDeliveryPaused = false;
|
|
|
|
mPendingEvents.Clear();
|
2017-10-12 05:46:13 +03:00
|
|
|
|
|
|
|
AssertReadyStateIsNothing();
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NoSupportedMediaSourceError(
|
|
|
|
const nsACString& aErrorDetails) {
|
2016-11-01 12:33:33 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
ShutdownDecoder();
|
|
|
|
}
|
2016-11-24 05:24:04 +03:00
|
|
|
mErrorSink->SetError(MEDIA_ERR_SRC_NOT_SUPPORTED, aErrorDetails);
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2016-01-25 19:03:42 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2018-05-14 12:11:18 +03:00
|
|
|
RejectPromises(TakePendingPlayPromises(),
|
|
|
|
NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR);
|
2009-02-15 19:26:32 +03:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
typedef void (HTMLMediaElement::*SyncSectionFn)();
|
2010-09-03 04:03:03 +04:00
|
|
|
|
|
|
|
// Runs a "synchronous section", a function that must run once the event loop
|
|
|
|
// has reached a "stable state". See:
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section
|
|
|
|
class nsSyncSection : public nsMediaEvent {
|
|
|
|
private:
|
2013-06-28 05:05:03 +04:00
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
2018-05-14 12:11:18 +03:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
public:
|
2018-05-14 12:11:18 +03:00
|
|
|
nsSyncSection(HTMLMediaElement* aElement, nsIRunnable* aRunnable)
|
|
|
|
: nsMediaEvent("dom::nsSyncSection", aElement), mRunnable(aRunnable) {}
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2010-09-03 04:03:03 +04:00
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled()) return NS_OK;
|
2013-06-28 05:05:03 +04:00
|
|
|
mRunnable->Run();
|
2010-09-03 04:03:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::RunInStableState(nsIRunnable* aRunnable) {
|
2016-12-13 10:45:59 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-28 05:05:03 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsSyncSection(this, aRunnable);
|
2015-06-11 05:36:12 +03:00
|
|
|
nsContentUtils::RunInStableState(event.forget());
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::QueueLoadFromSourceTask() {
|
2016-12-13 10:45:59 +03:00
|
|
|
if (!mIsLoadingFromSourceChildren || mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-08 18:08:00 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
// Reset readyState to HAVE_NOTHING since we're going to load a new decoder.
|
|
|
|
ShutdownDecoder();
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_NOTHING);
|
2017-10-08 18:08:00 +03:00
|
|
|
}
|
|
|
|
|
2017-10-12 05:46:13 +03:00
|
|
|
AssertReadyStateIsNothing();
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(true);
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_LOADING);
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<Runnable> r =
|
|
|
|
NewRunnableMethod("HTMLMediaElement::LoadFromSourceChildren", this,
|
|
|
|
&HTMLMediaElement::LoadFromSourceChildren);
|
2016-05-05 11:45:00 +03:00
|
|
|
RunInStableState(r);
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::QueueSelectResourceTask() {
|
2010-09-03 04:03:03 +04:00
|
|
|
// Don't allow multiple async select resource calls to be queued.
|
2012-02-20 01:02:08 +04:00
|
|
|
if (mHaveQueuedSelectResource) return;
|
|
|
|
mHaveQueuedSelectResource = true;
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_NO_SOURCE);
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<Runnable> r =
|
|
|
|
NewRunnableMethod("HTMLMediaElement::SelectResourceWrapper", this,
|
|
|
|
&HTMLMediaElement::SelectResourceWrapper);
|
2016-05-05 11:45:00 +03:00
|
|
|
RunInStableState(r);
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
static bool HasSourceChildren(nsIContent* aElement) {
|
|
|
|
for (nsIContent* child = aElement->GetFirstChild(); child;
|
2016-07-12 07:25:33 +03:00
|
|
|
child = child->GetNextSibling()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::source)) {
|
2016-07-12 07:25:33 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-15 06:39:44 +03:00
|
|
|
static nsCString DocumentOrigin(nsIDocument* aDoc) {
|
|
|
|
if (!aDoc) {
|
|
|
|
return NS_LITERAL_CSTRING("null");
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = aDoc->NodePrincipal();
|
|
|
|
if (!principal) {
|
|
|
|
return NS_LITERAL_CSTRING("null");
|
|
|
|
}
|
|
|
|
nsCString origin;
|
|
|
|
if (NS_FAILED(principal->GetOrigin(origin))) {
|
|
|
|
return NS_LITERAL_CSTRING("null");
|
|
|
|
}
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
void HTMLMediaElement::Load() {
|
2016-07-12 07:25:33 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Load() hasSrcAttrStream=%d hasSrcAttr=%d hasSourceChildren=%d "
|
2018-02-15 06:39:44 +03:00
|
|
|
"handlingInput=%d hasAutoplayAttr=%d IsAllowedToPlay=%d "
|
|
|
|
"ownerDoc=%p (%s) ownerDocUserActivated=%d "
|
|
|
|
"muted=%d volume=%f",
|
|
|
|
this, !!mSrcAttrStream, HasAttr(kNameSpaceID_None, nsGkAtoms::src),
|
|
|
|
HasSourceChildren(this), EventStateManager::IsHandlingUserInput(),
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay),
|
2018-07-23 18:43:08 +03:00
|
|
|
AutoplayPolicy::IsAllowedToPlay(*this), OwnerDoc(),
|
2018-02-15 06:39:44 +03:00
|
|
|
DocumentOrigin(OwnerDoc()).get(),
|
Bug 1470346 - Gesture activate all documents in tab, even across origins, upon user interaction. r=smaug
Sometimes when video is playing, a preroll ad plays, and that may be in a cross
origin iframe. If autoplay media is disabled, we require a user gesture in a
document before playback in that document is permitted, and we require each
origin to be gesture activated separately. So in the cross origin preroll video
add case, then the user will have to click once to unblock playback for the
cross origin ad, and then once the preroll ad finishes, the user will have to
click again to activate playback of the same origin content video.
This is a bad user experience.
So we should instead make gesture activation propagate up the doc tree
irrespective of crossing origins. This way, when the user clicks to activate,
all documents in that tab are also also effectively gesture activated, and so
can autoplay.
MozReview-Commit-ID: 1HZQ5zkubR
--HG--
extra : rebase_source : d6b75732548cb1d73b9f82dce60a5e6e97d1da14
2018-06-22 02:52:20 +03:00
|
|
|
OwnerDoc() ? OwnerDoc()->HasBeenUserGestureActivated() : 0, mMuted,
|
2018-02-15 06:39:44 +03:00
|
|
|
mVolume));
|
2016-07-12 07:25:33 +03:00
|
|
|
|
2015-06-17 03:02:51 +03:00
|
|
|
if (mIsRunningLoadMethod) {
|
2018-02-15 08:22:38 +03:00
|
|
|
return;
|
2015-06-17 03:02:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mIsDoingExplicitLoad = true;
|
|
|
|
DoLoad();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DoLoad() {
|
2017-11-21 09:02:13 +03:00
|
|
|
// Check if media is allowed for the docshell.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = OwnerDoc()->GetDocShell();
|
|
|
|
if (docShell && !docShell->GetAllowMedia()) {
|
|
|
|
LOG(LogLevel::Debug, ("%p Media not allowed", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-17 03:02:51 +03:00
|
|
|
if (mIsRunningLoadMethod) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2016-11-18 05:30:00 +03:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2017-11-29 13:59:56 +03:00
|
|
|
// Detect if user has interacted with element so that play will not be
|
|
|
|
// blocked when initiated by a script. This enables sites to capture user
|
|
|
|
// intent to play by calling load() in the click handler of a "catalog
|
|
|
|
// view" of a gallery of videos.
|
|
|
|
mIsBlessed = true;
|
2017-04-28 10:27:10 +03:00
|
|
|
// Mark the channel as urgent-start when autopaly so that it will play the
|
|
|
|
// media from src after loading enough resource.
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
|
|
|
|
mUseUrgentStartForChannel = true;
|
|
|
|
}
|
2016-07-12 07:25:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
SetPlayedOrSeeked(false);
|
|
|
|
mIsRunningLoadMethod = true;
|
2009-03-08 23:59:08 +03:00
|
|
|
AbortExistingLoads();
|
2018-02-15 08:22:38 +03:00
|
|
|
SetPlaybackRate(mDefaultPlaybackRate, IgnoreErrors());
|
2009-03-08 23:59:08 +03:00
|
|
|
QueueSelectResourceTask();
|
2012-12-27 19:21:30 +04:00
|
|
|
ResetState();
|
2011-09-30 03:34:37 +04:00
|
|
|
mIsRunningLoadMethod = false;
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ResetState() {
|
2014-03-27 03:27:01 +04:00
|
|
|
// There might be a pending MediaDecoder::PlaybackPositionChanged() which
|
2015-04-14 08:15:46 +03:00
|
|
|
// will overwrite |mMediaInfo.mVideo.mDisplay| in UpdateMediaSize() to give
|
|
|
|
// staled videoWidth and videoHeight. We have to call ForgetElement() here
|
|
|
|
// such that the staled callbacks won't reach us.
|
2014-03-27 03:27:01 +04:00
|
|
|
if (mVideoFrameContainer) {
|
|
|
|
mVideoFrameContainer->ForgetElement();
|
|
|
|
mVideoFrameContainer = nullptr;
|
2012-12-27 19:21:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SelectResourceWrapper() {
|
2012-02-20 01:02:08 +04:00
|
|
|
SelectResource();
|
|
|
|
mIsRunningSelectResource = false;
|
|
|
|
mHaveQueuedSelectResource = false;
|
2015-06-17 03:02:51 +03:00
|
|
|
mIsDoingExplicitLoad = false;
|
2012-02-20 01:02:08 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SelectResource() {
|
2014-09-12 12:39:46 +04:00
|
|
|
if (!mSrcAttrStream && !HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
|
|
|
|
!HasSourceChildren(this)) {
|
2010-09-03 04:03:03 +04:00
|
|
|
// The media element has neither a src attribute nor any source
|
|
|
|
// element children, abort the load.
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_EMPTY);
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-03-08 23:59:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(true);
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_LOADING);
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
|
2009-02-15 19:26:32 +03:00
|
|
|
|
2012-02-20 01:02:08 +04:00
|
|
|
// Delay setting mIsRunningSeletResource until after UpdatePreloadAction
|
|
|
|
// so that we don't lose our state change by bailing out of the preload
|
|
|
|
// state update
|
|
|
|
UpdatePreloadAction();
|
|
|
|
mIsRunningSelectResource = true;
|
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
// If we have a 'src' attribute, use that exclusively.
|
2011-11-16 11:50:19 +04:00
|
|
|
nsAutoString src;
|
2012-04-30 07:12:28 +04:00
|
|
|
if (mSrcAttrStream) {
|
2012-09-25 07:25:43 +04:00
|
|
|
SetupSrcMediaStreamPlayback(mSrcAttrStream);
|
2012-04-30 07:12:28 +04:00
|
|
|
} else if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
2011-11-16 11:50:19 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-11-17 05:32:41 +03:00
|
|
|
MediaResult rv = NewURIFromString(src, getter_AddRefs(uri));
|
2009-03-08 23:59:08 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p Trying load from src=%s", this,
|
|
|
|
NS_ConvertUTF16toUTF8(src).get()));
|
|
|
|
NS_ASSERTION(
|
|
|
|
!mIsLoadingFromSourceChildren,
|
2010-10-16 23:57:50 +04:00
|
|
|
"Should think we're not loading from source children by default");
|
2012-09-25 07:25:43 +04:00
|
|
|
|
2015-09-10 10:01:44 +03:00
|
|
|
RemoveMediaElementFromURITable();
|
2010-09-03 04:03:03 +04:00
|
|
|
mLoadingSrc = uri;
|
2017-10-06 00:47:09 +03:00
|
|
|
mLoadingSrcTriggeringPrincipal = mSrcAttrTriggeringPrincipal;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Property, "loading_src",
|
|
|
|
nsCString(NS_ConvertUTF16toUTF8(src)));
|
2015-05-28 05:38:34 +03:00
|
|
|
mMediaSource = mSrcMediaSource;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLINKCHILD("mediasource", mMediaSource.get());
|
2015-02-15 20:38:00 +03:00
|
|
|
UpdatePreloadAction();
|
2018-04-24 17:19:51 +03:00
|
|
|
if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE && !mMediaSource) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// preload:none media, suspend the load here before we make any
|
|
|
|
// network requests.
|
2011-11-25 06:06:22 +04:00
|
|
|
SuspendLoad();
|
2010-08-20 02:50:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
rv = LoadResource();
|
2010-09-03 04:03:03 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2009-03-08 23:59:08 +03:00
|
|
|
return;
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
2011-12-22 03:33:39 +04:00
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* params[] = {src.get()};
|
2011-12-22 03:33:39 +04:00
|
|
|
ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
|
2017-11-17 05:32:41 +03:00
|
|
|
rv = MediaResult(rv.Code(), "MediaLoadInvalidURI");
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
2016-11-18 06:04:36 +03:00
|
|
|
// The media element has neither a src attribute nor a source element child:
|
|
|
|
// set the networkState to NETWORK_EMPTY, and abort these steps; the
|
|
|
|
// synchronous section ends.
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(NewRunnableMethod<nsCString>(
|
|
|
|
"HTMLMediaElement::NoSupportedMediaSourceError", this,
|
2017-11-17 05:32:41 +03:00
|
|
|
&HTMLMediaElement::NoSupportedMediaSourceError, rv.Description()));
|
2009-03-08 23:59:08 +03:00
|
|
|
} else {
|
|
|
|
// Otherwise, the source elements will be used.
|
2011-09-30 03:34:37 +04:00
|
|
|
mIsLoadingFromSourceChildren = true;
|
2009-03-08 23:59:08 +03:00
|
|
|
LoadFromSourceChildren();
|
|
|
|
}
|
2009-02-20 05:49:00 +03:00
|
|
|
}
|
2009-01-27 05:32:33 +03:00
|
|
|
|
2017-07-14 10:17:32 +03:00
|
|
|
void HTMLMediaElement::NotifyLoadError(const nsACString& aErrorDetails) {
|
2010-10-16 23:57:50 +04:00
|
|
|
if (!mIsLoadingFromSourceChildren) {
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Debug, ("NotifyLoadError(), no supported media error"));
|
2017-07-14 10:17:32 +03:00
|
|
|
NoSupportedMediaSourceError(aErrorDetails);
|
2011-04-28 18:08:03 +04:00
|
|
|
} else if (mSourceLoadCandidate) {
|
2010-09-03 04:03:03 +04:00
|
|
|
DispatchAsyncSourceError(mSourceLoadCandidate);
|
2009-03-08 23:59:08 +03:00
|
|
|
QueueLoadFromSourceTask();
|
2011-04-28 18:08:03 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Should know the source we were loading from!");
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyMediaTrackEnabled(MediaTrack* aTrack) {
|
2016-08-24 11:58:04 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
2014-05-23 13:34:14 +04:00
|
|
|
if (!aTrack) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-16 21:11:00 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsString id;
|
|
|
|
aTrack->GetId(id);
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p %sTrack with id %s enabled", this,
|
|
|
|
aTrack->AsAudioTrack() ? "Audio" : "Video",
|
|
|
|
NS_ConvertUTF16toUTF8(id).get()));
|
2015-11-16 21:11:00 +03:00
|
|
|
#endif
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-08-24 11:58:04 +03:00
|
|
|
MOZ_ASSERT((aTrack->AsAudioTrack() && aTrack->AsAudioTrack()->Enabled()) ||
|
|
|
|
(aTrack->AsVideoTrack() && aTrack->AsVideoTrack()->Selected()));
|
|
|
|
|
|
|
|
if (aTrack->AsAudioTrack()) {
|
|
|
|
SetMutedInternal(mMuted & ~MUTED_BY_AUDIO_TRACK);
|
|
|
|
} else if (aTrack->AsVideoTrack()) {
|
2016-08-23 18:51:50 +03:00
|
|
|
if (!IsVideo()) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-24 11:58:04 +03:00
|
|
|
mDisableVideo = false;
|
2016-08-23 18:51:50 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "Unknown track type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSrcStream) {
|
|
|
|
if (aTrack->AsVideoTrack()) {
|
|
|
|
MOZ_ASSERT(!mSelectedVideoStreamTrack);
|
2018-11-23 18:00:43 +03:00
|
|
|
MOZ_ASSERT(!mVideoFrameListener);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
mSelectedVideoStreamTrack = aTrack->AsVideoTrack()->GetVideoStreamTrack();
|
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
|
|
|
if (mSrcStreamIsPlaying && container) {
|
|
|
|
mSelectedVideoStreamTrack->AddVideoOutput(container);
|
|
|
|
}
|
|
|
|
HTMLVideoElement* self = static_cast<HTMLVideoElement*>(this);
|
|
|
|
if (self->VideoWidth() <= 1 && self->VideoHeight() <= 1) {
|
|
|
|
// MediaInfo uses dummy values of 1 for width and height to
|
|
|
|
// mark video as valid. We need a new stream size listener
|
|
|
|
// if size is 0x0 or 1x1.
|
2018-11-23 18:00:43 +03:00
|
|
|
mVideoFrameListener = new VideoFrameListener(this);
|
|
|
|
mSelectedVideoStreamTrack->AddDirectListener(mVideoFrameListener);
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
|
|
|
// No MediaStreamTracks are captured until we have metadata.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
if (aTrack->AsVideoTrack() && ms.mCapturingAudioOnly) {
|
|
|
|
// If the output stream is for audio only we ignore video tracks.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AddCaptureMediaTrackToOutputStream(aTrack, ms);
|
|
|
|
}
|
2016-08-24 11:58:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyMediaTrackDisabled(MediaTrack* aTrack) {
|
2016-08-24 11:58:04 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
if (!aTrack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsString id;
|
|
|
|
aTrack->GetId(id);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p %sTrack with id %s disabled", this,
|
|
|
|
aTrack->AsAudioTrack() ? "Audio" : "Video",
|
|
|
|
NS_ConvertUTF16toUTF8(id).get()));
|
2016-08-24 11:58:04 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
MOZ_ASSERT((!aTrack->AsAudioTrack() || !aTrack->AsAudioTrack()->Enabled()) &&
|
|
|
|
(!aTrack->AsVideoTrack() || !aTrack->AsVideoTrack()->Selected()));
|
|
|
|
|
|
|
|
if (aTrack->AsAudioTrack()) {
|
2017-02-23 09:16:44 +03:00
|
|
|
// If we don't have any alive track , we don't need to mute MediaElement.
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(AudioTracks(), "Element can't have been unlinked");
|
2017-02-23 09:16:44 +03:00
|
|
|
if (AudioTracks()->Length() > 0) {
|
|
|
|
bool shouldMute = true;
|
|
|
|
for (uint32_t i = 0; i < AudioTracks()->Length(); ++i) {
|
|
|
|
if ((*AudioTracks())[i]->Enabled()) {
|
|
|
|
shouldMute = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldMute) {
|
|
|
|
SetMutedInternal(mMuted | MUTED_BY_AUDIO_TRACK);
|
2016-08-24 11:58:04 +03:00
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
2016-08-24 11:58:04 +03:00
|
|
|
} else if (aTrack->AsVideoTrack()) {
|
2016-08-23 18:51:50 +03:00
|
|
|
if (mSrcStream) {
|
|
|
|
MOZ_ASSERT(mSelectedVideoStreamTrack);
|
2018-11-23 18:00:43 +03:00
|
|
|
if (mSelectedVideoStreamTrack && mVideoFrameListener) {
|
2018-05-14 12:11:18 +03:00
|
|
|
mSelectedVideoStreamTrack->RemoveDirectListener(mVideoFrameListener);
|
2018-11-23 18:00:43 +03:00
|
|
|
mVideoFrameListener->Forget();
|
|
|
|
mVideoFrameListener = nullptr;
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
|
|
|
if (mSrcStreamIsPlaying && container) {
|
|
|
|
mSelectedVideoStreamTrack->RemoveVideoOutput(container);
|
|
|
|
}
|
|
|
|
mSelectedVideoStreamTrack = nullptr;
|
2016-08-24 11:58:04 +03:00
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
|
2017-01-09 18:36:00 +03:00
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
|
|
|
// No MediaStreamTracks are captured until we have metadata, and code
|
|
|
|
// below doesn't do anything for captured decoders.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
if (ms.mCapturingDecoder) {
|
|
|
|
MOZ_ASSERT(!ms.mCapturingMediaStream);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(ms.mCapturingMediaStream);
|
|
|
|
for (int32_t i = ms.mTrackPorts.Length() - 1; i >= 0; --i) {
|
|
|
|
if (ms.mTrackPorts[i].first() == aTrack->GetId()) {
|
|
|
|
// The source of this track just ended. Force-notify that it ended.
|
|
|
|
// If we bounce it to the MediaStreamGraph it might not be picked up,
|
|
|
|
// for instance if the MediaInputPort was destroyed in the same
|
|
|
|
// iteration as it was added.
|
|
|
|
MediaStreamTrack* outputTrack = ms.mStream->FindOwnedDOMTrack(
|
2018-05-14 12:11:18 +03:00
|
|
|
ms.mTrackPorts[i].second()->GetDestination(),
|
|
|
|
ms.mTrackPorts[i].second()->GetDestinationTrackId());
|
2016-08-23 18:51:50 +03:00
|
|
|
MOZ_ASSERT(outputTrack);
|
|
|
|
if (outputTrack) {
|
2018-05-14 12:11:18 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(
|
|
|
|
NewRunnableMethod("MediaStreamTrack::OverrideEnded", outputTrack,
|
|
|
|
&MediaStreamTrack::OverrideEnded));
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ms.mTrackPorts[i].second()->Destroy();
|
|
|
|
ms.mTrackPorts.RemoveElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (auto pair : ms.mTrackPorts) {
|
|
|
|
MOZ_ASSERT(pair.first() != aTrack->GetId(),
|
2018-05-14 12:11:18 +03:00
|
|
|
"The same MediaTrack was forwarded to the output stream more "
|
|
|
|
"than once. This shouldn't happen.");
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement) {
|
2016-12-13 10:45:59 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchAsyncSourceError(aSourceElement);
|
2018-05-14 12:11:18 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(
|
|
|
|
NewRunnableMethod("HTMLMediaElement::QueueLoadFromSourceTask", this,
|
|
|
|
&HTMLMediaElement::QueueLoadFromSourceTask));
|
2016-12-13 10:45:59 +03:00
|
|
|
}
|
|
|
|
|
2016-09-23 17:53:10 +03:00
|
|
|
void HTMLMediaElement::NotifyOutputTrackStopped(DOMMediaStream* aOwningStream,
|
|
|
|
TrackID aDestinationTrackID) {
|
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
if (!ms.mCapturingMediaStream) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms.mStream != aOwningStream) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = ms.mTrackPorts.Length() - 1; i >= 0; --i) {
|
|
|
|
MediaInputPort* port = ms.mTrackPorts[i].second();
|
|
|
|
if (port->GetDestinationTrackId() != aDestinationTrackID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
port->Destroy();
|
|
|
|
ms.mTrackPorts.RemoveElementAt(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// An output track ended but its port is already gone.
|
|
|
|
// It was probably cleared by the removal of the source MediaTrack.
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::LoadFromSourceChildren() {
|
2009-10-01 18:10:13 +04:00
|
|
|
NS_ASSERTION(mDelayingLoadEvent,
|
|
|
|
"Should delay load event (if in document) during load");
|
2010-10-16 23:57:50 +04:00
|
|
|
NS_ASSERTION(mIsLoadingFromSourceChildren,
|
2010-09-03 04:03:03 +04:00
|
|
|
"Must remember we're loading from source children");
|
2012-05-15 16:56:51 +04:00
|
|
|
|
2017-06-23 03:03:08 +03:00
|
|
|
AddMutationObserverUnlessExists(this);
|
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
while (true) {
|
2017-12-07 21:13:50 +03:00
|
|
|
Element* child = GetNextSource();
|
2010-09-03 04:03:03 +04:00
|
|
|
if (!child) {
|
2009-03-08 23:59:08 +03:00
|
|
|
// Exhausted candidates, wait for more candidates to be appended to
|
|
|
|
// the media element.
|
|
|
|
mLoadWaitStatus = WAITING_FOR_SOURCE;
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_NO_SOURCE);
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2011-12-22 03:33:39 +04:00
|
|
|
ReportLoadError("MediaLoadExhaustedCandidates");
|
2009-03-08 23:59:08 +03:00
|
|
|
return;
|
2009-02-15 19:26:32 +03:00
|
|
|
}
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
// Must have src attribute.
|
2011-11-16 11:50:19 +04:00
|
|
|
nsAutoString src;
|
2010-09-03 04:03:03 +04:00
|
|
|
if (!child->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
2011-12-22 03:33:39 +04:00
|
|
|
ReportLoadError("MediaLoadSourceMissingSrc");
|
2016-12-13 10:45:59 +03:00
|
|
|
DealWithFailedElement(child);
|
|
|
|
return;
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a type attribute, it must be a supported type.
|
2011-11-16 11:50:19 +04:00
|
|
|
nsAutoString type;
|
2016-04-19 10:36:19 +03:00
|
|
|
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type)) {
|
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
|
|
|
CanPlayStatus canPlay = GetCanPlay(type, &diagnostics);
|
2016-04-22 06:42:11 +03:00
|
|
|
diagnostics.StoreFormatDiagnostics(OwnerDoc(), type,
|
|
|
|
canPlay != CANPLAY_NO, __func__);
|
2016-04-19 10:36:19 +03:00
|
|
|
if (canPlay == CANPLAY_NO) {
|
|
|
|
const char16_t* params[] = {type.get(), src.get()};
|
2018-05-14 12:11:18 +03:00
|
|
|
ReportLoadError("MediaLoadUnsupportedTypeAttribute", params,
|
|
|
|
ArrayLength(params));
|
2016-12-13 10:45:59 +03:00
|
|
|
DealWithFailedElement(child);
|
|
|
|
return;
|
2016-04-19 10:36:19 +03:00
|
|
|
}
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
HTMLSourceElement* childSrc = HTMLSourceElement::FromNode(child);
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Trying load from <source>=%s type=%s", this,
|
|
|
|
NS_ConvertUTF16toUTF8(src).get(), NS_ConvertUTF16toUTF8(type).get()));
|
2011-11-16 11:50:19 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2010-09-03 04:03:03 +04:00
|
|
|
NewURIFromString(src, getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* params[] = {src.get()};
|
2011-12-22 03:33:39 +04:00
|
|
|
ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
|
2016-12-13 10:45:59 +03:00
|
|
|
DealWithFailedElement(child);
|
|
|
|
return;
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2015-09-10 10:01:44 +03:00
|
|
|
RemoveMediaElementFromURITable();
|
2010-09-03 04:03:03 +04:00
|
|
|
mLoadingSrc = uri;
|
2017-10-06 01:28:22 +03:00
|
|
|
mLoadingSrcTriggeringPrincipal = childSrc->GetSrcTriggeringPrincipal();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Property, "loading_src",
|
|
|
|
nsCString(NS_ConvertUTF16toUTF8(src)));
|
2015-05-28 05:38:34 +03:00
|
|
|
mMediaSource = childSrc->GetSrcMediaSource();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLINKCHILD("mediasource", mMediaSource.get());
|
2018-02-15 06:23:32 +03:00
|
|
|
NS_ASSERTION(mNetworkState == NETWORK_LOADING,
|
2010-09-03 04:03:03 +04:00
|
|
|
"Network state should be loading");
|
2009-11-06 10:32:52 +03:00
|
|
|
|
2018-04-24 17:19:51 +03:00
|
|
|
if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE && !mMediaSource) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// preload:none media, suspend the load here before we make any
|
|
|
|
// network requests.
|
2011-11-25 06:06:22 +04:00
|
|
|
SuspendLoad();
|
2010-08-20 02:50:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
if (NS_SUCCEEDED(LoadResource())) {
|
2009-03-08 23:59:08 +03:00
|
|
|
return;
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2009-03-08 23:59:08 +03:00
|
|
|
// If we fail to load, loop back and try loading the next resource.
|
2010-09-03 04:03:03 +04:00
|
|
|
DispatchAsyncSourceError(child);
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Execution should not reach here!");
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SuspendLoad() {
|
2012-05-28 02:40:06 +04:00
|
|
|
mSuspendedForPreloadNone = true;
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_IDLE);
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2010-08-20 02:50:37 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ResumeLoad(PreloadAction aAction) {
|
2012-05-28 02:40:06 +04:00
|
|
|
NS_ASSERTION(mSuspendedForPreloadNone,
|
2018-05-14 12:11:18 +03:00
|
|
|
"Must be halted for preload:none to resume from preload:none "
|
|
|
|
"suspended load.");
|
2012-05-28 02:40:06 +04:00
|
|
|
mSuspendedForPreloadNone = false;
|
2010-08-20 02:50:37 +04:00
|
|
|
mPreloadAction = aAction;
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(true);
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_LOADING);
|
2010-10-16 23:57:50 +04:00
|
|
|
if (!mIsLoadingFromSourceChildren) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// We were loading from the element's src attribute.
|
2017-11-17 06:07:30 +03:00
|
|
|
MediaResult rv = LoadResource();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NoSupportedMediaSourceError(rv.Description());
|
2010-08-20 02:50:37 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We were loading from a child <source> element. Try to resume the
|
|
|
|
// load of that child, and if that fails, try the next child.
|
2011-11-25 06:06:22 +04:00
|
|
|
if (NS_FAILED(LoadResource())) {
|
2010-08-20 02:50:37 +04:00
|
|
|
LoadFromSourceChildren();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 05:25:17 +03:00
|
|
|
bool HTMLMediaElement::AllowedToPlay() const {
|
2018-07-23 18:43:08 +03:00
|
|
|
return AutoplayPolicy::IsAllowedToPlay(*this);
|
2018-07-25 05:25:17 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UpdatePreloadAction() {
|
2010-08-20 02:50:37 +04:00
|
|
|
PreloadAction nextAction = PRELOAD_UNDEFINED;
|
2010-10-16 22:41:53 +04:00
|
|
|
// If autoplay is set, or we're playing, we should always preload data,
|
|
|
|
// as we'll need it to play.
|
2018-07-23 18:43:08 +03:00
|
|
|
if ((AutoplayPolicy::IsAllowedToPlay(*this) &&
|
2017-11-30 05:50:21 +03:00
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) ||
|
2018-05-14 12:11:18 +03:00
|
|
|
!mPaused) {
|
2013-03-19 16:23:54 +04:00
|
|
|
nextAction = HTMLMediaElement::PRELOAD_ENOUGH;
|
2010-08-20 02:50:37 +04:00
|
|
|
} else {
|
|
|
|
// Find the appropriate preload action by looking at the attribute.
|
2018-05-14 12:11:18 +03:00
|
|
|
const nsAttrValue* val =
|
2018-08-07 22:07:26 +03:00
|
|
|
mAttrs.GetAttr(nsGkAtoms::preload, kNameSpaceID_None);
|
2015-02-15 20:38:00 +03:00
|
|
|
// MSE doesn't work if preload is none, so it ignores the pref when src is
|
|
|
|
// from MSE.
|
2018-05-14 12:11:18 +03:00
|
|
|
uint32_t preloadDefault =
|
|
|
|
mMediaSource
|
|
|
|
? HTMLMediaElement::PRELOAD_ATTR_METADATA
|
|
|
|
: Preferences::GetInt("media.preload.default",
|
|
|
|
HTMLMediaElement::PRELOAD_ATTR_METADATA);
|
|
|
|
uint32_t preloadAuto = Preferences::GetInt(
|
|
|
|
"media.preload.auto", HTMLMediaElement::PRELOAD_ENOUGH);
|
2010-08-20 02:50:37 +04:00
|
|
|
if (!val) {
|
2012-11-16 07:25:26 +04:00
|
|
|
// Attribute is not set. Use the preload action specified by the
|
2011-02-16 03:54:47 +03:00
|
|
|
// media.preload.default pref, or just preload metadata if not present.
|
|
|
|
nextAction = static_cast<PreloadAction>(preloadDefault);
|
2010-08-20 02:50:37 +04:00
|
|
|
} else if (val->Type() == nsAttrValue::eEnum) {
|
2018-05-14 12:11:18 +03:00
|
|
|
PreloadAttrValue attr =
|
|
|
|
static_cast<PreloadAttrValue>(val->GetEnumValue());
|
2013-03-19 16:23:54 +04:00
|
|
|
if (attr == HTMLMediaElement::PRELOAD_ATTR_EMPTY ||
|
2018-05-14 12:11:18 +03:00
|
|
|
attr == HTMLMediaElement::PRELOAD_ATTR_AUTO) {
|
2011-02-16 03:54:47 +03:00
|
|
|
nextAction = static_cast<PreloadAction>(preloadAuto);
|
2013-03-19 16:23:54 +04:00
|
|
|
} else if (attr == HTMLMediaElement::PRELOAD_ATTR_METADATA) {
|
|
|
|
nextAction = HTMLMediaElement::PRELOAD_METADATA;
|
|
|
|
} else if (attr == HTMLMediaElement::PRELOAD_ATTR_NONE) {
|
|
|
|
nextAction = HTMLMediaElement::PRELOAD_NONE;
|
2010-08-20 02:50:37 +04:00
|
|
|
}
|
|
|
|
} else {
|
2011-02-16 03:54:47 +03:00
|
|
|
// Use the suggested "missing value default" of "metadata", or the value
|
|
|
|
// specified by the media.preload.default, if present.
|
|
|
|
nextAction = static_cast<PreloadAction>(preloadDefault);
|
2010-08-20 02:50:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 03:02:51 +03:00
|
|
|
if (nextAction == HTMLMediaElement::PRELOAD_NONE && mIsDoingExplicitLoad) {
|
|
|
|
nextAction = HTMLMediaElement::PRELOAD_METADATA;
|
|
|
|
}
|
|
|
|
|
2010-08-20 02:50:37 +04:00
|
|
|
mPreloadAction = nextAction;
|
2015-06-17 03:02:51 +03:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
if (nextAction == HTMLMediaElement::PRELOAD_ENOUGH) {
|
2012-05-28 02:40:06 +04:00
|
|
|
if (mSuspendedForPreloadNone) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// Our load was previouly suspended due to the media having preload
|
|
|
|
// value "none". The preload value has changed to preload:auto, so
|
|
|
|
// resume the load.
|
|
|
|
ResumeLoad(PRELOAD_ENOUGH);
|
|
|
|
} else {
|
|
|
|
// Preload as much of the video as we can, i.e. don't suspend after
|
|
|
|
// the first frame.
|
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
} else if (nextAction == HTMLMediaElement::PRELOAD_METADATA) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// Ensure that the video can be suspended after first frame.
|
2011-09-30 03:34:37 +04:00
|
|
|
mAllowSuspendAfterFirstFrame = true;
|
2012-05-28 02:40:06 +04:00
|
|
|
if (mSuspendedForPreloadNone) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// Our load was previouly suspended due to the media having preload
|
|
|
|
// value "none". The preload value has changed to preload:metadata, so
|
|
|
|
// resume the load. We'll pause the load again after we've read the
|
|
|
|
// metadata.
|
|
|
|
ResumeLoad(PRELOAD_METADATA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:32:41 +03:00
|
|
|
MediaResult HTMLMediaElement::LoadResource() {
|
2017-08-01 00:29:07 +03:00
|
|
|
AbstractThread::AutoEnter context(AbstractMainThread());
|
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
NS_ASSERTION(mDelayingLoadEvent,
|
|
|
|
"Should delay load event (if in document) during load");
|
2009-02-20 05:49:00 +03:00
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
if (mChannelLoader) {
|
|
|
|
mChannelLoader->Cancel();
|
|
|
|
mChannelLoader = nullptr;
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
|
|
|
|
2012-01-26 02:31:30 +04:00
|
|
|
// Set the media element's CORS mode only when loading a resource
|
2012-03-10 20:13:52 +04:00
|
|
|
mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
2012-01-26 02:31:30 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc);
|
2012-09-25 07:25:43 +04:00
|
|
|
if (other && other->mDecoder) {
|
2011-11-25 06:06:22 +04:00
|
|
|
// Clone it.
|
2017-06-20 13:10:27 +03:00
|
|
|
// TODO: remove the cast by storing ChannelMediaDecoder in the URI table.
|
|
|
|
nsresult rv = InitializeDecoderAsClone(
|
|
|
|
static_cast<ChannelMediaDecoder*>(other->mDecoder.get()));
|
2011-11-25 06:06:22 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2015-05-28 05:38:34 +03:00
|
|
|
if (mMediaSource) {
|
2017-06-07 09:10:26 +03:00
|
|
|
MediaDecoderInit decoderInit(
|
|
|
|
this, mMuted ? 0.0 : mVolume, mPreservesPitch,
|
2018-11-07 16:56:25 +03:00
|
|
|
ClampPlaybackRate(mPlaybackRate),
|
2017-06-07 09:10:26 +03:00
|
|
|
mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, mHasSuspendTaint,
|
2017-06-26 12:10:47 +03:00
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::loop),
|
|
|
|
MediaContainerType(MEDIAMIMETYPE("application/x.mediasource")));
|
2017-06-07 09:10:26 +03:00
|
|
|
|
2017-06-07 07:14:11 +03:00
|
|
|
RefPtr<MediaSourceDecoder> decoder = new MediaSourceDecoder(decoderInit);
|
2015-05-28 05:38:34 +03:00
|
|
|
if (!mMediaSource->Attach(decoder)) {
|
2014-09-12 12:39:46 +04:00
|
|
|
// TODO: Handle failure: run "If the media data cannot be fetched at
|
|
|
|
// all, due to network errors, causing the user agent to give up
|
|
|
|
// trying to fetch the resource" section of resource fetch algorithm.
|
2015-07-21 13:01:00 +03:00
|
|
|
decoder->Shutdown();
|
2017-11-17 05:32:41 +03:00
|
|
|
return MediaResult(NS_ERROR_FAILURE, "Failed to attach MediaSource");
|
2014-09-12 12:39:46 +04:00
|
|
|
}
|
2016-07-15 07:22:47 +03:00
|
|
|
ChangeDelayLoadStatus(false);
|
2017-06-23 10:39:57 +03:00
|
|
|
nsresult rv = decoder->Load(mMediaSource->GetPrincipal());
|
2017-06-23 09:12:41 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
decoder->Shutdown();
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Failed to load for decoder %p", this, decoder.get()));
|
2017-11-17 05:32:41 +03:00
|
|
|
return MediaResult(rv, "Fail to load decoder");
|
2017-06-23 09:12:41 +03:00
|
|
|
}
|
2017-11-17 05:32:41 +03:00
|
|
|
rv = FinishDecoderSetup(decoder);
|
|
|
|
return MediaResult(rv, "Failed to set up decoder");
|
2013-06-21 07:15:47 +04:00
|
|
|
}
|
|
|
|
|
2017-10-12 05:46:13 +03:00
|
|
|
AssertReadyStateIsNothing();
|
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
RefPtr<ChannelLoader> loader = new ChannelLoader;
|
|
|
|
nsresult rv = loader->Load(this);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mChannelLoader = loader.forget();
|
2016-04-13 16:34:36 +03:00
|
|
|
}
|
2017-11-17 05:32:41 +03:00
|
|
|
return MediaResult(rv, "Failed to load channel");
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::LoadWithChannel(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener) {
|
2008-12-16 06:32:03 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aListener = nullptr;
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
// Make sure we don't reenter during synchronous abort events.
|
|
|
|
if (mIsRunningLoadMethod) return NS_OK;
|
|
|
|
mIsRunningLoadMethod = true;
|
2009-03-08 23:59:08 +03:00
|
|
|
AbortExistingLoads();
|
2012-04-30 07:12:28 +04:00
|
|
|
mIsRunningLoadMethod = false;
|
2008-12-16 06:32:03 +03:00
|
|
|
|
2017-10-06 00:47:09 +03:00
|
|
|
mLoadingSrcTriggeringPrincipal = nullptr;
|
2011-11-25 06:06:22 +04:00
|
|
|
nsresult rv = aChannel->GetOriginalURI(getter_AddRefs(mLoadingSrc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-24 03:30:03 +04:00
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
ChangeDelayLoadStatus(true);
|
|
|
|
rv = InitializeDecoderForChannel(aChannel, aListener);
|
2008-12-16 06:32:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-09-15 06:30:44 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
SetPlaybackRate(mDefaultPlaybackRate, IgnoreErrors());
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
|
2009-09-15 06:30:44 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
bool HTMLMediaElement::Seeking() const {
|
|
|
|
return mDecoder && mDecoder->IsSeeking();
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
double HTMLMediaElement::CurrentTime() const {
|
2015-08-31 14:33:53 +03:00
|
|
|
if (MediaStream* stream = GetSrcMediaStream()) {
|
2018-11-23 18:01:13 +03:00
|
|
|
MediaStreamGraph* graph = stream->Graph();
|
|
|
|
GraphTime currentTime =
|
|
|
|
mSrcStreamPausedGraphTime == GRAPH_TIME_MAX
|
|
|
|
? graph->CurrentTime() - mSrcStreamGraphTimeOffset
|
|
|
|
: mSrcStreamPausedGraphTime;
|
|
|
|
return stream->StreamTimeToSeconds(currentTime);
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
2015-10-26 12:36:16 +03:00
|
|
|
if (mDefaultPlaybackStartPosition == 0.0 && mDecoder) {
|
2013-03-19 16:25:19 +04:00
|
|
|
return mDecoder->GetCurrentTime();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2015-10-26 12:36:16 +03:00
|
|
|
return mDefaultPlaybackStartPosition;
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
void HTMLMediaElement::FastSeek(double aTime, ErrorResult& aRv) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p FastSeek(%f) called by JS", this, aTime));
|
2016-02-05 06:32:41 +03:00
|
|
|
LOG(LogLevel::Debug, ("Reporting telemetry VIDEO_FASTSEEK_USED"));
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_FASTSEEK_USED, 1);
|
2018-10-08 22:39:41 +03:00
|
|
|
RefPtr<Promise> tobeDropped =
|
|
|
|
Seek(aTime, SeekTarget::PrevSyncPoint, IgnoreErrors());
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:05:35 +03:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::SeekToNextFrame(ErrorResult& aRv) {
|
2017-10-04 17:01:04 +03:00
|
|
|
/* This will cause JIT code to be kept around longer, to help performance
|
|
|
|
* when using SeekToNextFrame to iterate through every frame of a video.
|
|
|
|
*/
|
2018-02-23 01:28:39 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow();
|
2017-10-04 17:01:04 +03:00
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
if (win) {
|
2018-05-14 12:11:18 +03:00
|
|
|
if (JSObject* obj = win->AsGlobal()->GetGlobalJSObject()) {
|
2017-10-04 17:01:04 +03:00
|
|
|
js::NotifyAnimationActivity(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:27:39 +03:00
|
|
|
return Seek(CurrentTime(), SeekTarget::NextFrame, aRv);
|
2016-05-24 18:05:35 +03:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
void HTMLMediaElement::SetCurrentTime(double aCurrentTime, ErrorResult& aRv) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p SetCurrentTime(%f) called by JS", this, aCurrentTime));
|
2018-10-08 22:39:41 +03:00
|
|
|
RefPtr<Promise> tobeDropped =
|
|
|
|
Seek(aCurrentTime, SeekTarget::Accurate, IgnoreErrors());
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-16 21:34:28 +03:00
|
|
|
* Check if aValue is inside a range of aRanges, and if so returns true
|
|
|
|
* and puts the range index in aIntervalIndex. If aValue is not
|
|
|
|
* inside a range, returns false, and aIntervalIndex
|
2018-02-17 21:29:43 +03:00
|
|
|
* is set to the index of the range which starts immediately after aValue
|
|
|
|
* (and can be aRanges.Length() if aValue is after the last range).
|
2014-04-01 07:39:04 +04:00
|
|
|
*/
|
2018-05-14 12:11:18 +03:00
|
|
|
static bool IsInRanges(TimeRanges& aRanges, double aValue,
|
|
|
|
uint32_t& aIntervalIndex) {
|
2018-02-16 21:34:28 +03:00
|
|
|
uint32_t length = aRanges.Length();
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2018-02-16 21:36:40 +03:00
|
|
|
double start = aRanges.Start(i);
|
2014-04-01 07:39:04 +04:00
|
|
|
if (start > aValue) {
|
2018-02-17 21:29:43 +03:00
|
|
|
aIntervalIndex = i;
|
2018-02-16 21:34:28 +03:00
|
|
|
return false;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
2018-02-16 21:36:40 +03:00
|
|
|
double end = aRanges.End(i);
|
2014-04-01 07:39:04 +04:00
|
|
|
if (aValue <= end) {
|
|
|
|
aIntervalIndex = i;
|
2018-02-16 21:34:28 +03:00
|
|
|
return true;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
}
|
2018-02-17 21:29:43 +03:00
|
|
|
aIntervalIndex = length;
|
2018-02-16 21:34:28 +03:00
|
|
|
return false;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> HTMLMediaElement::Seek(double aTime,
|
|
|
|
SeekTarget::Type aSeekType,
|
|
|
|
ErrorResult& aRv) {
|
2018-10-05 18:43:32 +03:00
|
|
|
// Note: Seek is called both by synchronous code that expects errors thrown in
|
|
|
|
// aRv, as well as asynchronous code that expects a promise. Make sure all
|
|
|
|
// synchronous errors are returned using aRv, not promise rejections.
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
// aTime should be non-NaN.
|
2014-12-22 03:16:26 +03:00
|
|
|
MOZ_ASSERT(!mozilla::IsNaN(aTime));
|
2013-03-19 16:25:19 +04:00
|
|
|
|
2018-10-08 22:39:41 +03:00
|
|
|
RefPtr<Promise> promise = CreateDOMPromise(aRv);
|
2016-06-09 22:27:39 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-27 05:55:02 +03:00
|
|
|
// Detect if user has interacted with element by seeking so that
|
|
|
|
// play will not be blocked when initiated by a script.
|
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2017-11-29 13:59:56 +03:00
|
|
|
mIsBlessed = true;
|
2017-11-27 05:55:02 +03:00
|
|
|
}
|
|
|
|
|
2009-05-18 06:00:44 +04:00
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
2015-10-27 12:57:31 +03:00
|
|
|
// do nothing since media streams have an empty Seekable range.
|
2018-10-05 18:43:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
|
|
|
|
2015-10-27 12:57:31 +03:00
|
|
|
if (mPlayed && mCurrentPlayRangeStart != -1.0) {
|
2013-03-19 16:25:19 +04:00
|
|
|
double rangeEndTime = CurrentTime();
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p Adding \'played\' a range : [%f, %f]", this,
|
|
|
|
mCurrentPlayRangeStart, rangeEndTime));
|
2012-05-01 04:29:24 +04:00
|
|
|
// Multiple seek without playing, or seek while playing.
|
|
|
|
if (mCurrentPlayRangeStart != rangeEndTime) {
|
2013-04-23 03:45:00 +04:00
|
|
|
mPlayed->Add(mCurrentPlayRangeStart, rangeEndTime);
|
2012-05-01 04:29:24 +04:00
|
|
|
}
|
2014-04-01 07:39:04 +04:00
|
|
|
// Reset the current played range start time. We'll re-set it once
|
|
|
|
// the seek completes.
|
|
|
|
mCurrentPlayRangeStart = -1.0;
|
2012-05-01 04:29:24 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
2015-10-27 12:57:31 +03:00
|
|
|
mDefaultPlaybackStartPosition = aTime;
|
2018-10-05 18:43:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2009-09-30 01:32:44 +04:00
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2015-10-27 12:57:31 +03:00
|
|
|
if (!mDecoder) {
|
|
|
|
// mDecoder must always be set in order to reach this point.
|
|
|
|
NS_ASSERTION(mDecoder, "SetCurrentTime failed: no decoder");
|
2018-10-05 18:43:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2014-03-28 13:36:10 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
// Clamp the seek target to inside the seekable ranges.
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals seekableIntervals = mDecoder->GetSeekable();
|
|
|
|
if (seekableIntervals.IsInvalid()) {
|
2018-10-05 18:43:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
2017-08-21 06:08:25 +03:00
|
|
|
RefPtr<TimeRanges> seekable =
|
|
|
|
new TimeRanges(ToSupports(OwnerDoc()), seekableIntervals);
|
2018-02-16 21:34:28 +03:00
|
|
|
uint32_t length = seekable->Length();
|
|
|
|
if (length == 0) {
|
2018-10-05 18:43:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the position we want to seek to is not in a seekable range, we seek
|
|
|
|
// to the closest position in the seekable ranges instead. If two positions
|
|
|
|
// are equally close, we seek to the closest position from the currentTime.
|
|
|
|
// See seeking spec, point 7 :
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#seeking
|
2018-02-17 21:29:43 +03:00
|
|
|
uint32_t range = 0;
|
2018-02-16 21:34:28 +03:00
|
|
|
bool isInRange = IsInRanges(*seekable, aTime, range);
|
2014-04-01 07:39:04 +04:00
|
|
|
if (!isInRange) {
|
2018-02-17 21:29:43 +03:00
|
|
|
if (range == 0) {
|
2014-04-01 07:39:04 +04:00
|
|
|
// aTime is before the first range in |seekable|, the closest point we can
|
|
|
|
// seek to is the start of the first range.
|
2018-02-16 21:36:40 +03:00
|
|
|
aTime = seekable->Start(0);
|
2018-02-17 21:29:43 +03:00
|
|
|
} else if (range == length) {
|
|
|
|
// Seek target is after the end last range in seekable data.
|
|
|
|
// Clamp the seek target to the end of the last seekable range.
|
|
|
|
aTime = seekable->End(length - 1);
|
|
|
|
} else {
|
|
|
|
double leftBound = seekable->End(range - 1);
|
|
|
|
double rightBound = seekable->Start(range);
|
|
|
|
double distanceLeft = Abs(leftBound - aTime);
|
|
|
|
double distanceRight = Abs(rightBound - aTime);
|
|
|
|
if (distanceLeft == distanceRight) {
|
|
|
|
double currentTime = CurrentTime();
|
|
|
|
distanceLeft = Abs(leftBound - currentTime);
|
|
|
|
distanceRight = Abs(rightBound - currentTime);
|
|
|
|
}
|
|
|
|
aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
|
2014-04-01 07:39:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: The spec requires us to update the current time to reflect the
|
|
|
|
// actual seek target before beginning the synchronous section, but
|
|
|
|
// that requires changing all MediaDecoderReaders to support telling
|
|
|
|
// us the fastSeek target, and it's currently not possible to get
|
|
|
|
// this information as we don't yet control the demuxer for all
|
|
|
|
// MediaDecoderReaders.
|
2014-03-28 13:36:10 +04:00
|
|
|
|
2008-12-15 06:38:16 +03:00
|
|
|
mPlayingBeforeSeek = IsPotentiallyPlaying();
|
2015-10-22 06:37:16 +03:00
|
|
|
|
2018-08-15 19:35:51 +03:00
|
|
|
// If the audio track is silent before seeking, we should end current silence
|
|
|
|
// range and start a new range after seeking. Since seek() could be called
|
|
|
|
// multiple times before seekEnd() executed, we should only calculate silence
|
|
|
|
// range when first time seek() called. Calculating on other seek() calls
|
|
|
|
// would cause a wrong result. In order to get correct time, this checking
|
|
|
|
// should be called before decoder->seek().
|
|
|
|
if (IsAudioTrackCurrentlySilent() &&
|
|
|
|
!mHasAccumulatedSilenceRangeBeforeSeekEnd) {
|
|
|
|
AccumulateAudioTrackSilence();
|
|
|
|
mHasAccumulatedSilenceRangeBeforeSeekEnd = true;
|
|
|
|
}
|
|
|
|
|
2008-10-23 12:02:18 +04:00
|
|
|
// The media backend is responsible for dispatching the timeupdate
|
|
|
|
// event if it changes the playback position as a result of the seek.
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p SetCurrentTime(%f) starting seek", this, aTime));
|
2018-04-30 20:58:11 +03:00
|
|
|
mDecoder->Seek(aTime, aSeekType);
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
// We changed whether we're seeking so we need to AddRemoveSelfReference.
|
2009-10-01 18:10:13 +04:00
|
|
|
AddRemoveSelfReference();
|
2016-06-09 22:27:39 +03:00
|
|
|
|
2017-04-17 13:25:26 +03:00
|
|
|
// Keep the DOM promise.
|
2018-10-08 22:39:41 +03:00
|
|
|
mSeekDOMPromise = promise;
|
|
|
|
|
|
|
|
return promise.forget();
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
double HTMLMediaElement::Duration() const {
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
2013-03-19 16:25:19 +04:00
|
|
|
return std::numeric_limits<double>::infinity();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2013-03-19 16:25:19 +04:00
|
|
|
|
|
|
|
if (mDecoder) {
|
|
|
|
return mDecoder->GetDuration();
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> HTMLMediaElement::Seekable() const {
|
2017-08-21 06:08:25 +03:00
|
|
|
media::TimeIntervals seekable =
|
|
|
|
mDecoder ? mDecoder->GetSeekable() : media::TimeIntervals();
|
|
|
|
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()), seekable);
|
2013-03-19 16:25:19 +04:00
|
|
|
return ranges.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TimeRanges> HTMLMediaElement::Played() {
|
2015-10-19 09:10:47 +03:00
|
|
|
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
|
2012-05-01 04:29:24 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t timeRangeCount = 0;
|
2013-12-03 11:22:37 +04:00
|
|
|
if (mPlayed) {
|
2018-02-16 21:34:28 +03:00
|
|
|
timeRangeCount = mPlayed->Length();
|
2013-12-03 11:22:37 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < timeRangeCount; i++) {
|
2018-02-16 21:36:40 +03:00
|
|
|
double begin = mPlayed->Start(i);
|
|
|
|
double end = mPlayed->End(i);
|
2012-05-01 04:29:24 +04:00
|
|
|
ranges->Add(begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurrentPlayRangeStart != -1.0) {
|
2013-03-19 16:25:19 +04:00
|
|
|
double now = CurrentTime();
|
2012-05-01 04:29:24 +04:00
|
|
|
if (mCurrentPlayRangeStart != now) {
|
|
|
|
ranges->Add(mCurrentPlayRangeStart, now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ranges->Normalize();
|
2013-03-19 16:25:19 +04:00
|
|
|
return ranges.forget();
|
|
|
|
}
|
2012-05-01 04:29:24 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
void HTMLMediaElement::Pause(ErrorResult& aRv) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p Pause() called by JS", this));
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState == NETWORK_EMPTY) {
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG(LogLevel::Debug, ("Loading due to Pause()"));
|
2015-06-17 03:02:51 +03:00
|
|
|
DoLoad();
|
2009-01-08 11:44:38 +03:00
|
|
|
} else if (mDecoder) {
|
|
|
|
mDecoder->Pause();
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool oldPaused = mPaused;
|
2011-09-30 03:34:37 +04:00
|
|
|
mPaused = true;
|
|
|
|
mAutoplaying = false;
|
2009-10-01 18:10:13 +04:00
|
|
|
// We changed mPaused and mAutoplaying which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2015-08-31 14:33:53 +03:00
|
|
|
UpdateSrcMediaStreamPlaying();
|
2017-01-23 05:52:06 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
|
|
|
mAudioChannelWrapper->NotifyPlayStateChanged();
|
|
|
|
}
|
2009-11-06 10:32:52 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
if (!oldPaused) {
|
2011-09-30 03:34:37 +04:00
|
|
|
FireTimeUpdate(false);
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
|
2016-08-18 15:05:13 +03:00
|
|
|
AsyncRejectPendingPlayPromises(NS_ERROR_DOM_MEDIA_ABORT_ERR);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
void HTMLMediaElement::SetVolume(double aVolume, ErrorResult& aRv) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p SetVolume(%f) called by JS", this, aVolume));
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
if (aVolume < 0.0 || aVolume > 1.0) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-01 09:44:16 +04:00
|
|
|
|
2009-02-25 13:59:00 +03:00
|
|
|
if (aVolume == mVolume) return;
|
|
|
|
|
|
|
|
mVolume = aVolume;
|
|
|
|
|
2013-05-21 21:49:17 +04:00
|
|
|
// Here we want just to update the volume.
|
2013-05-27 09:13:05 +04:00
|
|
|
SetVolumeInternal();
|
2009-02-25 13:59:00 +03:00
|
|
|
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
|
2018-03-12 03:05:04 +03:00
|
|
|
|
|
|
|
// We allow inaudible autoplay. But changing our volume may make this
|
|
|
|
// media audible. So pause if we are no longer supposed to be autoplaying.
|
|
|
|
PauseIfShouldNotBePlaying();
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void HTMLMediaElement::MozGetMetadata(JSContext* cx,
|
|
|
|
JS::MutableHandle<JSObject*> aRetval,
|
|
|
|
ErrorResult& aRv) {
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mReadyState < HAVE_METADATA) {
|
2013-03-19 16:25:19 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2012-07-31 04:14:29 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 18:38:08 +03:00
|
|
|
JS::Rooted<JSObject*> tags(cx, JS_NewPlainObject(cx));
|
2012-07-31 04:14:29 +04:00
|
|
|
if (!tags) {
|
2013-03-19 16:25:19 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2012-07-31 04:14:29 +04:00
|
|
|
}
|
|
|
|
if (mTags) {
|
2015-07-28 04:45:12 +03:00
|
|
|
for (auto iter = mTags->ConstIter(); !iter.Done(); iter.Next()) {
|
2018-02-15 08:22:38 +03:00
|
|
|
nsString wideValue;
|
|
|
|
CopyUTF8toUTF16(iter.UserData(), wideValue);
|
2015-07-28 04:45:12 +03:00
|
|
|
JS::Rooted<JSString*> string(cx,
|
|
|
|
JS_NewUCStringCopyZ(cx, wideValue.Data()));
|
2018-05-14 12:11:18 +03:00
|
|
|
if (!string || !JS_DefineProperty(cx, tags, iter.Key().Data(), string,
|
|
|
|
JSPROP_ENUMERATE)) {
|
2015-07-28 04:45:12 +03:00
|
|
|
NS_WARNING("couldn't create metadata object!");
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-15 00:04:46 +04:00
|
|
|
}
|
2012-07-31 04:14:29 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
aRetval.set(tags);
|
2012-07-31 04:14:29 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
void HTMLMediaElement::SetMutedInternal(uint32_t aMuted) {
|
2013-05-21 21:49:17 +04:00
|
|
|
uint32_t oldMuted = mMuted;
|
|
|
|
mMuted = aMuted;
|
|
|
|
|
|
|
|
if (!!aMuted == !!oldMuted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-27 09:13:05 +04:00
|
|
|
SetVolumeInternal();
|
|
|
|
}
|
|
|
|
|
2018-03-12 03:05:04 +03:00
|
|
|
void HTMLMediaElement::PauseIfShouldNotBePlaying() {
|
|
|
|
if (GetPaused()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-23 18:43:08 +03:00
|
|
|
if (!AutoplayPolicy::IsAllowedToPlay(*this)) {
|
2018-08-02 03:30:59 +03:00
|
|
|
AUTOPLAY_LOG("pause because not allowed to play, element=%p", this);
|
2018-03-12 03:05:04 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
Pause(rv);
|
2018-07-18 06:34:04 +03:00
|
|
|
OwnerDoc()->SetDocTreeHadPlayRevoked();
|
2018-03-12 03:05:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
void HTMLMediaElement::SetVolumeInternal() {
|
2015-07-16 21:34:30 +03:00
|
|
|
float effectiveVolume = ComputedVolume();
|
2014-03-11 14:46:55 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
if (mDecoder) {
|
2012-04-30 07:12:28 +04:00
|
|
|
mDecoder->SetVolume(effectiveVolume);
|
2015-08-31 14:33:53 +03:00
|
|
|
} else if (MediaStream* stream = GetSrcMediaStream()) {
|
|
|
|
if (mSrcStreamIsPlaying) {
|
|
|
|
stream->SetAudioOutputVolume(this, effectiveVolume);
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2015-08-01 17:31:04 +03:00
|
|
|
|
2016-06-01 05:26:10 +03:00
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::eVolumeChanged);
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
void HTMLMediaElement::SetMuted(bool aMuted) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p SetMuted(%d) called by JS", this, aMuted));
|
2013-05-24 16:04:20 +04:00
|
|
|
if (aMuted == Muted()) {
|
2018-02-15 08:22:38 +03:00
|
|
|
return;
|
2013-05-24 16:04:20 +04:00
|
|
|
}
|
|
|
|
|
2013-05-21 21:49:17 +04:00
|
|
|
if (aMuted) {
|
|
|
|
SetMutedInternal(mMuted | MUTED_BY_CONTENT);
|
|
|
|
} else {
|
|
|
|
SetMutedInternal(mMuted & ~MUTED_BY_CONTENT);
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
|
2018-03-12 03:05:04 +03:00
|
|
|
|
|
|
|
// We allow inaudible autoplay. But changing our mute status may make this
|
|
|
|
// media audible. So pause if we are no longer supposed to be autoplaying.
|
|
|
|
PauseIfShouldNotBePlaying();
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SetCapturedOutputStreamsEnabled(bool aEnabled) {
|
2016-08-23 18:51:50 +03:00
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
if (ms.mCapturingDecoder) {
|
|
|
|
MOZ_ASSERT(!ms.mCapturingMediaStream);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto pair : ms.mTrackPorts) {
|
|
|
|
MediaStream* outputSource = ms.mStream->GetInputStream();
|
|
|
|
if (!outputSource) {
|
|
|
|
NS_ERROR("No output source stream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackID id = pair.second()->GetDestinationTrackId();
|
2018-05-14 12:11:18 +03:00
|
|
|
outputSource->SetTrackEnabled(
|
|
|
|
id, aEnabled ? DisabledTrackMode::ENABLED
|
|
|
|
: DisabledTrackMode::SILENCE_FREEZE);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%s track %d for captured MediaStream %p",
|
2018-05-14 12:11:18 +03:00
|
|
|
aEnabled ? "Enabled" : "Disabled", id, ms.mStream.get()));
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::AddCaptureMediaTrackToOutputStream(
|
|
|
|
MediaTrack* aTrack, OutputMediaStream& aOutputStream, bool aAsyncAddtrack) {
|
2016-08-23 18:51:50 +03:00
|
|
|
if (aOutputStream.mCapturingDecoder) {
|
|
|
|
MOZ_ASSERT(!aOutputStream.mCapturingMediaStream);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aOutputStream.mCapturingMediaStream = true;
|
|
|
|
|
2017-01-09 21:10:48 +03:00
|
|
|
if (aOutputStream.mStream == mSrcStream) {
|
|
|
|
// Cycle detected. This can happen since tracks are added async.
|
|
|
|
// We avoid forwarding it to the output here or we'd get into an infloop.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
MediaStream* outputSource = aOutputStream.mStream->GetInputStream();
|
|
|
|
if (!outputSource) {
|
|
|
|
NS_ERROR("No output source stream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessedMediaStream* processedOutputSource =
|
|
|
|
outputSource->AsProcessedStream();
|
|
|
|
if (!processedOutputSource) {
|
|
|
|
NS_ERROR("Input stream not a ProcessedMediaStream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aTrack) {
|
|
|
|
MOZ_ASSERT(false, "Bad MediaTrack");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStreamTrack* inputTrack = mSrcStream->GetTrackById(aTrack->GetId());
|
|
|
|
MOZ_ASSERT(inputTrack);
|
|
|
|
if (!inputTrack) {
|
|
|
|
NS_ERROR("Input track not found in source stream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
for (auto pair : aOutputStream.mTrackPorts) {
|
|
|
|
MOZ_ASSERT(pair.first() != aTrack->GetId(),
|
|
|
|
"Captured track already captured to output stream");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TrackID destinationTrackID = aOutputStream.mNextAvailableTrackID++;
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<MediaStreamTrackSource> source =
|
|
|
|
new StreamCaptureTrackSource(this, &inputTrack->GetSource(),
|
|
|
|
aOutputStream.mStream, destinationTrackID);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
MediaSegment::Type type = inputTrack->AsAudioStreamTrack()
|
2018-05-14 12:11:18 +03:00
|
|
|
? MediaSegment::AUDIO
|
|
|
|
: MediaSegment::VIDEO;
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
RefPtr<MediaStreamTrack> track =
|
|
|
|
aOutputStream.mStream->CreateDOMTrack(destinationTrackID, type, source);
|
|
|
|
|
|
|
|
if (aAsyncAddtrack) {
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(
|
2017-01-08 23:55:19 +03:00
|
|
|
NewRunnableMethod<StoreRefPtrPassByPtr<MediaStreamTrack>>(
|
2017-05-10 02:19:37 +03:00
|
|
|
"DOMMediaStream::AddTrackInternal", aOutputStream.mStream,
|
2018-05-14 12:11:18 +03:00
|
|
|
&DOMMediaStream::AddTrackInternal, track));
|
2016-08-23 18:51:50 +03:00
|
|
|
} else {
|
|
|
|
aOutputStream.mStream->AddTrackInternal(track);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track is muted initially, so we don't leak data if it's added while paused
|
|
|
|
// and an MSG iteration passes before the mute comes into effect.
|
2016-08-15 15:19:42 +03:00
|
|
|
processedOutputSource->SetTrackEnabled(destinationTrackID,
|
|
|
|
DisabledTrackMode::SILENCE_FREEZE);
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<MediaInputPort> port = inputTrack->ForwardTrackContentsTo(
|
|
|
|
processedOutputSource, destinationTrackID);
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
Pair<nsString, RefPtr<MediaInputPort>> p(aTrack->GetId(), port);
|
2018-05-30 22:15:35 +03:00
|
|
|
aOutputStream.mTrackPorts.AppendElement(std::move(p));
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
if (mSrcStreamIsPlaying) {
|
2016-08-15 15:19:42 +03:00
|
|
|
processedOutputSource->SetTrackEnabled(destinationTrackID,
|
|
|
|
DisabledTrackMode::ENABLED);
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("Created %s track %p with id %d from track %p through MediaInputPort %p",
|
|
|
|
inputTrack->AsAudioStreamTrack() ? "audio" : "video", track.get(),
|
2018-05-14 12:11:18 +03:00
|
|
|
destinationTrackID, inputTrack, port.get()));
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
bool HTMLMediaElement::CanBeCaptured(StreamCaptureType aCaptureType) {
|
2017-06-29 01:19:39 +03:00
|
|
|
// Don't bother capturing when the document has gone away
|
|
|
|
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent capturing restricted video
|
2017-07-28 18:53:12 +03:00
|
|
|
if (aCaptureType == StreamCaptureType::CAPTURE_ALL_TRACKS &&
|
|
|
|
ContainsRestrictedContent()) {
|
2017-06-29 01:19:39 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
already_AddRefed<DOMMediaStream> HTMLMediaElement::CaptureStreamInternal(
|
|
|
|
StreamCaptureBehavior aFinishBehavior, StreamCaptureType aStreamCaptureType,
|
2016-01-14 13:34:39 +03:00
|
|
|
MediaStreamGraph* aGraph) {
|
2016-09-07 16:14:15 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aGraph);
|
2017-07-28 18:53:12 +03:00
|
|
|
MOZ_ASSERT(CanBeCaptured(aStreamCaptureType));
|
2016-09-07 16:14:15 +03:00
|
|
|
|
2017-03-22 09:33:11 +03:00
|
|
|
MarkAsContentSource(CallerAPI::CAPTURE_STREAM);
|
2017-03-22 09:46:09 +03:00
|
|
|
MarkAsTainted();
|
2016-09-02 11:52:44 +03:00
|
|
|
|
2017-06-29 01:19:39 +03:00
|
|
|
// We don't support routing to a different graph.
|
2015-12-03 15:30:46 +03:00
|
|
|
if (!mOutputStreams.IsEmpty() &&
|
|
|
|
aGraph != mOutputStreams[0].mStream->GetInputStream()->Graph()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
OutputMediaStream* out = mOutputStreams.AppendElement();
|
2017-06-29 01:19:39 +03:00
|
|
|
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
2018-11-23 18:02:03 +03:00
|
|
|
out->mStream = DOMMediaStream::CreateTrackUnionStreamAsInput(window, aGraph);
|
|
|
|
out->mStream->SetFinishedOnInactive(false);
|
2018-05-14 12:11:18 +03:00
|
|
|
out->mFinishWhenEnded =
|
|
|
|
aFinishBehavior == StreamCaptureBehavior::FINISH_WHEN_ENDED;
|
|
|
|
out->mCapturingAudioOnly =
|
|
|
|
aStreamCaptureType == StreamCaptureType::CAPTURE_AUDIO;
|
2016-08-23 18:51:50 +03:00
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
if (aStreamCaptureType == StreamCaptureType::CAPTURE_AUDIO) {
|
2016-08-23 18:51:50 +03:00
|
|
|
if (mSrcStream) {
|
|
|
|
// We don't support applying volume and mute to the captured stream, when
|
|
|
|
// capturing a MediaStream.
|
2018-05-14 12:11:18 +03:00
|
|
|
nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("Media"), OwnerDoc(),
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"MediaElementAudioCaptureOfMediaStreamError");
|
2016-08-23 18:51:50 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mAudioCaptured tells the user that the audio played by this media element
|
|
|
|
// is being routed to the captureStreams *instead* of being played to
|
|
|
|
// speakers.
|
|
|
|
mAudioCaptured = true;
|
|
|
|
}
|
|
|
|
|
2016-08-31 15:54:03 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
out->mCapturingDecoder = true;
|
2018-11-23 18:02:03 +03:00
|
|
|
mDecoder->AddOutputStream(out->mStream);
|
2016-08-31 15:54:03 +03:00
|
|
|
} else if (mSrcStream) {
|
|
|
|
out->mCapturingMediaStream = true;
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
2016-08-31 15:54:03 +03:00
|
|
|
// Do not expose the tracks until we have metadata.
|
2016-08-23 18:51:50 +03:00
|
|
|
RefPtr<DOMMediaStream> result = out->mStream;
|
|
|
|
return result.forget();
|
|
|
|
}
|
2012-04-30 07:12:42 +04:00
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
if (mSrcStream) {
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(AudioTracks(), "Element can't have been unlinked");
|
2016-08-23 18:51:50 +03:00
|
|
|
for (size_t i = 0; i < AudioTracks()->Length(); ++i) {
|
|
|
|
AudioTrack* t = (*AudioTracks())[i];
|
|
|
|
if (t->Enabled()) {
|
|
|
|
AddCaptureMediaTrackToOutputStream(t, *out, false);
|
2015-02-09 10:23:34 +03:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
if (IsVideo() && !out->mCapturingAudioOnly) {
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(VideoTracks(), "Element can't have been unlinked");
|
2016-08-23 18:51:50 +03:00
|
|
|
// Only add video tracks if we're a video element and the output stream
|
|
|
|
// wants video.
|
|
|
|
for (size_t i = 0; i < VideoTracks()->Length(); ++i) {
|
|
|
|
VideoTrack* t = (*VideoTracks())[i];
|
|
|
|
if (t->Selected()) {
|
|
|
|
AddCaptureMediaTrackToOutputStream(t, *out, false);
|
|
|
|
}
|
2015-02-09 10:23:34 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMediaStream> result = out->mStream;
|
2012-04-30 07:12:42 +04:00
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
already_AddRefed<DOMMediaStream> HTMLMediaElement::CaptureAudio(
|
2018-05-14 12:11:18 +03:00
|
|
|
ErrorResult& aRv, MediaStreamGraph* aGraph) {
|
2016-09-07 16:14:15 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aGraph);
|
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
if (!CanBeCaptured(StreamCaptureType::CAPTURE_AUDIO)) {
|
2017-07-27 17:02:28 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-09-07 16:14:15 +03:00
|
|
|
RefPtr<DOMMediaStream> stream =
|
2017-07-28 18:53:12 +03:00
|
|
|
CaptureStreamInternal(StreamCaptureBehavior::CONTINUE_WHEN_ENDED,
|
|
|
|
StreamCaptureType::CAPTURE_AUDIO, aGraph);
|
2016-08-23 18:51:50 +03:00
|
|
|
if (!stream) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2016-09-07 16:14:15 +03:00
|
|
|
already_AddRefed<DOMMediaStream> HTMLMediaElement::MozCaptureStream(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
MediaStreamGraph::GraphDriverType graphDriverType =
|
|
|
|
HasAudio() ? MediaStreamGraph::AUDIO_THREAD_DRIVER
|
|
|
|
: MediaStreamGraph::SYSTEM_THREAD_DRIVER;
|
2017-06-29 01:19:39 +03:00
|
|
|
|
|
|
|
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
if (!CanBeCaptured(StreamCaptureType::CAPTURE_ALL_TRACKS)) {
|
2017-06-29 01:19:39 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MediaStreamGraph* graph = MediaStreamGraph::GetInstance(
|
|
|
|
graphDriverType, window, MediaStreamGraph::REQUEST_DEFAULT_SAMPLE_RATE);
|
2016-09-07 16:14:15 +03:00
|
|
|
|
|
|
|
RefPtr<DOMMediaStream> stream =
|
2017-07-28 18:53:12 +03:00
|
|
|
CaptureStreamInternal(StreamCaptureBehavior::CONTINUE_WHEN_ENDED,
|
|
|
|
StreamCaptureType::CAPTURE_ALL_TRACKS, graph);
|
2013-03-19 16:25:19 +04:00
|
|
|
if (!stream) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stream.forget();
|
|
|
|
}
|
|
|
|
|
2016-09-07 16:14:15 +03:00
|
|
|
already_AddRefed<DOMMediaStream> HTMLMediaElement::MozCaptureStreamUntilEnded(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
MediaStreamGraph::GraphDriverType graphDriverType =
|
|
|
|
HasAudio() ? MediaStreamGraph::AUDIO_THREAD_DRIVER
|
|
|
|
: MediaStreamGraph::SYSTEM_THREAD_DRIVER;
|
2017-06-29 01:19:39 +03:00
|
|
|
|
|
|
|
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:53:12 +03:00
|
|
|
if (!CanBeCaptured(StreamCaptureType::CAPTURE_ALL_TRACKS)) {
|
2017-06-29 01:19:39 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MediaStreamGraph* graph = MediaStreamGraph::GetInstance(
|
|
|
|
graphDriverType, window, MediaStreamGraph::REQUEST_DEFAULT_SAMPLE_RATE);
|
2016-09-07 16:14:15 +03:00
|
|
|
|
|
|
|
RefPtr<DOMMediaStream> stream =
|
2017-07-28 18:53:12 +03:00
|
|
|
CaptureStreamInternal(StreamCaptureBehavior::FINISH_WHEN_ENDED,
|
|
|
|
StreamCaptureType::CAPTURE_ALL_TRACKS, graph);
|
2013-03-19 16:25:19 +04:00
|
|
|
if (!stream) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-02-15 12:04:11 +04:00
|
|
|
}
|
2013-03-19 16:25:19 +04:00
|
|
|
|
|
|
|
return stream.forget();
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
class MediaElementSetForURI : public nsURIHashKey {
|
2011-11-25 06:06:22 +04:00
|
|
|
public:
|
Bug 1415980 - make hash keys movable and not copyable; r=erahm
Everything that goes in a PLDHashtable (and its derivatives, like
nsTHashtable) needs to inherit from PLDHashEntryHdr. But through a lack
of enforcement, copy constructors for these derived classes didn't
explicitly invoke the copy constructor for PLDHashEntryHdr (and the
compiler didn't invoke the copy constructor for us). Instead,
PLDHashTable explicitly copied around the bits that the copy constructor
would have.
The current setup has two problems:
1) Derived classes should be using move construction, not copy
construction, since anything that's shuffling hash table keys/entries
around will be using move construction.
2) Derived classes should take responsibility for transferring bits of
superclass state around, and not rely on something else to handle that.
The second point is not a huge problem for PLDHashTable (PLDHashTable
only has to copy PLDHashEntryHdr's bits in a single place), but future
hash table implementations that might move entries around more
aggressively would have to insert compensation code all over the
place. Additionally, if moving entries is implemented via memcpy (which
is quite common), PLDHashTable copying around bits *again* is
inefficient.
Let's fix all these problems in one go, by:
1) Explicitly declaring the set of constructors that PLDHashEntryHdr
implements (and does not implement). In particular, the copy
constructor is deleted, so any derived classes that attempt to make
themselves copyable will be detected at compile time: the compiler
will complain that the superclass type is not copyable.
This change on its own will result in many compiler errors, so...
2) Change any derived classes to implement move constructors instead of
copy constructors. Note that some of these move constructors are,
strictly speaking, unnecessary, since the relevant classes are moved
via memcpy in nsTHashtable and its derivatives.
2018-09-20 18:20:36 +03:00
|
|
|
explicit MediaElementSetForURI(const nsIURI* aKey) : nsURIHashKey(aKey) {}
|
|
|
|
MediaElementSetForURI(MediaElementSetForURI&& aOther)
|
|
|
|
: nsURIHashKey(std::move(aOther)),
|
|
|
|
mElements(std::move(aOther.mElements)) {}
|
2013-03-19 16:23:54 +04:00
|
|
|
nsTArray<HTMLMediaElement*> mElements;
|
2011-11-25 06:06:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<MediaElementSetForURI> MediaElementURITable;
|
|
|
|
// Elements in this table must have non-null mDecoder and mLoadingSrc, and those
|
|
|
|
// can't change while the element is in the table. The table is keyed by
|
|
|
|
// the element's mLoadingSrc. Each entry has a list of all elements with the
|
|
|
|
// same mLoadingSrc.
|
|
|
|
static MediaElementURITable* gElementTable;
|
|
|
|
|
2012-01-11 02:58:43 +04:00
|
|
|
#ifdef DEBUG
|
2015-09-10 10:00:15 +03:00
|
|
|
static bool URISafeEquals(nsIURI* a1, nsIURI* a2) {
|
|
|
|
if (!a1 || !a2) {
|
|
|
|
// Consider two empty URIs *not* equal!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool equal = false;
|
|
|
|
nsresult rv = a1->Equals(a2, &equal);
|
|
|
|
return NS_SUCCEEDED(rv) && equal;
|
|
|
|
}
|
2012-01-11 02:58:43 +04:00
|
|
|
// Returns the number of times aElement appears in the media element table
|
|
|
|
// for aURI. If this returns other than 0 or 1, there's a bug somewhere!
|
2013-03-19 16:23:54 +04:00
|
|
|
static unsigned MediaElementTableCount(HTMLMediaElement* aElement,
|
|
|
|
nsIURI* aURI) {
|
2015-09-10 10:00:15 +03:00
|
|
|
if (!gElementTable || !aElement) {
|
2012-01-11 02:58:43 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-10 10:00:15 +03:00
|
|
|
uint32_t uriCount = 0;
|
|
|
|
uint32_t otherCount = 0;
|
|
|
|
for (auto it = gElementTable->ConstIter(); !it.Done(); it.Next()) {
|
|
|
|
MediaElementSetForURI* entry = it.Get();
|
|
|
|
uint32_t count = 0;
|
|
|
|
for (const auto& elem : entry->mElements) {
|
|
|
|
if (elem == aElement) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (URISafeEquals(aURI, entry->GetKey())) {
|
|
|
|
uriCount = count;
|
|
|
|
} else {
|
|
|
|
otherCount += count;
|
2012-01-11 02:58:43 +04:00
|
|
|
}
|
|
|
|
}
|
2015-09-10 10:00:15 +03:00
|
|
|
NS_ASSERTION(otherCount == 0, "Should not have entries for unknown URIs");
|
|
|
|
return uriCount;
|
2012-01-11 02:58:43 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
void HTMLMediaElement::AddMediaElementToURITable() {
|
2017-08-17 10:41:22 +03:00
|
|
|
NS_ASSERTION(mDecoder, "Call this only with decoder Load called");
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
MediaElementTableCount(this, mLoadingSrc) == 0,
|
2012-01-11 02:58:43 +04:00
|
|
|
"Should not have entry for element in element table before addition");
|
2011-11-25 06:06:22 +04:00
|
|
|
if (!gElementTable) {
|
|
|
|
gElementTable = new MediaElementURITable();
|
|
|
|
}
|
|
|
|
MediaElementSetForURI* entry = gElementTable->PutEntry(mLoadingSrc);
|
|
|
|
entry->mElements.AppendElement(this);
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
MediaElementTableCount(this, mLoadingSrc) == 1,
|
2012-01-11 02:58:43 +04:00
|
|
|
"Should have a single entry for element in element table after addition");
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
|
|
|
|
2018-02-07 05:28:07 +03:00
|
|
|
void HTMLMediaElement::RemoveMediaElementFromURITable() {
|
2015-09-10 10:01:44 +03:00
|
|
|
if (!mDecoder || !mLoadingSrc || !gElementTable) {
|
2011-11-25 06:06:22 +04:00
|
|
|
return;
|
2015-09-10 10:01:44 +03:00
|
|
|
}
|
2011-11-25 06:06:22 +04:00
|
|
|
MediaElementSetForURI* entry = gElementTable->GetEntry(mLoadingSrc);
|
2015-09-10 10:01:44 +03:00
|
|
|
if (!entry) {
|
2011-11-25 06:06:22 +04:00
|
|
|
return;
|
2015-09-10 10:01:44 +03:00
|
|
|
}
|
2018-02-07 05:28:07 +03:00
|
|
|
entry->mElements.RemoveElement(this);
|
|
|
|
if (entry->mElements.IsEmpty()) {
|
2015-09-25 05:05:16 +03:00
|
|
|
gElementTable->RemoveEntry(entry);
|
2018-02-07 05:28:07 +03:00
|
|
|
if (gElementTable->Count() == 0) {
|
|
|
|
delete gElementTable;
|
|
|
|
gElementTable = nullptr;
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
|
|
|
}
|
2012-01-11 02:58:43 +04:00
|
|
|
NS_ASSERTION(MediaElementTableCount(this, mLoadingSrc) == 0,
|
2018-05-14 12:11:18 +03:00
|
|
|
"After remove, should no longer have an entry in element table");
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* HTMLMediaElement::LookupMediaElementURITable(nsIURI* aURI) {
|
2015-09-10 10:01:44 +03:00
|
|
|
if (!gElementTable) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-09-10 10:01:44 +03:00
|
|
|
}
|
2011-11-25 06:06:22 +04:00
|
|
|
MediaElementSetForURI* entry = gElementTable->GetEntry(aURI);
|
2015-09-10 10:01:44 +03:00
|
|
|
if (!entry) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-09-10 10:01:44 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < entry->mElements.Length(); ++i) {
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* elem = entry->mElements[i];
|
2011-11-25 06:06:22 +04:00
|
|
|
bool equal;
|
2012-01-26 02:31:30 +04:00
|
|
|
// Look for elements that have the same principal and CORS mode.
|
|
|
|
// Ditto for anything else that could cause us to send different headers.
|
2018-05-14 12:11:18 +03:00
|
|
|
if (NS_SUCCEEDED(elem->NodePrincipal()->Equals(NodePrincipal(), &equal)) &&
|
|
|
|
equal && elem->mCORSMode == mCORSMode) {
|
2017-08-04 10:29:55 +03:00
|
|
|
// See SetupDecoder() below. We only add a element to the table when
|
|
|
|
// mDecoder is a ChannelMediaDecoder.
|
|
|
|
auto decoder = static_cast<ChannelMediaDecoder*>(elem->mDecoder.get());
|
|
|
|
NS_ASSERTION(decoder, "Decoder gone");
|
|
|
|
if (decoder->CanClone()) {
|
2012-03-20 11:55:40 +04:00
|
|
|
return elem;
|
|
|
|
}
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
|
|
|
|
2017-09-20 12:46:34 +03:00
|
|
|
class HTMLMediaElement::ShutdownObserver : public nsIObserver {
|
|
|
|
enum class Phase : int8_t { Init, Subscribed, Unsubscribed };
|
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2017-09-20 12:46:34 +03:00
|
|
|
NS_IMETHOD Observe(nsISupports*, const char* aTopic,
|
|
|
|
const char16_t*) override {
|
2017-09-20 12:51:10 +03:00
|
|
|
if (mPhase != Phase::Subscribed) {
|
|
|
|
// Bail out if we are not subscribed for this might be called even after
|
|
|
|
// |nsContentUtils::UnregisterShutdownObserver(this)|.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-05-22 16:39:55 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWeak);
|
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
mWeak->NotifyShutdownEvent();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-09-20 12:46:34 +03:00
|
|
|
void Subscribe(HTMLMediaElement* aPtr) {
|
2016-09-20 06:27:46 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPhase == Phase::Init);
|
2016-05-22 16:39:55 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mWeak);
|
|
|
|
mWeak = aPtr;
|
|
|
|
nsContentUtils::RegisterShutdownObserver(this);
|
2016-09-20 06:27:46 +03:00
|
|
|
mPhase = Phase::Subscribed;
|
2016-05-22 16:39:55 +03:00
|
|
|
}
|
2017-09-20 12:46:34 +03:00
|
|
|
void Unsubscribe() {
|
2016-09-20 06:27:46 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPhase == Phase::Subscribed);
|
2016-05-22 16:39:55 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWeak);
|
2018-11-15 15:48:11 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mAddRefed,
|
|
|
|
"ReleaseMediaElement should have been called first");
|
2016-05-22 16:39:55 +03:00
|
|
|
mWeak = nullptr;
|
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
2016-09-20 06:27:46 +03:00
|
|
|
mPhase = Phase::Unsubscribed;
|
2016-05-22 16:39:55 +03:00
|
|
|
}
|
2018-11-15 15:48:11 +03:00
|
|
|
void AddRefMediaElement() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWeak);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mAddRefed, "Should only ever AddRef once");
|
|
|
|
mWeak->AddRef();
|
|
|
|
mAddRefed = true;
|
|
|
|
}
|
|
|
|
void ReleaseMediaElement() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWeak);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mAddRefed, "Should only release after AddRef");
|
|
|
|
mWeak->Release();
|
|
|
|
mAddRefed = false;
|
|
|
|
}
|
2017-09-20 12:46:34 +03:00
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
private:
|
2017-09-20 12:46:34 +03:00
|
|
|
virtual ~ShutdownObserver() {
|
2016-09-20 06:27:46 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPhase == Phase::Unsubscribed);
|
2016-05-22 16:39:55 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mWeak);
|
2018-11-15 15:48:11 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mAddRefed,
|
|
|
|
"ReleaseMediaElement should have been called first");
|
2016-05-22 16:39:55 +03:00
|
|
|
}
|
|
|
|
// Guaranteed to be valid by HTMLMediaElement.
|
|
|
|
HTMLMediaElement* mWeak = nullptr;
|
2016-09-20 06:27:46 +03:00
|
|
|
Phase mPhase = Phase::Init;
|
2018-11-15 15:48:11 +03:00
|
|
|
bool mAddRefed = false;
|
2016-05-22 16:39:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(HTMLMediaElement::ShutdownObserver, nsIObserver)
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
HTMLMediaElement::HTMLMediaElement(
|
2018-09-21 23:45:49 +03:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)),
|
2018-05-21 05:19:47 +03:00
|
|
|
mWatchManager(this,
|
|
|
|
OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other)),
|
2018-03-13 03:41:46 +03:00
|
|
|
mMainThreadEventTarget(OwnerDoc()->EventTargetFor(TaskCategory::Other)),
|
|
|
|
mAbstractMainThread(
|
|
|
|
OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other)),
|
|
|
|
mShutdownObserver(new ShutdownObserver),
|
|
|
|
mPlayed(new TimeRanges(ToSupports(OwnerDoc()))),
|
2018-05-21 05:19:47 +03:00
|
|
|
mPaused(true, "HTMLMediaElement::mPaused"),
|
2018-11-15 15:48:34 +03:00
|
|
|
mAudioTrackList(new AudioTrackList(OwnerDoc()->GetParentObject(), this)),
|
|
|
|
mVideoTrackList(new VideoTrackList(OwnerDoc()->GetParentObject(), this)),
|
2018-03-13 03:41:46 +03:00
|
|
|
mErrorSink(new ErrorSink(this)),
|
|
|
|
mAudioChannelWrapper(new AudioChannelAgentCallback(this)),
|
2018-10-12 12:39:30 +03:00
|
|
|
mSink(MakePair(nsString(), RefPtr<AudioDeviceInfo>())) {
|
2017-07-07 05:36:13 +03:00
|
|
|
MOZ_ASSERT(mMainThreadEventTarget);
|
|
|
|
MOZ_ASSERT(mAbstractMainThread);
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LogConstruction(this);
|
|
|
|
|
2018-05-21 05:19:47 +03:00
|
|
|
mWatchManager.Watch(mPaused, &HTMLMediaElement::UpdateWakeLock);
|
|
|
|
|
2016-05-24 20:55:45 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
|
|
|
|
double defaultVolume = Preferences::GetFloat("media.default_volume", 1.0);
|
|
|
|
SetVolume(defaultVolume, rv);
|
|
|
|
|
2014-06-19 06:09:35 +04:00
|
|
|
RegisterActivityObserver();
|
2016-08-29 13:56:38 +03:00
|
|
|
NotifyOwnerDocumentActivityChanged();
|
2015-03-19 05:01:12 +03:00
|
|
|
|
2018-12-13 23:06:03 +03:00
|
|
|
// We initialize the MediaShutdownManager as the HTMLMediaElement is always
|
|
|
|
// constructed on the main thread, and not during stable state.
|
|
|
|
// (MediaShutdownManager make use of nsIAsyncShutdownClient which is written
|
|
|
|
// in JS)
|
|
|
|
MediaShutdownManager::InitStatics();
|
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
mShutdownObserver->Subscribe(this);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement::~HTMLMediaElement() {
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
!mHasSelfReference,
|
|
|
|
"How can we be destroyed if we're still holding a self reference?");
|
2018-02-07 05:28:48 +03:00
|
|
|
|
2016-05-22 16:39:55 +03:00
|
|
|
mShutdownObserver->Unsubscribe();
|
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
if (mVideoFrameContainer) {
|
|
|
|
mVideoFrameContainer->ForgetElement();
|
|
|
|
}
|
2014-06-19 06:09:35 +04:00
|
|
|
UnregisterActivityObserver();
|
2017-11-15 07:32:50 +03:00
|
|
|
|
|
|
|
mSetCDMRequest.DisconnectIfExists();
|
2018-06-22 01:14:33 +03:00
|
|
|
mAutoplayPermissionRequest.DisconnectIfExists();
|
2008-10-19 11:39:21 +04:00
|
|
|
if (mDecoder) {
|
2012-04-30 07:13:09 +04:00
|
|
|
ShutdownDecoder();
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2014-11-28 02:17:18 +03:00
|
|
|
if (mProgressTimer) {
|
|
|
|
StopProgress();
|
|
|
|
}
|
2016-08-08 05:14:39 +03:00
|
|
|
if (mVideoDecodeSuspendTimer) {
|
|
|
|
mVideoDecodeSuspendTimer->Cancel();
|
|
|
|
mVideoDecodeSuspendTimer = nullptr;
|
|
|
|
}
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
|
|
|
EndSrcMediaStreamPlayback();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2012-01-11 02:58:43 +04:00
|
|
|
|
2015-07-24 15:28:17 +03:00
|
|
|
if (mCaptureStreamPort) {
|
|
|
|
mCaptureStreamPort->Destroy();
|
|
|
|
mCaptureStreamPort = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-11 02:58:43 +04:00
|
|
|
NS_ASSERTION(MediaElementTableCount(this, mLoadingSrc) == 0,
|
2018-05-14 12:11:18 +03:00
|
|
|
"Destroyed media element should no longer be in element table");
|
2012-01-11 02:58:43 +04:00
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
if (mChannelLoader) {
|
|
|
|
mChannelLoader->Cancel();
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
2013-05-28 21:30:17 +04:00
|
|
|
|
2016-12-04 06:02:10 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
|
|
|
mAudioChannelWrapper->Shutdown();
|
|
|
|
mAudioChannelWrapper = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:30:17 +04:00
|
|
|
WakeLockRelease();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
|
|
|
|
DecoderDoctorLogger::LogDestruction(this);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::StopSuspendingAfterFirstFrame() {
|
2011-09-30 03:34:37 +04:00
|
|
|
mAllowSuspendAfterFirstFrame = false;
|
2009-05-18 06:00:44 +04:00
|
|
|
if (!mSuspendedAfterFirstFrame) return;
|
2011-09-30 03:34:37 +04:00
|
|
|
mSuspendedAfterFirstFrame = false;
|
2009-05-18 06:00:44 +04:00
|
|
|
if (mDecoder) {
|
2016-01-12 03:04:32 +03:00
|
|
|
mDecoder->Resume();
|
2009-05-18 06:00:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SetPlayedOrSeeked(bool aValue) {
|
2011-11-16 11:50:19 +04:00
|
|
|
if (aValue == mHasPlayedOrSeeked) {
|
2009-06-26 11:25:17 +04:00
|
|
|
return;
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
2009-06-26 11:25:17 +04:00
|
|
|
|
|
|
|
mHasPlayedOrSeeked = aValue;
|
|
|
|
|
|
|
|
// Force a reflow so that the poster frame hides or shows immediately.
|
2009-12-25 00:20:05 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2011-11-16 11:50:19 +04:00
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
frame->PresShell()->FrameNeedsReflow(frame, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2009-06-26 11:25:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-27 05:26:21 +03:00
|
|
|
void HTMLMediaElement::NotifyXPCOMShutdown() { ShutdownDecoder(); }
|
|
|
|
|
2018-06-22 01:14:33 +03:00
|
|
|
bool HTMLMediaElement::AudioChannelAgentDelayingPlayback() {
|
|
|
|
return mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked();
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:50:54 +03:00
|
|
|
void HTMLMediaElement::UpdateHadAudibleAutoplayState() {
|
2018-07-18 06:34:04 +03:00
|
|
|
// If we're audible, and autoplaying...
|
|
|
|
if ((Volume() > 0.0 && !Muted()) &&
|
|
|
|
(!OwnerDoc()->HasBeenUserGestureActivated() || Autoplay())) {
|
|
|
|
OwnerDoc()->SetDocTreeHadAudibleMedia();
|
|
|
|
if (AutoplayPolicy::WouldBeAllowedToPlayIfAutoplayDisabled(*this)) {
|
|
|
|
ScalarAdd(Telemetry::ScalarID::MEDIA_AUTOPLAY_WOULD_BE_ALLOWED_COUNT, 1);
|
2018-08-23 01:54:05 +03:00
|
|
|
if (mReadyState >= HAVE_METADATA && !HasAudio()) {
|
|
|
|
ScalarAdd(
|
|
|
|
Telemetry::ScalarID::MEDIA_ALLOWED_AUTOPLAY_NO_AUDIO_TRACK_COUNT,
|
|
|
|
1);
|
|
|
|
}
|
2018-07-18 06:34:04 +03:00
|
|
|
} else {
|
2018-08-23 01:50:54 +03:00
|
|
|
if (mReadyState < HAVE_METADATA) {
|
|
|
|
mBlockedAsWithoutMetadata = true;
|
|
|
|
ScalarAdd(Telemetry::ScalarID::MEDIA_BLOCKED_NO_METADATA, 1);
|
|
|
|
}
|
2018-07-18 06:34:04 +03:00
|
|
|
ScalarAdd(Telemetry::ScalarID::MEDIA_AUTOPLAY_WOULD_NOT_BE_ALLOWED_COUNT,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::Play(ErrorResult& aRv) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Play() called by JS readyState=%d", this, mReadyState));
|
2018-02-15 06:39:44 +03:00
|
|
|
|
2018-06-22 01:14:33 +03:00
|
|
|
// 4.8.12.8
|
|
|
|
// When the play() method on a media element is invoked, the user agent must
|
|
|
|
// run the following steps.
|
2016-08-08 09:52:00 +03:00
|
|
|
|
2018-04-13 11:28:39 +03:00
|
|
|
RefPtr<PlayPromise> promise = CreatePlayPromise(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
// 4.8.12.8 - Step 1:
|
|
|
|
// If the media element is not allowed to play, return a promise rejected
|
|
|
|
// with a "NotAllowedError" DOMException and abort these steps.
|
2018-06-22 01:14:33 +03:00
|
|
|
// NOTE: we may require requesting permission from the user, so we do the
|
|
|
|
// "not allowed" check below.
|
2016-11-30 11:01:36 +03:00
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
// 4.8.12.8 - Step 2:
|
|
|
|
// If the media element's error attribute is not null and its code
|
|
|
|
// attribute has the value MEDIA_ERR_SRC_NOT_SUPPORTED, return a promise
|
|
|
|
// rejected with a "NotSupportedError" DOMException and abort these steps.
|
|
|
|
if (GetError() && GetError()->Code() == MEDIA_ERR_SRC_NOT_SUPPORTED) {
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Play() promise rejected because source not supported.", this));
|
2018-04-13 11:28:39 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR);
|
|
|
|
return promise.forget();
|
2016-12-01 09:54:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4.8.12.8 - Step 3:
|
|
|
|
// Let promise be a new promise and append promise to the list of pending
|
|
|
|
// play promises.
|
2018-06-22 01:14:33 +03:00
|
|
|
// Note: Promise appended to list of pending promises as needed below.
|
|
|
|
|
|
|
|
if (AudioChannelAgentDelayingPlayback()) {
|
|
|
|
// The audio channel agent may delay starting playback of a media resource
|
|
|
|
// until the tab the media element is in has been in the foreground.
|
|
|
|
// Save a reference to the promise, and return it. The AudioChannelAgent
|
|
|
|
// will call Play() again if the tab is brought to the foreground, or the
|
|
|
|
// audio tab indicator is clicked, which will resolve the promise if we end
|
|
|
|
// up playing.
|
|
|
|
LOG(LogLevel::Debug, ("%p Play() call delayed by AudioChannelAgent", this));
|
|
|
|
MaybeDoLoad();
|
|
|
|
mPendingPlayPromises.AppendElement(promise);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:16:13 +03:00
|
|
|
if (AudioChannelAgentBlockedPlay()) {
|
|
|
|
LOG(LogLevel::Debug, ("%p play blocked by AudioChannelAgent.", this));
|
2018-06-22 01:14:33 +03:00
|
|
|
promise->MaybeReject(NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
|
2018-08-29 01:03:15 +03:00
|
|
|
DispatchEventsWhenPlayWasNotAllowed();
|
2018-06-22 01:14:33 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2018-07-25 19:08:44 +03:00
|
|
|
UpdateHadAudibleAutoplayState();
|
2018-07-18 06:34:04 +03:00
|
|
|
|
2018-06-26 05:16:13 +03:00
|
|
|
const bool handlingUserInput = EventStateManager::IsHandlingUserInput();
|
2018-07-23 18:43:08 +03:00
|
|
|
if (AutoplayPolicy::IsAllowedToPlay(*this)) {
|
|
|
|
mPendingPlayPromises.AppendElement(promise);
|
|
|
|
PlayInternal(handlingUserInput);
|
|
|
|
UpdateCustomPolicyAfterPlayed();
|
|
|
|
} else {
|
|
|
|
// Prompt the user for permission to play.
|
|
|
|
mPendingPlayPromises.AppendElement(promise);
|
|
|
|
EnsureAutoplayRequested(handlingUserInput);
|
2018-06-26 05:16:13 +03:00
|
|
|
}
|
2018-06-22 01:14:33 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
2016-12-01 09:54:33 +03:00
|
|
|
|
2018-06-22 01:14:33 +03:00
|
|
|
void HTMLMediaElement::EnsureAutoplayRequested(bool aHandlingUserInput) {
|
|
|
|
if (mAutoplayPermissionRequest.Exists()) {
|
|
|
|
// Autoplay has already been requested in a previous play() call.
|
|
|
|
// Await for the previous request to be approved or denied. This
|
|
|
|
// play request's promise will be fulfilled with all other pending
|
|
|
|
// promises when the permission prompt is resolved.
|
2018-08-02 03:50:19 +03:00
|
|
|
AUTOPLAY_LOG("%p EnsureAutoplayRequested() existing request, bailing.",
|
|
|
|
this);
|
2018-06-22 01:14:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 12:15:20 +03:00
|
|
|
RefPtr<AutoplayPermissionManager> request =
|
|
|
|
AutoplayPolicy::RequestFor(*OwnerDoc());
|
2018-06-22 01:14:33 +03:00
|
|
|
if (!request) {
|
|
|
|
AsyncRejectPendingPlayPromises(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefPtr<HTMLMediaElement> self = this;
|
|
|
|
request->RequestWithPrompt()
|
|
|
|
->Then(mAbstractMainThread, __func__,
|
|
|
|
[self, handlingUserInput = aHandlingUserInput,
|
|
|
|
request](bool aApproved) {
|
|
|
|
self->mAutoplayPermissionRequest.Complete();
|
2018-08-02 03:50:19 +03:00
|
|
|
AUTOPLAY_LOG("%p Autoplay request approved request=%p",
|
|
|
|
self.get(), request.get());
|
2018-06-22 01:14:33 +03:00
|
|
|
self->PlayInternal(handlingUserInput);
|
|
|
|
self->UpdateCustomPolicyAfterPlayed();
|
|
|
|
},
|
|
|
|
[self, request](nsresult aError) {
|
|
|
|
self->mAutoplayPermissionRequest.Complete();
|
2018-08-02 03:50:19 +03:00
|
|
|
AUTOPLAY_LOG("%p Autoplay request denied request=%p", self.get(),
|
|
|
|
request.get());
|
2018-08-29 19:51:24 +03:00
|
|
|
LOG(LogLevel::Debug, ("%s rejecting play promises", __func__));
|
2018-06-22 01:14:33 +03:00
|
|
|
self->AsyncRejectPendingPlayPromises(
|
|
|
|
NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
|
2018-08-29 19:51:24 +03:00
|
|
|
nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"),
|
|
|
|
self->OwnerDoc(), nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"BlockAutoplayError");
|
2018-06-22 01:14:33 +03:00
|
|
|
})
|
|
|
|
->Track(mAutoplayPermissionRequest);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-29 01:03:15 +03:00
|
|
|
void HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed() {
|
|
|
|
if (StaticPrefs::MediaBlockEventEnabled()) {
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("blocked"));
|
|
|
|
}
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
|
|
|
|
this, NS_LITERAL_STRING("MozAutoplayMediaBlocked"), CanBubble::eYes,
|
|
|
|
ChromeOnlyDispatch::eYes);
|
|
|
|
asyncDispatcher->PostDOMEvent();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-06-22 01:14:33 +03:00
|
|
|
void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
|
2017-04-10 10:23:11 +03:00
|
|
|
if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE) {
|
|
|
|
// The media load algorithm will be initiated by a user interaction.
|
|
|
|
// We want to boost the channel priority for better responsiveness.
|
|
|
|
// Note this must be done before UpdatePreloadAction() which will
|
|
|
|
// update |mPreloadAction|.
|
|
|
|
mUseUrgentStartForChannel = true;
|
|
|
|
}
|
|
|
|
|
2009-05-18 06:00:44 +04:00
|
|
|
StopSuspendingAfterFirstFrame();
|
2011-09-30 03:34:37 +04:00
|
|
|
SetPlayedOrSeeked(true);
|
2009-05-18 06:00:44 +04:00
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
// 4.8.12.8 - Step 4:
|
|
|
|
// If the media element's networkState attribute has the value NETWORK_EMPTY,
|
|
|
|
// invoke the media element's resource selection algorithm.
|
2016-11-02 09:22:35 +03:00
|
|
|
MaybeDoLoad();
|
2012-05-28 02:40:06 +04:00
|
|
|
if (mSuspendedForPreloadNone) {
|
2010-08-20 02:50:37 +04:00
|
|
|
ResumeLoad(PRELOAD_ENOUGH);
|
2011-11-25 06:06:22 +04:00
|
|
|
}
|
2015-07-09 02:10:16 +03:00
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
// 4.8.12.8 - Step 5:
|
|
|
|
// If the playback has ended and the direction of playback is forwards,
|
|
|
|
// seek to the earliest possible position of the media resource.
|
|
|
|
|
2011-11-25 06:06:22 +04:00
|
|
|
// Even if we just did Load() or ResumeLoad(), we could already have a decoder
|
|
|
|
// here if we managed to clone an existing decoder.
|
|
|
|
if (mDecoder) {
|
2016-08-01 10:22:32 +03:00
|
|
|
if (mDecoder->IsEnded()) {
|
2009-02-11 04:23:19 +03:00
|
|
|
SetCurrentTime(0);
|
|
|
|
}
|
2012-12-12 05:58:07 +04:00
|
|
|
if (!mPausedForInactiveDocumentOrChannel) {
|
2018-05-28 23:09:26 +03:00
|
|
|
mDecoder->Play();
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
2008-10-21 13:19:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-01 04:29:24 +04:00
|
|
|
if (mCurrentPlayRangeStart == -1.0) {
|
2013-03-19 16:25:19 +04:00
|
|
|
mCurrentPlayRangeStart = CurrentTime();
|
2012-05-01 04:29:24 +04:00
|
|
|
}
|
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
const bool oldPaused = mPaused;
|
2016-08-29 11:34:28 +03:00
|
|
|
mPaused = false;
|
|
|
|
mAutoplaying = false;
|
|
|
|
|
|
|
|
// We changed mPaused and mAutoplaying which can affect AddRemoveSelfReference
|
|
|
|
// and our preload status.
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
UpdatePreloadAction();
|
|
|
|
UpdateSrcMediaStreamPlaying();
|
|
|
|
|
2018-04-20 08:53:37 +03:00
|
|
|
// Once play() has been called in a user generated event handler,
|
|
|
|
// it is allowed to autoplay. Note: we can reach here when not in
|
|
|
|
// a user generated event handler if our readyState has not yet
|
|
|
|
// reached HAVE_METADATA.
|
2018-06-22 01:14:33 +03:00
|
|
|
mIsBlessed |= aHandlingUserInput;
|
2018-04-20 08:53:37 +03:00
|
|
|
|
2009-11-06 10:32:52 +03:00
|
|
|
// TODO: If the playback has ended, then the user agent must set
|
2009-03-08 23:59:08 +03:00
|
|
|
// seek to the effective start.
|
2016-12-01 09:54:33 +03:00
|
|
|
|
|
|
|
// 4.8.12.8 - Step 6:
|
|
|
|
// If the media element's paused attribute is true, run the following steps:
|
2016-08-29 11:34:28 +03:00
|
|
|
if (oldPaused) {
|
2016-12-01 09:54:33 +03:00
|
|
|
// 6.1. Change the value of paused to false. (Already done.)
|
|
|
|
// This step is uplifted because the "block-media-playback" feature needs
|
|
|
|
// the mPaused to be false before UpdateAudioChannelPlayingState() being
|
|
|
|
// called.
|
|
|
|
|
|
|
|
// 6.2. If the show poster flag is true, set the element's show poster flag
|
|
|
|
// to false and run the time marches on steps.
|
|
|
|
|
|
|
|
// 6.3. Queue a task to fire a simple event named play at the element.
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
|
2016-12-01 09:54:33 +03:00
|
|
|
|
|
|
|
// 6.4. If the media element's readyState attribute has the value
|
|
|
|
// HAVE_NOTHING, HAVE_METADATA, or HAVE_CURRENT_DATA, queue a task to
|
|
|
|
// fire a simple event named waiting at the element.
|
|
|
|
// Otherwise, the media element's readyState attribute has the value
|
|
|
|
// HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA: notify about playing for the
|
|
|
|
// element.
|
2009-02-11 04:23:19 +03:00
|
|
|
switch (mReadyState) {
|
2018-05-14 12:11:18 +03:00
|
|
|
case HAVE_NOTHING:
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
|
|
|
break;
|
|
|
|
case HAVE_METADATA:
|
|
|
|
case HAVE_CURRENT_DATA:
|
|
|
|
FireTimeUpdate(false);
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
|
|
|
break;
|
|
|
|
case HAVE_FUTURE_DATA:
|
|
|
|
case HAVE_ENOUGH_DATA:
|
|
|
|
FireTimeUpdate(false);
|
2018-05-16 08:27:01 +03:00
|
|
|
NotifyAboutPlaying();
|
2018-05-14 12:11:18 +03:00
|
|
|
break;
|
2009-02-11 04:23:19 +03:00
|
|
|
}
|
2018-05-28 23:09:26 +03:00
|
|
|
} else if (mReadyState >= HAVE_FUTURE_DATA) {
|
2016-12-01 09:54:33 +03:00
|
|
|
// 7. Otherwise, if the media element's readyState attribute has the value
|
|
|
|
// HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, take pending play promises and
|
|
|
|
// queue a task to resolve pending play promises with the result.
|
|
|
|
AsyncResolvePendingPlayPromises();
|
2009-02-11 04:23:19 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-12-01 09:54:33 +03:00
|
|
|
// 8. Set the media element's autoplaying flag to false. (Already done.)
|
|
|
|
|
|
|
|
// 9. Return promise.
|
2018-06-22 01:14:33 +03:00
|
|
|
// (Done in caller.)
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-11-02 09:22:35 +03:00
|
|
|
void HTMLMediaElement::MaybeDoLoad() {
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState == NETWORK_EMPTY) {
|
2016-11-02 09:22:35 +03:00
|
|
|
DoLoad();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 05:19:47 +03:00
|
|
|
void HTMLMediaElement::UpdateWakeLock() {
|
2017-07-07 05:36:13 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-05-21 05:19:47 +03:00
|
|
|
// Ensure we have a wake lock if we're playing audibly. This ensures the
|
|
|
|
// device doesn't sleep while playing.
|
|
|
|
bool playing = !mPaused;
|
|
|
|
bool isAudible = Volume() > 0.0 && !mMuted && mIsAudioTrackAudible;
|
|
|
|
// WakeLock when playing audible media.
|
2017-08-29 10:25:44 +03:00
|
|
|
if (playing && isAudible) {
|
2018-10-02 20:56:21 +03:00
|
|
|
CreateAudioWakeLockIfNeeded();
|
2017-08-29 05:54:25 +03:00
|
|
|
} else {
|
2018-10-02 20:56:21 +03:00
|
|
|
ReleaseAudioWakeLockIfExists();
|
2013-05-10 16:42:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:56:21 +03:00
|
|
|
void HTMLMediaElement::CreateAudioWakeLockIfNeeded() {
|
2013-05-10 16:42:39 +04:00
|
|
|
if (!mWakeLock) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<power::PowerManagerService> pmService =
|
2014-01-07 16:16:07 +04:00
|
|
|
power::PowerManagerService::GetInstance();
|
2013-05-02 20:45:35 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(pmService);
|
2012-11-01 16:47:51 +04:00
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
ErrorResult rv;
|
2018-10-02 20:56:21 +03:00
|
|
|
mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("audio-playing"),
|
|
|
|
OwnerDoc()->GetInnerWindow(), rv);
|
2013-05-10 16:42:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:56:21 +03:00
|
|
|
void HTMLMediaElement::ReleaseAudioWakeLockIfExists() {
|
2013-05-10 16:42:39 +04:00
|
|
|
if (mWakeLock) {
|
2014-01-07 16:16:07 +04:00
|
|
|
ErrorResult rv;
|
|
|
|
mWakeLock->Unlock(rv);
|
2015-11-21 00:29:41 +03:00
|
|
|
rv.SuppressException();
|
2013-04-03 05:14:24 +04:00
|
|
|
mWakeLock = nullptr;
|
2012-11-01 16:47:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:56:21 +03:00
|
|
|
void HTMLMediaElement::WakeLockRelease() { ReleaseAudioWakeLockIfExists(); }
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
HTMLMediaElement::OutputMediaStream::OutputMediaStream()
|
2018-05-29 11:21:51 +03:00
|
|
|
: mNextAvailableTrackID(1),
|
|
|
|
mFinishWhenEnded(false),
|
2016-08-23 18:51:50 +03:00
|
|
|
mCapturingAudioOnly(false),
|
|
|
|
mCapturingDecoder(false),
|
|
|
|
mCapturingMediaStream(false) {}
|
|
|
|
|
|
|
|
HTMLMediaElement::OutputMediaStream::~OutputMediaStream() {
|
|
|
|
for (auto pair : mTrackPorts) {
|
|
|
|
pair.second()->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 06:07:12 +03:00
|
|
|
void HTMLMediaElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
|
|
|
if (!this->Controls() || !aVisitor.mEvent->mFlags.mIsTrusted) {
|
2018-04-05 20:42:41 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
|
|
|
return;
|
2017-11-17 06:07:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HTMLInputElement* el = nullptr;
|
|
|
|
nsCOMPtr<nsINode> node;
|
|
|
|
|
|
|
|
// We will need to trap pointer, touch, and mouse events within the media
|
|
|
|
// element, allowing media control exclusive consumption on these events,
|
|
|
|
// and preventing the content from handling them.
|
|
|
|
switch (aVisitor.mEvent->mMessage) {
|
|
|
|
case ePointerDown:
|
|
|
|
case ePointerUp:
|
|
|
|
case eTouchEnd:
|
2018-05-14 12:11:18 +03:00
|
|
|
// Always prevent touchmove captured in video element from being handled by
|
|
|
|
// content, since we always do that for touchstart.
|
2017-11-17 06:07:12 +03:00
|
|
|
case eTouchMove:
|
|
|
|
case eTouchStart:
|
|
|
|
case eMouseClick:
|
|
|
|
case eMouseDoubleClick:
|
|
|
|
case eMouseDown:
|
|
|
|
case eMouseUp:
|
|
|
|
aVisitor.mCanHandle = false;
|
2018-04-05 20:42:41 +03:00
|
|
|
return;
|
2017-11-17 06:07:12 +03:00
|
|
|
|
|
|
|
// The *move events however are only comsumed when the range input is being
|
|
|
|
// dragged.
|
|
|
|
case ePointerMove:
|
|
|
|
case eMouseMove:
|
|
|
|
node = do_QueryInterface(aVisitor.mEvent->mOriginalTarget);
|
2018-07-12 07:32:44 +03:00
|
|
|
if (node->IsInNativeAnonymousSubtree() || node->IsInUAWidget()) {
|
2017-11-17 06:07:12 +03:00
|
|
|
if (node->IsHTMLElement(nsGkAtoms::input)) {
|
|
|
|
// The node is a <input type="range">
|
|
|
|
el = static_cast<HTMLInputElement*>(node.get());
|
|
|
|
} else if (node->GetParentNode() &&
|
|
|
|
node->GetParentNode()->IsHTMLElement(nsGkAtoms::input)) {
|
|
|
|
// The node is a child of <input type="range">
|
|
|
|
el = static_cast<HTMLInputElement*>(node->GetParentNode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (el && el->IsDraggingRange()) {
|
|
|
|
aVisitor.mCanHandle = false;
|
2018-04-05 20:42:41 +03:00
|
|
|
return;
|
2017-11-17 06:07:12 +03:00
|
|
|
}
|
2018-04-05 20:42:41 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
|
|
|
return;
|
2017-11-17 06:07:12 +03:00
|
|
|
|
|
|
|
default:
|
2018-04-05 20:42:41 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
|
|
|
return;
|
2017-11-17 06:07:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
nsAttrValue& aResult) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// Mappings from 'preload' attribute strings to an enumeration.
|
|
|
|
static const nsAttrValue::EnumTable kPreloadTable[] = {
|
2018-05-14 12:11:18 +03:00
|
|
|
{"", HTMLMediaElement::PRELOAD_ATTR_EMPTY},
|
|
|
|
{"none", HTMLMediaElement::PRELOAD_ATTR_NONE},
|
2013-03-19 16:23:54 +04:00
|
|
|
{"metadata", HTMLMediaElement::PRELOAD_ATTR_METADATA},
|
2018-05-14 12:11:18 +03:00
|
|
|
{"auto", HTMLMediaElement::PRELOAD_ATTR_AUTO},
|
|
|
|
{nullptr, 0}};
|
2010-08-20 02:50:37 +04:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2011-11-16 11:50:19 +04:00
|
|
|
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
2011-09-30 03:34:37 +04:00
|
|
|
return true;
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2012-01-26 02:31:30 +04:00
|
|
|
if (aAttribute == nsGkAtoms::crossorigin) {
|
2012-03-10 20:13:51 +04:00
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
2012-01-26 02:31:30 +04:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
if (aAttribute == nsGkAtoms::preload) {
|
2011-09-30 03:34:37 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kPreloadTable, false);
|
2010-08-20 02:50:37 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DoneCreatingElement() {
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::muted)) {
|
|
|
|
mMuted |= MUTED_BY_CONTENT;
|
|
|
|
}
|
2011-12-15 23:36:46 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
|
|
|
int32_t* aTabIndex) {
|
|
|
|
if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable,
|
|
|
|
aTabIndex)) {
|
2013-02-12 08:56:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aIsFocusable = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
int32_t HTMLMediaElement::TabIndexDefault() { return 0; }
|
2013-02-12 08:56:03 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) {
|
2017-06-07 20:28:20 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::src) {
|
|
|
|
mSrcMediaSource = nullptr;
|
2017-10-06 00:47:09 +03:00
|
|
|
mSrcAttrTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
2018-05-14 12:11:18 +03:00
|
|
|
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
|
|
|
aMaybeScriptedPrincipal);
|
2017-06-07 20:28:20 +03:00
|
|
|
if (aValue) {
|
|
|
|
nsString srcStr = aValue->GetStringValue();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NewURIFromString(srcStr, getter_AddRefs(uri));
|
|
|
|
if (uri && IsMediaSourceURI(uri)) {
|
|
|
|
nsresult rv = NS_GetSourceForMediaSourceURI(
|
|
|
|
uri, getter_AddRefs(mSrcMediaSource));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsAutoString spec;
|
|
|
|
GetCurrentSrc(spec);
|
|
|
|
const char16_t* params[] = {spec.get()};
|
|
|
|
ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::autoplay) {
|
|
|
|
if (aNotify) {
|
|
|
|
if (aValue) {
|
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
CheckAutoplayDataReady();
|
|
|
|
}
|
|
|
|
// This attribute can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
UpdatePreloadAction();
|
|
|
|
}
|
2010-08-20 02:50:37 +04:00
|
|
|
} else if (aName == nsGkAtoms::preload) {
|
|
|
|
UpdatePreloadAction();
|
2017-06-08 07:03:10 +03:00
|
|
|
} else if (aName == nsGkAtoms::loop) {
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->SetLooping(!!aValue);
|
|
|
|
}
|
2018-06-27 21:12:38 +03:00
|
|
|
} else if (nsContentUtils::IsUAWidgetEnabled() &&
|
|
|
|
aName == nsGkAtoms::controls && IsInComposedDoc()) {
|
2018-12-15 05:48:46 +03:00
|
|
|
NotifyUAWidgetSetupOrChange();
|
2009-05-18 06:00:44 +04:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 20:28:20 +03:00
|
|
|
// Since AfterMaybeChangeAttr may call DoLoad, make sure that it is called
|
|
|
|
// *after* any possible changes to mSrcMediaSource.
|
|
|
|
if (aValue) {
|
|
|
|
AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(
|
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::OnAttrSetButNotChanged(
|
2017-06-07 20:28:20 +03:00
|
|
|
int32_t aNamespaceID, nsAtom* aName, const nsAttrValueOrString& aValue,
|
|
|
|
bool aNotify) {
|
|
|
|
AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
bool aNotify) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::src) {
|
|
|
|
DoLoad();
|
2015-05-26 13:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult rv =
|
2018-07-31 21:18:38 +03:00
|
|
|
nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent);
|
2016-09-23 09:51:52 +03:00
|
|
|
|
2018-06-27 21:12:38 +03:00
|
|
|
if (nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
|
|
|
|
// Construct Shadow Root so web content can be hidden in the DOM.
|
|
|
|
AttachAndSetUAShadowRoot();
|
|
|
|
#ifdef ANDROID
|
2018-12-15 05:48:46 +03:00
|
|
|
NotifyUAWidgetSetupOrChange();
|
2018-06-27 21:12:38 +03:00
|
|
|
#else
|
|
|
|
// We don't want to call into JS if the website never asks for native
|
|
|
|
// video controls.
|
|
|
|
// If controls attribute is set later, controls is constructed lazily
|
|
|
|
// with the UAWidgetAttributeChanged event.
|
|
|
|
// This only applies to Desktop because on Fennec we would need to show
|
|
|
|
// an UI if the video is blocked.
|
|
|
|
if (Controls()) {
|
2018-12-15 05:48:46 +03:00
|
|
|
NotifyUAWidgetSetupOrChange();
|
2018-06-27 21:12:38 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-23 09:51:52 +03:00
|
|
|
mUnboundFromTree = false;
|
|
|
|
|
2010-02-24 22:14:14 +03:00
|
|
|
if (aDocument) {
|
2010-08-20 02:50:37 +04:00
|
|
|
// The preload action depends on the value of the autoplay attribute.
|
|
|
|
// It's value may have changed, so update it.
|
|
|
|
UpdatePreloadAction();
|
2010-02-24 22:14:14 +03:00
|
|
|
}
|
2015-01-22 07:01:12 +03:00
|
|
|
|
2017-03-11 13:25:41 +03:00
|
|
|
NotifyDecoderActivityChanges();
|
2009-02-16 04:05:28 +03:00
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
/* static */
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::VideoDecodeSuspendTimerCallback(nsITimer* aTimer,
|
|
|
|
void* aClosure) {
|
2016-08-08 05:14:39 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto element = static_cast<HTMLMediaElement*>(aClosure);
|
|
|
|
element->mVideoDecodeSuspendTime.Start();
|
|
|
|
element->mVideoDecodeSuspendTimer = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::HiddenVideoStart() {
|
2016-08-08 05:14:39 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mHiddenPlayTime.Start();
|
|
|
|
if (mVideoDecodeSuspendTimer) {
|
|
|
|
// Already started, just keep it running.
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_NewTimerWithFuncCallback(
|
|
|
|
getter_AddRefs(mVideoDecodeSuspendTimer), VideoDecodeSuspendTimerCallback,
|
|
|
|
this, StaticPrefs::MediaSuspendBkgndVideoDelayMs(),
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"HTMLMediaElement::VideoDecodeSuspendTimerCallback",
|
|
|
|
mMainThreadEventTarget);
|
2016-08-08 05:14:39 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::HiddenVideoStop() {
|
2016-08-08 05:14:39 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mHiddenPlayTime.Pause();
|
|
|
|
mVideoDecodeSuspendTime.Pause();
|
|
|
|
if (!mVideoDecodeSuspendTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mVideoDecodeSuspendTimer->Cancel();
|
|
|
|
mVideoDecodeSuspendTimer = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-05 22:48:45 +03:00
|
|
|
void HTMLMediaElement::ReportTelemetry() {
|
2015-02-13 08:02:35 +03:00
|
|
|
// Report telemetry for videos when a page is unloaded. We
|
|
|
|
// want to know data on what state the video is at when
|
|
|
|
// the user has exited.
|
2018-05-14 12:11:18 +03:00
|
|
|
enum UnloadedState {
|
2015-02-13 08:02:35 +03:00
|
|
|
ENDED = 0,
|
|
|
|
PAUSED = 1,
|
|
|
|
STALLED = 2,
|
|
|
|
SEEKING = 3,
|
|
|
|
OTHER = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
UnloadedState state = OTHER;
|
|
|
|
if (Seeking()) {
|
|
|
|
state = SEEKING;
|
2018-05-14 12:11:18 +03:00
|
|
|
} else if (Ended()) {
|
2015-02-13 08:02:35 +03:00
|
|
|
state = ENDED;
|
2018-05-14 12:11:18 +03:00
|
|
|
} else if (Paused()) {
|
2015-02-13 08:02:35 +03:00
|
|
|
state = PAUSED;
|
2018-05-14 12:11:18 +03:00
|
|
|
} else {
|
2015-02-13 08:02:35 +03:00
|
|
|
// For buffering we check if the current playback position is at the end
|
|
|
|
// of a buffered range, within a margin of error. We also consider to be
|
|
|
|
// buffering if the last frame status was buffering and the ready state is
|
|
|
|
// HAVE_CURRENT_DATA to account for times where we are in a buffering state
|
|
|
|
// regardless of what actual data we have buffered.
|
|
|
|
bool stalled = false;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TimeRanges> ranges = Buffered();
|
2015-02-13 08:02:35 +03:00
|
|
|
const double errorMargin = 0.05;
|
|
|
|
double t = CurrentTime();
|
|
|
|
TimeRanges::index_type index = ranges->Find(t, errorMargin);
|
2018-05-14 12:11:18 +03:00
|
|
|
stalled =
|
|
|
|
index != TimeRanges::NoIndex && (ranges->End(index) - t) < errorMargin;
|
|
|
|
stalled |= mDecoder &&
|
|
|
|
NextFrameStatus() ==
|
|
|
|
MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING &&
|
2018-02-15 06:23:32 +03:00
|
|
|
mReadyState == HAVE_CURRENT_DATA;
|
2015-02-13 08:02:35 +03:00
|
|
|
if (stalled) {
|
|
|
|
state = STALLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 01:08:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_UNLOAD_STATE, state);
|
|
|
|
LOG(LogLevel::Debug, ("%p VIDEO_UNLOAD_STATE = %d", this, state));
|
|
|
|
|
2016-07-27 08:43:01 +03:00
|
|
|
FrameStatisticsData data;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
if (HTMLVideoElement* vid = HTMLVideoElement::FromNodeOrNull(this)) {
|
2016-07-26 04:32:58 +03:00
|
|
|
FrameStatistics* stats = vid->GetFrameStatistics();
|
|
|
|
if (stats) {
|
2016-07-27 08:43:01 +03:00
|
|
|
data = stats->GetFrameStatisticsData();
|
2016-07-26 04:32:58 +03:00
|
|
|
if (data.mParsedFrames) {
|
|
|
|
MOZ_ASSERT(data.mDroppedFrames <= data.mParsedFrames);
|
|
|
|
// Dropped frames <= total frames, so 'percentage' cannot be higher than
|
|
|
|
// 100 and therefore can fit in a uint32_t (that Telemetry takes).
|
|
|
|
uint32_t percentage = 100 * data.mDroppedFrames / data.mParsedFrames;
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("Reporting telemetry DROPPED_FRAMES_IN_VIDEO_PLAYBACK"));
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_DROPPED_FRAMES_PROPORTION,
|
|
|
|
percentage);
|
|
|
|
}
|
2016-02-18 05:22:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mMediaInfo.HasVideo() && mMediaInfo.mVideo.mImage.height > 0) {
|
2016-07-27 09:26:45 +03:00
|
|
|
// We have a valid video.
|
|
|
|
double playTime = mPlayTime.Total();
|
|
|
|
double hiddenPlayTime = mHiddenPlayTime.Total();
|
2016-08-08 05:14:39 +03:00
|
|
|
double videoDecodeSuspendTime = mVideoDecodeSuspendTime.Total();
|
2016-07-27 09:26:45 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_PLAY_TIME_MS,
|
|
|
|
SECONDS_TO_MS(playTime));
|
2016-07-27 09:26:45 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p VIDEO_PLAY_TIME_MS = %f", this, playTime));
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_MS,
|
|
|
|
SECONDS_TO_MS(hiddenPlayTime));
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_HIDDEN_PLAY_TIME_MS = %f", this, hiddenPlayTime));
|
2016-07-27 09:26:45 +03:00
|
|
|
|
|
|
|
if (playTime > 0.0) {
|
2016-08-08 05:14:39 +03:00
|
|
|
// We have actually played something -> Report some valid-video telemetry.
|
2016-07-27 09:26:45 +03:00
|
|
|
|
|
|
|
// Keyed by audio+video or video alone, and by a resolution range.
|
|
|
|
nsCString key(mMediaInfo.HasAudio() ? "AV," : "V,");
|
2018-05-14 12:11:18 +03:00
|
|
|
static const struct {
|
|
|
|
int32_t mH;
|
|
|
|
const char* mRes;
|
|
|
|
} sResolutions[] = {{240, "0<h<=240"}, {480, "240<h<=480"},
|
|
|
|
{576, "480<h<=576"}, {720, "576<h<=720"},
|
|
|
|
{1080, "720<h<=1080"}, {2160, "1080<h<=2160"}};
|
2016-07-27 09:26:45 +03:00
|
|
|
const char* resolution = "h>2160";
|
|
|
|
int32_t height = mMediaInfo.mVideo.mImage.height;
|
|
|
|
for (const auto& res : sResolutions) {
|
|
|
|
if (height <= res.mH) {
|
|
|
|
resolution = res.mRes;
|
|
|
|
break;
|
|
|
|
}
|
2016-07-19 10:47:45 +03:00
|
|
|
}
|
2016-07-27 09:26:45 +03:00
|
|
|
key.AppendASCII(resolution);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
uint32_t hiddenPercentage =
|
|
|
|
uint32_t(hiddenPlayTime / playTime * 100.0 + 0.5);
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE, key,
|
|
|
|
hiddenPercentage);
|
2016-07-27 09:26:45 +03:00
|
|
|
// Also accumulate all percentages in an "All" key.
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE,
|
|
|
|
NS_LITERAL_CSTRING("All"), hiddenPercentage);
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE = %u, keys: '%s' and 'All'",
|
|
|
|
this, hiddenPercentage, key.get()));
|
2016-07-27 08:43:01 +03:00
|
|
|
|
2016-08-08 05:14:39 +03:00
|
|
|
uint32_t videoDecodeSuspendPercentage =
|
|
|
|
uint32_t(videoDecodeSuspendTime / playTime * 100.0 + 0.5);
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE,
|
|
|
|
key, videoDecodeSuspendPercentage);
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE,
|
|
|
|
NS_LITERAL_CSTRING("All"),
|
|
|
|
videoDecodeSuspendPercentage);
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE = %u, keys: '%s' and "
|
|
|
|
"'All'",
|
|
|
|
this, videoDecodeSuspendPercentage, key.get()));
|
2016-08-08 05:14:39 +03:00
|
|
|
|
2016-07-27 08:43:01 +03:00
|
|
|
if (data.mInterKeyframeCount != 0) {
|
2018-05-14 12:11:18 +03:00
|
|
|
uint32_t average_ms = uint32_t(std::min<uint64_t>(
|
|
|
|
double(data.mInterKeyframeSum_us) /
|
|
|
|
double(data.mInterKeyframeCount) / 1000.0 +
|
|
|
|
0.5,
|
|
|
|
UINT32_MAX));
|
2016-07-27 08:43:01 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_AVERAGE_MS, key,
|
|
|
|
average_ms);
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_AVERAGE_MS,
|
2016-08-08 05:14:39 +03:00
|
|
|
NS_LITERAL_CSTRING("All"), average_ms);
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_INTER_KEYFRAME_AVERAGE_MS = %u, keys: '%s' and 'All'",
|
|
|
|
this, average_ms, key.get()));
|
|
|
|
|
|
|
|
uint32_t max_ms = uint32_t(std::min<uint64_t>(
|
|
|
|
(data.mInterKeyFrameMax_us + 500) / 1000, UINT32_MAX));
|
2016-07-27 08:43:01 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_MAX_MS, key,
|
|
|
|
max_ms);
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_MAX_MS,
|
2016-08-08 05:14:39 +03:00
|
|
|
NS_LITERAL_CSTRING("All"), max_ms);
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_INTER_KEYFRAME_MAX_MS = %u, keys: '%s' and 'All'", this,
|
|
|
|
max_ms, key.get()));
|
2016-08-18 04:54:00 +03:00
|
|
|
} else {
|
|
|
|
// Here, we have played *some* of the video, but didn't get more than 1
|
|
|
|
// keyframe. Report '0' if we have played for longer than the video-
|
|
|
|
// decode-suspend delay (showing recovery would be difficult).
|
2018-05-14 12:11:18 +03:00
|
|
|
uint32_t suspendDelay_ms = StaticPrefs::MediaSuspendBkgndVideoDelayMs();
|
2016-08-18 04:54:00 +03:00
|
|
|
if (uint32_t(playTime * 1000.0) > suspendDelay_ms) {
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_MAX_MS, key, 0);
|
2016-08-18 04:54:00 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_INTER_KEYFRAME_MAX_MS,
|
|
|
|
NS_LITERAL_CSTRING("All"), 0);
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p VIDEO_INTER_KEYFRAME_MAX_MS = 0 (only 1 keyframe), keys: "
|
|
|
|
"'%s' and 'All'",
|
|
|
|
this, key.get()));
|
2016-08-18 04:54:00 +03:00
|
|
|
}
|
2016-07-27 08:43:01 +03:00
|
|
|
}
|
2016-07-19 10:47:45 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-13 08:02:35 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2016-09-23 09:51:52 +03:00
|
|
|
mUnboundFromTree = true;
|
2017-03-16 14:26:49 +03:00
|
|
|
mVisibilityState = Visibility::UNTRACKED;
|
2016-09-23 09:51:52 +03:00
|
|
|
|
2018-12-15 05:48:46 +03:00
|
|
|
if (nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
|
|
|
|
NotifyUAWidgetTeardown();
|
2018-11-28 05:29:38 +03:00
|
|
|
}
|
|
|
|
|
2008-07-09 12:22:20 +04:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2016-01-29 02:32:51 +03:00
|
|
|
|
2017-03-11 13:25:41 +03:00
|
|
|
MOZ_ASSERT(IsHidden());
|
|
|
|
NotifyDecoderActivityChanges();
|
2016-09-23 11:16:43 +03:00
|
|
|
|
|
|
|
RefPtr<HTMLMediaElement> self(this);
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> task =
|
|
|
|
NS_NewRunnableFunction("dom::HTMLMediaElement::UnbindFromTree", [self]() {
|
|
|
|
if (self->mUnboundFromTree) {
|
|
|
|
self->Pause();
|
|
|
|
}
|
|
|
|
});
|
2016-09-23 11:16:43 +03:00
|
|
|
RunInStableState(task);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2010-06-09 03:31:27 +04:00
|
|
|
/* static */
|
2016-04-19 10:36:19 +03:00
|
|
|
CanPlayStatus HTMLMediaElement::GetCanPlay(
|
|
|
|
const nsAString& aType, DecoderDoctorDiagnostics* aDiagnostics) {
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<MediaContainerType> containerType = MakeMediaContainerType(aType);
|
|
|
|
if (!containerType) {
|
2016-12-01 04:56:11 +03:00
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
CanPlayStatus status =
|
|
|
|
DecoderTraits::CanHandleContainerType(*containerType, aDiagnostics);
|
2017-09-11 12:17:55 +03:00
|
|
|
if (status == CANPLAY_YES &&
|
|
|
|
(*containerType).ExtendedType().Codecs().IsEmpty()) {
|
|
|
|
// Per spec: 'Generally, a user agent should never return "probably" for a
|
2018-05-14 12:11:18 +03:00
|
|
|
// type that allows the `codecs` parameter if that parameter is not
|
|
|
|
// present.' As all our currently-supported types allow for `codecs`, we can
|
|
|
|
// do this check here.
|
2017-09-11 12:17:55 +03:00
|
|
|
// TODO: Instead, missing `codecs` should be checked in each decoder's
|
|
|
|
// `IsSupportedType` call from `CanHandleCodecsType()`.
|
|
|
|
// See bug 1399023.
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2017-02-15 03:37:01 +03:00
|
|
|
return status;
|
2008-12-17 05:11:07 +03:00
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
void HTMLMediaElement::CanPlayType(const nsAString& aType, nsAString& aResult) {
|
2016-04-19 10:36:19 +03:00
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
|
|
|
CanPlayStatus canPlay = GetCanPlay(aType, &diagnostics);
|
2016-04-22 06:42:11 +03:00
|
|
|
diagnostics.StoreFormatDiagnostics(OwnerDoc(), aType, canPlay != CANPLAY_NO,
|
|
|
|
__func__);
|
2016-04-19 10:36:19 +03:00
|
|
|
switch (canPlay) {
|
2018-05-14 12:11:18 +03:00
|
|
|
case CANPLAY_NO:
|
|
|
|
aResult.Truncate();
|
|
|
|
break;
|
|
|
|
case CANPLAY_YES:
|
|
|
|
aResult.AssignLiteral("probably");
|
|
|
|
break;
|
|
|
|
case CANPLAY_MAYBE:
|
|
|
|
aResult.AssignLiteral("maybe");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected case.");
|
|
|
|
break;
|
2008-12-17 05:11:07 +03:00
|
|
|
}
|
2013-02-27 00:27:43 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p CanPlayType(%s) = \"%s\"", this, NS_ConvertUTF16toUTF8(aType).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aResult).get()));
|
2008-12-17 05:11:07 +03:00
|
|
|
}
|
|
|
|
|
2017-10-12 05:46:13 +03:00
|
|
|
void HTMLMediaElement::AssertReadyStateIsNothing() {
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mReadyState != HAVE_NOTHING) {
|
2017-10-12 05:46:13 +03:00
|
|
|
char buf[1024];
|
|
|
|
SprintfLiteral(buf,
|
|
|
|
"readyState=%d networkState=%d mLoadWaitStatus=%d "
|
|
|
|
"mSourceLoadCandidate=%d "
|
|
|
|
"mIsLoadingFromSourceChildren=%d mPreloadAction=%d "
|
|
|
|
"mSuspendedForPreloadNone=%d error=%d",
|
|
|
|
int(mReadyState), int(mNetworkState), int(mLoadWaitStatus),
|
|
|
|
!!mSourceLoadCandidate, mIsLoadingFromSourceChildren,
|
|
|
|
int(mPreloadAction), mSuspendedForPreloadNone,
|
|
|
|
GetError() ? GetError()->Code() : 0);
|
|
|
|
MOZ_CRASH_UNSAFE_PRINTF("ReadyState should be HAVE_NOTHING! %s", buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-06-20 13:10:27 +03:00
|
|
|
nsresult HTMLMediaElement::InitializeDecoderAsClone(
|
|
|
|
ChannelMediaDecoder* aOriginal) {
|
2011-11-25 06:06:22 +04:00
|
|
|
NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mDecoder == nullptr, "Shouldn't have a decoder");
|
2017-10-12 05:46:13 +03:00
|
|
|
AssertReadyStateIsNothing();
|
2011-11-25 06:06:22 +04:00
|
|
|
|
2017-06-26 12:10:47 +03:00
|
|
|
MediaDecoderInit decoderInit(
|
|
|
|
this, mMuted ? 0.0 : mVolume, mPreservesPitch,
|
2018-11-07 16:56:25 +03:00
|
|
|
ClampPlaybackRate(mPlaybackRate),
|
2017-06-26 12:10:47 +03:00
|
|
|
mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, mHasSuspendTaint,
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::loop), aOriginal->ContainerType());
|
2017-06-07 09:10:26 +03:00
|
|
|
|
2017-06-20 13:10:27 +03:00
|
|
|
RefPtr<ChannelMediaDecoder> decoder = aOriginal->Clone(decoderInit);
|
2009-09-15 06:30:44 +04:00
|
|
|
if (!decoder) return NS_ERROR_FAILURE;
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Cloned decoder %p from %p", this, decoder.get(), aOriginal));
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2017-06-23 10:25:40 +03:00
|
|
|
return FinishDecoderSetup(decoder);
|
2009-09-15 06:30:44 +04:00
|
|
|
}
|
|
|
|
|
2017-07-26 10:49:03 +03:00
|
|
|
template <typename DecoderType, typename... LoadArgs>
|
|
|
|
nsresult HTMLMediaElement::SetupDecoder(DecoderType* aDecoder,
|
|
|
|
LoadArgs&&... aArgs) {
|
|
|
|
LOG(LogLevel::Debug, ("%p Created decoder %p for type %s", this, aDecoder,
|
|
|
|
aDecoder->ContainerType().OriginalString().Data()));
|
|
|
|
|
2018-06-01 19:30:30 +03:00
|
|
|
nsresult rv = aDecoder->Load(std::forward<LoadArgs>(aArgs)...);
|
2017-07-26 10:49:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aDecoder->Shutdown();
|
|
|
|
LOG(LogLevel::Debug, ("%p Failed to load for decoder %p", this, aDecoder));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = FinishDecoderSetup(aDecoder);
|
|
|
|
// Only ChannelMediaDecoder supports resource cloning.
|
|
|
|
if (IsSame<DecoderType, ChannelMediaDecoder>::value && NS_SUCCEEDED(rv)) {
|
|
|
|
AddMediaElementToURITable();
|
|
|
|
NS_ASSERTION(
|
|
|
|
MediaElementTableCount(this, mLoadingSrc) == 1,
|
|
|
|
"Media element should have single table entry if decode initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::InitializeDecoderForChannel(
|
|
|
|
nsIChannel* aChannel, nsIStreamListener** aListener) {
|
2017-05-05 10:12:51 +03:00
|
|
|
NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
|
2017-10-12 05:46:13 +03:00
|
|
|
AssertReadyStateIsNothing();
|
2011-11-25 06:06:22 +04:00
|
|
|
|
2017-06-26 12:10:47 +03:00
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
2016-07-18 18:26:25 +03:00
|
|
|
|
2017-07-26 10:49:03 +03:00
|
|
|
nsAutoCString mimeType;
|
2016-07-18 18:26:25 +03:00
|
|
|
aChannel->GetContentType(mimeType);
|
|
|
|
NS_ASSERTION(!mimeType.IsEmpty(), "We should have the Content-Type.");
|
2017-07-26 10:49:03 +03:00
|
|
|
NS_ConvertUTF8toUTF16 mimeUTF16(mimeType);
|
|
|
|
|
2018-05-03 09:37:27 +03:00
|
|
|
RefPtr<HTMLMediaElement> self = this;
|
|
|
|
auto reportCanPlay = [&, self](bool aCanPlay) {
|
2017-07-26 10:49:03 +03:00
|
|
|
diagnostics.StoreFormatDiagnostics(self->OwnerDoc(), mimeUTF16, aCanPlay,
|
|
|
|
__func__);
|
|
|
|
if (!aCanPlay) {
|
|
|
|
nsAutoString src;
|
|
|
|
self->GetCurrentSrc(src);
|
|
|
|
const char16_t* params[] = {mimeUTF16.get(), src.get()};
|
|
|
|
self->ReportLoadError("MediaLoadUnsupportedMimeType", params,
|
|
|
|
ArrayLength(params));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-03 09:09:58 +03:00
|
|
|
auto onExit = MakeScopeExit([self] {
|
2017-07-26 10:49:03 +03:00
|
|
|
if (self->mChannelLoader) {
|
|
|
|
self->mChannelLoader->Done();
|
|
|
|
self->mChannelLoader = nullptr;
|
|
|
|
}
|
|
|
|
});
|
2012-09-05 04:49:46 +04:00
|
|
|
|
2017-06-26 12:10:47 +03:00
|
|
|
Maybe<MediaContainerType> containerType = MakeMediaContainerType(mimeType);
|
|
|
|
if (!containerType) {
|
2017-07-26 10:49:03 +03:00
|
|
|
reportCanPlay(false);
|
2017-06-26 12:10:47 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaDecoderInit decoderInit(
|
|
|
|
this, mMuted ? 0.0 : mVolume, mPreservesPitch,
|
2018-11-07 16:56:25 +03:00
|
|
|
ClampPlaybackRate(mPlaybackRate),
|
2017-06-26 12:10:47 +03:00
|
|
|
mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, mHasSuspendTaint,
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::loop), *containerType);
|
2017-06-07 09:10:26 +03:00
|
|
|
|
2017-07-26 10:49:03 +03:00
|
|
|
#ifdef MOZ_ANDROID_HLS_SUPPORT
|
|
|
|
if (HLSDecoder::IsSupportedType(*containerType)) {
|
|
|
|
RefPtr<HLSDecoder> decoder = new HLSDecoder(decoderInit);
|
|
|
|
reportCanPlay(true);
|
2017-07-26 21:54:53 +03:00
|
|
|
return SetupDecoder(decoder.get(), aChannel);
|
2017-07-26 10:49:03 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-20 13:10:27 +03:00
|
|
|
RefPtr<ChannelMediaDecoder> decoder =
|
2017-10-16 23:55:26 +03:00
|
|
|
ChannelMediaDecoder::Create(decoderInit, &diagnostics);
|
2009-10-01 18:10:13 +04:00
|
|
|
if (!decoder) {
|
2017-07-26 10:49:03 +03:00
|
|
|
reportCanPlay(false);
|
2008-10-30 08:20:08 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
2008-10-30 08:20:08 +03:00
|
|
|
|
2017-07-26 10:49:03 +03:00
|
|
|
reportCanPlay(true);
|
2017-07-26 21:54:53 +03:00
|
|
|
bool isPrivateBrowsing = NodePrincipal()->GetPrivateBrowsingId() > 0;
|
2017-07-26 10:49:03 +03:00
|
|
|
return SetupDecoder(decoder.get(), aChannel, isPrivateBrowsing, aListener);
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
|
|
|
|
2017-06-23 10:25:40 +03:00
|
|
|
nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder) {
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_LOADING);
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
// Set mDecoder now so if methods like GetCurrentSrc get called between
|
|
|
|
// here and Load(), they work.
|
2015-03-19 05:01:12 +03:00
|
|
|
SetDecoder(aDecoder);
|
2012-04-30 07:12:28 +04:00
|
|
|
|
2017-03-12 08:56:43 +03:00
|
|
|
// Notify the decoder of the initial activity status.
|
|
|
|
NotifyDecoderActivityChanges();
|
2014-04-01 07:43:57 +04:00
|
|
|
|
2014-12-17 20:03:34 +03:00
|
|
|
// Update decoder principal before we start decoding, since it
|
|
|
|
// can affect how we feed data to MediaStreams
|
|
|
|
NotifyDecoderPrincipalChanged();
|
|
|
|
|
2018-10-12 12:39:30 +03:00
|
|
|
// Set sink device if we have one. Otherwise the default is used.
|
|
|
|
if (mSink.second()) {
|
|
|
|
mDecoder
|
|
|
|
->SetSink(mSink.second())
|
|
|
|
#ifdef DEBUG
|
|
|
|
->Then(mAbstractMainThread, __func__,
|
|
|
|
[](const GenericPromise::ResolveOrRejectValue& aValue) {
|
|
|
|
MOZ_ASSERT(aValue.IsResolve() && !aValue.ResolveValue());
|
|
|
|
});
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-23 18:02:03 +03:00
|
|
|
// Set CORSMode now before any streams are added. It won't change over time.
|
|
|
|
mDecoder->SetOutputStreamCORSMode(mCORSMode);
|
|
|
|
|
|
|
|
if (!mOutputStreams.IsEmpty()) {
|
|
|
|
mDecoder->SetNextOutputStreamTrackID(
|
|
|
|
mNextAvailableMediaDecoderOutputTrackID);
|
|
|
|
}
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
if (ms.mCapturingMediaStream) {
|
|
|
|
MOZ_ASSERT(!ms.mCapturingDecoder);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ms.mCapturingDecoder = true;
|
2018-11-23 18:02:03 +03:00
|
|
|
aDecoder->AddOutputStream(ms.mStream);
|
2015-05-28 09:16:29 +03:00
|
|
|
}
|
|
|
|
|
2014-12-23 05:23:17 +03:00
|
|
|
if (mMediaKeys) {
|
2016-06-29 07:09:24 +03:00
|
|
|
if (mMediaKeys->GetCDMProxy()) {
|
|
|
|
mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy());
|
|
|
|
} else {
|
|
|
|
// CDM must have crashed.
|
|
|
|
ShutdownDecoder();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-12-23 05:23:17 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:41:43 +03:00
|
|
|
if (mChannelLoader) {
|
|
|
|
mChannelLoader->Done();
|
|
|
|
mChannelLoader = nullptr;
|
|
|
|
}
|
2009-04-10 05:28:24 +04:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
// We may want to suspend the new stream now.
|
2009-10-01 18:10:13 +04:00
|
|
|
// This will also do an AddRemoveSelfReference.
|
2016-08-29 13:56:38 +03:00
|
|
|
NotifyOwnerDocumentActivityChanged();
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2017-10-13 06:58:05 +03:00
|
|
|
if (mPausedForInactiveDocumentOrChannel) {
|
|
|
|
mDecoder->Suspend();
|
|
|
|
}
|
|
|
|
|
2018-05-28 23:09:26 +03:00
|
|
|
if (!mPaused) {
|
2011-09-30 03:34:37 +04:00
|
|
|
SetPlayedOrSeeked(true);
|
2012-12-12 05:58:07 +04:00
|
|
|
if (!mPausedForInactiveDocumentOrChannel) {
|
2018-05-02 18:27:27 +03:00
|
|
|
mDecoder->Play();
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
2009-02-11 04:23:19 +03:00
|
|
|
}
|
|
|
|
|
2018-05-02 18:27:27 +03:00
|
|
|
return NS_OK;
|
2008-10-30 08:20:08 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
class HTMLMediaElement::MediaStreamTrackListener
|
|
|
|
: public DOMMediaStream::TrackListener {
|
2015-09-30 04:32:06 +03:00
|
|
|
public:
|
2018-05-14 12:11:18 +03:00
|
|
|
explicit MediaStreamTrackListener(HTMLMediaElement* aElement)
|
|
|
|
: mElement(aElement) {}
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) override {
|
2018-11-23 18:00:55 +03:00
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-30 04:32:06 +03:00
|
|
|
mElement->NotifyMediaStreamTrackAdded(aTrack);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override {
|
2018-11-23 18:00:55 +03:00
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-30 04:32:06 +03:00
|
|
|
mElement->NotifyMediaStreamTrackRemoved(aTrack);
|
|
|
|
}
|
|
|
|
|
2016-09-14 11:04:26 +03:00
|
|
|
void NotifyActive() override {
|
2018-11-23 18:00:55 +03:00
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p, mSrcStream %p became active", mElement.get(),
|
|
|
|
mElement->mSrcStream.get()));
|
2016-09-14 11:04:26 +03:00
|
|
|
mElement->CheckAutoplayDataReady();
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:42:36 +03:00
|
|
|
void NotifyInactive() override {
|
2018-11-23 18:00:55 +03:00
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-23 18:00:37 +03:00
|
|
|
if (mElement->IsPlaybackEnded()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p, mSrcStream %p became inactive", mElement.get(),
|
|
|
|
mElement->mSrcStream.get()));
|
2016-09-08 14:42:36 +03:00
|
|
|
MOZ_ASSERT(!mElement->mSrcStream->Active());
|
|
|
|
mElement->PlaybackEnded();
|
2018-11-23 18:00:49 +03:00
|
|
|
mElement->UpdateReadyStateInternal();
|
2016-09-08 14:42:36 +03:00
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
protected:
|
2018-11-23 18:00:55 +03:00
|
|
|
const WeakPtr<HTMLMediaElement> mElement;
|
2015-09-30 04:32:06 +03:00
|
|
|
};
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UpdateSrcMediaStreamPlaying(uint32_t aFlags) {
|
2015-08-31 14:33:53 +03:00
|
|
|
if (!mSrcStream) {
|
2014-12-05 02:07:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
// We might be in cycle collection with mSrcStream->GetPlaybackStream()
|
|
|
|
// already returning null due to unlinking.
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
MediaStream* stream = GetSrcMediaStream();
|
2018-11-23 18:01:13 +03:00
|
|
|
MediaStreamGraph* graph = stream ? stream->Graph() : nullptr;
|
2015-08-31 14:33:53 +03:00
|
|
|
bool shouldPlay = !(aFlags & REMOVING_SRC_STREAM) && !mPaused &&
|
2018-05-14 12:11:18 +03:00
|
|
|
!mPausedForInactiveDocumentOrChannel && stream;
|
2015-08-31 14:33:53 +03:00
|
|
|
if (shouldPlay == mSrcStreamIsPlaying) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mSrcStreamIsPlaying = shouldPlay;
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaElement %p %s playback of DOMMediaStream %p", this,
|
|
|
|
shouldPlay ? "Setting up" : "Removing", mSrcStream.get()));
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
if (shouldPlay) {
|
2018-11-23 18:00:37 +03:00
|
|
|
mSrcStreamPlaybackEnded = false;
|
2018-11-23 18:01:13 +03:00
|
|
|
mSrcStreamGraphTimeOffset =
|
|
|
|
graph->CurrentTime() - mSrcStreamPausedGraphTime;
|
|
|
|
mSrcStreamPausedGraphTime = GRAPH_TIME_MAX;
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2018-11-23 18:01:13 +03:00
|
|
|
mWatchManager.Watch(graph->CurrentTime(),
|
|
|
|
&HTMLMediaElement::UpdateSrcStreamTime);
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
stream->AddAudioOutput(this);
|
|
|
|
SetVolumeInternal();
|
2018-10-12 12:39:30 +03:00
|
|
|
if (mSink.second()) {
|
|
|
|
NS_WARNING(
|
|
|
|
"setSinkId() when playing a MediaStream is not supported yet and "
|
|
|
|
"will be ignored");
|
|
|
|
}
|
2015-04-08 08:51:21 +03:00
|
|
|
|
2015-12-29 12:07:33 +03:00
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
2016-07-25 05:01:26 +03:00
|
|
|
if (mSelectedVideoStreamTrack && container) {
|
|
|
|
mSelectedVideoStreamTrack->AddVideoOutput(container);
|
2015-08-31 14:33:53 +03:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
SetCapturedOutputStreamsEnabled(true); // Unmute
|
2016-11-29 07:40:43 +03:00
|
|
|
// If the input is a media stream, we don't check its data and always regard
|
|
|
|
// it as audible when it's playing.
|
|
|
|
SetAudibleState(true);
|
2015-08-31 14:33:53 +03:00
|
|
|
} else {
|
|
|
|
if (stream) {
|
2018-11-23 18:01:13 +03:00
|
|
|
mSrcStreamPausedGraphTime =
|
|
|
|
graph->CurrentTime() - mSrcStreamGraphTimeOffset;
|
2014-10-10 13:34:57 +04:00
|
|
|
|
2018-11-23 18:01:13 +03:00
|
|
|
mWatchManager.Unwatch(graph->CurrentTime(),
|
|
|
|
&HTMLMediaElement::UpdateSrcStreamTime);
|
2014-10-10 13:34:57 +04:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
stream->RemoveAudioOutput(this);
|
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
2016-07-25 05:01:26 +03:00
|
|
|
if (mSelectedVideoStreamTrack && container) {
|
|
|
|
mSelectedVideoStreamTrack->RemoveVideoOutput(container);
|
2015-08-31 14:33:53 +03:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
SetCapturedOutputStreamsEnabled(false); // Mute
|
2015-08-31 14:33:53 +03:00
|
|
|
}
|
|
|
|
// If stream is null, then DOMMediaStream::Destroy must have been
|
|
|
|
// called and that will remove all listeners/outputs.
|
2015-06-10 00:22:00 +03:00
|
|
|
}
|
2015-08-31 14:33:53 +03:00
|
|
|
}
|
|
|
|
|
2018-11-23 18:01:13 +03:00
|
|
|
void HTMLMediaElement::UpdateSrcStreamTime() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mSrcStreamPausedGraphTime == GRAPH_TIME_MAX);
|
|
|
|
MOZ_ASSERT(!mPaused);
|
|
|
|
MOZ_ASSERT(!mSrcStreamPlaybackEnded);
|
|
|
|
FireTimeUpdate(true);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SetupSrcMediaStreamPlayback(DOMMediaStream* aStream) {
|
2018-11-23 18:01:13 +03:00
|
|
|
NS_ASSERTION(!mSrcStream && !mVideoFrameListener,
|
2015-08-31 14:33:53 +03:00
|
|
|
"Should have been ended already");
|
|
|
|
|
|
|
|
mSrcStream = aStream;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
2015-08-31 14:33:53 +03:00
|
|
|
if (!window) {
|
|
|
|
return;
|
2015-06-10 00:22:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-23 18:01:13 +03:00
|
|
|
mSrcStreamPausedGraphTime = 0;
|
|
|
|
if (MediaStream* stream = GetSrcMediaStream()) {
|
|
|
|
if (MediaStreamGraph* graph = stream->Graph()) {
|
|
|
|
// The current graph time will represent 0 for this media element.
|
|
|
|
mSrcStreamPausedGraphTime = graph->CurrentTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
UpdateSrcMediaStreamPlaying();
|
2014-10-10 13:34:57 +04:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
// If we pause this media element, track changes in the underlying stream
|
|
|
|
// will continue to fire events at this element and alter its track list.
|
|
|
|
// That's simpler than delaying the events, but probably confusing...
|
2016-08-23 18:51:50 +03:00
|
|
|
nsTArray<RefPtr<MediaStreamTrack>> tracks;
|
|
|
|
mSrcStream->GetTracks(tracks);
|
|
|
|
for (const RefPtr<MediaStreamTrack>& track : tracks) {
|
|
|
|
NotifyMediaStreamTrackAdded(track);
|
|
|
|
}
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2018-11-23 18:00:55 +03:00
|
|
|
mMediaStreamTrackListener = MakeUnique<MediaStreamTrackListener>(this);
|
|
|
|
mSrcStream->RegisterTrackListener(mMediaStreamTrackListener.get());
|
2015-02-09 10:23:34 +03:00
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
mSrcStream->AddPrincipalChangeObserver(this);
|
|
|
|
mSrcStreamVideoPrincipal = mSrcStream->GetVideoPrincipal();
|
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_IDLE);
|
2015-08-31 14:33:53 +03:00
|
|
|
ChangeDelayLoadStatus(false);
|
|
|
|
CheckAutoplayDataReady();
|
|
|
|
|
2018-11-23 18:02:23 +03:00
|
|
|
// FirstFrameLoaded() will be called when the stream has tracks.
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::EndSrcMediaStreamPlayback() {
|
2015-08-31 14:33:53 +03:00
|
|
|
MOZ_ASSERT(mSrcStream);
|
2014-10-04 01:29:29 +04:00
|
|
|
|
2015-08-31 14:33:53 +03:00
|
|
|
UpdateSrcMediaStreamPlaying(REMOVING_SRC_STREAM);
|
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
if (mVideoFrameListener) {
|
2016-08-23 18:51:50 +03:00
|
|
|
MOZ_ASSERT(mSelectedVideoStreamTrack);
|
|
|
|
if (mSelectedVideoStreamTrack) {
|
2018-11-23 18:00:43 +03:00
|
|
|
mSelectedVideoStreamTrack->RemoveDirectListener(mVideoFrameListener);
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
2018-11-23 18:00:43 +03:00
|
|
|
mVideoFrameListener->Forget();
|
2016-01-29 06:10:19 +03:00
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
mSelectedVideoStreamTrack = nullptr;
|
2018-11-23 18:00:43 +03:00
|
|
|
mVideoFrameListener = nullptr;
|
2016-01-29 06:10:19 +03:00
|
|
|
|
2018-11-23 18:00:55 +03:00
|
|
|
mSrcStream->UnregisterTrackListener(mMediaStreamTrackListener.get());
|
2015-09-30 04:32:06 +03:00
|
|
|
mMediaStreamTrackListener = nullptr;
|
2016-08-19 14:41:48 +03:00
|
|
|
mSrcStreamTracksAvailable = false;
|
2014-12-05 02:07:00 +03:00
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
mSrcStream->RemovePrincipalChangeObserver(this);
|
|
|
|
mSrcStreamVideoPrincipal = nullptr;
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
|
|
|
for (auto pair : ms.mTrackPorts) {
|
|
|
|
pair.second()->Destroy();
|
|
|
|
}
|
|
|
|
ms.mTrackPorts.Clear();
|
|
|
|
}
|
|
|
|
|
2012-08-20 08:52:59 +04:00
|
|
|
mSrcStream = nullptr;
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
static already_AddRefed<AudioTrack> CreateAudioTrack(
|
2018-05-14 12:11:18 +03:00
|
|
|
AudioStreamTrack* aStreamTrack, nsIGlobalObject* aOwnerGlobal) {
|
2015-09-30 04:32:06 +03:00
|
|
|
nsAutoString id;
|
|
|
|
nsAutoString label;
|
|
|
|
aStreamTrack->GetId(id);
|
2017-10-13 06:57:25 +03:00
|
|
|
aStreamTrack->GetLabel(label, CallerType::System);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
return MediaTrackList::CreateAudioTrack(
|
|
|
|
aOwnerGlobal, id, NS_LITERAL_STRING("main"), label, EmptyString(), true);
|
2015-09-30 04:32:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<VideoTrack> CreateVideoTrack(
|
2018-05-14 12:11:18 +03:00
|
|
|
VideoStreamTrack* aStreamTrack, nsIGlobalObject* aOwnerGlobal) {
|
2015-09-30 04:32:06 +03:00
|
|
|
nsAutoString id;
|
|
|
|
nsAutoString label;
|
|
|
|
aStreamTrack->GetId(id);
|
2017-10-13 06:57:25 +03:00
|
|
|
aStreamTrack->GetLabel(label, CallerType::System);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2018-04-11 17:27:00 +03:00
|
|
|
return MediaTrackList::CreateVideoTrack(aOwnerGlobal, id,
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_LITERAL_STRING("main"), label,
|
2016-05-10 12:02:15 +03:00
|
|
|
EmptyString(), aStreamTrack);
|
2015-09-30 04:32:06 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyMediaStreamTrackAdded(
|
|
|
|
const RefPtr<MediaStreamTrack>& aTrack) {
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
if (aTrack->Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsString id;
|
|
|
|
aTrack->GetId(id);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p, Adding %sTrack with id %s", this,
|
|
|
|
aTrack->AsAudioStreamTrack() ? "Audio" : "Video",
|
|
|
|
NS_ConvertUTF16toUTF8(id).get()));
|
2015-09-30 04:32:06 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (AudioStreamTrack* t = aTrack->AsAudioStreamTrack()) {
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(AudioTracks(), "Element can't have been unlinked");
|
2018-04-11 17:27:00 +03:00
|
|
|
RefPtr<AudioTrack> audioTrack =
|
|
|
|
CreateAudioTrack(t, AudioTracks()->GetOwnerGlobal());
|
2015-09-30 04:32:06 +03:00
|
|
|
AudioTracks()->AddTrack(audioTrack);
|
|
|
|
} else if (VideoStreamTrack* t = aTrack->AsVideoStreamTrack()) {
|
2016-05-10 12:02:15 +03:00
|
|
|
// TODO: Fix this per the spec on bug 1273443.
|
2016-08-23 18:51:50 +03:00
|
|
|
if (!IsVideo()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(VideoTracks(), "Element can't have been unlinked");
|
2018-04-11 17:27:00 +03:00
|
|
|
RefPtr<VideoTrack> videoTrack =
|
|
|
|
CreateVideoTrack(t, VideoTracks()->GetOwnerGlobal());
|
2015-09-30 04:32:06 +03:00
|
|
|
VideoTracks()->AddTrack(videoTrack);
|
2016-05-10 12:02:15 +03:00
|
|
|
// New MediaStreamTrack added, set the new added video track as selected
|
|
|
|
// video track when there is no selected track.
|
2016-08-23 18:51:50 +03:00
|
|
|
if (VideoTracks()->SelectedIndex() == -1) {
|
2016-05-10 12:02:15 +03:00
|
|
|
MOZ_ASSERT(!mSelectedVideoStreamTrack);
|
|
|
|
videoTrack->SetEnabledInternal(true, MediaTrack::FIRE_NO_EVENTS);
|
|
|
|
}
|
2015-09-30 04:32:06 +03:00
|
|
|
}
|
2016-08-19 14:41:48 +03:00
|
|
|
|
2017-10-17 09:52:38 +03:00
|
|
|
UpdateReadyStateInternal();
|
2018-11-23 18:02:23 +03:00
|
|
|
|
|
|
|
if (!mSrcStreamTracksAvailable) {
|
|
|
|
mAbstractMainThread->Dispatch(NS_NewRunnableFunction(
|
|
|
|
"HTMLMediaElement::NotifyMediaStreamTrackAdded->FirstFrameLoaded",
|
|
|
|
[this, self = RefPtr<HTMLMediaElement>(this), stream = mSrcStream]() {
|
|
|
|
if (!mSrcStream || mSrcStream != stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaElement %p MediaStream tracks available", this));
|
|
|
|
|
|
|
|
mSrcStreamTracksAvailable = true;
|
|
|
|
|
|
|
|
FirstFrameLoaded();
|
|
|
|
UpdateReadyStateInternal();
|
|
|
|
}));
|
|
|
|
}
|
2015-09-30 04:32:06 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyMediaStreamTrackRemoved(
|
|
|
|
const RefPtr<MediaStreamTrack>& aTrack) {
|
2015-09-30 04:32:06 +03:00
|
|
|
MOZ_ASSERT(aTrack);
|
|
|
|
|
|
|
|
nsAutoString id;
|
|
|
|
aTrack->GetId(id);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p, Removing %sTrack with id %s", this,
|
|
|
|
aTrack->AsAudioStreamTrack() ? "Audio" : "Video",
|
|
|
|
NS_ConvertUTF16toUTF8(id).get()));
|
2015-09-30 04:32:06 +03:00
|
|
|
|
2018-11-15 15:48:34 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(AudioTracks() && VideoTracks(),
|
|
|
|
"Element can't have been unlinked");
|
2015-09-30 04:32:06 +03:00
|
|
|
if (MediaTrack* t = AudioTracks()->GetTrackById(id)) {
|
|
|
|
AudioTracks()->RemoveTrack(t);
|
|
|
|
} else if (MediaTrack* t = VideoTracks()->GetTrackById(id)) {
|
|
|
|
VideoTracks()->RemoveTrack(t);
|
|
|
|
} else {
|
2016-09-23 17:56:39 +03:00
|
|
|
NS_ASSERTION(aTrack->AsVideoStreamTrack() && !IsVideo(),
|
|
|
|
"MediaStreamTrack ended but did not exist in track lists. "
|
|
|
|
"This is only allowed if a video element ends and we are an "
|
|
|
|
"audio element.");
|
2015-09-30 04:32:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ProcessMediaFragmentURI() {
|
2012-12-21 05:04:50 +04:00
|
|
|
nsMediaFragmentURIParser parser(mLoadingSrc);
|
|
|
|
|
|
|
|
if (mDecoder && parser.HasEndTime()) {
|
|
|
|
mFragmentEnd = parser.GetEndTime();
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
if (parser.HasStartTime()) {
|
|
|
|
SetCurrentTime(parser.GetStartTime());
|
|
|
|
mFragmentStart = parser.GetStartTime();
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 09:10:35 +03:00
|
|
|
void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
|
|
|
|
UniquePtr<const MetadataTags> aTags) {
|
2015-04-14 08:15:46 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-08-29 13:56:32 +03:00
|
|
|
SetMediaInfo(*aInfo);
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
mIsEncrypted =
|
|
|
|
aInfo->IsEncrypted() || mPendingEncryptedInitData.IsEncrypted();
|
2018-05-30 22:15:35 +03:00
|
|
|
mTags = std::move(aTags);
|
2014-09-24 11:25:00 +04:00
|
|
|
mLoadedDataFired = false;
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_METADATA);
|
2015-02-01 18:20:57 +03:00
|
|
|
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
|
2015-02-09 09:51:17 +03:00
|
|
|
if (IsVideo() && HasVideo()) {
|
2014-12-04 04:01:00 +03:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("resize"));
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ASSERTION(!HasVideo() || (mMediaInfo.mVideo.mDisplay.width > 0 &&
|
|
|
|
mMediaInfo.mVideo.mDisplay.height > 0),
|
2016-01-21 14:42:55 +03:00
|
|
|
"Video resolution must be known on 'loadedmetadata'");
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
|
2018-08-23 01:50:54 +03:00
|
|
|
|
|
|
|
if (mBlockedAsWithoutMetadata && !HasAudio()) {
|
|
|
|
mBlockedAsWithoutMetadata = false;
|
|
|
|
ScalarAdd(
|
|
|
|
Telemetry::ScalarID::MEDIA_BLOCKED_NO_METADATA_ENDUP_NO_AUDIO_TRACK, 1);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mDecoder && mDecoder->IsTransportSeekable() &&
|
|
|
|
mDecoder->IsMediaSeekable()) {
|
2011-08-25 03:42:23 +04:00
|
|
|
ProcessMediaFragmentURI();
|
2012-11-19 19:11:21 +04:00
|
|
|
mDecoder->SetFragmentEndTime(mFragmentEnd);
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
2015-03-23 05:31:15 +03:00
|
|
|
if (mIsEncrypted) {
|
2016-09-21 04:04:01 +03:00
|
|
|
// We only support playback of encrypted content via MSE by default.
|
2015-03-25 05:00:26 +03:00
|
|
|
if (!mMediaSource && Preferences::GetBool("media.eme.mse-only", true)) {
|
2018-05-14 12:11:18 +03:00
|
|
|
DecodeError(
|
|
|
|
MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
|
|
|
"Encrypted content not supported outside of MSE"));
|
2015-03-23 05:31:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
// Dispatch a distinct 'encrypted' event for each initData we have.
|
|
|
|
for (const auto& initData : mPendingEncryptedInitData.mInitDatas) {
|
|
|
|
DispatchEncrypted(initData.mInitData, initData.mType);
|
|
|
|
}
|
2017-01-12 06:33:55 +03:00
|
|
|
mPendingEncryptedInitData.Reset();
|
2015-03-23 05:31:15 +03:00
|
|
|
}
|
2012-12-27 19:21:30 +04:00
|
|
|
|
2014-10-10 13:34:57 +04:00
|
|
|
if (IsVideo() && aInfo->HasVideo()) {
|
|
|
|
// We are a video element playing video so update the screen wakelock
|
2016-08-29 13:56:38 +03:00
|
|
|
NotifyOwnerDocumentActivityChanged();
|
2014-10-10 13:34:57 +04:00
|
|
|
}
|
2015-10-26 12:36:16 +03:00
|
|
|
|
2015-11-20 09:00:45 +03:00
|
|
|
if (mDefaultPlaybackStartPosition != 0.0) {
|
2015-10-26 12:36:16 +03:00
|
|
|
SetCurrentTime(mDefaultPlaybackStartPosition);
|
|
|
|
mDefaultPlaybackStartPosition = 0.0;
|
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
|
2017-10-17 09:52:38 +03:00
|
|
|
UpdateReadyStateInternal();
|
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
if (!mSrcStream) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-15 15:48:34 +03:00
|
|
|
|
2016-08-23 18:51:50 +03:00
|
|
|
for (OutputMediaStream& ms : mOutputStreams) {
|
2018-11-15 15:48:34 +03:00
|
|
|
if (AudioTracks()) {
|
|
|
|
for (size_t i = 0; i < AudioTracks()->Length(); ++i) {
|
|
|
|
AudioTrack* t = (*AudioTracks())[i];
|
|
|
|
if (t->Enabled()) {
|
|
|
|
AddCaptureMediaTrackToOutputStream(t, ms);
|
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-15 15:48:34 +03:00
|
|
|
if (VideoTracks() && IsVideo() && !ms.mCapturingAudioOnly) {
|
2016-08-23 18:51:50 +03:00
|
|
|
// Only add video tracks if we're a video element and the output stream
|
|
|
|
// wants video.
|
|
|
|
for (size_t i = 0; i < VideoTracks()->Length(); ++i) {
|
|
|
|
VideoTrack* t = (*VideoTracks())[i];
|
|
|
|
if (t->Selected()) {
|
|
|
|
AddCaptureMediaTrackToOutputStream(t, ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::FirstFrameLoaded() {
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p, FirstFrameLoaded() mFirstFrameLoaded=%d mWaitingForKey=%d", this,
|
|
|
|
mFirstFrameLoaded, mWaitingForKey));
|
2016-10-17 04:16:54 +03:00
|
|
|
|
2014-09-29 12:57:48 +04:00
|
|
|
NS_ASSERTION(!mSuspendedAfterFirstFrame, "Should not have already suspended");
|
|
|
|
|
2015-10-22 10:46:27 +03:00
|
|
|
if (!mFirstFrameLoaded) {
|
|
|
|
mFirstFrameLoaded = true;
|
|
|
|
UpdateReadyStateInternal();
|
|
|
|
}
|
|
|
|
|
2014-09-24 11:25:00 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
|
|
|
|
2009-05-18 06:00:44 +04:00
|
|
|
if (mDecoder && mAllowSuspendAfterFirstFrame && mPaused &&
|
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) &&
|
2013-03-19 16:23:54 +04:00
|
|
|
mPreloadAction == HTMLMediaElement::PRELOAD_METADATA) {
|
2011-09-30 03:34:37 +04:00
|
|
|
mSuspendedAfterFirstFrame = true;
|
2009-05-18 06:00:44 +04:00
|
|
|
mDecoder->Suspend();
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 06:07:30 +03:00
|
|
|
void HTMLMediaElement::NetworkError(const MediaResult& aError) {
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
2017-11-17 06:07:30 +03:00
|
|
|
NoSupportedMediaSourceError(aError.Description());
|
2016-09-14 09:45:52 +03:00
|
|
|
} else {
|
|
|
|
Error(MEDIA_ERR_NETWORK);
|
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DecodeError(const MediaResult& aError) {
|
2011-12-22 03:33:39 +04:00
|
|
|
nsAutoString src;
|
|
|
|
GetCurrentSrc(src);
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* params[] = {src.get()};
|
2011-12-22 03:33:39 +04:00
|
|
|
ReportLoadError("MediaLoadDecodeError", params, ArrayLength(params));
|
|
|
|
|
2017-02-21 06:02:11 +03:00
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
|
|
|
diagnostics.StoreDecodeError(OwnerDoc(), aError, src, __func__);
|
|
|
|
|
2018-11-15 15:48:34 +03:00
|
|
|
if (AudioTracks()) {
|
|
|
|
AudioTracks()->EmptyTracks();
|
|
|
|
}
|
|
|
|
if (VideoTracks()) {
|
|
|
|
VideoTracks()->EmptyTracks();
|
|
|
|
}
|
2010-10-16 23:57:50 +04:00
|
|
|
if (mIsLoadingFromSourceChildren) {
|
2016-11-24 05:24:04 +03:00
|
|
|
mErrorSink->ResetError();
|
2011-04-28 18:08:03 +04:00
|
|
|
if (mSourceLoadCandidate) {
|
|
|
|
DispatchAsyncSourceError(mSourceLoadCandidate);
|
|
|
|
QueueLoadFromSourceTask();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Should know the source we were loading from!");
|
|
|
|
}
|
2018-02-15 06:23:32 +03:00
|
|
|
} else if (mReadyState == HAVE_NOTHING) {
|
2016-09-15 09:17:10 +03:00
|
|
|
NoSupportedMediaSourceError(aError.Description());
|
2010-10-07 02:58:36 +04:00
|
|
|
} else {
|
2016-09-15 09:17:10 +03:00
|
|
|
Error(MEDIA_ERR_DECODE, aError.Description());
|
2010-10-07 02:58:36 +04:00
|
|
|
}
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DecodeWarning(const MediaResult& aError) {
|
2017-02-27 04:12:37 +03:00
|
|
|
nsAutoString src;
|
|
|
|
GetCurrentSrc(src);
|
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
2017-03-13 17:12:20 +03:00
|
|
|
diagnostics.StoreDecodeWarning(OwnerDoc(), aError, src, __func__);
|
2017-02-27 04:12:37 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::HasError() const { return GetError(); }
|
2016-02-08 07:27:14 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::LoadAborted() { Error(MEDIA_ERR_ABORTED); }
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::Error(uint16_t aErrorCode,
|
|
|
|
const nsACString& aErrorDetails) {
|
2016-11-24 05:24:04 +03:00
|
|
|
mErrorSink->SetError(aErrorCode, aErrorDetails);
|
2011-09-30 03:34:37 +04:00
|
|
|
ChangeDelayLoadStatus(false);
|
2016-01-25 19:03:42 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2009-09-22 04:08:13 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::PlaybackEnded() {
|
2012-04-30 07:12:28 +04:00
|
|
|
// We changed state which can affect AddRemoveSelfReference
|
2009-10-01 18:10:13 +04:00
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2016-08-01 10:22:32 +03:00
|
|
|
NS_ASSERTION(!mDecoder || mDecoder->IsEnded(),
|
2012-04-30 07:12:28 +04:00
|
|
|
"Decoder fired ended, but not in ended state");
|
2012-07-31 16:17:22 +04:00
|
|
|
|
|
|
|
// Discard all output streams that have finished now.
|
|
|
|
for (int32_t i = mOutputStreams.Length() - 1; i >= 0; --i) {
|
|
|
|
if (mOutputStreams[i].mFinishWhenEnded) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
2018-11-23 18:02:03 +03:00
|
|
|
("Playback ended. Letting output stream %p go inactive",
|
2018-05-14 12:11:18 +03:00
|
|
|
mOutputStreams[i].mStream.get()));
|
2018-11-23 18:02:03 +03:00
|
|
|
mOutputStreams[i].mStream->SetFinishedOnInactive(true);
|
|
|
|
if (mOutputStreams[i].mCapturingDecoder) {
|
|
|
|
mDecoder->RemoveOutputStream(mOutputStreams[i].mStream);
|
|
|
|
}
|
2012-07-31 16:17:22 +04:00
|
|
|
mOutputStreams.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 09:15:29 +03:00
|
|
|
if (mSrcStream) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p, got duration by reaching the end of the resource", this));
|
2018-11-23 18:00:37 +03:00
|
|
|
mSrcStreamPlaybackEnded = true;
|
2011-08-01 22:11:20 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
|
|
|
|
}
|
|
|
|
|
2011-11-21 02:59:01 +04:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
|
|
|
|
SetCurrentTime(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-19 06:52:04 +03:00
|
|
|
FireTimeUpdate(false);
|
|
|
|
|
|
|
|
if (!mPaused) {
|
|
|
|
Pause();
|
|
|
|
}
|
2012-08-06 21:27:55 +04:00
|
|
|
|
2016-09-14 11:04:26 +03:00
|
|
|
if (mSrcStream) {
|
|
|
|
// A MediaStream that goes from inactive to active shall be eligible for
|
|
|
|
// autoplay again according to the mediacapture-main spec.
|
|
|
|
mAutoplaying = true;
|
|
|
|
}
|
|
|
|
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SeekStarted() {
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("seeking"));
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SeekCompleted() {
|
2011-09-30 03:34:37 +04:00
|
|
|
mPlayingBeforeSeek = false;
|
|
|
|
SetPlayedOrSeeked(true);
|
2016-06-01 10:13:43 +03:00
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->DidSeek();
|
|
|
|
}
|
2015-03-23 13:03:39 +03:00
|
|
|
FireTimeUpdate(false);
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("seeked"));
|
2009-10-01 18:10:13 +04:00
|
|
|
// We changed whether we're seeking so we need to AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2014-04-01 07:39:04 +04:00
|
|
|
if (mCurrentPlayRangeStart == -1.0) {
|
|
|
|
mCurrentPlayRangeStart = CurrentTime();
|
|
|
|
}
|
2018-08-15 19:35:51 +03:00
|
|
|
|
|
|
|
// After seeking completed, if the audio track is silent, start another new
|
|
|
|
// silence range.
|
|
|
|
mHasAccumulatedSilenceRangeBeforeSeekEnd = false;
|
|
|
|
if (IsAudioTrackCurrentlySilent()) {
|
|
|
|
UpdateAudioTrackSilenceRange(mIsAudioTrackAudible);
|
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2017-08-23 09:42:25 +03:00
|
|
|
void HTMLMediaElement::NotifySuspendedByCache(bool aSuspendedByCache) {
|
|
|
|
mDownloadSuspendedByCache = aSuspendedByCache;
|
2017-10-17 09:46:15 +03:00
|
|
|
UpdateReadyStateInternal();
|
2012-05-28 02:40:06 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DownloadSuspended() {
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState == NETWORK_LOADING) {
|
2014-11-28 02:17:18 +03:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
|
|
|
|
}
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_IDLE);
|
2009-05-18 06:03:37 +04:00
|
|
|
}
|
|
|
|
|
2017-10-10 02:04:18 +03:00
|
|
|
void HTMLMediaElement::DownloadResumed() {
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeNetworkState(NETWORK_LOADING);
|
2009-05-18 06:03:37 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::CheckProgress(bool aHaveNewProgress) {
|
2014-11-28 02:17:18 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-02-15 06:23:32 +03:00
|
|
|
MOZ_ASSERT(mNetworkState == NETWORK_LOADING);
|
2014-11-28 02:17:18 +03:00
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::NowLoRes();
|
|
|
|
|
|
|
|
if (aHaveNewProgress) {
|
|
|
|
mDataTime = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the first progress, or PROGRESS_MS has passed since the last
|
|
|
|
// progress event fired and more data has arrived since then, fire a
|
|
|
|
// progress event.
|
2014-11-28 07:07:15 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
(mProgressTime.IsNull() && !aHaveNewProgress) || !mDataTime.IsNull(),
|
|
|
|
"null TimeStamp mDataTime should not be used in comparison");
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mProgressTime.IsNull()
|
|
|
|
? aHaveNewProgress
|
|
|
|
: (now - mProgressTime >=
|
|
|
|
TimeDuration::FromMilliseconds(PROGRESS_MS) &&
|
|
|
|
mDataTime > mProgressTime)) {
|
2014-09-24 11:26:00 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
|
2014-11-28 02:17:18 +03:00
|
|
|
// Resolution() ensures that future data will have now > mProgressTime,
|
|
|
|
// and so will trigger another event. mDataTime is not reset because it
|
|
|
|
// is still required to detect stalled; it is similarly offset by
|
|
|
|
// resolution to indicate the new data has not yet arrived.
|
|
|
|
mProgressTime = now - TimeDuration::Resolution();
|
|
|
|
if (mDataTime > mProgressTime) {
|
|
|
|
mDataTime = mProgressTime;
|
|
|
|
}
|
2014-11-28 07:07:15 +03:00
|
|
|
if (!mProgressTimer) {
|
|
|
|
NS_ASSERTION(aHaveNewProgress,
|
|
|
|
"timer dispatched when there was no timer");
|
|
|
|
// Were stalled. Restart timer.
|
|
|
|
StartProgressTimer();
|
2014-12-11 04:51:10 +03:00
|
|
|
if (!mLoadedDataFired) {
|
|
|
|
ChangeDelayLoadStatus(true);
|
|
|
|
}
|
2014-11-28 07:07:15 +03:00
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
// Download statistics may have been updated, force a recheck of the
|
|
|
|
// readyState.
|
2016-04-24 16:34:23 +03:00
|
|
|
UpdateReadyStateInternal();
|
2014-11-28 02:17:18 +03:00
|
|
|
}
|
|
|
|
|
2014-11-28 07:07:15 +03:00
|
|
|
if (now - mDataTime >= TimeDuration::FromMilliseconds(STALL_MS)) {
|
2018-05-14 12:32:09 +03:00
|
|
|
if (!mMediaSource) {
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("stalled"));
|
|
|
|
} else {
|
2015-02-01 20:21:00 +03:00
|
|
|
ChangeDelayLoadStatus(false);
|
|
|
|
}
|
2014-12-11 04:51:10 +03:00
|
|
|
|
2014-11-28 07:07:15 +03:00
|
|
|
NS_ASSERTION(mProgressTimer, "detected stalled without timer");
|
|
|
|
// Stop timer events, which prevents repeated stalled events until there
|
|
|
|
// is more progress.
|
|
|
|
StopProgress();
|
2014-09-24 11:26:00 +04:00
|
|
|
}
|
2014-12-11 06:08:20 +03:00
|
|
|
|
|
|
|
AddRemoveSelfReference();
|
2014-09-24 11:26:00 +04:00
|
|
|
}
|
|
|
|
|
2014-11-28 02:17:18 +03:00
|
|
|
/* static */
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ProgressTimerCallback(nsITimer* aTimer, void* aClosure) {
|
2014-11-28 02:17:18 +03:00
|
|
|
auto decoder = static_cast<HTMLMediaElement*>(aClosure);
|
|
|
|
decoder->CheckProgress(false);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::StartProgressTimer() {
|
2014-11-28 02:17:18 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-02-15 06:23:32 +03:00
|
|
|
MOZ_ASSERT(mNetworkState == NETWORK_LOADING);
|
2014-11-28 02:17:18 +03:00
|
|
|
NS_ASSERTION(!mProgressTimer, "Already started progress timer.");
|
|
|
|
|
2017-10-16 09:15:40 +03:00
|
|
|
NS_NewTimerWithFuncCallback(
|
|
|
|
getter_AddRefs(mProgressTimer), ProgressTimerCallback, this, PROGRESS_MS,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK, "HTMLMediaElement::ProgressTimerCallback",
|
|
|
|
mMainThreadEventTarget);
|
2014-11-28 07:07:15 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::StartProgress() {
|
2014-11-28 07:07:15 +03:00
|
|
|
// Record the time now for detecting stalled.
|
|
|
|
mDataTime = TimeStamp::NowLoRes();
|
|
|
|
// Reset mProgressTime so that mDataTime is not indicating bytes received
|
|
|
|
// after the last progress event.
|
|
|
|
mProgressTime = TimeStamp();
|
|
|
|
StartProgressTimer();
|
2014-11-28 02:17:18 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::StopProgress() {
|
2014-11-28 02:17:18 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-28 07:07:15 +03:00
|
|
|
if (!mProgressTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-28 02:17:18 +03:00
|
|
|
|
2014-11-28 07:07:15 +03:00
|
|
|
mProgressTimer->Cancel();
|
2014-11-28 02:17:18 +03:00
|
|
|
mProgressTimer = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DownloadProgressed() {
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState != NETWORK_LOADING) {
|
2014-11-28 02:17:18 +03:00
|
|
|
return;
|
2009-05-18 06:03:37 +04:00
|
|
|
}
|
2014-11-28 02:17:18 +03:00
|
|
|
CheckProgress(true);
|
2009-05-18 06:03:37 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::ShouldCheckAllowOrigin() {
|
2012-01-26 02:31:30 +04:00
|
|
|
return mCORSMode != CORS_NONE;
|
2009-01-24 14:00:17 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsCORSSameOrigin() {
|
2015-01-29 10:30:38 +03:00
|
|
|
bool subsumes;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIPrincipal> principal = GetCurrentPrincipal();
|
2018-05-14 12:11:18 +03:00
|
|
|
return (NS_SUCCEEDED(NodePrincipal()->Subsumes(principal, &subsumes)) &&
|
|
|
|
subsumes) ||
|
|
|
|
ShouldCheckAllowOrigin();
|
2015-01-29 10:30:38 +03:00
|
|
|
}
|
|
|
|
|
2015-03-19 05:01:12 +03:00
|
|
|
void HTMLMediaElement::UpdateReadyStateInternal() {
|
|
|
|
if (!mDecoder && !mSrcStream) {
|
|
|
|
// Not initialized - bail out.
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Not initialized",
|
|
|
|
this));
|
2015-03-19 05:01:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-10-10 13:34:57 +04:00
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mDecoder && mReadyState < HAVE_METADATA) {
|
2009-04-01 04:52:56 +04:00
|
|
|
// aNextFrame might have a next frame because the decoder can advance
|
2014-09-24 11:25:00 +04:00
|
|
|
// on its own thread before MetadataLoaded gets a chance to run.
|
2009-04-01 04:52:56 +04:00
|
|
|
// The arrival of more data can't change us out of this readyState.
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Decoder ready state < HAVE_METADATA",
|
|
|
|
this));
|
2009-02-05 11:02:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mSrcStream && mReadyState < HAVE_METADATA) {
|
2016-08-19 14:41:48 +03:00
|
|
|
if (!mSrcStreamTracksAvailable) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"MediaStreamTracks not available yet",
|
|
|
|
this));
|
2016-08-19 14:41:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-15 15:48:34 +03:00
|
|
|
bool hasAudioTracks = AudioTracks() && !AudioTracks()->IsEmpty();
|
|
|
|
bool hasVideoTracks = VideoTracks() && !VideoTracks()->IsEmpty();
|
2016-04-07 06:44:00 +03:00
|
|
|
if (!hasAudioTracks && !hasVideoTracks) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Stream with no tracks",
|
|
|
|
this));
|
2018-11-15 15:48:34 +03:00
|
|
|
// Give it one last chance to remove the self reference if needed.
|
|
|
|
AddRemoveSelfReference();
|
2015-09-25 18:23:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-07 06:44:00 +03:00
|
|
|
if (IsVideo() && hasVideoTracks && !HasVideo()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Stream waiting for video",
|
|
|
|
this));
|
2015-09-30 04:31:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaElement %p UpdateReadyStateInternal() Stream has "
|
|
|
|
"metadata; audioTracks=%d, videoTracks=%d, "
|
|
|
|
"hasVideoFrame=%d",
|
|
|
|
this, AudioTracks()->Length(), VideoTracks()->Length(), HasVideo()));
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2014-10-10 13:34:57 +04:00
|
|
|
// We are playing a stream that has video and a video frame is now set.
|
|
|
|
// This means we have all metadata needed to change ready state.
|
2015-04-14 08:15:46 +03:00
|
|
|
MediaInfo mediaInfo = mMediaInfo;
|
2016-04-07 06:44:00 +03:00
|
|
|
if (hasAudioTracks) {
|
2015-07-16 12:15:06 +03:00
|
|
|
mediaInfo.EnableAudio();
|
|
|
|
}
|
2016-04-07 06:44:00 +03:00
|
|
|
if (hasVideoTracks) {
|
2015-07-16 12:15:06 +03:00
|
|
|
mediaInfo.EnableVideo();
|
|
|
|
}
|
2017-08-28 09:10:35 +03:00
|
|
|
MetadataLoaded(&mediaInfo, nullptr);
|
2014-10-10 13:34:57 +04:00
|
|
|
}
|
|
|
|
|
2017-05-09 13:23:11 +03:00
|
|
|
if (mMediaSource) {
|
|
|
|
// readyState has changed, assuming it's following the pending mediasource
|
|
|
|
// operations. Notify the Mediasource that the operations have completed.
|
|
|
|
mMediaSource->CompletePendingTransactions();
|
|
|
|
}
|
|
|
|
|
2015-12-02 03:50:21 +03:00
|
|
|
enum NextFrameStatus nextFrameStatus = NextFrameStatus();
|
2017-08-17 05:47:07 +03:00
|
|
|
if (mWaitingForKey == NOT_WAITING_FOR_KEY) {
|
|
|
|
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE && mDecoder &&
|
|
|
|
!mDecoder->IsEnded()) {
|
|
|
|
nextFrameStatus = mDecoder->NextFrameBufferedStatus();
|
|
|
|
}
|
|
|
|
} else if (mWaitingForKey == WAITING_FOR_KEY) {
|
|
|
|
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE ||
|
|
|
|
nextFrameStatus == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
|
2016-10-17 04:16:54 +03:00
|
|
|
// http://w3c.github.io/encrypted-media/#wait-for-key
|
|
|
|
// Continuing 7.3.4 Queue a "waitingforkey" Event
|
|
|
|
// 4. Queue a task to fire a simple event named waitingforkey
|
|
|
|
// at the media element.
|
|
|
|
// 5. Set the readyState of media element to HAVE_METADATA.
|
|
|
|
// NOTE: We'll change to HAVE_CURRENT_DATA or HAVE_METADATA
|
|
|
|
// depending on whether we've loaded the first frame or not
|
|
|
|
// below.
|
|
|
|
// 6. Suspend playback.
|
|
|
|
// Note: Playback will already be stalled, as the next frame is
|
|
|
|
// unavailable.
|
2017-08-17 05:47:07 +03:00
|
|
|
mWaitingForKey = WAITING_FOR_KEY_DISPATCHED;
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waitingforkey"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mWaitingForKey == WAITING_FOR_KEY_DISPATCHED);
|
|
|
|
if (nextFrameStatus == NEXT_FRAME_AVAILABLE) {
|
|
|
|
// We have new frames after dispatching "waitingforkey".
|
|
|
|
// This means we've got the key and can reset mWaitingForKey now.
|
|
|
|
mWaitingForKey = NOT_WAITING_FOR_KEY;
|
2016-10-17 04:16:54 +03:00
|
|
|
}
|
2015-12-02 03:50:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_SEEKING) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"NEXT_FRAME_UNAVAILABLE_SEEKING; Forcing HAVE_METADATA",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_METADATA);
|
2014-09-24 11:25:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-23 18:01:24 +03:00
|
|
|
if (IsVideo() && VideoTracks() && !VideoTracks()->IsEmpty() &&
|
|
|
|
!IsPlaybackEnded() && GetImageContainer() &&
|
|
|
|
!GetImageContainer()->HasCurrentImage()) {
|
2014-10-10 13:34:57 +04:00
|
|
|
// Don't advance if we are playing video, but don't have a video frame.
|
|
|
|
// Also, if video became available after advancing to HAVE_CURRENT_DATA
|
|
|
|
// while we are still playing, we need to revert to HAVE_METADATA until
|
|
|
|
// a video frame is available.
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Playing video but no video frame; Forcing HAVE_METADATA",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_METADATA);
|
2014-10-10 13:34:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:54:51 +03:00
|
|
|
if (!mFirstFrameLoaded) {
|
|
|
|
// We haven't yet loaded the first frame, making us unable to determine
|
|
|
|
// if we have enough valid data at the present stage.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 23:41:33 +03:00
|
|
|
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
|
|
|
|
// Force HAVE_CURRENT_DATA when buffering.
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_CURRENT_DATA);
|
2016-12-07 23:41:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-21 10:44:00 +03:00
|
|
|
// TextTracks must be loaded for the HAVE_ENOUGH_DATA and
|
|
|
|
// HAVE_FUTURE_DATA.
|
|
|
|
// So force HAVE_CURRENT_DATA if text tracks not loaded.
|
|
|
|
if (mTextTrackManager && !mTextTrackManager->IsLoaded()) {
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_CURRENT_DATA);
|
2017-02-21 10:44:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:54:51 +03:00
|
|
|
if (mDownloadSuspendedByCache && mDecoder && !mDecoder->IsEnded()) {
|
2014-09-24 11:25:00 +04:00
|
|
|
// The decoder has signaled that the download has been suspended by the
|
2012-05-28 02:40:06 +04:00
|
|
|
// media cache. So move readyState into HAVE_ENOUGH_DATA, in case there's
|
|
|
|
// script waiting for a "canplaythrough" event; without this forced
|
|
|
|
// transition, we will never fire the "canplaythrough" event if the
|
|
|
|
// media cache is too small, and scripts are bound to fail. Don't force
|
|
|
|
// this transition if the decoder is in ended state; the readyState
|
|
|
|
// should remain at HAVE_CURRENT_DATA in this case.
|
2014-09-24 11:25:00 +04:00
|
|
|
// Note that this state transition includes the case where we finished
|
|
|
|
// downloaded the whole data stream.
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Decoder download suspended by cache",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_ENOUGH_DATA);
|
2012-05-28 02:40:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-02 03:50:21 +03:00
|
|
|
if (nextFrameStatus != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Next frame not available",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_CURRENT_DATA);
|
2015-10-22 09:40:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Stream HAVE_ENOUGH_DATA",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_ENOUGH_DATA);
|
2012-04-30 07:12:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 09:14:20 +04:00
|
|
|
// Now see if we should set HAVE_ENOUGH_DATA.
|
|
|
|
// If it's something we don't know the size of, then we can't
|
|
|
|
// make a real estimate, so we go straight to HAVE_ENOUGH_DATA once
|
|
|
|
// we've downloaded enough data that our download rate is considered
|
|
|
|
// reliable. We have to move to HAVE_ENOUGH_DATA at some point or
|
2010-07-23 02:48:32 +04:00
|
|
|
// autoplay elements for live streams will never play. Otherwise we
|
|
|
|
// move to HAVE_ENOUGH_DATA if we can play through the entire media
|
|
|
|
// without stopping to buffer.
|
2017-08-18 22:00:08 +03:00
|
|
|
if (mDecoder->CanPlayThrough()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Decoder can play through",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_ENOUGH_DATA);
|
2009-02-05 11:02:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
|
|
|
|
"Default; Decoder has future data",
|
|
|
|
this));
|
2018-02-15 06:23:32 +03:00
|
|
|
ChangeReadyState(HAVE_FUTURE_DATA);
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
static const char* const gReadyStateToString[] = {
|
|
|
|
"HAVE_NOTHING", "HAVE_METADATA", "HAVE_CURRENT_DATA", "HAVE_FUTURE_DATA",
|
|
|
|
"HAVE_ENOUGH_DATA"};
|
2009-03-19 02:59:34 +03:00
|
|
|
|
2017-10-17 09:18:27 +03:00
|
|
|
void HTMLMediaElement::ChangeReadyState(nsMediaReadyState aState) {
|
|
|
|
if (mReadyState == aState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-05 11:02:21 +03:00
|
|
|
nsMediaReadyState oldState = mReadyState;
|
2009-03-19 02:59:34 +03:00
|
|
|
mReadyState = aState;
|
2017-10-17 09:18:27 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Ready state changed to %s", this, gReadyStateToString[aState]));
|
2009-03-19 02:59:34 +03:00
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Property, "ready_state", gReadyStateToString[aState]);
|
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState == NETWORK_EMPTY) {
|
2009-03-19 02:59:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:58:07 +04:00
|
|
|
UpdateAudioChannelPlayingState();
|
|
|
|
|
2008-12-15 06:38:16 +03:00
|
|
|
// Handle raising of "waiting" event during seek (see 4.8.10.9)
|
2016-08-27 15:23:52 +03:00
|
|
|
// or
|
|
|
|
// 4.8.12.7 Ready states:
|
|
|
|
// "If the previous ready state was HAVE_FUTURE_DATA or more, and the new
|
|
|
|
// ready state is HAVE_CURRENT_DATA or less
|
|
|
|
// If the media element was potentially playing before its readyState
|
|
|
|
// attribute changed to a value lower than HAVE_FUTURE_DATA, and the element
|
|
|
|
// has not ended playback, and playback has not stopped due to errors,
|
|
|
|
// paused for user interaction, or paused for in-band content, the user agent
|
|
|
|
// must queue a task to fire a simple event named timeupdate at the element,
|
|
|
|
// and queue a task to fire a simple event named waiting at the element."
|
2018-05-14 12:11:18 +03:00
|
|
|
if (mPlayingBeforeSeek && mReadyState < HAVE_FUTURE_DATA) {
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
2018-05-14 12:11:18 +03:00
|
|
|
} else if (oldState >= HAVE_FUTURE_DATA && mReadyState < HAVE_FUTURE_DATA &&
|
2016-11-24 05:24:04 +03:00
|
|
|
!Paused() && !Ended() && !mErrorSink->mError) {
|
2016-08-27 15:23:52 +03:00
|
|
|
FireTimeUpdate(false);
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
2009-02-05 11:02:21 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (oldState < HAVE_CURRENT_DATA && mReadyState >= HAVE_CURRENT_DATA &&
|
2014-09-24 11:25:00 +04:00
|
|
|
!mLoadedDataFired) {
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadeddata"));
|
2014-09-24 11:25:00 +04:00
|
|
|
mLoadedDataFired = true;
|
2009-03-19 02:59:34 +03:00
|
|
|
}
|
2009-02-05 13:51:24 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (oldState < HAVE_FUTURE_DATA && mReadyState >= HAVE_FUTURE_DATA) {
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
|
2018-06-28 13:53:42 +03:00
|
|
|
if (!mPaused) {
|
2018-06-28 06:54:36 +03:00
|
|
|
if (mDecoder && !mPausedForInactiveDocumentOrChannel) {
|
2018-07-23 18:43:08 +03:00
|
|
|
MOZ_ASSERT(AutoplayPolicy::IsAllowedToPlay(*this));
|
2018-05-16 08:27:01 +03:00
|
|
|
mDecoder->Play();
|
2018-03-13 06:40:18 +03:00
|
|
|
}
|
2016-08-05 11:42:31 +03:00
|
|
|
NotifyAboutPlaying();
|
2016-09-23 09:03:50 +03:00
|
|
|
}
|
2009-03-19 02:59:34 +03:00
|
|
|
}
|
|
|
|
|
2013-03-20 15:11:48 +04:00
|
|
|
CheckAutoplayDataReady();
|
2009-11-06 10:32:52 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
if (oldState < HAVE_ENOUGH_DATA && mReadyState >= HAVE_ENOUGH_DATA) {
|
2010-09-10 07:29:06 +04:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("canplaythrough"));
|
2008-12-16 06:32:03 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
static const char* const gNetworkStateToString[] = {"EMPTY", "IDLE", "LOADING",
|
|
|
|
"NO_SOURCE"};
|
2014-09-24 11:26:00 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ChangeNetworkState(nsMediaNetworkState aState) {
|
2014-09-24 11:26:00 +04:00
|
|
|
if (mNetworkState == aState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaNetworkState oldState = mNetworkState;
|
|
|
|
mNetworkState = aState;
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Network state changed to %s", this, gNetworkStateToString[aState]));
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Property, "network_state",
|
|
|
|
gNetworkStateToString[aState]);
|
2014-09-24 11:26:00 +04:00
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (oldState == NETWORK_LOADING) {
|
2014-11-28 02:17:18 +03:00
|
|
|
// Stop progress notification when exiting NETWORK_LOADING.
|
|
|
|
StopProgress();
|
2014-09-24 11:26:00 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mNetworkState == NETWORK_LOADING) {
|
2014-11-28 02:17:18 +03:00
|
|
|
// Start progress notification when entering NETWORK_LOADING.
|
|
|
|
StartProgress();
|
2018-05-14 12:11:18 +03:00
|
|
|
} else if (mNetworkState == NETWORK_IDLE && !mErrorSink->mError) {
|
2014-09-24 11:26:00 +04:00
|
|
|
// Fire 'suspend' event when entering NETWORK_IDLE and no error presented.
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
|
|
|
|
}
|
2014-12-31 06:34:56 +03:00
|
|
|
|
|
|
|
// Changing mNetworkState affects AddRemoveSelfReference().
|
|
|
|
AddRemoveSelfReference();
|
2014-09-24 11:26:00 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::CanActivateAutoplay() {
|
2014-10-10 13:34:57 +04:00
|
|
|
// For stream inputs, we activate autoplay on HAVE_NOTHING because
|
2013-03-20 15:11:48 +04:00
|
|
|
// this element itself might be blocking the stream from making progress by
|
2016-09-14 11:04:26 +03:00
|
|
|
// being paused. We only check that it has data by checking its active state.
|
|
|
|
// We also activate autoplay when playing a media source since the data
|
|
|
|
// download is controlled by the script and there is no way to evaluate
|
|
|
|
// MediaDecoder::CanPlayThrough().
|
2016-04-06 10:30:06 +03:00
|
|
|
|
2017-11-13 13:43:55 +03:00
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
|
2016-04-06 10:30:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAutoplaying) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEditable()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPaused) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPausedForInactiveDocumentOrChannel) {
|
2017-11-13 13:43:55 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
// Static document is used for print preview and printing, should not be
|
|
|
|
// autoplay
|
2017-11-13 13:43:55 +03:00
|
|
|
if (OwnerDoc()->IsStaticDocument()) {
|
2016-04-06 10:30:06 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:01:36 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
2018-05-14 12:11:18 +03:00
|
|
|
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single
|
|
|
|
// state.
|
|
|
|
if (mAudioChannelWrapper->GetSuspendType() ==
|
|
|
|
nsISuspendedTypes::SUSPENDED_PAUSE ||
|
|
|
|
mAudioChannelWrapper->GetSuspendType() ==
|
|
|
|
nsISuspendedTypes::SUSPENDED_BLOCK ||
|
2016-11-30 11:01:36 +03:00
|
|
|
mAudioChannelWrapper->IsPlaybackBlocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-02 09:22:24 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool hasData = (mDecoder && mReadyState >= HAVE_ENOUGH_DATA) ||
|
|
|
|
(mSrcStream && mSrcStream->Active());
|
2016-04-06 10:30:06 +03:00
|
|
|
|
|
|
|
return hasData;
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::CheckAutoplayDataReady() {
|
2015-07-09 02:10:16 +03:00
|
|
|
if (!CanActivateAutoplay()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-01 18:10:13 +04:00
|
|
|
|
2018-07-25 19:08:44 +03:00
|
|
|
UpdateHadAudibleAutoplayState();
|
2018-07-23 18:43:08 +03:00
|
|
|
if (!AutoplayPolicy::IsAllowedToPlay(*this)) {
|
|
|
|
EnsureAutoplayRequested(false);
|
|
|
|
return;
|
2018-06-29 06:10:14 +03:00
|
|
|
}
|
|
|
|
|
2015-07-09 02:10:16 +03:00
|
|
|
mPaused = false;
|
|
|
|
// We changed mPaused which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2015-08-31 14:33:53 +03:00
|
|
|
UpdateSrcMediaStreamPlaying();
|
2015-11-23 14:35:14 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2015-07-09 02:10:16 +03:00
|
|
|
|
|
|
|
if (mDecoder) {
|
|
|
|
SetPlayedOrSeeked(true);
|
|
|
|
if (mCurrentPlayRangeStart == -1.0) {
|
|
|
|
mCurrentPlayRangeStart = CurrentTime();
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
2018-06-28 06:54:36 +03:00
|
|
|
MOZ_ASSERT(!mPausedForInactiveDocumentOrChannel);
|
2016-11-02 09:22:24 +03:00
|
|
|
mDecoder->Play();
|
2015-07-09 02:10:16 +03:00
|
|
|
} else if (mSrcStream) {
|
|
|
|
SetPlayedOrSeeked(true);
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
2015-07-09 02:10:16 +03:00
|
|
|
|
2016-08-29 11:34:26 +03:00
|
|
|
// For blocked media, the event would be pending until it is resumed.
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
|
2016-09-23 09:05:44 +03:00
|
|
|
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
|
2009-04-01 04:52:56 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsActive() const {
|
2015-01-22 07:01:12 +03:00
|
|
|
nsIDocument* ownerDoc = OwnerDoc();
|
|
|
|
return ownerDoc && ownerDoc->IsActive() && ownerDoc->IsVisible();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsHidden() const {
|
2016-09-23 09:51:52 +03:00
|
|
|
nsIDocument* ownerDoc;
|
|
|
|
return mUnboundFromTree || !(ownerDoc = OwnerDoc()) || ownerDoc->Hidden();
|
2015-01-22 07:01:12 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
VideoFrameContainer* HTMLMediaElement::GetVideoFrameContainer() {
|
2016-05-22 16:39:55 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-10 13:34:57 +04:00
|
|
|
if (mVideoFrameContainer) return mVideoFrameContainer;
|
2014-10-04 12:52:22 +04:00
|
|
|
|
2010-03-02 02:41:49 +03:00
|
|
|
// Only video frames need an image container.
|
2014-07-13 06:20:42 +04:00
|
|
|
if (!IsVideo()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-07-13 06:20:42 +04:00
|
|
|
}
|
2010-03-02 02:41:49 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
mVideoFrameContainer = new VideoFrameContainer(
|
|
|
|
this, LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS));
|
2012-07-13 23:38:09 +04:00
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
return mVideoFrameContainer;
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
void HTMLMediaElement::PrincipalChanged(DOMMediaStream* aStream) {
|
|
|
|
LOG(LogLevel::Info, ("HTMLMediaElement %p Stream principal changed.", this));
|
|
|
|
nsContentUtils::CombineResourcePrincipals(&mSrcStreamVideoPrincipal,
|
|
|
|
aStream->GetVideoPrincipal());
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("HTMLMediaElement %p Stream video principal changed to "
|
|
|
|
"%p. Waiting for it to reach VideoFrameContainer before "
|
|
|
|
"setting.",
|
|
|
|
this, aStream->GetVideoPrincipal()));
|
2016-01-26 10:36:52 +03:00
|
|
|
if (mVideoFrameContainer) {
|
2018-05-14 12:11:18 +03:00
|
|
|
UpdateSrcStreamVideoPrincipal(
|
|
|
|
mVideoFrameContainer->GetLastPrincipalHandle());
|
2016-01-26 10:36:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UpdateSrcStreamVideoPrincipal(
|
|
|
|
const PrincipalHandle& aPrincipalHandle) {
|
2016-02-04 04:27:09 +03:00
|
|
|
nsTArray<RefPtr<VideoStreamTrack>> videoTracks;
|
|
|
|
mSrcStream->GetVideoTracks(videoTracks);
|
|
|
|
|
|
|
|
PrincipalHandle handle(aPrincipalHandle);
|
|
|
|
bool matchesTrackPrincipal = false;
|
|
|
|
for (const RefPtr<VideoStreamTrack>& track : videoTracks) {
|
2018-05-14 12:11:18 +03:00
|
|
|
if (PrincipalHandleMatches(handle, track->GetPrincipal()) &&
|
2016-02-04 04:27:09 +03:00
|
|
|
!track->Ended()) {
|
|
|
|
// When the PrincipalHandle for the VideoFrameContainer changes to that of
|
|
|
|
// a track in mSrcStream we know that a removed track was displayed but
|
|
|
|
// is no longer so.
|
|
|
|
matchesTrackPrincipal = true;
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("HTMLMediaElement %p VideoFrameContainer's "
|
|
|
|
"PrincipalHandle matches track %p. That's all we "
|
|
|
|
"need.",
|
|
|
|
this, track.get()));
|
2016-02-04 04:27:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchesTrackPrincipal) {
|
|
|
|
mSrcStreamVideoPrincipal = mSrcStream->GetVideoPrincipal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::PrincipalHandleChangedForVideoFrameContainer(
|
|
|
|
VideoFrameContainer* aContainer,
|
|
|
|
const PrincipalHandle& aNewPrincipalHandle) {
|
2016-02-04 04:27:09 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mSrcStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("HTMLMediaElement %p PrincipalHandle changed in "
|
|
|
|
"VideoFrameContainer.",
|
|
|
|
this));
|
2016-02-04 04:27:09 +03:00
|
|
|
|
|
|
|
UpdateSrcStreamVideoPrincipal(aNewPrincipalHandle);
|
2016-01-26 10:36:52 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::DispatchEvent(const nsAString& aName) {
|
|
|
|
LOG_EVENT(LogLevel::Debug, ("%p Dispatching event %s", this,
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get()));
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2010-09-10 08:20:10 +04:00
|
|
|
// Save events that occur while in the bfcache. These will be dispatched
|
|
|
|
// if the page comes out of the bfcache.
|
2012-12-12 05:58:07 +04:00
|
|
|
if (mEventDeliveryPaused) {
|
2010-09-10 08:20:10 +04:00
|
|
|
mPendingEvents.AppendElement(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
return nsContentUtils::DispatchTrustedEvent(
|
2018-06-25 19:23:50 +03:00
|
|
|
OwnerDoc(), static_cast<nsIContent*>(this), aName, CanBubble::eNo,
|
|
|
|
Cancelable::eNo);
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2017-11-05 11:12:44 +03:00
|
|
|
void HTMLMediaElement::DispatchAsyncEvent(const nsAString& aName) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG_EVENT(LogLevel::Debug,
|
|
|
|
("%p Queuing event %s", this, NS_ConvertUTF16toUTF8(aName).get()));
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Event, "HTMLMediaElement",
|
|
|
|
nsCString(NS_ConvertUTF16toUTF8(aName)));
|
2009-09-30 01:32:44 +04:00
|
|
|
|
2014-01-31 22:14:17 +04:00
|
|
|
// Save events that occur while in the bfcache. These will be dispatched
|
|
|
|
// if the page comes out of the bfcache.
|
|
|
|
if (mEventDeliveryPaused) {
|
|
|
|
mPendingEvents.AppendElement(aName);
|
2017-11-05 11:12:44 +03:00
|
|
|
return;
|
2014-01-31 22:14:17 +04:00
|
|
|
}
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event;
|
|
|
|
|
|
|
|
if (aName.EqualsLiteral("playing")) {
|
|
|
|
event = new nsNotifyAboutPlayingRunner(this, TakePendingPlayPromises());
|
|
|
|
} else {
|
|
|
|
event = new nsAsyncEventRunner(aName, this);
|
|
|
|
}
|
|
|
|
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(event.forget());
|
2015-02-24 06:11:43 +03:00
|
|
|
|
|
|
|
if ((aName.EqualsLiteral("play") || aName.EqualsLiteral("playing"))) {
|
|
|
|
mPlayTime.Start();
|
2016-07-08 09:40:31 +03:00
|
|
|
if (IsHidden()) {
|
2016-08-08 05:14:39 +03:00
|
|
|
HiddenVideoStart();
|
2016-07-08 09:40:31 +03:00
|
|
|
}
|
2015-02-24 06:11:43 +03:00
|
|
|
} else if (aName.EqualsLiteral("waiting")) {
|
|
|
|
mPlayTime.Pause();
|
2016-08-08 05:14:39 +03:00
|
|
|
HiddenVideoStop();
|
2015-02-24 06:11:43 +03:00
|
|
|
} else if (aName.EqualsLiteral("pause")) {
|
|
|
|
mPlayTime.Pause();
|
2016-08-08 05:14:39 +03:00
|
|
|
HiddenVideoStop();
|
2015-02-24 06:11:43 +03:00
|
|
|
}
|
2008-07-09 12:22:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsresult HTMLMediaElement::DispatchPendingMediaEvents() {
|
2012-12-12 05:58:07 +04:00
|
|
|
NS_ASSERTION(!mEventDeliveryPaused,
|
2010-09-10 08:20:10 +04:00
|
|
|
"Must not be in bfcache when dispatching pending media events");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mPendingEvents.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-09-10 08:20:10 +04:00
|
|
|
DispatchAsyncEvent(mPendingEvents[i]);
|
|
|
|
}
|
|
|
|
mPendingEvents.Clear();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsPotentiallyPlaying() const {
|
2009-11-06 10:32:52 +03:00
|
|
|
// TODO:
|
|
|
|
// playback has not stopped due to errors,
|
2008-10-19 11:39:21 +04:00
|
|
|
// and the element has not paused for user interaction
|
2018-05-14 12:11:18 +03:00
|
|
|
return !mPaused &&
|
|
|
|
(mReadyState == HAVE_ENOUGH_DATA || mReadyState == HAVE_FUTURE_DATA) &&
|
|
|
|
!IsPlaybackEnded();
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
2008-12-14 21:02:54 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsPlaybackEnded() const {
|
2008-10-19 11:39:21 +04:00
|
|
|
// TODO:
|
2018-05-14 12:11:18 +03:00
|
|
|
// the current playback position is equal to the effective end of the media
|
|
|
|
// resource. See bug 449157.
|
2018-11-23 18:00:37 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
return mReadyState >= HAVE_METADATA && mDecoder->IsEnded();
|
|
|
|
} else if (mSrcStream) {
|
|
|
|
return mReadyState >= HAVE_METADATA && mSrcStreamPlaybackEnded;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
already_AddRefed<nsIPrincipal> HTMLMediaElement::GetCurrentPrincipal() {
|
2012-04-30 07:12:28 +04:00
|
|
|
if (mDecoder) {
|
|
|
|
return mDecoder->GetCurrentPrincipal();
|
|
|
|
}
|
2012-08-20 08:52:59 +04:00
|
|
|
if (mSrcStream) {
|
2016-01-26 10:36:52 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = mSrcStream->GetPrincipal();
|
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
already_AddRefed<nsIPrincipal> HTMLMediaElement::GetCurrentVideoPrincipal() {
|
2016-01-26 10:36:52 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
return mDecoder->GetCurrentPrincipal();
|
|
|
|
}
|
|
|
|
if (mSrcStream) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = mSrcStreamVideoPrincipal;
|
2012-04-30 07:12:28 +04:00
|
|
|
return principal.forget();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-09-07 03:47:28 +04:00
|
|
|
}
|
2008-09-26 16:56:21 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyDecoderPrincipalChanged() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIPrincipal> principal = GetCurrentPrincipal();
|
2013-07-24 13:55:23 +04:00
|
|
|
|
2015-01-29 10:30:38 +03:00
|
|
|
mDecoder->UpdateSameOriginStatus(!principal || IsCORSSameOrigin());
|
2012-04-30 07:12:42 +04:00
|
|
|
}
|
|
|
|
|
2017-11-13 06:09:23 +03:00
|
|
|
void HTMLMediaElement::Invalidate(bool aImageSizeChanged,
|
|
|
|
Maybe<nsIntSize>& aNewIntrinsicSize,
|
|
|
|
bool aForceInvalidate) {
|
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (aNewIntrinsicSize) {
|
|
|
|
UpdateMediaSize(aNewIntrinsicSize.value());
|
|
|
|
if (frame) {
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
|
|
|
presShell->FrameNeedsReflow(frame, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ImageContainer> imageContainer = GetImageContainer();
|
|
|
|
bool asyncInvalidate =
|
|
|
|
imageContainer && imageContainer->IsAsync() && !aForceInvalidate;
|
|
|
|
if (frame) {
|
|
|
|
if (aImageSizeChanged) {
|
|
|
|
frame->InvalidateFrame();
|
|
|
|
} else {
|
|
|
|
frame->InvalidateLayer(DisplayItemType::TYPE_VIDEO, nullptr, nullptr,
|
|
|
|
asyncInvalidate ? nsIFrame::UPDATE_IS_ASYNC : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UpdateMediaSize(const nsIntSize& aSize) {
|
2015-04-14 08:15:46 +03:00
|
|
|
if (IsVideo() && mReadyState != HAVE_NOTHING &&
|
|
|
|
mMediaInfo.mVideo.mDisplay != aSize) {
|
2014-12-04 04:01:00 +03:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("resize"));
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
mMediaInfo.mVideo.mDisplay = aSize;
|
2017-10-17 09:52:38 +03:00
|
|
|
UpdateReadyStateInternal();
|
2008-10-19 11:39:21 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::UpdateInitialMediaSize(const nsIntSize& aSize) {
|
2015-04-29 04:56:03 +03:00
|
|
|
if (!mMediaInfo.HasVideo()) {
|
2015-04-08 08:51:21 +03:00
|
|
|
UpdateMediaSize(aSize);
|
|
|
|
}
|
2016-01-29 06:10:19 +03:00
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
if (!mVideoFrameListener) {
|
2016-01-29 06:10:19 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-08-23 18:51:50 +03:00
|
|
|
|
|
|
|
if (!mSelectedVideoStreamTrack) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-23 18:00:43 +03:00
|
|
|
mSelectedVideoStreamTrack->RemoveDirectListener(mVideoFrameListener);
|
|
|
|
mVideoFrameListener->Forget();
|
|
|
|
mVideoFrameListener = nullptr;
|
2015-04-08 08:51:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement,
|
|
|
|
bool aSuspendEvents) {
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p SuspendOrResumeElement(pause=%d, suspendEvents=%d) hidden=%d", this,
|
|
|
|
aPauseElement, aSuspendEvents, OwnerDoc()->Hidden()));
|
2015-07-09 02:10:16 +03:00
|
|
|
|
2012-12-12 05:58:07 +04:00
|
|
|
if (aPauseElement != mPausedForInactiveDocumentOrChannel) {
|
|
|
|
mPausedForInactiveDocumentOrChannel = aPauseElement;
|
2015-08-31 14:33:53 +03:00
|
|
|
UpdateSrcMediaStreamPlaying();
|
2015-11-23 14:35:14 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2012-12-12 05:58:07 +04:00
|
|
|
if (aPauseElement) {
|
2016-07-19 07:33:55 +03:00
|
|
|
ReportTelemetry();
|
2015-02-13 08:02:35 +03:00
|
|
|
|
2016-10-31 00:55:19 +03:00
|
|
|
// For EME content, we may force destruction of the CDM client (and CDM
|
2014-08-18 01:41:50 +04:00
|
|
|
// instance if this is the last client for that CDM instance) and
|
|
|
|
// the CDM's decoder. This ensures the CDM gets reliable and prompt
|
|
|
|
// shutdown notifications, as it may have book-keeping it needs
|
|
|
|
// to do on shutdown.
|
|
|
|
if (mMediaKeys) {
|
2016-10-31 00:55:19 +03:00
|
|
|
nsAutoString keySystem;
|
|
|
|
mMediaKeys->GetKeySystem(keySystem);
|
2014-08-18 01:41:50 +04:00
|
|
|
}
|
2012-04-30 07:12:28 +04:00
|
|
|
if (mDecoder) {
|
2009-10-01 18:10:13 +04:00
|
|
|
mDecoder->Pause();
|
|
|
|
mDecoder->Suspend();
|
2012-04-30 07:12:28 +04:00
|
|
|
}
|
2012-12-12 05:58:07 +04:00
|
|
|
mEventDeliveryPaused = aSuspendEvents;
|
2012-04-30 07:12:28 +04:00
|
|
|
} else {
|
|
|
|
if (mDecoder) {
|
2016-01-12 03:04:32 +03:00
|
|
|
mDecoder->Resume();
|
2016-08-01 10:22:32 +03:00
|
|
|
if (!mPaused && !mDecoder->IsEnded()) {
|
2009-10-01 18:10:13 +04:00
|
|
|
mDecoder->Play();
|
|
|
|
}
|
|
|
|
}
|
2012-12-12 05:58:07 +04:00
|
|
|
if (mEventDeliveryPaused) {
|
|
|
|
mEventDeliveryPaused = false;
|
2013-01-14 02:46:50 +04:00
|
|
|
DispatchPendingMediaEvents();
|
2012-12-12 05:58:07 +04:00
|
|
|
}
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
2008-10-28 21:48:39 +03:00
|
|
|
}
|
2012-12-12 05:58:07 +04:00
|
|
|
}
|
2009-01-22 02:54:40 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
bool HTMLMediaElement::IsBeingDestroyed() {
|
2012-12-12 05:58:07 +04:00
|
|
|
nsIDocument* ownerDoc = OwnerDoc();
|
2015-02-13 08:02:35 +03:00
|
|
|
nsIDocShell* docShell = ownerDoc ? ownerDoc->GetDocShell() : nullptr;
|
|
|
|
bool isBeingDestroyed = false;
|
|
|
|
if (docShell) {
|
|
|
|
docShell->IsBeingDestroyed(&isBeingDestroyed);
|
|
|
|
}
|
|
|
|
return isBeingDestroyed;
|
|
|
|
}
|
2013-06-10 16:22:05 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyOwnerDocumentActivityChanged() {
|
2016-07-08 09:40:31 +03:00
|
|
|
bool visible = !IsHidden();
|
|
|
|
if (visible) {
|
|
|
|
// Visible -> Just pause hidden play time (no-op if already paused).
|
2016-08-08 05:14:39 +03:00
|
|
|
HiddenVideoStop();
|
2016-07-08 09:40:31 +03:00
|
|
|
} else if (mPlayTime.IsStarted()) {
|
|
|
|
// Not visible, play time is running -> Start hidden play time if needed.
|
2016-08-08 05:14:39 +03:00
|
|
|
HiddenVideoStart();
|
2016-07-08 09:40:31 +03:00
|
|
|
}
|
|
|
|
|
2015-02-13 08:02:35 +03:00
|
|
|
if (mDecoder && !IsBeingDestroyed()) {
|
2017-03-11 13:25:41 +03:00
|
|
|
NotifyDecoderActivityChanges();
|
2013-06-10 16:22:05 +04:00
|
|
|
}
|
|
|
|
|
2016-08-29 11:34:26 +03:00
|
|
|
bool pauseElement = ShouldElementBePaused();
|
2015-01-22 07:01:12 +03:00
|
|
|
SuspendOrResumeElement(pauseElement, !IsActive());
|
2012-12-04 23:46:07 +04:00
|
|
|
|
2016-11-14 05:02:48 +03:00
|
|
|
// If the owning document has become inactive we should shutdown the CDM.
|
|
|
|
if (!OwnerDoc()->IsCurrentActiveDocument() && mMediaKeys) {
|
2018-05-14 12:11:18 +03:00
|
|
|
mMediaKeys->Shutdown();
|
|
|
|
DDUNLINKCHILD(mMediaKeys.get());
|
|
|
|
mMediaKeys = nullptr;
|
|
|
|
if (mDecoder) {
|
|
|
|
ShutdownDecoder();
|
2016-11-14 05:02:48 +03:00
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
}
|
2016-11-14 05:02:48 +03:00
|
|
|
|
2009-10-01 18:10:13 +04:00
|
|
|
AddRemoveSelfReference();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::AddRemoveSelfReference() {
|
2009-10-01 18:10:13 +04:00
|
|
|
// XXX we could release earlier here in many situations if we examined
|
|
|
|
// which event listeners are attached. Right now we assume there is a
|
|
|
|
// potential listener for every event. We would also have to keep the
|
|
|
|
// element alive if it was playing and producing audio output --- right now
|
|
|
|
// that's covered by the !mPaused check.
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* ownerDoc = OwnerDoc();
|
2009-10-01 18:10:13 +04:00
|
|
|
|
|
|
|
// See the comment at the top of this file for the explanation of this
|
|
|
|
// boolean expression.
|
2018-05-14 12:11:18 +03:00
|
|
|
bool needSelfReference =
|
|
|
|
!mShuttingDown && ownerDoc->IsActive() &&
|
2018-11-23 18:03:21 +03:00
|
|
|
(mDelayingLoadEvent || (!mPaused && !Ended()) ||
|
|
|
|
(mDecoder && mDecoder->IsSeeking()) || CanActivateAutoplay() ||
|
2018-05-14 12:11:18 +03:00
|
|
|
(mMediaSource ? mProgressTimer : mNetworkState == NETWORK_LOADING));
|
2009-10-01 18:10:13 +04:00
|
|
|
|
|
|
|
if (needSelfReference != mHasSelfReference) {
|
|
|
|
mHasSelfReference = needSelfReference;
|
2018-11-15 15:48:11 +03:00
|
|
|
RefPtr<HTMLMediaElement> self = this;
|
2009-10-01 18:10:13 +04:00
|
|
|
if (needSelfReference) {
|
2016-05-22 16:39:55 +03:00
|
|
|
// The shutdown observer will hold a strong reference to us. This
|
2010-02-24 22:14:14 +03:00
|
|
|
// will do to keep us alive. We need to know about shutdown so that
|
|
|
|
// we can release our self-reference.
|
2018-11-15 15:48:11 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLMediaElement::AddSelfReference",
|
|
|
|
[self]() { self->mShutdownObserver->AddRefMediaElement(); }));
|
2009-10-01 18:10:13 +04:00
|
|
|
} else {
|
|
|
|
// Dispatch Release asynchronously so that we don't destroy this object
|
|
|
|
// inside a call stack of method calls on this object
|
2018-11-15 15:48:11 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLMediaElement::AddSelfReference",
|
|
|
|
[self]() { self->mShutdownObserver->ReleaseMediaElement(); }));
|
2009-10-01 18:10:13 +04:00
|
|
|
}
|
2009-01-22 02:54:40 +03:00
|
|
|
}
|
2008-10-28 21:48:39 +03:00
|
|
|
}
|
2009-02-16 04:05:28 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyShutdownEvent() {
|
2016-05-22 16:39:55 +03:00
|
|
|
mShuttingDown = true;
|
2018-09-17 19:54:17 +03:00
|
|
|
// Since target thread had been shutdown, it's no chance to execute the Then()
|
|
|
|
// afterward. Therefore, we should disconnect the request.
|
|
|
|
mAutoplayPermissionRequest.DisconnectIfExists();
|
2016-05-22 16:39:55 +03:00
|
|
|
ResetState();
|
|
|
|
AddRemoveSelfReference();
|
2010-02-24 22:14:14 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::DispatchAsyncSourceError(nsIContent* aSourceElement) {
|
2015-06-04 01:25:57 +03:00
|
|
|
LOG_EVENT(LogLevel::Debug, ("%p Queuing simple source error event", this));
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new nsSourceErrorEventRunner(this, aSourceElement);
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(event.forget());
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::NotifyAddedSource() {
|
2010-09-03 04:03:03 +04:00
|
|
|
// If a source element is inserted as a child of a media element
|
|
|
|
// that has no src attribute and whose networkState has the value
|
|
|
|
// NETWORK_EMPTY, the user agent must invoke the media element's
|
|
|
|
// resource selection algorithm.
|
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
|
2018-05-14 12:11:18 +03:00
|
|
|
mNetworkState == NETWORK_EMPTY) {
|
2017-10-12 05:46:13 +03:00
|
|
|
AssertReadyStateIsNothing();
|
2009-03-08 23:59:08 +03:00
|
|
|
QueueSelectResourceTask();
|
2010-09-03 04:03:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// A load was paused in the resource selection algorithm, waiting for
|
2012-05-01 04:29:24 +04:00
|
|
|
// a new source child to be added, resume the resource selection algorithm.
|
2010-09-03 04:03:03 +04:00
|
|
|
if (mLoadWaitStatus == WAITING_FOR_SOURCE) {
|
2015-12-21 14:55:43 +03:00
|
|
|
// Rest the flag so we don't queue multiple LoadFromSourceTask() when
|
|
|
|
// multiple <source> are attached in an event loop.
|
|
|
|
mLoadWaitStatus = NOT_WAITING;
|
2009-03-08 23:59:08 +03:00
|
|
|
QueueLoadFromSourceTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
Element* HTMLMediaElement::GetNextSource() {
|
2012-07-30 18:20:58 +04:00
|
|
|
mSourceLoadCandidate = nullptr;
|
2010-09-03 04:03:03 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
while (true) {
|
2017-07-10 20:53:48 +03:00
|
|
|
if (mSourcePointer == nsINode::GetLastChild()) {
|
|
|
|
return nullptr; // no more children
|
|
|
|
}
|
2009-03-08 23:59:08 +03:00
|
|
|
|
2017-07-10 20:53:48 +03:00
|
|
|
if (!mSourcePointer) {
|
|
|
|
mSourcePointer = nsINode::GetFirstChild();
|
|
|
|
} else {
|
|
|
|
mSourcePointer = mSourcePointer->GetNextSibling();
|
|
|
|
}
|
|
|
|
nsIContent* child = mSourcePointer;
|
2009-03-08 23:59:08 +03:00
|
|
|
|
2010-09-03 04:03:03 +04:00
|
|
|
// If child is a <source> element, it is the next candidate.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child && child->IsHTMLElement(nsGkAtoms::source)) {
|
2010-09-03 04:03:03 +04:00
|
|
|
mSourceLoadCandidate = child;
|
2017-12-07 21:13:50 +03:00
|
|
|
return child->AsElement();
|
2009-03-08 23:59:08 +03:00
|
|
|
}
|
2009-02-16 04:05:28 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Execution should not reach here!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-02-16 04:05:28 +03:00
|
|
|
}
|
2009-03-09 00:01:03 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::ChangeDelayLoadStatus(bool aDelay) {
|
2009-03-09 00:01:03 +03:00
|
|
|
if (mDelayingLoadEvent == aDelay) return;
|
|
|
|
|
|
|
|
mDelayingLoadEvent = aDelay;
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p ChangeDelayLoadStatus(%d) doc=0x%p", this, aDelay,
|
|
|
|
mLoadBlockedDoc.get()));
|
2014-12-23 04:16:05 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->SetLoadInBackground(!aDelay);
|
|
|
|
}
|
2009-03-09 00:01:03 +03:00
|
|
|
if (aDelay) {
|
2011-10-18 14:53:36 +04:00
|
|
|
mLoadBlockedDoc = OwnerDoc();
|
2009-03-09 00:01:03 +03:00
|
|
|
mLoadBlockedDoc->BlockOnload();
|
|
|
|
} else {
|
2010-02-24 22:14:14 +03:00
|
|
|
// mLoadBlockedDoc might be null due to GC unlinking
|
|
|
|
if (mLoadBlockedDoc) {
|
2011-09-30 03:34:37 +04:00
|
|
|
mLoadBlockedDoc->UnblockOnload(false);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadBlockedDoc = nullptr;
|
2010-02-24 22:14:14 +03:00
|
|
|
}
|
2009-03-09 00:01:03 +03:00
|
|
|
}
|
2009-10-01 18:10:13 +04:00
|
|
|
|
|
|
|
// We changed mDelayingLoadEvent which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2009-03-09 00:01:03 +03:00
|
|
|
}
|
2009-04-10 05:28:24 +04:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
already_AddRefed<nsILoadGroup> HTMLMediaElement::GetDocumentLoadGroup() {
|
2012-02-24 05:07:35 +04:00
|
|
|
if (!OwnerDoc()->IsActive()) {
|
|
|
|
NS_WARNING("Load group requested for media element in inactive document.");
|
|
|
|
}
|
2011-10-18 15:19:44 +04:00
|
|
|
return OwnerDoc()->GetDocumentLoadGroup();
|
2009-04-10 05:28:24 +04:00
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult HTMLMediaElement::CopyInnerTo(Element* aDest) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-18 14:53:36 +04:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2013-03-19 16:23:54 +04:00
|
|
|
HTMLMediaElement* dest = static_cast<HTMLMediaElement*>(aDest);
|
2016-08-29 13:56:32 +03:00
|
|
|
dest->SetMediaInfo(mMediaInfo);
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
already_AddRefed<TimeRanges> HTMLMediaElement::Buffered() const {
|
2017-08-21 06:08:25 +03:00
|
|
|
media::TimeIntervals buffered =
|
|
|
|
mDecoder ? mDecoder->GetBuffered() : media::TimeIntervals();
|
|
|
|
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()), buffered);
|
2013-03-19 16:25:19 +04:00
|
|
|
return ranges.forget();
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SetRequestHeaders(nsIHttpChannel* aChannel) {
|
2010-09-16 21:36:23 +04:00
|
|
|
// Send Accept header for video and audio types only (Bug 489071)
|
|
|
|
SetAcceptHeader(aChannel);
|
|
|
|
|
2010-11-29 00:21:27 +03:00
|
|
|
// Apache doesn't send Content-Length when gzip transfer encoding is used,
|
2018-05-14 12:11:18 +03:00
|
|
|
// which prevents us from estimating the video length (if explicit
|
|
|
|
// Content-Duration and a length spec in the container are not present either)
|
|
|
|
// and from seeking. So, disable the standard "Accept-Encoding: gzip,deflate"
|
|
|
|
// that we usually send. See bug 614760.
|
|
|
|
DebugOnly<nsresult> rv = aChannel->SetRequestHeader(
|
|
|
|
NS_LITERAL_CSTRING("Accept-Encoding"), EmptyCString(), false);
|
2016-12-20 06:49:32 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2010-11-29 00:21:27 +03:00
|
|
|
|
2010-09-16 21:36:23 +04:00
|
|
|
// Set the Referer header
|
2016-12-20 06:49:32 +03:00
|
|
|
rv = aChannel->SetReferrerWithPolicy(OwnerDoc()->GetDocumentURI(),
|
|
|
|
OwnerDoc()->GetReferrerPolicy());
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2010-09-16 21:36:23 +04:00
|
|
|
}
|
2010-11-24 21:34:57 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::FireTimeUpdate(bool aPeriodic) {
|
2010-11-24 21:34:57 +03:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
2013-03-19 16:25:19 +04:00
|
|
|
double time = CurrentTime();
|
2010-11-24 21:34:57 +03:00
|
|
|
|
2012-04-30 07:12:28 +04:00
|
|
|
// Fire a timeupdate event if this is not a periodic update (i.e. it's a
|
2010-11-24 21:34:57 +03:00
|
|
|
// timeupdate event mandated by the spec), or if it's a periodic update
|
|
|
|
// and TIMEUPDATE_MS has passed since the last timeupdate event fired and
|
|
|
|
// the time has changed.
|
2018-05-14 12:11:18 +03:00
|
|
|
if (!aPeriodic || (mLastCurrentTime != time &&
|
|
|
|
(mTimeUpdateTime.IsNull() ||
|
|
|
|
now - mTimeUpdateTime >=
|
|
|
|
TimeDuration::FromMilliseconds(TIMEUPDATE_MS)))) {
|
2010-11-24 21:34:57 +03:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("timeupdate"));
|
|
|
|
mTimeUpdateTime = now;
|
|
|
|
mLastCurrentTime = time;
|
|
|
|
}
|
2011-08-25 03:42:23 +04:00
|
|
|
if (mFragmentEnd >= 0.0 && time >= mFragmentEnd) {
|
|
|
|
Pause();
|
|
|
|
mFragmentEnd = -1.0;
|
|
|
|
mFragmentStart = -1.0;
|
2012-11-19 19:11:21 +04:00
|
|
|
mDecoder->SetFragmentEndTime(mFragmentEnd);
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2013-12-12 21:02:17 +04:00
|
|
|
// Update the cues displaying on the video.
|
2013-10-23 22:45:00 +04:00
|
|
|
// Here mTextTrackManager can be null if the cycle collector has unlinked
|
2013-05-21 20:14:00 +04:00
|
|
|
// us before our parent. In that case UnbindFromTree will call us
|
|
|
|
// when our parent is unlinked.
|
2013-10-23 22:45:00 +04:00
|
|
|
if (mTextTrackManager) {
|
2016-06-01 12:37:26 +03:00
|
|
|
mTextTrackManager->TimeMarchesOn();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
MediaStream* HTMLMediaElement::GetSrcMediaStream() const {
|
2016-06-29 13:27:13 +03:00
|
|
|
if (!mSrcStream) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mSrcStream->GetPlaybackStream();
|
|
|
|
}
|
|
|
|
|
2016-11-24 05:24:04 +03:00
|
|
|
MediaError* HTMLMediaElement::GetError() const { return mErrorSink->mError; }
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::GetCurrentSpec(nsCString& aString) {
|
2011-11-25 06:06:22 +04:00
|
|
|
if (mLoadingSrc) {
|
2011-08-25 03:42:23 +04:00
|
|
|
mLoadingSrc->GetSpec(aString);
|
2011-11-25 06:06:22 +04:00
|
|
|
} else {
|
|
|
|
aString.Truncate();
|
2011-08-25 03:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:25:19 +04:00
|
|
|
double HTMLMediaElement::MozFragmentEnd() {
|
|
|
|
double duration = Duration();
|
2011-08-25 03:42:23 +04:00
|
|
|
|
|
|
|
// If there is no end fragment, or the fragment end is greater than the
|
|
|
|
// duration, return the duration.
|
2018-05-14 12:11:18 +03:00
|
|
|
return (mFragmentEnd < 0.0 || mFragmentEnd > duration) ? duration
|
|
|
|
: mFragmentEnd;
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
void HTMLMediaElement::SetDefaultPlaybackRate(double aDefaultPlaybackRate,
|
|
|
|
ErrorResult& aRv) {
|
2012-11-22 14:38:28 +04:00
|
|
|
if (aDefaultPlaybackRate < 0) {
|
2013-03-19 16:25:19 +04:00
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDefaultPlaybackRate = ClampPlaybackRate(aDefaultPlaybackRate);
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("ratechange"));
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::SetPlaybackRate(double aPlaybackRate, ErrorResult& aRv) {
|
2013-03-04 18:48:58 +04:00
|
|
|
// Changing the playback rate of a media that has more than two channels is
|
|
|
|
// not supported.
|
2014-04-03 01:53:39 +04:00
|
|
|
if (aPlaybackRate < 0) {
|
2017-08-24 11:58:42 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2013-03-19 16:25:19 +04:00
|
|
|
return;
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
2017-08-24 11:58:45 +03:00
|
|
|
if (mPlaybackRate == aPlaybackRate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPlaybackRate = aPlaybackRate;
|
2012-11-22 14:38:28 +04:00
|
|
|
|
2014-09-01 08:52:39 +04:00
|
|
|
if (mPlaybackRate != 0.0 &&
|
2017-08-24 11:58:42 +03:00
|
|
|
(mPlaybackRate > THRESHOLD_HIGH_PLAYBACKRATE_AUDIO ||
|
2014-09-01 08:52:39 +04:00
|
|
|
mPlaybackRate < THRESHOLD_LOW_PLAYBACKRATE_AUDIO)) {
|
2013-05-21 21:49:17 +04:00
|
|
|
SetMutedInternal(mMuted | MUTED_BY_INVALID_PLAYBACK_RATE);
|
|
|
|
} else {
|
|
|
|
SetMutedInternal(mMuted & ~MUTED_BY_INVALID_PLAYBACK_RATE);
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mDecoder) {
|
2017-08-24 11:58:45 +03:00
|
|
|
mDecoder->SetPlaybackRate(ClampPlaybackRate(mPlaybackRate));
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("ratechange"));
|
2013-03-19 16:25:19 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
void HTMLMediaElement::SetMozPreservesPitch(bool aPreservesPitch) {
|
2012-11-22 14:38:28 +04:00
|
|
|
mPreservesPitch = aPreservesPitch;
|
2013-02-26 12:51:59 +04:00
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->SetPreservesPitch(mPreservesPitch);
|
|
|
|
}
|
2012-11-22 14:38:28 +04:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:22:38 +03:00
|
|
|
ImageContainer* HTMLMediaElement::GetImageContainer() {
|
2012-11-14 23:45:31 +04:00
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
|
|
|
return container ? container->GetImageContainer() : nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:22:24 +03:00
|
|
|
void HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying) {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
|
|
|
mAudioChannelWrapper->UpdateAudioChannelPlayingState(aForcePlaying);
|
2016-11-29 00:16:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:16:13 +03:00
|
|
|
bool HTMLMediaElement::AudioChannelAgentBlockedPlay() {
|
|
|
|
if (!mAudioChannelWrapper) {
|
|
|
|
// If the mAudioChannelWrapper doesn't exist that means the CC happened.
|
2018-02-15 06:39:44 +03:00
|
|
|
LOG(LogLevel::Debug,
|
2018-06-26 05:16:13 +03:00
|
|
|
("%p AudioChannelAgentBlockedPlay() returning true due to null "
|
|
|
|
"AudioChannelAgent.",
|
|
|
|
this));
|
2016-11-30 11:01:36 +03:00
|
|
|
return true;
|
2016-11-29 07:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-06-26 05:16:13 +03:00
|
|
|
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single
|
|
|
|
// state.
|
|
|
|
const auto suspendType = mAudioChannelWrapper->GetSuspendType();
|
|
|
|
return suspendType == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
|
|
|
suspendType == nsISuspendedTypes::SUSPENDED_BLOCK;
|
2016-11-29 00:16:31 +03:00
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
static const char* VisibilityString(Visibility aVisibility) {
|
|
|
|
switch (aVisibility) {
|
2016-07-04 08:26:40 +03:00
|
|
|
case Visibility::UNTRACKED: {
|
|
|
|
return "UNTRACKED";
|
|
|
|
}
|
|
|
|
case Visibility::APPROXIMATELY_NONVISIBLE: {
|
|
|
|
return "APPROXIMATELY_NONVISIBLE";
|
|
|
|
}
|
|
|
|
case Visibility::APPROXIMATELY_VISIBLE: {
|
|
|
|
return "APPROXIMATELY_VISIBLE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "NAN";
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::OnVisibilityChange(Visibility aNewVisibility) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("OnVisibilityChange(): %s\n", VisibilityString(aNewVisibility)));
|
2016-07-04 08:26:40 +03:00
|
|
|
|
2016-09-02 11:52:44 +03:00
|
|
|
mVisibilityState = aNewVisibility;
|
2018-12-21 09:40:10 +03:00
|
|
|
if (StaticPrefs::MediaTestVideoSuspend()) {
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("visibilitychanged"));
|
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
|
2016-07-04 08:26:40 +03:00
|
|
|
if (!mDecoder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aNewVisibility) {
|
|
|
|
case Visibility::UNTRACKED: {
|
2018-05-14 12:11:18 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility");
|
|
|
|
return;
|
2016-07-04 08:26:40 +03:00
|
|
|
}
|
|
|
|
case Visibility::APPROXIMATELY_NONVISIBLE: {
|
2016-08-30 09:53:04 +03:00
|
|
|
if (mPlayTime.IsStarted()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
// Not visible, play time is running -> Start hidden play time if
|
|
|
|
// needed.
|
2016-08-30 09:53:04 +03:00
|
|
|
HiddenVideoStart();
|
|
|
|
}
|
2016-07-04 08:26:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Visibility::APPROXIMATELY_VISIBLE: {
|
2016-08-30 09:53:04 +03:00
|
|
|
// Visible -> Just pause hidden play time (no-op if already paused).
|
|
|
|
HiddenVideoStop();
|
2016-07-04 08:26:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-11 13:25:41 +03:00
|
|
|
NotifyDecoderActivityChanges();
|
2016-07-04 08:26:40 +03:00
|
|
|
}
|
2016-09-08 13:06:20 +03:00
|
|
|
|
2014-06-07 00:52:15 +04:00
|
|
|
MediaKeys* HTMLMediaElement::GetMediaKeys() const { return mMediaKeys; }
|
|
|
|
|
2014-10-28 03:21:12 +03:00
|
|
|
bool HTMLMediaElement::ContainsRestrictedContent() {
|
|
|
|
return GetMediaKeys() != nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
void HTMLMediaElement::SetCDMProxyFailure(const MediaResult& aResult) {
|
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
|
|
|
MOZ_ASSERT(mSetMediaKeysDOMPromise);
|
|
|
|
|
|
|
|
ResetSetMediaKeysTempVariables();
|
|
|
|
|
|
|
|
mSetMediaKeysDOMPromise->MaybeReject(aResult.Code(), aResult.Message());
|
|
|
|
}
|
|
|
|
|
2017-11-03 09:35:32 +03:00
|
|
|
void HTMLMediaElement::RemoveMediaKeys() {
|
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
|
|
|
// 5.2.3 Stop using the CDM instance represented by the mediaKeys attribute
|
|
|
|
// to decrypt media data and remove the association with the media element.
|
2017-11-28 18:06:34 +03:00
|
|
|
if (mMediaKeys) {
|
|
|
|
mMediaKeys->Unbind();
|
|
|
|
}
|
2017-11-03 09:35:32 +03:00
|
|
|
mMediaKeys = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
bool HTMLMediaElement::TryRemoveMediaKeysAssociation() {
|
2017-11-03 09:35:32 +03:00
|
|
|
MOZ_ASSERT(mMediaKeys);
|
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
|
|
|
// 5.2.1 If the user agent or CDM do not support removing the association,
|
|
|
|
// let this object's attaching media keys value be false and reject promise
|
|
|
|
// with a new DOMException whose name is NotSupportedError.
|
|
|
|
// 5.2.2 If the association cannot currently be removed, let this object's
|
|
|
|
// attaching media keys value be false and reject promise with a new
|
|
|
|
// DOMException whose name is InvalidStateError.
|
|
|
|
if (mDecoder) {
|
2017-11-03 15:14:17 +03:00
|
|
|
RefPtr<HTMLMediaElement> self = this;
|
|
|
|
mDecoder->SetCDMProxy(nullptr)
|
|
|
|
->Then(mAbstractMainThread, __func__,
|
|
|
|
[self]() {
|
|
|
|
self->mSetCDMRequest.Complete();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
self->RemoveMediaKeys();
|
|
|
|
if (self->AttachNewMediaKeys()) {
|
2018-05-14 12:11:18 +03:00
|
|
|
// No incoming MediaKeys object or MediaDecoder is not
|
|
|
|
// created yet.
|
2017-11-03 15:14:17 +03:00
|
|
|
self->MakeAssociationWithCDMResolved();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aResult) {
|
|
|
|
self->mSetCDMRequest.Complete();
|
2018-05-14 12:11:18 +03:00
|
|
|
// 5.2.4 If the preceding step failed, let this object's
|
|
|
|
// attaching media keys value be false and reject promise with
|
|
|
|
// a new DOMException whose name is the appropriate error name.
|
2017-11-03 15:14:17 +03:00
|
|
|
self->SetCDMProxyFailure(aResult);
|
|
|
|
})
|
|
|
|
->Track(mSetCDMRequest);
|
2017-11-03 09:35:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
RemoveMediaKeys();
|
2017-11-03 09:35:32 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
bool HTMLMediaElement::DetachExistingMediaKeys() {
|
2017-11-03 09:35:32 +03:00
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
2017-11-03 15:14:17 +03:00
|
|
|
MOZ_ASSERT(mSetMediaKeysDOMPromise);
|
2017-11-03 09:35:32 +03:00
|
|
|
// 5.1 If mediaKeys is not null, CDM instance represented by mediaKeys is
|
|
|
|
// already in use by another media element, and the user agent is unable
|
|
|
|
// to use it with this element, let this object's attaching media keys
|
|
|
|
// value be false and reject promise with a new DOMException whose name
|
|
|
|
// is QuotaExceededError.
|
|
|
|
if (mIncomingMediaKeys && mIncomingMediaKeys->IsBoundToMediaElement()) {
|
2017-11-03 15:14:17 +03:00
|
|
|
SetCDMProxyFailure(MediaResult(
|
2017-11-03 09:35:32 +03:00
|
|
|
NS_ERROR_DOM_QUOTA_EXCEEDED_ERR,
|
2017-11-03 15:14:17 +03:00
|
|
|
"MediaKeys object is already bound to another HTMLMediaElement"));
|
2017-11-03 09:35:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5.2 If the mediaKeys attribute is not null, run the following steps:
|
|
|
|
if (mMediaKeys) {
|
2017-11-03 15:14:17 +03:00
|
|
|
return TryRemoveMediaKeysAssociation();
|
2017-11-03 09:35:32 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
void HTMLMediaElement::MakeAssociationWithCDMResolved() {
|
2017-11-03 09:35:32 +03:00
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
2017-11-03 15:14:17 +03:00
|
|
|
MOZ_ASSERT(mSetMediaKeysDOMPromise);
|
2017-11-03 09:35:32 +03:00
|
|
|
|
|
|
|
// 5.4 Set the mediaKeys attribute to mediaKeys.
|
|
|
|
mMediaKeys = mIncomingMediaKeys;
|
|
|
|
// 5.5 Let this object's attaching media keys value be false.
|
|
|
|
ResetSetMediaKeysTempVariables();
|
|
|
|
// 5.6 Resolve promise.
|
2017-11-03 15:14:17 +03:00
|
|
|
mSetMediaKeysDOMPromise->MaybeResolveWithUndefined();
|
|
|
|
mSetMediaKeysDOMPromise = nullptr;
|
2017-11-03 09:35:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLMediaElement::TryMakeAssociationWithCDM(CDMProxy* aProxy) {
|
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
2017-11-03 15:14:17 +03:00
|
|
|
MOZ_ASSERT(aProxy);
|
|
|
|
|
2017-11-03 09:35:32 +03:00
|
|
|
// 5.3.3 Queue a task to run the "Attempt to Resume Playback If Necessary"
|
|
|
|
// algorithm on the media element.
|
|
|
|
// Note: Setting the CDMProxy on the MediaDecoder will unblock playback.
|
|
|
|
if (mDecoder) {
|
2017-11-03 15:14:17 +03:00
|
|
|
// CDMProxy is set asynchronously in MediaFormatReader, once it's done,
|
|
|
|
// HTMLMediaElement should resolve or reject the DOM promise.
|
|
|
|
RefPtr<HTMLMediaElement> self = this;
|
|
|
|
mDecoder->SetCDMProxy(aProxy)
|
|
|
|
->Then(mAbstractMainThread, __func__,
|
|
|
|
[self]() {
|
|
|
|
self->mSetCDMRequest.Complete();
|
|
|
|
self->MakeAssociationWithCDMResolved();
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aResult) {
|
|
|
|
self->mSetCDMRequest.Complete();
|
|
|
|
self->SetCDMProxyFailure(aResult);
|
|
|
|
})
|
|
|
|
->Track(mSetCDMRequest);
|
|
|
|
return false;
|
2017-11-03 09:35:32 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
bool HTMLMediaElement::AttachNewMediaKeys() {
|
2017-11-03 09:35:32 +03:00
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%s incoming MediaKeys(%p)", __func__, mIncomingMediaKeys.get()));
|
2017-11-03 15:14:17 +03:00
|
|
|
MOZ_ASSERT(mSetMediaKeysDOMPromise);
|
2017-11-03 09:35:32 +03:00
|
|
|
|
|
|
|
// 5.3. If mediaKeys is not null, run the following steps:
|
|
|
|
if (mIncomingMediaKeys) {
|
|
|
|
auto cdmProxy = mIncomingMediaKeys->GetCDMProxy();
|
|
|
|
if (!cdmProxy) {
|
2017-11-03 15:14:17 +03:00
|
|
|
SetCDMProxyFailure(MediaResult(
|
2017-11-03 09:35:32 +03:00
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR,
|
2017-11-03 15:14:17 +03:00
|
|
|
"CDM crashed before binding MediaKeys object to HTMLMediaElement"));
|
2017-11-03 09:35:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5.3.1 Associate the CDM instance represented by mediaKeys with the
|
|
|
|
// media element for decrypting media data.
|
|
|
|
if (NS_FAILED(mIncomingMediaKeys->Bind(this))) {
|
|
|
|
// 5.3.2 If the preceding step failed, run the following steps:
|
|
|
|
|
|
|
|
// 5.3.2.1 Set the mediaKeys attribute to null.
|
|
|
|
mMediaKeys = nullptr;
|
|
|
|
// 5.3.2.2 Let this object's attaching media keys value be false.
|
|
|
|
// 5.3.2.3 Reject promise with a new DOMException whose name is
|
|
|
|
// the appropriate error name.
|
2017-11-03 15:14:17 +03:00
|
|
|
SetCDMProxyFailure(
|
|
|
|
MediaResult(NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
"Failed to bind MediaKeys object to HTMLMediaElement"));
|
2017-11-03 09:35:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return TryMakeAssociationWithCDM(cdmProxy);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::ResetSetMediaKeysTempVariables() {
|
|
|
|
mAttachingMediaKey = false;
|
|
|
|
mIncomingMediaKeys = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-07 00:52:15 +04:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::SetMediaKeys(
|
|
|
|
mozilla::dom::MediaKeys* aMediaKeys, ErrorResult& aRv) {
|
2018-05-14 12:11:18 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p SetMediaKeys(%p) mMediaKeys=%p mDecoder=%p", this,
|
|
|
|
aMediaKeys, mMediaKeys.get(), mDecoder.get()));
|
2016-04-21 23:31:18 +03:00
|
|
|
|
2014-10-28 03:21:12 +03:00
|
|
|
if (MozAudioCaptured()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!win) {
|
2014-06-07 00:52:15 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<DetailedPromise> promise = DetailedPromise::Create(
|
|
|
|
win->AsGlobal(), aRv,
|
|
|
|
NS_LITERAL_CSTRING("HTMLMediaElement.setMediaKeys"));
|
2014-07-19 05:31:11 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-06 03:28:43 +03:00
|
|
|
|
|
|
|
// 1. If mediaKeys and the mediaKeys attribute are the same object,
|
|
|
|
// return a resolved promise.
|
2014-10-13 02:53:43 +04:00
|
|
|
if (mMediaKeys == aMediaKeys) {
|
2016-08-09 12:15:13 +03:00
|
|
|
promise->MaybeResolveWithUndefined();
|
2014-10-13 02:53:43 +04:00
|
|
|
return promise.forget();
|
2014-06-07 00:52:15 +04:00
|
|
|
}
|
2016-01-06 03:28:43 +03:00
|
|
|
|
|
|
|
// 2. If this object's attaching media keys value is true, return a
|
|
|
|
// promise rejected with a new DOMException whose name is InvalidStateError.
|
2017-11-03 09:35:32 +03:00
|
|
|
if (mAttachingMediaKey) {
|
|
|
|
promise->MaybeReject(
|
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
NS_LITERAL_CSTRING("A MediaKeys object is in attaching operation."));
|
2014-10-13 02:53:43 +04:00
|
|
|
return promise.forget();
|
|
|
|
}
|
2016-01-06 03:28:43 +03:00
|
|
|
|
2017-11-03 09:35:32 +03:00
|
|
|
// 3. Let this object's attaching media keys value be true.
|
|
|
|
mAttachingMediaKey = true;
|
|
|
|
mIncomingMediaKeys = aMediaKeys;
|
2016-01-06 03:28:43 +03:00
|
|
|
|
2017-11-03 09:35:32 +03:00
|
|
|
// 4. Let promise be a new promise.
|
2017-11-03 15:14:17 +03:00
|
|
|
mSetMediaKeysDOMPromise = promise;
|
2014-10-27 04:47:00 +03:00
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
// 5. Run the following steps in parallel:
|
2016-01-06 03:28:43 +03:00
|
|
|
|
2017-11-03 15:14:17 +03:00
|
|
|
// 5.1 & 5.2 & 5.3
|
|
|
|
if (!DetachExistingMediaKeys() || !AttachNewMediaKeys()) {
|
2017-11-03 09:35:32 +03:00
|
|
|
return promise.forget();
|
2017-11-06 13:34:02 +03:00
|
|
|
}
|
|
|
|
|
2017-11-03 09:35:32 +03:00
|
|
|
// 5.4, 5.5, 5.6
|
2017-11-03 15:14:17 +03:00
|
|
|
MakeAssociationWithCDMResolved();
|
2016-01-06 03:28:43 +03:00
|
|
|
|
|
|
|
// 6. Return promise.
|
2014-06-07 00:52:15 +04:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-27 12:46:56 +04:00
|
|
|
EventHandlerNonNull* HTMLMediaElement::GetOnencrypted() {
|
2018-07-25 01:15:19 +03:00
|
|
|
return EventTarget::GetEventHandler(nsGkAtoms::onencrypted);
|
2014-06-07 00:52:15 +04:00
|
|
|
}
|
|
|
|
|
2016-09-22 07:25:38 +03:00
|
|
|
void HTMLMediaElement::SetOnencrypted(EventHandlerNonNull* aCallback) {
|
2018-07-25 01:15:19 +03:00
|
|
|
EventTarget::SetEventHandler(nsGkAtoms::onencrypted, aCallback);
|
2014-06-07 00:52:15 +04:00
|
|
|
}
|
|
|
|
|
2016-09-21 05:10:26 +03:00
|
|
|
EventHandlerNonNull* HTMLMediaElement::GetOnwaitingforkey() {
|
2018-07-25 01:15:19 +03:00
|
|
|
return EventTarget::GetEventHandler(nsGkAtoms::onwaitingforkey);
|
2016-09-21 05:10:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::SetOnwaitingforkey(EventHandlerNonNull* aCallback) {
|
2018-07-25 01:15:19 +03:00
|
|
|
EventTarget::SetEventHandler(nsGkAtoms::onwaitingforkey, aCallback);
|
2016-09-21 05:10:26 +03:00
|
|
|
}
|
|
|
|
|
2014-08-27 12:46:56 +04:00
|
|
|
void HTMLMediaElement::DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
|
|
|
|
const nsAString& aInitDataType) {
|
2016-10-10 06:42:01 +03:00
|
|
|
LOG(LogLevel::Debug, ("%p DispatchEncrypted initDataType='%s'", this,
|
2018-05-14 12:11:18 +03:00
|
|
|
NS_ConvertUTF16toUTF8(aInitDataType).get()));
|
2016-10-10 06:42:01 +03:00
|
|
|
|
2018-02-15 06:23:32 +03:00
|
|
|
if (mReadyState == HAVE_NOTHING) {
|
2015-04-01 10:36:00 +03:00
|
|
|
// Ready state not HAVE_METADATA (yet), don't dispatch encrypted now.
|
|
|
|
// Queueing for later dispatch in MetadataLoaded.
|
|
|
|
mPendingEncryptedInitData.AddInitData(aInitDataType, aInitData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaEncryptedEvent> event;
|
2015-01-29 10:30:38 +03:00
|
|
|
if (IsCORSSameOrigin()) {
|
|
|
|
event = MediaEncryptedEvent::Constructor(this, aInitDataType, aInitData);
|
|
|
|
} else {
|
|
|
|
event = MediaEncryptedEvent::Constructor(this);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
2014-06-07 00:52:15 +04:00
|
|
|
new AsyncEventDispatcher(this, event);
|
|
|
|
asyncDispatcher->PostDOMEvent();
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool HTMLMediaElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
2014-08-27 12:46:56 +04:00
|
|
|
return aName == nsGkAtoms::onencrypted ||
|
2017-07-04 23:54:30 +03:00
|
|
|
nsGenericHTMLElement::IsEventAttributeNameInternal(aName);
|
2014-06-07 00:52:15 +04:00
|
|
|
}
|
2014-10-13 02:53:43 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIPrincipal> HTMLMediaElement::GetTopLevelPrincipal() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIPrincipal> principal;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = OwnerDoc()->GetInnerWindow();
|
2014-10-13 02:53:43 +04:00
|
|
|
if (!window) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
// XXXkhuey better hope we always have an outer ...
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> top = window->GetOuterWindow()->GetTop();
|
2014-10-13 02:53:43 +04:00
|
|
|
if (!top) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIDocument* doc = top->GetExtantDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
principal = doc->NodePrincipal();
|
|
|
|
return principal.forget();
|
|
|
|
}
|
2014-06-07 00:52:15 +04:00
|
|
|
|
2017-07-13 09:41:09 +03:00
|
|
|
void HTMLMediaElement::NotifyWaitingForKey() {
|
|
|
|
LOG(LogLevel::Debug, ("%p, NotifyWaitingForKey()", this));
|
2016-10-17 04:16:54 +03:00
|
|
|
|
|
|
|
// http://w3c.github.io/encrypted-media/#wait-for-key
|
|
|
|
// 7.3.4 Queue a "waitingforkey" Event
|
|
|
|
// 1. Let the media element be the specified HTMLMediaElement object.
|
|
|
|
// 2. If the media element's waiting for key value is true, abort these steps.
|
|
|
|
if (mWaitingForKey == NOT_WAITING_FOR_KEY) {
|
|
|
|
// 3. Set the media element's waiting for key value to true.
|
|
|
|
// Note: algorithm continues in UpdateReadyStateInternal() when all decoded
|
|
|
|
// data enqueued in the MDSM is consumed.
|
|
|
|
mWaitingForKey = WAITING_FOR_KEY;
|
|
|
|
UpdateReadyStateInternal();
|
2016-08-21 23:51:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 13:34:14 +04:00
|
|
|
AudioTrackList* HTMLMediaElement::AudioTracks() { return mAudioTrackList; }
|
|
|
|
|
|
|
|
VideoTrackList* HTMLMediaElement::VideoTracks() { return mVideoTrackList; }
|
|
|
|
|
2015-01-12 14:07:38 +03:00
|
|
|
TextTrackList* HTMLMediaElement::GetTextTracks() {
|
|
|
|
return GetOrCreateTextTrackManager()->GetTextTracks();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TextTrack> HTMLMediaElement::AddTextTrack(
|
|
|
|
TextTrackKind aKind, const nsAString& aLabel, const nsAString& aLanguage) {
|
2018-05-14 12:11:18 +03:00
|
|
|
return GetOrCreateTextTrackManager()->AddTextTrack(
|
|
|
|
aKind, aLabel, aLanguage, TextTrackMode::Hidden,
|
|
|
|
TextTrackReadyState::Loaded, TextTrackSource::AddTextTrack);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
void HTMLMediaElement::PopulatePendingTextTrackList() {
|
|
|
|
if (mTextTrackManager) {
|
|
|
|
mTextTrackManager->PopulatePendingList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-24 19:48:37 +04:00
|
|
|
TextTrackManager* HTMLMediaElement::GetOrCreateTextTrackManager() {
|
|
|
|
if (!mTextTrackManager) {
|
|
|
|
mTextTrackManager = new TextTrackManager(this);
|
2014-04-07 23:42:33 +04:00
|
|
|
mTextTrackManager->AddListeners();
|
2014-03-24 19:48:37 +04:00
|
|
|
}
|
|
|
|
return mTextTrackManager;
|
|
|
|
}
|
|
|
|
|
2015-04-01 04:44:36 +03:00
|
|
|
MediaDecoderOwner::NextFrameStatus HTMLMediaElement::NextFrameStatus() {
|
|
|
|
if (mDecoder) {
|
|
|
|
return mDecoder->NextFrameStatus();
|
2018-11-23 18:00:49 +03:00
|
|
|
}
|
|
|
|
if (mSrcStream) {
|
|
|
|
if (mSrcStreamTracksAvailable && !mSrcStreamPlaybackEnded) {
|
|
|
|
return NEXT_FRAME_AVAILABLE;
|
|
|
|
}
|
|
|
|
return NEXT_FRAME_UNAVAILABLE;
|
2015-04-01 04:44:36 +03:00
|
|
|
}
|
|
|
|
return NEXT_FRAME_UNINITIALIZED;
|
|
|
|
}
|
|
|
|
|
2017-08-15 08:09:06 +03:00
|
|
|
void HTMLMediaElement::SetDecoder(MediaDecoder* aDecoder) {
|
|
|
|
MOZ_ASSERT(aDecoder); // Use ShutdownDecoder() to clear.
|
|
|
|
if (mDecoder) {
|
|
|
|
ShutdownDecoder();
|
|
|
|
}
|
|
|
|
mDecoder = aDecoder;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLINKCHILD("decoder", mDecoder.get());
|
2018-02-27 07:33:41 +03:00
|
|
|
if (mDecoder && mForcedHidden) {
|
|
|
|
mDecoder->SetForcedHidden(mForcedHidden);
|
|
|
|
}
|
2017-08-15 08:09:06 +03:00
|
|
|
}
|
|
|
|
|
2015-07-16 21:34:30 +03:00
|
|
|
float HTMLMediaElement::ComputedVolume() const {
|
2018-05-14 12:11:18 +03:00
|
|
|
return mMuted
|
|
|
|
? 0.0f
|
|
|
|
: mAudioChannelWrapper ? mAudioChannelWrapper->GetEffectiveVolume()
|
|
|
|
: mVolume;
|
2015-07-16 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLMediaElement::ComputedMuted() const {
|
|
|
|
return (mMuted & MUTED_BY_AUDIO_CHANNEL);
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:52:53 +03:00
|
|
|
nsSuspendedTypes HTMLMediaElement::ComputedSuspended() const {
|
2018-05-14 12:11:18 +03:00
|
|
|
return mAudioChannelWrapper ? mAudioChannelWrapper->GetSuspendType()
|
|
|
|
: nsISuspendedTypes::NONE_SUSPENDED;
|
2016-05-03 04:52:53 +03:00
|
|
|
}
|
|
|
|
|
2015-11-23 09:52:28 +03:00
|
|
|
bool HTMLMediaElement::IsCurrentlyPlaying() const {
|
|
|
|
// We have playable data, but we still need to check whether data is "real"
|
|
|
|
// current data.
|
2018-05-14 12:11:18 +03:00
|
|
|
return mReadyState >= HAVE_CURRENT_DATA && !IsPlaybackEnded();
|
2015-11-23 09:52:28 +03:00
|
|
|
}
|
|
|
|
|
2016-05-03 12:59:43 +03:00
|
|
|
void HTMLMediaElement::SetAudibleState(bool aAudible) {
|
2016-01-21 05:27:38 +03:00
|
|
|
if (mIsAudioTrackAudible != aAudible) {
|
2018-08-15 19:35:51 +03:00
|
|
|
UpdateAudioTrackSilenceRange(aAudible);
|
2016-01-21 05:27:38 +03:00
|
|
|
mIsAudioTrackAudible = aAudible;
|
2016-06-01 05:26:10 +03:00
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::eDataAudibleChanged);
|
2016-05-03 12:59:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-15 19:35:51 +03:00
|
|
|
bool HTMLMediaElement::IsAudioTrackCurrentlySilent() const {
|
|
|
|
return HasAudio() && !mIsAudioTrackAudible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::UpdateAudioTrackSilenceRange(bool aAudible) {
|
|
|
|
if (!HasAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aAudible) {
|
|
|
|
mAudioTrackSilenceStartedTime = CurrentTime();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccumulateAudioTrackSilence();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::AccumulateAudioTrackSilence() {
|
|
|
|
MOZ_ASSERT(HasAudio());
|
|
|
|
const double current = CurrentTime();
|
|
|
|
if (current < mAudioTrackSilenceStartedTime) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto start =
|
|
|
|
media::TimeUnit::FromSeconds(mAudioTrackSilenceStartedTime);
|
|
|
|
const auto end = media::TimeUnit::FromSeconds(current);
|
|
|
|
mSilenceTimeRanges += media::TimeInterval(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::ReportAudioTrackSilenceProportionTelemetry() {
|
|
|
|
if (!HasAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add last silence range to our ranges set.
|
|
|
|
if (!mIsAudioTrackAudible) {
|
|
|
|
AccumulateAudioTrackSilence();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<TimeRanges> ranges = Played();
|
|
|
|
const uint32_t lengthPlayedRange = ranges->Length();
|
|
|
|
const uint32_t lengthSilenceRange = mSilenceTimeRanges.Length();
|
|
|
|
if (!lengthPlayedRange || !lengthSilenceRange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double playedTime = 0.0, silenceTime = 0.0;
|
|
|
|
for (uint32_t idx = 0; idx < lengthPlayedRange; idx++) {
|
|
|
|
playedTime += ranges->End(idx) - ranges->Start(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t idx = 0; idx < lengthSilenceRange; idx++) {
|
|
|
|
silenceTime += mSilenceTimeRanges.End(idx).ToSeconds() -
|
|
|
|
mSilenceTimeRanges.Start(idx).ToSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
double silenceProportion = (silenceTime / playedTime) * 100;
|
|
|
|
// silenceProportion should be in the range [0, 100]
|
|
|
|
silenceProportion = std::min(100.0, std::max(silenceProportion, 0.0));
|
|
|
|
Telemetry::Accumulate(Telemetry::AUDIO_TRACK_SILENCE_PROPORTION,
|
|
|
|
silenceProportion);
|
|
|
|
}
|
|
|
|
|
2016-06-01 05:26:10 +03:00
|
|
|
void HTMLMediaElement::NotifyAudioPlaybackChanged(
|
|
|
|
AudibleChangedReasons aReason) {
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
|
|
|
mAudioChannelWrapper->NotifyAudioPlaybackChanged(aReason);
|
2016-11-29 00:16:31 +03:00
|
|
|
}
|
2017-08-29 10:25:44 +03:00
|
|
|
// only request wake lock for audible media.
|
2018-05-21 05:19:47 +03:00
|
|
|
UpdateWakeLock();
|
2016-11-29 00:16:31 +03:00
|
|
|
}
|
|
|
|
|
2016-08-29 11:34:26 +03:00
|
|
|
bool HTMLMediaElement::ShouldElementBePaused() {
|
|
|
|
// Bfcached page or inactive document.
|
|
|
|
if (!IsActive()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-05 07:23:23 +03:00
|
|
|
void HTMLMediaElement::SetMediaInfo(const MediaInfo& aInfo) {
|
2016-12-13 17:47:13 +03:00
|
|
|
const bool oldHasAudio = mMediaInfo.HasAudio();
|
2016-08-29 13:56:32 +03:00
|
|
|
mMediaInfo = aInfo;
|
2016-12-13 17:47:13 +03:00
|
|
|
if (aInfo.HasAudio() != oldHasAudio) {
|
2017-05-09 09:10:43 +03:00
|
|
|
UpdateAudioChannelPlayingState();
|
2016-12-13 17:47:13 +03:00
|
|
|
NotifyAudioPlaybackChanged(
|
|
|
|
AudioChannelService::AudibleChangedReasons::eDataAudibleChanged);
|
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
if (mAudioChannelWrapper) {
|
|
|
|
mAudioChannelWrapper->AudioCaptureStreamChangeIfNeeded();
|
|
|
|
}
|
2018-10-02 20:55:50 +03:00
|
|
|
UpdateWakeLock();
|
2016-08-29 13:56:32 +03:00
|
|
|
}
|
|
|
|
|
2016-11-29 07:40:32 +03:00
|
|
|
void HTMLMediaElement::AudioCaptureStreamChange(bool aCapture) {
|
2016-09-02 13:47:10 +03:00
|
|
|
// No need to capture a silence media element.
|
|
|
|
if (!HasAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-29 07:40:32 +03:00
|
|
|
if (aCapture && !mCaptureStreamPort) {
|
2016-08-29 13:56:32 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!OwnerDoc()->GetInnerWindow()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t id = window->WindowID();
|
2018-05-14 12:11:18 +03:00
|
|
|
MediaStreamGraph* msg = MediaStreamGraph::GetInstance(
|
|
|
|
MediaStreamGraph::AUDIO_THREAD_DRIVER, window,
|
|
|
|
MediaStreamGraph::REQUEST_DEFAULT_SAMPLE_RATE);
|
2016-08-29 13:56:32 +03:00
|
|
|
|
|
|
|
if (GetSrcMediaStream()) {
|
|
|
|
mCaptureStreamPort = msg->ConnectToCaptureStream(id, GetSrcMediaStream());
|
|
|
|
} else {
|
2016-09-07 16:14:15 +03:00
|
|
|
RefPtr<DOMMediaStream> stream =
|
2017-07-28 18:53:12 +03:00
|
|
|
CaptureStreamInternal(StreamCaptureBehavior::CONTINUE_WHEN_ENDED,
|
|
|
|
StreamCaptureType::CAPTURE_AUDIO, msg);
|
2018-05-14 12:11:18 +03:00
|
|
|
mCaptureStreamPort =
|
|
|
|
msg->ConnectToCaptureStream(id, stream->GetPlaybackStream());
|
2016-08-29 13:56:32 +03:00
|
|
|
}
|
2016-11-29 07:40:32 +03:00
|
|
|
} else if (!aCapture && mCaptureStreamPort) {
|
2016-08-29 13:56:32 +03:00
|
|
|
if (mDecoder) {
|
|
|
|
ProcessedMediaStream* ps =
|
|
|
|
mCaptureStreamPort->GetSource()->AsProcessedStream();
|
|
|
|
MOZ_ASSERT(ps);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mOutputStreams.Length(); i++) {
|
|
|
|
if (mOutputStreams[i].mStream->GetPlaybackStream() == ps) {
|
2018-11-23 18:02:03 +03:00
|
|
|
mDecoder->RemoveOutputStream(mOutputStreams[i].mStream);
|
2016-08-29 13:56:32 +03:00
|
|
|
mOutputStreams.RemoveElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCaptureStreamPort->Destroy();
|
|
|
|
mCaptureStreamPort = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 11:43:07 +03:00
|
|
|
void HTMLMediaElement::NotifyCueDisplayStatesChanged() {
|
|
|
|
if (!mTextTrackManager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTextTrackManager->DispatchUpdateCueDisplay();
|
|
|
|
}
|
|
|
|
|
2016-09-02 11:52:44 +03:00
|
|
|
void HTMLMediaElement::MarkAsContentSource(CallerAPI aAPI) {
|
2017-03-16 14:26:49 +03:00
|
|
|
const bool isVisible = mVisibilityState == Visibility::APPROXIMATELY_VISIBLE;
|
2016-09-02 11:52:44 +03:00
|
|
|
|
|
|
|
if (isVisible) {
|
|
|
|
// 0 = ALL_VISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 0);
|
|
|
|
} else {
|
|
|
|
// 1 = ALL_INVISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 1);
|
2017-02-07 13:20:47 +03:00
|
|
|
|
2018-07-03 18:13:17 +03:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-07 13:20:47 +03:00
|
|
|
// 0 = ALL_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT,
|
|
|
|
0);
|
2017-02-07 13:20:47 +03:00
|
|
|
} else {
|
|
|
|
// 1 = ALL_NOT_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT,
|
|
|
|
1);
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aAPI) {
|
|
|
|
case CallerAPI::DRAW_IMAGE: {
|
|
|
|
if (isVisible) {
|
|
|
|
// 2 = drawImage_VISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 2);
|
|
|
|
} else {
|
|
|
|
// 3 = drawImage_INVISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 3);
|
2017-02-07 13:20:47 +03:00
|
|
|
|
2018-07-03 18:13:17 +03:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-07 13:20:47 +03:00
|
|
|
// 2 = drawImage_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 2);
|
2017-02-07 13:20:47 +03:00
|
|
|
} else {
|
|
|
|
// 3 = drawImage_NOT_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 3);
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CallerAPI::CREATE_PATTERN: {
|
|
|
|
if (isVisible) {
|
|
|
|
// 4 = createPattern_VISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 4);
|
|
|
|
} else {
|
|
|
|
// 5 = createPattern_INVISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 5);
|
2017-02-07 13:20:47 +03:00
|
|
|
|
2018-07-03 18:13:17 +03:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-07 13:20:47 +03:00
|
|
|
// 4 = createPattern_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 4);
|
2017-02-07 13:20:47 +03:00
|
|
|
} else {
|
|
|
|
// 5 = createPattern_NOT_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 5);
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CallerAPI::CREATE_IMAGEBITMAP: {
|
|
|
|
if (isVisible) {
|
|
|
|
// 6 = createImageBitmap_VISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 6);
|
|
|
|
} else {
|
|
|
|
// 7 = createImageBitmap_INVISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 7);
|
2017-02-07 13:20:47 +03:00
|
|
|
|
2018-07-03 18:13:17 +03:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-07 13:20:47 +03:00
|
|
|
// 6 = createImageBitmap_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 6);
|
2017-02-07 13:20:47 +03:00
|
|
|
} else {
|
|
|
|
// 7 = createImageBitmap_NOT_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 7);
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CallerAPI::CAPTURE_STREAM: {
|
|
|
|
if (isVisible) {
|
|
|
|
// 8 = captureStream_VISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 8);
|
|
|
|
} else {
|
|
|
|
// 9 = captureStream_INVISIBLE
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_AS_CONTENT_SOURCE, 9);
|
2017-02-07 13:20:47 +03:00
|
|
|
|
2018-07-03 18:13:17 +03:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-07 13:20:47 +03:00
|
|
|
// 8 = captureStream_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 8);
|
2017-02-07 13:20:47 +03:00
|
|
|
} else {
|
|
|
|
// 9 = captureStream_NOT_IN_TREE
|
2018-05-14 12:11:18 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT, 9);
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("%p Log VIDEO_AS_CONTENT_SOURCE: visibility = %u, API: '%d' and 'All'",
|
2018-05-14 12:11:18 +03:00
|
|
|
this, isVisible, static_cast<int>(aAPI)));
|
2017-02-07 13:20:47 +03:00
|
|
|
|
|
|
|
if (!isVisible) {
|
|
|
|
LOG(LogLevel::Debug,
|
2018-05-14 12:11:18 +03:00
|
|
|
("%p Log VIDEO_AS_CONTENT_SOURCE_IN_TREE_OR_NOT: inTree = %u, API: "
|
|
|
|
"'%d' and 'All'",
|
|
|
|
this, IsInComposedDoc(), static_cast<int>(aAPI)));
|
2017-02-07 13:20:47 +03:00
|
|
|
}
|
2016-09-02 11:52:44 +03:00
|
|
|
}
|
|
|
|
|
2016-11-29 07:40:47 +03:00
|
|
|
void HTMLMediaElement::UpdateCustomPolicyAfterPlayed() {
|
|
|
|
if (mAudioChannelWrapper) {
|
2017-01-23 05:52:04 +03:00
|
|
|
mAudioChannelWrapper->NotifyPlayStateChanged();
|
2016-11-29 07:40:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 08:03:36 +03:00
|
|
|
AbstractThread* HTMLMediaElement::AbstractMainThread() const {
|
|
|
|
MOZ_ASSERT(mAbstractMainThread);
|
|
|
|
|
|
|
|
return mAbstractMainThread;
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
nsTArray<RefPtr<PlayPromise>> HTMLMediaElement::TakePendingPlayPromises() {
|
2018-05-30 22:15:35 +03:00
|
|
|
return std::move(mPendingPlayPromises);
|
2016-12-09 03:34:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::NotifyAboutPlaying() {
|
|
|
|
// Stick to the DispatchAsyncEvent() call path for now because we want to
|
|
|
|
// trigger some telemetry-related codes in the DispatchAsyncEvent() method.
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
|
|
|
|
}
|
|
|
|
|
2018-04-13 11:28:39 +03:00
|
|
|
already_AddRefed<PlayPromise> HTMLMediaElement::CreatePlayPromise(
|
|
|
|
ErrorResult& aRv) const {
|
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow();
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PlayPromise> promise = PlayPromise::Create(win->AsGlobal(), aRv);
|
|
|
|
LOG(LogLevel::Debug, ("%p created PlayPromise %p", this, promise.get()));
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-08 11:53:20 +03:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::CreateDOMPromise(
|
|
|
|
ErrorResult& aRv) const {
|
2018-02-23 01:28:39 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow();
|
2016-08-08 11:53:20 +03:00
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
if (!win) {
|
2016-08-08 11:53:20 +03:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
return Promise::Create(win->AsGlobal(), aRv);
|
2016-08-08 11:53:20 +03:00
|
|
|
}
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
void HTMLMediaElement::AsyncResolvePendingPlayPromises() {
|
2018-07-12 07:19:25 +03:00
|
|
|
// Disconnect requests for permission to play. We're playing either way,
|
|
|
|
// so there's no point keeping the promise connected. Note: the front
|
|
|
|
// end permission prompt code will detect that we've started playing, and
|
|
|
|
// hide the permission prompt.
|
|
|
|
mAutoplayPermissionRequest.DisconnectIfExists();
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsResolveOrRejectPendingPlayPromisesRunner(
|
|
|
|
this, TakePendingPlayPromises());
|
2016-12-09 03:34:39 +03:00
|
|
|
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(event.forget());
|
2016-12-09 03:34:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::AsyncRejectPendingPlayPromises(nsresult aError) {
|
2018-06-22 01:14:33 +03:00
|
|
|
mAutoplayPermissionRequest.DisconnectIfExists();
|
|
|
|
|
|
|
|
if (!mPaused) {
|
|
|
|
mPaused = true;
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:34:39 +03:00
|
|
|
if (mShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 06:35:33 +03:00
|
|
|
|
2018-08-29 01:03:15 +03:00
|
|
|
if (aError == NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR) {
|
|
|
|
DispatchEventsWhenPlayWasNotAllowed();
|
2018-06-25 06:35:33 +03:00
|
|
|
}
|
2016-12-09 03:34:39 +03:00
|
|
|
|
2018-05-14 12:11:18 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsResolveOrRejectPendingPlayPromisesRunner(
|
|
|
|
this, TakePendingPlayPromises(), aError);
|
2016-12-09 03:34:39 +03:00
|
|
|
|
2017-07-07 05:36:13 +03:00
|
|
|
mMainThreadEventTarget->Dispatch(event.forget());
|
2016-12-09 03:34:39 +03:00
|
|
|
}
|
|
|
|
|
2017-03-01 02:56:29 +03:00
|
|
|
void HTMLMediaElement::GetEMEInfo(nsString& aEMEInfo) {
|
|
|
|
if (!mMediaKeys) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString keySystem;
|
|
|
|
mMediaKeys->GetKeySystem(keySystem);
|
|
|
|
|
|
|
|
nsString sessionsInfo;
|
|
|
|
mMediaKeys->GetSessionsInfo(sessionsInfo);
|
|
|
|
|
|
|
|
aEMEInfo.AppendLiteral("Key System=");
|
|
|
|
aEMEInfo.Append(keySystem);
|
|
|
|
aEMEInfo.AppendLiteral(" SessionsInfo=");
|
|
|
|
aEMEInfo.Append(sessionsInfo);
|
|
|
|
}
|
|
|
|
|
2017-03-11 13:25:41 +03:00
|
|
|
void HTMLMediaElement::NotifyDecoderActivityChanges() const {
|
|
|
|
if (mDecoder) {
|
2018-05-14 12:11:18 +03:00
|
|
|
mDecoder->NotifyOwnerActivityChanged(!IsHidden(), mVisibilityState,
|
2018-07-03 18:13:17 +03:00
|
|
|
IsInComposedDoc());
|
2017-03-11 13:25:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 06:40:37 +03:00
|
|
|
nsIDocument* HTMLMediaElement::GetDocument() const { return OwnerDoc(); }
|
|
|
|
|
2017-03-15 12:33:21 +03:00
|
|
|
void HTMLMediaElement::ConstructMediaTracks(const MediaInfo* aInfo) {
|
2017-04-18 10:43:55 +03:00
|
|
|
if (mMediaTracksConstructed || !aInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMediaTracksConstructed = true;
|
2017-03-15 12:33:21 +03:00
|
|
|
|
|
|
|
AudioTrackList* audioList = AudioTracks();
|
|
|
|
if (audioList && aInfo->HasAudio()) {
|
|
|
|
const TrackInfo& info = aInfo->mAudio;
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<AudioTrack> track = MediaTrackList::CreateAudioTrack(
|
|
|
|
audioList->GetOwnerGlobal(), info.mId, info.mKind, info.mLabel,
|
|
|
|
info.mLanguage, info.mEnabled);
|
2017-03-15 12:33:21 +03:00
|
|
|
|
|
|
|
audioList->AddTrack(track);
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoTrackList* videoList = VideoTracks();
|
|
|
|
if (videoList && aInfo->HasVideo()) {
|
|
|
|
const TrackInfo& info = aInfo->mVideo;
|
2018-05-14 12:11:18 +03:00
|
|
|
RefPtr<VideoTrack> track = MediaTrackList::CreateVideoTrack(
|
|
|
|
videoList->GetOwnerGlobal(), info.mId, info.mKind, info.mLabel,
|
|
|
|
info.mLanguage);
|
2017-03-15 12:33:21 +03:00
|
|
|
|
|
|
|
videoList->AddTrack(track);
|
|
|
|
track->SetEnabledInternal(info.mEnabled, MediaTrack::FIRE_NO_EVENTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::RemoveMediaTracks() {
|
2017-04-10 13:09:35 +03:00
|
|
|
if (mAudioTrackList) {
|
|
|
|
mAudioTrackList->RemoveTracks();
|
2017-03-15 12:33:21 +03:00
|
|
|
}
|
|
|
|
|
2017-04-10 13:09:35 +03:00
|
|
|
if (mVideoTrackList) {
|
|
|
|
mVideoTrackList->RemoveTracks();
|
2017-03-15 12:33:21 +03:00
|
|
|
}
|
2017-04-18 10:43:55 +03:00
|
|
|
|
|
|
|
mMediaTracksConstructed = false;
|
2017-03-15 12:33:21 +03:00
|
|
|
}
|
|
|
|
|
2017-03-16 06:16:15 +03:00
|
|
|
class MediaElementGMPCrashHelper : public GMPCrashHelper {
|
|
|
|
public:
|
|
|
|
explicit MediaElementGMPCrashHelper(HTMLMediaElement* aElement)
|
|
|
|
: mElement(aElement) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
|
|
|
|
}
|
|
|
|
already_AddRefed<nsPIDOMWindowInner> GetPluginCrashedEventTarget() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
|
|
|
|
if (!mElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return do_AddRef(mElement->OwnerDoc()->GetInnerWindow());
|
|
|
|
}
|
2018-05-14 12:11:18 +03:00
|
|
|
|
2017-03-16 06:16:15 +03:00
|
|
|
private:
|
|
|
|
WeakPtr<HTMLMediaElement> mElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<GMPCrashHelper> HTMLMediaElement::CreateGMPCrashHelper() {
|
|
|
|
return MakeAndAddRef<MediaElementGMPCrashHelper>(this);
|
|
|
|
}
|
|
|
|
|
2017-03-22 09:46:09 +03:00
|
|
|
void HTMLMediaElement::MarkAsTainted() {
|
|
|
|
mHasSuspendTaint = true;
|
|
|
|
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->SetSuspendTaint(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 06:53:01 +03:00
|
|
|
bool HasDebuggerOrTabsPrivilege(JSContext* aCx, JSObject* aObj) {
|
2017-09-04 04:51:02 +03:00
|
|
|
return nsContentUtils::CallerHasPermission(aCx, nsGkAtoms::debugger) ||
|
|
|
|
nsContentUtils::CallerHasPermission(aCx, nsGkAtoms::tabs);
|
2018-05-14 12:11:18 +03:00
|
|
|
}
|
2016-12-09 03:34:39 +03:00
|
|
|
|
2017-04-17 13:25:26 +03:00
|
|
|
void HTMLMediaElement::AsyncResolveSeekDOMPromiseIfExists() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mSeekDOMPromise) {
|
|
|
|
RefPtr<dom::Promise> promise = mSeekDOMPromise.forget();
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLMediaElement::AsyncResolveSeekDOMPromiseIfExists",
|
2018-10-08 22:53:08 +03:00
|
|
|
[promise]() { promise->MaybeResolveWithUndefined(); });
|
2017-04-17 13:25:26 +03:00
|
|
|
mAbstractMainThread->Dispatch(r.forget());
|
|
|
|
mSeekDOMPromise = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLMediaElement::AsyncRejectSeekDOMPromiseIfExists() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mSeekDOMPromise) {
|
|
|
|
RefPtr<dom::Promise> promise = mSeekDOMPromise.forget();
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLMediaElement::AsyncRejectSeekDOMPromiseIfExists",
|
2018-10-08 22:53:08 +03:00
|
|
|
[promise]() { promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR); });
|
2017-04-17 13:25:26 +03:00
|
|
|
mAbstractMainThread->Dispatch(r.forget());
|
|
|
|
mSeekDOMPromise = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 02:31:16 +03:00
|
|
|
void HTMLMediaElement::ReportCanPlayTelemetry() {
|
|
|
|
LOG(LogLevel::Debug, ("%s", __func__));
|
|
|
|
|
|
|
|
RefPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_NewNamedThread("MediaTelemetry", getter_AddRefs(thread));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-07 05:36:13 +03:00
|
|
|
RefPtr<AbstractThread> abstractThread = mAbstractMainThread;
|
|
|
|
|
2017-05-10 02:31:16 +03:00
|
|
|
thread->Dispatch(
|
2017-06-12 22:34:10 +03:00
|
|
|
NS_NewRunnableFunction(
|
|
|
|
"dom::HTMLMediaElement::ReportCanPlayTelemetry",
|
2017-07-07 05:36:13 +03:00
|
|
|
[thread, abstractThread]() {
|
2017-05-10 02:31:16 +03:00
|
|
|
#if XP_WIN
|
2017-06-12 22:34:10 +03:00
|
|
|
// Windows Media Foundation requires MSCOM to be inited.
|
2017-08-24 19:52:36 +03:00
|
|
|
DebugOnly<HRESULT> hr = CoInitializeEx(0, COINIT_MULTITHREADED);
|
2017-06-12 22:34:10 +03:00
|
|
|
MOZ_ASSERT(hr == S_OK);
|
2017-05-10 02:31:16 +03:00
|
|
|
#endif
|
2017-06-12 22:34:10 +03:00
|
|
|
bool aac = MP4Decoder::IsSupportedType(
|
2018-03-06 19:43:57 +03:00
|
|
|
MediaContainerType(MEDIAMIMETYPE(AUDIO_MP4)), nullptr);
|
2017-06-12 22:34:10 +03:00
|
|
|
bool h264 = MP4Decoder::IsSupportedType(
|
2018-03-06 19:43:57 +03:00
|
|
|
MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)), nullptr);
|
2017-05-10 02:31:16 +03:00
|
|
|
#if XP_WIN
|
2017-06-12 22:34:10 +03:00
|
|
|
CoUninitialize();
|
2017-05-10 02:31:16 +03:00
|
|
|
#endif
|
2017-07-07 05:36:13 +03:00
|
|
|
abstractThread->Dispatch(NS_NewRunnableFunction(
|
2017-06-12 22:34:10 +03:00
|
|
|
"dom::HTMLMediaElement::ReportCanPlayTelemetry",
|
|
|
|
[thread, aac, h264]() {
|
|
|
|
LOG(LogLevel::Debug,
|
|
|
|
("MediaTelemetry aac=%d h264=%d", aac, h264));
|
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::HistogramID::VIDEO_CAN_CREATE_AAC_DECODER,
|
|
|
|
aac);
|
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::HistogramID::VIDEO_CAN_CREATE_H264_DECODER,
|
|
|
|
h264);
|
|
|
|
thread->AsyncShutdown();
|
|
|
|
}));
|
|
|
|
}),
|
2017-05-10 02:31:16 +03:00
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-12 12:39:30 +03:00
|
|
|
already_AddRefed<Promise> HTMLMediaElement::SetSinkId(const nsAString& aSinkId,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Promise> promise = Promise::Create(win->AsGlobal(), aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSink.first().Equals(aSinkId)) {
|
|
|
|
promise->MaybeResolveWithUndefined();
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString sinkId(aSinkId);
|
|
|
|
MediaManager::Get()
|
|
|
|
->GetSinkDevice(win, sinkId)
|
|
|
|
->Then(
|
|
|
|
mAbstractMainThread, __func__,
|
|
|
|
[self = RefPtr<HTMLMediaElement>(this)](
|
|
|
|
RefPtr<AudioDeviceInfo>&& aInfo) {
|
|
|
|
// Sink found switch output device.
|
|
|
|
MOZ_ASSERT(aInfo);
|
|
|
|
if (self->mDecoder) {
|
|
|
|
RefPtr<SinkInfoPromise> p = self->mDecoder->SetSink(aInfo)->Then(
|
|
|
|
self->mAbstractMainThread, __func__,
|
|
|
|
[aInfo](const GenericPromise::ResolveOrRejectValue& aValue) {
|
|
|
|
if (aValue.IsResolve()) {
|
|
|
|
return SinkInfoPromise::CreateAndResolve(aInfo, __func__);
|
|
|
|
}
|
|
|
|
return SinkInfoPromise::CreateAndReject(
|
|
|
|
aValue.RejectValue(), __func__);
|
|
|
|
});
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
if (self->GetSrcMediaStream()) {
|
|
|
|
// Set Sink Id through MSG is not supported yet.
|
|
|
|
return SinkInfoPromise::CreateAndReject(NS_ERROR_ABORT, __func__);
|
|
|
|
}
|
|
|
|
// No media attached to the element save it for later.
|
|
|
|
return SinkInfoPromise::CreateAndResolve(aInfo, __func__);
|
|
|
|
},
|
|
|
|
[](nsresult res) {
|
|
|
|
// Promise is rejected, sink not found.
|
|
|
|
return SinkInfoPromise::CreateAndReject(res, __func__);
|
|
|
|
})
|
|
|
|
->Then(
|
|
|
|
mAbstractMainThread, __func__,
|
|
|
|
[promise, self = RefPtr<HTMLMediaElement>(this),
|
2018-10-19 15:47:06 +03:00
|
|
|
sinkId](const SinkInfoPromise::ResolveOrRejectValue& aValue) {
|
2018-10-12 12:39:30 +03:00
|
|
|
if (aValue.IsResolve()) {
|
|
|
|
self->mSink = MakePair(sinkId, aValue.ResolveValue());
|
|
|
|
promise->MaybeResolveWithUndefined();
|
|
|
|
} else {
|
|
|
|
switch (aValue.RejectValue()) {
|
|
|
|
case NS_ERROR_ABORT:
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
break;
|
|
|
|
case NS_ERROR_NOT_AVAILABLE: {
|
|
|
|
ErrorResult notFoundError;
|
|
|
|
notFoundError.ThrowDOMException(
|
|
|
|
NS_ERROR_DOM_NOT_FOUND_ERR,
|
|
|
|
NS_LITERAL_CSTRING("The object can not be found here."));
|
|
|
|
promise->MaybeReject(notFoundError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR:
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_NOT_ALLOWED_ERR);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid error.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
aRv = NS_OK;
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2018-01-11 11:57:00 +03:00
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#undef LOG_EVENT
|