Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding cleaned up SEI frame-type 6 logic for 608/708 captions #334

Merged
merged 21 commits into from
Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/debug/flashls.swc
Binary file not shown.
Binary file modified bin/debug/flashlsOSMF.swc
Binary file not shown.
Binary file modified bin/release/flashls.swc
Binary file not shown.
Binary file modified bin/release/flashlsOSMF.swc
Binary file not shown.
Empty file modified examples/chromeless/index.html
100644 → 100755
Empty file.
Empty file modified examples/chromeless/metrics.html
100644 → 100755
Empty file.
101 changes: 101 additions & 0 deletions src/org/mangui/hls/demux/TSDemuxer.as
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package org.mangui.hls.demux {
import flash.utils.Timer;
import org.mangui.hls.flv.FLVTag;
import org.mangui.hls.model.AudioTrack;
import by.blooddy.crypto.Base64;

CONFIG::LOGGING {
import org.mangui.hls.utils.Log;
Expand Down Expand Up @@ -496,6 +497,106 @@ package org.mangui.hls.demux {
pes.data.position = frame.start;
pes.data.readBytes(pps, 0, frame.length);
ppsvect.push(pps);
} else if (frame.type == 6) {

// We already know it's 6, so skip first byte
pes.data.position = frame.start + 1;

// get the SEI payload type
var payload_type : uint = pes.data.readUnsignedByte();

if (payload_type == 4)
{
var payload_size : uint = 0;

do {
payload_size = pes.data.readUnsignedByte();
}
while(payload_size === 255)

var country_code : uint = pes.data.readUnsignedByte();

if (country_code == 181)
{
var provider_code : uint = pes.data.readUnsignedShort();

if (provider_code == 49)
{
var user_structure : uint = pes.data.readUnsignedInt();

if (user_structure == 0x47413934) // GA94
{
var user_data_type : uint = pes.data.readUnsignedByte();

// CEA-608 wrapped in 708 ( user_data_type == 4 is raw 608, not handled yet )
if (user_data_type == 3)
{
// cc -- the first 8 bits are 1-Boolean-0 and the 5 bits for the number of CCs
var byte:uint = pes.data.readUnsignedByte();

// get the total number of cc_datas
var total:uint = 31 & byte;
var count:uint = 0;

// supposedly a flag to process the cc_datas or not
// isn't working for me, so i don't use it yet
var process:Boolean = !((64 & byte) == 0);

var size:uint = total * 3;

// em_data, do we need? It's not used for anything, but it's there, so i need to pull it out
var otherByte:uint = pes.data.readUnsignedByte();

if (pes.data.bytesAvailable >= size)
{
// ByteArray for onCaptionInfo event
var sei : ByteArray = new ByteArray();

// onCaptionInfo payloads need to know the size of the binary data
// there's two two bytes we just read, plus the cc_datas, which are 3 bytes each
sei.writeUnsignedInt(2+3*total);

// write those two bytes
sei.writeByte(byte);
sei.writeByte(otherByte);

// write the cc_datas
pes.data.readBytes(sei, 6, 3*total);

pes.data.position -= total * 3;

// onCaptionInfo expects Base64 data...
var sei_data:String = Base64.encode(sei);

var cc_data:Object = {
type: "708",
data: sei_data
};

// add a new FLVTag with the onCaptionInfo call
var tag:FLVTag = new FLVTag(FLVTag.METADATA, pes.pts, pes.pts, false);

var data : ByteArray = new ByteArray();
data.objectEncoding = ObjectEncoding.AMF0;
data.writeObject("onCaptionInfo");
data.objectEncoding = ObjectEncoding.AMF3;
data.writeByte(0x11);
data.writeObject(cc_data);
tag.push(data, 0, data.length);

_tags.push(tag);
}
else
{
CONFIG::LOGGING {
Log.info("not enough bytes!");
}
}
}
}
}
}
}
}
}
// if both SPS and PPS have been found, build AVCC and push tag if needed
Expand Down
8 changes: 5 additions & 3 deletions src/org/mangui/hls/stream/StreamBuffer.as
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,13 @@ package org.mangui.hls.stream {
if(headerAppended) {
_headerTags = _headerTags.sort(compareTags);
}
if(metaAppended) {
_metaTags = _metaTags.sort(compareTags);
}
}

if(metaAppended) {
_metaTags = _metaTags.sort(compareTags);
}


if (_hls.seekState == HLSSeekStates.SEEKING) {
/* if in seeking mode, force timer start here, this could help reducing the seek time by 100ms */
_timer.start();
Expand Down