b=1023697 add functions to convert between track rates and remove global StreamTime/tick conversion functions r=roc

--HG--
extra : transplant_source : %B6%BC%83%17%22%EE%5D%BEl%B6%17m%1C%D0N%D1C%97%60%E1
This commit is contained in:
Karl Tomlinson 2014-06-12 16:44:59 +12:00
parent b0bb0ef6be
commit d8be06bf30
4 changed files with 37 additions and 39 deletions

View File

@ -349,8 +349,7 @@ MediaStreamGraphImpl::GetAudioPosition(MediaStream* aStream)
return mCurrentTime;
}
return aStream->mAudioOutputStreams[0].mAudioPlaybackStartTime +
TicksToTimeRoundDown(mSampleRate,
positionInFrames);
RateConvertTicksRoundDown(GraphRate(), mSampleRate, positionInFrames);
}
void
@ -1157,7 +1156,8 @@ MediaStreamGraphImpl::EnsureNextIterationLocked(MonitorAutoLock& aLock)
static GraphTime
RoundUpToNextAudioBlock(TrackRate aSampleRate, GraphTime aTime)
{
TrackTicks ticks = TimeToTicksRoundUp(aSampleRate, aTime);
TrackTicks ticks = RateConvertTicksRoundUp(aSampleRate,
1 << MEDIA_TIME_FRAC_BITS, aTime);
uint64_t block = ticks >> WEBAUDIO_BLOCK_SIZE_BITS;
uint64_t nextBlock = block + 1;
TrackTicks nextTicks = nextBlock << WEBAUDIO_BLOCK_SIZE_BITS;
@ -2902,7 +2902,8 @@ MediaStreamGraph::StartNonRealtimeProcessing(TrackRate aRate, uint32_t aTicksToP
if (graph->mNonRealtimeProcessing)
return;
graph->mEndTime = graph->mCurrentTime + TicksToTimeRoundUp(aRate, aTicksToProcess);
graph->mEndTime = graph->mCurrentTime +
RateConvertTicksRoundUp(graph->GraphRate(), aRate, aTicksToProcess);
graph->mNonRealtimeProcessing = true;
graph->EnsureRunInStableState();
}

View File

@ -494,15 +494,15 @@ public:
}
TrackTicks TimeToTicksRoundUp(TrackRate aRate, StreamTime aTime)
{
return mozilla::TimeToTicksRoundUp(aRate, aTime);
return RateConvertTicksRoundUp(aRate, mBuffer.GraphRate(), aTime);
}
TrackTicks TimeToTicksRoundDown(TrackRate aRate, StreamTime aTime)
{
return mozilla::TimeToTicksRoundDown(aRate, aTime);
return RateConvertTicksRoundDown(aRate, mBuffer.GraphRate(), aTime);
}
StreamTime TicksToTimeRoundDown(TrackRate aRate, TrackTicks aTicks)
{
return mozilla::TicksToTimeRoundDown(aRate, aTicks);
return RateConvertTicksRoundDown(mBuffer.GraphRate(), aRate, aTicks);
}
/**
* Convert graph time to stream time. aTime must be <= mStateComputedTime

View File

@ -395,6 +395,11 @@ public:
TrackRate AudioSampleRate() const { return mSampleRate; }
TrackRate GraphRate() const { return 1 << MEDIA_TIME_FRAC_BITS; }
TrackTicks TimeToTicksRoundDown(TrackRate aRate, StreamTime aTime)
{
return RateConvertTicksRoundDown(aRate, GraphRate(), aTime);
}
// Data members
/**

View File

@ -25,32 +25,22 @@ const StreamTime STREAM_TIME_MAX = MEDIA_TIME_MAX;
typedef int32_t TrackID;
const TrackID TRACK_NONE = 0;
inline TrackTicks TimeToTicksRoundUp(TrackRate aRate, StreamTime aTime)
inline TrackTicks RateConvertTicksRoundDown(TrackRate aOutRate,
TrackRate aInRate,
TrackTicks aTicks)
{
NS_ASSERTION(0 < aRate && aRate <= TRACK_RATE_MAX, "Bad rate");
NS_ASSERTION(0 <= aTime && aTime <= STREAM_TIME_MAX, "Bad time");
return (aTime*aRate + (1 << MEDIA_TIME_FRAC_BITS) - 1) >> MEDIA_TIME_FRAC_BITS;
NS_ASSERTION(0 < aOutRate && aOutRate <= TRACK_RATE_MAX, "Bad out rate");
NS_ASSERTION(0 < aInRate && aInRate <= TRACK_RATE_MAX, "Bad in rate");
NS_ASSERTION(0 <= aTicks && aTicks <= TRACK_TICKS_MAX, "Bad ticks");
return (aTicks * aOutRate) / aInRate;
}
inline TrackTicks TimeToTicksRoundDown(TrackRate aRate, StreamTime aTime)
inline TrackTicks RateConvertTicksRoundUp(TrackRate aOutRate,
TrackRate aInRate, TrackTicks aTicks)
{
NS_ASSERTION(0 < aRate && aRate <= TRACK_RATE_MAX, "Bad rate");
NS_ASSERTION(0 <= aTime && aTime <= STREAM_TIME_MAX, "Bad time");
return (aTime*aRate) >> MEDIA_TIME_FRAC_BITS;
}
inline StreamTime TicksToTimeRoundUp(TrackRate aRate, TrackTicks aTicks)
{
NS_ASSERTION(0 < aRate && aRate <= TRACK_RATE_MAX, "Bad rate");
NS_ASSERTION(0 <= aTicks && aTicks <= TRACK_TICKS_MAX, "Bad samples");
return ((aTicks << MEDIA_TIME_FRAC_BITS) + aRate - 1)/aRate;
}
inline StreamTime TicksToTimeRoundDown(TrackRate aRate, TrackTicks aTicks)
{
NS_ASSERTION(0 < aRate && aRate <= TRACK_RATE_MAX, "Bad rate");
NS_WARN_IF_FALSE(0 <= aTicks && aTicks <= TRACK_TICKS_MAX, "Bad samples");
return (aTicks << MEDIA_TIME_FRAC_BITS)/aRate;
NS_ASSERTION(0 < aOutRate && aOutRate <= TRACK_RATE_MAX, "Bad out rate");
NS_ASSERTION(0 < aInRate && aInRate <= TRACK_RATE_MAX, "Bad in rate");
NS_ASSERTION(0 <= aTicks && aTicks <= TRACK_TICKS_MAX, "Bad ticks");
return (aTicks * aOutRate + aInRate - 1) / aInRate;
}
/**
@ -113,19 +103,19 @@ public:
TrackTicks GetEnd() const { return mSegment->GetDuration(); }
StreamTime GetEndTimeRoundDown() const
{
return mozilla::TicksToTimeRoundDown(mRate, mSegment->GetDuration());
return TicksToTimeRoundDown(mSegment->GetDuration());
}
StreamTime GetStartTimeRoundDown() const
{
return mozilla::TicksToTimeRoundDown(mRate, mStart);
return TicksToTimeRoundDown(mStart);
}
TrackTicks TimeToTicksRoundDown(StreamTime aTime) const
{
return mozilla::TimeToTicksRoundDown(mRate, aTime);
return RateConvertTicksRoundDown(mRate, mGraphRate, aTime);
}
StreamTime TicksToTimeRoundDown(TrackTicks aTicks) const
{
return mozilla::TicksToTimeRoundDown(mRate, aTicks);
return RateConvertTicksRoundDown(mGraphRate, mRate, aTicks);
}
MediaSegment::Type GetType() const { return mSegment->GetType(); }
@ -234,18 +224,20 @@ public:
*/
Track& AddTrack(TrackID aID, TrackRate aRate, TrackTicks aStart, MediaSegment* aSegment)
{
NS_ASSERTION(!FindTrack(aID), "Track with this ID already exists");
Track* track = new Track(aID, aRate, aStart, aSegment, GraphRate());
mTracks.InsertElementSorted(track, CompareTracksByID());
if (mTracksKnownTime == STREAM_TIME_MAX) {
// There exists code like
// http://mxr.mozilla.org/mozilla-central/source/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp?rev=96b197deb91e&mark=1292-1297#1292
NS_WARNING("Adding track to StreamBuffer that should have no more tracks");
} else {
NS_ASSERTION(TimeToTicksRoundDown(aRate, mTracksKnownTime) <= aStart,
NS_ASSERTION(track->TimeToTicksRoundDown(mTracksKnownTime) <= aStart,
"Start time too early");
}
NS_ASSERTION(!FindTrack(aID), "Track with this ID already exists");
Track* track = new Track(aID, aRate, aStart, aSegment, GraphRate());
return **mTracks.InsertElementSorted(track, CompareTracksByID());
return *track;
}
void AdvanceKnownTracksTime(StreamTime aKnownTime)
{