webrtc: fix packet corruption when reading G711 (#5048)
Some checks failed
code_lint / go (push) Has been cancelled
code_lint / go_mod (push) Has been cancelled
code_lint / docs (push) Has been cancelled
code_lint / api_docs (push) Has been cancelled
code_test / test_64 (push) Has been cancelled
code_test / test_32 (push) Has been cancelled
code_test / test_e2e (push) Has been cancelled

when a reader is reading a G711 track, stream units are modified
globally, affecting every other reader. This fixes the issue.
This commit is contained in:
Alessandro Ros 2025-09-30 10:42:24 +02:00 committed by GitHub
parent 2690ef8e71
commit 691d7290fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ import (
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/stream"
"github.com/bluenviron/mediamtx/internal/unit"
"github.com/pion/rtp"
"github.com/pion/webrtc/v4"
)
@ -377,7 +378,12 @@ func setupAudioTrack(
media,
opusFormat,
func(u unit.Unit) error {
for _, pkt := range u.GetRTPPackets() {
for _, orig := range u.GetRTPPackets() {
pkt := &rtp.Packet{
Header: orig.Header,
Payload: orig.Payload,
}
// recompute timestamp from scratch.
// Chrome requires a precise timestamp that FFmpeg doesn't provide.
pkt.Timestamp = curTimestamp
@ -488,7 +494,12 @@ func setupAudioTrack(
media,
g711Format,
func(u unit.Unit) error {
for _, pkt := range u.GetRTPPackets() {
for _, orig := range u.GetRTPPackets() {
pkt := &rtp.Packet{
Header: orig.Header,
Payload: orig.Payload,
}
// recompute timestamp from scratch.
// Chrome requires a precise timestamp that FFmpeg doesn't provide.
pkt.Timestamp = curTimestamp