Adds stats to RTMP connection

This commit is contained in:
Alexey Khit
2022-08-18 23:58:22 +03:00
parent 7c23625a24
commit cc00633161
2 changed files with 24 additions and 0 deletions

View File

@@ -22,6 +22,8 @@ type Client struct {
conn *rtmp.Conn
closed bool
receive int
}
func NewClient(uri string) *Client {
@@ -94,6 +96,8 @@ func (c *Client) Handle() (err error) {
return
}
c.receive += len(pkt.Data)
track := c.tracks[int(pkt.Idx)]
timestamp := uint32(pkt.Time / time.Duration(track.Codec.ClockRate))

View File

@@ -1,7 +1,9 @@
package rtmp
import (
"encoding/json"
"github.com/AlexxIT/go2rtc/pkg/streamer"
"strconv"
)
func (c *Client) GetMedias() []*streamer.Media {
@@ -24,3 +26,21 @@ func (c *Client) Start() error {
func (c *Client) Stop() error {
return c.Close()
}
func (c *Client) MarshalJSON() ([]byte, error) {
v := map[string]interface{}{
streamer.JSONReceive: c.receive,
streamer.JSONType: "RTMP client producer",
streamer.JSONRemoteAddr: c.conn.NetConn().RemoteAddr().String(),
"url": c.URI,
}
for i, media := range c.medias {
k := "media:" + strconv.Itoa(i)
v[k] = media.String()
}
for i, track := range c.tracks {
k := "track:" + strconv.Itoa(i)
v[k] = track.String()
}
return json.Marshal(v)
}