Commit dc644ae8 by Oliver Woodman

Make single MICROS_PER_SECOND constant + use it everywhere.

parent 656fc0b0
...@@ -23,7 +23,12 @@ public final class C { ...@@ -23,7 +23,12 @@ public final class C {
/** /**
* Represents an unknown microsecond time or duration. * Represents an unknown microsecond time or duration.
*/ */
public static final long UNKNOWN_TIME_US = -1; public static final long UNKNOWN_TIME_US = -1L;
/**
* The number of microseconds in one second.
*/
public static final long MICROS_PER_SECOND = 1000000L;
/** /**
* Represents an unbounded length of data. * Represents an unbounded length of data.
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.audio; package com.google.android.exoplayer.audio;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
...@@ -80,22 +81,20 @@ public final class AudioTrack { ...@@ -80,22 +81,20 @@ public final class AudioTrack {
private static final String TAG = "AudioTrack"; private static final String TAG = "AudioTrack";
private static final long MICROS_PER_SECOND = 1000000L;
/** /**
* AudioTrack timestamps are deemed spurious if they are offset from the system clock by more * AudioTrack timestamps are deemed spurious if they are offset from the system clock by more
* than this amount. * than this amount.
* *
* <p>This is a fail safe that should not be required on correctly functioning devices. * <p>This is a fail safe that should not be required on correctly functioning devices.
*/ */
private static final long MAX_AUDIO_TIMESTAMP_OFFSET_US = 10 * MICROS_PER_SECOND; private static final long MAX_AUDIO_TIMESTAMP_OFFSET_US = 10 * C.MICROS_PER_SECOND;
/** /**
* AudioTrack latencies are deemed impossibly large if they are greater than this amount. * AudioTrack latencies are deemed impossibly large if they are greater than this amount.
* *
* <p>This is a fail safe that should not be required on correctly functioning devices. * <p>This is a fail safe that should not be required on correctly functioning devices.
*/ */
private static final long MAX_LATENCY_US = 10 * MICROS_PER_SECOND; private static final long MAX_LATENCY_US = 10 * C.MICROS_PER_SECOND;
private static final int START_NOT_SET = 0; private static final int START_NOT_SET = 0;
private static final int START_IN_SYNC = 1; private static final int START_IN_SYNC = 1;
...@@ -624,11 +623,11 @@ public final class AudioTrack { ...@@ -624,11 +623,11 @@ public final class AudioTrack {
} }
private long framesToDurationUs(long frameCount) { private long framesToDurationUs(long frameCount) {
return (frameCount * MICROS_PER_SECOND) / sampleRate; return (frameCount * C.MICROS_PER_SECOND) / sampleRate;
} }
private long durationUsToFrames(long durationUs) { private long durationUsToFrames(long durationUs) {
return (durationUs * sampleRate) / MICROS_PER_SECOND; return (durationUs * sampleRate) / C.MICROS_PER_SECOND;
} }
private void resetSyncParams() { private void resetSyncParams() {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.dash.mpd; package com.google.android.exoplayer.dash.mpd;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
import android.net.Uri; import android.net.Uri;
...@@ -141,11 +142,12 @@ public abstract class SegmentBase { ...@@ -141,11 +142,12 @@ public abstract class SegmentBase {
public final long getSegmentDurationUs(int sequenceNumber) { public final long getSegmentDurationUs(int sequenceNumber) {
if (segmentTimeline != null) { if (segmentTimeline != null) {
return (segmentTimeline.get(sequenceNumber - startNumber).duration * 1000000) / timescale; long duration = segmentTimeline.get(sequenceNumber - startNumber).duration;
return (duration * C.MICROS_PER_SECOND) / timescale;
} else { } else {
return sequenceNumber == getLastSegmentNum() return sequenceNumber == getLastSegmentNum()
? (periodDurationMs * 1000) - getSegmentTimeUs(sequenceNumber) ? ((periodDurationMs * 1000) - getSegmentTimeUs(sequenceNumber))
: ((duration * 1000000L) / timescale); : ((duration * C.MICROS_PER_SECOND) / timescale);
} }
} }
...@@ -157,7 +159,7 @@ public abstract class SegmentBase { ...@@ -157,7 +159,7 @@ public abstract class SegmentBase {
} else { } else {
unscaledSegmentTime = (sequenceNumber - startNumber) * duration; unscaledSegmentTime = (sequenceNumber - startNumber) * duration;
} }
return Util.scaleLargeTimestamp(unscaledSegmentTime, 1000000, timescale); return Util.scaleLargeTimestamp(unscaledSegmentTime, C.MICROS_PER_SECOND, timescale);
} }
public abstract RangedUri getSegmentUrl(Representation representation, int index); public abstract RangedUri getSegmentUrl(Representation representation, int index);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.parser.mp4; package com.google.android.exoplayer.parser.mp4;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.ParserException; import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.SampleHolder; import com.google.android.exoplayer.SampleHolder;
...@@ -26,6 +27,7 @@ import com.google.android.exoplayer.upstream.NonBlockingInputStream; ...@@ -26,6 +27,7 @@ import com.google.android.exoplayer.upstream.NonBlockingInputStream;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.CodecSpecificDataUtil; import com.google.android.exoplayer.util.CodecSpecificDataUtil;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.Util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.media.MediaCodec; import android.media.MediaCodec;
...@@ -1053,6 +1055,7 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -1053,6 +1055,7 @@ public final class FragmentedMp4Extractor implements Extractor {
long offset = firstOffset; long offset = firstOffset;
long time = earliestPresentationTime; long time = earliestPresentationTime;
long timeUs = Util.scaleLargeTimestamp(time, C.MICROS_PER_SECOND, timescale);
for (int i = 0; i < referenceCount; i++) { for (int i = 0; i < referenceCount; i++) {
int firstInt = atom.readInt(); int firstInt = atom.readInt();
...@@ -1067,10 +1070,10 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -1067,10 +1070,10 @@ public final class FragmentedMp4Extractor implements Extractor {
// Calculate time and duration values such that any rounding errors are consistent. i.e. That // Calculate time and duration values such that any rounding errors are consistent. i.e. That
// timesUs[i] + durationsUs[i] == timesUs[i + 1]. // timesUs[i] + durationsUs[i] == timesUs[i + 1].
timesUs[i] = (time * 1000000L) / timescale; timesUs[i] = timeUs;
long nextTimeUs = ((time + referenceDuration) * 1000000L) / timescale;
durationsUs[i] = nextTimeUs - timesUs[i];
time += referenceDuration; time += referenceDuration;
timeUs = Util.scaleLargeTimestamp(time, C.MICROS_PER_SECOND, timescale);
durationsUs[i] = timeUs - timesUs[i];
atom.skip(4); atom.skip(4);
offset += sizes[i]; offset += sizes[i];
......
...@@ -32,8 +32,6 @@ import java.util.UUID; ...@@ -32,8 +32,6 @@ import java.util.UUID;
*/ */
public class SmoothStreamingManifest { public class SmoothStreamingManifest {
private static final long MICROS_PER_SECOND = 1000000L;
/** /**
* The client manifest major version. * The client manifest major version.
*/ */
...@@ -102,9 +100,9 @@ public class SmoothStreamingManifest { ...@@ -102,9 +100,9 @@ public class SmoothStreamingManifest {
this.protectionElement = protectionElement; this.protectionElement = protectionElement;
this.streamElements = streamElements; this.streamElements = streamElements;
dvrWindowLengthUs = dvrWindowLength == 0 ? C.UNKNOWN_TIME_US dvrWindowLengthUs = dvrWindowLength == 0 ? C.UNKNOWN_TIME_US
: Util.scaleLargeTimestamp(dvrWindowLength, MICROS_PER_SECOND, timescale); : Util.scaleLargeTimestamp(dvrWindowLength, C.MICROS_PER_SECOND, timescale);
durationUs = duration == 0 ? C.UNKNOWN_TIME_US durationUs = duration == 0 ? C.UNKNOWN_TIME_US
: Util.scaleLargeTimestamp(duration, MICROS_PER_SECOND, timescale); : Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, timescale);
} }
/** /**
...@@ -226,9 +224,9 @@ public class SmoothStreamingManifest { ...@@ -226,9 +224,9 @@ public class SmoothStreamingManifest {
this.chunkCount = chunkStartTimes.size(); this.chunkCount = chunkStartTimes.size();
this.chunkStartTimes = chunkStartTimes; this.chunkStartTimes = chunkStartTimes;
lastChunkDurationUs = lastChunkDurationUs =
Util.scaleLargeTimestamp(lastChunkDuration, MICROS_PER_SECOND, timescale); Util.scaleLargeTimestamp(lastChunkDuration, C.MICROS_PER_SECOND, timescale);
chunkStartTimesUs = chunkStartTimesUs =
Util.scaleLargeTimestamps(chunkStartTimes, MICROS_PER_SECOND, timescale); Util.scaleLargeTimestamps(chunkStartTimes, C.MICROS_PER_SECOND, timescale);
} }
/** /**
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.text.ttml; package com.google.android.exoplayer.text.ttml;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.ParserException; import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.text.Subtitle; import com.google.android.exoplayer.text.Subtitle;
import com.google.android.exoplayer.text.SubtitleParser; import com.google.android.exoplayer.text.SubtitleParser;
...@@ -254,7 +255,7 @@ public class TtmlParser implements SubtitleParser { ...@@ -254,7 +255,7 @@ public class TtmlParser implements SubtitleParser {
String subframes = matcher.group(6); String subframes = matcher.group(6);
durationSeconds += (subframes != null) ? durationSeconds += (subframes != null) ?
((double) Long.parseLong(subframes)) / subframeRate / frameRate : 0; ((double) Long.parseLong(subframes)) / subframeRate / frameRate : 0;
return (long) (durationSeconds * 1000000); return (long) (durationSeconds * C.MICROS_PER_SECOND);
} }
matcher = OFFSET_TIME.matcher(time); matcher = OFFSET_TIME.matcher(time);
if (matcher.matches()) { if (matcher.matches()) {
...@@ -274,7 +275,7 @@ public class TtmlParser implements SubtitleParser { ...@@ -274,7 +275,7 @@ public class TtmlParser implements SubtitleParser {
} else if (unit.equals("t")) { } else if (unit.equals("t")) {
offsetSeconds /= tickRate; offsetSeconds /= tickRate;
} }
return (long) (offsetSeconds * 1000000); return (long) (offsetSeconds * C.MICROS_PER_SECOND);
} }
throw new ParserException("Malformed time expression: " + time); throw new ParserException("Malformed time expression: " + time);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment