Add RTSP SDP to stream info JSON

This commit is contained in:
Alexey Khit
2023-07-23 17:26:26 +03:00
parent 3defbd60db
commit e6a87fbd69
5 changed files with 20 additions and 7 deletions
+1
View File
@@ -90,6 +90,7 @@ type Info struct {
URL string `json:"url,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
SDP string `json:"sdp,omitempty"`
Medias []*Media `json:"medias,omitempty"`
Receivers []*Receiver `json:"receivers,omitempty"`
Senders []*Sender `json:"senders,omitempty"`
+4 -1
View File
@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"github.com/AlexxIT/go2rtc/pkg/tcp/websocket"
"net"
"net/http"
"net/url"
@@ -12,6 +11,8 @@ import (
"strings"
"time"
"github.com/AlexxIT/go2rtc/pkg/tcp/websocket"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
@@ -139,6 +140,8 @@ func (c *Conn) Describe() error {
}
}
c.sdp = string(res.Body) // for info
medias, err := UnmarshalSDP(res.Body)
if err != nil {
return err
+6 -4
View File
@@ -4,16 +4,17 @@ import (
"bufio"
"encoding/binary"
"fmt"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"io"
"net"
"net/url"
"strconv"
"sync"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
"github.com/pion/rtcp"
"github.com/pion/rtp"
)
type Conn struct {
@@ -39,6 +40,7 @@ type Conn struct {
reader *bufio.Reader
sequence int
session string
sdp string
uri string
state State
+2
View File
@@ -3,6 +3,7 @@ package rtsp
import (
"encoding/json"
"errors"
"github.com/AlexxIT/go2rtc/pkg/core"
)
@@ -100,6 +101,7 @@ func (c *Conn) Stop() (err error) {
func (c *Conn) MarshalJSON() ([]byte, error) {
info := &core.Info{
Type: "RTSP " + c.mode.String(),
SDP: c.sdp,
UserAgent: c.UserAgent,
Medias: c.Medias,
Receivers: c.receivers,
+7 -2
View File
@@ -4,12 +4,13 @@ import (
"bufio"
"errors"
"fmt"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
"net"
"net/url"
"strconv"
"strings"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
func NewServer(conn net.Conn) *Conn {
@@ -69,6 +70,8 @@ func (c *Conn) Accept() error {
return errors.New("wrong content type")
}
c.sdp = string(req.Body) // for info
c.Medias, err = UnmarshalSDP(req.Body)
if err != nil {
return err
@@ -125,6 +128,8 @@ func (c *Conn) Accept() error {
return err
}
c.sdp = string(res.Body) // for info
if err = c.WriteResponse(res); err != nil {
return err
}