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
ef2d7c7f
authored
Jan 02, 2017
by
Julian Cable
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
tests pass.
parent
b692d9fa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
45 deletions
library/src/androidTest/java/com/google/android/exoplayer2/text/ssa/SSATests.java
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java
library/src/main/java/com/google/android/exoplayer2/text/ssa/Style.java
library/src/androidTest/java/com/google/android/exoplayer2/text/ssa/SSATests.java
View file @
ef2d7c7f
...
@@ -13,17 +13,21 @@ import java.text.SimpleDateFormat;
...
@@ -13,17 +13,21 @@ import java.text.SimpleDateFormat;
public
class
SSATests
extends
InstrumentationTestCase
{
public
class
SSATests
extends
InstrumentationTestCase
{
private
static
final
String
TYPICAL_FILE
=
"ssa/typical"
;
private
static
final
String
TYPICAL_FILE
=
"ssa/typical"
;
private
static
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"HH:mm:ss.SSS"
);
public
void
testTimeCodeConvert
()
throws
IOException
{
assertEquals
(
"0:00:04.230"
,
SSADecoder
.
formatTimeCode
(
SSADecoder
.
parseTimecode
(
"0:00:04.23"
)));
}
public
void
testDecodeTypical
()
throws
IOException
{
public
void
testDecodeTypical
()
throws
IOException
{
SSADecoder
decoder
=
new
SSADecoder
();
SSADecoder
decoder
=
new
SSADecoder
();
byte
[]
bytes
=
TestUtil
.
getByteArray
(
getInstrumentation
(),
TYPICAL_FILE
);
byte
[]
bytes
=
TestUtil
.
getByteArray
(
getInstrumentation
(),
TYPICAL_FILE
);
SSASubtitle
subtitle
=
decoder
.
decodeFile
(
bytes
,
bytes
.
length
);
SSASubtitle
subtitle
=
decoder
.
decodeFile
(
bytes
,
bytes
.
length
);
int
n
=
subtitle
.
getEventTimeCount
();
int
n
=
subtitle
.
getEventTimeCount
();
assertEquals
(
462
,
n
);
assertEquals
(
924
,
n
);
// includes end events
assertTypicalCue1
(
subtitle
,
0
);
assertTypicalCue1
(
subtitle
,
0
);
assertTypicalCue2
(
subtitle
,
2
);
assertTypicalCue2
(
subtitle
,
2
);
assertTypicalCue3
(
subtitle
,
4
);
assertTypicalCue3
(
subtitle
,
4
);
assertTypicalCue4
(
subtitle
,
6
);
}
}
/*
/*
...
@@ -34,27 +38,35 @@ public class SSATests extends InstrumentationTestCase {
...
@@ -34,27 +38,35 @@ public class SSATests extends InstrumentationTestCase {
*/
*/
private
static
void
assertTypicalCue1
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
private
static
void
assertTypicalCue1
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
assertEquals
(
"0
0:00:04.230"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
)
)));
assertEquals
(
"0
:00:04.230"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
)));
assertEquals
(
"The prince should be with the princess."
,
assertEquals
(
"The prince should be with the princess."
,
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
assertEquals
(
"0
0:00:09.610"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
+
1
)
)));
assertEquals
(
"0
:00:06.900"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
+
1
)));
}
}
private
static
void
assertTypicalCue2
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
private
static
void
assertTypicalCue2
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
assertEquals
(
"0
0:00:33.010"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
)
)));
assertEquals
(
"0
:00:09.610"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
)));
assertEquals
(
"
Kiss Him, Not Me
"
,
assertEquals
(
"
Who was the one who decided that?
"
,
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
assertEquals
(
"0
0:01:48.870"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
+
1
)
)));
assertEquals
(
"0
:00:13.200"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
+
1
)));
}
}
private
static
void
assertTypicalCue3
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
private
static
void
assertTypicalCue3
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
String
s1
=
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
)));
assertEquals
(
"0:00:33.010"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
)));
String
s2
=
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
+
1
)));
assertEquals
(
"Kiss Him, Not Me"
,
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
assertEquals
(
"0:00:41.770"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
+
1
)));
}
private
static
void
assertTypicalCue4
(
SSASubtitle
subtitle
,
int
eventIndex
)
{
String
s1
=
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
));
String
s2
=
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
+
1
));
String
s3
=
String
s3
=
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
();
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
();
assertEquals
(
"0
0:01:59.610"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
)
)));
assertEquals
(
"0
:01:48.870"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
)));
assertEquals
(
"
Nice one, Igarashi!
"
,
assertEquals
(
"
Can She Do It? A Real Life Otome Game
"
,
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
subtitle
.
getCues
(
subtitle
.
getEventTime
(
eventIndex
)).
get
(
0
).
text
.
toString
());
assertEquals
(
"0
0:02:01.220"
,
sdf
.
format
(
new
java
.
util
.
Date
(
subtitle
.
getEventTime
(
eventIndex
+
1
)
)));
assertEquals
(
"0
:01:54.380"
,
SSADecoder
.
formatTimeCode
(
subtitle
.
getEventTime
(
eventIndex
+
1
)));
}
}
}
}
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java
View file @
ef2d7c7f
...
@@ -11,6 +11,8 @@ import java.util.HashMap;
...
@@ -11,6 +11,8 @@ import java.util.HashMap;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
static
android
.
R
.
attr
.
subtitle
;
/**
/**
* Created by cablej01 on 26/12/2016.
* Created by cablej01 on 26/12/2016.
*/
*/
...
@@ -59,7 +61,7 @@ import java.util.Map;
...
@@ -59,7 +61,7 @@ import java.util.Map;
public
class
SSADecoder
extends
SimpleSubtitleDecoder
{
public
class
SSADecoder
extends
SimpleSubtitleDecoder
{
private
static
final
String
TAG
=
"SSADecoder"
;
private
static
final
String
TAG
=
"SSADecoder"
;
private
static
String
defaultDialogueFormat
=
"Start, End,
,
Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
;
private
static
String
defaultDialogueFormat
=
"Start, End, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
;
private
static
String
defaultStyleFormat
=
"Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"
;
private
static
String
defaultStyleFormat
=
"Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"
;
private
String
[]
dialogueFormat
;
private
String
[]
dialogueFormat
;
private
String
[]
styleFormat
;
private
String
[]
styleFormat
;
...
@@ -99,21 +101,18 @@ public class SSADecoder extends SimpleSubtitleDecoder {
...
@@ -99,21 +101,18 @@ public class SSADecoder extends SimpleSubtitleDecoder {
decodeHeader
(
data
);
decodeHeader
(
data
);
String
currentLine
;
String
currentLine
;
while
((
currentLine
=
data
.
readLine
())
!=
null
)
{
while
((
currentLine
=
data
.
readLine
())
!=
null
)
{
while
(
true
)
{
if
(
currentLine
==
null
)
currentLine
=
data
.
readLine
();
break
;
if
(
currentLine
==
null
)
Log
.
i
(
TAG
,
currentLine
);
break
;
if
(!
currentLine
.
contains
(
":"
))
Log
.
i
(
TAG
,
currentLine
);
break
;
if
(!
currentLine
.
contains
(
":"
))
String
p
[]
=
currentLine
.
split
(
":"
,
2
);
break
;
if
(
p
[
0
].
equals
(
"Format"
))
{
String
p
[]
=
currentLine
.
split
(
":"
,
2
);
dialogueFormat
=
parseKeys
(
p
[
1
]);
if
(
p
[
0
].
equals
(
"Format"
))
{
}
dialogueFormat
=
parseKeys
(
p
[
1
]);
else
if
(
p
[
0
].
equals
(
"Dialogue"
))
{
}
Map
<
String
,
String
>
ev
=
parseLine
(
dialogueFormat
,
p
[
1
].
trim
());
else
if
(
p
[
0
].
equals
(
"Dialogue"
))
{
subtitle
.
addEvent
(
ev
,
styles
);
Map
<
String
,
String
>
ev
=
parseLine
(
dialogueFormat
,
p
[
1
].
trim
());
subtitle
.
addEvent
(
ev
,
styles
);
}
}
}
}
}
return
subtitle
;
return
subtitle
;
...
@@ -176,7 +175,7 @@ public class SSADecoder extends SimpleSubtitleDecoder {
...
@@ -176,7 +175,7 @@ public class SSADecoder extends SimpleSubtitleDecoder {
public
static
Map
<
String
,
String
>
parseLine
(
String
[]
keys
,
String
event
)
{
public
static
Map
<
String
,
String
>
parseLine
(
String
[]
keys
,
String
event
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
Map
<
String
,
String
>
result
=
new
HashMap
<>();
String
fields
[]
=
event
.
split
(
", *"
,
keys
.
length
);
String
fields
[]
=
event
.
split
(
", *"
,
keys
.
length
);
for
(
int
i
=
0
;
i
<
key
s
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
field
s
.
length
;
i
++)
{
String
k
=
keys
[
i
];
String
k
=
keys
[
i
];
String
v
=
fields
[
i
].
trim
();
String
v
=
fields
[
i
].
trim
();
result
.
put
(
k
,
v
);
result
.
put
(
k
,
v
);
...
...
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java
View file @
ef2d7c7f
...
@@ -61,10 +61,18 @@ public class SSASubtitle implements Subtitle {
...
@@ -61,10 +61,18 @@ public class SSASubtitle implements Subtitle {
}
}
protected
void
addEvent
(
Map
<
String
,
String
>
ev
,
Map
<
String
,
Style
>
styles
)
{
protected
void
addEvent
(
Map
<
String
,
String
>
ev
,
Map
<
String
,
Style
>
styles
)
{
// int readOrder = Integer.parseInt(ev.get("readorder")); ? not needed
int
marginL
=
0
;
int
marginL
=
Integer
.
parseInt
(
ev
.
get
(
"marginl"
));
String
m
=
ev
.
get
(
"marginl"
);
int
marginR
=
Integer
.
parseInt
(
ev
.
get
(
"marginr"
));
if
(!
m
.
equals
(
""
))
int
marginV
=
Integer
.
parseInt
(
ev
.
get
(
"marginv"
));
marginL
=
Integer
.
parseInt
(
m
);
int
marginR
=
0
;
m
=
ev
.
get
(
"marginr"
);
if
(!
m
.
equals
(
""
))
marginR
=
Integer
.
parseInt
(
m
);
int
marginV
=
0
;
m
=
ev
.
get
(
"marginv"
);
if
(!
m
.
equals
(
""
))
marginV
=
Integer
.
parseInt
(
m
);
String
styleName
=
ev
.
get
(
"style"
);
String
styleName
=
ev
.
get
(
"style"
);
Style
style
=
styles
.
get
(
styleName
);
Style
style
=
styles
.
get
(
styleName
);
if
(
marginL
!=
0
||
marginR
!=
0
||
marginV
!=
0
)
{
if
(
marginL
!=
0
||
marginR
!=
0
||
marginV
!=
0
)
{
...
...
library/src/main/java/com/google/android/exoplayer2/text/ssa/Style.java
View file @
ef2d7c7f
...
@@ -2,6 +2,8 @@ package com.google.android.exoplayer2.text.ssa;
...
@@ -2,6 +2,8 @@ package com.google.android.exoplayer2.text.ssa;
import
java.util.Map
;
import
java.util.Map
;
import
static
android
.
R
.
attr
.
angle
;
/**
/**
* Created by cablej01 on 27/12/2016.
* Created by cablej01 on 27/12/2016.
*/
*/
...
@@ -12,9 +14,11 @@ public class Style {
...
@@ -12,9 +14,11 @@ public class Style {
private
int
fontSize
;
private
int
fontSize
;
private
int
primaryColour
,
secondaryColour
,
outlineColour
,
backColour
;
private
int
primaryColour
,
secondaryColour
,
outlineColour
,
backColour
;
private
boolean
bold
,
italic
,
underline
,
strikeOut
;
private
boolean
bold
,
italic
,
underline
,
strikeOut
;
private
int
scaleX
,
scaleY
,
spacing
,
angle
;
private
int
scaleX
,
scaleY
,
spacing
;
private
float
angle
;
private
int
borderStyle
;
private
int
borderStyle
;
private
int
outline
,
shadow
,
alignment
,
marginL
,
marginR
,
marginV
;
private
float
outline
;
private
int
shadow
,
alignment
,
marginL
,
marginR
,
marginV
;
private
int
alphaLevel
=
0
;
private
int
alphaLevel
=
0
;
private
int
encoding
;
private
int
encoding
;
...
@@ -30,16 +34,16 @@ public class Style {
...
@@ -30,16 +34,16 @@ public class Style {
secondaryColour
=
parseColour
(
init
.
get
(
"secondarycolour"
));
secondaryColour
=
parseColour
(
init
.
get
(
"secondarycolour"
));
outlineColour
=
parseColour
(
init
.
get
(
"outlinecolour"
));
outlineColour
=
parseColour
(
init
.
get
(
"outlinecolour"
));
backColour
=
parseColour
(
init
.
get
(
"backcolour"
));
backColour
=
parseColour
(
init
.
get
(
"backcolour"
));
bold
=
init
.
get
(
"bold"
).
equals
(
"0"
)?
false
:
true
;
bold
=
!
init
.
get
(
"bold"
).
equals
(
"0"
)
;
italic
=
init
.
get
(
"italic"
).
equals
(
"0"
)?
false
:
true
;
italic
=
!
init
.
get
(
"italic"
).
equals
(
"0"
)
;
underline
=
init
.
get
(
"underline"
).
equals
(
"0"
)?
false
:
true
;
underline
=
!
init
.
get
(
"underline"
).
equals
(
"0"
)
;
strikeOut
=
init
.
get
(
"strikeout"
).
equals
(
"0"
)?
false
:
true
;
strikeOut
=
!
init
.
get
(
"strikeout"
).
equals
(
"0"
)
;
scaleX
=
Integer
.
parseInt
(
init
.
get
(
"scalex"
));
scaleX
=
Integer
.
parseInt
(
init
.
get
(
"scalex"
));
scaleY
=
Integer
.
parseInt
(
init
.
get
(
"scaley"
));
scaleY
=
Integer
.
parseInt
(
init
.
get
(
"scaley"
));
spacing
=
Integer
.
parseInt
(
init
.
get
(
"spacing"
));
spacing
=
Integer
.
parseInt
(
init
.
get
(
"spacing"
));
angle
=
Integer
.
parseIn
t
(
init
.
get
(
"angle"
));
angle
=
Float
.
parseFloa
t
(
init
.
get
(
"angle"
));
borderStyle
=
Integer
.
parseInt
(
init
.
get
(
"borderstyle"
));
borderStyle
=
Integer
.
parseInt
(
init
.
get
(
"borderstyle"
));
outline
=
Integer
.
parseIn
t
(
init
.
get
(
"outline"
));
outline
=
Float
.
parseFloa
t
(
init
.
get
(
"outline"
));
shadow
=
Integer
.
parseInt
(
init
.
get
(
"shadow"
));
shadow
=
Integer
.
parseInt
(
init
.
get
(
"shadow"
));
alignment
=
Integer
.
parseInt
(
init
.
get
(
"alignment"
));
alignment
=
Integer
.
parseInt
(
init
.
get
(
"alignment"
));
marginL
=
Integer
.
parseInt
(
init
.
get
(
"marginl"
));
marginL
=
Integer
.
parseInt
(
init
.
get
(
"marginl"
));
...
@@ -197,11 +201,11 @@ public class Style {
...
@@ -197,11 +201,11 @@ public class Style {
this
.
spacing
=
spacing
;
this
.
spacing
=
spacing
;
}
}
public
in
t
getAngle
()
{
public
floa
t
getAngle
()
{
return
angle
;
return
angle
;
}
}
public
void
setAngle
(
in
t
angle
)
{
public
void
setAngle
(
floa
t
angle
)
{
this
.
angle
=
angle
;
this
.
angle
=
angle
;
}
}
...
@@ -213,11 +217,11 @@ public class Style {
...
@@ -213,11 +217,11 @@ public class Style {
this
.
borderStyle
=
borderStyle
;
this
.
borderStyle
=
borderStyle
;
}
}
public
in
t
getOutline
()
{
public
floa
t
getOutline
()
{
return
outline
;
return
outline
;
}
}
public
void
setOutline
(
in
t
outline
)
{
public
void
setOutline
(
floa
t
outline
)
{
this
.
outline
=
outline
;
this
.
outline
=
outline
;
}
}
...
...
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