@@ -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