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
703fb777
authored
Apr 08, 2020
by
kimvde
Committed by
Oliver Woodman
Apr 08, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Optimize extractors sniffing order
Issue: #6410 PiperOrigin-RevId: 305436352
parent
4e2a0f60
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
57 deletions
RELEASENOTES.md
library/extractor/src/main/java/com/google/android/exoplayer2/extractor/DefaultExtractorsFactory.java
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java
RELEASENOTES.md
View file @
703fb777
...
@@ -109,6 +109,9 @@
...
@@ -109,6 +109,9 @@
*
Cast extension: Implement playlist API and deprecate the old queue
*
Cast extension: Implement playlist API and deprecate the old queue
manipulation API.
manipulation API.
*
Demo app: Retain previous position in list of samples.
*
Demo app: Retain previous position in list of samples.
*
Change the order of extractors for sniffing to reduce start-up latency in
`DefaultExtractorsFactory`
and
`DefaultHlsExtractorsFactory`
(
[
#6410
](
https://github.com/google/ExoPlayer/issues/6410
)
).
### 2.11.4 (2020-04-08)
### 2.11.4 (2020-04-08)
...
...
library/extractor/src/main/java/com/google/android/exoplayer2/extractor/DefaultExtractorsFactory.java
View file @
703fb777
...
@@ -241,44 +241,46 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
...
@@ -241,44 +241,46 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
@Override
@Override
public
synchronized
Extractor
[]
createExtractors
()
{
public
synchronized
Extractor
[]
createExtractors
()
{
Extractor
[]
extractors
=
new
Extractor
[
14
];
Extractor
[]
extractors
=
new
Extractor
[
14
];
extractors
[
0
]
=
new
MatroskaExtractor
(
matroskaFlags
);
// Extractors order is optimized according to
extractors
[
1
]
=
new
FragmentedMp4Extractor
(
fragmentedMp4Flags
);
// https://docs.google.com/document/d/1w2mKaWMxfz2Ei8-LdxqbPs1VLe_oudB-eryXXw9OvQQ.
extractors
[
2
]
=
new
Mp4Extractor
(
mp4Flags
);
extractors
[
0
]
=
new
FlvExtractor
();
extractors
[
3
]
=
if
(
FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR
!=
null
)
{
new
Mp3Extractor
(
try
{
mp3Flags
extractors
[
1
]
=
FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR
.
newInstance
();
}
catch
(
Exception
e
)
{
// Should never happen.
throw
new
IllegalStateException
(
"Unexpected error creating FLAC extractor"
,
e
);
}
}
else
{
extractors
[
1
]
=
new
FlacExtractor
(
coreFlacFlags
);
}
extractors
[
2
]
=
new
WavExtractor
();
extractors
[
3
]
=
new
FragmentedMp4Extractor
(
fragmentedMp4Flags
);
extractors
[
4
]
=
new
Mp4Extractor
(
mp4Flags
);
extractors
[
5
]
=
new
AmrExtractor
(
amrFlags
|
(
constantBitrateSeekingEnabled
|
(
constantBitrateSeekingEnabled
?
Mp3
Extractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
?
Amr
Extractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
:
0
));
:
0
));
extractors
[
4
]
=
extractors
[
6
]
=
new
PsExtractor
();
extractors
[
7
]
=
new
OggExtractor
();
extractors
[
8
]
=
new
TsExtractor
(
tsMode
,
tsFlags
);
extractors
[
9
]
=
new
MatroskaExtractor
(
matroskaFlags
);
extractors
[
10
]
=
new
AdtsExtractor
(
new
AdtsExtractor
(
adtsFlags
adtsFlags
|
(
constantBitrateSeekingEnabled
|
(
constantBitrateSeekingEnabled
?
AdtsExtractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
?
AdtsExtractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
:
0
));
:
0
));
extractors
[
5
]
=
new
Ac3Extractor
();
extractors
[
11
]
=
new
Ac3Extractor
();
extractors
[
6
]
=
new
TsExtractor
(
tsMode
,
tsFlags
);
extractors
[
12
]
=
new
Ac4Extractor
();
extractors
[
7
]
=
new
FlvExtractor
();
extractors
[
13
]
=
extractors
[
8
]
=
new
OggExtractor
();
new
Mp3Extractor
(
extractors
[
9
]
=
new
PsExtractor
();
mp3Flags
extractors
[
10
]
=
new
WavExtractor
();
extractors
[
11
]
=
new
AmrExtractor
(
amrFlags
|
(
constantBitrateSeekingEnabled
|
(
constantBitrateSeekingEnabled
?
Amr
Extractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
?
Mp3
Extractor
.
FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
:
0
));
:
0
));
extractors
[
12
]
=
new
Ac4Extractor
();
if
(
FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR
!=
null
)
{
try
{
extractors
[
13
]
=
FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR
.
newInstance
();
}
catch
(
Exception
e
)
{
// Should never happen.
throw
new
IllegalStateException
(
"Unexpected error creating FLAC extractor"
,
e
);
}
}
else
{
extractors
[
13
]
=
new
FlacExtractor
(
coreFlacFlags
);
}
return
extractors
;
return
extractors
;
}
}
...
...
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/DefaultHlsExtractorFactory.java
View file @
703fb777
...
@@ -29,6 +29,7 @@ import com.google.android.exoplayer2.extractor.ts.AdtsExtractor;
...
@@ -29,6 +29,7 @@ import com.google.android.exoplayer2.extractor.ts.AdtsExtractor;
import
com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory
;
import
com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory
;
import
com.google.android.exoplayer2.extractor.ts.TsExtractor
;
import
com.google.android.exoplayer2.extractor.ts.TsExtractor
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.TimestampAdjuster
;
import
com.google.android.exoplayer2.util.TimestampAdjuster
;
import
java.io.EOFException
;
import
java.io.EOFException
;
...
@@ -51,6 +52,8 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -51,6 +52,8 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
public
static
final
String
M4_FILE_EXTENSION_PREFIX
=
".m4"
;
public
static
final
String
M4_FILE_EXTENSION_PREFIX
=
".m4"
;
public
static
final
String
MP4_FILE_EXTENSION_PREFIX
=
".mp4"
;
public
static
final
String
MP4_FILE_EXTENSION_PREFIX
=
".mp4"
;
public
static
final
String
CMF_FILE_EXTENSION_PREFIX
=
".cmf"
;
public
static
final
String
CMF_FILE_EXTENSION_PREFIX
=
".cmf"
;
public
static
final
String
TS_FILE_EXTENSION
=
".ts"
;
public
static
final
String
TS_FILE_EXTENSION_PREFIX
=
".ts"
;
public
static
final
String
VTT_FILE_EXTENSION
=
".vtt"
;
public
static
final
String
VTT_FILE_EXTENSION
=
".vtt"
;
public
static
final
String
WEBVTT_FILE_EXTENSION
=
".webvtt"
;
public
static
final
String
WEBVTT_FILE_EXTENSION
=
".webvtt"
;
...
@@ -94,7 +97,7 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -94,7 +97,7 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
throws
IOException
{
throws
IOException
{
if
(
previousExtractor
!=
null
)
{
if
(
previousExtractor
!=
null
)
{
// A extractor has already been successfully used. Return one of the same type.
// A
n
extractor has already been successfully used. Return one of the same type.
if
(
isReusable
(
previousExtractor
))
{
if
(
isReusable
(
previousExtractor
))
{
return
buildResult
(
previousExtractor
);
return
buildResult
(
previousExtractor
);
}
else
{
}
else
{
...
@@ -108,15 +111,29 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -108,15 +111,29 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
}
}
// Try selecting the extractor by the file extension.
// Try selecting the extractor by the file extension.
@Nullable
Extractor
extractorByFileExtension
=
Extractor
extractorByFileExtension
=
createExtractorByFileExtension
(
uri
,
format
,
muxedCaptionFormats
,
timestampAdjuster
);
createExtractorByFileExtension
(
uri
,
format
,
muxedCaptionFormats
,
timestampAdjuster
);
extractorInput
.
resetPeekPosition
();
extractorInput
.
resetPeekPosition
();
if
(
sniffQuietly
(
extractorByFileExtension
,
extractorInput
))
{
if
(
extractorByFileExtension
!=
null
&&
sniffQuietly
(
extractorByFileExtension
,
extractorInput
))
{
return
buildResult
(
extractorByFileExtension
);
return
buildResult
(
extractorByFileExtension
);
}
}
// We need to manually sniff each known type, without retrying the one selected by file
// We need to manually sniff each known type, without retrying the one selected by file
// extension.
// extension. Extractors order is optimized according to
// https://docs.google.com/document/d/1w2mKaWMxfz2Ei8-LdxqbPs1VLe_oudB-eryXXw9OvQQ.
// Extractor to be used if the type is not recognized.
@Nullable
Extractor
fallBackExtractor
=
extractorByFileExtension
;
if
(!(
extractorByFileExtension
instanceof
FragmentedMp4Extractor
))
{
FragmentedMp4Extractor
fragmentedMp4Extractor
=
createFragmentedMp4Extractor
(
timestampAdjuster
,
format
,
muxedCaptionFormats
);
if
(
sniffQuietly
(
fragmentedMp4Extractor
,
extractorInput
))
{
return
buildResult
(
fragmentedMp4Extractor
);
}
}
if
(!(
extractorByFileExtension
instanceof
WebvttExtractor
))
{
if
(!(
extractorByFileExtension
instanceof
WebvttExtractor
))
{
WebvttExtractor
webvttExtractor
=
new
WebvttExtractor
(
format
.
language
,
timestampAdjuster
);
WebvttExtractor
webvttExtractor
=
new
WebvttExtractor
(
format
.
language
,
timestampAdjuster
);
...
@@ -125,6 +142,22 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -125,6 +142,22 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
}
}
}
}
if
(!(
extractorByFileExtension
instanceof
TsExtractor
))
{
TsExtractor
tsExtractor
=
createTsExtractor
(
payloadReaderFactoryFlags
,
exposeCea608WhenMissingDeclarations
,
format
,
muxedCaptionFormats
,
timestampAdjuster
);
if
(
sniffQuietly
(
tsExtractor
,
extractorInput
))
{
return
buildResult
(
tsExtractor
);
}
if
(
fallBackExtractor
==
null
)
{
fallBackExtractor
=
tsExtractor
;
}
}
if
(!(
extractorByFileExtension
instanceof
AdtsExtractor
))
{
if
(!(
extractorByFileExtension
instanceof
AdtsExtractor
))
{
AdtsExtractor
adtsExtractor
=
new
AdtsExtractor
();
AdtsExtractor
adtsExtractor
=
new
AdtsExtractor
();
if
(
sniffQuietly
(
adtsExtractor
,
extractorInput
))
{
if
(
sniffQuietly
(
adtsExtractor
,
extractorInput
))
{
...
@@ -154,31 +187,10 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -154,31 +187,10 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
}
}
}
}
if
(!(
extractorByFileExtension
instanceof
FragmentedMp4Extractor
))
{
return
buildResult
(
Assertions
.
checkNotNull
(
fallBackExtractor
));
FragmentedMp4Extractor
fragmentedMp4Extractor
=
createFragmentedMp4Extractor
(
timestampAdjuster
,
format
,
muxedCaptionFormats
);
if
(
sniffQuietly
(
fragmentedMp4Extractor
,
extractorInput
))
{
return
buildResult
(
fragmentedMp4Extractor
);
}
}
if
(!(
extractorByFileExtension
instanceof
TsExtractor
))
{
TsExtractor
tsExtractor
=
createTsExtractor
(
payloadReaderFactoryFlags
,
exposeCea608WhenMissingDeclarations
,
format
,
muxedCaptionFormats
,
timestampAdjuster
);
if
(
sniffQuietly
(
tsExtractor
,
extractorInput
))
{
return
buildResult
(
tsExtractor
);
}
}
// Fall back on the extractor created by file extension.
return
buildResult
(
extractorByFileExtension
);
}
}
@Nullable
private
Extractor
createExtractorByFileExtension
(
private
Extractor
createExtractorByFileExtension
(
Uri
uri
,
Uri
uri
,
Format
format
,
Format
format
,
...
@@ -206,14 +218,16 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
...
@@ -206,14 +218,16 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
||
lastPathSegment
.
startsWith
(
MP4_FILE_EXTENSION_PREFIX
,
lastPathSegment
.
length
()
-
5
)
||
lastPathSegment
.
startsWith
(
MP4_FILE_EXTENSION_PREFIX
,
lastPathSegment
.
length
()
-
5
)
||
lastPathSegment
.
startsWith
(
CMF_FILE_EXTENSION_PREFIX
,
lastPathSegment
.
length
()
-
5
))
{
||
lastPathSegment
.
startsWith
(
CMF_FILE_EXTENSION_PREFIX
,
lastPathSegment
.
length
()
-
5
))
{
return
createFragmentedMp4Extractor
(
timestampAdjuster
,
format
,
muxedCaptionFormats
);
return
createFragmentedMp4Extractor
(
timestampAdjuster
,
format
,
muxedCaptionFormats
);
}
else
{
}
else
if
(
lastPathSegment
.
endsWith
(
TS_FILE_EXTENSION
)
// For any other file extension, we assume TS format.
||
lastPathSegment
.
startsWith
(
TS_FILE_EXTENSION_PREFIX
,
lastPathSegment
.
length
()
-
4
))
{
return
createTsExtractor
(
return
createTsExtractor
(
payloadReaderFactoryFlags
,
payloadReaderFactoryFlags
,
exposeCea608WhenMissingDeclarations
,
exposeCea608WhenMissingDeclarations
,
format
,
format
,
muxedCaptionFormats
,
muxedCaptionFormats
,
timestampAdjuster
);
timestampAdjuster
);
}
else
{
return
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