@@ -22,6 +22,7 @@ pub struct OnvifCameraContext {
22
22
pub device : OnvifDevice ,
23
23
pub device_information : OnvifDeviceInformation ,
24
24
pub streams_information : Option < Vec < OnvifStreamInformation > > ,
25
+ pub credentials : Option < soap:: client:: Credentials > ,
25
26
devicemgmt : soap:: client:: Client ,
26
27
event : Option < soap:: client:: Client > ,
27
28
deviceio : Option < soap:: client:: Client > ,
@@ -78,6 +79,7 @@ impl OnvifCamera {
78
79
device : device. clone ( ) ,
79
80
device_information,
80
81
streams_information : None ,
82
+ credentials : creds. clone ( ) ,
81
83
devicemgmt,
82
84
imaging : None ,
83
85
ptz : None ,
@@ -148,9 +150,10 @@ impl OnvifCamera {
148
150
// Sometimes a camera responds empty, so we try a couple of times to improve our reliability
149
151
let mut tries = 10 ;
150
152
let new_streams_information = loop {
151
- let new_streams_information = OnvifCamera :: get_streams_information ( & media_client)
152
- . await
153
- . context ( "Failed to get streams information" ) ?;
153
+ let new_streams_information =
154
+ OnvifCamera :: get_streams_information ( & media_client, & context. credentials )
155
+ . await
156
+ . context ( "Failed to get streams information" ) ?;
154
157
155
158
if new_streams_information. is_empty ( ) {
156
159
if tries == 0 {
@@ -172,6 +175,7 @@ impl OnvifCamera {
172
175
#[ instrument( level = "trace" , skip_all) ]
173
176
async fn get_streams_information (
174
177
media_client : & soap:: client:: Client ,
178
+ credentials : & Option < soap:: client:: Credentials > ,
175
179
) -> Result < Vec < OnvifStreamInformation > , transport:: Error > {
176
180
let mut streams_information = vec ! [ ] ;
177
181
@@ -206,7 +210,7 @@ impl OnvifCamera {
206
210
trace ! ( "token={} name={}" , & profile. token. 0 , & profile. name. 0 ) ;
207
211
trace ! ( "\t {}" , & stream_uri_response. media_uri. uri) ;
208
212
209
- let stream_uri = match url:: Url :: parse ( & stream_uri_response. media_uri . uri ) {
213
+ let mut stream_uri = match url:: Url :: parse ( & stream_uri_response. media_uri . uri ) {
210
214
Ok ( stream_url) => stream_url,
211
215
Err ( error) => {
212
216
error ! (
@@ -222,7 +226,25 @@ impl OnvifCamera {
222
226
continue ;
223
227
} ;
224
228
229
+ if let Some ( credentials) = & credentials {
230
+ if stream_uri. set_username ( & credentials. username ) . is_err ( ) {
231
+ warn ! ( "Failed setting username" ) ;
232
+ continue ;
233
+ }
234
+
235
+ if stream_uri
236
+ . set_password ( Some ( & credentials. password ) )
237
+ . is_err ( )
238
+ {
239
+ warn ! ( "Failed setting password" ) ;
240
+ continue ;
241
+ }
242
+
243
+ trace ! ( "Using credentials {credentials:?}" ) ;
244
+ }
245
+
225
246
let Some ( encode) = get_encode_from_rtspsrc ( & stream_uri) . await else {
247
+ warn ! ( "Failed getting encoding from RTSP stream at {stream_uri}" ) ;
226
248
continue ;
227
249
} ;
228
250
0 commit comments