Skip to content

Modules API

villainhr edited this page Feb 1, 2018 · 2 revisions

HTTPChunked

Construtor

[Constructor]
interface HTTPChunked(String url, Object config);


[Parameter] String url;

[Parameter] 
Object config{
    attribute Boolean withCredentials, true;
    attribute Number timeout, 0;
    attribute String cors, "cors";
}

Firstly, if your url is cross-origin, you can pass withCredentials and cors to indicate that is CORS request. The default parameters is CORS params.

let chunked = new HTTPChunked({
    withCredentials:true,
    cors:"cors",
});

Initialization

[Return]
interface HTTPChunked{
    void send(String url);
    void retry();
    void drop();
    EventListener on(event,fn);
    EventListener bind(event,fn);
    EventListener addEventListener(event,fn);
}

enum event{
    stream,
    chunk,
    end,
    error
}

When you want to connect live video url, just call send(url):

let chunked = new HTTPChunked({
    withCredentials:true,
    cors:"cors",
});

chunked.send('https://xxxxxxxflv');

But if you want to process the flv chunks, you can listen on stream and chunk Event.

chunked.on('chunk',(chunk)=>{
    // the raw data from the sever before been pared
});

chunked.on('stream',(stream,type)=>{
     // after been decoded, it will return stream[chunkArray] which has already been distinguished by `IS` and `MS`
});

chunked.send('https://xxxxxxxflv');

The callback constructor is:

[EventListener]
EventName chunk{
    attribute ArrayBuffer chunk
}

EventName stream{
    attribute Array stream;
    attribute String type;
}
  • type: indicates which type of this streamArray is. IS || MS
if type is 'IS':
    // the stream always contains video and audio
    stream = [
        {
            attribute ArrayBuffer buffer;
            attribute Object info:{
                // the following is for 'header'
                attribute String type;
                attribute String desc;
                attribute Number version;
                attribute Number tagOffset;
                attribute Boolean hasAudio;
                attribute Boolean hasVideo;

                // the following is for 'body'
                attribute Number dataOffset;
                attribute Number dataSize;
                attribute Number timeStamp;
                attribute Number tagLen;
            }
        },
        ...
    ]
else if type is 'MS'
    stream = [
        {
            attribute ArrayBuffer buffer;
            attribute Object info:{
                attribute String type;
                attribute String desc;
                attribute Number dataOffset;
                attribute Number dataSize;
                attribute Number timeStamp;
                attribute Number tagLen;
            }
        },
        ...
    ]

IS Stream Information

  • buffer: the raw chunk of this tag, like, script,header,audio,video.
  • info:
    • type: Indicates type of the tag, like: "header","video","audio","script".
    • desc: Distinguish these tags into MS and IS type. like: "header","body".
    • version: the flv format's version
    • tagOffset: Offset in bytes from start of file to start of body. Simply, it is the size of header
    • hasAudio: indicates whether or not audio is included.
    • hasVideo: indicates whether or not video is included.

The rest props are explain in MS Stream Information

MS Stream Information

  • buffer: the raw chunk of this tag.
  • info:
    • type: Indicates type of the tag, like: "header","video","audio","script".
    • desc: Distinguish these tags into MS and IS type. like: "header","body".
    • dataOffset: the raw VideoData/AudioData offset from the start of tag.
    • dataSize: the length of raw VideoData/AudioData
    • tagLen: the length of flv tag

MuxController

Constructor

[Constructor]
interface MuxController();

Initialization

[Return]
interface MuxController{
    Object parse(Array stream, String type);
}

you can get the stream and type params from HTTPChunked stream event.

  • type: indicates which type of stream is. like: IS,MS

When you call the parse function, it will return different result depending on your parameters.

if type is "IS":
    return {
        attribute ArrayBuffer videoIS;*
        attribute ArrayBuffer audioIS;*
        attribute Object mediaInfo;
        attribute String videoMime;*
        attribute String audioMime;*
    }
else if type is "MS":
    return {
        attribute ArrayBuffer audioMS;*
        attribute ArrayBuffer videoMS;*
        attribute Number videoTimebase;
        attribute Number audioTimebase;
        attribute Number diffTimebase;
        attribute Number videoTimeStamp;
        attribute Number audioTimeStamp;
    }

If you use custom module to replace MuxController, only these props followed by asterisk are necessary.

MSEController

Constructor

[Constructor]
interface MSEController(HTMLElement video,Object options);

[Parameter]
Object options{
    attribute Number    maxBufferTime, 60;
    attribute Number    trailedTime, 2;
    attribute Boolean   keepUpdated, true;
    attribute Number    playbackRate, 1.5;
}
  • video: The video element you want to bind with [MSE][4].
  • options: some params to control the MSE
    • maxBufferTime: the maximum playing time to remove timeRanges
    • keepUpdated: indicate to catch up time when the video time behind the ranges.end(0)
    • trailedTime: the maximum delay time of video behind the ranges.end(0), otherwise, the play will use fast forward to catch up live time.
    • playbackRate: the fast forward rate when to catch up time.

Initialization

[Return]
interface MSEController{
    SourceBuffer addSourceBuffer(String mime,String type);
}

[SourceBuffer]
Initialization sourceBuffer{
    void appendBuffer(buffer);
}
  • addSourceBuffer: MSE instantiates an sourceBuffer based on MIME.
  • appendBuffer: Receive IS and MS chunk.