Back out 29ec386d969f and ed18b0cca283 (bug 462959) for a very frequent assertion loop in test_played.html

This commit is contained in:
Phil Ringnalda 2011-07-03 18:26:00 -07:00
parent 87578b97f7
commit 902b4e6f6f
10 changed files with 7 additions and 351 deletions

View File

@ -50,7 +50,6 @@
#include "nsIObserver.h"
#include "ImageLayers.h"
#include "nsAudioStream.h"
#include "nsTimeRanges.h"
// Define to output information on decoding and painting framerate
/* #define DEBUG_FRAME_RATE 1 */
@ -625,12 +624,6 @@ protected:
// a media and element same-origin check.
PRBool mAllowAudioData;
// Range of time played.
nsTimeRanges mPlayed;
// Temporary variable for storing a time, when the stream starts to play
double mCurrentPlayRangeStart;
// If true then we have begun downloading the media content.
// Set to false when completed, or not yet started.
PRPackedBool mBegun;

View File

@ -39,6 +39,7 @@
#include "nsIDOMHTMLMediaElement.h"
#include "nsIDOMHTMLSourceElement.h"
#include "nsHTMLMediaElement.h"
#include "nsTimeRanges.h"
#include "nsGenericHTMLElement.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
@ -1091,16 +1092,6 @@ NS_IMETHODIMP nsHTMLMediaElement::SetCurrentTime(double aCurrentTime)
{
StopSuspendingAfterFirstFrame();
if (mCurrentPlayRangeStart != -1) {
double oldCurrentTime = 0;
GetCurrentTime(&oldCurrentTime);
LOG(PR_LOG_DEBUG, ("Adding a range: [%f, %f]", mCurrentPlayRangeStart, oldCurrentTime));
// Multiple seek without playing
if (mCurrentPlayRangeStart != oldCurrentTime) {
mPlayed.Add(mCurrentPlayRangeStart, oldCurrentTime);
}
}
if (!mDecoder) {
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) failed: no decoder", this, aCurrentTime));
return NS_ERROR_DOM_INVALID_STATE_ERR;
@ -1130,9 +1121,6 @@ NS_IMETHODIMP nsHTMLMediaElement::SetCurrentTime(double aCurrentTime)
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) starting seek", this, aCurrentTime));
nsresult rv = mDecoder->Seek(clampedTime);
// Start a new range at position we seeked to
mCurrentPlayRangeStart = clampedTime;
// We changed whether we're seeking so we need to AddRemoveSelfReference
AddRemoveSelfReference();
@ -1154,35 +1142,6 @@ NS_IMETHODIMP nsHTMLMediaElement::GetPaused(PRBool *aPaused)
return NS_OK;
}
/* readonly attribute nsIDOMHTMLTimeRanges played; */
NS_IMETHODIMP nsHTMLMediaElement::GetPlayed(nsIDOMTimeRanges** aPlayed)
{
nsRefPtr<nsTimeRanges> ranges = new nsTimeRanges();
PRUint32 timeRangeCount = 0;
mPlayed.GetLength(&timeRangeCount);
for (PRUint32 i = 0; i < timeRangeCount; i++) {
double begin;
double end;
mPlayed.Start(i, &begin);
mPlayed.End(i, &end);
ranges->Add(begin, end);
}
if (mCurrentPlayRangeStart != -1.0) {
double now = 0.0;
GetCurrentTime(&now);
if (mCurrentPlayRangeStart != now) {
ranges->Add(mCurrentPlayRangeStart, now);
}
}
ranges->Normalize();
ranges.forget(aPlayed);
return NS_OK;
}
/* void pause (); */
NS_IMETHODIMP nsHTMLMediaElement::Pause()
{
@ -1321,7 +1280,6 @@ nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
mMediaSize(-1,-1),
mLastCurrentTime(0.0),
mAllowAudioData(PR_FALSE),
mCurrentPlayRangeStart(-1.0),
mBegun(PR_FALSE),
mLoadedFirstFrame(PR_FALSE),
mAutoplaying(PR_TRUE),
@ -1422,10 +1380,6 @@ NS_IMETHODIMP nsHTMLMediaElement::Play()
}
}
if (mCurrentPlayRangeStart == -1.0) {
GetCurrentTime(&mCurrentPlayRangeStart);
}
// TODO: If the playback has ended, then the user agent must set
// seek to the effective start.
// TODO: The playback rate must be set to the default playback rate.
@ -2080,13 +2034,6 @@ void nsHTMLMediaElement::PlaybackEnded()
// We changed the state of IsPlaybackEnded which can affect AddRemoveSelfReference
AddRemoveSelfReference();
double end = 0.0;
GetCurrentTime(&end);
if (mCurrentPlayRangeStart != end) {
mPlayed.Add(mCurrentPlayRangeStart, end);
}
mCurrentPlayRangeStart = -1.0;
FireTimeUpdate(PR_FALSE);
DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
}
@ -2502,7 +2449,7 @@ void nsHTMLMediaElement::NotifyAddedSource()
}
// A load was paused in the resource selection algorithm, waiting for
// a new source child to be added, resume the resource selection algorithm.
// a new source child to be added, resume the resource selction algorithm.
if (mLoadWaitStatus == WAITING_FOR_SOURCE) {
QueueLoadFromSourceTask();
}

