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
78ef90f6
authored
Nov 12, 2018
by
Arnold Szabo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Correcting default sizing of bitmaps, code review adjustments
parent
d159050e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
23 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlDecoder.java
View file @
78ef90f6
...
@@ -70,7 +70,6 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
...
@@ -70,7 +70,6 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
private
static
final
String
ATTR_REGION
=
"region"
;
private
static
final
String
ATTR_REGION
=
"region"
;
private
static
final
String
ATTR_IMAGE
=
"backgroundImage"
;
private
static
final
String
ATTR_IMAGE
=
"backgroundImage"
;
private
static
final
Pattern
CLOCK_TIME
=
private
static
final
Pattern
CLOCK_TIME
=
Pattern
.
compile
(
"^([0-9][0-9]+):([0-9][0-9]):([0-9][0-9])"
Pattern
.
compile
(
"^([0-9][0-9]+):([0-9][0-9]):([0-9][0-9])"
+
"(?:(\\.[0-9]+)|:([0-9][0-9])(?:\\.([0-9]+))?)?$"
);
+
"(?:(\\.[0-9]+)|:([0-9][0-9])(?:\\.([0-9]+))?)?$"
);
...
@@ -130,7 +129,7 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
...
@@ -130,7 +129,7 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
Log
.
i
(
TAG
,
"Ignoring unsupported tag: "
+
xmlParser
.
getName
());
Log
.
i
(
TAG
,
"Ignoring unsupported tag: "
+
xmlParser
.
getName
());
unsupportedNodeDepth
++;
unsupportedNodeDepth
++;
}
else
if
(
TtmlNode
.
TAG_HEAD
.
equals
(
name
))
{
}
else
if
(
TtmlNode
.
TAG_HEAD
.
equals
(
name
))
{
parseHeader
(
xmlParser
,
globalStyles
,
regionMap
,
cellResolution
,
imageMap
);
parseHeader
(
xmlParser
,
globalStyles
,
cellResolution
,
regionMap
,
imageMap
);
}
else
{
}
else
{
try
{
try
{
TtmlNode
node
=
parseNode
(
xmlParser
,
parent
,
regionMap
,
frameAndTickRate
);
TtmlNode
node
=
parseNode
(
xmlParser
,
parent
,
regionMap
,
frameAndTickRate
);
...
@@ -232,8 +231,8 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
...
@@ -232,8 +231,8 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
private
Map
<
String
,
TtmlStyle
>
parseHeader
(
private
Map
<
String
,
TtmlStyle
>
parseHeader
(
XmlPullParser
xmlParser
,
XmlPullParser
xmlParser
,
Map
<
String
,
TtmlStyle
>
globalStyles
,
Map
<
String
,
TtmlStyle
>
globalStyles
,
Map
<
String
,
TtmlRegion
>
globalRegions
,
CellResolution
cellResolution
,
CellResolution
cellResolution
,
Map
<
String
,
TtmlRegion
>
globalRegions
,
Map
<
String
,
String
>
imageMap
)
Map
<
String
,
String
>
imageMap
)
throws
IOException
,
XmlPullParserException
{
throws
IOException
,
XmlPullParserException
{
do
{
do
{
...
@@ -255,23 +254,21 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
...
@@ -255,23 +254,21 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
globalRegions
.
put
(
ttmlRegion
.
id
,
ttmlRegion
);
globalRegions
.
put
(
ttmlRegion
.
id
,
ttmlRegion
);
}
}
}
else
if
(
XmlPullParserUtil
.
isStartTag
(
xmlParser
,
TtmlNode
.
TAG_METADATA
)){
}
else
if
(
XmlPullParserUtil
.
isStartTag
(
xmlParser
,
TtmlNode
.
TAG_METADATA
)){
parseMeta
D
ata
(
xmlParser
,
imageMap
);
parseMeta
d
ata
(
xmlParser
,
imageMap
);
}
}
}
while
(!
XmlPullParserUtil
.
isEndTag
(
xmlParser
,
TtmlNode
.
TAG_HEAD
));
}
while
(!
XmlPullParserUtil
.
isEndTag
(
xmlParser
,
TtmlNode
.
TAG_HEAD
));
return
globalStyles
;
return
globalStyles
;
}
}
p
ublic
void
parseMetaD
ata
(
XmlPullParser
xmlParser
,
Map
<
String
,
String
>
imageMap
)
throws
IOException
,
XmlPullParserException
{
p
rivate
void
parseMetad
ata
(
XmlPullParser
xmlParser
,
Map
<
String
,
String
>
imageMap
)
throws
IOException
,
XmlPullParserException
{
do
{
do
{
xmlParser
.
next
();
xmlParser
.
next
();
if
(
XmlPullParserUtil
.
isStartTag
(
xmlParser
,
TtmlNode
.
TAG_SMPTE_IMAGE
))
{
if
(
XmlPullParserUtil
.
isStartTag
(
xmlParser
,
TtmlNode
.
TAG_SMPTE_IMAGE
))
{
for
(
int
i
=
0
;
i
<
xmlParser
.
getAttributeCount
();
i
++)
{
String
id
=
XmlPullParserUtil
.
getAttributeValue
(
xmlParser
,
"id"
);
String
id
=
XmlPullParserUtil
.
getAttributeValue
(
xmlParser
,
"id"
);
if
(
id
!=
null
)
{
if
(
id
!=
null
){
String
base64
=
xmlParser
.
nextText
();
String
base64
=
xmlParser
.
nextText
();
imageMap
.
put
(
id
,
base64
);
imageMap
.
put
(
id
,
base64
);
}
}
}
}
}
}
while
(!
XmlPullParserUtil
.
isEndTag
(
xmlParser
,
TtmlNode
.
TAG_METADATA
));
}
while
(!
XmlPullParserUtil
.
isEndTag
(
xmlParser
,
TtmlNode
.
TAG_METADATA
));
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java
View file @
78ef90f6
...
@@ -183,18 +183,24 @@ import java.util.TreeSet;
...
@@ -183,18 +183,24 @@ import java.util.TreeSet;
public
List
<
Cue
>
getCues
(
long
timeUs
,
Map
<
String
,
TtmlStyle
>
globalStyles
,
public
List
<
Cue
>
getCues
(
long
timeUs
,
Map
<
String
,
TtmlStyle
>
globalStyles
,
Map
<
String
,
TtmlRegion
>
regionMap
,
Map
<
String
,
String
>
imageMap
)
{
Map
<
String
,
TtmlRegion
>
regionMap
,
Map
<
String
,
String
>
imageMap
)
{
TreeMap
<
String
,
SpannableStringBuilder
>
regionOutputs
=
new
TreeMap
<>();
TreeMap
<
String
,
SpannableStringBuilder
>
region
Text
Outputs
=
new
TreeMap
<>();
List
<
Pair
<
String
,
String
>>
regionImage
List
=
new
ArrayList
<>();
List
<
Pair
<
String
,
String
>>
regionImage
Outputs
=
new
ArrayList
<>();
traverseForText
(
timeUs
,
false
,
regionId
,
regionOutputs
);
traverseForText
(
timeUs
,
false
,
regionId
,
region
Text
Outputs
);
traverseForStyle
(
timeUs
,
globalStyles
,
regionOutputs
);
traverseForStyle
(
timeUs
,
globalStyles
,
region
Text
Outputs
);
traverseForImage
(
timeUs
,
regionId
,
regionImage
List
);
traverseForImage
(
timeUs
,
regionId
,
regionImage
Outputs
);
List
<
Cue
>
cues
=
new
ArrayList
<>();
List
<
Cue
>
cues
=
new
ArrayList
<>();
// Create image based cues
// Create image based cues
for
(
Pair
<
String
,
String
>
regionImagePair
:
regionImage
List
)
{
for
(
Pair
<
String
,
String
>
regionImagePair
:
regionImage
Outputs
)
{
String
base64
=
imageMap
.
get
(
regionImagePair
.
second
);
String
base64
=
imageMap
.
get
(
regionImagePair
.
second
);
if
(
base64
==
null
)
{
// Image ref points to invalid image, do nothing
continue
;
}
byte
[]
decodedString
=
Base64
.
decode
(
base64
,
Base64
.
DEFAULT
);
byte
[]
decodedString
=
Base64
.
decode
(
base64
,
Base64
.
DEFAULT
);
Bitmap
decodedByte
=
BitmapFactory
.
decodeByteArray
(
decodedString
,
0
,
decodedString
.
length
);
Bitmap
decodedByte
=
BitmapFactory
.
decodeByteArray
(
decodedString
,
0
,
decodedString
.
length
);
TtmlRegion
region
=
regionMap
.
get
(
regionImagePair
.
first
);
TtmlRegion
region
=
regionMap
.
get
(
regionImagePair
.
first
);
...
@@ -206,13 +212,13 @@ import java.util.TreeSet;
...
@@ -206,13 +212,13 @@ import java.util.TreeSet;
region
.
line
,
region
.
line
,
region
.
lineAnchor
,
region
.
lineAnchor
,
region
.
width
,
region
.
width
,
Cue
.
DIMEN_UNSET
/* height= */
Cue
.
DIMEN_UNSET
)
)
);
);
}
}
// Create text based cues
// Create text based cues
for
(
Entry
<
String
,
SpannableStringBuilder
>
entry
:
regionOutputs
.
entrySet
())
{
for
(
Entry
<
String
,
SpannableStringBuilder
>
entry
:
region
Text
Outputs
.
entrySet
())
{
TtmlRegion
region
=
regionMap
.
get
(
entry
.
getKey
());
TtmlRegion
region
=
regionMap
.
get
(
entry
.
getKey
());
cues
.
add
(
cues
.
add
(
new
Cue
(
new
Cue
(
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
View file @
78ef90f6
...
@@ -355,8 +355,12 @@ import com.google.android.exoplayer2.util.Util;
...
@@ -355,8 +355,12 @@ import com.google.android.exoplayer2.util.Util;
}
}
private
void
setupBitmapLayout
()
{
private
void
setupBitmapLayout
()
{
int
parentWidth
=
parentRight
-
parentLeft
;
int
parentHeight
=
parentBottom
-
parentTop
;
// Default position
// Default position
if
(
cuePosition
==
Cue
.
DIMEN_UNSET
)
{
if
(
cuePosition
==
Cue
.
DIMEN_UNSET
)
{
cuePositionAnchor
=
Cue
.
ANCHOR_TYPE_MIDDLE
;
cuePosition
=
0.5f
;
cuePosition
=
0.5f
;
}
}
...
@@ -366,13 +370,25 @@ import com.google.android.exoplayer2.util.Util;
...
@@ -366,13 +370,25 @@ import com.google.android.exoplayer2.util.Util;
cueLine
=
0.85f
;
cueLine
=
0.85f
;
}
}
// Default width
// Default width
and height
if
(
cueSize
==
Cue
.
DIMEN_UNSET
)
{
if
(
cueSize
==
Cue
.
DIMEN_UNSET
)
{
cueSize
=
0.5f
;
// Scale up by height to be 10% of the parent's height
cueBitmapHeight
=
0.1f
;
float
heightInParent
=
parentHeight
*
cueBitmapHeight
;
float
widthInParent
=
heightInParent
*
((
float
)
cueBitmap
.
getWidth
()
/
cueBitmap
.
getHeight
());
cueSize
=
widthInParent
/
parentWidth
;
// If by the previous scaling the width exceeds 50% of the parent's width
// then scale back to 50% by width and adjust its height to keep the aspect ratio
if
(
cueSize
>
0.5f
)
{
cueSize
=
0.5f
;
widthInParent
=
parentWidth
*
cueSize
;
heightInParent
=
widthInParent
*
((
float
)
cueBitmap
.
getHeight
()
/
cueBitmap
.
getWidth
());
cueBitmapHeight
=
heightInParent
/
parentHeight
;
}
}
}
int
parentWidth
=
parentRight
-
parentLeft
;
int
parentHeight
=
parentBottom
-
parentTop
;
float
anchorX
=
parentLeft
+
(
parentWidth
*
cuePosition
);
float
anchorX
=
parentLeft
+
(
parentWidth
*
cuePosition
);
float
anchorY
=
parentTop
+
(
parentHeight
*
cueLine
);
float
anchorY
=
parentTop
+
(
parentHeight
*
cueLine
);
int
width
=
Math
.
round
(
parentWidth
*
cueSize
);
int
width
=
Math
.
round
(
parentWidth
*
cueSize
);
...
...
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