mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
4cc4e96dbd
* Updates all Copyright years to 2015. * Adds licenses annotations to all JS. * Makes all licenses identical to avoid repeated appearance in the compiled output. * Drops fileoverview annotations, which do not affect docs output. * The linter still requires fileoverview on externs. This patch required a newer closure compiler, since the previous version we used had a bug regarding license annotations that caused the license comment block to appear in the output once per file regardless of uniqueness. Change-Id: I2e9272db680cba7ecc4613d97f1d3a94ac2244cc
119 lines
3.7 KiB
JavaScript
119 lines
3.7 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2015 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.
|
|
*/
|
|
|
|
goog.provide('shaka.util.ContentDatabaseReader');
|
|
|
|
goog.require('shaka.util.ArrayUtils');
|
|
goog.require('shaka.util.ContentDatabase');
|
|
goog.require('shaka.util.PublicPromise');
|
|
goog.require('shaka.util.TypedBind');
|
|
|
|
|
|
|
|
/**
|
|
* Creates a new ContentDatabaseReader.
|
|
*
|
|
* @constructor
|
|
* @struct
|
|
* @extends {shaka.util.ContentDatabase}
|
|
*/
|
|
shaka.util.ContentDatabaseReader = function() {
|
|
shaka.util.ContentDatabase.call(this, 'readonly', null);
|
|
};
|
|
goog.inherits(shaka.util.ContentDatabaseReader, shaka.util.ContentDatabase);
|
|
|
|
|
|
/**
|
|
* Retrieves an array of all stored group IDs.
|
|
* @return {!Promise.<!Array.<number>>} The unique IDs of all of the
|
|
* stored groups.
|
|
*/
|
|
shaka.util.ContentDatabaseReader.prototype.retrieveGroupIds = function() {
|
|
var p = new shaka.util.PublicPromise();
|
|
var groupIds = [];
|
|
var request = this.getGroupStore().openCursor();
|
|
|
|
request.onerror = function(e) { p.reject(request.error); };
|
|
request.onsuccess = function(e) {
|
|
var cursor = e.target.result;
|
|
if (cursor) {
|
|
groupIds.push(cursor.key);
|
|
cursor.continue();
|
|
} else {
|
|
p.resolve(groupIds);
|
|
}
|
|
};
|
|
|
|
return p;
|
|
};
|
|
|
|
|
|
/**
|
|
* Retrieves the group for a stream from the database.
|
|
* @param {number} groupId The unique id of the group.
|
|
* @return {!Promise.<shaka.util.ContentDatabase.GroupInformation>} The unique
|
|
* ids of the streams the group.
|
|
*/
|
|
shaka.util.ContentDatabaseReader.prototype.retrieveGroup = function(groupId) {
|
|
var p = this.retrieveItem(this.getGroupStore(), groupId);
|
|
return p.then(shaka.util.TypedBind(this,
|
|
/** @param {shaka.util.ContentDatabase.GroupInformation} groupInfo */
|
|
function(groupInfo) {
|
|
groupInfo['session_ids'] =
|
|
shaka.util.ArrayUtils.removeDuplicates(groupInfo['session_ids']);
|
|
|
|
if (!groupInfo.hasOwnProperty('duration') &&
|
|
!groupInfo.hasOwnProperty('key_system')) {
|
|
return this.retrieveStreamIndex(groupInfo['stream_ids'][0]).then(
|
|
function(index) {
|
|
groupInfo['duration'] = index['duration'];
|
|
groupInfo['key_system'] = index['key_system'];
|
|
return Promise.resolve(groupInfo);
|
|
});
|
|
} else {
|
|
return Promise.resolve(groupInfo);
|
|
}
|
|
}));
|
|
};
|
|
|
|
|
|
/**
|
|
* Retrieves the index for a stream from the database.
|
|
* @param {number} streamId The unique id of the stream.
|
|
* @return {!Promise.<shaka.util.ContentDatabase.StreamIndex>}
|
|
*/
|
|
shaka.util.ContentDatabaseReader.prototype.retrieveStreamIndex = function(
|
|
streamId) {
|
|
return this.retrieveItem(this.getIndexStore(), streamId);
|
|
};
|
|
|
|
|
|
/**
|
|
* Retrieves the segment with |segmentId| from the stream with |streamId| in
|
|
* the database.
|
|
* @param {number} streamId The unique id of the stream to retrieve.
|
|
* @param {number} segmentId The id of the segment to retrieve.
|
|
* @return {!Promise.<ArrayBuffer>}
|
|
*/
|
|
shaka.util.ContentDatabaseReader.prototype.retrieveSegment = function(
|
|
streamId, segmentId) {
|
|
var p = this.retrieveItem(
|
|
this.getContentStore().index('segment'), [streamId, segmentId]);
|
|
return p.then(function(data) { return Promise.resolve(data.content); });
|
|
};
|
|
|