Skip to content

Commit

Permalink
Merge branch 'master' into feature/audio-track-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed May 14, 2018
2 parents afd6579 + b5cd012 commit 690ba79
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 65 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js: node
# Work-around for https://github.com/travis-ci/travis-ci/issues/8836#issuecomment-356362524.
# (Restore `sudo: false` once that is resolved.)
# so that chrome works
# see https://github.com/video-dev/hls.js/pull/1710#discussion_r187754754
sudo: required
# don't connect to sauce labs unless running functional tests
# before_install: if [ "${TRAVIS_MODE}" != "funcTests" ]; then unset SAUCE_USERNAME && unset SAUCE_ACCESS_KEY; fi
Expand All @@ -11,12 +11,19 @@ after_success: npm run coverage
env:
global:
- SAUCE_USERNAME=mangui
stages:
- required
- optional
jobs:
# stage: optional is allowed to be failure
fast_finish: true
allow_failures:
- stage: optional
include:
# publish canary package if on master
- stage: required
if: branch = master AND type != pull_request
env: TRAVIS_MODE=releaseCanary
# Required tests
- stage: required
env: TRAVIS_MODE=build
Expand All @@ -43,7 +50,6 @@ jobs:
# env: TRAVIS_MODE=funcTests UA=firefox OS="OS X 10.11"
- stage: optional
env: TRAVIS_MODE=funcTests UA=safari OS="OS X 10.11" UA_VERSION="9.0"

