Java Code Examples for com.google.android.exoplayer2.util.ParsableBitArray#readBits()
The following examples show how to use
com.google.android.exoplayer2.util.ParsableBitArray#readBits() .
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: DvbParser.java From Telegram-FOSS 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 3
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 4
Source File: LatmReader.java From Telegram 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; default: throw new IllegalStateException(); } }
Example 5
Source File: Ac4Util.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static int readVariableBits(ParsableBitArray data, int bitsPerRead) { int value = 0; while (true) { value += data.readBits(bitsPerRead); if (!data.readBit()) { break; } value++; value <<= bitsPerRead; } return value; }
Example 6
Source File: DvbParser.java From Telegram 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 7
Source File: Id3Decoder.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static MlltFrame decodeMlltFrame(ParsableByteArray id3Data, int frameSize) { // See ID3v2.4.0 native frames subsection 4.6. int mpegFramesBetweenReference = id3Data.readUnsignedShort(); int bytesBetweenReference = id3Data.readUnsignedInt24(); int millisecondsBetweenReference = id3Data.readUnsignedInt24(); int bitsForBytesDeviation = id3Data.readUnsignedByte(); int bitsForMillisecondsDeviation = id3Data.readUnsignedByte(); ParsableBitArray references = new ParsableBitArray(); references.reset(id3Data); int referencesBits = 8 * (frameSize - 10); int bitsPerReference = bitsForBytesDeviation + bitsForMillisecondsDeviation; int referencesCount = referencesBits / bitsPerReference; int[] bytesDeviations = new int[referencesCount]; int[] millisecondsDeviations = new int[referencesCount]; for (int i = 0; i < referencesCount; i++) { int bytesDeviation = references.readBits(bitsForBytesDeviation); int millisecondsDeviation = references.readBits(bitsForMillisecondsDeviation); bytesDeviations[i] = bytesDeviation; millisecondsDeviations[i] = millisecondsDeviation; } return new MlltFrame( mpegFramesBetweenReference, bytesBetweenReference, millisecondsBetweenReference, bytesDeviations, millisecondsDeviations); }
Example 8
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private int parsePayloadLengthInfo(ParsableBitArray data) throws ParserException { int muxSlotLengthBytes = 0; // Assuming single program and single layer. if (frameLengthType == 0) { int tmp; do { tmp = data.readBits(8); muxSlotLengthBytes += tmp; } while (tmp == 255); return muxSlotLengthBytes; } else { throw new ParserException(); } }
Example 9
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 10
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Paint an 8-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint8BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(8); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else { if (!data.readBit()) { peek = data.readBits(7); if (peek != 0x00) { runLength = peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else { runLength = data.readBits(7); clutIndex = data.readBits(8); } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 11
Source File: Id3Decoder.java From MediaSDK with Apache License 2.0 | 5 votes |
private static MlltFrame decodeMlltFrame(ParsableByteArray id3Data, int frameSize) { // See ID3v2.4.0 native frames subsection 4.6. int mpegFramesBetweenReference = id3Data.readUnsignedShort(); int bytesBetweenReference = id3Data.readUnsignedInt24(); int millisecondsBetweenReference = id3Data.readUnsignedInt24(); int bitsForBytesDeviation = id3Data.readUnsignedByte(); int bitsForMillisecondsDeviation = id3Data.readUnsignedByte(); ParsableBitArray references = new ParsableBitArray(); references.reset(id3Data); int referencesBits = 8 * (frameSize - 10); int bitsPerReference = bitsForBytesDeviation + bitsForMillisecondsDeviation; int referencesCount = referencesBits / bitsPerReference; int[] bytesDeviations = new int[referencesCount]; int[] millisecondsDeviations = new int[referencesCount]; for (int i = 0; i < referencesCount; i++) { int bytesDeviation = references.readBits(bitsForBytesDeviation); int millisecondsDeviation = references.readBits(bitsForMillisecondsDeviation); bytesDeviations[i] = bytesDeviation; millisecondsDeviations[i] = millisecondsDeviation; } return new MlltFrame( mpegFramesBetweenReference, bytesBetweenReference, millisecondsBetweenReference, bytesDeviations, millisecondsDeviations); }
Example 12
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString( ParsableBitArray data, int[] clutEntries, @Nullable byte[] clutMapTable, int column, int line, @Nullable Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 13
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock(byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; byte[] clutMapTable2To4 = null; byte[] clutMapTable2To8 = null; byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString(data, clutEntries, null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }
Example 14
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 15
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 16
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 17
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 18
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 19
Source File: LatmReader.java From MediaSDK with Apache License 2.0 | 4 votes |
private static long latmGetValue(ParsableBitArray data) { int bytesForValue = data.readBits(2); return data.readBits((bytesForValue + 1) * 8); }
Example 20
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private static long latmGetValue(ParsableBitArray data) { int bytesForValue = data.readBits(2); return data.readBits((bytesForValue + 1) * 8); }