зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1065218 - Convert MediaSourceReader timestamp handling to int64_t/microseconds. r=karlt
This commit is contained in:
Родитель
aba8fc1912
Коммит
dd0bc2fbde
|
@ -85,7 +85,7 @@ MediaSourceReader::RequestAudioData()
|
|||
return;
|
||||
}
|
||||
mAudioIsSeeking = false;
|
||||
SwitchAudioReader(double(mLastAudioTime) / USECS_PER_S);
|
||||
SwitchAudioReader(mLastAudioTime);
|
||||
mAudioReader->RequestAudioData();
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ MediaSourceReader::OnAudioEOS()
|
|||
{
|
||||
MSE_DEBUG("MediaSourceReader(%p)::OnAudioEOS reader=%p (decoders=%u)",
|
||||
this, mAudioReader.get(), mAudioTrack->Decoders().Length());
|
||||
if (SwitchAudioReader(double(mLastAudioTime) / USECS_PER_S)) {
|
||||
if (SwitchAudioReader(mLastAudioTime)) {
|
||||
// Success! Resume decoding with next audio decoder.
|
||||
RequestAudioData();
|
||||
} else if (IsEnded()) {
|
||||
|
@ -146,7 +146,7 @@ MediaSourceReader::RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThres
|
|||
mDropVideoBeforeThreshold = true;
|
||||
}
|
||||
mVideoIsSeeking = false;
|
||||
SwitchVideoReader(double(mLastVideoTime) / USECS_PER_S);
|
||||
SwitchVideoReader(mLastVideoTime);
|
||||
mVideoReader->RequestVideoData(aSkipToNextKeyframe, aTimeThreshold);
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ MediaSourceReader::OnVideoEOS()
|
|||
// End of stream. See if we can switch to another video decoder.
|
||||
MSE_DEBUG("MediaSourceReader(%p)::OnVideoEOS reader=%p (decoders=%u)",
|
||||
this, mVideoReader.get(), mVideoTrack->Decoders().Length());
|
||||
if (SwitchVideoReader(double(mLastVideoTime) / USECS_PER_S)) {
|
||||
if (SwitchVideoReader(mLastVideoTime)) {
|
||||
// Success! Resume decoding with next video decoder.
|
||||
RequestVideoData(false, 0);
|
||||
} else if (IsEnded()) {
|
||||
|
@ -263,7 +263,7 @@ MediaSourceReader::CanSelectVideoReader(MediaDecoderReader* aNewReader)
|
|||
}
|
||||
|
||||
already_AddRefed<MediaDecoderReader>
|
||||
MediaSourceReader::SelectReader(double aTarget,
|
||||
MediaSourceReader::SelectReader(int64_t aTarget,
|
||||
bool (MediaSourceReader::*aCanSelectReader)(MediaDecoderReader*),
|
||||
const nsTArray<nsRefPtr<SourceBufferDecoder>>& aTrackDecoders)
|
||||
{
|
||||
|
@ -283,8 +283,8 @@ MediaSourceReader::SelectReader(double aTarget,
|
|||
|
||||
nsRefPtr<dom::TimeRanges> ranges = new dom::TimeRanges();
|
||||
aTrackDecoders[i]->GetBuffered(ranges);
|
||||
if (ranges->Find(aTarget) == dom::TimeRanges::NoIndex) {
|
||||
MSE_DEBUGV("MediaSourceReader(%p)::SelectReader(%f) newReader=%p target not in ranges=%s",
|
||||
if (ranges->Find(double(aTarget) / USECS_PER_S) == dom::TimeRanges::NoIndex) {
|
||||
MSE_DEBUGV("MediaSourceReader(%p)::SelectReader(%lld) newReader=%p target not in ranges=%s",
|
||||
this, aTarget, newReader.get(), DumpTimeRanges(ranges).get());
|
||||
continue;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ MediaSourceReader::SelectReader(double aTarget,
|
|||
}
|
||||
|
||||
bool
|
||||
MediaSourceReader::SwitchAudioReader(double aTarget)
|
||||
MediaSourceReader::SwitchAudioReader(int64_t aTarget)
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
|
||||
// XXX: Can't handle adding an audio track after ReadMetadata.
|
||||
|
@ -316,7 +316,7 @@ MediaSourceReader::SwitchAudioReader(double aTarget)
|
|||
}
|
||||
|
||||
bool
|
||||
MediaSourceReader::SwitchVideoReader(double aTarget)
|
||||
MediaSourceReader::SwitchVideoReader(int64_t aTarget)
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
|
||||
// XXX: Can't handle adding a video track after ReadMetadata.
|
||||
|
@ -439,22 +439,22 @@ private:
|
|||
};
|
||||
|
||||
void
|
||||
MediaSourceReader::WaitForTimeRange(double aTime)
|
||||
MediaSourceReader::WaitForTimeRange(int64_t aTime)
|
||||
{
|
||||
MSE_DEBUG("MediaSourceReader(%p)::WaitForTimeRange(%f)", this, aTime);
|
||||
MSE_DEBUG("MediaSourceReader(%p)::WaitForTimeRange(%lld)", this, aTime);
|
||||
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
|
||||
|
||||
// Loop until we have the requested time range in the active TrackBuffers.
|
||||
// Ideally, this wait loop would use an async request and callback
|
||||
// instead. Bug 1056441 covers that change.
|
||||
while (!TrackBuffersContainTime(aTime) && !IsShutdown() && !IsEnded()) {
|
||||
MSE_DEBUG("MediaSourceReader(%p)::WaitForTimeRange(%f) waiting", this, aTime);
|
||||
MSE_DEBUG("MediaSourceReader(%p)::WaitForTimeRange(%lld) waiting", this, aTime);
|
||||
mon.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
MediaSourceReader::TrackBuffersContainTime(double aTime)
|
||||
MediaSourceReader::TrackBuffersContainTime(int64_t aTime)
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
|
||||
if (mAudioTrack && !mAudioTrack->ContainsTime(aTime)) {
|
||||
|
@ -482,13 +482,12 @@ MediaSourceReader::Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
|
|||
mLastAudioTime = aTime;
|
||||
mLastVideoTime = aTime;
|
||||
|
||||
double target = static_cast<double>(aTime) / USECS_PER_S;
|
||||
if (!TrackBuffersContainTime(target)) {
|
||||
MSE_DEBUG("MediaSourceReader(%p)::Seek no active buffer contains target=%f", this, target);
|
||||
if (!TrackBuffersContainTime(aTime)) {
|
||||
MSE_DEBUG("MediaSourceReader(%p)::Seek no active buffer contains target=%lld", this, aTime);
|
||||
NS_DispatchToMainThread(new ChangeToHaveMetadata(mDecoder));
|
||||
}
|
||||
|
||||
WaitForTimeRange(target);
|
||||
WaitForTimeRange(aTime);
|
||||
|
||||
if (IsShutdown()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -496,8 +495,7 @@ MediaSourceReader::Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
|
|||
|
||||
if (mAudioTrack) {
|
||||
mAudioIsSeeking = true;
|
||||
SwitchAudioReader(target);
|
||||
MOZ_ASSERT(static_cast<SourceBufferDecoder*>(mAudioReader->GetDecoder())->ContainsTime(target));
|
||||
SwitchAudioReader(aTime);
|
||||
nsresult rv = mAudioReader->Seek(aTime, aStartTime, aEndTime, aCurrentTime);
|
||||
MSE_DEBUG("MediaSourceReader(%p)::Seek audio reader=%p rv=%x", this, mAudioReader.get(), rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -506,8 +504,7 @@ MediaSourceReader::Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
|
|||
}
|
||||
if (mVideoTrack) {
|
||||
mVideoIsSeeking = true;
|
||||
SwitchVideoReader(target);
|
||||
MOZ_ASSERT(static_cast<SourceBufferDecoder*>(mVideoReader->GetDecoder())->ContainsTime(target));
|
||||
SwitchVideoReader(aTime);
|
||||
nsresult rv = mVideoReader->Seek(aTime, aStartTime, aEndTime, aCurrentTime);
|
||||
MSE_DEBUG("MediaSourceReader(%p)::Seek video reader=%p rv=%x", this, mVideoReader.get(), rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public:
|
|||
}
|
||||
|
||||
// Return true if all of the active tracks contain data for the specified time.
|
||||
bool TrackBuffersContainTime(double aTime);
|
||||
bool TrackBuffersContainTime(int64_t aTime);
|
||||
|
||||
// Mark the reader to indicate that EndOfStream has been called on our MediaSource
|
||||
void Ended();
|
||||
|
@ -102,15 +102,15 @@ public:
|
|||
bool IsEnded();
|
||||
|
||||
private:
|
||||
bool SwitchAudioReader(double aTarget);
|
||||
bool SwitchVideoReader(double aTarget);
|
||||
bool SwitchAudioReader(int64_t aTarget);
|
||||
bool SwitchVideoReader(int64_t aTarget);
|
||||
|
||||
// Return a reader from the set available in aTrackDecoders that is considered
|
||||
// usable by the aCanUserReader callback and has data available in the range
|
||||
// requested by aTarget.
|
||||
// aCanSelectReader is passed each reader available in aTrackDecoders and is
|
||||
// expected to return true if the reader is considerable selectable.
|
||||
already_AddRefed<MediaDecoderReader> SelectReader(double aTarget,
|
||||
already_AddRefed<MediaDecoderReader> SelectReader(int64_t aTarget,
|
||||
bool (MediaSourceReader::*aCanSelectReader)(MediaDecoderReader*),
|
||||
const nsTArray<nsRefPtr<SourceBufferDecoder>>& aTrackDecoders);
|
||||
|
||||
|
@ -124,7 +124,7 @@ private:
|
|||
// Waits on the decoder monitor for aTime to become available in the active
|
||||
// TrackBuffers. Used to block a Seek call until the necessary data has been
|
||||
// provided to the relevant SourceBuffers.
|
||||
void WaitForTimeRange(double aTime);
|
||||
void WaitForTimeRange(int64_t aTime);
|
||||
|
||||
nsRefPtr<MediaDecoderReader> mAudioReader;
|
||||
nsRefPtr<MediaDecoderReader> mVideoReader;
|
||||
|
|
|
@ -236,16 +236,4 @@ SourceBufferDecoder::ConvertToByteOffset(double aTime)
|
|||
return offset;
|
||||
}
|
||||
|
||||
bool
|
||||
SourceBufferDecoder::ContainsTime(double aTime)
|
||||
{
|
||||
ErrorResult dummy;
|
||||
nsRefPtr<dom::TimeRanges> ranges = new dom::TimeRanges();
|
||||
nsresult rv = GetBuffered(ranges);
|
||||
if (NS_FAILED(rv) || ranges->Length() == 0) {
|
||||
return false;
|
||||
}
|
||||
return ranges->Find(aTime) != dom::TimeRanges::NoIndex;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -85,9 +85,6 @@ public:
|
|||
// cached data. Returns -1 if no such value is computable.
|
||||
int64_t ConvertToByteOffset(double aTime);
|
||||
|
||||
// Returns true if the data buffered by this decoder contains the given time.
|
||||
bool ContainsTime(double aTime);
|
||||
|
||||
private:
|
||||
virtual ~SourceBufferDecoder();
|
||||
|
||||
|
|
|
@ -314,13 +314,13 @@ TrackBuffer::SetLastEndTimestamp(int64_t aEnd)
|
|||
}
|
||||
|
||||
bool
|
||||
TrackBuffer::ContainsTime(double aTime)
|
||||
TrackBuffer::ContainsTime(int64_t aTime)
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
|
||||
for (uint32_t i = 0; i < mInitializedDecoders.Length(); ++i) {
|
||||
nsRefPtr<dom::TimeRanges> r = new dom::TimeRanges();
|
||||
mInitializedDecoders[i]->GetBuffered(r);
|
||||
if (r->Find(aTime) != dom::TimeRanges::NoIndex) {
|
||||
if (r->Find(double(aTime) / USECS_PER_S) != dom::TimeRanges::NoIndex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
|
||||
// Returns true if any of the decoders managed by this track buffer
|
||||
// contain aTime in their buffered ranges.
|
||||
bool ContainsTime(double aTime);
|
||||
bool ContainsTime(int64_t aTime);
|
||||
|
||||
void BreakCycles();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче