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. const Functional = shaka.util.Functional;
  34. if (relativeUris.length == 0) {
  35. return baseUris;
  36. }
  37. let relativeAsGoog =
  38. relativeUris.map(function(uri) { return new goog.Uri(uri); });
  39. // Resolve each URI relative to each base URI, creating an Array of Arrays.
  40. // Then flatten the Arrays into a single Array.
  41. return baseUris.map(function(uri) { return new goog.Uri(uri); })
  42. .map(function(base) { return relativeAsGoog.map(base.resolve.bind(base)); })
  43. .reduce(Functional.collapseArrays, [])
  44. .map(function(uri) { return uri.toString(); });
  45. };
  46. /**
  47. * Creates a DrmInfo object from the given info.
  48. *
  49. * @param {string} keySystem
  50. * @param {Array.<shaka.extern.InitDataOverride>} initData
  51. * @return {shaka.extern.DrmInfo}
  52. */
  53. shaka.util.ManifestParserUtils.createDrmInfo = function(keySystem, initData) {
  54. return {
  55. keySystem: keySystem,
  56. licenseServerUri: '',
  57. distinctiveIdentifierRequired: false,
  58. persistentStateRequired: false,
  59. audioRobustness: '',
  60. videoRobustness: '',
  61. serverCertificate: null,
  62. initData: initData || [],
  63. keyIds: [],
  64. };
  65. };
  66. /**
  67. * @enum {string}
  68. */
  69. shaka.util.ManifestParserUtils.ContentType = {
  70. VIDEO: 'video',
  71. AUDIO: 'audio',
  72. TEXT: 'text',
  73. IMAGE: 'image',
  74. APPLICATION: 'application',
  75. };
  76. /**
  77. * @enum {string}
  78. */
  79. shaka.util.ManifestParserUtils.TextStreamKind = {
  80. SUBTITLE: 'subtitle',
  81. CLOSED_CAPTION: 'caption',
  82. };
  83. /**
  84. * Specifies how tolerant the player is of inaccurate segment start times and
  85. * end times within a manifest. For example, gaps or overlaps between segments
  86. * in a SegmentTimeline which are greater than or equal to this value will
  87. * result in a warning message.
  88. *
  89. * @const {number}
  90. */
  91. shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS = 1 / 15;