123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- import QUnit from 'qunit';
- import {
- segmentsFromList
- } from '../../src/segment/segmentList';
- import errors from '../../src/errors';
- QUnit.module('segmentList - segmentsFromList');
- QUnit.test('uses segmentTimeline to set segments', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }, {
- media: '3.fmp4'
- }, {
- media: '4.fmp4'
- }, {
- media: '5.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- const inputTimeline = [{
- t: 1000,
- d: 1000,
- r: 4
- }];
- assert.deepEqual(segmentsFromList(inputAttributes, inputTimeline), [{
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 1000,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 2000,
- uri: '2.fmp4',
- number: 2
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/3.fmp4',
- timeline: 0,
- presentationTime: 3000,
- uri: '3.fmp4',
- number: 3
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/4.fmp4',
- timeline: 0,
- presentationTime: 4000,
- uri: '4.fmp4',
- number: 4
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/5.fmp4',
- timeline: 0,
- presentationTime: 5000,
- uri: '5.fmp4',
- number: 5
- }]);
- });
- QUnit.test(
- 'truncates if segmentTimeline does not apply for all segments',
- function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }, {
- media: '3.fmp4'
- }, {
- media: '4.fmp4'
- }, {
- media: '5.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- const inputTimeline = [{
- t: 1000,
- d: 1000,
- r: 1
- }];
- assert.deepEqual(segmentsFromList(inputAttributes, inputTimeline), [{
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 1000,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 2000,
- uri: '2.fmp4',
- number: 2
- }]);
- }
- );
- QUnit.test(
- 'if segment timeline is too long does not add extra blank segments',
- function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }, {
- media: '3.fmp4'
- }, {
- media: '4.fmp4'
- }, {
- media: '5.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- const inputTimeline = [{
- t: 1000,
- d: 1000,
- r: 10
- }];
- assert.deepEqual(segmentsFromList(inputAttributes, inputTimeline), [{
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 1000,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 2000,
- uri: '2.fmp4',
- number: 2
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/3.fmp4',
- timeline: 0,
- presentationTime: 3000,
- uri: '3.fmp4',
- number: 3
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/4.fmp4',
- timeline: 0,
- presentationTime: 4000,
- uri: '4.fmp4',
- number: 4
- }, {
- duration: 1000,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/5.fmp4',
- timeline: 0,
- presentationTime: 5000,
- uri: '5.fmp4',
- number: 5
- }]);
- }
- );
- QUnit.test('uses duration to set segments', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }, {
- media: '3.fmp4'
- }, {
- media: '4.fmp4'
- }, {
- media: '5.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- duration: 10,
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- sourceDuration: 50,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.deepEqual(segmentsFromList(inputAttributes), [{
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '2.fmp4',
- number: 2
- }, {
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/3.fmp4',
- timeline: 0,
- presentationTime: 20,
- uri: '3.fmp4',
- number: 3
- }, {
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/4.fmp4',
- timeline: 0,
- presentationTime: 30,
- uri: '4.fmp4',
- number: 4
- }, {
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/5.fmp4',
- timeline: 0,
- presentationTime: 40,
- uri: '5.fmp4',
- number: 5
- }]);
- });
- QUnit.test('uses timescale to set segment duration', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }, {
- media: '3.fmp4'
- }, {
- media: '4.fmp4'
- }, {
- media: '5.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- duration: 10,
- timescale: 2,
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- sourceDuration: 25,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.deepEqual(segmentsFromList(inputAttributes), [{
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 5,
- uri: '2.fmp4',
- number: 2
- }, {
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/3.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '3.fmp4',
- number: 3
- }, {
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/4.fmp4',
- timeline: 0,
- presentationTime: 15,
- uri: '4.fmp4',
- number: 4
- }, {
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/5.fmp4',
- timeline: 0,
- presentationTime: 20,
- uri: '5.fmp4',
- number: 5
- }]);
- });
- QUnit.test('timescale sets duration of last segment correctly', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- duration: 10,
- timescale: 1,
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- sourceDuration: 15,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.deepEqual(segmentsFromList(inputAttributes), [{
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 5,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/2.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '2.fmp4',
- number: 2
- }]);
- });
- QUnit.test('segmentUrl translates ranges correctly', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4',
- mediaRange: '0-200'
- }, {
- media: '1.fmp4',
- mediaRange: '201-400'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- duration: 10,
- timescale: 1,
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- sourceDuration: 20,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.deepEqual(segmentsFromList(inputAttributes), [{
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- byterange: {
- length: 201,
- offset: 0
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 10,
- byterange: {
- length: 200,
- offset: 201
- },
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4'
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '1.fmp4',
- number: 2
- }]);
- });
- QUnit.test(
- 'throws error if more than 1 segment and no duration or timeline',
- function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }],
- duration: 10,
- initialization: { sourceURL: 'init.fmp4' },
- timescale: 1,
- periodIndex: 0,
- startNumber: 1,
- sourceDuration: 20,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- const inputTimeline = [{
- t: 1000,
- d: 1000,
- r: 4
- }];
- assert.throws(
- () => segmentsFromList(inputAttributes, inputTimeline),
- new Error(errors.SEGMENT_TIME_UNSPECIFIED)
- );
- }
- );
- QUnit.test('throws error if timeline and duration are both defined', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '2.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4' },
- timescale: 1,
- periodIndex: 0,
- startNumber: 1,
- sourceDuration: 20,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.throws(
- () => segmentsFromList(inputAttributes),
- new Error(errors.SEGMENT_TIME_UNSPECIFIED)
- );
- });
- QUnit.test('translates ranges in <Initialization> node', function(assert) {
- const inputAttributes = {
- segmentUrls: [{
- media: '1.fmp4'
- }, {
- media: '1.fmp4'
- }],
- initialization: { sourceURL: 'init.fmp4', range: '121-125' },
- duration: 10,
- timescale: 1,
- periodIndex: 0,
- periodStart: 0,
- startNumber: 1,
- sourceDuration: 20,
- baseUrl: 'http://example.com/',
- type: 'static'
- };
- assert.deepEqual(segmentsFromList(inputAttributes), [{
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4',
- byterange: {
- length: 5,
- offset: 121
- }
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 0,
- uri: '1.fmp4',
- number: 1
- }, {
- duration: 10,
- map: {
- resolvedUri: 'http://example.com/init.fmp4',
- uri: 'init.fmp4',
- byterange: {
- length: 5,
- offset: 121
- }
- },
- resolvedUri: 'http://example.com/1.fmp4',
- timeline: 0,
- presentationTime: 10,
- uri: '1.fmp4',
- number: 2
- }]);
- });
|