Skip to content

Commit 6da2913

Browse files
rahulnmohancopybara-github
authored andcommitted
Merge Issue: androidx/media#275: MPEG2-TS: Support DTS, DTS-LBR and DTS:X Profile2
Imported from GitHub PR androidx/media#275 Added below mentioned features. - Support for extracting DTS LBR(DTS Express) and DTS UHD Profile 2(DTS:X) descriptor ID from PSI PMT - The DTSReader class is updated for extracting a DTS LBR. - Newly added DtsUhdReader class for extracting DTS UHD frame. - The DTSUtil class is updated to parse the DTS LBR or DTS UHD frame and report the format information. Feature request for ExoPlayer: #11075 Merge 21efa0810db31550d6b215639f9ca2af6a32139a into 104cfc3 COPYBARA_INTEGRATE_REVIEW=androidx/media#275 from rahulnmohan:dts-mpeg2ts-update 21efa0810db31550d6b215639f9ca2af6a32139a PiperOrigin-RevId: 598854998
1 parent 6970af4 commit 6da2913

24 files changed

+4577
-62
lines changed

library/common/src/main/java/com/google/android/exoplayer2/util/Util.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import com.google.common.base.Charsets;
9494
import com.google.common.math.DoubleMath;
9595
import com.google.common.math.LongMath;
96+
import com.google.common.primitives.UnsignedBytes;
9697
import com.google.common.util.concurrent.AsyncFunction;
9798
import com.google.common.util.concurrent.Futures;
9899
import com.google.common.util.concurrent.ListenableFuture;
@@ -2716,6 +2717,49 @@ public static int crc32(byte[] bytes, int start, int end, int initialValue) {
27162717
return initialValue;
27172718
}
27182719

2720+
/**
2721+
* Returns the result of updating a CRC-16 with the specified bytes in a "most significant bit
2722+
* first" order.
2723+
*
2724+
* @param bytes Array containing the bytes to update the crc value with.
2725+
* @param start The start index (inclusive) of the byte range to update the crc with.
2726+
* @param end The end index (exclusive) of the byte range to update the crc with.
2727+
* @param initialValue The initial value for the crc calculation. The lower 16 bits of this 32-bit
2728+
* integer are used for the CRC computation.
2729+
* @return The result of updating the initial value with the specified bytes.
2730+
*/
2731+
public static int crc16(byte[] bytes, int start, int end, int initialValue) {
2732+
for (int i = start; i < end; i++) {
2733+
int value = UnsignedBytes.toInt(bytes[i]);
2734+
// Process one message byte to update the current CRC-16 value.
2735+
initialValue = crc16UpdateFourBits(value >> 4, initialValue); // High nibble first.
2736+
initialValue = crc16UpdateFourBits(value & 0x0F, initialValue); // Low nibble.
2737+
}
2738+
return initialValue;
2739+
}
2740+
2741+
/**
2742+
* Process 4 bits of the message to update the CRC Value. Note that the data will be in the low
2743+
* nibble of value.
2744+
*
2745+
* @param value The 4-bit message data to be processed.
2746+
* @param crc16Register The current CRC-16 register to be updated. Only the lower 16 bits of this
2747+
* 32-bit integer are used for the CRC computation.
2748+
* @return The result of updating the CRC-16 register with the specified 4-bit message data.
2749+
*/
2750+
private static int crc16UpdateFourBits(int value, int crc16Register) {
2751+
// Step one, extract the most significant 4 bits of the CRC register.
2752+
int mostSignificant4Bits = (crc16Register >> 12) & 0xFF;
2753+
// XOR in the Message Data into the extracted bits.
2754+
mostSignificant4Bits = (mostSignificant4Bits ^ value) & 0xFF;
2755+
// Shift the CRC register left 4 bits.
2756+
crc16Register = (crc16Register << 4) & 0xFFFF; // Handle as 16 bit, discard any sign extension.
2757+
// Do the table look-ups and XOR the result into the CRC tables.
2758+
crc16Register = (crc16Register ^ CRC16_BYTES_MSBF[mostSignificant4Bits]) & 0xFFFF;
2759+
2760+
return crc16Register;
2761+
}
2762+
27192763
/**
27202764
* Returns the result of updating a CRC-8 with the specified bytes in a "most significant bit
27212765
* first" order.
@@ -3671,6 +3715,16 @@ private static String maybeReplaceLegacyLanguageTags(String languageTag) {
36713715
0XBCB4666D, 0XB8757BDA, 0XB5365D03, 0XB1F740B4
36723716
};
36733717

3718+
/**
3719+
* Allows the CRC-16 calculation to be done byte by byte instead of bit per bit in the order "most
3720+
* significant bit first".
3721+
*/
3722+
private static final int[] CRC16_BYTES_MSBF =
3723+
new int[] {
3724+
0x0000, 0x01021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
3725+
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
3726+
};
3727+
36743728
/**
36753729
* Allows the CRC-8 calculation to be done byte by byte instead of bit per bit in the order "most
36763730
* significant bit first".

0 commit comments

Comments
 (0)