MCPcopy
hub / github.com/livekit/livekit / TestCodecChange

Function TestCodecChange

pkg/sfu/buffer/buffer_test.go:329–461  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327}
328
329func TestCodecChange(t *testing.T) {
330 // codec change before bind
331 buff := NewBuffer(123, 1, 1)
332 require.NotNil(t, buff)
333 changedCodec := make(chan webrtc.RTPCodecParameters, 1)
334 buff.OnCodecChange(func(rp webrtc.RTPCodecParameters) {
335 select {
336 case changedCodec <- rp:
337 default:
338 t.Fatalf("codec change not consumed")
339 }
340 })
341 buff.OnStreamRestart(func(reason string) {
342 require.Equal(t, "codec-change", reason)
343
344 // read once to clear pending restart
345 var buf [1500]byte
346 extPkt, err := buff.ReadExtended(buf[:])
347 require.NoError(t, err)
348 require.Nil(t, extPkt)
349 })
350
351 h265Pkt := rtp.Packet{
352 Header: rtp.Header{
353 Version: 2,
354 PayloadType: 116,
355 SequenceNumber: 1,
356 Timestamp: 1,
357 SSRC: 123,
358 },
359 Payload: []byte{0xff, 0xff, 0xff, 0xfd, 0xb4, 0x9f, 0x94, 0x1},
360 }
361 buf, err := h265Pkt.Marshal()
362 require.NoError(t, err)
363 _, err = buff.Write(buf)
364 require.NoError(t, err)
365
366 select {
367 case <-changedCodec:
368 t.Fatalf("unexpected codec change")
369 case <-time.After(100 * time.Millisecond):
370 }
371
372 // Bind sets up VP8 as expected codec,
373 // packet written to the buffer above before Bind is H.265,
374 // that should trigger a codec change and a stream restart
375 // when the queued packets from Write before Bind get flushed
376 buff.Bind(
377 webrtc.RTPParameters{
378 HeaderExtensions: nil,
379 Codecs: []webrtc.RTPCodecParameters{vp8Codec, h265Codec},
380 },
381 vp8Codec.RTPCodecCapability,
382 0,
383 )
384
385 select {
386 case c := <-changedCodec:

Callers

nothing calls this directly

Calls 7

MarshalMethod · 0.95
WriteMethod · 0.95
BindMethod · 0.95
NewBufferFunction · 0.85
OnCodecChangeMethod · 0.65
OnStreamRestartMethod · 0.65
ReadExtendedMethod · 0.65

Tested by

no test coverage detected