Java Code Examples for com.google.android.exoplayer2.util.ParsableBitArray#skipBits()
The following examples show how to use
com.google.android.exoplayer2.util.ParsableBitArray#skipBits() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example 2
Source File: DtsUtil.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example 3
Source File: LatmReader.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Parses an AudioMuxElement as defined in 14496-3:2009, Section 1.7.3.1, Table 1.41. * * @param data A {@link ParsableBitArray} containing the AudioMuxElement's bytes. */ private void parseAudioMuxElement(ParsableBitArray data) throws ParserException { boolean useSameStreamMux = data.readBit(); if (!useSameStreamMux) { streamMuxRead = true; parseStreamMuxConfig(data); } else if (!streamMuxRead) { return; // Parsing cannot continue without StreamMuxConfig information. } if (audioMuxVersionA == 0) { if (numSubframes != 0) { throw new ParserException(); } int muxSlotLengthBytes = parsePayloadLengthInfo(data); parsePayloadMux(data, muxSlotLengthBytes); if (otherDataPresent) { data.skipBits((int) otherDataLenBits); } } else { throw new ParserException(); // Not defined by ISO/IEC 14496-3:2009. } }
Example 4
Source File: DtsUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example 5
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Parses a page composition segment, as defined by ETSI EN 300 743 7.2.2. */ private static PageComposition parsePageComposition(ParsableBitArray data, int length) { int timeoutSecs = data.readBits(8); int version = data.readBits(4); int state = data.readBits(2); data.skipBits(2); int remainingLength = length - 2; SparseArray<PageRegion> regions = new SparseArray<>(); while (remainingLength > 0) { int regionId = data.readBits(8); data.skipBits(8); // Skip reserved. int regionHorizontalAddress = data.readBits(16); int regionVerticalAddress = data.readBits(16); remainingLength -= 6; regions.put(regionId, new PageRegion(regionHorizontalAddress, regionVerticalAddress)); } return new PageComposition(timeoutSecs, version, state, regions); }
Example 6
Source File: LatmReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Parses an AudioMuxElement as defined in 14496-3:2009, Section 1.7.3.1, Table 1.41. * * @param data A {@link ParsableBitArray} containing the AudioMuxElement's bytes. */ private void parseAudioMuxElement(ParsableBitArray data) throws ParserException { boolean useSameStreamMux = data.readBit(); if (!useSameStreamMux) { streamMuxRead = true; parseStreamMuxConfig(data); } else if (!streamMuxRead) { return; // Parsing cannot continue without StreamMuxConfig information. } if (audioMuxVersionA == 0) { if (numSubframes != 0) { throw new ParserException(); } int muxSlotLengthBytes = parsePayloadLengthInfo(data); parsePayloadMux(data, muxSlotLengthBytes); if (otherDataPresent) { data.skipBits((int) otherDataLenBits); } } else { throw new ParserException(); // Not defined by ISO/IEC 14496-3:2009. } }
Example 7
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void parseFrameLength(ParsableBitArray data) { frameLengthType = data.readBits(3); switch (frameLengthType) { case 0: data.skipBits(8); // latmBufferFullness. break; case 1: data.skipBits(9); // frameLength. break; case 3: case 4: case 5: data.skipBits(6); // CELPframeLengthTableIndex. break; case 6: case 7: data.skipBits(1); // HVXCframeLengthTableIndex. break; } }
Example 8
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Parses a page composition segment, as defined by ETSI EN 300 743 7.2.2. */ private static PageComposition parsePageComposition(ParsableBitArray data, int length) { int timeoutSecs = data.readBits(8); int version = data.readBits(4); int state = data.readBits(2); data.skipBits(2); int remainingLength = length - 2; SparseArray<PageRegion> regions = new SparseArray<>(); while (remainingLength > 0) { int regionId = data.readBits(8); data.skipBits(8); // Skip reserved. int regionHorizontalAddress = data.readBits(16); int regionVerticalAddress = data.readBits(16); remainingLength -= 6; regions.put(regionId, new PageRegion(regionHorizontalAddress, regionVerticalAddress)); } return new PageComposition(timeoutSecs, version, state, regions); }
Example 9
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the DTS format given {@code data} containing the DTS frame according to ETSI TS 102 114 * subsections 5.3/5.4. * * @param frame The DTS frame to parse. * @param trackId The track identifier to set on the format. * @param language The language to set on the format. * @param drmInitData {@link DrmInitData} to be included in the format. * @return The DTS format parsed from data in the header. */ public static Format parseDtsFormat( byte[] frame, String trackId, String language, DrmInitData drmInitData) { ParsableBitArray frameBits = getNormalizedFrameHeader(frame); frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE int amode = frameBits.readBits(6); int channelCount = CHANNELS_BY_AMODE[amode]; int sfreq = frameBits.readBits(4); int sampleRate = SAMPLE_RATE_BY_SFREQ[sfreq]; int rate = frameBits.readBits(5); int bitrate = rate >= TWICE_BITRATE_KBPS_BY_RATE.length ? Format.NO_VALUE : TWICE_BITRATE_KBPS_BY_RATE[rate] * 1000 / 2; frameBits.skipBits(10); // MIX, DYNF, TIMEF, AUXF, HDCD, EXT_AUDIO_ID, EXT_AUDIO, ASPF channelCount += frameBits.readBits(2) > 0 ? 1 : 0; // LFF return Format.createAudioSampleFormat(trackId, MimeTypes.AUDIO_DTS, null, bitrate, Format.NO_VALUE, channelCount, sampleRate, null, drmInitData, 0, language); }
Example 10
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 11
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Parses a display definition segment, as defined by ETSI EN 300 743 7.2.1. */ private static DisplayDefinition parseDisplayDefinition(ParsableBitArray data) { data.skipBits(4); // dds_version_number (4). boolean displayWindowFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int horizontalPositionMinimum; int horizontalPositionMaximum; int verticalPositionMinimum; int verticalPositionMaximum; if (displayWindowFlag) { horizontalPositionMinimum = data.readBits(16); horizontalPositionMaximum = data.readBits(16); verticalPositionMinimum = data.readBits(16); verticalPositionMaximum = data.readBits(16); } else { horizontalPositionMinimum = 0; horizontalPositionMaximum = width; verticalPositionMinimum = 0; verticalPositionMaximum = height; } return new DisplayDefinition(width, height, horizontalPositionMinimum, horizontalPositionMaximum, verticalPositionMinimum, verticalPositionMaximum); }
Example 12
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Parses an object data segment, as defined by ETSI EN 300 743 7.2.5. * * @return The parsed object data. */ private static ObjectData parseObjectData(ParsableBitArray data) { int objectId = data.readBits(16); data.skipBits(4); // Skip object_version_number int objectCodingMethod = data.readBits(2); boolean nonModifyingColorFlag = data.readBit(); data.skipBits(1); // Skip reserved. @Nullable byte[] topFieldData = null; @Nullable byte[] bottomFieldData = null; if (objectCodingMethod == OBJECT_CODING_STRING) { int numberOfCodes = data.readBits(8); // TODO: Parse and use character_codes. data.skipBits(numberOfCodes * 16); // Skip character_codes. } else if (objectCodingMethod == OBJECT_CODING_PIXELS) { int topFieldDataLength = data.readBits(16); int bottomFieldDataLength = data.readBits(16); if (topFieldDataLength > 0) { topFieldData = new byte[topFieldDataLength]; data.readBytes(topFieldData, 0, topFieldDataLength); } if (bottomFieldDataLength > 0) { bottomFieldData = new byte[bottomFieldDataLength]; data.readBytes(bottomFieldData, 0, bottomFieldDataLength); } else { bottomFieldData = topFieldData; } } return new ObjectData(objectId, nonModifyingColorFlag, topFieldData, bottomFieldData); }
Example 13
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 14
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Parses a display definition segment, as defined by ETSI EN 300 743 7.2.1. */ private static DisplayDefinition parseDisplayDefinition(ParsableBitArray data) { data.skipBits(4); // dds_version_number (4). boolean displayWindowFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int horizontalPositionMinimum; int horizontalPositionMaximum; int verticalPositionMinimum; int verticalPositionMaximum; if (displayWindowFlag) { horizontalPositionMinimum = data.readBits(16); horizontalPositionMaximum = data.readBits(16); verticalPositionMinimum = data.readBits(16); verticalPositionMaximum = data.readBits(16); } else { horizontalPositionMinimum = 0; horizontalPositionMaximum = width; verticalPositionMinimum = 0; verticalPositionMaximum = height; } return new DisplayDefinition(width, height, horizontalPositionMinimum, horizontalPositionMaximum, verticalPositionMinimum, verticalPositionMaximum); }
Example 15
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Parses an object data segment, as defined by ETSI EN 300 743 7.2.5. * * @return The parsed object data. */ private static ObjectData parseObjectData(ParsableBitArray data) { int objectId = data.readBits(16); data.skipBits(4); // Skip object_version_number int objectCodingMethod = data.readBits(2); boolean nonModifyingColorFlag = data.readBit(); data.skipBits(1); // Skip reserved. byte[] topFieldData = null; byte[] bottomFieldData = null; if (objectCodingMethod == OBJECT_CODING_STRING) { int numberOfCodes = data.readBits(8); // TODO: Parse and use character_codes. data.skipBits(numberOfCodes * 16); // Skip character_codes. } else if (objectCodingMethod == OBJECT_CODING_PIXELS) { int topFieldDataLength = data.readBits(16); int bottomFieldDataLength = data.readBits(16); if (topFieldDataLength > 0) { topFieldData = new byte[topFieldDataLength]; data.readBytes(topFieldData, 0, topFieldDataLength); } if (bottomFieldDataLength > 0) { bottomFieldData = new byte[bottomFieldDataLength]; data.readBytes(bottomFieldData, 0, bottomFieldDataLength); } else { bottomFieldData = topFieldData; } } return new ObjectData(objectId, nonModifyingColorFlag, topFieldData, bottomFieldData); }
Example 16
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Parses a display definition segment, as defined by ETSI EN 300 743 7.2.1. */ private static DisplayDefinition parseDisplayDefinition(ParsableBitArray data) { data.skipBits(4); // dds_version_number (4). boolean displayWindowFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int horizontalPositionMinimum; int horizontalPositionMaximum; int verticalPositionMinimum; int verticalPositionMaximum; if (displayWindowFlag) { horizontalPositionMinimum = data.readBits(16); horizontalPositionMaximum = data.readBits(16); verticalPositionMinimum = data.readBits(16); verticalPositionMaximum = data.readBits(16); } else { horizontalPositionMinimum = 0; horizontalPositionMaximum = width; verticalPositionMinimum = 0; verticalPositionMaximum = height; } return new DisplayDefinition(width, height, horizontalPositionMinimum, horizontalPositionMaximum, verticalPositionMinimum, verticalPositionMaximum); }
Example 17
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Parses a CLUT definition segment, as defined by ETSI EN 300 743 7.2.4. */ private static ClutDefinition parseClutDefinition(ParsableBitArray data, int length) { int clutId = data.readBits(8); data.skipBits(8); // Skip clut_version_number (4), reserved (4) int remainingLength = length - 2; int[] clutEntries2Bit = generateDefault2BitClutEntries(); int[] clutEntries4Bit = generateDefault4BitClutEntries(); int[] clutEntries8Bit = generateDefault8BitClutEntries(); while (remainingLength > 0) { int entryId = data.readBits(8); int entryFlags = data.readBits(8); remainingLength -= 2; int[] clutEntries; if ((entryFlags & 0x80) != 0) { clutEntries = clutEntries2Bit; } else if ((entryFlags & 0x40) != 0) { clutEntries = clutEntries4Bit; } else { clutEntries = clutEntries8Bit; } int y; int cr; int cb; int t; if ((entryFlags & 0x01) != 0) { y = data.readBits(8); cr = data.readBits(8); cb = data.readBits(8); t = data.readBits(8); remainingLength -= 4; } else { y = data.readBits(6) << 2; cr = data.readBits(4) << 4; cb = data.readBits(4) << 4; t = data.readBits(2) << 6; remainingLength -= 2; } if (y == 0x00) { cr = 0x00; cb = 0x00; t = 0xFF; } int a = (byte) (0xFF - (t & 0xFF)); int r = (int) (y + (1.40200 * (cr - 128))); int g = (int) (y - (0.34414 * (cb - 128)) - (0.71414 * (cr - 128))); int b = (int) (y + (1.77200 * (cb - 128))); clutEntries[entryId] = getColor(a, Util.constrainValue(r, 0, 255), Util.constrainValue(g, 0, 255), Util.constrainValue(b, 0, 255)); } return new ClutDefinition(clutId, clutEntries2Bit, clutEntries4Bit, clutEntries8Bit); }
Example 18
Source File: Ac4Util.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Returns AC-4 format information given {@code data} containing a syncframe. The reading position * of {@code data} will be modified. * * @param data The data to parse, positioned at the start of the syncframe. * @return The AC-4 format data parsed from the header. */ public static SyncFrameInfo parseAc4SyncframeInfo(ParsableBitArray data) { int headerSize = 0; int syncWord = data.readBits(16); headerSize += 2; int frameSize = data.readBits(16); headerSize += 2; if (frameSize == 0xFFFF) { frameSize = data.readBits(24); headerSize += 3; // Extended frame_size } frameSize += headerSize; if (syncWord == AC41_SYNCWORD) { frameSize += 2; // crc_word } int bitstreamVersion = data.readBits(2); if (bitstreamVersion == 3) { bitstreamVersion += readVariableBits(data, /* bitsPerRead= */ 2); } int sequenceCounter = data.readBits(10); if (data.readBit()) { // b_wait_frames if (data.readBits(3) > 0) { // wait_frames data.skipBits(2); // reserved } } int sampleRate = data.readBit() ? 48000 : 44100; int frameRateIndex = data.readBits(4); int sampleCount = 0; if (sampleRate == 44100 && frameRateIndex == 13) { sampleCount = SAMPLE_COUNT[frameRateIndex]; } else if (sampleRate == 48000 && frameRateIndex < SAMPLE_COUNT.length) { sampleCount = SAMPLE_COUNT[frameRateIndex]; switch (sequenceCounter % 5) { case 1: // fall through case 3: if (frameRateIndex == 3 || frameRateIndex == 8) { sampleCount++; } break; case 2: if (frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; case 4: if (frameRateIndex == 3 || frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; default: break; } } return new SyncFrameInfo(bitstreamVersion, CHANNEL_COUNT_2, sampleRate, frameSize, sampleCount); }
Example 19
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Parses a CLUT definition segment, as defined by ETSI EN 300 743 7.2.4. */ private static ClutDefinition parseClutDefinition(ParsableBitArray data, int length) { int clutId = data.readBits(8); data.skipBits(8); // Skip clut_version_number (4), reserved (4) int remainingLength = length - 2; int[] clutEntries2Bit = generateDefault2BitClutEntries(); int[] clutEntries4Bit = generateDefault4BitClutEntries(); int[] clutEntries8Bit = generateDefault8BitClutEntries(); while (remainingLength > 0) { int entryId = data.readBits(8); int entryFlags = data.readBits(8); remainingLength -= 2; int[] clutEntries; if ((entryFlags & 0x80) != 0) { clutEntries = clutEntries2Bit; } else if ((entryFlags & 0x40) != 0) { clutEntries = clutEntries4Bit; } else { clutEntries = clutEntries8Bit; } int y; int cr; int cb; int t; if ((entryFlags & 0x01) != 0) { y = data.readBits(8); cr = data.readBits(8); cb = data.readBits(8); t = data.readBits(8); remainingLength -= 4; } else { y = data.readBits(6) << 2; cr = data.readBits(4) << 4; cb = data.readBits(4) << 4; t = data.readBits(2) << 6; remainingLength -= 2; } if (y == 0x00) { cr = 0x00; cb = 0x00; t = 0xFF; } int a = (byte) (0xFF - (t & 0xFF)); int r = (int) (y + (1.40200 * (cr - 128))); int g = (int) (y - (0.34414 * (cb - 128)) - (0.71414 * (cr - 128))); int b = (int) (y + (1.77200 * (cb - 128))); clutEntries[entryId] = getColor(a, Util.constrainValue(r, 0, 255), Util.constrainValue(g, 0, 255), Util.constrainValue(b, 0, 255)); } return new ClutDefinition(clutId, clutEntries2Bit, clutEntries4Bit, clutEntries8Bit); }
Example 20
Source File: Ac4Util.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Returns AC-4 format information given {@code data} containing a syncframe. The reading position * of {@code data} will be modified. * * @param data The data to parse, positioned at the start of the syncframe. * @return The AC-4 format data parsed from the header. */ public static SyncFrameInfo parseAc4SyncframeInfo(ParsableBitArray data) { int headerSize = 0; int syncWord = data.readBits(16); headerSize += 2; int frameSize = data.readBits(16); headerSize += 2; if (frameSize == 0xFFFF) { frameSize = data.readBits(24); headerSize += 3; // Extended frame_size } frameSize += headerSize; if (syncWord == AC41_SYNCWORD) { frameSize += 2; // crc_word } int bitstreamVersion = data.readBits(2); if (bitstreamVersion == 3) { bitstreamVersion += readVariableBits(data, /* bitsPerRead= */ 2); } int sequenceCounter = data.readBits(10); if (data.readBit()) { // b_wait_frames if (data.readBits(3) > 0) { // wait_frames data.skipBits(2); // reserved } } int sampleRate = data.readBit() ? 48000 : 44100; int frameRateIndex = data.readBits(4); int sampleCount = 0; if (sampleRate == 44100 && frameRateIndex == 13) { sampleCount = SAMPLE_COUNT[frameRateIndex]; } else if (sampleRate == 48000 && frameRateIndex < SAMPLE_COUNT.length) { sampleCount = SAMPLE_COUNT[frameRateIndex]; switch (sequenceCounter % 5) { case 1: // fall through case 3: if (frameRateIndex == 3 || frameRateIndex == 8) { sampleCount++; } break; case 2: if (frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; case 4: if (frameRateIndex == 3 || frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; default: break; } } return new SyncFrameInfo(bitstreamVersion, CHANNEL_COUNT_2, sampleRate, frameSize, sampleCount); }