mediamtx/internal/protocols/rtmp/message/msg_acknowledge.go
hyesung913 cb16f68432
rtmp: improve control message compatibility with non-standard cameras (#4909)
* feat: improve RTMP control message compatibility with non-standard cameras

- Add flexible chunk stream ID validation for control messages
- Support common non-standard chunk stream IDs (2,3,4,5,6) used by various cameras
- Maintain backward compatibility with standard RTMP clients
- Fix connection issues with PTZ cameras using chunk stream ID 4

This resolves compatibility issues with IP cameras that don't strictly follow
RTMP spec while maintaining full support for standard RTMP implementations.
Previously, cameras using non-standard chunk stream IDs would fail with
'unexpected chunk stream ID' errors. Now MediaMTX provides nginx-rtmp level
compatibility with real-world camera implementations."

* add tests

* entirely remove control chunk stream ID validation

---------

Co-authored-by: Hyesung.Kim <hyesung.kim@xcath.com>
Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
2025-09-03 15:11:32 +02:00

37 lines
814 B
Go

package message //nolint:dupl
import (
"fmt"
"github.com/bluenviron/mediamtx/internal/protocols/rtmp/rawmessage"
)
// Acknowledge is an acknowledgement message.
type Acknowledge struct {
Value uint32
}
func (m *Acknowledge) unmarshal(raw *rawmessage.Message) error {
if len(raw.Body) != 4 {
return fmt.Errorf("unexpected body size")
}
m.Value = uint32(raw.Body[0])<<24 | uint32(raw.Body[1])<<16 | uint32(raw.Body[2])<<8 | uint32(raw.Body[3])
return nil
}
func (m *Acknowledge) marshal() (*rawmessage.Message, error) {
buf := make([]byte, 4)
buf[0] = byte(m.Value >> 24)
buf[1] = byte(m.Value >> 16)
buf[2] = byte(m.Value >> 8)
buf[3] = byte(m.Value)
return &rawmessage.Message{
ChunkStreamID: ControlChunkStreamID,
Type: uint8(TypeAcknowledge),
Body: buf,
}, nil
}