Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dts mpeg2ts update #275

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ This release includes the following changes since
inspected with `instanceof`. If you want runtime access to the
implementation details of an `Extractor` you must first call
`Extractor.getUnderlyingInstance`.
* MPEG2-TS: Add DTS, DTS-LBR and DTS:X Profile2 support
([#275](https://github.com/androidx/media/pull/275)).
* Audio:
* Add support for 24/32-bit big-endian PCM in MP4 and Matroska, and parse
PCM encoding for `lpcm` in MP4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,46 @@ public static int crc32(byte[] bytes, int start, int end, int initialValue) {
return initialValue;
}

/**
* Returns the result of updating a CRC-16 with the specified bytes in a "most significant bit
* first" order.
*
* @param bytes Array containing the bytes to update the crc value with.
* @param start The index to the first byte in the byte range to update the crc with.
* @param end The index after the last byte in the byte range to update the crc with.
* @param initialValue The initial value for the crc calculation.
* @return The result of updating the initial value with the specified bytes.
*/
@UnstableApi
public static int crc16(byte[] bytes, int start, int end, int initialValue) {
for (int i = start; i < end; i++) {
short value = (short) (bytes[i] & 0xFF);
// Process one message byte to update the current CRC-16 value.
initialValue = crc16UpdateFourBits((short) (value >> 4), initialValue); // High nibble first.
initialValue = crc16UpdateFourBits((short) (value & 0x0F), initialValue); // Low nibble.
}
return initialValue;
}

/**
* Process 4 bits of the message to update the CRC Value. Note that the data will be in the low
* nibble of val.
*/
private static int crc16UpdateFourBits(short val, int crc16Register) {
short t; // This will be handled as unsigned 8 bit data.

// Step one, extract the most significant 4 bits of the CRC register.
t = (short) ((crc16Register >> 12) & 0xFF);
// XOR in the Message Data into the extracted bits.
t = (short) ((t ^ val) & 0xFF);
// Shift the CRC register left 4 bits.
crc16Register = (crc16Register << 4) & 0xFFFF; // Handle as 16 bit, discard any sign extension.
// Do the table look-ups and XOR the result into the CRC tables.
crc16Register = (crc16Register ^ CRC16_BYTES_MSBF[t]) & 0xFFFF;

return crc16Register;
}

/**
* Returns the result of updating a CRC-8 with the specified bytes in a "most significant bit
* first" order.
Expand Down Expand Up @@ -3511,6 +3551,16 @@ private static String maybeReplaceLegacyLanguageTags(String languageTag) {
0XBCB4666D, 0XB8757BDA, 0XB5365D03, 0XB1F740B4
};

/**
* Allows the CRC-16 calculation to be done byte by byte instead of bit per bit in the order "most
* significant bit first".
*/
private static final int[] CRC16_BYTES_MSBF =
new int[] {
0x0000, 0x01021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
};

/**
* Allows the CRC-8 calculation to be done byte by byte instead of bit per bit in the order "most
* significant bit first".
Expand Down
Loading