com.google.android.exoplayer2.source.SampleMetadataQueue.SampleExtrasHolder Java Examples
The following examples show how to use
com.google.android.exoplayer2.source.SampleMetadataQueue.SampleExtrasHolder.
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: SampleQueue.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Creates a sample queue. * * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. * @param drmSessionManager The {@link DrmSessionManager} to obtain {@link DrmSession DrmSessions} * from. The created instance does not take ownership of this {@link DrmSessionManager}. */ public SampleQueue(Allocator allocator, DrmSessionManager<?> drmSessionManager) { this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(drmSessionManager); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); firstAllocationNode = new AllocationNode(0, allocationLength); readAllocationNode = firstAllocationNode; writeAllocationNode = firstAllocationNode; }
Example #2
Source File: SampleQueue.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Reads data from the rolling buffer to populate a decoder input buffer. * * @param buffer The buffer to populate. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readToBuffer(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { // Read encryption data if the sample is encrypted. if (buffer.isEncrypted()) { readEncryptionData(buffer, extrasHolder); } // Read sample data, extracting supplemental data into a separate buffer if needed. if (buffer.hasSupplementalData()) { // If there is supplemental data, the sample data is prefixed by its size. scratch.reset(4); readData(extrasHolder.offset, scratch.data, 4); int sampleSize = scratch.readUnsignedIntToInt(); extrasHolder.offset += 4; extrasHolder.size -= 4; // Write the sample data. buffer.ensureSpaceForWrite(sampleSize); readData(extrasHolder.offset, buffer.data, sampleSize); extrasHolder.offset += sampleSize; extrasHolder.size -= sampleSize; // Write the remaining data as supplemental data. buffer.resetSupplementalData(extrasHolder.size); readData(extrasHolder.offset, buffer.supplementalData, extrasHolder.size); } else { // Write the sample data. buffer.ensureSpaceForWrite(extrasHolder.size); readData(extrasHolder.offset, buffer.data, extrasHolder.size); } }
Example #3
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. */ public SampleQueue(Allocator allocator) { this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); firstAllocationNode = new AllocationNode(0, allocationLength); readAllocationNode = firstAllocationNode; writeAllocationNode = firstAllocationNode; }
Example #4
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. */ public SampleQueue(Allocator allocator) { this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); firstAllocationNode = new AllocationNode(0, allocationLength); readAllocationNode = firstAllocationNode; writeAllocationNode = firstAllocationNode; }
Example #5
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. */ public SampleQueue(Allocator allocator) { this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); firstAllocationNode = new AllocationNode(0, allocationLength); readAllocationNode = firstAllocationNode; writeAllocationNode = firstAllocationNode; }
Example #6
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * @param allocator An {@link Allocator} from which allocations for sample data can be obtained. */ public SampleQueue(Allocator allocator) { this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); firstAllocationNode = new AllocationNode(0, allocationLength); readAllocationNode = firstAllocationNode; writeAllocationNode = firstAllocationNode; }
Example #7
Source File: SampleQueue.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Reads encryption data for the current sample. * * <p>The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and {@link * SampleExtrasHolder#size} is adjusted to subtract the number of bytes that were read. The same * value is added to {@link SampleExtrasHolder#offset}. * * @param buffer The buffer into which the encryption data should be written. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readEncryptionData(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { long offset = extrasHolder.offset; // Read the signal byte. scratch.reset(1); readData(offset, scratch.data, 1); offset++; byte signalByte = scratch.data[0]; boolean subsampleEncryption = (signalByte & 0x80) != 0; int ivSize = signalByte & 0x7F; // Read the initialization vector. if (buffer.cryptoInfo.iv == null) { buffer.cryptoInfo.iv = new byte[16]; } readData(offset, buffer.cryptoInfo.iv, ivSize); offset += ivSize; // Read the subsample count, if present. int subsampleCount; if (subsampleEncryption) { scratch.reset(2); readData(offset, scratch.data, 2); offset += 2; subsampleCount = scratch.readUnsignedShort(); } else { subsampleCount = 1; } // Write the clear and encrypted subsample sizes. int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { clearDataSizes = new int[subsampleCount]; } int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { encryptedDataSizes = new int[subsampleCount]; } if (subsampleEncryption) { int subsampleDataLength = 6 * subsampleCount; scratch.reset(subsampleDataLength); readData(offset, scratch.data, subsampleDataLength); offset += subsampleDataLength; scratch.setPosition(0); for (int i = 0; i < subsampleCount; i++) { clearDataSizes[i] = scratch.readUnsignedShort(); encryptedDataSizes[i] = scratch.readUnsignedIntToInt(); } } else { clearDataSizes[0] = 0; encryptedDataSizes[0] = extrasHolder.size - (int) (offset - extrasHolder.offset); } // Populate the cryptoInfo. CryptoData cryptoData = extrasHolder.cryptoData; buffer.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, cryptoData.encryptionKey, buffer.cryptoInfo.iv, cryptoData.cryptoMode, cryptoData.encryptedBlocks, cryptoData.clearBlocks); // Adjust the offset and size to take into account the bytes read. int bytesRead = (int) (offset - extrasHolder.offset); extrasHolder.offset += bytesRead; extrasHolder.size -= bytesRead; }
Example #8
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Reads encryption data for the current sample. * <p> * The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and * {@link SampleExtrasHolder#size} is adjusted to subtract the number of bytes that were read. The * same value is added to {@link SampleExtrasHolder#offset}. * * @param buffer The buffer into which the encryption data should be written. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readEncryptionData(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { long offset = extrasHolder.offset; // Read the signal byte. scratch.reset(1); readData(offset, scratch.data, 1); offset++; byte signalByte = scratch.data[0]; boolean subsampleEncryption = (signalByte & 0x80) != 0; int ivSize = signalByte & 0x7F; // Read the initialization vector. if (buffer.cryptoInfo.iv == null) { buffer.cryptoInfo.iv = new byte[16]; } readData(offset, buffer.cryptoInfo.iv, ivSize); offset += ivSize; // Read the subsample count, if present. int subsampleCount; if (subsampleEncryption) { scratch.reset(2); readData(offset, scratch.data, 2); offset += 2; subsampleCount = scratch.readUnsignedShort(); } else { subsampleCount = 1; } // Write the clear and encrypted subsample sizes. int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { clearDataSizes = new int[subsampleCount]; } int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { encryptedDataSizes = new int[subsampleCount]; } if (subsampleEncryption) { int subsampleDataLength = 6 * subsampleCount; scratch.reset(subsampleDataLength); readData(offset, scratch.data, subsampleDataLength); offset += subsampleDataLength; scratch.setPosition(0); for (int i = 0; i < subsampleCount; i++) { clearDataSizes[i] = scratch.readUnsignedShort(); encryptedDataSizes[i] = scratch.readUnsignedIntToInt(); } } else { clearDataSizes[0] = 0; encryptedDataSizes[0] = extrasHolder.size - (int) (offset - extrasHolder.offset); } // Populate the cryptoInfo. CryptoData cryptoData = extrasHolder.cryptoData; buffer.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, cryptoData.encryptionKey, buffer.cryptoInfo.iv, cryptoData.cryptoMode, cryptoData.encryptedBlocks, cryptoData.clearBlocks); // Adjust the offset and size to take into account the bytes read. int bytesRead = (int) (offset - extrasHolder.offset); extrasHolder.offset += bytesRead; extrasHolder.size -= bytesRead; }
Example #9
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Reads encryption data for the current sample. * <p> * The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and * {@link SampleExtrasHolder#size} is adjusted to subtract the number of bytes that were read. The * same value is added to {@link SampleExtrasHolder#offset}. * * @param buffer The buffer into which the encryption data should be written. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readEncryptionData(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { long offset = extrasHolder.offset; // Read the signal byte. scratch.reset(1); readData(offset, scratch.data, 1); offset++; byte signalByte = scratch.data[0]; boolean subsampleEncryption = (signalByte & 0x80) != 0; int ivSize = signalByte & 0x7F; // Read the initialization vector. if (buffer.cryptoInfo.iv == null) { buffer.cryptoInfo.iv = new byte[16]; } readData(offset, buffer.cryptoInfo.iv, ivSize); offset += ivSize; // Read the subsample count, if present. int subsampleCount; if (subsampleEncryption) { scratch.reset(2); readData(offset, scratch.data, 2); offset += 2; subsampleCount = scratch.readUnsignedShort(); } else { subsampleCount = 1; } // Write the clear and encrypted subsample sizes. int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { clearDataSizes = new int[subsampleCount]; } int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { encryptedDataSizes = new int[subsampleCount]; } if (subsampleEncryption) { int subsampleDataLength = 6 * subsampleCount; scratch.reset(subsampleDataLength); readData(offset, scratch.data, subsampleDataLength); offset += subsampleDataLength; scratch.setPosition(0); for (int i = 0; i < subsampleCount; i++) { clearDataSizes[i] = scratch.readUnsignedShort(); encryptedDataSizes[i] = scratch.readUnsignedIntToInt(); } } else { clearDataSizes[0] = 0; encryptedDataSizes[0] = extrasHolder.size - (int) (offset - extrasHolder.offset); } // Populate the cryptoInfo. CryptoData cryptoData = extrasHolder.cryptoData; buffer.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, cryptoData.encryptionKey, buffer.cryptoInfo.iv, cryptoData.cryptoMode, cryptoData.encryptedBlocks, cryptoData.clearBlocks); // Adjust the offset and size to take into account the bytes read. int bytesRead = (int) (offset - extrasHolder.offset); extrasHolder.offset += bytesRead; extrasHolder.size -= bytesRead; }
Example #10
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Reads encryption data for the current sample. * <p> * The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and * {@link SampleExtrasHolder#size} is adjusted to subtract the number of bytes that were read. The * same value is added to {@link SampleExtrasHolder#offset}. * * @param buffer The buffer into which the encryption data should be written. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readEncryptionData(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { long offset = extrasHolder.offset; // Read the signal byte. scratch.reset(1); readData(offset, scratch.data, 1); offset++; byte signalByte = scratch.data[0]; boolean subsampleEncryption = (signalByte & 0x80) != 0; int ivSize = signalByte & 0x7F; // Read the initialization vector. if (buffer.cryptoInfo.iv == null) { buffer.cryptoInfo.iv = new byte[16]; } readData(offset, buffer.cryptoInfo.iv, ivSize); offset += ivSize; // Read the subsample count, if present. int subsampleCount; if (subsampleEncryption) { scratch.reset(2); readData(offset, scratch.data, 2); offset += 2; subsampleCount = scratch.readUnsignedShort(); } else { subsampleCount = 1; } // Write the clear and encrypted subsample sizes. int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { clearDataSizes = new int[subsampleCount]; } int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { encryptedDataSizes = new int[subsampleCount]; } if (subsampleEncryption) { int subsampleDataLength = 6 * subsampleCount; scratch.reset(subsampleDataLength); readData(offset, scratch.data, subsampleDataLength); offset += subsampleDataLength; scratch.setPosition(0); for (int i = 0; i < subsampleCount; i++) { clearDataSizes[i] = scratch.readUnsignedShort(); encryptedDataSizes[i] = scratch.readUnsignedIntToInt(); } } else { clearDataSizes[0] = 0; encryptedDataSizes[0] = extrasHolder.size - (int) (offset - extrasHolder.offset); } // Populate the cryptoInfo. CryptoData cryptoData = extrasHolder.cryptoData; buffer.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, cryptoData.encryptionKey, buffer.cryptoInfo.iv, cryptoData.cryptoMode, cryptoData.encryptedBlocks, cryptoData.clearBlocks); // Adjust the offset and size to take into account the bytes read. int bytesRead = (int) (offset - extrasHolder.offset); extrasHolder.offset += bytesRead; extrasHolder.size -= bytesRead; }
Example #11
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Reads encryption data for the current sample. * <p> * The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and * {@link SampleExtrasHolder#size} is adjusted to subtract the number of bytes that were read. The * same value is added to {@link SampleExtrasHolder#offset}. * * @param buffer The buffer into which the encryption data should be written. * @param extrasHolder The extras holder whose offset should be read and subsequently adjusted. */ private void readEncryptionData(DecoderInputBuffer buffer, SampleExtrasHolder extrasHolder) { long offset = extrasHolder.offset; // Read the signal byte. scratch.reset(1); readData(offset, scratch.data, 1); offset++; byte signalByte = scratch.data[0]; boolean subsampleEncryption = (signalByte & 0x80) != 0; int ivSize = signalByte & 0x7F; // Read the initialization vector. if (buffer.cryptoInfo.iv == null) { buffer.cryptoInfo.iv = new byte[16]; } readData(offset, buffer.cryptoInfo.iv, ivSize); offset += ivSize; // Read the subsample count, if present. int subsampleCount; if (subsampleEncryption) { scratch.reset(2); readData(offset, scratch.data, 2); offset += 2; subsampleCount = scratch.readUnsignedShort(); } else { subsampleCount = 1; } // Write the clear and encrypted subsample sizes. int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { clearDataSizes = new int[subsampleCount]; } int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { encryptedDataSizes = new int[subsampleCount]; } if (subsampleEncryption) { int subsampleDataLength = 6 * subsampleCount; scratch.reset(subsampleDataLength); readData(offset, scratch.data, subsampleDataLength); offset += subsampleDataLength; scratch.setPosition(0); for (int i = 0; i < subsampleCount; i++) { clearDataSizes[i] = scratch.readUnsignedShort(); encryptedDataSizes[i] = scratch.readUnsignedIntToInt(); } } else { clearDataSizes[0] = 0; encryptedDataSizes[0] = extrasHolder.size - (int) (offset - extrasHolder.offset); } // Populate the cryptoInfo. CryptoData cryptoData = extrasHolder.cryptoData; buffer.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, cryptoData.encryptionKey, buffer.cryptoInfo.iv, cryptoData.cryptoMode, cryptoData.encryptedBlocks, cryptoData.clearBlocks); // Adjust the offset and size to take into account the bytes read. int bytesRead = (int) (offset - extrasHolder.offset); extrasHolder.offset += bytesRead; extrasHolder.size -= bytesRead; }