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
93764795
authored
Dec 05, 2019
by
olly
Committed by
Oliver Woodman
Dec 06, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add NonNull annotations to text packages
PiperOrigin-RevId: 283951181
parent
cb873dd1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
134 additions
and
42 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java
library/core/src/main/java/com/google/android/exoplayer2/text/SimpleSubtitleDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java
library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Cue.java
library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/cea/package-info.java
library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java
library/core/src/main/java/com/google/android/exoplayer2/text/dvb/package-info.java
library/core/src/main/java/com/google/android/exoplayer2/text/package-info.java
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/package-info.java
library/core/src/main/java/com/google/android/exoplayer2/text/subrip/SubripDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/package-info.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCssStyle.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCue.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttParserUtil.java
library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java
View file @
93764795
...
...
@@ -333,7 +333,7 @@ public class Cue {
*/
public
Cue
(
CharSequence
text
,
Alignment
textAlignment
,
@Nullable
Alignment
textAlignment
,
float
line
,
@LineType
int
lineType
,
@AnchorType
int
lineAnchor
,
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/SimpleSubtitleDecoder.java
View file @
93764795
...
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.decoder.SimpleDecoder
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.nio.ByteBuffer
;
/**
...
...
@@ -29,9 +30,8 @@ public abstract class SimpleSubtitleDecoder extends
private
final
String
name
;
/**
* @param name The name of the decoder.
*/
/** @param name The name of the decoder. */
@SuppressWarnings
(
"initialization:method.invocation.invalid"
)
protected
SimpleSubtitleDecoder
(
String
name
)
{
super
(
new
SubtitleInputBuffer
[
2
],
new
SubtitleOutputBuffer
[
2
]);
this
.
name
=
name
;
...
...
@@ -74,7 +74,7 @@ public abstract class SimpleSubtitleDecoder extends
protected
final
SubtitleDecoderException
decode
(
SubtitleInputBuffer
inputBuffer
,
SubtitleOutputBuffer
outputBuffer
,
boolean
reset
)
{
try
{
ByteBuffer
inputData
=
inputBuffer
.
data
;
ByteBuffer
inputData
=
Assertions
.
checkNotNull
(
inputBuffer
.
data
)
;
Subtitle
subtitle
=
decode
(
inputData
.
array
(),
inputData
.
limit
(),
reset
);
outputBuffer
.
setContent
(
inputBuffer
.
timeUs
,
subtitle
,
inputBuffer
.
subsampleOffsetUs
);
// Clear BUFFER_FLAG_DECODE_ONLY (see [Internal: b/27893809]).
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java
View file @
93764795
...
...
@@ -80,11 +80,11 @@ public final class TextRenderer extends BaseRenderer implements Callback {
private
boolean
inputStreamEnded
;
private
boolean
outputStreamEnded
;
@ReplacementState
private
int
decoderReplacementState
;
private
Format
streamFormat
;
private
SubtitleDecoder
decoder
;
private
SubtitleInputBuffer
nextInputBuffer
;
private
SubtitleOutputBuffer
subtitle
;
private
SubtitleOutputBuffer
nextSubtitle
;
@Nullable
private
Format
streamFormat
;
@Nullable
private
SubtitleDecoder
decoder
;
@Nullable
private
SubtitleInputBuffer
nextInputBuffer
;
@Nullable
private
SubtitleOutputBuffer
subtitle
;
@Nullable
private
SubtitleOutputBuffer
nextSubtitle
;
private
int
nextSubtitleEventIndex
;
/**
...
...
@@ -132,7 +132,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
}
@Override
protected
void
onStreamChanged
(
Format
[]
formats
,
long
offsetUs
)
throws
ExoPlaybackException
{
protected
void
onStreamChanged
(
Format
[]
formats
,
long
offsetUs
)
{
streamFormat
=
formats
[
0
];
if
(
decoder
!=
null
)
{
decoderReplacementState
=
REPLACEMENT_STATE_SIGNAL_END_OF_STREAM
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Cue.java
View file @
93764795
...
...
@@ -25,11 +25,6 @@ import com.google.android.exoplayer2.text.Cue;
/* package */
final
class
Cea708Cue
extends
Cue
implements
Comparable
<
Cea708Cue
>
{
/**
* An unset priority.
*/
public
static
final
int
PRIORITY_UNSET
=
-
1
;
/**
* The priority of the cue box.
*/
public
final
int
priority
;
...
...
@@ -64,5 +59,4 @@ import com.google.android.exoplayer2.text.Cue;
}
return
0
;
}
}
library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java
View file @
93764795
...
...
@@ -25,6 +25,7 @@ import android.text.style.BackgroundColorSpan;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.UnderlineSpan
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.text.Cue
;
...
...
@@ -152,7 +153,8 @@ public final class Cea708Decoder extends CeaDecoder {
private
DtvCcPacket
currentDtvCcPacket
;
private
int
currentWindow
;
public
Cea708Decoder
(
int
accessibilityChannel
,
List
<
byte
[]>
initializationData
)
{
// TODO: Retrieve isWideAspectRatio from initializationData and use it.
public
Cea708Decoder
(
int
accessibilityChannel
,
@Nullable
List
<
byte
[]>
initializationData
)
{
ccData
=
new
ParsableByteArray
();
serviceBlockPacket
=
new
ParsableBitArray
();
selectedServiceNumber
=
accessibilityChannel
==
Format
.
NO_VALUE
?
1
:
accessibilityChannel
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/cea/package-info.java
0 → 100644
View file @
93764795
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
text
.
cea
;
import
com.google.android.exoplayer2.util.NonNullApi
;
library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java
View file @
93764795
This diff is collapsed.
Click to expand it.
library/core/src/main/java/com/google/android/exoplayer2/text/dvb/package-info.java
0 → 100644
View file @
93764795
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
text
.
dvb
;
import
com.google.android.exoplayer2.util.NonNullApi
;
library/core/src/main/java/com/google/android/exoplayer2/text/package-info.java
0 → 100644
View file @
93764795
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
text
;
import
com.google.android.exoplayer2.util.NonNullApi
;
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
View file @
93764795
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
text
.
ssa
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.text.Layout
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
...
...
@@ -115,7 +117,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* @param data A {@link ParsableByteArray} from which the header should be read.
*/
private
void
parseHeader
(
ParsableByteArray
data
)
{
String
currentLine
;
@Nullable
String
currentLine
;
while
((
currentLine
=
data
.
readLine
())
!=
null
)
{
if
(
"[Script Info]"
.
equalsIgnoreCase
(
currentLine
))
{
parseScriptInfo
(
data
);
...
...
@@ -140,7 +142,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* set to the beginning of of the first line after {@code [Script Info]}.
*/
private
void
parseScriptInfo
(
ParsableByteArray
data
)
{
String
currentLine
;
@Nullable
String
currentLine
;
while
((
currentLine
=
data
.
readLine
())
!=
null
&&
(
data
.
bytesLeft
()
==
0
||
data
.
peekUnsignedByte
()
!=
'['
))
{
String
[]
infoNameAndValue
=
currentLine
.
split
(
":"
);
...
...
@@ -176,9 +178,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* at the beginning of of the first line after {@code [V4+ Styles]}.
*/
private
static
Map
<
String
,
SsaStyle
>
parseStyles
(
ParsableByteArray
data
)
{
SsaStyle
.
Format
formatInfo
=
null
;
Map
<
String
,
SsaStyle
>
styles
=
new
LinkedHashMap
<>();
String
currentLine
;
@Nullable
SsaStyle
.
Format
formatInfo
=
null
;
@Nullable
String
currentLine
;
while
((
currentLine
=
data
.
readLine
())
!=
null
&&
(
data
.
bytesLeft
()
==
0
||
data
.
peekUnsignedByte
()
!=
'['
))
{
if
(
currentLine
.
startsWith
(
FORMAT_LINE_PREFIX
))
{
...
...
@@ -188,7 +190,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
Log
.
w
(
TAG
,
"Skipping 'Style:' line before 'Format:' line: "
+
currentLine
);
continue
;
}
SsaStyle
style
=
SsaStyle
.
fromStyleLine
(
currentLine
,
formatInfo
);
@Nullable
SsaStyle
style
=
SsaStyle
.
fromStyleLine
(
currentLine
,
formatInfo
);
if
(
style
!=
null
)
{
styles
.
put
(
style
.
name
,
style
);
}
...
...
@@ -205,8 +207,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* @param cueTimesUs A sorted list to which parsed cue timestamps will be added.
*/
private
void
parseEventBody
(
ParsableByteArray
data
,
List
<
List
<
Cue
>>
cues
,
List
<
Long
>
cueTimesUs
)
{
@Nullable
SsaDialogueFormat
format
=
haveInitializationData
?
dialogueFormatFromInitializationData
:
null
;
String
currentLine
;
@Nullable
String
currentLine
;
while
((
currentLine
=
data
.
readLine
())
!=
null
)
{
if
(
currentLine
.
startsWith
(
FORMAT_LINE_PREFIX
))
{
format
=
SsaDialogueFormat
.
fromFormatLine
(
currentLine
);
...
...
@@ -250,6 +253,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
return
;
}
@Nullable
SsaStyle
style
=
styles
!=
null
&&
format
.
styleIndex
!=
C
.
INDEX_UNSET
?
styles
.
get
(
lineValues
[
format
.
styleIndex
].
trim
())
...
...
@@ -281,10 +285,11 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
if
(!
matcher
.
matches
())
{
return
C
.
TIME_UNSET
;
}
long
timestampUs
=
Long
.
parseLong
(
matcher
.
group
(
1
))
*
60
*
60
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
matcher
.
group
(
2
))
*
60
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
matcher
.
group
(
3
))
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
matcher
.
group
(
4
))
*
10000
;
// 100ths of a second.
long
timestampUs
=
Long
.
parseLong
(
castNonNull
(
matcher
.
group
(
1
)))
*
60
*
60
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
castNonNull
(
matcher
.
group
(
2
)))
*
60
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
castNonNull
(
matcher
.
group
(
3
)))
*
C
.
MICROS_PER_SECOND
;
timestampUs
+=
Long
.
parseLong
(
castNonNull
(
matcher
.
group
(
4
)))
*
10000
;
// 100ths of a second.
return
timestampUs
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/package-info.java
0 → 100644
View file @
93764795
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
text
.
ssa
;
import
com.google.android.exoplayer2.util.NonNullApi
;
library/core/src/main/java/com/google/android/exoplayer2/text/subrip/SubripDecoder.java
View file @
93764795
...
...
@@ -73,8 +73,8 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
ArrayList
<
Cue
>
cues
=
new
ArrayList
<>();
LongArray
cueTimesUs
=
new
LongArray
();
ParsableByteArray
subripData
=
new
ParsableByteArray
(
bytes
,
length
);
String
currentLine
;
@Nullable
String
currentLine
;
while
((
currentLine
=
subripData
.
readLine
())
!=
null
)
{
if
(
currentLine
.
length
()
==
0
)
{
// Skip blank lines.
...
...
@@ -119,7 +119,7 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
Spanned
text
=
Html
.
fromHtml
(
textBuilder
.
toString
());
String
alignmentTag
=
null
;
@Nullable
String
alignmentTag
=
null
;
for
(
int
i
=
0
;
i
<
tags
.
size
();
i
++)
{
String
tag
=
tags
.
get
(
i
);
if
(
tag
.
matches
(
SUBRIP_ALIGNMENT_TAG
))
{
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/package-info.java
0 → 100644
View file @
93764795
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
text
.
ttml
;
import
com.google.android.exoplayer2.util.NonNullApi
;
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCssStyle.java
View file @
93764795
...
...
@@ -220,7 +220,7 @@ public final class WebvttCssStyle {
return
fontFamily
;
}
public
WebvttCssStyle
setFontFamily
(
String
fontFamily
)
{
public
WebvttCssStyle
setFontFamily
(
@Nullable
String
fontFamily
)
{
this
.
fontFamily
=
Util
.
toLowerInvariant
(
fontFamily
);
return
this
;
}
...
...
@@ -264,7 +264,7 @@ public final class WebvttCssStyle {
return
textAlign
;
}
public
WebvttCssStyle
setTextAlign
(
Layout
.
Alignment
textAlign
)
{
public
WebvttCssStyle
setTextAlign
(
@Nullable
Layout
.
Alignment
textAlign
)
{
this
.
textAlign
=
textAlign
;
return
this
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCue.java
View file @
93764795
...
...
@@ -26,9 +26,7 @@ import com.google.android.exoplayer2.util.Log;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
/**
* A representation of a WebVTT cue.
*/
/** A representation of a WebVTT cue. */
public
final
class
WebvttCue
extends
Cue
{
private
static
final
float
DEFAULT_POSITION
=
0.5f
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java
View file @
93764795
...
...
@@ -44,9 +44,7 @@ import java.util.List;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* Parser for WebVTT cues. (https://w3c.github.io/webvtt/#cues)
*/
/** Parser for WebVTT cues. (https://w3c.github.io/webvtt/#cues) */
public
final
class
WebvttCueParser
{
public
static
final
Pattern
CUE_HEADER_PATTERN
=
Pattern
...
...
@@ -94,7 +92,7 @@ public final class WebvttCueParser {
*/
public
boolean
parseCue
(
ParsableByteArray
webvttData
,
WebvttCue
.
Builder
builder
,
List
<
WebvttCssStyle
>
styles
)
{
String
firstLine
=
webvttData
.
readLine
();
@Nullable
String
firstLine
=
webvttData
.
readLine
();
if
(
firstLine
==
null
)
{
return
false
;
}
...
...
@@ -104,7 +102,7 @@ public final class WebvttCueParser {
return
parseCue
(
null
,
cueHeaderMatcher
,
webvttData
,
builder
,
textBuilder
,
styles
);
}
// The first line is not the timestamps, but could be the cue id.
String
secondLine
=
webvttData
.
readLine
();
@Nullable
String
secondLine
=
webvttData
.
readLine
();
if
(
secondLine
==
null
)
{
return
false
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttParserUtil.java
View file @
93764795
...
...
@@ -52,7 +52,7 @@ public final class WebvttParserUtil {
* @param input The input from which the line should be read.
*/
public
static
boolean
isWebvttHeaderLine
(
ParsableByteArray
input
)
{
String
line
=
input
.
readLine
();
@Nullable
String
line
=
input
.
readLine
();
return
line
!=
null
&&
line
.
startsWith
(
WEBVTT_HEADER
);
}
...
...
@@ -101,7 +101,7 @@ public final class WebvttParserUtil {
*/
@Nullable
public
static
Matcher
findNextCueHeader
(
ParsableByteArray
input
)
{
String
line
;
@Nullable
String
line
;
while
((
line
=
input
.
readLine
())
!=
null
)
{
if
(
COMMENT
.
matcher
(
line
).
matches
())
{
// Skip until the end of the comment block.
...
...
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