@@ -4,12 +4,23 @@ import {expect} from 'chai';
44const context = { } ;
55
66describe ( 'PreBufferSink' , function ( ) {
7- function makeChunk ( start , end , data ) {
7+ function makeInit ( representation ) {
8+ const init = {
9+ data : 'init segment' ,
10+ segmentType : 'InitializationSegment' ,
11+ representation : representation || { id : 'representation1' }
12+ } ;
13+
14+ return init ;
15+ }
16+
17+ function makeChunk ( start , end , representation ) {
818 const chunk = {
919 start : start || 0 ,
1020 end : end || 4 ,
11- data : data || 'chickens' ,
12- segmentType : 'data'
21+ data : 'chickens' ,
22+ segmentType : 'data' ,
23+ representation : representation || { id : 'representation1' }
1324 } ;
1425
1526 return chunk ;
@@ -34,15 +45,19 @@ describe('PreBufferSink', function () {
3445 expect ( chunk . data ) . to . equal ( 'chickens' ) ;
3546 } ) ;
3647
37- it ( 'should take a series of chunks and return them in chronological order on discharge' , function ( ) {
48+ it ( 'should take a series of chunks and corresponding inits and return them in chronological order on discharge' , function ( ) {
49+ const representation2 = { id : 'representation2' } ;
50+ sink . append ( makeInit ( ) ) ;
3851 sink . append ( makeChunk ( 4 , 8 ) ) ;
39- sink . append ( makeChunk ( 12 , 16 ) ) ;
40- sink . append ( makeChunk ( 16 , 20 ) ) ;
52+ sink . append ( makeInit ( representation2 ) ) ;
53+ sink . append ( makeChunk ( 12 , 16 , representation2 ) ) ;
54+ sink . append ( makeChunk ( 16 , 20 , representation2 ) ) ;
55+ sink . append ( makeInit ( ) ) ;
4156 sink . append ( makeChunk ( 0 , 4 ) ) ;
4257 sink . append ( makeChunk ( 8 , 12 ) ) ;
4358
4459 const chunkList = sink . discharge ( ) ;
45- expect ( chunkList ) . to . have . length ( 5 ) ;
60+ expect ( chunkList ) . to . have . length ( 7 ) ;
4661
4762 let lastStart , lastEnd ;
4863 for ( let i = 0 ; i < chunkList . length ; i ++ ) {
@@ -54,65 +69,52 @@ describe('PreBufferSink', function () {
5469 lastStart = chunk . start ;
5570 lastEnd = chunk . end ;
5671 }
72+
73+ expect ( chunkList [ 0 ] . segmentType ) . to . equal ( 'InitializationSegment' ) ;
74+ expect ( chunkList [ 0 ] . representation . id ) . to . equal ( 'representation1' ) ;
75+
76+ expect ( chunkList [ 4 ] . segmentType ) . to . equal ( 'InitializationSegment' ) ;
77+ expect ( chunkList [ 4 ] . representation . id ) . to . equal ( 'representation2' ) ;
5778 } ) ;
5879
5980 it ( 'should return an init segment if it is the last segment that is passed in' , function ( ) {
60- const chunk = makeChunk ( ) ;
61- chunk . segmentType = 'InitializationSegment' ;
62-
63- sink . append ( chunk ) ;
81+ sink . append ( makeInit ( ) ) ;
82+ sink . append ( makeChunk ( ) ) ;
83+ sink . append ( makeInit ( { id : 'representation2' } ) ) ;
6484
6585 const chunkList = sink . discharge ( ) ;
66- expect ( chunkList ) . to . have . length ( 1 ) ;
86+ expect ( chunkList ) . to . have . length ( 3 ) ;
6787 } ) ;
6888
69- it ( 'should not return an init segment if other media segments are passed in afterwards' , function ( ) {
70- const chunk = makeChunk ( ) ;
71- chunk . segmentType = 'InitializationSegment' ;
89+ it ( 'should not return an init segment last if other media segments are passed in afterwards' , function ( ) {
90+ const init = makeInit ( ) ;
7291
73- sink . append ( chunk ) ;
92+ sink . append ( init ) ;
7493 sink . append ( makeChunk ( 0 , 4 ) ) ;
7594
7695 const chunkList = sink . discharge ( ) ;
77- expect ( chunkList ) . to . have . length ( 1 ) ;
78- expect ( chunkList [ 0 ] . segmentType ) . to . equal ( 'data' ) ;
79- } ) ;
80-
81- it ( 'should discharge only over a specified timerange' , function ( ) {
82- sink . append ( makeChunk ( 0 , 4 ) ) ;
83- sink . append ( makeChunk ( 4 , 8 ) ) ;
84- sink . append ( makeChunk ( 8 , 12 ) ) ;
85- sink . append ( makeChunk ( 12 , 16 ) ) ;
86- sink . append ( makeChunk ( 16 , 20 ) ) ;
87-
88- const chunkList = sink . discharge ( 0 , 12 ) ;
89- expect ( chunkList ) . to . have . length ( 3 ) ;
90-
91- expect ( chunkList [ 0 ] . start ) . to . equal ( 0 ) ;
92- expect ( chunkList [ 1 ] . start ) . to . equal ( 4 ) ;
93- expect ( chunkList [ 2 ] . start ) . to . equal ( 8 ) ;
96+ expect ( chunkList ) . to . have . length ( 2 ) ;
97+ expect ( chunkList [ 0 ] . segmentType ) . to . equal ( 'InitializationSegment' ) ;
98+ expect ( chunkList [ 1 ] . segmentType ) . to . equal ( 'data' ) ;
9499 } ) ;
95100
96101 it ( 'should remove chunks after they have been discharged' , function ( ) {
102+ sink . append ( makeInit ( ) ) ;
97103 sink . append ( makeChunk ( 0 , 4 ) ) ;
98104 sink . append ( makeChunk ( 4 , 8 ) ) ;
99105 sink . append ( makeChunk ( 8 , 12 ) ) ;
100106 sink . append ( makeChunk ( 12 , 16 ) ) ;
101107 sink . append ( makeChunk ( 16 , 20 ) ) ;
102108
103- const chunkList = sink . discharge ( 0 , 12 ) ;
104- expect ( chunkList ) . to . have . length ( 3 ) ;
105-
106- const emptyChunkList = sink . discharge ( 0 , 12 ) ;
107- expect ( emptyChunkList ) . to . have . length ( 0 ) ;
108-
109- const remainingChunkList = sink . discharge ( 12 , 20 ) ;
110- expect ( remainingChunkList ) . to . have . length ( 2 ) ;
109+ const chunkList = sink . discharge ( ) ;
110+ expect ( chunkList ) . to . have . length ( 6 ) ;
111+ expect ( sink . getAllBufferRanges ( ) . length ) . to . equal ( 0 ) ;
111112 } ) ;
112113 } ) ;
113114
114115 describe ( 'getAllBufferRanges' , function ( ) {
115116 it ( 'should report the buffer ranges of the chunks that have been added' , function ( ) {
117+ sink . append ( makeInit ( ) ) ;
116118 sink . append ( makeChunk ( 0 , 4 ) ) ;
117119 sink . append ( makeChunk ( 4 , 8 ) ) ;
118120 sink . append ( makeChunk ( 12 , 16 ) ) ;
@@ -131,6 +133,7 @@ describe('PreBufferSink', function () {
131133
132134 describe ( 'Reset' , function ( ) {
133135 it ( 'should have no segments left after it has reset' , function ( ) {
136+ sink . append ( makeInit ( ) ) ;
134137 sink . append ( makeChunk ( 0 , 4 ) ) ;
135138 sink . append ( makeChunk ( 4 , 8 ) ) ;
136139 sink . append ( makeChunk ( 8 , 12 ) ) ;
0 commit comments