media_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package core
  2. import (
  3. "fmt"
  4. "net/url"
  5. "testing"
  6. "github.com/pion/sdp/v3"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestSDP(t *testing.T) {
  11. medias := []*Media{{
  12. Kind: KindAudio, Direction: DirectionSendonly,
  13. Codecs: []*Codec{
  14. {Name: CodecPCMU, ClockRate: 8000},
  15. },
  16. }}
  17. data, err := MarshalSDP("go2rtc/1.0.0", medias)
  18. assert.Empty(t, err)
  19. sd := &sdp.SessionDescription{}
  20. err = sd.Unmarshal(data)
  21. assert.Empty(t, err)
  22. }
  23. func TestParseQuery(t *testing.T) {
  24. u, _ := url.Parse("rtsp://localhost:8554/camera1")
  25. medias := ParseQuery(u.Query())
  26. assert.Nil(t, medias)
  27. for _, rawULR := range []string{
  28. "rtsp://localhost:8554/camera1?video",
  29. "rtsp://localhost:8554/camera1?video=copy",
  30. "rtsp://localhost:8554/camera1?video=any",
  31. } {
  32. u, _ = url.Parse(rawULR)
  33. medias = ParseQuery(u.Query())
  34. assert.Equal(t, []*Media{
  35. {Kind: KindVideo, Direction: DirectionSendonly, Codecs: []*Codec{{Name: CodecAny}}},
  36. }, medias)
  37. }
  38. }
  39. func TestClone(t *testing.T) {
  40. media1 := &Media{
  41. Kind: KindVideo,
  42. Direction: DirectionRecvonly,
  43. Codecs: []*Codec{
  44. {Name: CodecPCMU, ClockRate: 8000},
  45. },
  46. }
  47. media2 := media1.Clone()
  48. p1 := fmt.Sprintf("%p", media1)
  49. p2 := fmt.Sprintf("%p", media2)
  50. require.NotEqualValues(t, p1, p2)
  51. p3 := fmt.Sprintf("%p", media1.Codecs[0])
  52. p4 := fmt.Sprintf("%p", media2.Codecs[0])
  53. require.NotEqualValues(t, p3, p4)
  54. }