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
3b4409ae
authored
Oct 09, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Allow relaxation of TTML validity requirement when parsing subtitles.
parent
d4e82463
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
12 deletions
library/src/main/java/com/google/android/exoplayer/ParserException.java
library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java
library/src/main/java/com/google/android/exoplayer/ParserException.java
View file @
3b4409ae
...
@@ -26,8 +26,12 @@ public class ParserException extends IOException {
...
@@ -26,8 +26,12 @@ public class ParserException extends IOException {
super
(
message
);
super
(
message
);
}
}
public
ParserException
(
Exception
cause
)
{
public
ParserException
(
Throwable
cause
)
{
super
(
cause
);
super
(
cause
);
}
}
public
ParserException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
}
library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java
View file @
3b4409ae
...
@@ -73,8 +73,23 @@ public class TtmlParser implements SubtitleParser {
...
@@ -73,8 +73,23 @@ public class TtmlParser implements SubtitleParser {
private
static
final
int
DEFAULT_TICKRATE
=
1
;
private
static
final
int
DEFAULT_TICKRATE
=
1
;
private
final
XmlPullParserFactory
xmlParserFactory
;
private
final
XmlPullParserFactory
xmlParserFactory
;
private
final
boolean
strictParsing
;
/**
* Equivalent to {@code TtmlParser(true)}.
*/
public
TtmlParser
()
{
public
TtmlParser
()
{
this
(
true
);
}
/**
* @param strictParsing If true, {@link #parse(InputStream, String, long)} will throw a
* {@link ParserException} if the stream contains invalid ttml. If false, the parser will
* make a best effort to ignore minor errors in the stream. Note however that a
* {@link ParserException} will still be thrown when this is not possible.
*/
public
TtmlParser
(
boolean
strictParsing
)
{
this
.
strictParsing
=
strictParsing
;
try
{
try
{
xmlParserFactory
=
XmlPullParserFactory
.
newInstance
();
xmlParserFactory
=
XmlPullParserFactory
.
newInstance
();
}
catch
(
XmlPullParserException
e
)
{
}
catch
(
XmlPullParserException
e
)
{
...
@@ -90,21 +105,31 @@ public class TtmlParser implements SubtitleParser {
...
@@ -90,21 +105,31 @@ public class TtmlParser implements SubtitleParser {
xmlParser
.
setInput
(
inputStream
,
inputEncoding
);
xmlParser
.
setInput
(
inputStream
,
inputEncoding
);
TtmlSubtitle
ttmlSubtitle
=
null
;
TtmlSubtitle
ttmlSubtitle
=
null
;
LinkedList
<
TtmlNode
>
nodeStack
=
new
LinkedList
<
TtmlNode
>();
LinkedList
<
TtmlNode
>
nodeStack
=
new
LinkedList
<
TtmlNode
>();
int
unsupported
Tag
Depth
=
0
;
int
unsupported
Node
Depth
=
0
;
int
eventType
=
xmlParser
.
getEventType
();
int
eventType
=
xmlParser
.
getEventType
();
while
(
eventType
!=
XmlPullParser
.
END_DOCUMENT
)
{
while
(
eventType
!=
XmlPullParser
.
END_DOCUMENT
)
{
TtmlNode
parent
=
nodeStack
.
peekLast
();
TtmlNode
parent
=
nodeStack
.
peekLast
();
if
(
unsupported
Tag
Depth
==
0
)
{
if
(
unsupported
Node
Depth
==
0
)
{
String
name
=
xmlParser
.
getName
();
String
name
=
xmlParser
.
getName
();
if
(
eventType
==
XmlPullParser
.
START_TAG
)
{
if
(
eventType
==
XmlPullParser
.
START_TAG
)
{
if
(!
isSupportedTag
(
name
))
{
if
(!
isSupportedTag
(
name
))
{
Log
.
w
(
TAG
,
"Ignoring unsupported tag: "
+
xmlParser
.
getName
());
Log
.
i
(
TAG
,
"Ignoring unsupported tag: "
+
xmlParser
.
getName
());
unsupported
Tag
Depth
++;
unsupported
Node
Depth
++;
}
else
{
}
else
{
TtmlNode
node
=
parseNode
(
xmlParser
,
parent
);
try
{
nodeStack
.
addLast
(
node
);
TtmlNode
node
=
parseNode
(
xmlParser
,
parent
);
if
(
parent
!=
null
)
{
nodeStack
.
addLast
(
node
);
parent
.
addChild
(
node
);
if
(
parent
!=
null
)
{
parent
.
addChild
(
node
);
}
}
catch
(
ParserException
e
)
{
if
(
strictParsing
)
{
throw
e
;
}
else
{
Log
.
e
(
TAG
,
"Suppressing parser error"
,
e
);
// Treat the node (and by extension, all of its children) as unsupported.
unsupportedNodeDepth
++;
}
}
}
}
}
}
else
if
(
eventType
==
XmlPullParser
.
TEXT
)
{
}
else
if
(
eventType
==
XmlPullParser
.
TEXT
)
{
...
@@ -117,9 +142,9 @@ public class TtmlParser implements SubtitleParser {
...
@@ -117,9 +142,9 @@ public class TtmlParser implements SubtitleParser {
}
}
}
else
{
}
else
{
if
(
eventType
==
XmlPullParser
.
START_TAG
)
{
if
(
eventType
==
XmlPullParser
.
START_TAG
)
{
unsupported
Tag
Depth
++;
unsupported
Node
Depth
++;
}
else
if
(
eventType
==
XmlPullParser
.
END_TAG
)
{
}
else
if
(
eventType
==
XmlPullParser
.
END_TAG
)
{
unsupported
Tag
Depth
--;
unsupported
Node
Depth
--;
}
}
}
}
xmlParser
.
next
();
xmlParser
.
next
();
...
@@ -127,7 +152,7 @@ public class TtmlParser implements SubtitleParser {
...
@@ -127,7 +152,7 @@ public class TtmlParser implements SubtitleParser {
}
}
return
ttmlSubtitle
;
return
ttmlSubtitle
;
}
catch
(
XmlPullParserException
xppe
)
{
}
catch
(
XmlPullParserException
xppe
)
{
throw
new
IO
Exception
(
"Unable to parse source"
,
xppe
);
throw
new
Parser
Exception
(
"Unable to parse source"
,
xppe
);
}
}
}
}
...
...
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