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
55b4272a
authored
Nov 05, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Pro-actively parse the final PES packet.
parent
71f918c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
16 deletions
library/src/main/java/com/google/android/exoplayer/parser/ts/TsExtractor.java
library/src/main/java/com/google/android/exoplayer/parser/ts/TsExtractor.java
View file @
55b4272a
...
...
@@ -267,7 +267,9 @@ public final class TsExtractor {
* Parses payload data.
*/
private
abstract
static
class
TsPayloadReader
{
public
abstract
void
read
(
BitsArray
tsBuffer
,
boolean
payloadUnitStartIndicator
);
}
/**
...
...
@@ -389,33 +391,47 @@ public final class TsExtractor {
// Parses PES payload and extracts individual samples.
private
final
PesPayloadReader
pesPayloadReader
;
private
int
packetLength
;
public
PesReader
(
PesPayloadReader
pesPayloadReader
)
{
this
.
pesPayloadReader
=
pesPayloadReader
;
this
.
packetLength
=
-
1
;
pesBuffer
=
new
BitsArray
();
}
@Override
public
void
read
(
BitsArray
tsBuffer
,
boolean
payloadUnitStartIndicator
)
{
if
(
payloadUnitStartIndicator
&&
!
pesBuffer
.
isEmpty
())
{
readPES
();
// We've encountered the start of the next packet, but haven't yet read the body. Read it.
// Note that this should only happen if the packet length was unspecified.
Assertions
.
checkState
(
packetLength
==
0
);
readPacketBody
();
}
pesBuffer
.
append
(
tsBuffer
,
tsBuffer
.
bytesLeft
());
if
(
packetLength
==
-
1
&&
pesBuffer
.
bytesLeft
()
>=
6
)
{
// We haven't read the start of the packet, but have enough data to do so.
readPacketStart
();
}
if
(
packetLength
>
0
&&
pesBuffer
.
bytesLeft
()
>=
packetLength
)
{
// The packet length was specified and we now have the whole packet. Read it.
readPacketBody
();
}
}
/**
* Parses completed PES data.
*/
private
void
readPES
()
{
int
packetStartCodePrefix
=
pesBuffer
.
readBits
(
24
);
if
(
packetStartCodePrefix
!=
0x000001
)
{
private
void
readPacketStart
()
{
int
startCodePrefix
=
pesBuffer
.
readBits
(
24
);
if
(
startCodePrefix
!=
0x000001
)
{
// Error.
}
// TODO: Read and use stream_id.
// Skip stream_id.
pesBuffer
.
skipBits
(
8
);
int
pesPacketLength
=
pesBuffer
.
readBits
(
16
);
packetLength
=
pesBuffer
.
readBits
(
16
);
}
private
void
readPacketBody
()
{
// Skip some fields/flags.
// TODO: might need to use data_alignment_indicator.
pesBuffer
.
skipBits
(
8
);
// 2+2+1+1+1+1
...
...
@@ -425,9 +441,9 @@ public final class TsExtractor {
// Skip some fields/flags.
pesBuffer
.
skipBits
(
6
);
// 1+1+1+1+1+1
int
pesH
eaderDataLength
=
pesBuffer
.
readBits
(
8
);
if
(
pesH
eaderDataLength
==
0
)
{
pesH
eaderDataLength
=
pesBuffer
.
bytesLeft
();
int
h
eaderDataLength
=
pesBuffer
.
readBits
(
8
);
if
(
h
eaderDataLength
==
0
)
{
h
eaderDataLength
=
pesBuffer
.
bytesLeft
();
}
long
timeUs
=
0
;
...
...
@@ -442,22 +458,23 @@ public final class TsExtractor {
pesBuffer
.
skipBits
(
1
);
timeUs
=
pts
*
1000000
/
90000
;
// Skip the rest of the header.
pesBuffer
.
skipBytes
(
pesH
eaderDataLength
-
5
);
pesBuffer
.
skipBytes
(
h
eaderDataLength
-
5
);
}
else
{
// Skip the rest of the header.
pesBuffer
.
skipBytes
(
pesH
eaderDataLength
);
pesBuffer
.
skipBytes
(
h
eaderDataLength
);
}
int
payloadSize
;
if
(
p
esP
acketLength
==
0
)
{
if
(
packetLength
==
0
)
{
// If pesPacketLength is not specified read all available data.
payloadSize
=
pesBuffer
.
bytesLeft
();
}
else
{
payloadSize
=
p
esPacketLength
-
pesH
eaderDataLength
-
3
;
payloadSize
=
p
acketLength
-
h
eaderDataLength
-
3
;
}
pesPayloadReader
.
read
(
pesBuffer
,
payloadSize
,
timeUs
);
pesBuffer
.
reset
();
packetLength
=
-
1
;
}
}
...
...
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