diff --git a/cmd/rtsp/rtsp.go b/cmd/rtsp/rtsp.go index 4fd54e39..c0409a04 100644 --- a/cmd/rtsp/rtsp.go +++ b/cmd/rtsp/rtsp.go @@ -84,10 +84,10 @@ func rtspHandler(url string) (streamer.Producer, error) { } // second try without backchannel, we need to reconnect + conn.Backchannel = false if err = conn.Dial(); err != nil { return nil, err } - conn.Backchannel = false if err = conn.Describe(); err != nil { return nil, err } diff --git a/cmd/streams/producer.go b/cmd/streams/producer.go index c6f8adb8..79757aad 100644 --- a/cmd/streams/producer.go +++ b/cmd/streams/producer.go @@ -64,6 +64,9 @@ func (p *Producer) GetTrack(media *streamer.Media, codec *streamer.Codec) *strea } track := p.element.GetTrack(media, codec) + if track == nil { + return nil + } for _, t := range p.tracks { if track == t { diff --git a/pkg/rtsp/conn.go b/pkg/rtsp/conn.go index 69a06446..1648fc0a 100644 --- a/pkg/rtsp/conn.go +++ b/pkg/rtsp/conn.go @@ -362,21 +362,25 @@ func (c *Conn) SetupMedia( var res *tcp.Response res, err = c.Do(req) if err != nil { - // Dahua VTO2111D fail on this step because of backchannel + // some Dahua/Amcrest cameras fail here because two simultaneous + // backchannel connections if c.Backchannel { - if err = c.Dial(); err != nil { - return nil, err - } c.Backchannel = false - if err = c.Describe(); err != nil { + if err := c.Dial(); err != nil { return nil, err } - res, err = c.Do(req) + if err := c.Describe(); err != nil { + return nil, err + } + + for _, newMedia := range c.Medias { + if newMedia.Control == media.Control { + return c.SetupMedia(newMedia, newMedia.Codecs[0]) + } + } } - if err != nil { - return nil, err - } + return nil, err } if c.Session == "" {