From 6f5a8818ad6efbdd6f3be79492768f01eec9016f Mon Sep 17 00:00:00 2001 From: Jonathan Hao Date: Wed, 8 Apr 2015 16:57:39 +0800 Subject: [PATCH] Bug 1149616 - Fix the calculation of slots count in Read/WriteBuffer. r=bechen --- dom/media/RtspMediaResource.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dom/media/RtspMediaResource.cpp b/dom/media/RtspMediaResource.cpp index 93e6315030b2..9d383f7fcad2 100644 --- a/dom/media/RtspMediaResource.cpp +++ b/dom/media/RtspMediaResource.cpp @@ -243,7 +243,10 @@ nsresult RtspTrackBuffer::ReadBuffer(uint8_t* aToBuffer, uint32_t aToBufferSize, aFrameSize = mBufferSlotData[mConsumerIdx].mLength; break; } - uint32_t slots = (mBufferSlotData[mConsumerIdx].mLength / mSlotSize) + 1; + uint32_t slots = mBufferSlotData[mConsumerIdx].mLength / mSlotSize; + if (mBufferSlotData[mConsumerIdx].mLength % mSlotSize > 0) { + slots++; + } // we have data, copy to aToBuffer MOZ_ASSERT(mBufferSlotData[mConsumerIdx].mLength <= (int32_t)((BUFFER_SLOT_NUM - mConsumerIdx) * mSlotSize)); @@ -335,13 +338,15 @@ void RtspTrackBuffer::WriteBuffer(const char *aFromBuffer, uint32_t aWriteCount, // The flag is true if the incoming data is larger than remainder free slots bool returnToHead = false; // Calculate how many slots the incoming data needed. - int32_t slots = 1; + int32_t slots = aWriteCount / mSlotSize; + if (aWriteCount % mSlotSize > 0) { + slots++; + } int32_t i; RTSPMLOG("WriteBuffer mTrackIdx %d mProducerIdx %d mConsumerIdx %d", mTrackIdx, mProducerIdx,mConsumerIdx); if (aWriteCount > mSlotSize) { isMultipleSlots = true; - slots = (aWriteCount / mSlotSize) + 1; } if (isMultipleSlots && (aWriteCount > (BUFFER_SLOT_NUM - mProducerIdx) * mSlotSize)) {