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
98de7c46
authored
Feb 18, 2020
by
Pierre-Hugues Husson
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
[AitDecoder] Move to ParsableBitArray
parent
28c5043d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
43 deletions
library/core/src/main/java/com/google/android/exoplayer2/metadata/dvbsi/AitDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/metadata/dvbsi/AitDecoder.java
View file @
98de7c46
...
...
@@ -3,16 +3,20 @@ package com.google.android.exoplayer2.metadata.dvbsi;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.MetadataDecoder
;
import
com.google.android.exoplayer2.metadata.MetadataInputBuffer
;
import
com.google.android.exoplayer2.util.ParsableBitArray
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
com.google.android.exoplayer2.util.TimestampAdjuster
;
import
java.nio.ByteBuffer
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
// Unless mentioned explicitly, every references here are to
// https://www.etsi.org/deliver/etsi_ts/102800_102899/102809/01.01.01_60/ts_102809v010101p.pdf
public
class
AitDecoder
implements
MetadataDecoder
{
// Specification of AIT can be found in 5.3.4 of TS 102 809 v1.1.1
// https://www.etsi.org/deliver/etsi_ts/102800_102899/102809/01.01.01_60/ts_102809v010101p.pdf
private
final
static
int
DESCRIPTOR_TRANSPORT_PROTOCOL
=
0x02
;
private
final
static
int
DESCRIPTOR_SIMPLE_APPLICATION_LOCATION
=
0x15
;
...
...
@@ -21,10 +25,10 @@ public class AitDecoder implements MetadataDecoder {
private
TimestampAdjuster
timestampAdjuster
;
private
final
ParsableB
yte
Array
sectionData
;
private
final
ParsableB
it
Array
sectionData
;
public
AitDecoder
()
{
sectionData
=
new
ParsableB
yte
Array
();
sectionData
=
new
ParsableB
it
Array
();
}
@Override
...
...
@@ -40,8 +44,7 @@ public class AitDecoder implements MetadataDecoder {
int
size
=
buffer
.
limit
();
sectionData
.
reset
(
data
,
size
);
int
tableId
=
sectionData
.
peekUnsignedByte
();
int
tableId
=
sectionData
.
data
[
0
];
//Only this table is allowed in AIT streams
if
(
tableId
==
0x74
)
{
return
parseAit
(
sectionData
);
...
...
@@ -50,80 +53,92 @@ public class AitDecoder implements MetadataDecoder {
return
new
Metadata
();
}
private
Metadata
parseAit
(
ParsableByteArray
sectionData
)
{
int
tmp
;
int
tableId
=
sectionData
.
readUnsignedByte
();
private
Metadata
parseAit
(
ParsableBitArray
sectionData
)
{
//tableId
sectionData
.
skipBits
(
8
);
tmp
=
sectionData
.
readUnsignedShort
();
int
endOfSection
=
sectionData
.
getPosition
()
+
(
tmp
&
4095
)
-
4
/* Ignore leading CRC */
;
//section_syntax_indication | reserved_future_use | reserved
sectionData
.
skipBits
(
4
);
int
sectionLength
=
sectionData
.
readBits
(
12
);
int
endOfSection
=
sectionData
.
getBytePosition
()
+
sectionLength
-
4
/* Ignore leading CRC */
;
tmp
=
sectionData
.
readUnsignedShort
();
int
applicationType
=
tmp
&
0x7fff
;
// test_application_flag | application_type
sectionData
.
skipBits
(
16
)
;
tmp
=
sectionData
.
readUnsignedByte
();
int
versionNumber
=
(
tmp
&
0x3e
)
>>
1
;
boolean
current
=
(
tmp
&
1
)
==
1
;
// reserved | version_number | current_next_indicator
sectionData
.
skipBits
(
8
);
int
section_number
=
sectionData
.
readUnsignedByte
();
int
last_section_number
=
sectionData
.
readUnsignedByte
();
// section_number
sectionData
.
skipBits
(
8
);
// last_section_number
sectionData
.
skipBits
(
8
);
tmp
=
sectionData
.
readUnsignedShort
();
int
commonDescriptorsLength
=
tmp
&
4095
;
// reserved_future_use
sectionData
.
skipBits
(
4
);
int
commonDescriptorsLength
=
sectionData
.
readBits
(
12
);
//Since we currently only keep url and control code, which are unique per application,
//there is no useful information in common descriptor.
sectionData
.
skipBytes
(
commonDescriptorsLength
);
tmp
=
sectionData
.
readUnsignedShort
();
int
appLoopLength
=
tmp
&
4095
;
// reserved_future_use | application_loop_length
sectionData
.
skipBits
(
16
)
;
ArrayList
<
Ait
>
aits
=
new
ArrayList
<>();
while
(
sectionData
.
getPosition
()
<
endOfSection
)
{
while
(
sectionData
.
get
Byte
Position
()
<
endOfSection
)
{
// Values that will be stored in Ait()
String
aitUrlBase
=
null
;
String
aitUrlExtension
=
null
;
int
aitControlCode
=
-
1
;
long
application_identifier
=
sectionData
.
readUnsignedInt24
()
<<
24L
;
application_identifier
|=
sectionData
.
readUnsignedInt24
(
);
int
controlCode
=
sectionData
.
read
UnsignedByte
(
);
// application_identifier
sectionData
.
skipBits
(
48
);
int
controlCode
=
sectionData
.
read
Bits
(
8
);
aitControlCode
=
controlCode
;
tmp
=
sectionData
.
readUnsignedShort
();
int
sectionLength
=
tmp
&
4095
;
int
positionOfNextSection
=
sectionData
.
getPosition
()
+
sectionLength
;
while
(
sectionData
.
getPosition
()
<
positionOfNextSection
)
{
int
type
=
sectionData
.
readUnsignedByte
();
int
l
=
sectionData
.
readUnsignedByte
();
int
positionOfNextSection2
=
sectionData
.
getPosition
()
+
l
;
// reserved_future_use
sectionData
.
skipBits
(
4
);
int
applicationDescriptorsLoopLength
=
sectionData
.
readBits
(
12
);
int
positionOfNextSection
=
sectionData
.
getBytePosition
()
+
applicationDescriptorsLoopLength
;
while
(
sectionData
.
getBytePosition
()
<
positionOfNextSection
)
{
int
type
=
sectionData
.
readBits
(
8
);
int
l
=
sectionData
.
readBits
(
8
);
int
positionOfNextSection2
=
sectionData
.
getBytePosition
()
+
l
;
if
(
type
==
DESCRIPTOR_TRANSPORT_PROTOCOL
)
{
int
protocolId
=
sectionData
.
readUnsignedShort
();
int
label
=
sectionData
.
readUnsignedByte
();
// See section 5.3.6
int
protocolId
=
sectionData
.
readBits
(
16
);
// label
sectionData
.
skipBits
(
8
);
if
(
protocolId
==
TRANSPORT_PROTOCOL_HTTP
)
{
while
(
sectionData
.
getPosition
()
<
positionOfNextSection2
)
{
int
urlBaseLength
=
sectionData
.
readUnsignedByte
();
String
urlBase
=
sectionData
.
readString
(
urlBaseLength
);
int
extensionCount
=
sectionData
.
readUnsignedByte
();
while
(
sectionData
.
getBytePosition
()
<
positionOfNextSection2
)
{
int
urlBaseLength
=
sectionData
.
readBits
(
8
);
byte
[]
urlBaseByteArray
=
new
byte
[
urlBaseLength
];
sectionData
.
readBytes
(
urlBaseByteArray
,
0
,
urlBaseLength
);
String
urlBase
=
new
String
(
urlBaseByteArray
,
Charset
.
forName
(
"ASCII"
));
int
extensionCount
=
sectionData
.
readBits
(
8
);
aitUrlBase
=
urlBase
;
for
(
int
i
=
0
;
i
<
extensionCount
;
i
++)
{
int
len
=
sectionData
.
read
UnsignedByte
(
);
int
len
=
sectionData
.
read
Bits
(
8
);
sectionData
.
skipBytes
(
len
);
}
}
}
}
else
if
(
type
==
DESCRIPTOR_SIMPLE_APPLICATION_LOCATION
)
{
String
url
=
sectionData
.
readString
(
l
);
byte
[]
urlByteArray
=
new
byte
[
l
];
sectionData
.
readBytes
(
urlByteArray
,
0
,
l
);
String
url
=
new
String
(
urlByteArray
,
Charset
.
forName
(
"ASCII"
));
aitUrlExtension
=
url
;
}
sectionData
.
setPosition
(
positionOfNextSection2
);
sectionData
.
setPosition
(
positionOfNextSection2
*
8
);
}
sectionData
.
setPosition
(
positionOfNextSection
);
sectionData
.
setPosition
(
positionOfNextSection
*
8
);
if
(
aitControlCode
!=
-
1
&&
aitUrlBase
!=
null
&&
aitUrlExtension
!=
null
)
{
aits
.
add
(
new
Ait
(
aitControlCode
,
aitUrlBase
+
aitUrlExtension
));
...
...
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