@@ -3,11 +3,18 @@ package core
33import (
44 "bufio"
55 "net"
6+ "net/http"
67 "testing"
8+ "time"
79
10+ "github.com/bluenviron/gortsplib/v4"
811 "github.com/bluenviron/gortsplib/v4/pkg/base"
12+ "github.com/bluenviron/gortsplib/v4/pkg/description"
913 "github.com/bluenviron/gortsplib/v4/pkg/headers"
14+ "github.com/pion/rtp"
1015 "github.com/stretchr/testify/require"
16+
17+ "github.com/bluenviron/mediamtx/internal/test"
1118)
1219
1320func TestPathAutoDeletion (t * testing.T ) {
@@ -82,3 +89,97 @@ func TestPathAutoDeletion(t *testing.T) {
8289 })
8390 }
8491}
92+
93+ func TestPathConfigurationHotReload (t * testing.T ) {
94+ // Start MediaMTX with basic configuration
95+ p , ok := newInstance ("api: yes\n " +
96+ "paths:\n " +
97+ " all:\n " +
98+ " record: no\n " )
99+ require .Equal (t , true , ok )
100+ defer p .Close ()
101+
102+ // Set up HTTP client for API calls
103+ tr := & http.Transport {}
104+ defer tr .CloseIdleConnections ()
105+ hc := & http.Client {Transport : tr }
106+
107+ // Create a publisher that will use the "all" configuration
108+ media0 := test .UniqueMediaH264 ()
109+ source := gortsplib.Client {}
110+ err := source .StartRecording (
111+ "rtsp://localhost:8554/undefined_stream" ,
112+ & description.Session {Medias : []* description.Media {media0 }})
113+ require .NoError (t , err )
114+ defer source .Close ()
115+
116+ // Send some data to establish the stream
117+ err = source .WritePacketRTP (media0 , & rtp.Packet {
118+ Header : rtp.Header {
119+ Version : 2 ,
120+ PayloadType : 96 ,
121+ },
122+ Payload : []byte {5 , 1 , 2 , 3 , 4 },
123+ })
124+ require .NoError (t , err )
125+
126+ time .Sleep (100 * time .Millisecond )
127+
128+ // Verify the path exists and is using the "all" configuration
129+ pathData , err := p .pathManager .APIPathsGet ("undefined_stream" )
130+ require .NoError (t , err )
131+ require .Equal (t , "undefined_stream" , pathData .Name )
132+ require .Equal (t , "all" , pathData .ConfName )
133+
134+ // Check the current configuration via API
135+ var allConfig map [string ]interface {}
136+ httpRequest (t , hc , http .MethodGet , "http://localhost:9997/v3/config/paths/get/all" , nil , & allConfig )
137+ require .Equal (t , false , allConfig ["record" ]) // Should be false from "all" config
138+
139+ // Add a new specific configuration for "undefined_stream" with record enabled
140+ httpRequest (t , hc , http .MethodPost , "http://localhost:9997/v3/config/paths/add/undefined_stream" ,
141+ map [string ]interface {}{
142+ "record" : true ,
143+ }, nil )
144+
145+ // Give the system time to process the configuration change
146+ time .Sleep (200 * time .Millisecond )
147+
148+ // Verify the path now uses the new specific configuration
149+ pathData , err = p .pathManager .APIPathsGet ("undefined_stream" )
150+ require .NoError (t , err )
151+ require .Equal (t , "undefined_stream" , pathData .Name )
152+ require .Equal (t , "undefined_stream" , pathData .ConfName ) // Should now use the specific config
153+
154+ // Check the new configuration via API
155+ var newConfig map [string ]interface {}
156+ httpRequest (t , hc , http .MethodGet , "http://localhost:9997/v3/config/paths/get/undefined_stream" , nil , & newConfig )
157+ require .Equal (t , true , newConfig ["record" ]) // Should be true from new config
158+
159+ // Verify the stream is still active and working
160+ err = source .WritePacketRTP (media0 , & rtp.Packet {
161+ Header : rtp.Header {
162+ Version : 2 ,
163+ PayloadType : 96 ,
164+ SequenceNumber : 2 ,
165+ },
166+ Payload : []byte {5 , 1 , 2 , 3 , 4 },
167+ })
168+ require .NoError (t , err )
169+
170+ // Verify the path is still ready and functional
171+ require .Equal (t , true , pathData .Ready )
172+
173+ // revert configuration
174+ httpRequest (t , hc , http .MethodDelete , "http://localhost:9997/v3/config/paths/delete/undefined_stream" ,
175+ nil , nil )
176+
177+ // Give the system time to process the configuration change
178+ time .Sleep (200 * time .Millisecond )
179+
180+ // Verify the path now uses the old configuration
181+ pathData , err = p .pathManager .APIPathsGet ("undefined_stream" )
182+ require .NoError (t , err )
183+ require .Equal (t , "undefined_stream" , pathData .Name )
184+ require .Equal (t , "all" , pathData .ConfName )
185+ }
0 commit comments