b=1016177 reduce MEDIA_TIME_MAX to not overflow when multiplying by sample rates r=roc

MediaTimes are multiplied by sample rates when converting to ticks.

This new maximum leaves 24 bits to count seconds, which corresponds to 194
days.

TimeVarying::GetAt() can return INT64_MAX, which may be > GRAPH_TIME_MAX.

The "Start time too early" assertion would now fail because conversion of
STREAM_TIME_MAX to ticks no longer overflows.

--HG--
extra : rebase_source : b49c95315d0c633f191ff68aab0b5b7aa04c6e38
This commit is contained in:
Karl Tomlinson 2014-06-05 22:08:05 +12:00
Родитель 55b123d9d9
Коммит b8776ea4bf
3 изменённых файлов: 21 добавлений и 12 удалений

Просмотреть файл

@ -15,13 +15,23 @@
namespace mozilla {
/**
* Track rate in Hz. Maximum 1 << TRACK_RATE_MAX_BITS Hz. This
* maximum avoids overflow in conversions between track rates and conversions
* from seconds.
*/
typedef int32_t TrackRate;
const int64_t TRACK_RATE_MAX_BITS = 20;
const TrackRate TRACK_RATE_MAX = 1 << TRACK_RATE_MAX_BITS;
/**
* We represent media times in 64-bit fixed point. So 1 MediaTime is
* 1/(2^MEDIA_TIME_FRAC_BITS) seconds.
* 1/(2^MEDIA_TIME_FRAC_BITS) seconds. We want to make sure that multiplying
* MediaTime by a TrackRate doesn't overflow, so we set its max accordingly.
*/
typedef int64_t MediaTime;
const int64_t MEDIA_TIME_FRAC_BITS = 20;
const int64_t MEDIA_TIME_MAX = INT64_MAX;
const int64_t MEDIA_TIME_MAX = INT64_MAX >> TRACK_RATE_MAX_BITS;
inline MediaTime MillisecondsToMediaTime(int32_t aMS)
{

Просмотреть файл

@ -2517,7 +2517,7 @@ MediaInputPort::GetNextInputInterval(GraphTime aTime)
for (;;) {
if (!mDest->mBlocked.GetAt(t, &end))
break;
if (end == GRAPH_TIME_MAX)
if (end >= GRAPH_TIME_MAX)
return result;
t = end;
}

Просмотреть файл

@ -17,13 +17,6 @@ namespace mozilla {
typedef MediaTime StreamTime;
const StreamTime STREAM_TIME_MAX = MEDIA_TIME_MAX;
/**
* Track rate in Hz. Maximum 1 << MEDIA_TIME_FRAC_BITS Hz. This ensures
* calculations below don't overflow.
*/
typedef int32_t TrackRate;
const TrackRate TRACK_RATE_MAX = 1 << MEDIA_TIME_FRAC_BITS;
/**
* Unique ID for track within a StreamBuffer. Tracks from different
* StreamBuffers may have the same ID; this matters when appending StreamBuffers,
@ -224,8 +217,14 @@ public:
*/
Track& AddTrack(TrackID aID, TrackRate aRate, TrackTicks aStart, MediaSegment* aSegment)
{
NS_ASSERTION(TimeToTicksRoundDown(aRate, mTracksKnownTime) <= aStart,
"Start time too early");
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,
"Start time too early");
}
NS_ASSERTION(!FindTrack(aID), "Track with this ID already exists");
return **mTracks.InsertElementSorted(new Track(aID, aRate, aStart, aSegment),