Files
shaka-player/lib/util/string_utils.js
T
Timothy Drews 689c2a47aa Use 'keystatuseschange' events and support @group.
Use 'keystatuseschange' events from EME together with cenc:default_KID
from the MPD so StreamVideoSource can determine if the key system
can/will decrypt a stream before it attempts to play it. This enables
the Player to safely (and automatically) switch between streams that
are encrypted with different keys.

Support AdaptationSet @group, which is the preferred approach to safely
use multiple encryption keys over multiple Representations.

* Squash AdaptationSets from the same group into one StreamSetInfo.
  This enables support for @group without introducing special case code
  into StreamVideoSource and EmeManager.
* Fire 'trackchanged' events when tracks becomes available/unavailable
  either from application restrictions or key status changes.
* Pull key IDs out of DrmInfo and put them into StreamInfo so key status
  changes can drive per stream availability instead of per StreamSet
  (AdaptationSet) availability.

Closes #67
Issue #160

Change-Id: Ife0814deb65715923a572b45880137a99b378035
2015-08-31 23:13:17 +00:00

66 lines
1.9 KiB
JavaScript

/**
* 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 String utility functions.
*/
goog.provide('shaka.util.StringUtils');
/**
* @namespace shaka.util.StringUtils
* @summary A set of string utility functions.
*/
/**
* Convert a raw string to a base64 string. The output will always use the
* alternate encoding/alphabet also known as "base64url".
* @param {string} str
* @param {boolean=} opt_padding If true, pad the output with equals signs.
* Defaults to true.
* @return {string}
*/
shaka.util.StringUtils.toBase64 = function(str, opt_padding) {
var padding = (opt_padding == undefined) ? true : opt_padding;
var base64 = window.btoa(str).replace(/\+/g, '-').replace(/\//g, '_');
return padding ? base64 : base64.replace(/=*$/, '');
};
/**
* Convert a base64 string to a raw string. Accepts either the standard
* alphabet or the alternate "base64url" alphabet.
* @param {string} str
* @return {string}
*/
shaka.util.StringUtils.fromBase64 = function(str) {
return window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
};
/**
* Separates every 4 characters by a space.
* @param {string} str
* @return {string}
*/
shaka.util.StringUtils.formatHexString = function(str) {
return str.split('').reduce(
function(acc, ch, i) {
return acc + (i && (i % 4 == 0) ? ' ' + ch : ch);
});
};