rewrite Unit definition (#5079)
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

Stream units now share the same struct, with a specialized payload.
This commit is contained in:
Alessandro Ros 2025-10-11 12:18:51 +02:00 committed by GitHub
parent e2294836f5
commit f5f03562d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
86 changed files with 1100 additions and 1602 deletions

View file

@ -298,16 +298,16 @@ func TestServerPublish(t *testing.T) {
r.OnData(
strm.Desc.Medias[0],
strm.Desc.Medias[0].Formats[0],
func(u unit.Unit) error {
func(u *unit.Unit) error {
select {
case <-recv:
return nil
default:
}
require.Equal(t, [][]byte{
require.Equal(t, unit.PayloadH264{
{1},
}, u.(*unit.H264).AU)
}, u.Payload)
close(recv)
return nil
@ -336,7 +336,7 @@ func TestServerRead(t *testing.T) {
for _, ca := range []struct {
name string
medias []*description.Media
unit unit.Unit
unit *unit.Unit
outRTPPayload []byte
}{
{
@ -347,8 +347,8 @@ func TestServerRead(t *testing.T) {
PayloadTyp: 96,
}},
}},
&unit.AV1{
TU: [][]byte{{1, 2}},
&unit.Unit{
Payload: unit.PayloadAV1{{1, 2}},
},
[]byte{0x10, 0x01, 0x02},
},
@ -360,8 +360,8 @@ func TestServerRead(t *testing.T) {
PayloadTyp: 96,
}},
}},
&unit.VP9{
Frame: []byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34},
&unit.Unit{
Payload: unit.PayloadVP9{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34},
},
[]byte{
0x8f, 0xa0, 0xfd, 0x18, 0x07, 0x80, 0x03, 0x24,
@ -377,16 +377,16 @@ func TestServerRead(t *testing.T) {
PayloadTyp: 96,
}},
}},
&unit.VP8{
Frame: []byte{1, 2},
&unit.Unit{
Payload: unit.PayloadVP8{1, 2},
},
[]byte{0x10, 1, 2},
},
{
"h264",
[]*description.Media{test.MediaH264},
&unit.H264{
AU: [][]byte{
&unit.Unit{
Payload: unit.PayloadH264{
{5, 1},
},
},
@ -407,8 +407,8 @@ func TestServerRead(t *testing.T) {
ChannelCount: 2,
}},
}},
&unit.Opus{
Packets: [][]byte{{1, 2}},
&unit.Unit{
Payload: unit.PayloadOpus{{1, 2}},
},
[]byte{1, 2},
},
@ -418,20 +418,18 @@ func TestServerRead(t *testing.T) {
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.G722{}},
}},
&unit.Generic{
Base: unit.Base{
RTPPackets: []*rtp.Packet{{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 9,
SequenceNumber: 1123,
Timestamp: 45343,
SSRC: 563423,
},
Payload: []byte{1, 2},
}},
},
&unit.Unit{
RTPPackets: []*rtp.Packet{{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 9,
SequenceNumber: 1123,
Timestamp: 45343,
SSRC: 563423,
},
Payload: []byte{1, 2},
}},
},
[]byte{1, 2},
},
@ -445,8 +443,8 @@ func TestServerRead(t *testing.T) {
ChannelCount: 1,
}},
}},
&unit.G711{
Samples: []byte{1, 2, 3},
&unit.Unit{
Payload: unit.PayloadG711{1, 2, 3},
},
[]byte{1, 2, 3},
},
@ -460,8 +458,8 @@ func TestServerRead(t *testing.T) {
ChannelCount: 2,
}},
}},
&unit.G711{
Samples: []byte{1, 2, 3, 4},
&unit.Unit{
Payload: unit.PayloadG711{1, 2, 3, 4},
},
[]byte{0x86, 0x84, 0x8a, 0x84, 0x8e, 0x84, 0x92, 0x84},
},
@ -476,8 +474,8 @@ func TestServerRead(t *testing.T) {
ChannelCount: 2,
}},
}},
&unit.LPCM{
Samples: []byte{1, 2, 3, 4},
&unit.Unit{
Payload: unit.PayloadLPCM{1, 2, 3, 4},
},
[]byte{1, 2, 3, 4},
},
@ -489,7 +487,7 @@ func TestServerRead(t *testing.T) {
WriteQueueSize: 512,
RTPMaxPayloadSize: 1450,
Desc: desc,
GenerateRTPPackets: reflect.TypeOf(ca.unit) != reflect.TypeOf(&unit.Generic{}),
GenerateRTPPackets: ca.unit.Payload != nil,
Parent: test.NilLogger,
}
err := strm.Initialize()
@ -555,11 +553,11 @@ func TestServerRead(t *testing.T) {
r := reflect.New(reflect.TypeOf(ca.unit).Elem())
r.Elem().Set(reflect.ValueOf(ca.unit).Elem())
if g, ok := r.Interface().(*unit.Generic); ok {
clone := *g.RTPPackets[0]
if ca.unit.Payload == nil {
clone := *ca.unit.RTPPackets[0]
strm.WriteRTPPacket(desc.Medias[0], desc.Medias[0].Formats[0], &clone, time.Time{}, 0)
} else {
strm.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], r.Interface().(unit.Unit))
strm.WriteUnit(desc.Medias[0], desc.Medias[0].Formats[0], r.Interface().(*unit.Unit))
}
}()