Source: lib/util/manifest_parser_utils.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.util.ManifestParserUtils');
  18. goog.require('goog.Uri');
  19. goog.require('shaka.util.Functional');
  20. /**
  21. * @namespace shaka.util.ManifestParserUtils
  22. * @summary Utility functions for manifest parsing.
  23. */
  24. /**
  25. * Resolves an array of relative URIs to the given base URIs. This will result
  26. * in M*N number of URIs.
  27. *
  28. * @param {!Array.<string>} baseUris
  29. * @param {!Array.<string>} relativeUris
  30. * @return {!Array.<string>}
  31. */
  32. shaka.util.ManifestParserUtils.resolveUris = function(baseUris, relativeUris) {
  33. var Functional = shaka.util.Functional;
  34. if (relativeUris.length == 0)
  35. return baseUris;
  36. var relativeAsGoog =
  37. relativeUris.map(function(uri) { return new goog.Uri(uri); });
  38. // Resolve each URI relative to each base URI, creating an Array of Arrays.
  39. // Then flatten the Arrays into a single Array.
  40. return baseUris.map(function(uri) { return new goog.Uri(uri); })
  41. .map(function(base) { return relativeAsGoog.map(base.resolve.bind(base)); })
  42. .reduce(Functional.collapseArrays, [])
  43. .map(function(uri) { return uri.toString(); });
  44. };
  45. /**
  46. * Creates a DrmInfo object from the given info.
  47. *
  48. * @param {string} keySystem
  49. * @param {Array.<shakaExtern.InitDataOverride>} initData
  50. * @return {shakaExtern.DrmInfo}
  51. */
  52. shaka.util.ManifestParserUtils.createDrmInfo = function(keySystem, initData) {
  53. return {
  54. keySystem: keySystem,
  55. licenseServerUri: '',
  56. distinctiveIdentifierRequired: false,
  57. persistentStateRequired: false,
  58. audioRobustness: '',
  59. videoRobustness: '',
  60. serverCertificate: null,
  61. initData: initData || [],
  62. keyIds: []
  63. };
  64. };
  65. /**
  66. * @enum {string}
  67. */
  68. shaka.util.ManifestParserUtils.ContentType = {
  69. VIDEO: 'video',
  70. AUDIO: 'audio',
  71. TEXT: 'text',
  72. APPLICATION: 'application'
  73. };
  74. /**
  75. * @enum {string}
  76. */
  77. shaka.util.ManifestParserUtils.TextStreamKind = {
  78. SUBTITLE: 'subtitle',
  79. CLOSED_CAPTION: 'caption'
  80. };
  81. /**
  82. * Specifies how tolerant the player is to inaccurate segment start times and
  83. * end times within a manifest. For example, gaps or overlaps between segments
  84. * in a SegmentTimeline which are greater than or equal to this value will
  85. * result in a warning message.
  86. *
  87. * @const {number}
  88. */
  89. shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS = 1 / 15;