public final class TimestampAdjuster extends Object
| Modifier and Type | Field | Description |
|---|---|---|
static long |
DO_NOT_OFFSET |
A special
firstSampleTimestampUs value indicating that presentation timestamps should
not be offset. |
| Constructor | Description |
|---|---|
TimestampAdjuster(long firstSampleTimestampUs) |
| Modifier and Type | Method | Description |
|---|---|---|
long |
adjustSampleTimestamp(long timeUs) |
Offsets a timestamp in microseconds.
|
long |
adjustTsTimestamp(long pts90Khz) |
Scales and offsets an MPEG-2 TS presentation timestamp considering wraparound.
|
long |
getFirstSampleTimestampUs() |
Returns the value of the first adjusted sample timestamp in microseconds, or
DO_NOT_OFFSET if timestamps will not be offset. |
long |
getLastAdjustedTimestampUs() |
Returns the last value obtained from
adjustSampleTimestamp(long). |
long |
getTimestampOffsetUs() |
Returns the offset between the input of
adjustSampleTimestamp(long) and its output. |
static long |
ptsToUs(long pts) |
Converts a 90 kHz clock timestamp to a timestamp in microseconds.
|
void |
reset(long firstSampleTimestampUs) |
Resets the instance to its initial state.
|
void |
sharedInitializeOrWait(boolean canInitialize,
long startTimeUs) |
For shared timestamp adjusters, performs necessary initialization actions for a caller.
|
static long |
usToNonWrappedPts(long us) |
Converts a timestamp in microseconds to a 90 kHz clock timestamp.
|
static long |
usToWrappedPts(long us) |
Converts a timestamp in microseconds to a 90 kHz clock timestamp, performing wraparound to keep
the result within 33-bits.
|
public static final long DO_NOT_OFFSET
firstSampleTimestampUs value indicating that presentation timestamps should
not be offset.public TimestampAdjuster(long firstSampleTimestampUs)
firstSampleTimestampUs - The desired value of the first adjusted sample timestamp in
microseconds, or DO_NOT_OFFSET if timestamps should not be offset.public void sharedInitializeOrWait(boolean canInitialize,
long startTimeUs)
throws InterruptedException
first sample
timestamp and if canInitialize is true, then initialization is started
by setting the target first sample timestamp to firstSampleTimestampUs. The call
returns, allowing the caller to proceed. Initialization completes when a caller adjusts
the first timestamp.
canInitialize is true and the adjuster already has a target first sample timestamp, then the call returns to allow the
caller to proceed only if firstSampleTimestampUs is equal to the target. This
ensures a caller that's previously started initialization can continue to proceed. It
also allows other callers with the same firstSampleTimestampUs to proceed, since
in this case it doesn't matter which caller adjusts the first timestamp to complete
initialization.
canInitialize is false or if firstSampleTimestampUs differs
from the target first sample timestamp, then the call
blocks until initialization completes. If initialization has already been completed the
call returns immediately.
canInitialize - Whether the caller is able to initialize the adjuster, if needed.startTimeUs - The desired first sample timestamp of the caller, in microseconds. Only used
if canInitialize is true.InterruptedException - If the thread is interrupted whilst blocked waiting for
initialization to complete.public long getFirstSampleTimestampUs()
DO_NOT_OFFSET if timestamps will not be offset.public long getLastAdjustedTimestampUs()
adjustSampleTimestamp(long). If adjustSampleTimestamp(long) has not been called, returns the result of calling getFirstSampleTimestampUs(). If this value is DO_NOT_OFFSET, returns C.TIME_UNSET.public long getTimestampOffsetUs()
adjustSampleTimestamp(long) and its output. If
DO_NOT_OFFSET was provided to the constructor, 0 is returned. If the timestamp
adjuster is yet not initialized, C.TIME_UNSET is returned.adjustSampleTimestamp(long)'s input and output. C.TIME_UNSET if the adjuster is not yet initialized and 0 if timestamps should not be
offset.public void reset(long firstSampleTimestampUs)
firstSampleTimestampUs - The desired value of the first adjusted sample timestamp after
this reset, in microseconds, or DO_NOT_OFFSET if timestamps should not be offset.public long adjustTsTimestamp(long pts90Khz)
pts90Khz - A 90 kHz clock MPEG-2 TS presentation timestamp.public long adjustSampleTimestamp(long timeUs)
timeUs - The timestamp to adjust in microseconds.public static long ptsToUs(long pts)
pts - A 90 kHz clock timestamp.public static long usToWrappedPts(long us)
us - A value in microseconds.public static long usToNonWrappedPts(long us)
Does not perform any wraparound. To get a 90 kHz timestamp suitable for use with MPEG-TS,
use usToWrappedPts(long).
us - A value in microseconds.