|
| 1 | +import CatchupController from '../../src/streaming/controllers/CatchupController'; |
| 2 | +import Settings from '../../src/core/Settings'; |
| 3 | + |
| 4 | +import VideoModelMock from './mocks/VideoModelMock'; |
| 5 | +import DashMetricsMock from './mocks/DashMetricsMock'; |
| 6 | +import StreamControllerMock from './mocks/StreamControllerMock'; |
| 7 | +import StreamMock from './mocks/StreamMock'; |
| 8 | +import MediaPlayerModelMock from './mocks/MediaPlayerModelMock'; |
| 9 | +import PlaybackControllerMock from './mocks/PlaybackControllerMock'; |
| 10 | + |
| 11 | +const expect = require('chai').expect; |
| 12 | +const context = {}; |
| 13 | + |
| 14 | +describe('CatchupController', function () { |
| 15 | + |
| 16 | + let catchupController, |
| 17 | + streamMock, |
| 18 | + videoModelMock, |
| 19 | + dashMetricsMock, |
| 20 | + streamControllerMock, |
| 21 | + playbackControllerMock, |
| 22 | + mediaPlayerModelMock, |
| 23 | + settings; |
| 24 | + |
| 25 | + beforeEach(function () { |
| 26 | + settings = Settings(context).getInstance(); |
| 27 | + videoModelMock = new VideoModelMock(); |
| 28 | + dashMetricsMock = new DashMetricsMock(); |
| 29 | + streamMock = new StreamMock(); |
| 30 | + streamControllerMock = new StreamControllerMock(); |
| 31 | + playbackControllerMock = new PlaybackControllerMock(); |
| 32 | + mediaPlayerModelMock = new MediaPlayerModelMock(); |
| 33 | + |
| 34 | + catchupController = CatchupController(context).getInstance(); |
| 35 | + catchupController.setConfig({ |
| 36 | + videoModel: videoModelMock, |
| 37 | + dashMetrics: dashMetricsMock, |
| 38 | + streamController: streamControllerMock, |
| 39 | + playbackController: playbackControllerMock, |
| 40 | + mediaPlayerModel: mediaPlayerModelMock, |
| 41 | + settings: settings, |
| 42 | + }); |
| 43 | + |
| 44 | + streamControllerMock.initialize([streamMock]); |
| 45 | + }); |
| 46 | + |
| 47 | + afterEach(function () { |
| 48 | + catchupController.reset(); |
| 49 | + catchupController = null; |
| 50 | + }); |
| 51 | + |
| 52 | + describe('Step Algorithm - _stepNeedToCatchUp', function () { |
| 53 | + |
| 54 | + beforeEach(function () { |
| 55 | + let streamInfo = { |
| 56 | + manifestInfo: { |
| 57 | + isDynamic: true, |
| 58 | + availableFrom: new Date() |
| 59 | + }, |
| 60 | + start: 10, |
| 61 | + duration: 600 |
| 62 | + }; |
| 63 | + |
| 64 | + catchupController.initialize(streamInfo); |
| 65 | + streamMock.initialize(streamInfo); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should true when current latency below the live delay', function () { |
| 69 | + expect(catchupController._stepNeedToCatchUp.bind(catchupController)).not.to.throw(); |
| 70 | + |
| 71 | + settings.update({ streaming: |
| 72 | + { |
| 73 | + delay: { liveDelay: 20 }, |
| 74 | + catchup:{ |
| 75 | + step: { |
| 76 | + start: { min: 1, max: 1 }, |
| 77 | + stop: { min: 0.5, max: 0.5 } |
| 78 | + }, |
| 79 | + mode: 'liveCatchupModeStep' |
| 80 | + } |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + expect(catchupController._stepNeedToCatchUp()).to.be.true; |
| 85 | + }); |
| 86 | + |
| 87 | + it('should true when current latency above the live delay', function () { |
| 88 | + expect(catchupController._stepNeedToCatchUp.bind(catchupController)).not.to.throw(); |
| 89 | + |
| 90 | + settings.update({ streaming: |
| 91 | + { |
| 92 | + delay: { liveDelay: 20 }, |
| 93 | + catchup:{ |
| 94 | + step: { |
| 95 | + start: { min: 1, max: 1 }, |
| 96 | + stop: { min: 0.5, max: 0.5 } |
| 97 | + }, |
| 98 | + mode: 'liveCatchupModeStep' |
| 99 | + } |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + expect(catchupController._stepNeedToCatchUp()).to.be.true; |
| 104 | + }); |
| 105 | + |
| 106 | + it('should true when current latency between start and stop min live delay', function () { |
| 107 | + expect(catchupController._stepNeedToCatchUp.bind(catchupController)).not.to.throw(); |
| 108 | + |
| 109 | + settings.update({ streaming: |
| 110 | + { |
| 111 | + delay: { liveDelay: 20 }, |
| 112 | + catchup:{ |
| 113 | + step: { |
| 114 | + start: { min: 1, max: 1 }, |
| 115 | + stop: { min: 0.5, max: 0.5 } |
| 116 | + }, |
| 117 | + mode: 'liveCatchupModeStep' |
| 118 | + } |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + expect(catchupController._stepNeedToCatchUp()).to.be.true; |
| 123 | + }); |
| 124 | + |
| 125 | + it('should true when current latency between start and stop max live delay', function () { |
| 126 | + expect(catchupController._stepNeedToCatchUp.bind(catchupController)).not.to.throw(); |
| 127 | + |
| 128 | + settings.update({ streaming: |
| 129 | + { |
| 130 | + delay: { liveDelay: 20 }, |
| 131 | + catchup:{ |
| 132 | + step: { |
| 133 | + start: { min: 1, max: 1 }, |
| 134 | + stop: { min: 0.5, max: 0.5 } |
| 135 | + }, |
| 136 | + mode: 'liveCatchupModeStep' |
| 137 | + } |
| 138 | + } |
| 139 | + }); |
| 140 | + |
| 141 | + expect(catchupController._stepNeedToCatchUp()).to.be.true; |
| 142 | + }); |
| 143 | + |
| 144 | + }) |
| 145 | +}); |
0 commit comments