Skip to content

Commit 5938ea4

Browse files
committed
convert example into test
1 parent 61cce8e commit 5938ea4

File tree

5 files changed

+129
-214
lines changed

5 files changed

+129
-214
lines changed

examples/server-per-stream-multicast-settings/main.go

Lines changed: 0 additions & 211 deletions
This file was deleted.

pkg/rtpreceiver/receiver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"github.com/pion/rtp"
1212
)
1313

14-
// Receiver is a utility to receive RTP packets. It is in charge of:
14+
// Receiver is a utility to receive RTP packets.
15+
// It is in charge of:
1516
// - removing duplicate packets (when transport is unreliable)
1617
// - reordering packets (when transport is unrealiable)
1718
// - counting received and lost packets

pkg/rtpsender/sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// Sender is a utility to send RTP packets.
14-
// It is in charge of
14+
// It is in charge of:
1515
// - counting sent packets
1616
// - generating RTCP sender reports.
1717
type Sender struct {

server_play_test.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/bluenviron/gortsplib/v5/pkg/mikey"
2727
"github.com/bluenviron/gortsplib/v5/pkg/ntp"
2828
"github.com/bluenviron/gortsplib/v5/pkg/sdp"
29+
"github.com/bluenviron/mediacommon/v2/pkg/codecs/mpeg4audio"
2930
)
3031

3132
func multicastCapableIP(t *testing.T) string {
@@ -2788,3 +2789,127 @@ func TestServerPlayBackChannel(t *testing.T) {
27882789
})
27892790
}
27902791
}
2792+
2793+
func TestServerPlayMulticastParams(t *testing.T) {
2794+
listenIP := multicastCapableIP(t)
2795+
2796+
var stream *ServerStream
2797+
2798+
s := &Server{
2799+
Handler: &testServerHandler{
2800+
onDescribe: func(_ *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
2801+
return &base.Response{
2802+
StatusCode: base.StatusOK,
2803+
}, stream, nil
2804+
},
2805+
onSetup: func(_ *ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error) {
2806+
return &base.Response{
2807+
StatusCode: base.StatusOK,
2808+
}, stream, nil
2809+
},
2810+
onPlay: func(_ *ServerHandlerOnPlayCtx) (*base.Response, error) {
2811+
return &base.Response{
2812+
StatusCode: base.StatusOK,
2813+
}, nil
2814+
},
2815+
},
2816+
RTSPAddress: listenIP + ":8554",
2817+
MulticastIPRange: "224.1.0.0/16",
2818+
MulticastRTPPort: 8000,
2819+
MulticastRTCPPort: 8001,
2820+
}
2821+
2822+
err := s.Start()
2823+
require.NoError(t, err)
2824+
defer s.Close()
2825+
2826+
media1 := &description.Media{
2827+
Type: description.MediaTypeVideo,
2828+
Formats: []format.Format{&format.H264{
2829+
PayloadTyp: 96,
2830+
SPS: []byte{
2831+
0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00, 0x78, 0x02,
2832+
0x27, 0xe5, 0x84, 0x00, 0x00, 0x03, 0x00, 0x04,
2833+
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9,
2834+
0x20,
2835+
},
2836+
PPS: []byte{
2837+
0x44, 0x01, 0xc0, 0x25, 0x2f, 0x05, 0x32, 0x40,
2838+
},
2839+
PacketizationMode: 1,
2840+
}},
2841+
}
2842+
2843+
media2 := &description.Media{
2844+
Type: description.MediaTypeAudio,
2845+
Formats: []format.Format{&format.MPEG4Audio{
2846+
PayloadTyp: 97,
2847+
Config: &mpeg4audio.AudioSpecificConfig{
2848+
Type: mpeg4audio.ObjectTypeAACLC,
2849+
SampleRate: 48000,
2850+
ChannelCount: 2,
2851+
},
2852+
SizeLength: 13,
2853+
IndexLength: 3,
2854+
IndexDeltaLength: 3,
2855+
}},
2856+
}
2857+
2858+
multicastParams := map[*description.Media]StreamMediaMulticastParams{
2859+
media1: {
2860+
IP: net.ParseIP("224.2.0.50"),
2861+
RTPPort: 9000,
2862+
RTCPPort: 9001,
2863+
},
2864+
media2: {
2865+
IP: net.ParseIP("224.2.0.51"),
2866+
RTPPort: 9002,
2867+
RTCPPort: 9003,
2868+
},
2869+
}
2870+
2871+
stream = &ServerStream{
2872+
Server: s,
2873+
Desc: &description.Session{
2874+
Medias: []*description.Media{media1, media2},
2875+
},
2876+
MulticastParams: multicastParams,
2877+
}
2878+
err = stream.Initialize()
2879+
require.NoError(t, err)
2880+
defer stream.Close()
2881+
2882+
nconn, err := net.Dial("tcp", listenIP+":8554")
2883+
require.NoError(t, err)
2884+
defer nconn.Close()
2885+
conn := conn.NewConn(bufio.NewReader(nconn), nconn)
2886+
2887+
desc := doDescribe(t, conn, false)
2888+
2889+
inTH1 := &headers.Transport{
2890+
Delivery: ptrOf(headers.TransportDeliveryMulticast),
2891+
Protocol: headers.TransportProtocolUDP,
2892+
Mode: ptrOf(headers.TransportModePlay),
2893+
}
2894+
2895+
res1, th1 := doSetup(t, conn, mediaURL(t, desc.BaseURL, desc.Medias[0]).String(), inTH1, "")
2896+
session := readSession(t, res1)
2897+
2898+
require.Equal(t, headers.TransportProtocolUDP, th1.Protocol)
2899+
require.Equal(t, headers.TransportDeliveryMulticast, *th1.Delivery)
2900+
require.Equal(t, "224.2.0.50", *th1.Destination2)
2901+
require.Equal(t, [2]int{9000, 9001}, *th1.Ports)
2902+
2903+
inTH2 := &headers.Transport{
2904+
Delivery: ptrOf(headers.TransportDeliveryMulticast),
2905+
Protocol: headers.TransportProtocolUDP,
2906+
Mode: ptrOf(headers.TransportModePlay),
2907+
}
2908+
2909+
_, th2 := doSetup(t, conn, mediaURL(t, desc.BaseURL, desc.Medias[1]).String(), inTH2, session)
2910+
2911+
require.Equal(t, headers.TransportProtocolUDP, th2.Protocol)
2912+
require.Equal(t, headers.TransportDeliveryMulticast, *th2.Delivery)
2913+
require.Equal(t, "224.2.0.51", *th2.Destination2)
2914+
require.Equal(t, [2]int{9002, 9003}, *th2.Ports)
2915+
}

server_stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type StreamMediaMulticastParams struct {
3333
RTCPPort int
3434
}
3535

36-
// ServerStream represents a data stream.
36+
// ServerStream represents a media stream.
3737
// This is in charge of
3838
// - storing stream description and statistics
3939
// - distributing the stream to each reader

0 commit comments

Comments
 (0)