Add support MJPEG codec for HomeKit cameras
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/AlexxIT/go2rtc/pkg/hap"
|
"github.com/AlexxIT/go2rtc/pkg/hap"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/hap/camera"
|
"github.com/AlexxIT/go2rtc/pkg/hap/camera"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/srtp"
|
"github.com/AlexxIT/go2rtc/pkg/srtp"
|
||||||
|
"github.com/pion/rtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@@ -180,6 +181,19 @@ func (c *Client) GetMedias() []*core.Media {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
media := &core.Media{
|
||||||
|
Kind: core.KindVideo,
|
||||||
|
Direction: core.DirectionRecvonly,
|
||||||
|
Codecs: []*core.Codec{
|
||||||
|
{
|
||||||
|
Name: core.CodecJPEG,
|
||||||
|
ClockRate: 90000,
|
||||||
|
PayloadType: core.PayloadTypeRAW,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.medias = append(c.medias, media)
|
||||||
|
|
||||||
return c.medias
|
return c.medias
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +214,10 @@ func (c *Client) Start() error {
|
|||||||
return errors.New("producer without tracks")
|
return errors.New("producer without tracks")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.receivers[0].Codec.Name == core.CodecJPEG {
|
||||||
|
return c.startMJPEG()
|
||||||
|
}
|
||||||
|
|
||||||
// get our server local IP-address
|
// get our server local IP-address
|
||||||
host, _, err := net.SplitHostPort(c.conn.LocalAddr())
|
host, _, err := net.SplitHostPort(c.conn.LocalAddr())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -369,3 +387,20 @@ func (c *Client) trackByKind(kind string) *core.Receiver {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) startMJPEG() error {
|
||||||
|
receiver := c.receivers[0]
|
||||||
|
|
||||||
|
for {
|
||||||
|
b, err := c.conn.GetImage(1920, 1080)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
packet := &rtp.Packet{
|
||||||
|
Header: rtp.Header{Timestamp: core.Now90000()},
|
||||||
|
Payload: b,
|
||||||
|
}
|
||||||
|
receiver.WriteRTP(packet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user