diff --git a/client.go b/client.go index 67f9ad8a..baabc4cb 100644 --- a/client.go +++ b/client.go @@ -1059,8 +1059,6 @@ func (c *Client) doAnnounce(u *url.URL, medias media.Medias) (*base.Response, er return nil, err } - medias.SetControls() - byts, err := medias.Marshal(false).Marshal() if err != nil { return nil, err diff --git a/client_record_test.go b/client_record_test.go index 4ad92d8c..7662bd1b 100644 --- a/client_record_test.go +++ b/client_record_test.go @@ -277,6 +277,7 @@ func TestClientRecordSerial(t *testing.T) { medi := testH264Media.Clone() medias := media.Medias{medi} + medias.SetControls() err = record(&c, scheme+"://localhost:8554/teststream", medias, func(medi *media.Media, pkt rtcp.Packet) { @@ -431,7 +432,10 @@ func TestClientRecordParallel(t *testing.T) { defer func() { <-writerDone }() medi := testH264Media.Clone() - err = record(&c, scheme+"://localhost:8554/teststream", media.Medias{medi}, nil) + medias := media.Medias{medi} + medias.SetControls() + + err = record(&c, scheme+"://localhost:8554/teststream", medias, nil) require.NoError(t, err) defer c.Close() @@ -581,7 +585,10 @@ func TestClientRecordPauseSerial(t *testing.T) { } medi := testH264Media.Clone() - err = record(&c, "rtsp://localhost:8554/teststream", media.Medias{medi}, nil) + medias := media.Medias{medi} + medias.SetControls() + + err = record(&c, "rtsp://localhost:8554/teststream", medias, nil) require.NoError(t, err) defer c.Close() @@ -709,7 +716,10 @@ func TestClientRecordPauseParallel(t *testing.T) { } medi := testH264Media.Clone() - err = record(&c, "rtsp://localhost:8554/teststream", media.Medias{medi}, nil) + medias := media.Medias{medi} + medias.SetControls() + + err = record(&c, "rtsp://localhost:8554/teststream", medias, nil) require.NoError(t, err) writerDone := make(chan struct{}) @@ -846,7 +856,10 @@ func TestClientRecordAutomaticProtocol(t *testing.T) { c := Client{} medi := testH264Media.Clone() - err = record(&c, "rtsp://localhost:8554/teststream", media.Medias{medi}, nil) + medias := media.Medias{medi} + medias.SetControls() + + err = record(&c, "rtsp://localhost:8554/teststream", medias, nil) require.NoError(t, err) defer c.Close() @@ -1025,7 +1038,10 @@ func TestClientRecordDecodeErrors(t *testing.T) { }, } - err = record(&c, "rtsp://localhost:8554/stream", media.Medias{testH264Media.Clone()}, nil) + medias := media.Medias{testH264Media.Clone()} + medias.SetControls() + + err = record(&c, "rtsp://localhost:8554/stream", medias, nil) require.NoError(t, err) defer c.Close() @@ -1181,7 +1197,10 @@ func TestClientRecordRTCPReport(t *testing.T) { } medi := testH264Media.Clone() - err = record(&c, "rtsp://localhost:8554/teststream", media.Medias{medi}, nil) + medias := media.Medias{medi} + medias.SetControls() + + err = record(&c, "rtsp://localhost:8554/teststream", medias, nil) require.NoError(t, err) defer c.Close() @@ -1308,6 +1327,7 @@ func TestClientRecordIgnoreTCPRTPPackets(t *testing.T) { } medias := media.Medias{testH264Media.Clone()} + medias.SetControls() err = record(&c, "rtsp://localhost:8554/teststream", medias, func(medi *media.Media, pkt rtcp.Packet) { diff --git a/examples/client-publish-format-g711/main.go b/examples/client-publish-format-g711/main.go index 8e1426ac..a2e33b05 100644 --- a/examples/client-publish-format-g711/main.go +++ b/examples/client-publish-format-g711/main.go @@ -36,16 +36,16 @@ func main() { log.Println("stream connected") // create a media that contains a G711 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.G711{}}, - } + }} + medias.SetControls() c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -60,7 +60,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-g722/main.go b/examples/client-publish-format-g722/main.go index d1643833..e80f0a3f 100644 --- a/examples/client-publish-format-g722/main.go +++ b/examples/client-publish-format-g722/main.go @@ -36,16 +36,16 @@ func main() { log.Println("stream connected") // create a media that contains a G722 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.G722{}}, - } + }} + medias.SetControls() c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -60,7 +60,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-h264/main.go b/examples/client-publish-format-h264/main.go index 9dd225d1..1fee630a 100644 --- a/examples/client-publish-format-h264/main.go +++ b/examples/client-publish-format-h264/main.go @@ -37,18 +37,18 @@ func main() { log.Println("stream connected") // create a media that contains a H264 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -63,7 +63,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-h265/main.go b/examples/client-publish-format-h265/main.go index 3fa9e113..4cd422bd 100644 --- a/examples/client-publish-format-h265/main.go +++ b/examples/client-publish-format-h265/main.go @@ -37,17 +37,17 @@ func main() { log.Println("stream connected") // create a media that contains a H265 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H265{ PayloadTyp: 96, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -62,7 +62,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-lpcm/main.go b/examples/client-publish-format-lpcm/main.go index 6f71932d..ad66b878 100644 --- a/examples/client-publish-format-lpcm/main.go +++ b/examples/client-publish-format-lpcm/main.go @@ -36,7 +36,7 @@ func main() { log.Println("stream connected") // create a media that contains a LPCM format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.LPCM{ PayloadTyp: 96, @@ -44,13 +44,13 @@ func main() { SampleRate: 44100, ChannelCount: 1, }}, - } + }} + medias.SetControls() c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -65,7 +65,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-mpeg4audio/main.go b/examples/client-publish-format-mpeg4audio/main.go index fae9c508..a24eb6d4 100644 --- a/examples/client-publish-format-mpeg4audio/main.go +++ b/examples/client-publish-format-mpeg4audio/main.go @@ -37,7 +37,7 @@ func main() { log.Println("stream connected") // create a media that contains a MPEG4-audio format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.MPEG4Audio{ PayloadTyp: 96, @@ -50,12 +50,12 @@ func main() { IndexLength: 3, IndexDeltaLength: 3, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -70,7 +70,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-opus/main.go b/examples/client-publish-format-opus/main.go index 59887ce9..70da9459 100644 --- a/examples/client-publish-format-opus/main.go +++ b/examples/client-publish-format-opus/main.go @@ -36,20 +36,20 @@ func main() { log.Println("stream connected") // create a media that contains a Opus format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeAudio, Formats: []format.Format{&format.Opus{ PayloadTyp: 96, SampleRate: 48000, ChannelCount: 2, }}, - } + }} + medias.SetControls() c := gortsplib.Client{} // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -64,7 +64,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-vp8/main.go b/examples/client-publish-format-vp8/main.go index 84c0b018..7eea8ce0 100644 --- a/examples/client-publish-format-vp8/main.go +++ b/examples/client-publish-format-vp8/main.go @@ -37,17 +37,17 @@ func main() { log.Println("stream connected") // create a media that contains a VP8 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.VP8{ PayloadTyp: 96, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -62,7 +62,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-format-vp9/main.go b/examples/client-publish-format-vp9/main.go index b720540b..ef80e06b 100644 --- a/examples/client-publish-format-vp9/main.go +++ b/examples/client-publish-format-vp9/main.go @@ -37,17 +37,17 @@ func main() { log.Println("stream connected") // create a media that contains a VP9 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.VP9{ PayloadTyp: 96, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -62,7 +62,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-options/main.go b/examples/client-publish-options/main.go index 9e71267b..2c822025 100644 --- a/examples/client-publish-options/main.go +++ b/examples/client-publish-options/main.go @@ -38,13 +38,14 @@ func main() { log.Println("stream connected") // create a media that contains a H264 media - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - } + }} + medias.SetControls() // Client allows to set additional client options c := &gortsplib.Client{ @@ -57,8 +58,7 @@ func main() { } // connect to the server and start recording the media - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -73,7 +73,7 @@ func main() { } // route RTP packet to the server - err = c.WritePacketRTP(medi, &pkt) + err = c.WritePacketRTP(medias[0], &pkt) if err != nil { panic(err) } diff --git a/examples/client-publish-pause/main.go b/examples/client-publish-pause/main.go index f7ca9c75..28c3aa39 100644 --- a/examples/client-publish-pause/main.go +++ b/examples/client-publish-pause/main.go @@ -39,18 +39,18 @@ func main() { log.Println("stream connected") // create a media that contains a H264 format - medi := &media.Media{ + medias := media.Medias{&media.Media{ Type: media.TypeVideo, Formats: []format.Format{&format.H264{ PayloadTyp: 96, PacketizationMode: 1, }}, - } + }} + medias.SetControls() // connect to the server and start recording the media c := gortsplib.Client{} - err = c.StartRecording("rtsp://localhost:8554/mystream", - media.Medias{medi}) + err = c.StartRecording("rtsp://localhost:8554/mystream", medias) if err != nil { panic(err) } @@ -67,7 +67,7 @@ func main() { } // route RTP packet to the server - c.WritePacketRTP(medi, &pkt) + c.WritePacketRTP(medias[0], &pkt) // read another RTP packet from source n, _, err = pc.ReadFrom(buf)