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
7cd94819
authored
Aug 25, 2016
by
Rik Heijdens
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Took care of caption styling priorities
parent
176ce485
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
11 deletions
library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java
library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java
View file @
7cd94819
...
@@ -513,7 +513,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -513,7 +513,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
private
void
handlePreambleCode
(
byte
cc1
,
byte
cc2
)
{
private
void
handlePreambleCode
(
byte
cc1
,
byte
cc2
)
{
// For PAC layout see: https://en.wikipedia.org/wiki/EIA-608#Control_commands
// For PAC layout see: https://en.wikipedia.org/wiki/EIA-608#Control_commands
applySpan
();
// Apply any
spans.
applySpan
s
();
// Apply any open
spans.
// Parse the "next row down" flag.
// Parse the "next row down" flag.
boolean
nextRowDown
=
(
cc2
&
0x20
)
!=
0
;
boolean
nextRowDown
=
(
cc2
&
0x20
)
!=
0
;
...
@@ -528,17 +528,17 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -528,17 +528,17 @@ public final class Eia608Decoder implements SubtitleDecoder {
// Go through the bits, starting with the last bit - the underline flag:
// Go through the bits, starting with the last bit - the underline flag:
boolean
underline
=
(
cc2
&
0x1
)
!=
0
;
boolean
underline
=
(
cc2
&
0x1
)
!=
0
;
if
(
underline
)
{
if
(
underline
)
{
captionStyles
.
put
(
getSpanStartIndex
(),
new
UnderlineSpan
());
setCharacterStyle
(
new
UnderlineSpan
());
}
}
// Next, parse the attribute bits:
// Next, parse the attribute bits:
int
attribute
=
cc2
>>
1
&
0xF
;
int
attribute
=
cc2
>>
1
&
0xF
;
if
(
attribute
>=
0x0
&&
attribute
<
0x7
)
{
if
(
attribute
>=
0x0
&&
attribute
<
0x7
)
{
// Attribute is a foreground color
// Attribute is a foreground color
captionStyles
.
put
(
getSpanStartIndex
(),
new
ForegroundColorSpan
(
COLOR_MAP
[
attribute
]));
setCharacterStyle
(
new
ForegroundColorSpan
(
COLOR_MAP
[
attribute
]));
}
else
if
(
attribute
==
0x7
)
{
}
else
if
(
attribute
==
0x7
)
{
// Attribute is "italics"
// Attribute is "italics"
captionStyles
.
put
(
getSpanStartIndex
(),
new
StyleSpan
(
STYLE_ITALIC
));
setCharacterStyle
(
new
StyleSpan
(
STYLE_ITALIC
));
}
else
if
(
attribute
>=
0x8
&&
attribute
<=
0xF
)
{
}
else
if
(
attribute
>=
0x8
&&
attribute
<=
0xF
)
{
// Attribute is an indent
// Attribute is an indent
if
(
cueIndent
==
DEFAULT_INDENT
)
{
if
(
cueIndent
==
DEFAULT_INDENT
)
{
...
@@ -558,14 +558,14 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -558,14 +558,14 @@ public final class Eia608Decoder implements SubtitleDecoder {
int
attribute
=
cc2
>>
1
&
0xF
;
int
attribute
=
cc2
>>
1
&
0xF
;
if
((
cc1
&
0x1
)
!=
0
)
{
if
((
cc1
&
0x1
)
!=
0
)
{
// Background Color
// Background Color
captionStyles
.
put
(
getSpanStartIndex
(),
new
BackgroundColorSpan
(
transparentOrUnderline
?
setCharacterStyle
(
new
BackgroundColorSpan
(
transparentOrUnderline
?
COLOR_MAP
[
attribute
]
&
TRANSPARENCY_MASK
:
COLOR_MAP
[
attribute
]));
COLOR_MAP
[
attribute
]
&
TRANSPARENCY_MASK
:
COLOR_MAP
[
attribute
]));
}
else
{
}
else
{
// Foreground color
// Foreground color
captionStyles
.
put
(
getSpanStartIndex
(),
new
ForegroundColorSpan
(
COLOR_MAP
[
attribute
]));
setCharacterStyle
(
new
ForegroundColorSpan
(
COLOR_MAP
[
attribute
]));
if
(
transparentOrUnderline
)
{
if
(
transparentOrUnderline
)
{
// Text should be underlined
// Text should be underlined
captionStyles
.
put
(
getSpanStartIndex
(),
new
UnderlineSpan
());
setCharacterStyle
(
new
UnderlineSpan
());
}
}
}
}
}
}
...
@@ -585,9 +585,43 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -585,9 +585,43 @@ public final class Eia608Decoder implements SubtitleDecoder {
}
}
/**
/**
* Applies a Span to the SpannableStringBuilder.
* Sets a character style at the current cueIndex.
* Takes care of style priorities.
*
* @param style the style to set.
*/
private
void
setCharacterStyle
(
CharacterStyle
style
)
{
int
startIndex
=
getSpanStartIndex
();
// Close all open spans of the same type, and add a new one.
if
(
style
instanceof
ForegroundColorSpan
)
{
// Setting a foreground color clears the italics style.
applySpan
(
StyleSpan
.
class
);
//
}
applySpan
(
style
.
getClass
());
captionStyles
.
put
(
startIndex
,
style
);
}
/**
* Closes all open spans of the spansToApply class.
* @param spansToClose the class of which the spans should be closed.
*/
private
void
applySpan
(
Class
<?
extends
CharacterStyle
>
spansToClose
)
{
for
(
Integer
index
:
captionStyles
.
keySet
())
{
CharacterStyle
style
=
captionStyles
.
get
(
index
);
if
(
spansToClose
.
isInstance
(
style
))
{
if
(
index
<
captionStringBuilder
.
length
())
{
captionStringBuilder
.
setSpan
(
style
,
index
,
captionStringBuilder
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
captionStyles
.
remove
(
index
);
}
}
}
/**
* Applies all currently opened spans to the SpannableStringBuilder.
*/
*/
private
void
applySpan
()
{
private
void
applySpan
s
()
{
// Check if we have to do anything.
// Check if we have to do anything.
if
(
captionStyles
.
size
()
==
0
)
{
if
(
captionStyles
.
size
()
==
0
)
{
return
;
return
;
...
@@ -609,7 +643,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -609,7 +643,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
* Builds a cue from whatever is in the SpannableStringBuilder now.
* Builds a cue from whatever is in the SpannableStringBuilder now.
*/
*/
private
void
buildCue
()
{
private
void
buildCue
()
{
applySpan
();
// Apply Spans
applySpan
s
();
// Apply Spans
CharSequence
captionString
=
getDisplayCaption
();
CharSequence
captionString
=
getDisplayCaption
();
if
(
captionString
!=
null
)
{
if
(
captionString
!=
null
)
{
cueIndent
=
tabOffset
*
2.5f
+
cueIndent
;
cueIndent
=
tabOffset
*
2.5f
+
cueIndent
;
...
@@ -633,7 +667,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
...
@@ -633,7 +667,7 @@ public final class Eia608Decoder implements SubtitleDecoder {
private
void
backspace
()
{
private
void
backspace
()
{
if
(
captionStringBuilder
.
length
()
>
0
)
{
if
(
captionStringBuilder
.
length
()
>
0
)
{
captionStringBuilder
.
replace
(
captionStringBuilder
.
length
()
-
1
,
captionStringBuilder
.
length
(),
""
);
captionStringBuilder
.
delete
(
captionStringBuilder
.
length
()
-
1
,
captionStringBuilder
.
length
()
);
}
}
}
}
...
...
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