(t *testing.T)
| 327 | } |
| 328 | |
| 329 | func 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: |
nothing calls this directly
no test coverage detected