toPlaylists.test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import {
  2. toPlaylists
  3. } from '../src/toPlaylists';
  4. import QUnit from 'qunit';
  5. QUnit.module('toPlaylists');
  6. QUnit.test('no representations', function(assert) {
  7. assert.deepEqual(toPlaylists([]), []);
  8. });
  9. QUnit.test('pretty simple', function(assert) {
  10. const representations = [{
  11. attributes: {
  12. baseUrl: 'http://example.com/',
  13. sourceDuration: 2,
  14. type: 'static',
  15. periodStart: 0
  16. },
  17. segmentInfo: {
  18. template: { }
  19. }
  20. }];
  21. const playlists = [{
  22. attributes: {
  23. baseUrl: 'http://example.com/',
  24. periodStart: 0,
  25. sourceDuration: 2,
  26. duration: 2,
  27. type: 'static'
  28. },
  29. segments: [{
  30. uri: '',
  31. timeline: 0,
  32. duration: 2,
  33. resolvedUri: 'http://example.com/',
  34. map: {
  35. uri: '',
  36. resolvedUri: 'http://example.com/'
  37. },
  38. number: 1,
  39. presentationTime: 0
  40. }]
  41. }];
  42. assert.deepEqual(toPlaylists(representations), playlists);
  43. });
  44. QUnit.test('segment base', function(assert) {
  45. const representations = [{
  46. attributes: {
  47. baseUrl: 'http://example.com/',
  48. periodStart: 0,
  49. sourceDuration: 2,
  50. type: 'static'
  51. },
  52. segmentInfo: {
  53. base: true
  54. }
  55. }];
  56. const playlists = [{
  57. attributes: {
  58. baseUrl: 'http://example.com/',
  59. periodStart: 0,
  60. sourceDuration: 2,
  61. duration: 2,
  62. type: 'static'
  63. },
  64. segments: [{
  65. map: {
  66. resolvedUri: 'http://example.com/',
  67. uri: ''
  68. },
  69. resolvedUri: 'http://example.com/',
  70. uri: 'http://example.com/',
  71. timeline: 0,
  72. duration: 2,
  73. presentationTime: 0,
  74. number: 0
  75. }]
  76. }];
  77. assert.deepEqual(toPlaylists(representations), playlists);
  78. });
  79. QUnit.test('segment base with sidx', function(assert) {
  80. const representations = [{
  81. attributes: {
  82. baseUrl: 'http://example.com/',
  83. periodStart: 0,
  84. sourceDuration: 2,
  85. indexRange: '10-19',
  86. type: 'static'
  87. },
  88. segmentInfo: {
  89. base: true
  90. }
  91. }];
  92. const playlists = [{
  93. attributes: {
  94. baseUrl: 'http://example.com/',
  95. periodStart: 0,
  96. sourceDuration: 2,
  97. duration: 2,
  98. indexRange: '10-19',
  99. type: 'static'
  100. },
  101. segments: [],
  102. sidx: {
  103. map: {
  104. resolvedUri: 'http://example.com/',
  105. uri: ''
  106. },
  107. resolvedUri: 'http://example.com/',
  108. uri: 'http://example.com/',
  109. byterange: {
  110. offset: 10,
  111. length: 10
  112. },
  113. timeline: 0,
  114. presentationTime: 0,
  115. duration: 2,
  116. number: 0
  117. }
  118. }];
  119. assert.deepEqual(toPlaylists(representations), playlists);
  120. });
  121. QUnit.test('segment list', function(assert) {
  122. const representations = [{
  123. attributes: {
  124. baseUrl: 'http://example.com/',
  125. duration: 10,
  126. sourceDuration: 11,
  127. periodStart: 0,
  128. type: 'static'
  129. },
  130. segmentInfo: {
  131. list: {
  132. segmentUrls: [{
  133. media: '1.fmp4'
  134. }, {
  135. media: '2.fmp4'
  136. }]
  137. }
  138. }
  139. }];
  140. const playlists = [{
  141. attributes: {
  142. baseUrl: 'http://example.com/',
  143. duration: 10,
  144. sourceDuration: 11,
  145. segmentUrls: [{
  146. media: '1.fmp4'
  147. }, {
  148. media: '2.fmp4'
  149. }],
  150. periodStart: 0,
  151. type: 'static'
  152. },
  153. segments: [{
  154. duration: 10,
  155. map: {
  156. resolvedUri: 'http://example.com/',
  157. uri: ''
  158. },
  159. resolvedUri: 'http://example.com/1.fmp4',
  160. timeline: 0,
  161. presentationTime: 0,
  162. uri: '1.fmp4',
  163. number: 1
  164. }, {
  165. duration: 1,
  166. map: {
  167. resolvedUri: 'http://example.com/',
  168. uri: ''
  169. },
  170. resolvedUri: 'http://example.com/2.fmp4',
  171. timeline: 0,
  172. presentationTime: 10,
  173. uri: '2.fmp4',
  174. number: 2
  175. }]
  176. }];
  177. assert.deepEqual(toPlaylists(representations), playlists);
  178. });
  179. QUnit.test('presentationTime accounts for presentationTimeOffset', function(assert) {
  180. const representations = [{
  181. attributes: {
  182. baseUrl: 'http://example.com/',
  183. sourceDuration: 2,
  184. type: 'static',
  185. periodStart: 25
  186. },
  187. segmentInfo: {
  188. template: {
  189. presentationTimeOffset: 100,
  190. timescale: 4
  191. }
  192. }
  193. }];
  194. const playlists = [{
  195. attributes: {
  196. baseUrl: 'http://example.com/',
  197. periodStart: 25,
  198. presentationTimeOffset: 100,
  199. sourceDuration: 2,
  200. duration: 2,
  201. timescale: 4,
  202. type: 'static'
  203. },
  204. segments: [{
  205. uri: '',
  206. timeline: 25,
  207. duration: 2,
  208. // The presentationTime value should be adjusted based on the presentationTimeOffset
  209. // and its timescale.
  210. presentationTime: 0,
  211. resolvedUri: 'http://example.com/',
  212. map: {
  213. uri: '',
  214. resolvedUri: 'http://example.com/'
  215. },
  216. number: 1
  217. }]
  218. }];
  219. assert.deepEqual(toPlaylists(representations), playlists);
  220. });