| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- 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('playlist with content steering BaseURLs', function(assert) {
- const representations = [
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn1.example.com/',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segmentInfo: {
- template: {}
- }
- },
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn2.example.com/',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segmentInfo: {
- template: {}
- }
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://example.com/en.vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- sourceDuration: 0,
- type: 'dyanmic'
- },
- segmentInfo: {}
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://example.com/en.vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- sourceDuration: 0,
- type: 'dyanmic'
- },
- segmentInfo: {}
- }
- ];
- const playlists = [{
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn1.example.com/',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- duration: 0,
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segments: [
- {
- duration: 0,
- map: {
- resolvedUri: 'https://cdn1.example.com/',
- uri: ''
- },
- number: 1,
- presentationTime: 0,
- resolvedUri: 'https://cdn1.example.com/',
- timeline: 0,
- uri: ''
- }
- ]
- }, {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn2.example.com/',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- duration: 0,
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segments: [
- {
- duration: 0,
- map: {
- resolvedUri: 'https://cdn2.example.com/',
- uri: ''
- },
- number: 1,
- presentationTime: 0,
- resolvedUri: 'https://cdn2.example.com/',
- timeline: 0,
- uri: ''
- }
- ]
- }, {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://example.com/en.vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- sourceDuration: 0,
- type: 'dyanmic'
- }
- }, {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://example.com/en.vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- sourceDuration: 0,
- type: 'dyanmic'
- }
- }];
- 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);
- });
- QUnit.test('playlist with content steering and resolvable BaseURLs', function(assert) {
- const representations = [
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn1.example.com/video',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segmentInfo: {
- template: {}
- }
- },
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn2.example.com/video',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segmentInfo: {
- template: {}
- }
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://cdn1.example.com/vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic'
- },
- segmentInfo: {
- template: {}
- }
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://cdn2.example.com/vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic'
- },
- segmentInfo: {}
- }
- ];
- const playlists = [
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn1.example.com/video',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- duration: 0,
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segments: [
- {
- duration: 0,
- map: {
- resolvedUri: 'https://cdn1.example.com/video',
- uri: ''
- },
- number: 1,
- presentationTime: 0,
- resolvedUri: 'https://cdn1.example.com/video',
- timeline: 0,
- uri: ''
- }
- ]
- },
- {
- attributes: {
- bandwidth: 5000000,
- baseUrl: 'https://cdn2.example.com/video',
- clientOffset: 0,
- codecs: 'avc1.64001e',
- duration: 0,
- height: 404,
- id: 'test',
- mimeType: 'video/mp4',
- periodStart: 0,
- role: {
- value: 'main'
- },
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic',
- width: 720
- },
- segments: [
- {
- duration: 0,
- map: {
- resolvedUri: 'https://cdn2.example.com/video',
- uri: ''
- },
- number: 1,
- presentationTime: 0,
- resolvedUri: 'https://cdn2.example.com/video',
- timeline: 0,
- uri: ''
- }
- ]
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://cdn1.example.com/vtt',
- clientOffset: 0,
- duration: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- serviceLocation: 'alpha',
- sourceDuration: 0,
- type: 'dyanmic'
- },
- segments: [
- {
- duration: 0,
- map: {
- resolvedUri: 'https://cdn1.example.com/vtt',
- uri: ''
- },
- number: 1,
- presentationTime: 0,
- resolvedUri: 'https://cdn1.example.com/vtt',
- timeline: 0,
- uri: ''
- }
- ]
- },
- {
- attributes: {
- bandwidth: 256,
- baseUrl: 'https://cdn2.example.com/vtt',
- clientOffset: 0,
- id: 'en',
- lang: 'en',
- mimeType: 'text/vtt',
- periodStart: 0,
- role: {},
- serviceLocation: 'beta',
- sourceDuration: 0,
- type: 'dyanmic'
- }
- }
- ];
- assert.deepEqual(toPlaylists(representations), playlists);
- });
|