mediamtx/internal/codecprocessor/klv_test.go
Alessandro Ros f5f03562d3
Some checks are pending
code_lint / go (push) Waiting to run
code_lint / go_mod (push) Waiting to run
code_lint / docs (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
rewrite Unit definition (#5079)
Stream units now share the same struct, with a specialized payload.
2025-10-11 12:18:51 +02:00

80 lines
1.6 KiB
Go

package codecprocessor
import (
"testing"
"github.com/bluenviron/gortsplib/v5/pkg/format"
"github.com/bluenviron/mediamtx/internal/unit"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestKlvCreateEncoder(t *testing.T) {
forma := &format.KLV{
PayloadTyp: 96,
}
p, err := New(1472, forma, false, nil)
require.NoError(t, err)
klvProc := p.(*klv)
err = klvProc.createEncoder()
require.NoError(t, err)
}
func TestKlvProcessUnit(t *testing.T) {
forma := &format.KLV{
PayloadTyp: 96,
}
p, err := New(1472, forma, true, nil)
require.NoError(t, err)
// create test Unit
when := int64(5000000000) // 5 seconds in nanoseconds
u := unit.Unit{
RTPPackets: nil,
PTS: when,
Payload: unit.PayloadKLV{1, 2, 3, 4},
}
uu := &u
// process the unit
err = p.ProcessUnit(uu)
require.NoError(t, err)
}
func TestKlvProcessRTPPacket(t *testing.T) {
forma := &format.KLV{
PayloadTyp: 96,
}
p, err := New(1472, forma, false, nil)
require.NoError(t, err)
pkt := &rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 3446,
Timestamp: 175349,
SSRC: 563423,
Padding: true,
},
Payload: []byte{1, 2, 3, 4},
PaddingSize: 20,
}
u := &unit.Unit{RTPPackets: []*rtp.Packet{pkt}}
err = p.ProcessRTPPacket(u, false)
require.NoError(t, err)
require.Equal(t, &rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 3446,
Timestamp: 175349,
SSRC: 563423,
},
Payload: []byte{1, 2, 3, 4},
}, pkt)
}