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
937675d1
authored
Mar 23, 2017
by
Sergio Moreno Mozota
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add DVB sustitles support to the TsExtractor
parent
d8f61ad7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
0 deletions
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DvbSubtitlesReader.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/TsExtractor.java
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DefaultTsPayloadReaderFactory.java
View file @
937675d1
...
...
@@ -109,6 +109,8 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
?
null
:
new
SectionReader
(
new
SpliceInfoSectionReader
());
case
TsExtractor
.
TS_STREAM_TYPE_ID3
:
return
new
PesReader
(
new
Id3Reader
());
case
TsExtractor
.
TS_STREAM_TYPE_DVBSUBS
:
return
new
PesReader
(
new
DvbSubtitlesReader
(
esInfo
));
default
:
return
null
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/DvbSubtitlesReader.java
0 → 100644
View file @
937675d1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
ts
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.extractor.ExtractorOutput
;
import
com.google.android.exoplayer2.extractor.TrackOutput
;
import
com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DvbSubtitlesReader
implements
ElementaryStreamReader
{
private
static
final
String
TAG
=
"DVBSubsReader"
;
private
final
String
language
;
private
List
<
byte
[]>
initializationData
=
new
ArrayList
<>();
private
long
sampleTimeUs
;
private
int
totalBytesWritten
;
private
boolean
writingSample
;
private
TrackOutput
output
;
public
DvbSubtitlesReader
(
TsPayloadReader
.
EsInfo
esInfo
)
{
// we only support one subtitle service per PID
this
.
language
=
esInfo
.
language
;
this
.
initializationData
.
add
(
new
byte
[]
{
esInfo
.
descriptorBytes
[
5
]});
// subtitle subtype
this
.
initializationData
.
add
(
new
byte
[]
{
esInfo
.
descriptorBytes
[
6
],
esInfo
.
descriptorBytes
[
7
]});
// subtitle compose page
this
.
initializationData
.
add
(
new
byte
[]
{
esInfo
.
descriptorBytes
[
8
],
esInfo
.
descriptorBytes
[
9
]});
// subtitle ancillary page
this
.
initializationData
.
add
(
"mp2t"
.
getBytes
());
}
@Override
public
void
seek
()
{
writingSample
=
false
;
}
@Override
public
void
createTracks
(
ExtractorOutput
extractorOutput
,
TrackIdGenerator
idGenerator
)
{
idGenerator
.
generateNewId
();
this
.
output
=
extractorOutput
.
track
(
idGenerator
.
getTrackId
(),
C
.
TRACK_TYPE_TEXT
);
output
.
format
(
Format
.
createImageSampleFormat
(
idGenerator
.
getFormatId
(),
MimeTypes
.
APPLICATION_DVBSUBS
,
null
,
Format
.
NO_VALUE
,
initializationData
,
language
,
null
));
}
@Override
public
void
packetStarted
(
long
pesTimeUs
,
boolean
dataAlignmentIndicator
)
{
if
(!
dataAlignmentIndicator
)
{
return
;
}
writingSample
=
true
;
sampleTimeUs
=
pesTimeUs
;
totalBytesWritten
=
0
;
}
@Override
public
void
packetFinished
()
{
output
.
sampleMetadata
(
sampleTimeUs
,
C
.
BUFFER_FLAG_KEY_FRAME
,
totalBytesWritten
,
0
,
null
);
writingSample
=
false
;
}
@Override
public
void
consume
(
ParsableByteArray
data
)
{
if
(
writingSample
)
{
totalBytesWritten
+=
data
.
bytesLeft
();
output
.
sampleData
(
data
,
data
.
bytesLeft
());
}
}
}
\ No newline at end of file
library/core/src/main/java/com/google/android/exoplayer2/extractor/ts/TsExtractor.java
View file @
937675d1
...
...
@@ -92,6 +92,7 @@ public final class TsExtractor implements Extractor {
public
static
final
int
TS_STREAM_TYPE_H265
=
0x24
;
public
static
final
int
TS_STREAM_TYPE_ID3
=
0x15
;
public
static
final
int
TS_STREAM_TYPE_SPLICE_INFO
=
0x86
;
public
static
final
int
TS_STREAM_TYPE_DVBSUBS
=
0x59
;
private
static
final
int
TS_PACKET_SIZE
=
188
;
private
static
final
int
TS_SYNC_BYTE
=
0x47
;
// First byte of each TS packet.
...
...
@@ -356,6 +357,7 @@ public final class TsExtractor implements Extractor {
private
static
final
int
TS_PMT_DESC_AC3
=
0x6A
;
private
static
final
int
TS_PMT_DESC_EAC3
=
0x7A
;
private
static
final
int
TS_PMT_DESC_DTS
=
0x7B
;
private
static
final
int
TS_PMT_DESC_DVBSUBS
=
0x59
;
private
final
ParsableBitArray
pmtScratch
;
private
final
int
pid
;
...
...
@@ -498,6 +500,10 @@ public final class TsExtractor implements Extractor {
}
else
if
(
descriptorTag
==
TS_PMT_DESC_ISO639_LANG
)
{
language
=
new
String
(
data
.
data
,
data
.
getPosition
(),
3
).
trim
();
// Audio type is ignored.
}
else
if
(
descriptorTag
==
TS_PMT_DESC_DVBSUBS
)
{
streamType
=
TS_STREAM_TYPE_DVBSUBS
;
// we only support one subtitle service per PID
language
=
new
String
(
data
.
data
,
data
.
getPosition
(),
3
).
trim
();
}
// Skip unused bytes of current descriptor.
data
.
skipBytes
(
positionOfNextDescriptor
-
data
.
getPosition
());
...
...
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