Source: lib/media/segment_reference.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.media.InitSegmentReference');
  18. goog.provide('shaka.media.SegmentReference');
  19. goog.require('goog.asserts');
  20. /**
  21. * Creates an InitSegmentReference, which provides the location to an
  22. * initialization segment.
  23. *
  24. * @param {function():!Array.<string>} uris
  25. * A function that creates the URIs of the resource containing the segment.
  26. * @param {number} startByte The offset from the start of the resource to the
  27. * start of the segment.
  28. * @param {?number} endByte The offset from the start of the resource to the
  29. * end of the segment, inclusive. null indicates that the segment extends
  30. * to the end of the resource.
  31. *
  32. * @constructor
  33. * @struct
  34. * @export
  35. */
  36. shaka.media.InitSegmentReference = function(uris, startByte, endByte) {
  37. /** @type {function():!Array.<string>} */
  38. this.getUris = uris;
  39. /** @const {number} */
  40. this.startByte = startByte;
  41. /** @const {?number} */
  42. this.endByte = endByte;
  43. };
  44. /**
  45. * Creates a SegmentReference, which provides the start time, end time, and
  46. * location to a media segment.
  47. *
  48. * @param {number} position The segment's position within a particular Period.
  49. * The following should hold true between any two SegmentReferences from the
  50. * same Period, r1 and r2:
  51. * IF r2.position > r1.position THEN
  52. * [ (r2.startTime > r1.startTime) OR
  53. * (r2.startTime == r1.startTime AND r2.endTime >= r1.endTime) ]
  54. * @param {number} startTime The segment's start time in seconds, relative to
  55. * the start of a particular Period.
  56. * @param {number} endTime The segment's end time in seconds, relative to
  57. * the start of a particular Period. The segment ends the instant before
  58. * this time, so |endTime| must be strictly greater than |startTime|.
  59. * @param {function():!Array.<string>} uris
  60. * A function that creates the URIs of the resource containing the segment.
  61. * @param {number} startByte The offset from the start of the resource to the
  62. * start of the segment.
  63. * @param {?number} endByte The offset from the start of the resource to the
  64. * end of the segment, inclusive. null indicates that the segment extends
  65. * to the end of the resource.
  66. *
  67. * @constructor
  68. * @struct
  69. * @export
  70. */
  71. shaka.media.SegmentReference = function(
  72. position, startTime, endTime, uris, startByte, endByte) {
  73. goog.asserts.assert(startTime < endTime,
  74. 'startTime must be less than endTime');
  75. goog.asserts.assert((startByte < endByte) || (endByte == null),
  76. 'startByte must be < endByte');
  77. /** @const {number} */
  78. this.position = position;
  79. /** @const {number} */
  80. this.startTime = startTime;
  81. /** @const {number} */
  82. this.endTime = endTime;
  83. /** @type {function():!Array.<string>} */
  84. this.getUris = uris;
  85. /** @const {number} */
  86. this.startByte = startByte;
  87. /** @const {?number} */
  88. this.endByte = endByte;
  89. };