Skip to content

Commit 86edd81

Browse files
committed
Add support new audio codec for tapo source #1954
1 parent 5a25999 commit 86edd81

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/mpegts/demuxer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ const (
330330
StreamTypeH264 = 0x1B
331331
StreamTypeH265 = 0x24
332332
StreamTypePCMATapo = 0x90
333+
StreamTypePCMUTapo = 0x91
333334
StreamTypePrivateOPUS = 0xEB
334335
)
335336

@@ -392,7 +393,7 @@ func (p *PES) GetPacket() (pkt *rtp.Packet) {
392393

393394
//p.Timestamp += aac.RTPTimeSize(pkt.Payload) // update next timestamp!
394395

395-
case StreamTypePCMATapo:
396+
case StreamTypePCMATapo, StreamTypePCMUTapo:
396397
p.Sequence++
397398

398399
pkt = &rtp.Packet{

pkg/tapo/client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/AlexxIT/go2rtc/pkg/core"
2222
"github.com/AlexxIT/go2rtc/pkg/mpegts"
23+
"github.com/AlexxIT/go2rtc/pkg/pcm"
2324
"github.com/AlexxIT/go2rtc/pkg/tcp"
2425
)
2526

@@ -185,6 +186,8 @@ func (c *Client) Handle() error {
185186
rd := multipart.NewReader(c.conn1, "--device-stream-boundary--")
186187
demux := mpegts.NewDemuxer()
187188

189+
var transcode func([]byte) []byte
190+
188191
for {
189192
p, err := rd.NextRawPart()
190193
if err != nil {
@@ -226,6 +229,23 @@ func (c *Client) Handle() error {
226229
return err2
227230
}
228231

232+
if pkt.PayloadType == mpegts.StreamTypePCMUTapo {
233+
// TODO: rewrite this part in the future
234+
// Some cameras in the new firmware began to use PCMU/16000.
235+
// https://github.com/AlexxIT/go2rtc/issues/1954
236+
// I don't know why Tapo considers this an improvement. The codec is no better than the previous one.
237+
// Unfortunately, we don't know in advance what codec the camera will use.
238+
// Therefore, it's easier to transcode to a standard codec that all Tapo cameras have.
239+
if transcode == nil {
240+
transcode = pcm.Transcode(
241+
&core.Codec{Name: core.CodecPCMA, ClockRate: 8000},
242+
&core.Codec{Name: core.CodecPCMU, ClockRate: 16000},
243+
)
244+
}
245+
pkt.PayloadType = mpegts.StreamTypePCMATapo
246+
pkt.Payload = transcode(pkt.Payload)
247+
}
248+
229249
for _, receiver := range c.receivers {
230250
if receiver.ID == pkt.PayloadType {
231251
mpegts.TimestampToRTP(pkt, receiver.Codec)

0 commit comments

Comments
 (0)