mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 23:02:45 +08:00
client: do not override media controls inside Announce()
this fixes the client-read-republish example and allows users to set their own media controls. Function medias.SetControls() is provided in order to automatically set media controls and must be called manually.
This commit is contained in:
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user