Class Ac3Util
- java.lang.Object
-
- com.google.android.exoplayer2.audio.Ac3Util
-
public final class Ac3Util extends Object
Utility methods for parsing Dolby TrueHD and (E-)AC-3 syncframes. (E-)AC-3 parsing follows the definition in ETSI TS 102 366 V1.4.1.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAc3Util.SyncFrameInfoHolds sample format information as presented by a syncframe header.
-
Field Summary
Fields Modifier and Type Field Description static intAC3_MAX_RATE_BYTES_PER_SECONDMaximum rate for an AC-3 audio stream, in bytes per second.static intE_AC3_MAX_RATE_BYTES_PER_SECONDMaximum rate for an E-AC-3 audio stream, in bytes per second.static intTRUEHD_MAX_RATE_BYTES_PER_SECONDMaximum rate for a TrueHD audio stream, in bytes per second.static intTRUEHD_RECHUNK_SAMPLE_COUNTThe number of samples to store in each output chunk when rechunking TrueHD streams.static intTRUEHD_SYNCFRAME_PREFIX_LENGTHThe number of bytes that must be parsed from a TrueHD syncframe to calculate the sample count.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intfindTrueHdSyncframeOffset(ByteBuffer buffer)Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, orC.INDEX_UNSETif no syncframe was found.static FormatparseAc3AnnexFFormat(ParsableByteArray data, String trackId, String language, DrmInitData drmInitData)Returns the AC-3 format givendatacontaining the AC3SpecificBox according to Annex F.static intparseAc3SyncframeAudioSampleCount(ByteBuffer buffer)Reads the number of audio samples represented by the given (E-)AC-3 syncframe.static Ac3Util.SyncFrameInfoparseAc3SyncframeInfo(ParsableBitArray data)Returns (E-)AC-3 format information givendatacontaining a syncframe.static intparseAc3SyncframeSize(byte[] data)Returns the size in bytes of the given (E-)AC-3 syncframe.static FormatparseEAc3AnnexFFormat(ParsableByteArray data, String trackId, String language, DrmInitData drmInitData)Returns the E-AC-3 format givendatacontaining the EC3SpecificBox according to Annex F.static intparseTrueHdSyncframeAudioSampleCount(byte[] syncframe)Returns the number of audio samples represented by the given TrueHD syncframe, or 0 if the buffer is not the start of a syncframe.static intparseTrueHdSyncframeAudioSampleCount(ByteBuffer buffer, int offset)Reads the number of audio samples represented by a TrueHD syncframe.
-
-
-
Field Detail
-
AC3_MAX_RATE_BYTES_PER_SECOND
public static final int AC3_MAX_RATE_BYTES_PER_SECOND
Maximum rate for an AC-3 audio stream, in bytes per second.- See Also:
- Constant Field Values
-
E_AC3_MAX_RATE_BYTES_PER_SECOND
public static final int E_AC3_MAX_RATE_BYTES_PER_SECOND
Maximum rate for an E-AC-3 audio stream, in bytes per second.- See Also:
- Constant Field Values
-
TRUEHD_MAX_RATE_BYTES_PER_SECOND
public static final int TRUEHD_MAX_RATE_BYTES_PER_SECOND
Maximum rate for a TrueHD audio stream, in bytes per second.- See Also:
- Constant Field Values
-
TRUEHD_RECHUNK_SAMPLE_COUNT
public static final int TRUEHD_RECHUNK_SAMPLE_COUNT
The number of samples to store in each output chunk when rechunking TrueHD streams. The number of samples extracted from the container corresponding to one syncframe must be an integer multiple of this value.- See Also:
- Constant Field Values
-
TRUEHD_SYNCFRAME_PREFIX_LENGTH
public static final int TRUEHD_SYNCFRAME_PREFIX_LENGTH
The number of bytes that must be parsed from a TrueHD syncframe to calculate the sample count.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseAc3AnnexFFormat
public static Format parseAc3AnnexFFormat(ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData)
Returns the AC-3 format givendatacontaining the AC3SpecificBox according to Annex F. The reading position ofdatawill be modified.- Parameters:
data- The AC3SpecificBox to parse.trackId- The track identifier to set on the format.language- The language to set on the format.drmInitData-DrmInitDatato be included in the format.- Returns:
- The AC-3 format parsed from data in the header.
-
parseEAc3AnnexFFormat
public static Format parseEAc3AnnexFFormat(ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData)
Returns the E-AC-3 format givendatacontaining the EC3SpecificBox according to Annex F. The reading position ofdatawill be modified.- Parameters:
data- The EC3SpecificBox to parse.trackId- The track identifier to set on the format.language- The language to set on the format.drmInitData-DrmInitDatato be included in the format.- Returns:
- The E-AC-3 format parsed from data in the header.
-
parseAc3SyncframeInfo
public static Ac3Util.SyncFrameInfo parseAc3SyncframeInfo(ParsableBitArray data)
Returns (E-)AC-3 format information givendatacontaining a syncframe. The reading position ofdatawill be modified.- Parameters:
data- The data to parse, positioned at the start of the syncframe.- Returns:
- The (E-)AC-3 format data parsed from the header.
-
parseAc3SyncframeSize
public static int parseAc3SyncframeSize(byte[] data)
Returns the size in bytes of the given (E-)AC-3 syncframe.- Parameters:
data- The syncframe to parse.- Returns:
- The syncframe size in bytes.
C.LENGTH_UNSETif the input is invalid.
-
parseAc3SyncframeAudioSampleCount
public static int parseAc3SyncframeAudioSampleCount(ByteBuffer buffer)
Reads the number of audio samples represented by the given (E-)AC-3 syncframe. The buffer's position is not modified.- Parameters:
buffer- TheByteBufferfrom which to read the syncframe.- Returns:
- The number of audio samples represented by the syncframe.
-
findTrueHdSyncframeOffset
public static int findTrueHdSyncframeOffset(ByteBuffer buffer)
Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, orC.INDEX_UNSETif no syncframe was found. The buffer's position is not modified.- Parameters:
buffer- TheByteBufferwithin which to find a syncframe.- Returns:
- The offset relative to the buffer's position of the start of a TrueHD syncframe, or
C.INDEX_UNSETif no syncframe was found.
-
parseTrueHdSyncframeAudioSampleCount
public static int parseTrueHdSyncframeAudioSampleCount(byte[] syncframe)
Returns the number of audio samples represented by the given TrueHD syncframe, or 0 if the buffer is not the start of a syncframe.- Parameters:
syncframe- The bytes from which to read the syncframe. Must be at leastTRUEHD_SYNCFRAME_PREFIX_LENGTHbytes long.- Returns:
- The number of audio samples represented by the syncframe, or 0 if the buffer doesn't contain the start of a syncframe.
-
parseTrueHdSyncframeAudioSampleCount
public static int parseTrueHdSyncframeAudioSampleCount(ByteBuffer buffer, int offset)
Reads the number of audio samples represented by a TrueHD syncframe. The buffer's position is not modified.- Parameters:
buffer- TheByteBufferfrom which to read the syncframe.offset- The offset of the start of the syncframe relative to the buffer's position.- Returns:
- The number of audio samples represented by the syncframe.
-
-