b=925619 truncate TrackTicks differences to uint32_t after limiting to WEBAUDIO_BLOCK_SIZE r=ehsan
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 23 Oct 2013 18:36:59 +1300
changeset 166660 506e26a05071c60b4496e40794451c81b3f400c1
parent 166659 440b13668e560b8467fb350a8896170b01e8665e
child 166661 05073dcfd397fac7ed376284a68020aa010a8b5c
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs925619
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=925619 truncate TrackTicks differences to uint32_t after limiting to WEBAUDIO_BLOCK_SIZE r=ehsan
content/media/test/crashtests/925619-1.html
content/media/test/crashtests/925619-2.html
content/media/test/crashtests/crashtests.list
content/media/webaudio/AudioBufferSourceNode.cpp
new file mode 100644
--- /dev/null
+++ b/content/media/test/crashtests/925619-1.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<script>
+// 1024 > 89478.5 * 48000 - (1 << 32)
+var context = new window.OfflineAudioContext(1, 1024, 48000);
+context.oncomplete = function(e) {
+    document.documentElement.removeAttribute("class");
+};
+var buffer = context.createBuffer(1, 2048, context.sampleRate);
+var source = context.createBufferSource();
+source.buffer = buffer;
+source.start(89478.5); // 89478.5 is a little greater than 2^32 / 48000.
+context.startRendering();
+</script>
new file mode 100644
--- /dev/null
+++ b/content/media/test/crashtests/925619-2.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<script>
+var context = new window.OfflineAudioContext(1, 2048, 48000);
+// 1024 > 89478.5 * 48000 - (1 << 32)
+var buffer = context.createBuffer(1, 1024, context.sampleRate);
+var source = context.createBufferSource();
+source.buffer = buffer;
+source.onended = function(e) {
+  document.documentElement.removeAttribute("class");
+};
+source.start(0);
+source.stop(89478.5); // 89478.5 is a little greater than 2^32 / 48000.
+context.startRendering();
+</script>
--- a/content/media/test/crashtests/crashtests.list
+++ b/content/media/test/crashtests/crashtests.list
@@ -52,11 +52,13 @@ load 884459.html
 load 889042.html
 test-pref(media.webvtt.enabled,true) load 894104.html
 load 907986-1.html
 load 907986-2.html
 load 907986-3.html
 load 907986-4.html
 load 910171-1.html
 load 920987.html
+load 925619-1.html
+load 925619-2.html
 skip-if(B2G) load oscillator-ended-1.html # intermittent B2G timeouts, bug 920338
 skip-if(B2G) load oscillator-ended-2.html # intermittent B2G timeouts, bug 920338
 test-pref(media.mediasource.enabled,true) load 926665.html
--- a/content/media/webaudio/AudioBufferSourceNode.cpp
+++ b/content/media/webaudio/AudioBufferSourceNode.cpp
@@ -241,18 +241,20 @@ public:
    * memory allocations.
    */
   void FillWithZeroes(AudioChunk* aOutput,
                       uint32_t aChannels,
                       uint32_t* aOffsetWithinBlock,
                       TrackTicks* aCurrentPosition,
                       TrackTicks aMaxPos)
   {
-    uint32_t numFrames = std::min(WEBAUDIO_BLOCK_SIZE - *aOffsetWithinBlock,
-                                  uint32_t(aMaxPos - *aCurrentPosition));
+    MOZ_ASSERT(*aCurrentPosition < aMaxPos);
+    uint32_t numFrames =
+      std::min<TrackTicks>(WEBAUDIO_BLOCK_SIZE - *aOffsetWithinBlock,
+                           aMaxPos - *aCurrentPosition);
     if (numFrames == WEBAUDIO_BLOCK_SIZE) {
       aOutput->SetNull(numFrames);
     } else {
       if (aOutput->IsNull()) {
         AllocateAudioBlock(aChannels, aOutput);
       }
       WriteZeroesToAudioBlock(aOutput, *aOffsetWithinBlock, numFrames);
     }
@@ -272,19 +274,21 @@ public:
   void CopyFromBuffer(AudioNodeStream* aStream,
                       AudioChunk* aOutput,
                       uint32_t aChannels,
                       uint32_t* aOffsetWithinBlock,
                       TrackTicks* aCurrentPosition,
                       uint32_t aBufferOffset,
                       uint32_t aBufferMax)
   {
-    uint32_t numFrames = std::min(std::min(WEBAUDIO_BLOCK_SIZE - *aOffsetWithinBlock,
-                                           aBufferMax - aBufferOffset),
-                                  uint32_t(mStop - *aCurrentPosition));
+    MOZ_ASSERT(*aCurrentPosition < mStop);
+    uint32_t numFrames =
+      std::min<TrackTicks>(std::min(WEBAUDIO_BLOCK_SIZE - *aOffsetWithinBlock,
+                                    aBufferMax - aBufferOffset),
+                           mStop - *aCurrentPosition);
     if (numFrames == WEBAUDIO_BLOCK_SIZE && !ShouldResample(aStream->SampleRate())) {
       BorrowFromInputBuffer(aOutput, aChannels, aBufferOffset);
       *aOffsetWithinBlock += numFrames;
       *aCurrentPosition += numFrames;
       mPosition += numFrames;
     } else {
       if (aOutput->IsNull()) {
         MOZ_ASSERT(*aOffsetWithinBlock == 0);