Skip to content

Commit

Permalink
Fix support 2 way audio for Reolink Doorbell AlexxIT#331
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 3, 2023
1 parent c192362 commit 6d9d89b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/pcm/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pcm

import (
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
)

func RepackBackchannel(handler core.HandlerFunc) core.HandlerFunc {
var buf []byte
var seq uint16

return func(packet *rtp.Packet) {
buf = append(buf, packet.Payload...)
if len(buf) < 1024 {
return
}

pkt := &rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true, // should be true
PayloadType: packet.PayloadType, // will be owerwriten
SequenceNumber: seq,
Timestamp: 0, // should be always zero
SSRC: packet.SSRC,
},
Payload: buf[:1024],
}

handler(pkt)

buf = buf[1024:]
seq++
}
}
7 changes: 7 additions & 0 deletions pkg/rtsp/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/AlexxIT/go2rtc/pkg/h264"
"github.com/AlexxIT/go2rtc/pkg/h265"
"github.com/AlexxIT/go2rtc/pkg/mjpeg"
"github.com/AlexxIT/go2rtc/pkg/pcm"
"github.com/pion/rtp"
"time"
)
Expand Down Expand Up @@ -60,6 +61,12 @@ func (c *Conn) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiv
sender := core.NewSender(media, codec)
// important to send original codec for valid IsRTP check
sender.Handler = c.packetWriter(track.Codec, channel, codec.PayloadType)

// https://github.com/AlexxIT/go2rtc/issues/331
if c.mode == core.ModeActiveProducer && track.Codec.Name == core.CodecPCMA {
sender.Handler = pcm.RepackBackchannel(sender.Handler)
}

sender.HandleRTP(track)

c.senders = append(c.senders, sender)
Expand Down

0 comments on commit 6d9d89b

Please sign in to comment.