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
5d1c84ce
authored
Feb 28, 2018
by
Sven Wischnowsky
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
support zlib compressed PGS subtitles
parent
aa570621
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java
View file @
5d1c84ce
...
...
@@ -25,6 +25,10 @@ import com.google.android.exoplayer2.util.Util;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.zip.InflaterInputStream
;
/** A {@link SimpleSubtitleDecoder} for PGS subtitles. */
public
final
class
PgsDecoder
extends
SimpleSubtitleDecoder
{
...
...
@@ -34,18 +38,29 @@ public final class PgsDecoder extends SimpleSubtitleDecoder {
private
static
final
int
SECTION_TYPE_IDENTIFIER
=
0x16
;
private
static
final
int
SECTION_TYPE_END
=
0x80
;
private
static
final
int
INFLATE_HEADER
=
0x78
;
private
static
final
int
INFLATE_BUFFER_SIZE
=
5
;
private
final
ParsableByteArray
buffer
;
private
final
CueBuilder
cueBuilder
;
private
final
ByteArrayOutputStream
inflateBuffer
;
private
final
byte
[]
inflateReadBuffer
;
public
PgsDecoder
()
{
super
(
"PgsDecoder"
);
buffer
=
new
ParsableByteArray
();
cueBuilder
=
new
CueBuilder
();
inflateBuffer
=
new
ByteArrayOutputStream
();
inflateReadBuffer
=
new
byte
[
INFLATE_BUFFER_SIZE
];
}
@Override
protected
Subtitle
decode
(
byte
[]
data
,
int
size
,
boolean
reset
)
throws
SubtitleDecoderException
{
buffer
.
reset
(
data
,
size
);
byte
[]
inflated
=
tryInflateBuffer
(
data
,
size
);
if
(
inflated
==
null
)
buffer
.
reset
(
data
,
size
);
else
buffer
.
reset
(
inflated
,
inflated
.
length
);
cueBuilder
.
reset
();
ArrayList
<
Cue
>
cues
=
new
ArrayList
<>();
while
(
buffer
.
bytesLeft
()
>=
3
)
{
...
...
@@ -57,6 +72,25 @@ public final class PgsDecoder extends SimpleSubtitleDecoder {
return
new
PgsSubtitle
(
Collections
.
unmodifiableList
(
cues
));
}
private
byte
[]
tryInflateBuffer
(
byte
[]
data
,
int
size
)
{
if
(
size
>
0
&&
(((
int
)
data
[
0
])
&
0xff
)
!=
INFLATE_HEADER
)
return
null
;
inflateBuffer
.
reset
();
try
{
InflaterInputStream
iis
=
new
InflaterInputStream
(
new
ByteArrayInputStream
(
data
,
0
,
size
));
int
len
=
-
1
;
while
((
len
=
iis
.
read
(
inflateReadBuffer
))
!=
-
1
)
{
inflateBuffer
.
write
(
inflateReadBuffer
,
0
,
len
);
}
return
inflateBuffer
.
toByteArray
();
}
catch
(
IOException
e
)
{
}
return
null
;
}
private
static
Cue
readNextSection
(
ParsableByteArray
buffer
,
CueBuilder
cueBuilder
)
{
int
limit
=
buffer
.
limit
();
int
sectionType
=
buffer
.
readUnsignedByte
();
...
...
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