Bug 855130 - Implement HTMLVideoElement's VideoPlaybackQuality (from Media Source Extensions spec). r=roc

This commit is contained in:
Matthew Gregan 2013-06-28 16:32:05 +12:00
parent b53bbbf3fe
commit 07a8149c7d
13 changed files with 216 additions and 1 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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()
{

View File

@ -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;

View File

@ -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;
}

View 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

View 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_ */

View File

@ -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',

View File

@ -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',

View File

@ -1122,6 +1122,10 @@ DOMInterfaces = {
'workers': True,
}],
'VideoPlaybackQuality': {
'nativeOwnership': 'refcounted',
},
'VideoStreamTrack': {
},

View File

@ -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;
};

View 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;
};

View File

@ -345,6 +345,7 @@ webidl_files = \
WheelEvent.webidl \
UndoManager.webidl \
URLUtils.webidl \
VideoPlaybackQuality.webidl \
VideoStreamTrack.webidl \
WaveShaperNode.webidl \
Window.webidl \