Commit c093cac3 authored by Brendan Long's avatar Brendan Long

Use mpegtssections-js for parsing DataCues.

parent 86634634
[submodule "mpegtssections-js"]
path = mpegtssections-js
url = https://github.com/cablelabs/mpegtssections-js.git
......@@ -11,6 +11,8 @@
background-color:#000;
}
</style>
<script src="mpegtssections-js/lib/mpegtssections.js"></script>
<script src="stringview.js"></script>
<script>
/* Set this to read the config from a file. Note that the same-origin policy
......@@ -95,40 +97,6 @@ var config = {
width: 640
};
function parsePMTCue(cue) {
var view = new DataView(cue.data);
var parsed = {
table_id: view.getUint8(0),
section_syntax_indicator: (view.getUint8(1) & parseInt('80', 16)) >> 7,
section_length: view.getUint16(1) & parseInt('FFF', 16),
program_number: view.getUint16(3),
version_number: (view.getUint8(5) & parseInt('3E', 16)) >> 1,
current_next_indicator: view.getUint8(5) & 1,
section_number: view.getUint8(6),
last_section_number: view.getUint8(7),
PCR_PID: view.getUint16(8) & parseInt('1FFF', 16),
program_info_length: view.getUint16(10) & parseInt('FFF', 16),
streams: [],
CRC: view.getUint32(cue.data.byteLength - 4),
};
// todo: handle descriptors
var stream_start = 12 + parsed.program_info_length;
var streams_end = cue.data.byteLength - 4 - 5;
var i = 0;
while (stream_start <= streams_end) {
parsed.streams[i] = {
stream_type: view.getUint8(stream_start),
elementary_PID: view.getUint16(stream_start + 1) & parseInt('1FFF', 16),
ES_info_length: view.getUint16(stream_start + 3) & parseInt('FFF', 16),
};
stream_start += 5 + parsed.streams[i].ES_info_length;
++i;
}
return parsed;
}
function listTracks(tracks, type) {
log("Listing " + tracks.length + " " + type + " tracks.");
for(var j = 0; j < tracks.length; ++j) {
......@@ -142,12 +110,18 @@ function flatten(obj) {
if (obj instanceof Object) {
var result = {};
for(var key in obj) {
if (obj instanceof DataCue && key == "track")
if (obj instanceof TextTrackCue && key == "track")
continue;
if (obj instanceof TextTrack && key == "inBandMetadataTrackDispatchType" && obj[key]) {
var data = new DataView(StringView.makeFromBase64(obj[key]).buffer);
result["decodedInBandMetadataTrackDispatchType"] = {
stream_type: "0x" + data.getUint8(0).toString(16)
};
}
result[key] = obj[key];
}
if (obj instanceof DataCue) {
result["data"] = parsePMTCue(obj);
if (obj instanceof DataCue && typeof MpegTs !== "undefined") {
result["data"] = MpegTs.decodeSection(obj.data);
} else if (obj instanceof TextTrack && obj.kind == "metadata" && obj.cues) {
result.cues = [];
for (var i = 0; i < obj.cues.length; ++i) {
......
Subproject commit 74ac0d956832f39254a876c2e432739cbee78b89
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment