Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4eaa6111
authored
Jan 20, 2021
by
aquilescanta
Committed by
kim-vde
Jan 22, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add SampleQueue.peek
PiperOrigin-RevId: 352779870
parent
c40d1c66
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
33 deletions
library/core/src/main/java/com/google/android/exoplayer2/source/SampleDataQueue.java
library/core/src/main/java/com/google/android/exoplayer2/source/SampleQueue.java
library/core/src/main/java/com/google/android/exoplayer2/source/SampleDataQueue.java
View file @
4eaa6111
...
@@ -115,45 +115,25 @@ import java.util.Arrays;
...
@@ -115,45 +115,25 @@ import java.util.Arrays;
}
}
/**
/**
* Reads data from the rolling buffer to populate a decoder input buffer.
* Reads data from the rolling buffer to populate a decoder input buffer, and advances the read
* position.
*
*
* @param buffer The buffer to populate.
* @param buffer The buffer to populate.
* @param extrasHolder The extras holder whose offset should be read and subsequently adjusted.
* @param extrasHolder The extras holder whose offset should be read and subsequently adjusted.
*/
*/
public
void
readToBuffer
(
DecoderInputBuffer
buffer
,
SampleExtrasHolder
extrasHolder
)
{
public
void
readToBuffer
(
DecoderInputBuffer
buffer
,
SampleExtrasHolder
extrasHolder
)
{
// Read encryption data if the sample is encrypted.
readAllocationNode
=
readSampleData
(
readAllocationNode
,
buffer
,
extrasHolder
,
scratch
);
AllocationNode
readAllocationNode
=
this
.
readAllocationNode
;
}
if
(
buffer
.
isEncrypted
())
{
readAllocationNode
=
readEncryptionData
(
readAllocationNode
,
buffer
,
extrasHolder
,
scratch
);
}
// 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
);
readAllocationNode
=
readData
(
readAllocationNode
,
extrasHolder
.
offset
,
scratch
.
getData
(),
4
);
int
sampleSize
=
scratch
.
readUnsignedIntToInt
();
extrasHolder
.
offset
+=
4
;
extrasHolder
.
size
-=
4
;
// Write the sample data.
buffer
.
ensureSpaceForWrite
(
sampleSize
);
readAllocationNode
=
readData
(
readAllocationNode
,
extrasHolder
.
offset
,
buffer
.
data
,
sampleSize
);
extrasHolder
.
offset
+=
sampleSize
;
extrasHolder
.
size
-=
sampleSize
;
// Write the remaining data as supplemental data.
/**
buffer
.
resetSupplementalData
(
extrasHolder
.
size
);
* Peeks data from the rolling buffer to populate a decoder input buffer, without advancing the
readAllocationNode
=
* read position.
readData
(
*
readAllocationNode
,
extrasHolder
.
offset
,
buffer
.
supplementalData
,
extrasHolder
.
size
);
* @param buffer The buffer to populate.
}
else
{
* @param extrasHolder The extras holder whose offset should be read and subsequently adjusted.
// Write the sample data.
*/
buffer
.
ensureSpaceForWrite
(
extrasHolder
.
size
);
public
void
peekToBuffer
(
DecoderInputBuffer
buffer
,
SampleExtrasHolder
extrasHolder
)
{
readAllocationNode
=
readSampleData
(
readAllocationNode
,
buffer
,
extrasHolder
,
scratch
);
readData
(
readAllocationNode
,
extrasHolder
.
offset
,
buffer
.
data
,
extrasHolder
.
size
);
}
this
.
readAllocationNode
=
readAllocationNode
;
}
}
/**
/**
...
@@ -271,6 +251,52 @@ import java.util.Arrays;
...
@@ -271,6 +251,52 @@ import java.util.Arrays;
}
}
/**
/**
* Reads data from the rolling buffer to populate a decoder input buffer.
*
* @param allocationNode The first {@link AllocationNode} containing data yet to be read.
* @param buffer The buffer to populate.
* @param extrasHolder The extras holder whose offset should be read and subsequently adjusted.
* @param scratch A scratch {@link ParsableByteArray}.
* @return The first {@link AllocationNode} that contains unread bytes after the last byte that
* the invocation read.
*/
private
static
AllocationNode
readSampleData
(
AllocationNode
allocationNode
,
DecoderInputBuffer
buffer
,
SampleExtrasHolder
extrasHolder
,
ParsableByteArray
scratch
)
{
if
(
buffer
.
isEncrypted
())
{
allocationNode
=
readEncryptionData
(
allocationNode
,
buffer
,
extrasHolder
,
scratch
);
}
// 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
);
allocationNode
=
readData
(
allocationNode
,
extrasHolder
.
offset
,
scratch
.
getData
(),
4
);
int
sampleSize
=
scratch
.
readUnsignedIntToInt
();
extrasHolder
.
offset
+=
4
;
extrasHolder
.
size
-=
4
;
// Write the sample data.
buffer
.
ensureSpaceForWrite
(
sampleSize
);
allocationNode
=
readData
(
allocationNode
,
extrasHolder
.
offset
,
buffer
.
data
,
sampleSize
);
extrasHolder
.
offset
+=
sampleSize
;
extrasHolder
.
size
-=
sampleSize
;
// Write the remaining data as supplemental data.
buffer
.
resetSupplementalData
(
extrasHolder
.
size
);
allocationNode
=
readData
(
allocationNode
,
extrasHolder
.
offset
,
buffer
.
supplementalData
,
extrasHolder
.
size
);
}
else
{
// Write the sample data.
buffer
.
ensureSpaceForWrite
(
extrasHolder
.
size
);
allocationNode
=
readData
(
allocationNode
,
extrasHolder
.
offset
,
buffer
.
data
,
extrasHolder
.
size
);
}
return
allocationNode
;
}
/**
* Reads encryption data for the sample described by {@code extrasHolder}.
* Reads encryption data for the sample described by {@code extrasHolder}.
*
*
* <p>The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and {@link
* <p>The encryption data is written into {@link DecoderInputBuffer#cryptoInfo}, and {@link
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/SampleQueue.java
View file @
4eaa6111
...
@@ -377,6 +377,20 @@ public class SampleQueue implements TrackOutput {
...
@@ -377,6 +377,20 @@ public class SampleQueue implements TrackOutput {
return
mayReadSample
(
relativeReadIndex
);
return
mayReadSample
(
relativeReadIndex
);
}
}
/** Equivalent to {@link #read}, except it never advances the read position. */
public
final
int
peek
(
FormatHolder
formatHolder
,
DecoderInputBuffer
buffer
,
boolean
formatRequired
,
boolean
loadingFinished
)
{
int
result
=
peekSampleMetadata
(
formatHolder
,
buffer
,
formatRequired
,
loadingFinished
,
extrasHolder
);
if
(
result
==
C
.
RESULT_BUFFER_READ
&&
!
buffer
.
isEndOfStream
()
&&
!
buffer
.
isFlagsOnly
())
{
sampleDataQueue
.
peekToBuffer
(
buffer
,
extrasHolder
);
}
return
result
;
}
/**
/**
* Attempts to read from the queue.
* Attempts to read from the queue.
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment