com.google.android.exoplayer2.upstream.Allocation Java Examples
The following examples show how to use
com.google.android.exoplayer2.upstream.Allocation.
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 | 6 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; System.arraycopy(allocation.data, readAllocationNode.translateOffset(absolutePosition), target, length - remaining, toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #2
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Clears allocation nodes starting from {@code fromNode}. * * @param fromNode The node from which to clear. */ private void clearAllocationNodes(AllocationNode fromNode) { if (!fromNode.wasInitialized) { return; } // Bulk release allocations for performance (it's significantly faster when using // DefaultAllocator because the allocator's lock only needs to be acquired and released once) // [Internal: See b/29542039]. int allocationCount = (writeAllocationNode.wasInitialized ? 1 : 0) + ((int) (writeAllocationNode.startPosition - fromNode.startPosition) / allocationLength); Allocation[] allocationsToRelease = new Allocation[allocationCount]; AllocationNode currentNode = fromNode; for (int i = 0; i < allocationsToRelease.length; i++) { allocationsToRelease[i] = currentNode.allocation; currentNode = currentNode.clear(); } allocator.release(allocationsToRelease); }
Example #3
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; System.arraycopy(allocation.data, readAllocationNode.translateOffset(absolutePosition), target, length - remaining, toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #4
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; System.arraycopy(allocation.data, readAllocationNode.translateOffset(absolutePosition), target, length - remaining, toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #5
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Clears allocation nodes starting from {@code fromNode}. * * @param fromNode The node from which to clear. */ private void clearAllocationNodes(AllocationNode fromNode) { if (!fromNode.wasInitialized) { return; } // Bulk release allocations for performance (it's significantly faster when using // DefaultAllocator because the allocator's lock only needs to be acquired and released once) // [Internal: See b/29542039]. int allocationCount = (writeAllocationNode.wasInitialized ? 1 : 0) + ((int) (writeAllocationNode.startPosition - fromNode.startPosition) / allocationLength); Allocation[] allocationsToRelease = new Allocation[allocationCount]; AllocationNode currentNode = fromNode; for (int i = 0; i < allocationsToRelease.length; i++) { allocationsToRelease[i] = currentNode.allocation; currentNode = currentNode.clear(); } allocator.release(allocationsToRelease); }
Example #6
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; System.arraycopy(allocation.data, readAllocationNode.translateOffset(absolutePosition), target, length - remaining, toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #7
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Clears allocation nodes starting from {@code fromNode}. * * @param fromNode The node from which to clear. */ private void clearAllocationNodes(AllocationNode fromNode) { if (!fromNode.wasInitialized) { return; } // Bulk release allocations for performance (it's significantly faster when using // DefaultAllocator because the allocator's lock only needs to be acquired and released once) // [Internal: See b/29542039]. int allocationCount = (writeAllocationNode.wasInitialized ? 1 : 0) + ((int) (writeAllocationNode.startPosition - fromNode.startPosition) / allocationLength); Allocation[] allocationsToRelease = new Allocation[allocationCount]; AllocationNode currentNode = fromNode; for (int i = 0; i < allocationsToRelease.length; i++) { allocationsToRelease[i] = currentNode.allocation; currentNode = currentNode.clear(); } allocator.release(allocationsToRelease); }
Example #8
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Clears allocation nodes starting from {@code fromNode}. * * @param fromNode The node from which to clear. */ private void clearAllocationNodes(AllocationNode fromNode) { if (!fromNode.wasInitialized) { return; } // Bulk release allocations for performance (it's significantly faster when using // DefaultAllocator because the allocator's lock only needs to be acquired and released once) // [Internal: See b/29542039]. int allocationCount = (writeAllocationNode.wasInitialized ? 1 : 0) + ((int) (writeAllocationNode.startPosition - fromNode.startPosition) / allocationLength); Allocation[] allocationsToRelease = new Allocation[allocationCount]; AllocationNode currentNode = fromNode; for (int i = 0; i < allocationsToRelease.length; i++) { allocationsToRelease[i] = currentNode.allocation; currentNode = currentNode.clear(); } allocator.release(allocationsToRelease); }
Example #9
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; System.arraycopy(allocation.data, readAllocationNode.translateOffset(absolutePosition), target, length - remaining, toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #10
Source File: SampleQueue.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Clears allocation nodes starting from {@code fromNode}. * * @param fromNode The node from which to clear. */ private void clearAllocationNodes(AllocationNode fromNode) { if (!fromNode.wasInitialized) { return; } // Bulk release allocations for performance (it's significantly faster when using // DefaultAllocator because the allocator's lock only needs to be acquired and released once) // [Internal: See b/29542039]. int allocationCount = (writeAllocationNode.wasInitialized ? 1 : 0) + ((int) (writeAllocationNode.startPosition - fromNode.startPosition) / allocationLength); Allocation[] allocationsToRelease = new Allocation[allocationCount]; AllocationNode currentNode = fromNode; for (int i = 0; i < allocationsToRelease.length; i++) { allocationsToRelease[i] = currentNode.allocation; currentNode = currentNode.clear(); } allocator.release(allocationsToRelease); }
Example #11
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; target.put(allocation.data, readAllocationNode.translateOffset(absolutePosition), toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #12
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; target.put(allocation.data, readAllocationNode.translateOffset(absolutePosition), toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #13
Source File: SampleQueue.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; target.put(allocation.data, readAllocationNode.translateOffset(absolutePosition), toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #14
Source File: DefaultTrackOutput.java From K-Sonic with MIT License | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { int remaining = length; while (remaining > 0) { dropDownstreamTo(absolutePosition); int positionInAllocation = (int) (absolutePosition - totalBytesDropped); int toCopy = Math.min(remaining, allocationLength - positionInAllocation); Allocation allocation = dataQueue.peek(); target.put(allocation.data, allocation.translateOffset(positionInAllocation), toCopy); absolutePosition += toCopy; remaining -= toCopy; } }
Example #15
Source File: DefaultTrackOutput.java From K-Sonic with MIT License | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The array into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, byte[] target, int length) { int bytesRead = 0; while (bytesRead < length) { dropDownstreamTo(absolutePosition); int positionInAllocation = (int) (absolutePosition - totalBytesDropped); int toCopy = Math.min(length - bytesRead, allocationLength - positionInAllocation); Allocation allocation = dataQueue.peek(); System.arraycopy(allocation.data, allocation.translateOffset(positionInAllocation), target, bytesRead, toCopy); absolutePosition += toCopy; bytesRead += toCopy; } }
Example #16
Source File: DefaultTrackOutput.java From K-Sonic with MIT License | 5 votes |
private void clearSampleData() { infoQueue.clearSampleData(); allocator.release(dataQueue.toArray(new Allocation[dataQueue.size()])); dataQueue.clear(); allocator.trim(); totalBytesDropped = 0; totalBytesWritten = 0; lastAllocation = null; lastAllocationOffset = allocationLength; needKeyframe = true; }
Example #17
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; target.put(allocation.data, readAllocationNode.translateOffset(absolutePosition), toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #18
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Reads data from the front of the rolling buffer. * * @param absolutePosition The absolute position from which data should be read. * @param target The buffer into which data should be written. * @param length The number of bytes to read. */ private void readData(long absolutePosition, ByteBuffer target, int length) { advanceReadTo(absolutePosition); int remaining = length; while (remaining > 0) { int toCopy = Math.min(remaining, (int) (readAllocationNode.endPosition - absolutePosition)); Allocation allocation = readAllocationNode.allocation; target.put(allocation.data, readAllocationNode.translateOffset(absolutePosition), toCopy); remaining -= toCopy; absolutePosition += toCopy; if (absolutePosition == readAllocationNode.endPosition) { readAllocationNode = readAllocationNode.next; } } }
Example #19
Source File: SampleQueue.java From Telegram with GNU General Public License v2.0 | 2 votes |
/** * Initializes the node. * * @param allocation The node's {@link Allocation}. * @param next The next {@link AllocationNode}. */ public void initialize(Allocation allocation, AllocationNode next) { this.allocation = allocation; this.next = next; wasInitialized = true; }
Example #20
Source File: SampleQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 2 votes |
/** * Initializes the node. * * @param allocation The node's {@link Allocation}. * @param next The next {@link AllocationNode}. */ public void initialize(Allocation allocation, AllocationNode next) { this.allocation = allocation; this.next = next; wasInitialized = true; }
Example #21
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 2 votes |
/** * Initializes the node. * * @param allocation The node's {@link Allocation}. * @param next The next {@link AllocationNode}. */ public void initialize(Allocation allocation, AllocationNode next) { this.allocation = allocation; this.next = next; wasInitialized = true; }
Example #22
Source File: SampleQueue.java From TelePlus-Android with GNU General Public License v2.0 | 2 votes |
/** * Initializes the node. * * @param allocation The node's {@link Allocation}. * @param next The next {@link AllocationNode}. */ public void initialize(Allocation allocation, AllocationNode next) { this.allocation = allocation; this.next = next; wasInitialized = true; }
Example #23
Source File: SampleQueue.java From MediaSDK with Apache License 2.0 | 2 votes |
/** * Initializes the node. * * @param allocation The node's {@link Allocation}. * @param next The next {@link AllocationNode}. */ public void initialize(Allocation allocation, AllocationNode next) { this.allocation = allocation; this.next = next; wasInitialized = true; }