Fix HomeKit client stat info

This commit is contained in:
Alexey Khit
2023-09-02 07:38:49 +03:00
parent 7fdc6b9472
commit 1c569e690d

View File

@@ -1,7 +1,6 @@
package homekit package homekit
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"math/rand" "math/rand"
@@ -50,7 +49,16 @@ func Dial(rawURL string, server *srtp.Server) (*Client, error) {
return nil, err return nil, err
} }
return &Client{hap: conn, srtp: server}, nil client := &Client{
SuperProducer: core.SuperProducer{
Type: "HomeKit active producer",
URL: conn.URL(),
},
hap: conn,
srtp: server,
}
return client, nil
} }
func (c *Client) Conn() net.Conn { func (c *Client) Conn() net.Conn {
@@ -83,6 +91,7 @@ func (c *Client) GetMedias() []*core.Media {
return nil return nil
} }
c.URL = c.hap.URL()
c.SDP = fmt.Sprintf("%+v\n%+v", c.videoConfig, c.audioConfig) c.SDP = fmt.Sprintf("%+v\n%+v", c.videoConfig, c.audioConfig)
c.Medias = []*core.Media{ c.Medias = []*core.Media{
@@ -126,15 +135,20 @@ func (c *Client) Start() error {
c.videoSession.OnReadRTP = func(packet *rtp.Packet) { c.videoSession.OnReadRTP = func(packet *rtp.Packet) {
deadline.Reset(core.ConnDeadline) deadline.Reset(core.ConnDeadline)
videoTrack.WriteRTP(packet) videoTrack.WriteRTP(packet)
c.Recv += len(packet.Payload)
} }
if audioTrack != nil { if audioTrack != nil {
c.audioSession.OnReadRTP = audioTrack.WriteRTP c.audioSession.OnReadRTP = func(packet *rtp.Packet) {
audioTrack.WriteRTP(packet)
c.Recv += len(packet.Payload)
}
} }
} else { } else {
c.audioSession.OnReadRTP = func(packet *rtp.Packet) { c.audioSession.OnReadRTP = func(packet *rtp.Packet) {
deadline.Reset(core.ConnDeadline) deadline.Reset(core.ConnDeadline)
audioTrack.WriteRTP(packet) audioTrack.WriteRTP(packet)
c.Recv += len(packet.Payload)
} }
} }
@@ -156,18 +170,6 @@ func (c *Client) Stop() error {
return c.hap.Close() return c.hap.Close()
} }
func (c *Client) MarshalJSON() ([]byte, error) {
info := &core.Info{
Type: "HomeKit active producer",
URL: c.hap.URL(),
SDP: fmt.Sprintf("%+v\n%+v", c.videoConfig, c.audioConfig),
Medias: c.Medias,
Receivers: c.Receivers,
Recv: c.videoSession.Recv + c.audioSession.Recv,
}
return json.Marshal(info)
}
func (c *Client) trackByKind(kind string) *core.Receiver { func (c *Client) trackByKind(kind string) *core.Receiver {
for _, receiver := range c.Receivers { for _, receiver := range c.Receivers {
if receiver.Codec.Kind() == kind { if receiver.Codec.Kind() == kind {
@@ -186,6 +188,8 @@ func (c *Client) startMJPEG() error {
return err return err
} }
c.Recv += len(b)
packet := &rtp.Packet{ packet := &rtp.Packet{
Header: rtp.Header{Timestamp: core.Now90000()}, Header: rtp.Header{Timestamp: core.Now90000()},
Payload: b, Payload: b,