mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 855130 - Implement HTMLVideoElement's VideoPlaybackQuality (from Media Source Extensions spec). r=roc
This commit is contained in:
parent
b53bbbf3fe
commit
07a8149c7d
@ -25,6 +25,7 @@
|
||||
#include "nsIDOMWakeLock.h"
|
||||
#include "AudioChannelCommon.h"
|
||||
#include "DecoderTraits.h"
|
||||
#include "MediaDecoder.h"
|
||||
#include "MediaMetadataManager.h"
|
||||
#include "AudioChannelAgent.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
@ -522,6 +523,12 @@ public:
|
||||
mTextTracks->AddTextTrack(aTextTrack);
|
||||
}
|
||||
|
||||
MediaDecoder::FrameStatistics& GetFrameStatistics()
|
||||
{
|
||||
MediaDecoder::FrameStatistics empty;
|
||||
return mDecoder ? mDecoder->GetFrameStatistics() : empty;
|
||||
}
|
||||
|
||||
protected:
|
||||
class MediaLoadListener;
|
||||
class StreamListener;
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIDOMHTMLVideoElement.h"
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "mozilla/dom/VideoPlaybackQuality.h"
|
||||
#include "nsPerformance.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -114,6 +116,8 @@ public:
|
||||
|
||||
void NotifyOwnerDocumentActivityChanged() MOZ_OVERRIDE;
|
||||
|
||||
already_AddRefed<dom::VideoPlaybackQuality> VideoPlaybackQuality();
|
||||
|
||||
protected:
|
||||
virtual JSObject* WrapNode(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
@ -258,6 +258,33 @@ HTMLVideoElement::NotifyOwnerDocumentActivityChanged()
|
||||
WakeLockUpdate();
|
||||
}
|
||||
|
||||
already_AddRefed<dom::VideoPlaybackQuality>
|
||||
HTMLVideoElement::VideoPlaybackQuality()
|
||||
{
|
||||
nsPIDOMWindow* window = OwnerDoc()->GetInnerWindow();
|
||||
NS_ENSURE_TRUE(window, nullptr);
|
||||
nsPerformance* perf = window->GetPerformance();
|
||||
NS_ENSURE_TRUE(perf, nullptr);
|
||||
DOMHighResTimeStamp creationTime = perf->GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
|
||||
|
||||
uint64_t totalFrames = 0;
|
||||
uint64_t droppedFrames = 0;
|
||||
uint64_t corruptedFrames = 0;
|
||||
double playbackJitter = 0.0;
|
||||
if (mDecoder && sVideoStatsEnabled) {
|
||||
MediaDecoder::FrameStatistics& stats = mDecoder->GetFrameStatistics();
|
||||
totalFrames = stats.GetParsedFrames();
|
||||
droppedFrames = totalFrames - stats.GetPresentedFrames();
|
||||
corruptedFrames = totalFrames - stats.GetDecodedFrames();
|
||||
playbackJitter = stats.GetPlaybackJitter();
|
||||
}
|
||||
|
||||
nsRefPtr<dom::VideoPlaybackQuality> playbackQuality =
|
||||
new dom::VideoPlaybackQuality(this, creationTime, totalFrames, droppedFrames,
|
||||
corruptedFrames, playbackJitter);
|
||||
return playbackQuality.forget();
|
||||
}
|
||||
|
||||
void
|
||||
HTMLVideoElement::WakeLockCreate()
|
||||
{
|
||||
|
@ -818,6 +818,7 @@ public:
|
||||
|
||||
FrameStatistics() :
|
||||
mReentrantMonitor("MediaDecoder::FrameStats"),
|
||||
mPlaybackJitter(0.0),
|
||||
mParsedFrames(0),
|
||||
mDecodedFrames(0),
|
||||
mPresentedFrames(0) {}
|
||||
@ -844,6 +845,11 @@ public:
|
||||
return mPresentedFrames;
|
||||
}
|
||||
|
||||
double GetPlaybackJitter() {
|
||||
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
||||
return mPlaybackJitter;
|
||||
}
|
||||
|
||||
// Increments the parsed and decoded frame counters by the passed in counts.
|
||||
// Can be called on any thread.
|
||||
void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) {
|
||||
@ -861,11 +867,22 @@ public:
|
||||
++mPresentedFrames;
|
||||
}
|
||||
|
||||
// Tracks the sum of display errors.
|
||||
// Can be called on any thread.
|
||||
void NotifyPlaybackJitter(double aDisplayError) {
|
||||
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
||||
mPlaybackJitter += aDisplayError;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// ReentrantMonitor to protect access of playback statistics.
|
||||
ReentrantMonitor mReentrantMonitor;
|
||||
|
||||
// Sum of display duration error.
|
||||
// Access protected by mStatsReentrantMonitor.
|
||||
double mPlaybackJitter;
|
||||
|
||||
// Number of frames parsed and demuxed from media.
|
||||
// Access protected by mStatsReentrantMonitor.
|
||||
uint32_t mParsedFrames;
|
||||
|
@ -2533,8 +2533,12 @@ void MediaDecoderStateMachine::AdvanceFrame()
|
||||
ScheduleStateMachine();
|
||||
return;
|
||||
}
|
||||
mDecoder->GetFrameStatistics().NotifyPresentedFrame();
|
||||
MediaDecoder::FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
|
||||
frameStats.NotifyPresentedFrame();
|
||||
remainingTime = currentFrame->mEndTime - clock_time;
|
||||
int64_t frameDuration = currentFrame->mEndTime - currentFrame->mTime;
|
||||
double displayError = fabs(double(frameDuration - remainingTime) / USECS_PER_S);
|
||||
frameStats.NotifyPlaybackJitter(displayError);
|
||||
currentFrame = nullptr;
|
||||
}
|
||||
|
||||
|
53
content/media/VideoPlaybackQuality.cpp
Normal file
53
content/media/VideoPlaybackQuality.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "VideoPlaybackQuality.h"
|
||||
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "mozilla/dom/VideoPlaybackQualityBinding.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "MediaDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
VideoPlaybackQuality::VideoPlaybackQuality(HTMLMediaElement* aElement,
|
||||
DOMHighResTimeStamp aCreationTime,
|
||||
uint64_t aTotalFrames,
|
||||
uint64_t aDroppedFrames,
|
||||
uint64_t aCorruptedFrames,
|
||||
double aPlaybackJitter)
|
||||
: mElement(aElement)
|
||||
, mCreationTime(aCreationTime)
|
||||
, mTotalFrames(aTotalFrames)
|
||||
, mDroppedFrames(aDroppedFrames)
|
||||
, mCorruptedFrames(aCorruptedFrames)
|
||||
, mPlaybackJitter(aPlaybackJitter)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
HTMLMediaElement*
|
||||
VideoPlaybackQuality::GetParentObject() const
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
||||
JSObject*
|
||||
VideoPlaybackQuality::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return VideoPlaybackQualityBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VideoPlaybackQuality, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VideoPlaybackQuality, Release)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(VideoPlaybackQuality, mElement)
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
68
content/media/VideoPlaybackQuality.h
Normal file
68
content/media/VideoPlaybackQuality.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_VideoPlaybackQuality_h_
|
||||
#define mozilla_dom_VideoPlaybackQuality_h_
|
||||
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsDOMNavigationTiming.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class VideoPlaybackQuality MOZ_FINAL : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VideoPlaybackQuality)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VideoPlaybackQuality)
|
||||
|
||||
VideoPlaybackQuality(HTMLMediaElement* aElement, DOMHighResTimeStamp aCreationTime,
|
||||
uint64_t aTotalFrames, uint64_t aDroppedFrames,
|
||||
uint64_t aCorruptedFrames, double aPlaybackJitter);
|
||||
|
||||
HTMLMediaElement* GetParentObject() const;
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
||||
DOMHighResTimeStamp CreationTime() const
|
||||
{
|
||||
return mCreationTime;
|
||||
}
|
||||
|
||||
uint64_t TotalVideoFrames()
|
||||
{
|
||||
return mTotalFrames;
|
||||
}
|
||||
|
||||
uint64_t DroppedVideoFrames()
|
||||
{
|
||||
return mDroppedFrames;
|
||||
}
|
||||
|
||||
uint64_t CorruptedVideoFrames()
|
||||
{
|
||||
return mCorruptedFrames;
|
||||
}
|
||||
|
||||
double PlaybackJitter()
|
||||
{
|
||||
return mPlaybackJitter;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<HTMLMediaElement> mElement;
|
||||
DOMHighResTimeStamp mCreationTime;
|
||||
uint64_t mTotalFrames;
|
||||
uint64_t mDroppedFrames;
|
||||
uint64_t mCorruptedFrames;
|
||||
double mPlaybackJitter;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
#endif /* mozilla_dom_VideoPlaybackQuality_h_ */
|
@ -85,6 +85,7 @@ EXPORTS.mozilla.dom += [
|
||||
'TextTrackCue.h',
|
||||
'TextTrackCueList.h',
|
||||
'TextTrackList.h',
|
||||
'VideoPlaybackQuality.h',
|
||||
'VideoStreamTrack.h',
|
||||
]
|
||||
|
||||
@ -112,6 +113,7 @@ CPP_SOURCES += [
|
||||
'TextTrackCueList.cpp',
|
||||
'TextTrackList.cpp',
|
||||
'VideoFrameContainer.cpp',
|
||||
'VideoPlaybackQuality.cpp',
|
||||
'VideoSegment.cpp',
|
||||
'VideoStreamTrack.cpp',
|
||||
'VideoUtils.cpp',
|
||||
|
@ -28,6 +28,7 @@ EXPORTS += [
|
||||
'nsDOMClassInfoClasses.h',
|
||||
'nsDOMClassInfoID.h',
|
||||
'nsDOMJSUtils.h',
|
||||
'nsDOMNavigationTiming.h',
|
||||
'nsDOMString.h',
|
||||
'nsFocusManager.h',
|
||||
'nsIDOMClassInfo.h',
|
||||
@ -47,6 +48,7 @@ EXPORTS += [
|
||||
'nsJSUtils.h',
|
||||
'nsPIDOMWindow.h',
|
||||
'nsPIWindowRoot.h',
|
||||
'nsPerformance.h',
|
||||
'nsStructuredCloneContainer.h',
|
||||
'nsWindowMemoryReporter.h',
|
||||
'nsWrapperCache.h',
|
||||
|
@ -1122,6 +1122,10 @@ DOMInterfaces = {
|
||||
'workers': True,
|
||||
}],
|
||||
|
||||
'VideoPlaybackQuality': {
|
||||
'nativeOwnership': 'refcounted',
|
||||
},
|
||||
|
||||
'VideoStreamTrack': {
|
||||
},
|
||||
|
||||
|
@ -45,3 +45,9 @@ partial interface HTMLVideoElement {
|
||||
// True if the video has an audio track available.
|
||||
readonly attribute boolean mozHasAudio;
|
||||
};
|
||||
|
||||
// https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#idl-def-HTMLVideoElement
|
||||
partial interface HTMLVideoElement {
|
||||
[Pref="media.mediasource.enabled", Creator]
|
||||
readonly attribute VideoPlaybackQuality videoPlaybackQuality;
|
||||
};
|
||||
|
20
dom/webidl/VideoPlaybackQuality.webidl
Normal file
20
dom/webidl/VideoPlaybackQuality.webidl
Normal file
@ -0,0 +1,20 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Pref="media.mediasource.enabled"]
|
||||
interface VideoPlaybackQuality {
|
||||
readonly attribute unsigned long totalVideoFrames;
|
||||
readonly attribute unsigned long droppedVideoFrames;
|
||||
readonly attribute unsigned long corruptedVideoFrames;
|
||||
readonly attribute double playbackJitter;
|
||||
};
|
||||
|
@ -345,6 +345,7 @@ webidl_files = \
|
||||
WheelEvent.webidl \
|
||||
UndoManager.webidl \
|
||||
URLUtils.webidl \
|
||||
VideoPlaybackQuality.webidl \
|
||||
VideoStreamTrack.webidl \
|
||||
WaveShaperNode.webidl \
|
||||
Window.webidl \
|
||||
|
Loading…
Reference in New Issue
Block a user