Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
videojs-contrib-hls
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
d94275ef
authored
2015-02-12 11:11:51 -0500
by
Ron Hopper
Committed by
David LaPalomento
2015-04-13 16:01:55 -0400
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
synchronize timestamp offsets between h.264 and AAC streams
1 parent
7add9298
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
31 deletions
src/aac-stream.js
src/h264-stream.js
src/segment-parser.js
test/h264-stream_test.js
src/aac-stream.js
View file @
d94275e
...
...
@@ -30,29 +30,25 @@ window.videojs.Hls.AacStream = function() {
this
.
tags
=
[];
// (pts:uint, pes_size:int, dataAligned:Boolean):void
this
.
setNextTimeStamp
=
function
(
pts
,
pes_size
,
dataAligned
)
{
// on the first invocation, capture the starting PTS value
// (pts:uint):void
this
.
setTimeStampOffset
=
function
(
pts
)
{
pts_offset
=
pts
;
// keep track of the last time a metadata tag was written out
// set the initial value so metadata will be generated before any
// payload data
lastMetaPts
=
pts
-
1000
;
};
// on subsequent invocations, calculate the PTS based on the starting offset
this
.
setNextTimeStamp
=
function
(
pts
,
pes_size
,
dataAligned
)
{
next_pts
=
pts
-
pts_offset
;
pes_length
=
pes_size
;
// If data is aligned, flush all internal buffers
if
(
dataAligned
)
{
state
=
0
;
}
};
// (pts:uint, pes_size:int, dataAligned:Boolean):void
this
.
setNextTimeStamp
=
function
(
pts
,
pes_size
,
dataAligned
)
{
next_pts
=
pts
-
pts_offset
;
pes_length
=
pes_size
;
this
.
setNextTimeStamp
(
pts
,
pes_size
,
dataAligned
);
// If data is aligned, flush all internal buffers
if
(
dataAligned
)
{
state
=
0
;
}
};
// (data:ByteArray, o:int = 0, l:int = 0):void
...
...
src/h264-stream.js
View file @
d94275e
...
...
@@ -258,24 +258,21 @@
this
.
tags
=
[];
//(pts:uint, dts:uint, dataAligned:Boolean):void
this
.
setNextTimeStamp
=
function
(
pts
,
dts
,
dataAligned
)
{
// on the first invocation, capture the starting PTS value
//(pts:uint):void
this
.
setTimeStampOffset
=
function
(
pts
)
{
pts_offset
=
pts
;
};
// on subsequent invocations, calculate the PTS based on the starting offset
this
.
setNextTimeStamp
=
function
(
pts
,
dts
,
dataAligned
)
{
// We could end up with a DTS less than 0 here. We need to deal with that!
next_pts
=
pts
-
pts_offset
;
next_dts
=
dts
-
pts_offset
;
// If data is aligned, flush all internal buffers
if
(
dataAligned
)
{
this
.
finishFrame
();
}
};
//(pts:uint, dts:uint, dataAligned:Boolean):void
this
.
setNextTimeStamp
=
function
(
pts
,
dts
,
dataAligned
)
{
// We could end up with a DTS less than 0 here. We need to deal with that!
next_pts
=
pts
-
pts_offset
;
next_dts
=
dts
-
pts_offset
;
this
.
setNextTimeStamp
(
pts
,
dts
,
dataAligned
);
// If data is aligned, flush all internal buffers
if
(
dataAligned
)
{
this
.
finishFrame
();
}
};
this
.
finishFrame
=
function
()
{
...
...
src/segment-parser.js
View file @
d94275e
...
...
@@ -19,7 +19,10 @@
streamBuffer
=
new
Uint8Array
(
MP2T_PACKET_LENGTH
),
streamBufferByteCount
=
0
,
h264Stream
=
new
H264Stream
(),
aacStream
=
new
AacStream
();
aacStream
=
new
AacStream
(),
h264HasTimeStampOffset
=
false
,
aacHasTimeStampOffset
=
false
,
timeStampOffset
;
// expose the stream metadata
self
.
stream
=
{
...
...
@@ -344,10 +347,24 @@
}
if
(
pid
===
self
.
stream
.
programMapTable
[
STREAM_TYPES
.
h264
])
{
if
(
!
h264HasTimeStampOffset
)
{
h264HasTimeStampOffset
=
true
;
if
(
timeStampOffset
===
undefined
)
{
timeStampOffset
=
pts
;
}
h264Stream
.
setTimeStampOffset
(
timeStampOffset
);
}
h264Stream
.
setNextTimeStamp
(
pts
,
dts
,
dataAlignmentIndicator
);
}
else
if
(
pid
===
self
.
stream
.
programMapTable
[
STREAM_TYPES
.
adts
])
{
if
(
!
aacHasTimeStampOffset
)
{
aacHasTimeStampOffset
=
true
;
if
(
timeStampOffset
===
undefined
)
{
timeStampOffset
=
pts
;
}
aacStream
.
setTimeStampOffset
(
timeStampOffset
);
}
aacStream
.
setNextTimeStamp
(
pts
,
pesPacketSize
,
dataAlignmentIndicator
);
...
...
test/h264-stream_test.js
View file @
d94275e
...
...
@@ -70,6 +70,7 @@ test('starting PTS values can be negative', function() {
nalUnitTypes
.
access_unit_delimiter_rbsp
]);
h264Stream
.
setTimeStampOffset
(
-
100
);
h264Stream
.
setNextTimeStamp
(
-
100
,
-
100
,
true
);
h264Stream
.
writeBytes
(
accessUnitDelimiter
,
0
,
accessUnitDelimiter
.
byteLength
);
h264Stream
.
setNextTimeStamp
(
-
99
,
-
99
,
true
);
...
...
Please
register
or
sign in
to post a comment