Skip to content

Commit

Permalink
Merge pull request bytedance#229 from yqjiang/refactor-live-loaderbuffer
Browse files Browse the repository at this point in the history
Refactor live loaderbuffer
  • Loading branch information
leonardoFu authored Sep 22, 2019
2 parents d42f1ee + 0e55342 commit c897045
Show file tree
Hide file tree
Showing 32 changed files with 1,545 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
"parser": "babel-eslint",
"extends": "standard",
"rules": {
"semi": 2
"semi": 0
},
"overrides": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/xgplayer-buffer/browser/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/xgplayer-buffer/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/xgplayer-buffer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"name": "xgplayer-buffer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0"
Expand Down
27 changes: 25 additions & 2 deletions packages/xgplayer-flv-live/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Context from 'xgplayer-utils'
import FetchLoader from "xgplayer-loader-fetch";
import XgBuffer from "xgplayer-buffer";
import FlvDemuxer from 'xgplayer-flv/demux'
import FetchLoader from 'xgplayer-loader-fetch'

Expand All @@ -13,6 +14,28 @@ class FlvLiveController {
this._context.registry('FLV_DEMUXER', FlvDemuxer)
this._context.registry('FETCH_LOADER', FetchLoader)
}

_init() {
this._registry();
}

_registry() {
this._context.registry("LOADER", FetchLoader);
this._context.registry("LOADER_BUBBER", XgBuffer);
// TODO: this._context.registry("DEMUXER", FLVDE)

}

_initInstances() {
this._context.initInstance("LOADER", {buffer: "LOADER_BUFFER"});
this._context.initInstance("LOADER_BUBBER");
}

load(url, opts) {
let loader = this._context.getInstance("LOADER");
loader.load(url, opts);
}
}

export default FlvLiveController
export default FlvLiveController;

11 changes: 10 additions & 1 deletion packages/xgplayer-flv.js/browser/index.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion packages/xgplayer-flv.js/dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/xgplayer-hls-live/browser/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/xgplayer-hls-live/dist/index.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/xgplayer-hls-live/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "xgplayer-hls-live",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xgplayer-remux": "1.0.0",
"xgplayer-utils": "1.1.6-alpha.0"
}
}
67 changes: 67 additions & 0 deletions packages/xgplayer-hls-live/src/demuxer/m3u8parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Reference: https://tools.ietf.org/html/rfc8216#section-4.3
*/

// TODO: Support More
class M3U8Parser {
static parse (text, baseurl = '') {
let ret = {
duration: 0
};
let refs = text.split(/\r|\n/);
let ref = refs.shift()
if (!ref.match('#EXTM3U')) {
// TODO:M3U格式错误。
return null;
}
ref = refs.shift()
while (ref !== undefined) {
let refm = ref.match(/#(.*):(.*)/);
if (refm && refm.length > 2) {
switch (refm[1]) {
case 'EXT-X-VERSION':
ret.version = parseInt(refm[2]);
break;
case 'EXT-X-MEDIA-SEQUENCE':
ret.sequence = parseInt(refm[2]);
break;
case 'EXT-X-TARGETDURATION':
ret.targetduration = parseFloat(refm[2]);
break;
case 'EXTINF':
if (!ret.frags) {
ret.frags = []
}
let freg = {
start: ret.duration,
duration: parseFloat(refm[2]) * 1000
}
ret.duration += freg.duration;
freg.url = baseurl + refs.shift();
ret.frags.push(freg);
break;
default:
break;
}
}
ref = refs.shift()
}
return ret;
}

static parseURL (url) {
let baseurl = '';
let urls = url.match(/(.*\/).*\.m3u8$/);
if (urls && urls.length > 0) {
for (let i = 0; i < urls.length; i++) {
if (urls[i].match(/.*\/$/g) && urls[i].length > baseurl.length) {
baseurl = urls[i];
}
}
}

return baseurl;
}
}

export default M3U8Parser;
Loading

0 comments on commit c897045

Please sign in to comment.