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
9c35d761
authored
Feb 22, 2021
by
Arnold Szabo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Parse font size into float, and fallback to Cue.DIMEN_UNSET instead of null.
parent
741a9c2e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
15 deletions
demos/main/src/main/assets/media.exolist.json
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaStyle.java
library/core/src/test/java/com/google/android/exoplayer2/text/ssa/SsaDecoderTest.java
testdata/src/test/assets/media/ssa/colors → testdata/src/test/assets/media/ssa/style_colors
testdata/src/test/assets/media/ssa/style_font_size
demos/main/src/main/assets/media.exolist.json
View file @
9c35d761
...
...
@@ -507,13 +507,6 @@
"subtitle_language"
:
"en"
},
{
"name"
:
"SubStation Alpha font size"
,
"uri"
:
"https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/video-avc-baseline-480.mp4"
,
"subtitle_uri"
:
"https://drive.google.com/uc?export=download&id=13EdW4Qru-vQerUlwS_Ht5Cely_Tn0tQe"
,
"subtitle_mime_type"
:
"text/x-ssa"
,
"subtitle_language"
:
"en"
},
{
"name"
:
"MPEG-4 Timed Text"
,
"uri"
:
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/dizzy-with-tx3g.mp4"
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
View file @
9c35d761
...
...
@@ -314,7 +314,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
/* end= */
spannableText
.
length
(),
SpannableString
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
if
(
style
.
fontSize
!=
null
&&
screenHeight
!=
Cue
.
DIMEN_UNSET
)
{
if
(
style
.
fontSize
!=
Cue
.
DIMEN_UNSET
&&
screenHeight
!=
Cue
.
DIMEN_UNSET
)
{
cue
.
setTextSize
(
style
.
fontSize
/
screenHeight
,
Cue
.
TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaStyle.java
View file @
9c35d761
...
...
@@ -27,6 +27,7 @@ import androidx.annotation.ColorInt;
import
androidx.annotation.IntDef
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Util
;
...
...
@@ -90,13 +91,13 @@ import java.util.regex.Pattern;
public
final
String
name
;
@SsaAlignment
public
final
int
alignment
;
@Nullable
@ColorInt
public
final
Integer
primaryColor
;
public
final
Integer
fontSize
;
public
final
float
fontSize
;
private
SsaStyle
(
String
name
,
@SsaAlignment
int
alignment
,
@Nullable
@ColorInt
Integer
primaryColor
,
Integer
fontSize
)
{
float
fontSize
)
{
this
.
name
=
name
;
this
.
alignment
=
alignment
;
this
.
primaryColor
=
primaryColor
;
...
...
@@ -197,12 +198,12 @@ import java.util.regex.Pattern;
return
Color
.
argb
(
a
,
r
,
g
,
b
);
}
private
static
Integer
parseFontSize
(
String
fontSize
)
{
private
static
float
parseFontSize
(
String
fontSize
)
{
try
{
return
Integer
.
parseIn
t
(
fontSize
);
return
Float
.
parseFloa
t
(
fontSize
);
}
catch
(
NumberFormatException
e
)
{
Log
.
w
(
TAG
,
"Failed to parse font size: '"
+
fontSize
+
"'"
,
e
);
return
null
;
return
Cue
.
DIMEN_UNSET
;
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/text/ssa/SsaDecoderTest.java
View file @
9c35d761
...
...
@@ -47,7 +47,8 @@ public final class SsaDecoderTest {
private
static
final
String
INVALID_TIMECODES
=
"media/ssa/invalid_timecodes"
;
private
static
final
String
INVALID_POSITIONS
=
"media/ssa/invalid_positioning"
;
private
static
final
String
POSITIONS_WITHOUT_PLAYRES
=
"media/ssa/positioning_without_playres"
;
private
static
final
String
COLORS
=
"media/ssa/colors"
;
private
static
final
String
STYLE_COLORS
=
"media/ssa/style_colors"
;
private
static
final
String
STYLE_FONT_SIZE
=
"media/ssa/style_font_size"
;
@Test
public
void
decodeEmpty
()
throws
IOException
{
...
...
@@ -274,7 +275,7 @@ public final class SsaDecoderTest {
@Test
public
void
decodeColors
()
throws
IOException
{
SsaDecoder
decoder
=
new
SsaDecoder
();
byte
[]
bytes
=
TestUtil
.
getByteArray
(
ApplicationProvider
.
getApplicationContext
(),
COLORS
);
byte
[]
bytes
=
TestUtil
.
getByteArray
(
ApplicationProvider
.
getApplicationContext
(),
STYLE_
COLORS
);
Subtitle
subtitle
=
decoder
.
decode
(
bytes
,
bytes
.
length
,
false
);
assertThat
(
subtitle
.
getEventTimeCount
()).
isEqualTo
(
14
);
// &H000000FF (AABBGGRR) -> #FFFF0000 (AARRGGBB)
...
...
@@ -319,6 +320,21 @@ public final class SsaDecoderTest {
.
hasNoForegroundColorSpanBetween
(
0
,
seventhCueText
.
length
());
}
@Test
public
void
decodeFontSize
()
throws
IOException
{
SsaDecoder
decoder
=
new
SsaDecoder
();
byte
[]
bytes
=
TestUtil
.
getByteArray
(
ApplicationProvider
.
getApplicationContext
(),
STYLE_FONT_SIZE
);
Subtitle
subtitle
=
decoder
.
decode
(
bytes
,
bytes
.
length
,
false
);
assertThat
(
subtitle
.
getEventTimeCount
()).
isEqualTo
(
4
);
Cue
firstCue
=
Iterables
.
getOnlyElement
(
subtitle
.
getCues
(
subtitle
.
getEventTime
(
0
)));
assertThat
(
firstCue
.
textSize
).
isEqualTo
(
30
f
/
720
f
);
assertThat
(
firstCue
.
textSizeType
).
isEqualTo
(
Cue
.
TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING
);
Cue
secondCue
=
Iterables
.
getOnlyElement
(
subtitle
.
getCues
(
subtitle
.
getEventTime
(
2
)));
assertThat
(
secondCue
.
textSize
).
isEqualTo
(
72.2f
/
720
f
);
assertThat
(
secondCue
.
textSizeType
).
isEqualTo
(
Cue
.
TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING
);
}
private
static
void
assertTypicalCue1
(
Subtitle
subtitle
,
int
eventIndex
)
{
assertThat
(
subtitle
.
getEventTime
(
eventIndex
)).
isEqualTo
(
0
);
assertThat
(
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
())
...
...
testdata/src/test/assets/media/ssa/colors
→
testdata/src/test/assets/media/ssa/
style_
colors
View file @
9c35d761
File moved
testdata/src/test/assets/media/ssa/style_font_size
0 → 100644
View file @
9c35d761
[Script Info]
Title: SSA/ASS Test
Original Script: Arnold Szabo
Script Type: V4.00+
PlayResX: 1280
PlayResY: 720
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: FontSizeSmall ,Roboto,30, &H000000FF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
Style: FontSizeBig ,Roboto,72.2,&H000000FF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,3,0,2,50,50,70,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.95,0:00:03.11,FontSizeSmall ,Arnold,0,0,0,,First line with font size 30.
Dialogue: 0,0:00:08.50,0:00:11.50,FontSizeBig ,Arnold,0,0,0,,Second line with font size 72.2.
\ No newline at end of file
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