@@ -18,11 +18,6 @@ type channelVideoAccessUnitReader struct {
1818 frames <- chan VideoAccessUnit
1919}
2020
21- type signaledVideoAccessUnitReader struct {
22- frames <- chan VideoAccessUnit
23- reads chan <- struct {}
24- }
25-
2621func waitForBroadcastSinkState (t * testing.T , sink * BroadcastSink , predicate func (* BroadcastSink ) bool , description string ) {
2722 t .Helper ()
2823 deadline := time .Now ().Add (time .Second )
@@ -55,15 +50,6 @@ func (r *channelVideoAccessUnitReader) ReadVideoAccessUnit() (VideoAccessUnit, e
5550 return frame , nil
5651}
5752
58- func (r * signaledVideoAccessUnitReader ) ReadVideoAccessUnit () (VideoAccessUnit , error ) {
59- r .reads <- struct {}{}
60- frame , ok := <- r .frames
61- if ! ok {
62- return VideoAccessUnit {}, io .EOF
63- }
64- return frame , nil
65- }
66-
6753func (r * sliceVideoAccessUnitReader ) ReadVideoAccessUnit () (VideoAccessUnit , error ) {
6854 if r .index == len (r .frames ) {
6955 return VideoAccessUnit {}, io .EOF
@@ -115,135 +101,6 @@ func TestBroadcastCapturePreservesTimestampedAccessUnits(t *testing.T) {
115101 }
116102}
117103
118- func TestBroadcastCaptureReplaysDecoderPrimerToLateSink (t * testing.T ) {
119- frames := make (chan VideoAccessUnit )
120- reads := make (chan struct {}, 4 )
121- capture := & ScreenCapture {
122- frames : & signaledVideoAccessUnitReader {frames : frames , reads : reads },
123- waitCh : make (chan struct {}),
124- }
125- broadcast := NewBroadcastCaptureWithFrameRate (capture , 30 )
126- replayPTS := time .Unix (110 , 0 )
127- broadcast .now = func () time.Time { return replayPTS }
128- runDone := make (chan error , 1 )
129- go func () { runDone <- broadcast .Run () }()
130-
131- <- reads
132- primer := VideoAccessUnit {
133- AnnexB : []byte {
134- 0 , 0 , 0 , 1 , 0x67 , 0x42 , 0x00 , 0x1f ,
135- 0 , 0 , 0 , 1 , 0x68 , 0xce , 0x06 , 0xe2 ,
136- 0 , 0 , 0 , 1 , 0x65 , 0x80 ,
137- },
138- PTS : time .Unix (100 , 0 ),
139- }
140- frames <- primer
141- <- reads
142-
143- sink := broadcast .AddSink ()
144- defer sink .Close ()
145- replayDone := make (chan struct {
146- frame VideoAccessUnit
147- err error
148- }, 1 )
149- go func () {
150- frame , err := sink .ReadVideoAccessUnit ()
151- replayDone <- struct {
152- frame VideoAccessUnit
153- err error
154- }{frame : frame , err : err }
155- }()
156- var replayed VideoAccessUnit
157- select {
158- case result := <- replayDone :
159- if result .err != nil {
160- t .Fatalf ("read replayed decoder primer: %v" , result .err )
161- }
162- replayed = result .frame
163- case <- time .After (time .Second ):
164- t .Fatal ("cached decoder primer was not available immediately" )
165- }
166- if ! bytes .Equal (replayed .AnnexB , primer .AnnexB ) {
167- t .Fatalf ("first late-sink frame = %x, want cached decoder primer %x" , replayed .AnnexB , primer .AnnexB )
168- }
169- if ! replayed .PTS .Equal (replayPTS ) {
170- t .Fatalf ("replayed primer PTS = %v, want attachment PTS %v" , replayed .PTS , replayPTS )
171- }
172-
173- boundary := VideoAccessUnit {
174- AnnexB : []byte {0 , 0 , 0 , 1 , 0x61 , 0x40 },
175- PTS : primer .PTS .Add (10 * time .Second ),
176- }
177- frames <- boundary
178- <- reads
179- live := VideoAccessUnit {
180- AnnexB : []byte {0 , 0 , 0 , 1 , 0x61 , 0x80 },
181- PTS : boundary .PTS .Add (time .Second / 30 ),
182- }
183- frames <- live
184- <- reads
185- randomAccess := VideoAccessUnit {
186- AnnexB : []byte {0 , 0 , 0 , 1 , 0x65 , 0x80 },
187- PTS : live .PTS .Add (time .Second / 30 ),
188- }
189- frames <- randomAccess
190- close (frames )
191-
192- next , err := sink .ReadVideoAccessUnit ()
193- if err != nil {
194- t .Fatalf ("read live frame after decoder primer: %v" , err )
195- }
196- if ! bytes .Equal (next .AnnexB , randomAccess .AnnexB ) || ! next .PTS .Equal (randomAccess .PTS ) {
197- t .Fatalf ("live frame after primer = {%x %v}, want random access {%x %v}" , next .AnnexB , next .PTS , randomAccess .AnnexB , randomAccess .PTS )
198- }
199- if err := <- runDone ; ! errors .Is (err , io .EOF ) {
200- t .Fatalf ("broadcast run = %v, want EOF" , err )
201- }
202- }
203-
204- func TestBroadcastCapturePrimerSnapshotSurvivesRefresh (t * testing.T ) {
205- frames := make (chan VideoAccessUnit )
206- reads := make (chan struct {}, 4 )
207- capture := & ScreenCapture {
208- frames : & signaledVideoAccessUnitReader {frames : frames , reads : reads },
209- waitCh : make (chan struct {}),
210- }
211- broadcast := NewBroadcastCapture (capture )
212- broadcast .now = func () time.Time { return time .Unix (120 , 0 ) }
213- runDone := make (chan error , 1 )
214- go func () { runDone <- broadcast .Run () }()
215-
216- first := VideoAccessUnit {AnnexB : []byte {
217- 0 , 0 , 0 , 1 , 0x67 , 0x42 ,
218- 0 , 0 , 0 , 1 , 0x68 , 0xce ,
219- 0 , 0 , 0 , 1 , 0x65 , 0xaa ,
220- }}
221- second := VideoAccessUnit {AnnexB : []byte {
222- 0 , 0 , 0 , 1 , 0x67 , 0x64 ,
223- 0 , 0 , 0 , 1 , 0x68 , 0xee ,
224- 0 , 0 , 0 , 1 , 0x65 , 0xbb ,
225- }}
226- <- reads
227- frames <- first
228- <- reads
229- sink := broadcast .AddSink ()
230- defer sink .Close ()
231- frames <- second
232- <- reads
233-
234- got , err := sink .ReadVideoAccessUnit ()
235- if err != nil {
236- t .Fatalf ("read primer snapshot: %v" , err )
237- }
238- if ! bytes .Equal (got .AnnexB , first .AnnexB ) {
239- t .Fatalf ("primer snapshot = %x, want %x" , got .AnnexB , first .AnnexB )
240- }
241- close (frames )
242- if err := <- runDone ; ! errors .Is (err , io .EOF ) {
243- t .Fatalf ("broadcast run = %v, want EOF" , err )
244- }
245- }
246-
247104func TestBroadcastSinkBackpressuresWithOnePendingAccessUnit (t * testing.T ) {
248105 sink := newBroadcastSinkWithPolicy (nil , true )
249106 base := time .Now ()
0 commit comments