View File

@ -85,28 +85,3 @@ void
nsTimeRanges::Add(double aStart, double aEnd) {
mRanges.AppendElement(TimeRange(aStart,aEnd));
}
void
nsTimeRanges::Normalize() {
if (mRanges.Length() <= 1) {
return;
}
nsAutoTArray<TimeRange, 4> normalized;
mRanges.Sort(CompareTimeRanges());
// This merges the intervals
TimeRange current(mRanges[0]);
for (PRUint32 i = 1; i < mRanges.Length(); i++) {
if (current.mEnd >= mRanges[i].mStart) {
current.mEnd = NS_MAX(current.mEnd, mRanges[i].mEnd);
} else {
normalized.AppendElement(current);
current = mRanges[i];
}
}
normalized.AppendElement(current);
mRanges = normalized;
}

View File

@ -55,9 +55,6 @@ public:
void Add(double aStart, double aEnd);
// See <http://www.whatwg.org/html/#normalized-timeranges-object>.
void Normalize();
private:
struct TimeRange {
@ -68,21 +65,6 @@ private:
double mEnd;
};
struct CompareTimeRanges
{
PRBool Equals(const TimeRange& tr1, const TimeRange& tr2) const
{
return tr1.mStart == tr2.mStart && tr1.mEnd == tr2.mEnd;
}
// Here, we aim at time range normalization. That why we order only by start
// time, since the ranges can overlap.
PRBool LessThan(const TimeRange& tr1, const TimeRange& tr2) const
{
return tr1.mStart < tr2.mStart;
}
};
nsAutoTArray<TimeRange,4> mRanges;
};

View File

@ -126,7 +126,6 @@ _TEST_FILES = \
test_paused_after_ended.html \
test_play_events.html \
test_play_events_2.html \
test_played.html \
test_playback.html \
test_playback_errors.html \
test_preload_actions.html \

View File