addons:
sauce_connect: true
jwt:
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/video-dev/hls.js.svg?branch=master)](https://travis-ci.org/video-dev/hls.js)
[![npm][npm-image]][npm-url]
[![npm](https://img.shields.io/npm/v/hls.js.svg?style=flat)](https://npmjs.org/package/hls.js)
[![npm](https://img.shields.io/npm/v/hls.js/canary.svg?style=flat)](https://www.npmjs.com/package/hls.js/v/canary)
[![Greenkeeper badge](https://badges.greenkeeper.io/video-dev/hls.js.svg)](https://greenkeeper.io/)
[![](https://data.jsdelivr.com/v1/package/npm/hls.js/badge?style=rounded)](https://www.jsdelivr.com/package/npm/hls.js)

Expand Down Expand Up @@ -39,6 +40,8 @@ hls.js is written in [ECMAScript6], and transpiled in ECMAScript5 using [Babel].

```html
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<!-- Or if you want a more recent canary version -->
<!-- <script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script> -->
<video id="video"></video>
<script>
var video = document.getElementById('video');
Expand Down Expand Up @@ -123,6 +126,10 @@ If you want to bundle the application yourself, use node
```
npm install hls.js
```
or for the version from master (canary)
```
npm install hls.js@canary
```

**NOTE:** `hls.light.*.js` dist files do not include subtitling and alternate-audio features.

Expand Down Expand Up @@ -254,6 +261,3 @@ Click [here](/docs/design.md) for details.
### Tested With

[<img src="https://cloud.githubusercontent.com/assets/7864462/12837037/452a17c6-cb73-11e5-9f39-fc96893bc9bf.png" alt="Browser Stack Logo" width="300">](https://www.browserstack.com/)

[npm-image]: https://img.shields.io/npm/v/hls.js.svg?style=flat
[npm-url]: https://npmjs.org/package/hls.js
7 changes: 7 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Demo: Log all the errors

- Buffering-progress

- Fallback to right group ID: https://apiproxy.akamaized.net/hlsjs/zdf/check_primfail5.m3u8

- Better internal Tracks API
4 changes: 2 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1087,11 +1087,11 @@ get : array of subtitle tracks exposed in manifest

### `hls.subtitleTrack`

get/set : subtitle track id (returned by). Returns -1 if no track is visible. Set to -1 to hide all subtitle tracks.
get/set : subtitle track id (returned by). Returns -1 if no track is visible. Set to -1 to disable all subtitle tracks.

### `hls.subtitleDisplay`

(default: `false`)
(default: `true`)

get/set : if set to true the active subtitle track mode will be set to `showing` and the browser will display the active subtitles. If set to false, the mode will be set to `hidden`.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"type": "git",
"url": "https://github.com/video-dev/hls.js"
},
"publishConfig": {
"registry": "http://registry.npmjs.org"
},
"bugs": {
"url": "https://github.com/video-dev/hls.js/issues"
},
Expand All @@ -24,6 +21,9 @@
"tests"
]
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "webpack --progress",
"build:watch": "webpack --progress --watch",
Expand Down
18 changes: 18 additions & 0 deletions scripts/check-already-published.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const package = require('../package.json');

try {
if (versionPublished()) {
console.log('published');
} else {
console.log('not published');
}
} catch(e) {
console.error(e);
process.exit(1);
}
process.exit(0);

function versionPublished() {
// npm view returns empty string if package doesn't exist
return !!require('child_process').execSync('npm view ' + package.name + '@' + package.version + ' --json').toString().trim();
}
28 changes: 28 additions & 0 deletions scripts/set-canary-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const package = require('../package.json');

try {
// bump patch
let matched = false;
let newVersion = package.version.replace(/^(\d+)\.(\d+)\.(\d+).*$/, function(_, major, minor, patch) {
matched = true;
return major + '.' + minor + '.' + (parseInt(patch, 10) + 1);
});
if (!matched) {
throw new Error('Error calculating version.');
}
newVersion += '-canary.' + getCommitNum();

package.version = newVersion;
fs.writeFileSync('./package.json', JSON.stringify(package));
console.log('Set canary version: ' + newVersion);
} catch(e) {
console.error(e);
process.exit(1);
}
process.exit(0);


function getCommitNum() {
return parseInt(require('child_process').execSync('git rev-list --count HEAD').toString(), 10);
}
31 changes: 27 additions & 4 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps
set -ev

npm install

if [ "${TRAVIS_MODE}" = "build" ]; then
npm run lint && npm run build
function testNodeRequire {
# check that hls.js doesn't error if requiring in node
# see https://github.com/video-dev/hls.js/pull/1642
node -e 'require("./" + require("./package.json").main)'
}

npm install

if [ "${TRAVIS_MODE}" = "build" ]; then
npm run lint
npm run build
testNodeRequire
elif [ "${TRAVIS_MODE}" = "unitTests" ]; then
npm run test:unit
elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
Expand All @@ -29,6 +34,24 @@ elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
if [ ${n} = ${maxRetries} ]; then
exit 1
fi
elif [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
# update the version
# make sure everything is fetched https://github.com/travis-ci/travis-ci/issues/3412
git fetch --unshallow
node ./scripts/set-canary-version.js
if [[ $(node ./scripts/check-already-published.js) = "not published" ]]; then
npm run lint
npm run build
testNodeRequire
npm run test:unit
# write the token to config
# see https://docs.npmjs.com/private-modules/ci-server-config
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npm publish --tag canary
echo "Published canary."
else
echo "Canary already published."
fi
else
echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2
exit 1
Expand Down
64 changes: 51 additions & 13 deletions src/controller/cap-level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ class CapLevelController extends EventHandler {
super(hls,
Event.FPS_DROP_LEVEL_CAPPING,
Event.MEDIA_ATTACHING,
Event.MANIFEST_PARSED);
Event.MANIFEST_PARSED,
Event.BUFFER_CODECS);

this.autoLevelCapping = Number.POSITIVE_INFINITY;
this.firstLevel = null;
this.levels = [];
this.media = null;
this.restrictedLevels = [];
this.timer = null;
}

destroy () {
if (this.hls.config.capLevelToPlayerSize) {
this.media = this.restrictedLevels = null;
this.autoLevelCapping = Number.POSITIVE_INFINITY;
if (this.timer) {
this.timer = clearInterval(this.timer);
}
this.media = null;
this._stopCapping();
}
}

Expand All @@ -37,17 +42,28 @@ class CapLevelController extends EventHandler {
onManifestParsed (data) {
const hls = this.hls;
this.restrictedLevels = [];
// Only fire getMaxLevel or detectPlayerSize if video is expected in the manifest
this.levels = data.levels;
this.firstLevel = data.firstLevel;
if (hls.config.capLevelToPlayerSize && (data.video || (data.levels.length && data.altAudio))) {
this.autoLevelCapping = Number.POSITIVE_INFINITY;
this.levels = data.levels;
hls.firstLevel = this.getMaxLevel(data.firstLevel);
clearInterval(this.timer);
this.timer = setInterval(this.detectPlayerSize.bind(this), 1000);
this.detectPlayerSize();
// Start capping immediately if the manifest has signaled video codecs
this._startCapping();
}
}

// Only activate capping when playing a video stream; otherwise, multi-bitrate audio-only streams will be restricted
// to the first level
onBufferCodecs (data) {
const hls = this.hls;
if (hls.config.capLevelToPlayerSize && data.video) {
// If the manifest did not signal a video codec capping has been deferred until we're certain video is present
this._startCapping();
}
}

onLevelsUpdated (data) {
this.levels = data.levels;
}

detectPlayerSize () {
if (this.media) {
let levelsLength = this.levels ? this.levels.length : 0;
Expand Down Expand Up @@ -79,6 +95,28 @@ class CapLevelController extends EventHandler {
return CapLevelController.getMaxLevelByMediaSize(validLevels, this.mediaWidth, this.mediaHeight);
}

_startCapping () {
if (this.timer) {
// Don't reset capping if started twice; this can happen if the manifest signals a video codec
return;
}
this.autoLevelCapping = Number.POSITIVE_INFINITY;
this.hls.firstLevel = this.getMaxLevel(this.firstLevel);
clearInterval(this.timer);
this.timer = setInterval(this.detectPlayerSize.bind(this), 1000);
this.detectPlayerSize();
}

_stopCapping () {
this.restrictedLevels = [];
this.firstLevel = null;
this.autoLevelCapping = Number.POSITIVE_INFINITY;
if (this.timer) {
this.timer = clearInterval(this.timer);
this.timer = null;
}
}

get mediaWidth () {
let width;
const media = this.media;
Expand Down
5 changes: 2 additions & 3 deletions src/controller/subtitle-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,14 @@ class SubtitleStreamController extends TaskLoop {

onSubtitleTrackSwitch (data) {
this.currentTrackId = data.id;
if (this.currentTrackId === -1) {
if (!this.tracks || this.currentTrackId === -1) {
return;
}

// Check if track was already loaded and if so make sure we finish
// downloading its frags, if not all have been downloaded yet
const currentTrack = this.tracks[this.currentTrackId];
let details = currentTrack.details;
if (details !== undefined) {
if (currentTrack && currentTrack.details) {
this.tick();
}
}
Expand Down
Loading

0 comments on commit 690ba79

Please sign in to comment.