123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- import {
- toPlaylists
- } from '../src/toPlaylists';
- import QUnit from 'qunit';
- QUnit.module('toPlaylists');
- QUnit.test('no representations', function(assert) {
- assert.deepEqual(toPlaylists([]), []);
- });
- QUnit.test('pretty simple', function(assert) {
- const representations = [{
- attributes: {
- baseUrl: 'http://example.com/',
- sourceDuration: 2,
- type: 'static',
- periodStart: 0
- },
- segmentInfo: {
- template: { }
- }
- }];
- const playlists = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 0,
- sourceDuration: 2,
- duration: 2,
- type: 'static'
- },
- segments: [{
- uri: '',
- timeline: 0,
- duration: 2,
- resolvedUri: 'http://example.com/',
- map: {
- uri: '',
- resolvedUri: 'http://example.com/'
- },
- number: 1,
- presentationTime: 0
- }]
- }];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
- QUnit.test('segment base', function(assert) {
- const representations = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 0,
- sourceDuration: 2,
- type: 'static'
- },
- segmentInfo: {
- base: true
- }
- }];
- const playlists = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 0,
- sourceDuration: 2,
- duration: 2,
- type: 'static'
- },
- segments: [{
- map: {
- resolvedUri: 'http://example.com/',
- uri: ''
- },
- resolvedUri: 'http://example.com/',
- uri: 'http://example.com/',
- timeline: 0,
- duration: 2,
- presentationTime: 0,
- number: 0
- }]
- }];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
- QUnit.test('segment base with sidx', function(assert) {
- const representations = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 0,
- sourceDuration: 2,
- indexRange: '10-19',
- type: 'static'
- },
- segmentInfo: {
- base: true
- }
- }];
- const playlists = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 0,
- sourceDuration: 2,
- duration: 2,
- indexRange: '10-19',
- type: 'static'
- },
- segments: [],
- sidx: {
- map: {
- resolvedUri: 'http://example.com/',
- uri: ''
- },
- resolvedUri: 'http://example.com/',
- uri: 'http://example.com/',
- byterange: {
- offset: 10,
- length: 10
- },
- timeline: 0,
- presentationTime: 0,
- duration: 2,
- number: 0
- }
- }];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
- QUnit.test('segment list', function(assert) {
- const representations = [{
- attributes: {
- baseUrl: 'http://example.com/',
- duration: 10,
- sourceDuration: 11,
- periodStart: 0,
- type: 'static'
- },
- segmentInfo: {
- list: {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }]
- }
- }
- }];
- const playlists = [{
- attributes: {
- baseUrl: 'http://example.com/',
- duration: 10,
- sourceDuration: 11,
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }],
- periodStart: 0,
- type: 'static'
- },
- segments: [{
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/',
- uri: ''
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 1,
- map: {
- resolvedUri: 'http://example.com/',
- uri: ''
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '2.fmp4',
- number: 2
- }]
- }];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
- QUnit.test('presentationTime accounts for presentationTimeOffset', function(assert) {
- const representations = [{
- attributes: {
- baseUrl: 'http://example.com/',
- sourceDuration: 2,
- type: 'static',
- periodStart: 25
- },
- segmentInfo: {
- template: {
- presentationTimeOffset: 100,
- timescale: 4
- }
- }
- }];
- const playlists = [{
- attributes: {
- baseUrl: 'http://example.com/',
- periodStart: 25,
- presentationTimeOffset: 100,
- sourceDuration: 2,
- duration: 2,
- timescale: 4,
- type: 'static'
- },
- segments: [{
- uri: '',
- timeline: 25,
- duration: 2,
- // The presentationTime value should be adjusted based on the presentationTimeOffset
- // and its timescale.
- presentationTime: 0,
- resolvedUri: 'http://example.com/',
- map: {
- uri: '',
- resolvedUri: 'http://example.com/'
- },
- number: 1
- }]
- }];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
|