Bug 1427932. P1 - replace NS_ASSERTION with MOZ_ASSERT to catch more bugs. r=jya
authorJW Wang <jwwang@mozilla.com>
Thu, 04 Jan 2018 11:09:54 +0800
changeset 453018 5765be2f5f105df8a6c24b7d9366b271916317d4
parent 452925 c2953fa3577168bcd574761ab452490e1e0e4fc7
child 453019 b861f596cf9e2e179e96cafed7c6d325fcb3c28e
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1427932
milestone59.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
Bug 1427932. P1 - replace NS_ASSERTION with MOZ_ASSERT to catch more bugs. r=jya MozReview-Commit-ID: H5SNFz956nG
dom/media/ogg/OggDemuxer.cpp
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -567,17 +567,17 @@ OggDemuxer::ReadMetadata()
     }
 
     if (mInfo.mMetadataDuration.isNothing() &&
         Resource(TrackInfo::kAudioTrack)->GetLength() >= 0) {
       // We didn't get a duration from the index or a Content-Duration header.
       // Seek to the end of file to find the end time.
       int64_t length = Resource(TrackInfo::kAudioTrack)->GetLength();
 
-      NS_ASSERTION(length > 0, "Must have a content length to get end time");
+      MOZ_ASSERT(length > 0, "Must have a content length to get end time");
 
       int64_t endTime = RangeEndTime(TrackInfo::kAudioTrack, length);
 
       if (endTime != -1) {
         mInfo.mUnadjustedMetadataEndTime.emplace(TimeUnit::FromMicroseconds(endTime));
         mInfo.mMetadataDuration.emplace(TimeUnit::FromMicroseconds(endTime - mStartTime.refOr(0)));
         OGG_DEBUG("Got Ogg duration from seeking to end %" PRId64, endTime);
       }
@@ -776,17 +776,17 @@ OggDemuxer::ReadOggPage(TrackInfo::Track
     if (ret < 0) {
       // Lost page sync, have to skip up to next page.
       continue;
     }
     // Returns a buffer that can be written too
     // with the given size. This buffer is stored
     // in the ogg synchronisation structure.
     char* buffer = ogg_sync_buffer(OggSyncState(aType), 4096);
-    NS_ASSERTION(buffer, "ogg_sync_buffer failed");
+    MOZ_ASSERT(buffer, "ogg_sync_buffer failed");
 
     // Read from the resource into the buffer
     uint32_t bytesRead = 0;
 
     nsresult rv = Resource(aType)->Read(buffer, 4096, &bytesRead);
     if (NS_FAILED(rv) || !bytesRead) {
       // End of file or error.
       return false;
@@ -951,29 +951,29 @@ OggDemuxer::GetBuffered(TrackInfo::Track
         startOffset += page.header_len + page.body_len;
         continue;
       }
 
       uint32_t serial = ogg_page_serialno(&page);
       if (aType == TrackInfo::kAudioTrack && mVorbisState &&
           serial == mVorbisState->mSerial) {
         startTime = mVorbisState->Time(granulepos);
-        NS_ASSERTION(startTime > 0, "Must have positive start time");
+        MOZ_ASSERT(startTime > 0, "Must have positive start time");
       } else if (aType == TrackInfo::kAudioTrack && mOpusState &&
                  serial == mOpusState->mSerial) {
         startTime = mOpusState->Time(granulepos);
-        NS_ASSERTION(startTime > 0, "Must have positive start time");
+        MOZ_ASSERT(startTime > 0, "Must have positive start time");
       } else if (aType == TrackInfo::kAudioTrack && mFlacState &&
                  serial == mFlacState->mSerial) {
         startTime = mFlacState->Time(granulepos);
-        NS_ASSERTION(startTime > 0, "Must have positive start time");
+        MOZ_ASSERT(startTime > 0, "Must have positive start time");
       } else if (aType == TrackInfo::kVideoTrack && mTheoraState &&
                  serial == mTheoraState->mSerial) {
         startTime = mTheoraState->Time(granulepos);
-        NS_ASSERTION(startTime > 0, "Must have positive start time");
+        MOZ_ASSERT(startTime > 0, "Must have positive start time");
       } else if (mCodecStore.Contains(serial)) {
         // Stream is not the theora or vorbis stream we're playing,
         // but is one that we have header data for.
         startOffset += page.header_len + page.body_len;
         continue;
       } else {
         // Page is for a stream we don't know about (possibly a chained
         // ogg), return OK to abort the finding any further ranges. This
@@ -1235,22 +1235,22 @@ OggDemuxer::PageSync(MediaResourceIndex*
   // Sync to the next page.
   int ret = 0;
   uint32_t bytesRead = 0;
   int64_t readHead = aOffset;
   while (ret <= 0) {
     ret = ogg_sync_pageseek(aState, aPage);
     if (ret == 0) {
       char* buffer = ogg_sync_buffer(aState, PAGE_STEP);
-      NS_ASSERTION(buffer, "Must have a buffer");
+      MOZ_ASSERT(buffer, "Must have a buffer");
 
       // Read from the file into the buffer
       int64_t bytesToRead = std::min(static_cast<int64_t>(PAGE_STEP),
                                    aEndOffset - readHead);
-      NS_ASSERTION(bytesToRead <= UINT32_MAX, "bytesToRead range check");
+      MOZ_ASSERT(bytesToRead <= UINT32_MAX, "bytesToRead range check");
       if (bytesToRead <= 0) {
         return PAGE_SYNC_END_OF_RANGE;
       }
       nsresult rv = NS_OK;
       if (aCachedDataOnly) {
         rv = aResource->GetResource()->ReadFromCache(buffer, readHead,
                                                      static_cast<uint32_t>(bytesToRead));
         NS_ENSURE_SUCCESS(rv,PAGE_SYNC_ERROR);
@@ -1272,19 +1272,19 @@ OggDemuxer::PageSync(MediaResourceIndex*
       // Update the synchronisation layer with the number
       // of bytes written to the buffer
       ret = ogg_sync_wrote(aState, bytesRead);
       NS_ENSURE_TRUE(ret == 0, PAGE_SYNC_ERROR);
       continue;
     }
 
     if (ret < 0) {
-      NS_ASSERTION(aSkippedBytes >= 0, "Offset >= 0");
+      MOZ_ASSERT(aSkippedBytes >= 0, "Offset >= 0");
       aSkippedBytes += -ret;
-      NS_ASSERTION(aSkippedBytes >= 0, "Offset >= 0");
+      MOZ_ASSERT(aSkippedBytes >= 0, "Offset >= 0");
       continue;
     }
   }
 
   return PAGE_SYNC_OK;
 }
 
 //OggTrackDemuxer
@@ -1537,24 +1537,24 @@ OggDemuxer::RangeEndTime(TrackInfo::Trac
 
       int64_t limit = std::min(static_cast<int64_t>(UINT32_MAX),
                                aEndOffset - readHead);
       limit = std::max(static_cast<int64_t>(0), limit);
       limit = std::min(limit, static_cast<int64_t>(step));
       uint32_t bytesToRead = static_cast<uint32_t>(limit);
       uint32_t bytesRead = 0;
       char* buffer = ogg_sync_buffer(&sync.mState, bytesToRead);
-      NS_ASSERTION(buffer, "Must have buffer");
+      MOZ_ASSERT(buffer, "Must have buffer");
       nsresult res;
       if (aCachedDataOnly) {
         res = Resource(aType)->GetResource()->ReadFromCache(buffer, readHead, bytesToRead);
         NS_ENSURE_SUCCESS(res, -1);
         bytesRead = bytesToRead;
       } else {
-        NS_ASSERTION(readHead < aEndOffset,
+        MOZ_ASSERT(readHead < aEndOffset,
                      "resource pos must be before range end");
         res = Resource(aType)->Seek(nsISeekableStream::NS_SEEK_SET, readHead);
         NS_ENSURE_SUCCESS(res, -1);
         res = Resource(aType)->Read(buffer, bytesToRead, &bytesRead);
         NS_ENSURE_SUCCESS(res, -1);
       }
       readHead += bytesRead;
       if (readHead > readLimitOffset) {
@@ -1705,17 +1705,17 @@ OggDemuxer::SeekInBufferedRange(TrackInf
 
     // We have an active Theora bitstream. Peek the next Theora frame, and
     // extract its keyframe's time.
     DemuxUntilPacketAvailable(aType, mTheoraState);
     ogg_packet* packet = mTheoraState->PacketPeek();
     if (packet && !mTheoraState->IsKeyframe(packet)) {
       // First post-seek frame isn't a keyframe, seek back to previous keyframe,
       // otherwise we'll get visual artifacts.
-      NS_ASSERTION(packet->granulepos != -1, "Must have a granulepos");
+      MOZ_ASSERT(packet->granulepos != -1, "Must have a granulepos");
       int shift = mTheoraState->KeyFrameGranuleJobs();
       int64_t keyframeGranulepos = (packet->granulepos >> shift) << shift;
       int64_t keyframeTime = mTheoraState->StartTime(keyframeGranulepos);
       SEEK_LOG(LogLevel::Debug,
                ("Keyframe for %lld is at %lld, seeking back to it", frameTime,
                 keyframeTime));
       aAdjustedTarget = std::min(aAdjustedTarget, keyframeTime);
     }
@@ -1797,17 +1797,17 @@ OggDemuxer::SeekBisection(TrackInfo::Tra
   ogg_int64_t endTime = aRange.mTimeEnd;
 
   ogg_int64_t seekTarget = aTarget;
   int64_t seekLowerBound = std::max(static_cast<int64_t>(0), aTarget - aFuzz);
   int hops = 0;
   DebugOnly<ogg_int64_t> previousGuess = -1;
   int backsteps = 0;
   const int maxBackStep = 10;
-  NS_ASSERTION(static_cast<uint64_t>(PAGE_STEP) * pow(2.0, maxBackStep) < INT32_MAX,
+  MOZ_ASSERT(static_cast<uint64_t>(PAGE_STEP) * pow(2.0, maxBackStep) < INT32_MAX,
                "Backstep calculation must not overflow");
 
   // Seek via bisection search. Loop until we find the offset where the page
   // before the offset is before the seek target, and the page after the offset
   // is after the seek target.
   while (true) {
     ogg_int64_t duration = 0;
     double target = 0;
@@ -1874,19 +1874,19 @@ OggDemuxer::SeekBisection(TrackInfo::Tra
       guess = std::max(guess, startOffset + startLength);
 
       SEEK_LOG(LogLevel::Debug, ("Seek loop start[o=%lld..%lld t=%lld] "
                               "end[o=%lld t=%lld] "
                               "interval=%lld target=%lf guess=%lld",
                               startOffset, (startOffset+startLength), startTime,
                               endOffset, endTime, interval, target, guess));
 
-      NS_ASSERTION(guess >= startOffset + startLength, "Guess must be after range start");
-      NS_ASSERTION(guess < endOffset, "Guess must be before range end");
-      NS_ASSERTION(guess != previousGuess, "Guess should be different to previous");
+      MOZ_ASSERT(guess >= startOffset + startLength, "Guess must be after range start");
+      MOZ_ASSERT(guess < endOffset, "Guess must be before range end");
+      MOZ_ASSERT(guess != previousGuess, "Guess should be different to previous");
       previousGuess = guess;
 
       hops++;
 
       // Locate the next page after our seek guess, and then figure out the
       // granule time of the audio and video bitstreams there. We can then
       // make a bisection decision based on our location in the media.
       PageSyncResult pageSyncResult = PageSync(Resource(aType),
@@ -1976,25 +1976,25 @@ OggDemuxer::SeekBisection(TrackInfo::Tra
         // that we've got more room to capture.
         mustBackoff = true;
         continue;
       }
 
       // We've found appropriate time stamps here. Proceed to bisect
       // the search space.
       granuleTime = aType == TrackInfo::kAudioTrack ? audioTime : videoTime;
-      NS_ASSERTION(granuleTime > 0, "Must get a granuletime");
+      MOZ_ASSERT(granuleTime > 0, "Must get a granuletime");
       break;
     } // End of "until we determine time at guess offset" loop.
 
     if (interval == 0) {
       // Seek termination condition; we've found the page boundary of the
       // last page before the target, and the first page after the target.
       SEEK_LOG(LogLevel::Debug, ("Terminating seek at offset=%lld", startOffset));
-      NS_ASSERTION(startTime < aTarget, "Start time must always be less than target");
+      MOZ_ASSERT(startTime < aTarget, "Start time must always be less than target");
       res = Resource(aType)->Seek(nsISeekableStream::NS_SEEK_SET, startOffset);
       NS_ENSURE_SUCCESS(res,res);
       if (NS_FAILED(Reset(aType))) {
         return NS_ERROR_FAILURE;
       }
       break;
     }
 
@@ -2007,29 +2007,29 @@ OggDemuxer::SeekBisection(TrackInfo::Tra
         return NS_ERROR_FAILURE;
       }
       SEEK_LOG(LogLevel::Debug, ("Terminating seek at offset=%lld", pageOffset));
       break;
     }
 
     if (granuleTime >= seekTarget) {
       // We've landed after the seek target.
-      NS_ASSERTION(pageOffset < endOffset, "offset_end must decrease");
+      MOZ_ASSERT(pageOffset < endOffset, "offset_end must decrease");
       endOffset = pageOffset;
       endTime = granuleTime;
     } else if (granuleTime < seekTarget) {
       // Landed before seek target.
-      NS_ASSERTION(pageOffset >= startOffset + startLength,
+      MOZ_ASSERT(pageOffset >= startOffset + startLength,
         "Bisection point should be at or after end of first page in interval");
       startOffset = pageOffset;
       startLength = pageLength;
       startTime = granuleTime;
     }
-    NS_ASSERTION(startTime <= seekTarget, "Must be before seek target");
-    NS_ASSERTION(endTime >= seekTarget, "End must be after seek target");
+    MOZ_ASSERT(startTime <= seekTarget, "Must be before seek target");
+    MOZ_ASSERT(endTime >= seekTarget, "End must be after seek target");
   }
 
   SEEK_LOG(LogLevel::Debug, ("Seek complete in %d bisections.", hops));
 
   return NS_OK;
 }
 
 #undef OGG_DEBUG