From 928af48f04b9e36844788867f6f773adce558b88 Mon Sep 17 00:00:00 2001 From: hexbabe Date: Wed, 5 Feb 2025 09:53:01 -0500 Subject: [PATCH 1/3] Debugging --- config.json | 1 + output.json | 1 + rtsp.go | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 config.json create mode 100644 output.json diff --git a/config.json b/config.json new file mode 100644 index 00000000..b52a5371 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{"creds":[{"user":"","pass":""}],"xaddrs":["192.168.254.254"]} \ No newline at end of file diff --git a/output.json b/output.json new file mode 100644 index 00000000..fb7f46e6 --- /dev/null +++ b/output.json @@ -0,0 +1 @@ +[{"host":"10.1.7.74","rtsp_urls":["rtsp://10.1.7.74:554/stream0?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E","rtsp://10.1.7.74:554/stream1?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E"],"manufacturer":"ONVIF_ICAMERA","model":"F26C_IR_c3","serial_number":"EF00000005087E34","firmware_version":"V3.3.0.6 build 2024-03-14 11:33:02 \n","hardware_id":"1419d68a-1dd2-11b2-a105-F00005087E34"},{"host":"10.1.3.68","rtsp_urls":["rtsp://10.1.3.68:554/stream0?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E","rtsp://10.1.3.68:554/stream1?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E"],"manufacturer":"A_ONVIF_CAMERA","model":"YMA42P_IR_N_AF","serial_number":"EF000000050998FA","firmware_version":"V3.2.5.6 build 2023-12-05 17:52:51 \n","hardware_id":"1419d68a-1dd2-11b2-a105-F000050998FA"},{"host":"10.1.11.241","rtsp_urls":["rtsp://10.1.11.241:554/cam/realmonitor?channel=1\u0026subtype=0\u0026unicast=true\u0026proto=Onvif","rtsp://10.1.11.241:554/cam/realmonitor?channel=1\u0026subtype=1\u0026unicast=true\u0026proto=Onvif"],"manufacturer":"Amcrest","model":"IP5M-T1179EW-AI-V3","serial_number":"AMC1083EC3C8118218","firmware_version":"2.880.00AC001.0.R, Build Date 2023-09-07","hardware_id":"1.00"}] \ No newline at end of file diff --git a/rtsp.go b/rtsp.go index 4fff91b8..c9e9affb 100644 --- a/rtsp.go +++ b/rtsp.go @@ -321,8 +321,16 @@ func (rc *rtspCamera) reconnectClient(codecInfo videoCodec, transport *gortsplib return fmt.Errorf("when calling RTSP DESCRIBE on %s: %w", rc.u, err) } + rc.logger.Infof("SESSION INFO!!! %+v", session) + for _, media := range session.Medias { + rc.logger.Infof("media: %+v", media) + for _, format := range media.Formats { + rc.logger.Infof("format: %+v", format) + rc.logger.Infof("format.RTPMap: %+v", format.RTPMap()) + } + } if codecInfo == Agnostic { - codecInfo = getAvailableCodec(session) + codecInfo = getAvailableCodec(session, rc.logger) } switch codecInfo { @@ -914,7 +922,7 @@ func modelToCodec(model resource.Model) (videoCodec, error) { // getAvailableCodec determines the first supported codec from a session's SDP data // returning Unknown if none are found. -func getAvailableCodec(session *description.Session) videoCodec { +func getAvailableCodec(session *description.Session, logger logging.Logger) videoCodec { var h264 *format.H264 var h265 *format.H265 var mjpeg *format.MJPEG @@ -928,6 +936,8 @@ func getAvailableCodec(session *description.Session) videoCodec { {&mpeg4, MPEG4}, } + logger.Infof("mpeg4 rtpmap: %+v", mpeg4.RTPMap()) + for _, codecFormat := range codecFormats { if session.FindFormat(codecFormat.formatPointer) != nil { return codecFormat.codec From b3792143433c964795f997086f85bf1074299a3c Mon Sep 17 00:00:00 2001 From: hexbabe Date: Wed, 5 Feb 2025 15:31:54 -0500 Subject: [PATCH 2/3] Clean up --- config.json | 1 - output.json | 1 - rtsp.go | 19 ++++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) delete mode 100644 config.json delete mode 100644 output.json diff --git a/config.json b/config.json deleted file mode 100644 index b52a5371..00000000 --- a/config.json +++ /dev/null @@ -1 +0,0 @@ -{"creds":[{"user":"","pass":""}],"xaddrs":["192.168.254.254"]} \ No newline at end of file diff --git a/output.json b/output.json deleted file mode 100644 index fb7f46e6..00000000 --- a/output.json +++ /dev/null @@ -1 +0,0 @@ -[{"host":"10.1.7.74","rtsp_urls":["rtsp://10.1.7.74:554/stream0?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E","rtsp://10.1.7.74:554/stream1?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E"],"manufacturer":"ONVIF_ICAMERA","model":"F26C_IR_c3","serial_number":"EF00000005087E34","firmware_version":"V3.3.0.6 build 2024-03-14 11:33:02 \n","hardware_id":"1419d68a-1dd2-11b2-a105-F00005087E34"},{"host":"10.1.3.68","rtsp_urls":["rtsp://10.1.3.68:554/stream0?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E","rtsp://10.1.3.68:554/stream1?username=admin\u0026password=E10ADC3949BA59ABBE56E057F20F883E"],"manufacturer":"A_ONVIF_CAMERA","model":"YMA42P_IR_N_AF","serial_number":"EF000000050998FA","firmware_version":"V3.2.5.6 build 2023-12-05 17:52:51 \n","hardware_id":"1419d68a-1dd2-11b2-a105-F000050998FA"},{"host":"10.1.11.241","rtsp_urls":["rtsp://10.1.11.241:554/cam/realmonitor?channel=1\u0026subtype=0\u0026unicast=true\u0026proto=Onvif","rtsp://10.1.11.241:554/cam/realmonitor?channel=1\u0026subtype=1\u0026unicast=true\u0026proto=Onvif"],"manufacturer":"Amcrest","model":"IP5M-T1179EW-AI-V3","serial_number":"AMC1083EC3C8118218","firmware_version":"2.880.00AC001.0.R, Build Date 2023-09-07","hardware_id":"1.00"}] \ No newline at end of file diff --git a/rtsp.go b/rtsp.go index c9e9affb..b187ecdd 100644 --- a/rtsp.go +++ b/rtsp.go @@ -321,14 +321,6 @@ func (rc *rtspCamera) reconnectClient(codecInfo videoCodec, transport *gortsplib return fmt.Errorf("when calling RTSP DESCRIBE on %s: %w", rc.u, err) } - rc.logger.Infof("SESSION INFO!!! %+v", session) - for _, media := range session.Medias { - rc.logger.Infof("media: %+v", media) - for _, format := range media.Formats { - rc.logger.Infof("format: %+v", format) - rc.logger.Infof("format.RTPMap: %+v", format.RTPMap()) - } - } if codecInfo == Agnostic { codecInfo = getAvailableCodec(session, rc.logger) } @@ -936,7 +928,16 @@ func getAvailableCodec(session *description.Session, logger logging.Logger) vide {&mpeg4, MPEG4}, } - logger.Infof("mpeg4 rtpmap: %+v", mpeg4.RTPMap()) + logger.Debugf("Session media info: %+v", session) + for _, media := range session.Medias { + for i, format := range media.Formats { + logger.Debugf("Media %d format: %s", i+1, format.Codec()) + logger.Debugf("Format clock rate: %d", format.ClockRate()) + logger.Debugf("Format payload type: %d", format.PayloadType()) + logger.Debugf("Format RTPMap: %s", format.RTPMap()) + logger.Debugf("Format FMTP: %+v", format.FMTP()) + } + } for _, codecFormat := range codecFormats { if session.FindFormat(codecFormat.formatPointer) != nil { From 92de7f222c2ea7d283e10e341affd254d7ae9596 Mon Sep 17 00:00:00 2001 From: hexbabe Date: Wed, 5 Feb 2025 15:34:00 -0500 Subject: [PATCH 3/3] Switch where the code is --- rtsp.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/rtsp.go b/rtsp.go index b187ecdd..ca4474f6 100644 --- a/rtsp.go +++ b/rtsp.go @@ -320,9 +320,19 @@ func (rc *rtspCamera) reconnectClient(codecInfo videoCodec, transport *gortsplib if err != nil { return fmt.Errorf("when calling RTSP DESCRIBE on %s: %w", rc.u, err) } + rc.logger.Debugf("Session media info: %+v", session) + for _, media := range session.Medias { + for i, format := range media.Formats { + rc.logger.Debugf("Media %d format: %s", i+1, format.Codec()) + rc.logger.Debugf("Format clock rate: %d", format.ClockRate()) + rc.logger.Debugf("Format payload type: %d", format.PayloadType()) + rc.logger.Debugf("Format RTPMap: %s", format.RTPMap()) + rc.logger.Debugf("Format FMTP: %+v", format.FMTP()) + } + } if codecInfo == Agnostic { - codecInfo = getAvailableCodec(session, rc.logger) + codecInfo = getAvailableCodec(session) } switch codecInfo { @@ -914,7 +924,7 @@ func modelToCodec(model resource.Model) (videoCodec, error) { // getAvailableCodec determines the first supported codec from a session's SDP data // returning Unknown if none are found. -func getAvailableCodec(session *description.Session, logger logging.Logger) videoCodec { +func getAvailableCodec(session *description.Session) videoCodec { var h264 *format.H264 var h265 *format.H265 var mjpeg *format.MJPEG @@ -928,17 +938,6 @@ func getAvailableCodec(session *description.Session, logger logging.Logger) vide {&mpeg4, MPEG4}, } - logger.Debugf("Session media info: %+v", session) - for _, media := range session.Medias { - for i, format := range media.Formats { - logger.Debugf("Media %d format: %s", i+1, format.Codec()) - logger.Debugf("Format clock rate: %d", format.ClockRate()) - logger.Debugf("Format payload type: %d", format.PayloadType()) - logger.Debugf("Format RTPMap: %s", format.RTPMap()) - logger.Debugf("Format FMTP: %+v", format.FMTP()) - } - } - for _, codecFormat := range codecFormats { if session.FindFormat(codecFormat.formatPointer) != nil { return codecFormat.codec