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
8b0f5b0a
authored
Dec 18, 2019
by
olly
Committed by
Oliver Woodman
Dec 18, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Some nullness cleanup for extractor.ogg
PiperOrigin-RevId: 286203692
parent
e8068f0f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
24 deletions
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/FlacReader.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/OpusReader.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/StreamReader.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/VorbisReader.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/FlacReader.java
View file @
8b0f5b0a
...
...
@@ -24,9 +24,9 @@ import com.google.android.exoplayer2.extractor.SeekMap;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.FlacConstants
;
import
com.google.android.exoplayer2.util.FlacStreamMetadata
;
import
com.google.android.exoplayer2.util.FlacStreamMetadata.SeekTable
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.util.Arrays
;
/**
...
...
@@ -70,15 +70,17 @@ import java.util.Arrays;
@Override
protected
boolean
readHeaders
(
ParsableByteArray
packet
,
long
position
,
SetupData
setupData
)
{
byte
[]
data
=
packet
.
data
;
@Nullable
FlacStreamMetadata
streamMetadata
=
this
.
streamMetadata
;
if
(
streamMetadata
==
null
)
{
streamMetadata
=
new
FlacStreamMetadata
(
data
,
17
);
this
.
streamMetadata
=
streamMetadata
;
byte
[]
metadata
=
Arrays
.
copyOfRange
(
data
,
9
,
packet
.
limit
());
setupData
.
format
=
streamMetadata
.
getFormat
(
metadata
,
/* id3Metadata= */
null
);
}
else
if
((
data
[
0
]
&
0x7F
)
==
FlacConstants
.
METADATA_TYPE_SEEK_TABLE
)
{
flacOggSeeker
=
new
FlacOggSeeker
();
FlacStreamMetadata
.
SeekTable
seekTable
=
FlacMetadataReader
.
readSeekTableMetadataBlock
(
packet
);
SeekTable
seekTable
=
FlacMetadataReader
.
readSeekTableMetadataBlock
(
packet
);
streamMetadata
=
streamMetadata
.
copyWithSeekTable
(
seekTable
);
this
.
streamMetadata
=
streamMetadata
;
flacOggSeeker
=
new
FlacOggSeeker
(
streamMetadata
,
seekTable
);
}
else
if
(
isAudioPacket
(
data
))
{
if
(
flacOggSeeker
!=
null
)
{
flacOggSeeker
.
setFirstFrameOffset
(
position
);
...
...
@@ -101,12 +103,16 @@ import java.util.Arrays;
return
result
;
}
private
class
FlacOggSeeker
implements
OggSeeker
{
private
static
final
class
FlacOggSeeker
implements
OggSeeker
{
private
FlacStreamMetadata
streamMetadata
;
private
SeekTable
seekTable
;
private
long
firstFrameOffset
;
private
long
pendingSeekGranule
;
public
FlacOggSeeker
()
{
public
FlacOggSeeker
(
FlacStreamMetadata
streamMetadata
,
SeekTable
seekTable
)
{
this
.
streamMetadata
=
streamMetadata
;
this
.
seekTable
=
seekTable
;
firstFrameOffset
=
-
1
;
pendingSeekGranule
=
-
1
;
}
...
...
@@ -116,7 +122,7 @@ import java.util.Arrays;
}
@Override
public
long
read
(
ExtractorInput
input
)
throws
IOException
,
InterruptedException
{
public
long
read
(
ExtractorInput
input
)
{
if
(
pendingSeekGranule
>=
0
)
{
long
result
=
-(
pendingSeekGranule
+
2
);
pendingSeekGranule
=
-
1
;
...
...
@@ -127,9 +133,10 @@ import java.util.Arrays;
@Override
public
void
startSeek
(
long
targetGranule
)
{
Assertions
.
checkNotNull
(
streamMetadata
.
seekTable
);
long
[]
seekPointGranules
=
streamMetadata
.
seekTable
.
pointSampleNumbers
;
int
index
=
Util
.
binarySearchFloor
(
seekPointGranules
,
targetGranule
,
true
,
true
);
long
[]
seekPointGranules
=
seekTable
.
pointSampleNumbers
;
int
index
=
Util
.
binarySearchFloor
(
seekPointGranules
,
targetGranule
,
/* inclusive= */
true
,
/* stayInBounds= */
true
);
pendingSeekGranule
=
seekPointGranules
[
index
];
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/OpusReader.java
View file @
8b0f5b0a
...
...
@@ -76,9 +76,19 @@ import java.util.List;
putNativeOrderLong
(
initializationData
,
preskip
);
putNativeOrderLong
(
initializationData
,
DEFAULT_SEEK_PRE_ROLL_SAMPLES
);
setupData
.
format
=
Format
.
createAudioSampleFormat
(
null
,
MimeTypes
.
AUDIO_OPUS
,
null
,
Format
.
NO_VALUE
,
Format
.
NO_VALUE
,
channelCount
,
SAMPLE_RATE
,
initializationData
,
null
,
0
,
null
);
setupData
.
format
=
Format
.
createAudioSampleFormat
(
null
,
MimeTypes
.
AUDIO_OPUS
,
/* codecs= */
null
,
Format
.
NO_VALUE
,
Format
.
NO_VALUE
,
channelCount
,
SAMPLE_RATE
,
initializationData
,
/* drmInitData= */
null
,
/* selectionFlags= */
0
,
/* language= */
null
);
headerRead
=
true
;
}
else
{
boolean
headerPacket
=
packet
.
readInt
()
==
OPUS_CODE
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/StreamReader.java
View file @
8b0f5b0a
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
ogg
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.extractor.Extractor
;
...
...
@@ -23,6 +24,7 @@ import com.google.android.exoplayer2.extractor.ExtractorOutput;
import
com.google.android.exoplayer2.extractor.PositionHolder
;
import
com.google.android.exoplayer2.extractor.SeekMap
;
import
com.google.android.exoplayer2.extractor.TrackOutput
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
java.io.IOException
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
...
...
@@ -51,7 +53,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private
long
currentGranule
;
private
int
state
;
private
int
sampleRate
;
private
SetupData
setupData
;
@Nullable
private
SetupData
setupData
;
private
long
lengthOfReadPacket
;
private
boolean
seekMapSet
;
private
boolean
formatSet
;
...
...
@@ -149,7 +151,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
boolean
isLastPage
=
(
firstPayloadPageHeader
.
type
&
0x04
)
!=
0
;
// Type 4 is end of stream.
oggSeeker
=
new
DefaultOggSeeker
(
this
,
/* streamReader= */
this
,
payloadStartPosition
,
input
.
getLength
(),
firstPayloadPageHeader
.
headerSize
+
firstPayloadPageHeader
.
bodySize
,
...
...
@@ -173,8 +175,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
else
if
(
position
<
-
1
)
{
onSeekEnd
(-(
position
+
2
));
}
if
(!
seekMapSet
)
{
SeekMap
seekMap
=
oggSeeker
.
createSeekMap
(
);
SeekMap
seekMap
=
Assertions
.
checkNotNull
(
oggSeeker
.
createSeekMap
()
);
extractorOutput
.
seekMap
(
seekMap
);
seekMapSet
=
true
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/extractor/ogg/VorbisReader.java
View file @
8b0f5b0a
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
ogg
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.VisibleForTesting
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.ParserException
;
...
...
@@ -30,16 +31,16 @@ import java.util.ArrayList;
*/
/* package */
final
class
VorbisReader
extends
StreamReader
{
private
VorbisSetup
vorbisSetup
;
@Nullable
private
VorbisSetup
vorbisSetup
;
private
int
previousPacketBlockSize
;
private
boolean
seenFirstAudioPacket
;
private
VorbisUtil
.
VorbisIdHeader
vorbisIdHeader
;
private
VorbisUtil
.
CommentHeader
commentHeader
;
@Nullable
private
VorbisUtil
.
VorbisIdHeader
vorbisIdHeader
;
@Nullable
private
VorbisUtil
.
CommentHeader
commentHeader
;
public
static
boolean
verifyBitstreamType
(
ParsableByteArray
data
)
{
try
{
return
VorbisUtil
.
verifyVorbisHeaderCapturePattern
(
0x01
,
data
,
true
);
return
VorbisUtil
.
verifyVorbisHeaderCapturePattern
(
/* headerType= */
0x01
,
data
,
true
);
}
catch
(
ParserException
e
)
{
return
false
;
}
...
...
@@ -102,14 +103,24 @@ import java.util.ArrayList;
codecInitialisationData
.
add
(
vorbisSetup
.
idHeader
.
data
);
codecInitialisationData
.
add
(
vorbisSetup
.
setupHeaderData
);
setupData
.
format
=
Format
.
createAudioSampleFormat
(
null
,
MimeTypes
.
AUDIO_VORBIS
,
null
,
this
.
vorbisSetup
.
idHeader
.
bitrateNominal
,
Format
.
NO_VALUE
,
this
.
vorbisSetup
.
idHeader
.
channels
,
(
int
)
this
.
vorbisSetup
.
idHeader
.
sampleRate
,
codecInitialisationData
,
null
,
0
,
null
);
setupData
.
format
=
Format
.
createAudioSampleFormat
(
null
,
MimeTypes
.
AUDIO_VORBIS
,
/* codecs= */
null
,
this
.
vorbisSetup
.
idHeader
.
bitrateNominal
,
Format
.
NO_VALUE
,
this
.
vorbisSetup
.
idHeader
.
channels
,
(
int
)
this
.
vorbisSetup
.
idHeader
.
sampleRate
,
codecInitialisationData
,
null
,
/* selectionFlags= */
0
,
/* language= */
null
);
return
true
;
}
@VisibleForTesting
@Nullable
/* package */
VorbisSetup
readSetupHeaders
(
ParsableByteArray
scratch
)
throws
IOException
{
if
(
vorbisIdHeader
==
null
)
{
...
...
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