mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
Adds stats to RTMP connection
This commit is contained in:
@@ -22,6 +22,8 @@ type Client struct {
|
|||||||
|
|
||||||
conn *rtmp.Conn
|
conn *rtmp.Conn
|
||||||
closed bool
|
closed bool
|
||||||
|
|
||||||
|
receive int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(uri string) *Client {
|
func NewClient(uri string) *Client {
|
||||||
@@ -94,6 +96,8 @@ func (c *Client) Handle() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.receive += len(pkt.Data)
|
||||||
|
|
||||||
track := c.tracks[int(pkt.Idx)]
|
track := c.tracks[int(pkt.Idx)]
|
||||||
|
|
||||||
timestamp := uint32(pkt.Time / time.Duration(track.Codec.ClockRate))
|
timestamp := uint32(pkt.Time / time.Duration(track.Codec.ClockRate))
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package rtmp
|
package rtmp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) GetMedias() []*streamer.Media {
|
func (c *Client) GetMedias() []*streamer.Media {
|
||||||
@@ -24,3 +26,21 @@ func (c *Client) Start() error {
|
|||||||
func (c *Client) Stop() error {
|
func (c *Client) Stop() error {
|
||||||
return c.Close()
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user