mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-16 16:16:40 +03:00
3cd18bb336
Some platforms (such as Chromecast) support extra MIME parameters like framerate, bitrate, width, height, and channels. Since other platforms will ignore these extra parameters, we should always query using these parameters. This introduces the framework to construct these "extended" MIME types from Stream objects. Extra parameters for other platforms can easily be added later. Change-Id: I8936ca93e84068da18f12127fbc8fc1a0646695a
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2016 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.MimeUtils');
|
|
|
|
|
|
/**
|
|
* @namespace shaka.util.MimeUtils
|
|
* @summary A set of utility functions for dealing with MIME types.
|
|
*/
|
|
|
|
|
|
/**
|
|
* Takes a MIME type and optional codecs string and produces the full MIME type.
|
|
*
|
|
* @param {string} mimeType
|
|
* @param {string=} opt_codecs
|
|
* @return {string}
|
|
*/
|
|
shaka.util.MimeUtils.getFullType = function(mimeType, opt_codecs) {
|
|
var fullMimeType = mimeType;
|
|
if (opt_codecs) {
|
|
fullMimeType += '; codecs="' + opt_codecs + '"';
|
|
}
|
|
return fullMimeType;
|
|
};
|
|
|
|
|
|
/**
|
|
* Takes a Stream object and produces an extended MIME type with information
|
|
* beyond the container and codec type, when available.
|
|
*
|
|
* @param {shakaExtern.Stream} stream
|
|
* @return {string}
|
|
*/
|
|
shaka.util.MimeUtils.getExtendedType = function(stream) {
|
|
var mimeType = stream.mimeType;
|
|
|
|
for (var streamKey in shaka.util.MimeUtils.EXTENDED_MIME_PARAMETERS_) {
|
|
var value = stream[streamKey];
|
|
var mimeKey = shaka.util.MimeUtils.EXTENDED_MIME_PARAMETERS_[streamKey];
|
|
if (value) {
|
|
mimeType += '; ' + mimeKey + '="' + value + '"';
|
|
}
|
|
}
|
|
|
|
return mimeType;
|
|
};
|
|
|
|
|
|
/**
|
|
* A map from Stream object keys to MIME type parameters. These should be
|
|
* ignored by platforms that do not recognize them.
|
|
*
|
|
* This initial set of parameters are all recognized by Chromecast.
|
|
*
|
|
* @const {!Object.<string, string>}
|
|
* @private
|
|
*/
|
|
shaka.util.MimeUtils.EXTENDED_MIME_PARAMETERS_ = {
|
|
'codecs': 'codecs',
|
|
'frameRate': 'framerate', // ours is camelCase, theirs is lowercase
|
|
'bandwidth': 'bitrate', // thankfully in the same unit, bits/sec
|
|
'width': 'width',
|
|
'height': 'height',
|
|
'channelsCount': 'channels'
|
|
};
|