Bug 928765 - Create MediaDecoderReader::GetBuffered() base implementation that estimates buffered ranges, so that subclasses do have to keep reimplementing the estimation. r=doublec

This commit is contained in:
Chris Pearce 2013-10-21 16:31:05 +13:00
parent 3b751c0f92
commit cd4b7635ae
11 changed files with 29 additions and 75 deletions

View File

@ -602,5 +602,19 @@ nsresult MediaDecoderReader::DecodeToTarget(int64_t aTarget)
return NS_OK;
}
nsresult
MediaDecoderReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered,
int64_t aStartTime)
{
MediaResource* stream = mDecoder->GetResource();
int64_t durationUs = 0;
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
durationUs = mDecoder->GetMediaDuration();
}
GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
return NS_OK;
}
} // namespace mozilla

View File

@ -525,9 +525,21 @@ public:
// Populates aBuffered with the time ranges which are buffered. aStartTime
// must be the presentation time of the first frame in the media, e.g.
// the media time corresponding to playback time/position 0. This function
// should only be called on the main thread.
// is called on the main, decode, and state machine threads.
//
// This base implementation in MediaDecoderReader estimates the time ranges
// buffered by interpolating the cached byte ranges with the duration
// of the media. Reader subclasses should override this method if they
// can quickly calculate the buffered ranges more accurately.
//
// The primary advantage of this implementation in the reader base class
// is that it's a fast approximation, which does not perform any I/O.
//
// The OggReader relies on this base implementation not performing I/O,
// since in FirefoxOS we can't do I/O on the main thread, where this is
// called.
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered,
int64_t aStartTime) = 0;
int64_t aStartTime);
class VideoQueueMemoryFunctor : public nsDequeFunctor {
public:

View File

@ -515,16 +515,4 @@ AppleMP3Reader::Seek(int64_t aTime,
return NS_OK;
}
nsresult
AppleMP3Reader::GetBuffered(dom::TimeRanges* aBuffered,
int64_t aStartTime)
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
GetEstimatedBufferedTimeRanges(mDecoder->GetResource(),
mDecoder->GetMediaDuration(),
aBuffered);
return NS_OK;
}
} // namespace mozilla

View File

@ -38,9 +38,6 @@ public:
int64_t aEndTime,
int64_t aCurrentTime) MOZ_OVERRIDE;
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered,
int64_t aStartTime) MOZ_OVERRIDE;
void AudioSampleCallback(UInt32 aNumBytes,
UInt32 aNumPackets,
const void *aData,

View File

@ -331,20 +331,6 @@ DirectShowReader::Seek(int64_t aTargetUs,
return DecodeToTarget(aTargetUs);
}
nsresult
DirectShowReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered,
int64_t aStartTime)
{
MediaResource* stream = mDecoder->GetResource();
int64_t durationUs = 0;
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
durationUs = mDecoder->GetMediaDuration();
}
GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
return NS_OK;
}
void
DirectShowReader::OnDecodeThreadStart()
{

View File

@ -65,9 +65,6 @@ public:
int64_t aEndTime,
int64_t aCurrentTime) MOZ_OVERRIDE;
nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered,
int64_t aStartTime) MOZ_OVERRIDE;
void OnDecodeThreadStart() MOZ_OVERRIDE;
void OnDecodeThreadFinish() MOZ_OVERRIDE;

View File

@ -1755,15 +1755,7 @@ nsresult OggReader::GetBuffered(TimeRanges* aBuffered, int64_t aStartTime)
return NS_ERROR_FAILURE;
}
#ifdef OGG_ESTIMATE_BUFFERED
MediaResource* stream = mDecoder->GetResource();
int64_t durationUs = 0;
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
durationUs = mDecoder->GetMediaDuration();
}
GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
return NS_OK;
return MediaDecoderReader::GetBuffered(aBuffered, aStartTime);
#else
// HasAudio and HasVideo are not used here as they take a lock and cause
// a deadlock. Accessing mInfo doesn't require a lock - it doesn't change

View File

@ -329,21 +329,6 @@ nsresult MediaPluginReader::Seek(int64_t aTarget, int64_t aStartTime, int64_t aE
return DecodeToTarget(aTarget);
}
nsresult MediaPluginReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_t aStartTime)
{
if (!mPlugin)
return NS_OK;
MediaResource* stream = mDecoder->GetResource();
int64_t durationUs = 0;
mPlugin->GetDuration(mPlugin, &durationUs);
GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
return NS_OK;
}
MediaPluginReader::ImageBufferCallback::ImageBufferCallback(mozilla::layers::ImageContainer *aImageContainer) :
mImageContainer(aImageContainer)
{

View File

@ -64,7 +64,6 @@ public:
virtual nsresult ReadMetadata(MediaInfo* aInfo,
MetadataTags** aTags);
virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
virtual nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_t aStartTime);
class ImageBufferCallback : public MPAPI::BufferCallback {
typedef mozilla::layers::Image Image;
public:

View File

@ -1028,17 +1028,4 @@ WMFReader::Seek(int64_t aTargetUs,
return DecodeToTarget(aTargetUs);
}
nsresult
WMFReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_t aStartTime)
{
MediaResource* stream = mDecoder->GetResource();
int64_t durationUs = 0;
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
durationUs = mDecoder->GetMediaDuration();
}
GetEstimatedBufferedTimeRanges(stream, durationUs, aBuffered);
return NS_OK;
}
} // namespace mozilla

View File

@ -48,9 +48,6 @@ public:
int64_t aEndTime,
int64_t aCurrentTime) MOZ_OVERRIDE;
nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered,
int64_t aStartTime) MOZ_OVERRIDE;
void OnDecodeThreadStart() MOZ_OVERRIDE;
void OnDecodeThreadFinish() MOZ_OVERRIDE;