feat(homekit): add Speaker service and enhance Consumer with backtrack audio handling
This commit is contained in:
@@ -13,6 +13,7 @@ func NewAccessory(manuf, model, name, serial, firmware string) *hap.Accessory {
|
|||||||
ServiceCameraRTPStreamManagement(),
|
ServiceCameraRTPStreamManagement(),
|
||||||
//hap.ServiceHAPProtocolInformation(),
|
//hap.ServiceHAPProtocolInformation(),
|
||||||
ServiceMicrophone(),
|
ServiceMicrophone(),
|
||||||
|
ServiceSpeaker(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
acc.InitIID()
|
acc.InitIID()
|
||||||
@@ -32,6 +33,7 @@ func NewHKSVAccessory(manuf, model, name, serial, firmware string) *hap.Accessor
|
|||||||
hap.ServiceAccessoryInformation(manuf, model, name, serial, firmware),
|
hap.ServiceAccessoryInformation(manuf, model, name, serial, firmware),
|
||||||
rtpStream,
|
rtpStream,
|
||||||
ServiceMicrophone(),
|
ServiceMicrophone(),
|
||||||
|
ServiceSpeaker(),
|
||||||
motionSensor,
|
motionSensor,
|
||||||
operatingMode,
|
operatingMode,
|
||||||
recordingMgmt,
|
recordingMgmt,
|
||||||
@@ -60,6 +62,7 @@ func NewHKSVDoorbellAccessory(manuf, model, name, serial, firmware string) *hap.
|
|||||||
hap.ServiceAccessoryInformation(manuf, model, name, serial, firmware),
|
hap.ServiceAccessoryInformation(manuf, model, name, serial, firmware),
|
||||||
rtpStream,
|
rtpStream,
|
||||||
ServiceMicrophone(),
|
ServiceMicrophone(),
|
||||||
|
ServiceSpeaker(),
|
||||||
motionSensor,
|
motionSensor,
|
||||||
operatingMode,
|
operatingMode,
|
||||||
recordingMgmt,
|
recordingMgmt,
|
||||||
@@ -75,6 +78,20 @@ func NewHKSVDoorbellAccessory(manuf, model, name, serial, firmware string) *hap.
|
|||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ServiceSpeaker() *hap.Service {
|
||||||
|
return &hap.Service{
|
||||||
|
Type: "113", // 'Speaker'
|
||||||
|
Characters: []*hap.Character{
|
||||||
|
{
|
||||||
|
Type: "11A",
|
||||||
|
Format: hap.FormatBool,
|
||||||
|
Value: 0,
|
||||||
|
Perms: hap.EVPRPW,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ServiceMicrophone() *hap.Service {
|
func ServiceMicrophone() *hap.Service {
|
||||||
return &hap.Service{
|
return &hap.Service{
|
||||||
Type: "112", // 'Microphone'
|
Type: "112", // 'Microphone'
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ type Consumer struct {
|
|||||||
videoSession *srtp.Session
|
videoSession *srtp.Session
|
||||||
audioSession *srtp.Session
|
audioSession *srtp.Session
|
||||||
audioRTPTime byte
|
audioRTPTime byte
|
||||||
|
|
||||||
|
backTrack *core.Receiver // backchannel audio (HomeKit viewer → camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsumer(conn net.Conn, server *srtp.Server) *Consumer {
|
func NewConsumer(conn net.Conn, server *srtp.Server) *Consumer {
|
||||||
@@ -44,6 +46,13 @@ func NewConsumer(conn net.Conn, server *srtp.Server) *Consumer {
|
|||||||
{Name: core.CodecOpus},
|
{Name: core.CodecOpus},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Kind: core.KindAudio,
|
||||||
|
Direction: core.DirectionRecvonly,
|
||||||
|
Codecs: []*core.Codec{
|
||||||
|
{Name: core.CodecOpus},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return &Consumer{
|
return &Consumer{
|
||||||
Connection: core.Connection{
|
Connection: core.Connection{
|
||||||
@@ -130,6 +139,26 @@ func (c *Consumer) SetConfig(conf *camera.SelectedStreamConfiguration) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Consumer) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
|
||||||
|
if codec.Kind() != core.KindAudio {
|
||||||
|
return nil, core.ErrCantGetTrack
|
||||||
|
}
|
||||||
|
|
||||||
|
c.backTrack = core.NewReceiver(media, codec)
|
||||||
|
|
||||||
|
c.audioSession.OnReadRTP = func(packet *rtp.Packet) {
|
||||||
|
c.backTrack.WriteRTP(packet)
|
||||||
|
c.Recv += len(packet.Payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Receivers = append(c.Receivers, c.backTrack)
|
||||||
|
return c.backTrack, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Consumer) Start() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Consumer) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
|
func (c *Consumer) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
|
||||||
var session *srtp.Session
|
var session *srtp.Session
|
||||||
if codec.Kind() == core.KindVideo {
|
if codec.Kind() == core.KindVideo {
|
||||||
|
|||||||
Reference in New Issue
Block a user