I am trying to do a rtsp live streaming POC with GO and rtsplib from github/bluenviron/gortsplib/v4. One thing I cannot seem to find in the docs is how to handle digest authentication. The camera I am trying to connect to is using digest authentication and the docs state that a DESCRIBE method must be done to get a 401 response with the digest details in the headers and then a second DESCRIBE request with the MD5 details and the digest headers generated from the app must be done. One of the problems I encountered is that the library has a client instance that can do describe requests, but when the error comes back it just errors out as a string without possibility of reading the headers. So I don´t know if I am using the client correctly. The second thing is that I was able to make the first request from the "net"package but after I get the MD5 details I do not know how to add the digest auth into the describe method for the client and then into de Play method, this is my code for the client.
package main
import (
"bufio"
"fmt"
"log"
"net"
"strings"
"github/bluenviron/gortsplib/v4"
"github/bluenviron/gortsplib/v4/pkg/base"
"github/bluenviron/gortsplib/v4/pkg/description"
"github/bluenviron/gortsplib/v4/pkg/format"
"github/pion/rtcp"
)
func main() {
DialRtsp()
// Connect to the RTSP camera
client := gortsplib.Client{}
u, err := base.ParseURL("rtsp:<ip>:<port>/<path>")
if err != nil {
panic(err)
}
fmt.Println(u.Scheme)
fmt.Println(u.Host)
fmt.Println(u)
// connect to the server
// I can't find if auth should be done here also
err = client.Start(u.Scheme, u.Host)
if err != nil {
panic(err)
}
defer client.Close()
fmt.Println("start")
if err != nil {
fmt.Println("ERROR IS", err)
}
// find available medias
desc, resp, err := client.Describe(u)
//this is the request that errors out as a simple string, I don't know if I am using it correctly
fmt.Println(resp)
if err != nil {
fmt.Print(err.Error())
}
client.Close()
// setup all medias
err = client.SetupAll(desc.BaseURL, desc.Medias)
if err != nil {
panic(err)
}
// called when a RTP packet arrives
client.OnPacketRTPAny(func(medi *description.Media, forma format.Format, pkt *rtp.Packet) {
log.Printf("RTP packet from media %v\n", medi)
})
// called when a RTCP packet arrives
client.OnPacketRTCPAny(func(medi *description.Media, pkt rtcp.Packet) {
log.Printf("RTCP packet from media %v, type %T\n", medi, pkt)
})
// start playing
_, err = client.Play(nil)
if err != nil {
panic(err)
}
// wait until a fatal error
panic(client.Wait())
}