Back out 4a9ca7d8c499 (bug 918135) for frequent OS X orange

This commit is contained in:
Phil Ringnalda 2013-09-22 22:23:56 -07:00
parent 20ca8da458
commit 599bc6ea85
5 changed files with 22 additions and 76 deletions

View File

@ -56,11 +56,6 @@ public:
// no MP3 frame has been detected yet.
int64_t GetMP3Offset();
// The location in the stream of the last byte we looked at.
uint64_t GetLastStreamOffset() {
return mOffset + mBufferLength;
}
private:
// Parses aBuffer, starting at offset 0. Returns the number of bytes

View File

@ -4,7 +4,6 @@
#include "VideoUtils.h"
#include "MediaResource.h"
#include "MP3FrameParser.h"
#include "mozilla/dom/TimeRanges.h"
#include "nsMathUtils.h"
#include "nsSize.h"
@ -90,37 +89,3 @@ void GetEstimatedBufferedTimeRanges(mozilla::MediaResource* aStream,
return;
}
static const uint32_t READ_SIZE = 4096;
int64_t
GetEstimatedMP3Duration(mozilla::MediaResource *aResource,
mozilla::MP3FrameParser *aParser)
{
if (!aResource || !aParser) {
return -1;
}
while (aParser->IsMP3()) {
// Find the next cached data range past the last offset seen by the parser.
uint64_t parserOffset = aParser->GetLastStreamOffset();
int64_t readOffset = aResource->GetNextCachedData(parserOffset);
if (readOffset < 0) {
// No more buffered data.
break;
}
char buffer[READ_SIZE];
uint64_t readLength = aResource->GetCachedDataEnd(readOffset) - readOffset;
readLength = readLength > READ_SIZE ? READ_SIZE : readLength;
nsresult rv = aResource->ReadFromCache(buffer, readOffset, readLength);
if (NS_FAILED(rv)) {
return -1;
}
aParser->Parse(buffer, readLength, readOffset);
}
return aParser->GetDuration();
}

View File

@ -132,7 +132,6 @@ private:
};
class MediaResource;
class MP3FrameParser;
} // namespace mozilla
namespace mozilla {
@ -151,11 +150,6 @@ void GetEstimatedBufferedTimeRanges(mozilla::MediaResource* aStream,
int64_t aDurationUsecs,
mozilla::dom::TimeRanges* aOutBuffered);
// Estimates the duration in microseconds of an MP3 stream with the given
// MediaResource.
int64_t GetEstimatedMP3Duration(mozilla::MediaResource *aResource,
mozilla::MP3FrameParser *aParser);
// Converts from number of audio frames (aFrames) to microseconds, given
// the specified audio rate (aRate). Stores result in aOutUsecs. Returns true
// if the operation succeeded, or false if there was an integer overflow

View File

@ -86,12 +86,17 @@ static void _AudioSampleCallback(void *aThis,
* put it in |aData|, and return true.
* Otherwise, put as much data as is left into |aData|, set |aNumBytes| to the
* amount of data we have left, and return false.
*
* This function also passes the read data on to the MP3 frame parser for
* stream duration estimation.
*/
nsresult
AppleMP3Reader::Read(uint32_t *aNumBytes, char *aData)
AppleMP3Reader::ReadAndNotify(uint32_t *aNumBytes, char *aData)
{
MediaResource *resource = mDecoder->GetResource();
uint64_t offset = resource->Tell();
// Loop until we have all the data asked for, or we've reached EOS
uint32_t totalBytes = 0;
uint32_t numBytes;
@ -106,6 +111,18 @@ AppleMP3Reader::Read(uint32_t *aNumBytes, char *aData)
}
} while(totalBytes < *aNumBytes && numBytes);
// Pass the buffer to the MP3 frame parser to improve our duration estimate.
if (mMP3FrameParser.IsMP3()) {
mMP3FrameParser.Parse(aData, totalBytes, offset);
uint64_t duration = mMP3FrameParser.GetDuration();
if (duration != mDuration) {
LOGD("Updating media duration to %lluus\n", duration);
mDuration = duration;
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mDecoder->UpdateEstimatedMediaDuration(duration);
}
}
*aNumBytes = totalBytes;
// We will have read some data in the last iteration iff we filled the buffer.
@ -269,7 +286,7 @@ AppleMP3Reader::DecodeAudioData()
char bytes[AUDIO_READ_BYTES];
uint32_t numBytes = AUDIO_READ_BYTES;
nsresult readrv = Read(&numBytes, bytes);
nsresult readrv = ReadAndNotify(&numBytes, bytes);
// This function calls |AudioSampleCallback| above, synchronously, when it
// finds compressed MP3 frame.
@ -360,7 +377,7 @@ AppleMP3Reader::ReadMetadata(VideoInfo* aInfo,
do {
char bytes[AUDIO_READ_BYTES];
uint32_t numBytes = AUDIO_READ_BYTES;
readrv = Read(&numBytes, bytes);
readrv = ReadAndNotify(&numBytes, bytes);
rv = AudioFileStreamParseBytes(mAudioFileStream,
numBytes,
@ -385,9 +402,6 @@ AppleMP3Reader::ReadMetadata(VideoInfo* aInfo,
aInfo->mAudioChannels = mAudioChannels;
aInfo->mHasAudio = mStreamReady;
// Pass what data we have to the MP3 parser to get a duration estimate.
mDuration = GetEstimatedMP3Duration(mDecoder->GetResource(),
&mMP3FrameParser);
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mDecoder->SetMediaDuration(mDuration);
@ -513,22 +527,4 @@ AppleMP3Reader::GetBuffered(dom::TimeRanges* aBuffered,
return NS_OK;
}
void
AppleMP3Reader::NotifyDataArrived(const char* aBuffer,
uint32_t aLength,
int64_t aOffset)
{
// As data enters the cache, pass it to the MP3 parser to estimate the
// duration of the stream.
int64_t duration = GetEstimatedMP3Duration(mDecoder->GetResource(),
&mMP3FrameParser);
if (duration != -1 && duration != mDuration) {
LOGD("Updating media duration to %lluus\n", duration);
mDuration = duration;
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mDecoder->UpdateEstimatedMediaDuration(duration);
}
}
} // namespace mozilla

View File

@ -41,10 +41,6 @@ public:
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered,
int64_t aStartTime) MOZ_OVERRIDE;
virtual void NotifyDataArrived(const char* aBuffer,
uint32_t aLength,
int64_t aOffset) MOZ_OVERRIDE;
void AudioSampleCallback(UInt32 aNumBytes,
UInt32 aNumPackets,
const void *aData,
@ -56,7 +52,7 @@ public:
private:
void SetupDecoder();
nsresult Read(uint32_t *aNumBytes, char *aData);
nsresult ReadAndNotify(uint32_t *aNumBytes, char *aData);
static OSStatus PassthroughInputDataCallback(AudioConverterRef aAudioConverter,
UInt32 *aNumDataPackets,
@ -75,7 +71,7 @@ private:
UInt32 mAudioChannels;
UInt32 mAudioSampleRate;
int64_t mDuration;
uint64_t mDuration;
AudioFileStreamID mAudioFileStream;
AudioConverterRef mAudioConverter;