2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2020-05-04 14:29:02 +00:00
|
|
|
|
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-03-19 12:28:34 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElementBinding.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSize.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "plbase64.h"
|
|
|
|
#include "prlock.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "nsRFPService.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2012-08-21 04:06:46 +00:00
|
|
|
#include "ImageContainer.h"
|
2016-05-27 06:33:48 +00:00
|
|
|
#include "VideoFrameContainer.h"
|
2019-11-22 12:52:48 +00:00
|
|
|
#include "VideoOutput.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2017-07-13 09:38:06 +00:00
|
|
|
#include "FrameStatistics.h"
|
2013-02-14 15:59:21 +00:00
|
|
|
#include "MediaError.h"
|
2012-11-14 19:46:40 +00:00
|
|
|
#include "MediaDecoder.h"
|
2019-03-01 22:36:40 +00:00
|
|
|
#include "MediaDecoderStateMachine.h"
|
2013-06-11 15:23:13 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-01-07 12:16:07 +00:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2016-06-09 17:04:42 +00:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2017-08-21 03:08:25 +00:00
|
|
|
#include "mozilla/dom/TimeRanges.h"
|
2013-10-21 21:23:33 +00:00
|
|
|
#include "mozilla/dom/VideoPlaybackQuality.h"
|
2019-03-01 22:36:40 +00:00
|
|
|
#include "mozilla/dom/VideoStreamTrack.h"
|
2019-08-02 12:34:11 +00:00
|
|
|
#include "mozilla/StaticPrefs_media.h"
|
2019-03-07 22:42:42 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2016-07-18 00:51:30 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <limits>
|
|
|
|
|
2022-12-06 18:21:39 +00:00
|
|
|
extern mozilla::LazyLogModule gMediaElementLog;
|
|
|
|
#define LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gMediaElementLog, LogLevel::Debug, \
|
|
|
|
("HTMLVideoElement=%p, " msg, this, ##__VA_ARGS__))
|
|
|
|
|
2019-02-28 19:02:55 +00:00
|
|
|
nsGenericHTMLElement* NS_NewHTMLVideoElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
|
|
|
mozilla::dom::FromParser aFromParser) {
|
2020-03-17 14:53:08 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
|
|
|
|
auto* nim = nodeInfo->NodeInfoManager();
|
2019-02-28 19:02:55 +00:00
|
|
|
mozilla::dom::HTMLVideoElement* element =
|
2020-03-17 14:53:08 +00:00
|
|
|
new (nim) mozilla::dom::HTMLVideoElement(nodeInfo.forget());
|
2019-02-28 19:02:55 +00:00
|
|
|
element->Init();
|
|
|
|
return element;
|
|
|
|
}
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
namespace mozilla::dom {
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2019-02-28 19:02:55 +00:00
|
|
|
nsresult HTMLVideoElement::Clone(mozilla::dom::NodeInfo* aNodeInfo,
|
|
|
|
nsINode** aResult) const {
|
|
|
|
*aResult = nullptr;
|
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni(aNodeInfo);
|
2020-03-17 14:53:08 +00:00
|
|
|
auto* nim = ni->NodeInfoManager();
|
|
|
|
HTMLVideoElement* it = new (nim) HTMLVideoElement(ni.forget());
|
2019-02-28 19:02:55 +00:00
|
|
|
it->Init();
|
|
|
|
nsCOMPtr<nsINode> kungFuDeathGrip = it;
|
|
|
|
nsresult rv = const_cast<HTMLVideoElement*>(this)->CopyInnerTo(it);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
kungFuDeathGrip.swap(*aResult);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2008-07-09 08:22:20 +00:00
|
|
|
|
2019-03-01 22:36:17 +00:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLVideoElement,
|
|
|
|
HTMLMediaElement)
|
|
|
|
|
2019-03-01 22:36:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLVideoElement)
|
|
|
|
|
2019-11-22 12:52:48 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(HTMLVideoElement)
|
2019-11-21 23:58:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVisualCloneTarget)
|
2019-11-22 12:52:48 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVisualCloneTargetPromise)
|
2019-03-01 22:36:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVisualCloneSource)
|
2020-08-26 14:25:40 +00:00
|
|
|
tmp->mSecondaryVideoOutput = nullptr;
|
2019-11-22 12:52:48 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(HTMLMediaElement)
|
2019-03-01 22:36:40 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLVideoElement,
|
|
|
|
HTMLMediaElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVisualCloneTarget)
|
2019-11-22 12:52:48 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVisualCloneTargetPromise)
|
2019-03-01 22:36:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVisualCloneSource)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2019-03-01 22:36:17 +00:00
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
HTMLVideoElement::HTMLVideoElement(already_AddRefed<NodeInfo>&& aNodeInfo)
|
2020-08-26 14:25:40 +00:00
|
|
|
: HTMLMediaElement(std::move(aNodeInfo)),
|
|
|
|
mIsOrientationLocked(false),
|
|
|
|
mVideoWatchManager(this, 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 06:55:27 +00:00
|
|
|
DecoderDoctorLogger::LogConstruction(this);
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
HTMLVideoElement::~HTMLVideoElement() {
|
2020-08-26 14:25:40 +00:00
|
|
|
mVideoWatchManager.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 06:55:27 +00:00
|
|
|
DecoderDoctorLogger::LogDestruction(this);
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 22:36:40 +00:00
|
|
|
void HTMLVideoElement::UpdateMediaSize(const nsIntSize& aSize) {
|
|
|
|
HTMLMediaElement::UpdateMediaSize(aSize);
|
|
|
|
// If we have a clone target, we should update its size as well.
|
|
|
|
if (mVisualCloneTarget) {
|
|
|
|
Maybe<nsIntSize> newSize = Some(aSize);
|
2023-05-16 21:30:29 +00:00
|
|
|
mVisualCloneTarget->Invalidate(ImageSizeChanged::Yes, newSize,
|
|
|
|
ForceInvalidate::Yes);
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 19:54:41 +00:00
|
|
|
Maybe<CSSIntSize> HTMLVideoElement::GetVideoSize() const {
|
2015-04-14 05:17:55 +00:00
|
|
|
if (!mMediaInfo.HasVideo()) {
|
2020-11-03 19:54:41 +00:00
|
|
|
return Nothing();
|
2012-05-11 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 09:34:14 +00:00
|
|
|
if (mDisableVideo) {
|
2020-11-03 19:54:41 +00:00
|
|
|
return Nothing();
|
2014-05-23 09:34:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 19:54:41 +00:00
|
|
|
CSSIntSize size;
|
2016-05-11 17:54:52 +00:00
|
|
|
switch (mMediaInfo.mVideo.mRotation) {
|
|
|
|
case VideoInfo::Rotation::kDegree_90:
|
|
|
|
case VideoInfo::Rotation::kDegree_270: {
|
2020-11-03 19:54:41 +00:00
|
|
|
size.width = mMediaInfo.mVideo.mDisplay.height;
|
|
|
|
size.height = mMediaInfo.mVideo.mDisplay.width;
|
2016-05-11 17:54:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VideoInfo::Rotation::kDegree_0:
|
|
|
|
case VideoInfo::Rotation::kDegree_180:
|
|
|
|
default: {
|
2020-11-03 19:54:41 +00:00
|
|
|
size.height = mMediaInfo.mVideo.mDisplay.height;
|
|
|
|
size.width = mMediaInfo.mVideo.mDisplay.width;
|
2016-05-11 17:54:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-03 19:54:41 +00:00
|
|
|
return Some(size);
|
2008-07-09 08:22:20 +00:00
|
|
|
}
|
2009-02-26 07:04:42 +00:00
|
|
|
|
2023-05-16 21:30:29 +00:00
|
|
|
void HTMLVideoElement::Invalidate(ImageSizeChanged aImageSizeChanged,
|
2023-04-03 08:36:39 +00:00
|
|
|
const Maybe<nsIntSize>& aNewIntrinsicSize,
|
2023-05-16 21:30:29 +00:00
|
|
|
ForceInvalidate aForceInvalidate) {
|
2019-03-13 01:43:24 +00:00
|
|
|
HTMLMediaElement::Invalidate(aImageSizeChanged, aNewIntrinsicSize,
|
|
|
|
aForceInvalidate);
|
2019-03-01 22:37:16 +00:00
|
|
|
if (mVisualCloneTarget) {
|
|
|
|
VideoFrameContainer* container =
|
|
|
|
mVisualCloneTarget->GetVideoFrameContainer();
|
|
|
|
if (container) {
|
|
|
|
container->Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
bool HTMLVideoElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-03-19 12:27:35 +00:00
|
|
|
nsAttrValue& aResult) {
|
2009-02-26 07:04:42 +00:00
|
|
|
if (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height) {
|
2019-06-28 20:56:55 +00:00
|
|
|
return aResult.ParseHTMLDimension(aValue);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-03-19 12:23:54 +00:00
|
|
|
return HTMLMediaElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 19:21:29 +00:00
|
|
|
void HTMLVideoElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2021-03-24 22:18:55 +00:00
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aDecls,
|
|
|
|
MapAspectRatio::Yes);
|
2018-06-22 16:48:42 +00:00
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-02 22:05:19 +00:00
|
|
|
HTMLVideoElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2009-02-26 07:04:42 +00:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2018-04-03 03:21:06 +00:00
|
|
|
{nsGkAtoms::width}, {nsGkAtoms::height}, {nullptr}};
|
2009-02-26 07:04:42 +00:00
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {attributes,
|
|
|
|
sCommonAttributeMap};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2009-02-26 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
nsMapRuleToAttributesFunc HTMLVideoElement::GetAttributeMappingFunction()
|
|
|
|
const {
|
2009-02-26 07:04:42 +00:00
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
2009-06-26 07:25:17 +00:00
|
|
|
|
2019-05-28 22:47:08 +00:00
|
|
|
void HTMLVideoElement::UnbindFromTree(bool aNullParent) {
|
2019-03-01 22:36:40 +00:00
|
|
|
if (mVisualCloneSource) {
|
|
|
|
mVisualCloneSource->EndCloningVisually();
|
|
|
|
} else if (mVisualCloneTarget) {
|
2023-05-15 01:07:29 +00:00
|
|
|
AsyncEventDispatcher::RunDOMEventWhenSafe(
|
|
|
|
*this, u"MozStopPictureInPicture"_ns, CanBubble::eNo,
|
|
|
|
ChromeOnlyDispatch::eYes);
|
2019-03-01 22:36:40 +00:00
|
|
|
EndCloningVisually();
|
|
|
|
}
|
|
|
|
|
2019-05-28 22:47:08 +00:00
|
|
|
HTMLMediaElement::UnbindFromTree(aNullParent);
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 12:27:35 +00:00
|
|
|
nsresult HTMLVideoElement::SetAcceptHeader(nsIHttpChannel* aChannel) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString value(
|
2011-11-16 07:50:19 +00:00
|
|
|
"video/webm,"
|
|
|
|
"video/ogg,"
|
|
|
|
"video/*;q=0.9,"
|
|
|
|
"application/ogg;q=0.7,"
|
|
|
|
"audio/*;q=0.6,*/*;q=0.5");
|
2010-07-29 04:58:07 +00:00
|
|
|
|
2011-11-16 07:50:19 +00:00
|
|
|
return aChannel->SetRequestHeader("Accept"_ns, value, false);
|
2010-07-29 04:58:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 11:22:32 +00:00
|
|
|
bool HTMLVideoElement::IsInteractiveHTMLContent() const {
|
2015-03-23 09:02:33 +00:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::controls) ||
|
2020-04-28 11:22:32 +00:00
|
|
|
HTMLMediaElement::IsInteractiveHTMLContent();
|
2015-01-20 20:39:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 13:32:40 +00:00
|
|
|
gfx::IntSize HTMLVideoElement::GetVideoIntrinsicDimensions() {
|
2023-04-03 08:36:40 +00:00
|
|
|
const auto& sz = mMediaInfo.mVideo.mDisplay;
|
|
|
|
|
2022-07-11 13:32:40 +00:00
|
|
|
// Prefer the size of the container as it's more up to date.
|
2023-04-03 08:36:40 +00:00
|
|
|
return ToMaybeRef(mVideoFrameContainer.get())
|
|
|
|
.map([&](auto& aVFC) { return aVFC.CurrentIntrinsicSize().valueOr(sz); })
|
|
|
|
.valueOr(sz);
|
2022-07-11 13:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::VideoWidth() {
|
2023-04-03 08:36:40 +00:00
|
|
|
if (!HasVideo()) {
|
2022-07-11 13:32:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
gfx::IntSize size = GetVideoIntrinsicDimensions();
|
|
|
|
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
|
|
|
|
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
|
|
|
|
return size.height;
|
|
|
|
}
|
|
|
|
return size.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::VideoHeight() {
|
2023-04-03 08:36:40 +00:00
|
|
|
if (!HasVideo()) {
|
2022-07-11 13:32:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
gfx::IntSize size = GetVideoIntrinsicDimensions();
|
|
|
|
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
|
|
|
|
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
|
|
|
|
return size.width;
|
|
|
|
}
|
|
|
|
return size.height;
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
uint32_t HTMLVideoElement::MozParsedFrames() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2017-06-19 06:43:26 +00:00
|
|
|
if (!IsVideoStatsEnabled()) {
|
2013-06-11 15:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 07:13:55 +00:00
|
|
|
|
2023-05-31 09:46:54 +00:00
|
|
|
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-07-17 07:13:55 +00:00
|
|
|
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetParsedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::MozDecodedFrames() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2017-06-19 06:43:26 +00:00
|
|
|
if (!IsVideoStatsEnabled()) {
|
2013-06-11 15:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 07:13:55 +00:00
|
|
|
|
2023-05-31 09:46:54 +00:00
|
|
|
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-07-17 07:13:55 +00:00
|
|
|
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetDecodedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:32:40 +00:00
|
|
|
uint32_t HTMLVideoElement::MozPresentedFrames() {
|
2013-03-19 12:28:34 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2017-06-19 06:43:26 +00:00
|
|
|
if (!IsVideoStatsEnabled()) {
|
2013-06-11 15:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 07:13:55 +00:00
|
|
|
|
2023-05-31 09:46:54 +00:00
|
|
|
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-07-17 07:13:55 +00:00
|
|
|
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
|
|
|
VideoWidth(), VideoHeight());
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
return mDecoder ? mDecoder->GetFrameStatistics().GetPresentedFrames() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HTMLVideoElement::MozPaintedFrames() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2017-06-19 06:43:26 +00:00
|
|
|
if (!IsVideoStatsEnabled()) {
|
2013-06-11 15:23:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 07:13:55 +00:00
|
|
|
|
2023-05-31 09:46:54 +00:00
|
|
|
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-07-17 07:13:55 +00:00
|
|
|
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
|
|
|
VideoWidth(), VideoHeight());
|
|
|
|
}
|
|
|
|
|
2013-03-19 12:23:54 +00:00
|
|
|
layers::ImageContainer* container = GetImageContainer();
|
2013-03-19 12:28:34 +00:00
|
|
|
return container ? container->GetPaintCount() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLVideoElement::MozFrameDelay() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2017-07-17 07:13:55 +00:00
|
|
|
|
2023-05-31 09:46:54 +00:00
|
|
|
if (!IsVideoStatsEnabled() ||
|
|
|
|
OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-06-19 06:43:26 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
VideoFrameContainer* container = GetVideoFrameContainer();
|
2015-05-25 03:42:24 +00:00
|
|
|
// Hide negative delays. Frame timing tweaks in the compositor (e.g.
|
|
|
|
// adding a bias value to prevent multiple dropped/duped frames when
|
|
|
|
// frame times are aligned with composition times) may produce apparent
|
|
|
|
// negative delay, but we shouldn't report that.
|
|
|
|
return container ? std::max(0.0, container->GetFrameDelay()) : 0.0;
|
2011-03-23 22:28:57 +00:00
|
|
|
}
|
2012-04-28 15:01:10 +00:00
|
|
|
|
2013-03-19 12:28:34 +00:00
|
|
|
bool HTMLVideoElement::MozHasAudio() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
2015-02-09 06:51:17 +00:00
|
|
|
return HasAudio();
|
2013-03-19 12:28:34 +00:00
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* HTMLVideoElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return HTMLVideoElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-03-19 12:28:34 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 00:24:35 +00:00
|
|
|
already_AddRefed<VideoPlaybackQuality>
|
|
|
|
HTMLVideoElement::GetVideoPlaybackQuality() {
|
|
|
|
DOMHighResTimeStamp creationTime = 0;
|
2016-07-14 05:18:36 +00:00
|
|
|
uint32_t totalFrames = 0;
|
|
|
|
uint32_t droppedFrames = 0;
|
2013-07-11 03:52:22 +00:00
|
|
|
|
2017-06-19 06:43:26 +00:00
|
|
|
if (IsVideoStatsEnabled()) {
|
2016-01-30 17:05:36 +00:00
|
|
|
if (nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow()) {
|
2016-06-09 17:04:42 +00:00
|
|
|
Performance* perf = window->GetPerformance();
|
2013-07-11 03:52:22 +00:00
|
|
|
if (perf) {
|
2015-07-30 05:41:00 +00:00
|
|
|
creationTime = perf->Now();
|
2013-07-11 03:52:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDecoder) {
|
2023-05-31 09:46:54 +00:00
|
|
|
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
|
2017-07-17 07:13:55 +00:00
|
|
|
totalFrames = nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
|
|
|
droppedFrames = nsRFPService::GetSpoofedDroppedFrames(
|
|
|
|
TotalPlayTime(), VideoWidth(), VideoHeight());
|
2016-07-18 00:51:30 +00:00
|
|
|
} else {
|
2019-04-16 11:50:38 +00:00
|
|
|
FrameStatistics* stats = &mDecoder->GetFrameStatistics();
|
|
|
|
if (sizeof(totalFrames) >= sizeof(stats->GetParsedFrames())) {
|
|
|
|
totalFrames = stats->GetTotalFrames();
|
|
|
|
droppedFrames = stats->GetDroppedFrames();
|
2016-07-18 00:51:30 +00:00
|
|
|
} else {
|
2019-04-16 11:50:38 +00:00
|
|
|
uint64_t total = stats->GetTotalFrames();
|
2017-07-17 07:13:55 +00:00
|
|
|
const auto maxNumber = std::numeric_limits<uint32_t>::max();
|
|
|
|
if (total <= maxNumber) {
|
|
|
|
totalFrames = uint32_t(total);
|
2019-04-16 11:50:38 +00:00
|
|
|
droppedFrames = uint32_t(stats->GetDroppedFrames());
|
2017-07-17 07:13:55 +00:00
|
|
|
} else {
|
|
|
|
// Too big number(s) -> Resize everything to fit in 32 bits.
|
|
|
|
double ratio = double(maxNumber) / double(total);
|
|
|
|
totalFrames = maxNumber; // === total * ratio
|
2019-04-16 11:50:38 +00:00
|
|
|
droppedFrames = uint32_t(double(stats->GetDroppedFrames()) * ratio);
|
2017-07-17 07:13:55 +00:00
|
|
|
}
|
2016-07-18 00:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-05 21:02:53 +00:00
|
|
|
if (!StaticPrefs::media_video_dropped_frame_stats_enabled()) {
|
|
|
|
droppedFrames = 0;
|
|
|
|
}
|
2013-07-11 03:52:22 +00:00
|
|
|
}
|
2013-06-21 03:14:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 07:19:15 +00:00
|
|
|
RefPtr<VideoPlaybackQuality> playbackQuality =
|
|
|
|
new VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames);
|
2013-06-21 03:14:18 +00:00
|
|
|
return playbackQuality.forget();
|
|
|
|
}
|
|
|
|
|
2013-05-10 12:42:39 +00:00
|
|
|
void HTMLVideoElement::WakeLockRelease() {
|
2014-03-18 08:44:41 +00:00
|
|
|
HTMLMediaElement::WakeLockRelease();
|
2018-10-02 17:56:21 +00:00
|
|
|
ReleaseVideoWakeLockIfExists();
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 17:56:21 +00:00
|
|
|
void HTMLVideoElement::UpdateWakeLock() {
|
|
|
|
HTMLMediaElement::UpdateWakeLock();
|
|
|
|
if (!mPaused) {
|
|
|
|
CreateVideoWakeLockIfNeeded();
|
|
|
|
} else {
|
|
|
|
ReleaseVideoWakeLockIfExists();
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
2018-10-02 17:56:21 +00:00
|
|
|
}
|
2013-05-10 12:42:39 +00:00
|
|
|
|
2018-10-02 17:55:50 +00:00
|
|
|
bool HTMLVideoElement::ShouldCreateVideoWakeLock() const {
|
2022-12-22 19:19:15 +00:00
|
|
|
if (!StaticPrefs::media_video_wakelock()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Only request wake lock for video with audio or video from media
|
|
|
|
// stream, because non-stream video without audio is often used as a
|
|
|
|
// background image.
|
2020-05-07 21:35:37 +00:00
|
|
|
//
|
2022-12-22 19:19:15 +00:00
|
|
|
// Some web conferencing sites route audio outside the video element,
|
|
|
|
// and would not be detected unless we check for media stream, so do
|
|
|
|
// that below.
|
2020-05-07 21:35:37 +00:00
|
|
|
//
|
2022-12-22 19:19:15 +00:00
|
|
|
// Media streams generally aren't used as background images, though if
|
|
|
|
// they were we'd get false positives. If this is an issue, we could
|
|
|
|
// check for media stream AND document has audio playing (but that was
|
|
|
|
// tricky to do).
|
2020-05-07 21:35:37 +00:00
|
|
|
return HasVideo() && (mSrcStream || HasAudio());
|
2018-10-02 17:55:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 17:56:21 +00:00
|
|
|
void HTMLVideoElement::CreateVideoWakeLockIfNeeded() {
|
2023-03-09 18:08:43 +00:00
|
|
|
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-02 17:55:50 +00:00
|
|
|
if (!mScreenWakeLock && ShouldCreateVideoWakeLock()) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<power::PowerManagerService> pmService =
|
2014-01-07 12:16:07 +00:00
|
|
|
power::PowerManagerService::GetInstance();
|
2013-05-10 12:42:39 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(pmService);
|
|
|
|
|
2014-01-07 12:16:07 +00:00
|
|
|
ErrorResult rv;
|
2017-08-29 02:54:28 +00:00
|
|
|
mScreenWakeLock = pmService->NewWakeLock(u"video-playing"_ns,
|
2014-01-07 12:16:07 +00:00
|
|
|
OwnerDoc()->GetInnerWindow(), rv);
|
2013-05-10 12:42:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 17:56:21 +00:00
|
|
|
void HTMLVideoElement::ReleaseVideoWakeLockIfExists() {
|
|
|
|
if (mScreenWakeLock) {
|
|
|
|
ErrorResult rv;
|
|
|
|
mScreenWakeLock->Unlock(rv);
|
|
|
|
rv.SuppressException();
|
|
|
|
mScreenWakeLock = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:36:17 +00:00
|
|
|
bool HTMLVideoElement::SetVisualCloneTarget(
|
2019-11-22 12:52:48 +00:00
|
|
|
RefPtr<HTMLVideoElement> aVisualCloneTarget,
|
|
|
|
RefPtr<Promise> aVisualCloneTargetPromise) {
|
2019-03-13 01:43:24 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
2019-06-19 22:37:56 +00:00
|
|
|
!aVisualCloneTarget || aVisualCloneTarget->IsInComposedDoc(),
|
2019-03-13 01:43:24 +00:00
|
|
|
"Can't set the clone target to a disconnected video "
|
|
|
|
"element.");
|
2019-03-01 22:36:17 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVisualCloneSource,
|
|
|
|
"Can't clone a video element that is already a clone.");
|
|
|
|
if (!aVisualCloneTarget ||
|
2019-06-19 22:37:56 +00:00
|
|
|
(aVisualCloneTarget->IsInComposedDoc() && !mVisualCloneSource)) {
|
2019-11-22 12:52:48 +00:00
|
|
|
mVisualCloneTarget = std::move(aVisualCloneTarget);
|
|
|
|
mVisualCloneTargetPromise = std::move(aVisualCloneTargetPromise);
|
2019-03-01 22:36:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLVideoElement::SetVisualCloneSource(
|
2019-11-22 12:52:48 +00:00
|
|
|
RefPtr<HTMLVideoElement> aVisualCloneSource) {
|
2019-03-13 01:43:24 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
2019-06-19 22:37:56 +00:00
|
|
|
!aVisualCloneSource || aVisualCloneSource->IsInComposedDoc(),
|
2019-03-13 01:43:24 +00:00
|
|
|
"Can't set the clone source to a disconnected video "
|
|
|
|
"element.");
|
2019-03-01 22:36:17 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVisualCloneTarget,
|
|
|
|
"Can't clone a video element that is already a "
|
|
|
|
"clone.");
|
|
|
|
if (!aVisualCloneSource ||
|
2019-06-19 22:37:56 +00:00
|
|
|
(aVisualCloneSource->IsInComposedDoc() && !mVisualCloneTarget)) {
|
2019-11-22 12:52:48 +00:00
|
|
|
mVisualCloneSource = std::move(aVisualCloneSource);
|
2019-03-01 22:36:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-28 19:02:55 +00:00
|
|
|
/* static */
|
2019-08-02 12:35:01 +00:00
|
|
|
bool HTMLVideoElement::IsVideoStatsEnabled() {
|
|
|
|
return StaticPrefs::media_video_stats_enabled();
|
2013-06-11 15:23:13 +00:00
|
|
|
}
|
2014-07-13 02:20:42 +00:00
|
|
|
|
2017-07-17 07:13:55 +00:00
|
|
|
double HTMLVideoElement::TotalPlayTime() const {
|
|
|
|
double total = 0.0;
|
|
|
|
|
|
|
|
if (mPlayed) {
|
2018-02-16 18:34:28 +00:00
|
|
|
uint32_t timeRangeCount = mPlayed->Length();
|
2017-07-17 07:13:55 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < timeRangeCount; i++) {
|
2018-02-16 18:36:40 +00:00
|
|
|
double begin = mPlayed->Start(i);
|
|
|
|
double end = mPlayed->End(i);
|
2017-07-17 07:13:55 +00:00
|
|
|
total += end - begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurrentPlayRangeStart != -1.0) {
|
|
|
|
double now = CurrentTime();
|
|
|
|
if (mCurrentPlayRangeStart != now) {
|
|
|
|
total += now - mCurrentPlayRangeStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
2017-06-19 06:43:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:52:48 +00:00
|
|
|
already_AddRefed<Promise> HTMLVideoElement::CloneElementVisually(
|
|
|
|
HTMLVideoElement& aTargetVideo, ErrorResult& aRv) {
|
2019-06-19 22:37:56 +00:00
|
|
|
MOZ_ASSERT(IsInComposedDoc(),
|
2019-03-01 22:36:40 +00:00
|
|
|
"Can't clone a video that's not bound to a DOM tree.");
|
2019-06-19 22:37:56 +00:00
|
|
|
MOZ_ASSERT(aTargetVideo.IsInComposedDoc(),
|
2019-03-01 22:36:40 +00:00
|
|
|
"Can't clone to a video that's not bound to a DOM tree.");
|
2019-06-19 22:37:56 +00:00
|
|
|
if (!IsInComposedDoc() || !aTargetVideo.IsInComposedDoc()) {
|
2019-11-22 12:52:48 +00:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 22:42:42 +00:00
|
|
|
// Do we already have a visual clone target? If so, shut it down.
|
|
|
|
if (mVisualCloneTarget) {
|
|
|
|
EndCloningVisually();
|
|
|
|
}
|
|
|
|
|
2019-03-08 16:46:44 +00:00
|
|
|
// If there's a poster set on the target video, clear it, otherwise
|
|
|
|
// it'll display over top of the cloned frames.
|
2019-11-22 12:52:48 +00:00
|
|
|
aTargetVideo.UnsetHTMLAttr(nsGkAtoms::poster, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2019-03-08 16:46:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:52:48 +00:00
|
|
|
if (!SetVisualCloneTarget(&aTargetVideo, promise)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aTargetVideo.SetVisualCloneSource(this)) {
|
|
|
|
mVisualCloneTarget = nullptr;
|
2019-11-22 12:52:48 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aTargetVideo.SetMediaInfo(mMediaInfo);
|
|
|
|
|
2019-08-02 12:34:11 +00:00
|
|
|
if (IsInComposedDoc() && !StaticPrefs::media_cloneElementVisually_testing()) {
|
2019-03-13 01:43:24 +00:00
|
|
|
NotifyUAWidgetSetupOrChange();
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:36:40 +00:00
|
|
|
MaybeBeginCloningVisually();
|
2019-11-22 12:52:48 +00:00
|
|
|
|
|
|
|
return promise.forget();
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 01:43:07 +00:00
|
|
|
void HTMLVideoElement::StopCloningElementVisually() {
|
|
|
|
if (mVisualCloneTarget) {
|
|
|
|
EndCloningVisually();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:36:40 +00:00
|
|
|
void HTMLVideoElement::MaybeBeginCloningVisually() {
|
|
|
|
if (!mVisualCloneTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDecoder) {
|
2020-08-26 14:25:40 +00:00
|
|
|
mDecoder->SetSecondaryVideoContainer(
|
|
|
|
mVisualCloneTarget->GetVideoFrameContainer());
|
2021-01-19 17:34:47 +00:00
|
|
|
NotifyDecoderActivityChanges();
|
2020-04-01 23:04:58 +00:00
|
|
|
UpdateMediaControlAfterPictureInPictureModeChanged();
|
2020-09-23 23:34:12 +00:00
|
|
|
OwnerDoc()->EnableChildElementInPictureInPictureMode();
|
2019-03-01 22:36:40 +00:00
|
|
|
} else if (mSrcStream) {
|
|
|
|
VideoFrameContainer* container =
|
|
|
|
mVisualCloneTarget->GetVideoFrameContainer();
|
2020-08-26 14:25:40 +00:00
|
|
|
if (container) {
|
|
|
|
mSecondaryVideoOutput =
|
|
|
|
MakeRefPtr<FirstFrameVideoOutput>(container, mAbstractMainThread);
|
|
|
|
mVideoWatchManager.Watch(
|
|
|
|
mSecondaryVideoOutput->mFirstFrameRendered,
|
|
|
|
&HTMLVideoElement::OnSecondaryVideoOutputFirstFrameRendered);
|
|
|
|
SetSecondaryMediaStreamRenderer(container, mSecondaryVideoOutput);
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
2020-04-01 23:04:58 +00:00
|
|
|
UpdateMediaControlAfterPictureInPictureModeChanged();
|
2020-09-23 23:34:12 +00:00
|
|
|
OwnerDoc()->EnableChildElementInPictureInPictureMode();
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLVideoElement::EndCloningVisually() {
|
|
|
|
MOZ_ASSERT(mVisualCloneTarget);
|
|
|
|
|
|
|
|
if (mDecoder) {
|
2019-11-22 00:07:04 +00:00
|
|
|
mDecoder->SetSecondaryVideoContainer(nullptr);
|
2021-01-19 17:34:47 +00:00
|
|
|
NotifyDecoderActivityChanges();
|
2020-09-23 23:34:12 +00:00
|
|
|
OwnerDoc()->DisableChildElementInPictureInPictureMode();
|
2019-03-01 22:36:40 +00:00
|
|
|
} else if (mSrcStream) {
|
2020-08-26 14:25:40 +00:00
|
|
|
if (mSecondaryVideoOutput) {
|
|
|
|
mVideoWatchManager.Unwatch(
|
|
|
|
mSecondaryVideoOutput->mFirstFrameRendered,
|
|
|
|
&HTMLVideoElement::OnSecondaryVideoOutputFirstFrameRendered);
|
2019-11-22 12:52:48 +00:00
|
|
|
mSecondaryVideoOutput = nullptr;
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
2020-08-26 14:25:40 +00:00
|
|
|
SetSecondaryMediaStreamRenderer(nullptr);
|
2020-09-23 23:34:12 +00:00
|
|
|
OwnerDoc()->DisableChildElementInPictureInPictureMode();
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 22:42:42 +00:00
|
|
|
Unused << mVisualCloneTarget->SetVisualCloneSource(nullptr);
|
|
|
|
Unused << SetVisualCloneTarget(nullptr);
|
2019-03-13 01:43:24 +00:00
|
|
|
|
2020-04-01 23:04:58 +00:00
|
|
|
UpdateMediaControlAfterPictureInPictureModeChanged();
|
2020-03-19 18:15:33 +00:00
|
|
|
|
2019-08-02 12:34:11 +00:00
|
|
|
if (IsInComposedDoc() && !StaticPrefs::media_cloneElementVisually_testing()) {
|
2019-03-13 01:43:24 +00:00
|
|
|
NotifyUAWidgetSetupOrChange();
|
|
|
|
}
|
2019-03-01 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:52:48 +00:00
|
|
|
void HTMLVideoElement::OnSecondaryVideoContainerInstalled(
|
|
|
|
const RefPtr<VideoFrameContainer>& aSecondaryContainer) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT_IF(mVisualCloneTargetPromise, mVisualCloneTarget);
|
|
|
|
if (!mVisualCloneTargetPromise) {
|
|
|
|
// Clone target was unset.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoFrameContainer* container = mVisualCloneTarget->GetVideoFrameContainer();
|
|
|
|
if (NS_WARN_IF(container != aSecondaryContainer)) {
|
|
|
|
// Not the right container.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMainThreadEventTarget->Dispatch(NewRunnableMethod(
|
|
|
|
"Promise::MaybeResolveWithUndefined", mVisualCloneTargetPromise,
|
|
|
|
&Promise::MaybeResolveWithUndefined));
|
|
|
|
mVisualCloneTargetPromise = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-08-26 14:25:40 +00:00
|
|
|
void HTMLVideoElement::OnSecondaryVideoOutputFirstFrameRendered() {
|
|
|
|
OnSecondaryVideoContainerInstalled(
|
|
|
|
mVisualCloneTarget->GetVideoFrameContainer());
|
|
|
|
}
|
|
|
|
|
2022-12-06 18:21:39 +00:00
|
|
|
void HTMLVideoElement::OnVisibilityChange(Visibility aNewVisibility) {
|
|
|
|
HTMLMediaElement::OnVisibilityChange(aNewVisibility);
|
|
|
|
|
|
|
|
// See the alternative part after step 4, but we only pause/resume invisible
|
|
|
|
// autoplay for non-audible video, which is different from the spec. This
|
|
|
|
// behavior seems aiming to reduce the power consumption without interering
|
|
|
|
// users, and Chrome and Safari also chose to do that only for non-audible
|
|
|
|
// video, so we want to match them in order to reduce webcompat issue.
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#ready-states:eligible-for-autoplay-2
|
|
|
|
if (!HasAttr(nsGkAtoms::autoplay) || IsAudible()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNewVisibility == Visibility::ApproximatelyVisible && mPaused &&
|
|
|
|
IsEligibleForAutoplay() && AllowedToPlay()) {
|
|
|
|
LOG("resume invisible paused autoplay video");
|
|
|
|
RunAutoplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to consider the Pip window as well, which won't reflect in the
|
|
|
|
// visibility event.
|
|
|
|
if ((aNewVisibility == Visibility::ApproximatelyNonVisible &&
|
|
|
|
!IsCloningElementVisually()) &&
|
|
|
|
mCanAutoplayFlag) {
|
|
|
|
LOG("pause non-audible autoplay video when it's invisible");
|
|
|
|
PauseInternal();
|
|
|
|
mCanAutoplayFlag = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
} // namespace mozilla::dom
|
2022-12-06 18:21:39 +00:00
|
|
|
|
|
|
|
#undef LOG
|