@ -23,14 +23,6 @@ var gProgressTests = [
{ name:"bogus.duh", type:"bogus/duh" }
];
// Used by test_played
var gPlayedTests = [
{ name:"big.wav", type:"audio/x-wav", duration:9.0, size:102444 },
{ name:"sound.ogg", type:"audio/ogg", duration:4.0, size:2603 },
{ name:"seek.ogv", type:"video/ogg", duration:3.966, size:285310 },
{ name:"seek.webm", type:"video/webm", duration:3.966 }
];
// Used by test_mozLoadFrom. Need one test file per decoder backend, plus
// anything for testing clone-specific bugs.
var gCloneTests = gSmallTests.concat([

View File

@ -1,231 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test played member for media elements</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id='test'>
<script class="testbody" type='application/javascript;version=1.8'>
let manager = new MediaTestManager;
function finish_test(element) {
if (element.parentNode)
element.parentNode.removeChild(element);
element.src = "";
manager.finished(element.token);
}
// Check that a file has been played in its entirety
function check_full_file_played(element) {
element.addEventListener('ended', function() {
let interval_count = element.played.length;
is(interval_count, 1, "normal play: a.played.length must be 1");
is(element.played.start(0), 0, "start time shall be 0");
is(element.played.end(0), element.duration, "end time shall be duration");
finish_test(element);
}, false);
}
var tests = [
// Without playing, check that player.played.length == 0
{
setup : function(element) {
element.addEventListener("loadedmetadata", function() {
is(element.played.length, 0, "audio: initial played.length equals zero");
finish_test(element);
});
}
},
// Play the file, test the range we have
{
setup : function(element) {
check_full_file_played(element);
element.play();
}
},
// Play the first half of the file, pause, play
// and check we have only one range
{
setup : function (element) {
let onEnded = function() {
element.pause();
element.currentTime = 0;
element.play();
}
element.addEventListener("ended", onEnded, false);
check_full_file_played(element);
element.play();
}
},
// Play the first half of the file, seek back, while
// continuing to play. We shall have only one range
{
setup : function (element) {
let onTimeUpdate = function() {
if (element.currentTime > element.duration / 2) {
element.removeEventListener("timeupdate", onTimeUpdate, false);
element.currentTime = element.duration / 4;
}
}
element.addEventListener("timeupdate", onTimeUpdate, false);
check_full_file_played(element);
element.play();
}
},
// Play and seek to have two ranges, and check that, as well a
// boundaries
{
setup : function (element) {
let onTimeUpdate = function() {
if (element.currentTime > element.duration / 2) {
element.removeEventListener("timeupdate", onTimeUpdate, false);
element.pause();
element.currentTime += element.duration / 10;
element.play();
}
}
element.addEventListener("loadedmetadata", function() {
element.addEventListener("timeupdate", onTimeUpdate, false);
}, false);
element.addEventListener("ended", (function() {
is(element.played.length, 2, "element.played.length == 2");
is(element.played.start(0), 0, "start of first range shall be 0");
var guess = element.played.end(0) + element.duration / 10.0;
ok(rangeCheck(element.played.start(1), guess), "we should have seeked forward by one tenth of the duration");
is(element.played.end(1), element.duration, "end of second range shall be the total duration");
finish_test(element);
}), false);
element.play();
}
},
// Play and seek to have to overlapping ranges. They should be merged, to a
// range spanning all the test audio file.
{
setup : function (element) {
let onTimeUpdate = function() {
if (element.currentTime > element.duration / 2) {
element.removeEventListener("timeupdate", onTimeUpdate, false);
element.currentTime = element.duration / 3;
}
};
element.addEventListener("loadedmetadata", function() {
element.addEventListener("timeupdate", onTimeUpdate, false);
check_full_file_played(element);
element.play();
}, false);
}
},
// Play to create two ranges, in the reverse order. check that they are sorted.
{
setup : function (element) {
function end() {
element.pause();
let p = element.played;
ok(p.length >= 1, "There should be at least one range");
is(p.start(0), element.duration / 6,
"Start of first range should be the sixth of the duration");
ok(p.end(p.length - 1) > 5 * element.duration / 6,
"End of last range should be greater that five times the sixth of the duration");
finish_test(element);
}
function pauseseekrestart() {
element.pause();
element.currentTime = element.duration / 6;
element.play();
}
function onTimeUpdate_pauseseekrestart() {
if (element.currentTime > 5 * element.duration / 6) {
element.removeEventListener("timeupdate", onTimeUpdate_pauseseekrestart, false);
pauseseekrestart();
element.addEventListener("timeupdate", onTimeUpdate_end, false);
}
}
function onTimeUpdate_end() {
if (element.currentTime > 3 * element.duration / 6) {
element.removeEventListener("timeupdate", onTimeUpdate_end, false);
end();
}
}
element.addEventListener("timeupdate", onTimeUpdate_pauseseekrestart, false);
element.addEventListener('loadedmetadata', function() {
element.currentTime = 4 * element.duration / 6;
element.play();
}, false);
}
},
// Seek repeatedly without playing. No range should appear.
{
setup : function(element) {
let index = 1;
element.addEventListener('ended', function() {
is(element.played.length, 0, "element.played.length should be 0");
finish_test(element);
}, false);
element.addEventListener('seeked', function() {
index++;
element.currentTime = index * element.duration / 5;
}, false);
element.addEventListener('loadedmetadata', function() {
element.currentTime = element.duration / 5;
}, false);
}
}
];
function rangeCheck(n1, n2) {
var THRESHOLD = 0.35;
var diff = Math.abs(n1 - n2);
return diff < THRESHOLD;
}
function createTestArray(tests) {
var A = [];
for (var i = 0; i < tests.length; i++) {
for (var k = 0; k < gPlayedTests.length; k++) {
A.push({
setup : tests[i].setup,
name : gPlayedTests[k].name,
type : gPlayedTests[k].type
});
}
}
return A;
}
function startTest(test, token) {
var elemType = /^audio/.test(test.type) ? "audio" : "video";
var element = document.createElement(elemType);
element.src = test.name;
element.token = token;
test.setup(element);
manager.started(token);
}
manager.runTests(createTestArray(tests), startTest);
</script>
</pre>
</body>
</html>

View File

@ -52,7 +52,7 @@
* @status UNDER_DEVELOPMENT
*/
[scriptable, uuid(1f2437f1-6037-40c4-bfb6-105c6c60f0ca)]
[scriptable, uuid(f0d4977c-9632-4fab-bc9b-91c250a6ef96)]
interface nsIDOMHTMLAudioElement : nsIDOMHTMLMediaElement
{
// Setup the audio stream for writing

View File

@ -57,7 +57,7 @@
#endif
%}
[scriptable, uuid(c8a5f714-97de-4e2c-8394-2397870224bb)]
[scriptable, uuid(d8213322-46d8-47ca-a15c-2abae47ddfde)]
interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
{
// error state
@ -89,7 +89,6 @@ interface nsIDOMHTMLMediaElement : nsIDOMHTMLElement
attribute double currentTime;
readonly attribute double duration;
readonly attribute boolean paused;
readonly attribute nsIDOMTimeRanges played;
readonly attribute boolean ended;
readonly attribute boolean mozAutoplayEnabled;
attribute boolean autoplay;

View File

@ -48,15 +48,15 @@
* @status UNDER_DEVELOPMENT
*/
[scriptable, uuid(169f0ff1-511a-453d-86b6-346c1e936122)]
[scriptable, uuid(00c757ec-db7b-477e-95cd-b2a03b0f8634)]
interface nsIDOMHTMLVideoElement : nsIDOMHTMLMediaElement
{
attribute long width;
attribute long width;
attribute long height;
readonly attribute unsigned long videoWidth;
readonly attribute unsigned long videoHeight;
attribute DOMString poster;
// A count of the number of video frames that have demuxed from the media
// resource. If we were playing perfectly, we'd be able to paint this many
// frames.