codec-utils.js.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: codec-utils.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: codec-utils.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * @file codec-utils.js
  21. */
  22. /**
  23. * Check if a codec string refers to an audio codec.
  24. *
  25. * @param {String} codec codec string to check
  26. * @return {Boolean} if this is an audio codec
  27. * @private
  28. */
  29. const isAudioCodec = function(codec) {
  30. return (/mp4a\.\d+.\d+/i).test(codec);
  31. };
  32. /**
  33. * Check if a codec string refers to a video codec.
  34. *
  35. * @param {String} codec codec string to check
  36. * @return {Boolean} if this is a video codec
  37. * @private
  38. */
  39. const isVideoCodec = function(codec) {
  40. return (/avc1\.[\da-f]+/i).test(codec);
  41. };
  42. /**
  43. * Parse a content type header into a type and parameters
  44. * object
  45. *
  46. * @param {String} type the content type header
  47. * @return {Object} the parsed content-type
  48. * @private
  49. */
  50. const parseContentType = function(type) {
  51. let object = {type: '', parameters: {}};
  52. let parameters = type.trim().split(';');
  53. // first parameter should always be content-type
  54. object.type = parameters.shift().trim();
  55. parameters.forEach((parameter) => {
  56. let pair = parameter.trim().split('=');
  57. if (pair.length > 1) {
  58. let name = pair[0].replace(/"/g, '').trim();
  59. let value = pair[1].replace(/"/g, '').trim();
  60. object.parameters[name] = value;
  61. }
  62. });
  63. return object;
  64. };
  65. /**
  66. * Replace the old apple-style `avc1.&lt;dd>.&lt;dd>` codec string with the standard
  67. * `avc1.&lt;hhhhhh>`
  68. *
  69. * @param {Array} codecs an array of codec strings to fix
  70. * @return {Array} the translated codec array
  71. * @private
  72. */
  73. const translateLegacyCodecs = function(codecs) {
  74. return codecs.map((codec) => {
  75. return codec.replace(/avc1\.(\d+)\.(\d+)/i, function(orig, profile, avcLevel) {
  76. let profileHex = ('00' + Number(profile).toString(16)).slice(-2);
  77. let avcLevelHex = ('00' + Number(avcLevel).toString(16)).slice(-2);
  78. return 'avc1.' + profileHex + '00' + avcLevelHex;
  79. });
  80. });
  81. };
  82. export default {
  83. isAudioCodec,
  84. parseContentType,
  85. isVideoCodec,
  86. translateLegacyCodecs
  87. };
  88. </code></pre>
  89. </article>
  90. </section>
  91. </div>
  92. <nav>
  93. <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>
  94. </nav>
  95. <br class="clear">
  96. <footer>
  97. 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)
  98. </footer>
  99. <script> prettyPrint(); </script>
  100. <script src="scripts/linenumber.js"> </script>
  101. </body>
  102. </html>