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
b5912efb
authored
Apr 16, 2018
by
ojw28
Committed by
GitHub
Apr 16, 2018
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #3921 from wischnow/dev-v2
support zlib compressed PGS subtitles
parents
650f96fd
5d1c84ce
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 @
b5912efb
...
@@ -25,6 +25,10 @@ import com.google.android.exoplayer2.util.Util;
...
@@ -25,6 +25,10 @@ import com.google.android.exoplayer2.util.Util;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
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. */
/** A {@link SimpleSubtitleDecoder} for PGS subtitles. */
public
final
class
PgsDecoder
extends
SimpleSubtitleDecoder
{
public
final
class
PgsDecoder
extends
SimpleSubtitleDecoder
{
...
@@ -34,18 +38,29 @@ 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_IDENTIFIER
=
0x16
;
private
static
final
int
SECTION_TYPE_END
=
0x80
;
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
ParsableByteArray
buffer
;
private
final
CueBuilder
cueBuilder
;
private
final
CueBuilder
cueBuilder
;
private
final
ByteArrayOutputStream
inflateBuffer
;
private
final
byte
[]
inflateReadBuffer
;
public
PgsDecoder
()
{
public
PgsDecoder
()
{
super
(
"PgsDecoder"
);
super
(
"PgsDecoder"
);
buffer
=
new
ParsableByteArray
();
buffer
=
new
ParsableByteArray
();
cueBuilder
=
new
CueBuilder
();
cueBuilder
=
new
CueBuilder
();
inflateBuffer
=
new
ByteArrayOutputStream
();
inflateReadBuffer
=
new
byte
[
INFLATE_BUFFER_SIZE
];
}
}
@Override
@Override
protected
Subtitle
decode
(
byte
[]
data
,
int
size
,
boolean
reset
)
throws
SubtitleDecoderException
{
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
();
cueBuilder
.
reset
();
ArrayList
<
Cue
>
cues
=
new
ArrayList
<>();
ArrayList
<
Cue
>
cues
=
new
ArrayList
<>();
while
(
buffer
.
bytesLeft
()
>=
3
)
{
while
(
buffer
.
bytesLeft
()
>=
3
)
{
...
@@ -57,6 +72,25 @@ public final class PgsDecoder extends SimpleSubtitleDecoder {
...
@@ -57,6 +72,25 @@ public final class PgsDecoder extends SimpleSubtitleDecoder {
return
new
PgsSubtitle
(
Collections
.
unmodifiableList
(
cues
));
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
)
{
private
static
Cue
readNextSection
(
ParsableByteArray
buffer
,
CueBuilder
cueBuilder
)
{
int
limit
=
buffer
.
limit
();
int
limit
=
buffer
.
limit
();
int
sectionType
=
buffer
.
readUnsignedByte
();
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