forked from bytedance/xgplayer
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bytedance#229 from yqjiang/refactor-live-loaderbuffer
Refactor live loaderbuffer
- Loading branch information
Showing
32 changed files
with
1,545 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.