yanchengPowerSupply/node_modules/videojs-contrib-media-sources/docs/api/codec-utils.js.html

131 lines
4.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: codec-utils.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: codec-utils.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file codec-utils.js
*/
/**
* Check if a codec string refers to an audio codec.
*
* @param {String} codec codec string to check
* @return {Boolean} if this is an audio codec
* @private
*/
const isAudioCodec = function(codec) {
return (/mp4a\.\d+.\d+/i).test(codec);
};
/**
* Check if a codec string refers to a video codec.
*
* @param {String} codec codec string to check
* @return {Boolean} if this is a video codec
* @private
*/
const isVideoCodec = function(codec) {
return (/avc1\.[\da-f]+/i).test(codec);
};
/**
* Parse a content type header into a type and parameters
* object
*
* @param {String} type the content type header
* @return {Object} the parsed content-type
* @private
*/
const parseContentType = function(type) {
let object = {type: '', parameters: {}};
let parameters = type.trim().split(';');
// first parameter should always be content-type
object.type = parameters.shift().trim();
parameters.forEach((parameter) => {
let pair = parameter.trim().split('=');
if (pair.length > 1) {
let name = pair[0].replace(/"/g, '').trim();
let value = pair[1].replace(/"/g, '').trim();
object.parameters[name] = value;
}
});
return object;
};
/**
* Replace the old apple-style `avc1.&lt;dd>.&lt;dd>` codec string with the standard
* `avc1.&lt;hhhhhh>`
*
* @param {Array} codecs an array of codec strings to fix
* @return {Array} the translated codec array
* @private
*/
const translateLegacyCodecs = function(codecs) {
return codecs.map((codec) => {
return codec.replace(/avc1\.(\d+)\.(\d+)/i, function(orig, profile, avcLevel) {
let profileHex = ('00' + Number(profile).toString(16)).slice(-2);
let avcLevelHex = ('00' + Number(avcLevel).toString(16)).slice(-2);
return 'avc1.' + profileHex + '00' + avcLevelHex;
});
});
};
export default {
isAudioCodec,
parseContentType,
isVideoCodec,
translateLegacyCodecs
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FlashMediaSource.html">FlashMediaSource</a></li><li><a href="FlashSourceBuffer.html">FlashSourceBuffer</a></li><li><a href="HtmlMediaSource.html">HtmlMediaSource</a></li><li><a href="MessageHandlers.html">MessageHandlers</a></li><li><a href="VirtualSourceBuffer.html">VirtualSourceBuffer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#abort">abort</a></li><li><a href="global.html#addSourceBuffer">addSourceBuffer</a></li><li><a href="global.html#appendBuffer">appendBuffer</a></li><li><a href="global.html#appendGopInfo_">appendGopInfo_</a></li><li><a href="global.html#endOfStream">endOfStream</a></li><li><a href="global.html#FlashTransmuxerWorker">FlashTransmuxerWorker</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#gopsSafeToAlignWith">gopsSafeToAlignWith</a></li><li><a href="global.html#MediaSource">MediaSource</a></li><li><a href="global.html#open">open</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#removeGopBuffer">removeGopBuffer</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#supportsNativeMediaSources">supportsNativeMediaSources</a></li><li><a href="global.html#TransmuxerWorker">TransmuxerWorker</a></li><li><a href="global.html#updateGopBuffer">updateGopBuffer</a></li><li><a href="global.html#URL">URL</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.4</a> on Thu Nov 02 2017 12:03:25 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>