Skip to content

Commit

Permalink
Added build options to disable unneeded features
Browse files Browse the repository at this point in the history
build.sh now accepts several arguments that will  disable features
that will not be needed.  The default is to include all features.
Part of #116.

--disable-offline
--disable-dash
--disable-http

Change-Id: Icdaf82b322debbdc1e898e93c539e35894678a8d
  • Loading branch information
TheModMaker committed Aug 14, 2015
1 parent 88c38cb commit 671611e
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 61 deletions.
49 changes: 42 additions & 7 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,49 @@ dir=$(dirname $0)/..

set -e

name=
arguments=
function argsHelper() {
local arg=$1
shift

while [[ $# -ne 0 ]]; do
if [[ $1 == $arg ]]; then
arguments="$arguments -D shaka.features.$2=false"
return 0
fi
shift 2
done

if [[ -z $name ]] && [[ $arg != -* ]]; then
name=$arg
else
echo "Usage: build.sh [--disable-dash] [--disable-offline] [--disable-http] [name]"
exit 1 # Exit here
fi
}

while [[ $# -ne 0 ]]; do
argsHelper "$1" --disable-dash "Dash" \
--disable-offline "Offline" \
--disable-http "Http"
shift
done

if [[ -z $name ]]; then
name=compiled
fi

# This was the old name.
rm -f "$dir"/lib.js{,.map}

# These are the new names.
rm -f "$dir"/shaka-player.compiled.debug.{js,map}
rm -f "$dir"/shaka-player.compiled.js
rm -f "$dir"/shaka-player.${name}.debug.{js,map}
rm -f "$dir"/shaka-player.${name}.js

# Compile once with app/controls.js so they get checked. Don't keep the output.
(library_sources_0; closure_sources_0) | compile_0 \
$arguments \
--summary_detail_level 3 "$dir"/{app,controls}.js > /dev/null
# NOTE: --js_output_file /dev/null results in a non-zero return value and
# stops execution of this script.
Expand All @@ -37,16 +71,17 @@ rm -f "$dir"/shaka-player.compiled.js
# should be exported. Otherwise, things unused internally may be seen as dead
# code.
(library_sources_0; closure_sources_0) | compile_0 \
$arguments \
"$dir"/shaka-player.uncompiled.js \
--create_source_map "$dir"/shaka-player.compiled.debug.map \
--js_output_file "$dir"/shaka-player.compiled.debug.js
--create_source_map "$dir"/shaka-player.${name}.debug.map \
--js_output_file "$dir"/shaka-player.${name}.debug.js

# Fork the non-debug version before appending debug info.
cp "$dir"/shaka-player.compiled{.debug,}.js
cp "$dir"/shaka-player.${name}{.debug,}.js

# Add a special source-mapping comment so that Chrome and Firefox can map line
# and character numbers from the compiled library back to the original source
# locations.
echo "//# sourceMappingURL=shaka-player.compiled.debug.map" >> \
"$dir"/shaka-player.compiled.debug.js
echo "//# sourceMappingURL=shaka-player.${name}.debug.map" >> \
"$dir"/shaka-player.${name}.debug.js

3 changes: 2 additions & 1 deletion build/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ closure_opts="
--jscomp_off=deprecatedAnnotations
--extra_annotation_name=listens
--extra_annotation_name=exportDoc
-O ADVANCED
--generate_exports
Expand Down Expand Up @@ -106,7 +107,7 @@ function compile_0() {
function lint_0() {
# Allow JSDoc3 tags not normally recognized by the linter, but be strict
# otherwise.
jsdoc3_tags=static,summary,namespace,event,description,property,fires,listens,example
jsdoc3_tags=static,summary,namespace,event,description,property,fires,listens,example,exportDoc
xargs -0 "$dir"/third_party/gjslint/gjslint \
--custom_jsdoc_tags $jsdoc3_tags \
--strict "$@" 1>&2
Expand Down
7 changes: 6 additions & 1 deletion lib/player/dash_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ goog.provide('shaka.player.DashVideoSource');
goog.require('shaka.dash.MpdProcessor');
goog.require('shaka.dash.MpdRequest');
goog.require('shaka.dash.mpd');
goog.require('shaka.features');
goog.require('shaka.media.IAbrManager');
goog.require('shaka.media.SimpleAbrManager');
goog.require('shaka.player.DrmSchemeInfo');
Expand All @@ -45,7 +46,7 @@ goog.require('shaka.util.TypedBind');
* @constructor
* @struct
* @extends {shaka.player.StreamVideoSource}
* @export
* @exportDoc
*/
shaka.player.DashVideoSource =
function(mpdUrl, interpretContentProtection, estimator, abrManager) {
Expand Down Expand Up @@ -76,6 +77,10 @@ shaka.player.DashVideoSource =
this.captionsMime_ = [];
};
goog.inherits(shaka.player.DashVideoSource, shaka.player.StreamVideoSource);
if (shaka.features.Dash) {
goog.exportSymbol('shaka.player.DashVideoSource',
shaka.player.DashVideoSource);
}


/**
Expand Down
7 changes: 6 additions & 1 deletion lib/player/http_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

goog.provide('shaka.player.HttpVideoSource');

goog.require('shaka.features');
goog.require('shaka.media.StreamConfig');
goog.require('shaka.player.DrmSchemeInfo');
goog.require('shaka.player.IVideoSource');
Expand All @@ -35,7 +36,7 @@ goog.require('shaka.util.FakeEventTarget');
* @constructor
* @implements {shaka.player.IVideoSource}
* @extends {shaka.util.FakeEventTarget}
* @export
* @exportDoc
*/
shaka.player.HttpVideoSource = function(mediaUrl, textUrl, drmScheme) {
shaka.util.FakeEventTarget.call(this, null);
Expand All @@ -54,6 +55,10 @@ shaka.player.HttpVideoSource = function(mediaUrl, textUrl, drmScheme) {
this.textTrack_ = null;
};
goog.inherits(shaka.player.HttpVideoSource, shaka.util.FakeEventTarget);
if (shaka.features.Http) {
goog.exportSymbol('shaka.player.HttpVideoSource',
shaka.player.HttpVideoSource);
}


/** @override */
Expand Down
13 changes: 11 additions & 2 deletions lib/player/offline_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ goog.require('shaka.asserts');
goog.require('shaka.dash.MpdProcessor');
goog.require('shaka.dash.MpdRequest');
goog.require('shaka.dash.mpd');
goog.require('shaka.features');
goog.require('shaka.log');
goog.require('shaka.media.EmeManager');
goog.require('shaka.media.IAbrManager');
Expand Down Expand Up @@ -51,7 +52,7 @@ goog.require('shaka.util.Uint8ArrayUtils');
* @struct
* @constructor
* @extends {shaka.player.StreamVideoSource}
* @export
* @exportDoc
*/
shaka.player.OfflineVideoSource = function(groupId, estimator, abrManager) {
if (!estimator) {
Expand Down Expand Up @@ -83,6 +84,10 @@ shaka.player.OfflineVideoSource = function(groupId, estimator, abrManager) {
this.config_ = {};
};
goog.inherits(shaka.player.OfflineVideoSource, shaka.player.StreamVideoSource);
if (shaka.features.Offline) {
goog.exportSymbol('shaka.player.OfflineVideoSource',
shaka.player.OfflineVideoSource);
}


/**
Expand Down Expand Up @@ -166,7 +171,7 @@ shaka.player.OfflineVideoSource.retrieveGroupIds = function() {
* elements in the MPD.
* @param {shaka.player.OfflineVideoSource.ChooseTracksCallback} chooseTracks
* @return {!Promise.<number>} The group ID of the stored content.
* @export
* @exportDoc
*/
shaka.player.OfflineVideoSource.prototype.store = function(
mpdUrl, preferredLanguage, interpretContentProtection, chooseTracks) {
Expand Down Expand Up @@ -284,6 +289,10 @@ shaka.player.OfflineVideoSource.prototype.store = function(
})
);
};
if (shaka.features.Dash) {
goog.exportSymbol('shaka.player.OfflineVideoSource.prototype.store',
shaka.player.OfflineVideoSource.prototype.store);
}


/**
Expand Down
100 changes: 52 additions & 48 deletions lib/util/ajax_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ goog.provide('shaka.util.AjaxRequest');

goog.require('goog.Uri');
goog.require('shaka.asserts');
goog.require('shaka.features');
goog.require('shaka.util.Clock');
goog.require('shaka.util.ContentDatabaseReader');
goog.require('shaka.util.IBandwidthEstimator');
Expand Down Expand Up @@ -221,6 +222,7 @@ shaka.util.AjaxRequest.prototype.send = function() {
if (this.url.lastIndexOf('data:', 0) == 0) {
return this.handleDataUri_();
} else if (this.url.lastIndexOf('idb:', 0) == 0) {
shaka.asserts.assert(shaka.features.Offline);
return this.handleOfflineUri_();
}

Expand Down Expand Up @@ -312,54 +314,56 @@ shaka.util.AjaxRequest.prototype.handleDataUri_ = function() {
};


/**
* Handles an offline URI.
* This method does not modify |this|'s state.
*
* @return {!Promise}
*
* @private
*/
shaka.util.AjaxRequest.prototype.handleOfflineUri_ = function() {
// URL should have format idb://<streamId>/<segmentId>
var ids = this.url.split('/');
shaka.asserts.assert(ids.length == 4);
var streamId = parseInt(ids[2], 10);
var segmentId = parseInt(ids[3], 10);
shaka.asserts.assert(!isNaN(streamId));
shaka.asserts.assert(!isNaN(segmentId));

// TODO: It may be inefficient to keep re-opening the database connection.
// Find a way to keep the database connection open between requests.
var contentDatabase = new shaka.util.ContentDatabaseReader();
return contentDatabase.setUpDatabase().then(
function() {
return contentDatabase.retrieveSegment(streamId, segmentId);
}
).then(shaka.util.TypedBind(this,
/** @param {ArrayBuffer} data */
function(data) {
// We can't set the response field of an XHR, although we can make a
// hacky object that will still look like an XHR.
var xhr = /** @type {!XMLHttpRequest} */ (
JSON.parse(JSON.stringify(new XMLHttpRequest())));
xhr.response = data;

var promise = this.promise_;
promise.resolve(xhr);
contentDatabase.closeDatabaseConnection();
this.destroy_();
return promise;
})
).catch(shaka.util.TypedBind(this,
/** @param {*} e */
function(e) {
contentDatabase.closeDatabaseConnection();
this.destroy_();
return Promise.reject(e);
})
);
};
if (shaka.features.Offline) {
/**
* Handles an offline URI.
* This method does not modify |this|'s state.
*
* @return {!Promise}
*
* @private
*/
shaka.util.AjaxRequest.prototype.handleOfflineUri_ = function() {
// URL should have format idb://<streamId>/<segmentId>
var ids = this.url.split('/');
shaka.asserts.assert(ids.length == 4);
var streamId = parseInt(ids[2], 10);
var segmentId = parseInt(ids[3], 10);
shaka.asserts.assert(!isNaN(streamId));
shaka.asserts.assert(!isNaN(segmentId));

// TODO: It may be inefficient to keep re-opening the database connection.
// Find a way to keep the database connection open between requests.
var contentDatabase = new shaka.util.ContentDatabaseReader();
return contentDatabase.setUpDatabase().then(
function() {
return contentDatabase.retrieveSegment(streamId, segmentId);
}
).then(shaka.util.TypedBind(this,
/** @param {ArrayBuffer} data */
function(data) {
// We can't set the response field of an XHR, although we can make a
// hacky object that will still look like an XHR.
var xhr = /** @type {!XMLHttpRequest} */ (
JSON.parse(JSON.stringify(new XMLHttpRequest())));
xhr.response = data;

var promise = this.promise_;
promise.resolve(xhr);
contentDatabase.closeDatabaseConnection();
this.destroy_();
return promise;
})
).catch(shaka.util.TypedBind(this,
/** @param {*} e */
function(e) {
contentDatabase.closeDatabaseConnection();
this.destroy_();
return Promise.reject(e);
})
);
};
}


/**
Expand Down
1 change: 0 additions & 1 deletion lib/util/failover_uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ goog.provide('shaka.util.FailoverUri');

goog.require('goog.Uri');
goog.require('shaka.asserts');
goog.require('shaka.dash.mpd');
goog.require('shaka.log');
goog.require('shaka.util.AjaxRequest');

Expand Down
44 changes: 44 additions & 0 deletions lib/util/features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @fileoverview Defines the compiler flags to enable features
*/

goog.provide('shaka.features');


/**
* @namespace shaka.features
* @summary Contains features flags used to enable features.
*/


/**
* @define {boolean} true to enable dash sources, false otherwise.
*/
goog.define('shaka.features.Dash', true);


/**
* @define {boolean} true to enable offline sources, false otherwise.
*/
goog.define('shaka.features.Offline', true);


/**
* @define {boolean} true to enable HTTP sources, false otherwise.
*/
goog.define('shaka.features.Http', true);

6 changes: 6 additions & 0 deletions third_party/jsdoc/lib/jsdoc/tag/dictionary/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,12 @@ var closureTags = exports.closureTags = {
doclet.visibility = 'export';
}
},
exportDoc: {
mustNotHaveValue: true,
onTagged: function(doclet, tag) {
doclet.visibility = 'export';
}
},
expose: {
onTagged: function(doclet, tag) {
doclet.visibility = 'expose';
Expand Down

0 comments on commit 671611e

Please sign in to comment.