Add support new audio codec for tapo source #1954

This commit is contained in:
Alex X
2025-11-25 15:51:55 +03:00
parent 5a259993d8
commit 86edd814c9
2 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -330,6 +330,7 @@ const (
StreamTypeH264 = 0x1B
StreamTypeH265 = 0x24
StreamTypePCMATapo = 0x90
StreamTypePCMUTapo = 0x91
StreamTypePrivateOPUS = 0xEB
)
@@ -392,7 +393,7 @@ func (p *PES) GetPacket() (pkt *rtp.Packet) {
//p.Timestamp += aac.RTPTimeSize(pkt.Payload) // update next timestamp!
case StreamTypePCMATapo:
case StreamTypePCMATapo, StreamTypePCMUTapo:
p.Sequence++
pkt = &rtp.Packet{
+20
View File
@@ -20,6 +20,7 @@ import (
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/mpegts"
"github.com/AlexxIT/go2rtc/pkg/pcm"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
@@ -185,6 +186,8 @@ func (c *Client) Handle() error {
rd := multipart.NewReader(c.conn1, "--device-stream-boundary--")
demux := mpegts.NewDemuxer()
var transcode func([]byte) []byte
for {
p, err := rd.NextRawPart()
if err != nil {
@@ -226,6 +229,23 @@ func (c *Client) Handle() error {
return err2
}
if pkt.PayloadType == mpegts.StreamTypePCMUTapo {
// TODO: rewrite this part in the future
// Some cameras in the new firmware began to use PCMU/16000.
// https://github.com/AlexxIT/go2rtc/issues/1954
// I don't know why Tapo considers this an improvement. The codec is no better than the previous one.
// Unfortunately, we don't know in advance what codec the camera will use.
// Therefore, it's easier to transcode to a standard codec that all Tapo cameras have.
if transcode == nil {
transcode = pcm.Transcode(
&core.Codec{Name: core.CodecPCMA, ClockRate: 8000},
&core.Codec{Name: core.CodecPCMU, ClockRate: 16000},
)
}
pkt.PayloadType = mpegts.StreamTypePCMATapo
pkt.Payload = transcode(pkt.Payload)
}
for _, receiver := range c.receivers {
if receiver.ID == pkt.PayloadType {
mpegts.TimestampToRTP(pkt, receiver.Codec)