Skip to content

Commit

Permalink
feat(thumbnails): Allow download thumbnails (for offline usage) (shak…
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored Mar 30, 2021
1 parent 1b1227f commit 06982de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions demo/common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.DASH)
.addFeature(shakaAssets.Feature.ULTRA_HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.THUMBNAILS),
new ShakaDemoAssetInfo(
/* name= */ 'DASH-IF THUMBNAILS - Single adaptation set, 4 tiles at 10x1, each thumb 205x115',
Expand All @@ -807,6 +808,7 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.DASH)
.addFeature(shakaAssets.Feature.ULTRA_HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.THUMBNAILS),
new ShakaDemoAssetInfo(
/* name= */ 'DASH-IF THUMBNAILS - Single adaptation set, 1 tile at 10x20, each thumb 102x58',
Expand All @@ -816,6 +818,7 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.DASH)
.addFeature(shakaAssets.Feature.ULTRA_HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.THUMBNAILS),
new ShakaDemoAssetInfo(
/* name= */ 'DASH-IF THUMBNAILS - Two adaptation sets with different thumb resolutions',
Expand All @@ -825,6 +828,7 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.DASH)
.addFeature(shakaAssets.Feature.ULTRA_HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.THUMBNAILS),
new ShakaDemoAssetInfo(
/* name= */ 'DASH-IF THUMBNAILS - Live stream, Single adaptation set, 1x1 tiles (livesim)',
Expand Down
14 changes: 14 additions & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ shaka.offline.Storage = class {
const variantIds = new Set();
/** @type {!Set.<number>} */
const textIds = new Set();
/** @type {!Set.<number>} */
const imageIds = new Set();

// Collect the IDs of the chosen tracks.
for (const track of chosenTracks) {
Expand All @@ -558,13 +560,18 @@ shaka.offline.Storage = class {
if (track.type == 'text') {
textIds.add(track.id);
}
if (track.type == 'image') {
imageIds.add(track.id);
}
}

// Filter the manifest to keep only what the app chose.
manifest.variants =
manifest.variants.filter((variant) => variantIds.has(variant.id));
manifest.textStreams =
manifest.textStreams.filter((stream) => textIds.has(stream.id));
manifest.imageStreams =
manifest.imageStreams.filter((stream) => imageIds.has(stream.id));

// Check the post-filtered manifest for characteristics that may indicate
// issues with how the app selected tracks.
Expand Down Expand Up @@ -1063,6 +1070,9 @@ shaka.offline.Storage = class {
for (const text of manifest.textStreams) {
estimator.addText(text);
}
for (const image of manifest.imageStreams) {
estimator.addImage(image);
}

// TODO(joeyparrish): Break out stack-based state and method params into a
// separate class to clean up. See:
Expand Down Expand Up @@ -1487,6 +1497,10 @@ shaka.offline.Storage = class {
set.add(text);
}

for (const image of manifest.imageStreams) {
set.add(image);
}

for (const variant of manifest.variants) {
if (variant.audio) {
set.add(variant.audio);
Expand Down
22 changes: 22 additions & 0 deletions lib/offline/stream_bandwidth_estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ shaka.offline.StreamBandwidthEstimator = class {
shaka.offline.StreamBandwidthEstimator.DEFAULT_TEXT_BITRATE_;
}

/**
* Create an estimate for the image stream.
*
* @param {shaka.extern.Stream} image
*/
addImage(image) {
this.estimateByStreamId_[image.id] = image.bandwidth ||
shaka.offline.StreamBandwidthEstimator.DEFAULT_IMAGE_BITRATE_;
}

/**
* Get the estimate for a segment that is part of a stream that has already
* added to the estimator.
Expand Down Expand Up @@ -171,3 +181,15 @@ shaka.offline.StreamBandwidthEstimator.DEFAULT_AUDIO_BITRATE_ = 393216;
*/
shaka.offline.StreamBandwidthEstimator.DEFAULT_TEXT_BITRATE_ = 52;


/**
* Since we don't normally get the bitrate for image, we still want to create
* some approximation so that it can influence progress.
*
* The size of the thumbnail usually is 2KB.
*
* @const {number}
* @private
*/
shaka.offline.StreamBandwidthEstimator.DEFAULT_IMAGE_BITRATE_ = 2048;

6 changes: 3 additions & 3 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ shaka.util.PlayerConfiguration = class {

// Since this default callback is used primarily by our own demo app and by
// app developers who haven't thought about which tracks they want, we
// should select all text tracks, regardless of language. This makes for a
// better demo for us, and does not rely on user preferences for the
// should select all image/text tracks, regardless of language. This makes
// for a better demo for us, and does not rely on user preferences for the
// unconfigured app.
for (const track of tracks) {
if (track.type == ContentType.TEXT) {
if (track.type == ContentType.TEXT || track.type == ContentType.IMAGE) {
selectedTracks.push(track);
}
}
Expand Down

0 comments on commit 06982de

Please sign in to comment.