Skip to content

Commit

Permalink
move each goroutine in a dedicated struct (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed May 17, 2023
1 parent f948850 commit b0947c1
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 633 deletions.
5 changes: 1 addition & 4 deletions client_play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2693,10 +2693,7 @@ func TestClientPlayKeepaliveFromSession(t *testing.T) {
}.Marshal(),
"Session": headers.Session{
Session: "ABCDE",
Timeout: func() *uint {
v := uint(1)
return &v
}(),
Timeout: uintPtr(1),
}.Marshal(),
},
})
Expand Down
19 changes: 10 additions & 9 deletions client_udpl.go → client_udp_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"golang.org/x/net/ipv4"
)

func int64Ptr(v int64) *int64 {
return &v
}

func randInRange(max int) int {
b := big.NewInt(int64(max + 1))
n, _ := rand.Int(rand.Reader, b)
Expand Down Expand Up @@ -129,15 +133,12 @@ func newClientUDPListener(
}

return &clientUDPListener{
anyPortEnable: anyPortEnable,
writeTimeout: writeTimeout,
pc: pc,
cm: cm,
isRTP: isRTP,
lastPacketTime: func() *int64 {
v := int64(0)
return &v
}(),
anyPortEnable: anyPortEnable,
writeTimeout: writeTimeout,
pc: pc,
cm: cm,
isRTP: isRTP,
lastPacketTime: int64Ptr(0),
}, nil
}

Expand Down
25 changes: 12 additions & 13 deletions pkg/formats/rtpav1/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

var shortOBU = []byte{
0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf,
0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
Expand Down Expand Up @@ -977,19 +985,10 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
PayloadType: 96,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
}
e.Init()

Expand Down
25 changes: 12 additions & 13 deletions pkg/formats/rtph264/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

func mergeBytes(vals ...[]byte) []byte {
size := 0
for _, v := range vals {
Expand Down Expand Up @@ -274,19 +282,10 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
PayloadType: 96,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
}
e.Init()

Expand Down
25 changes: 12 additions & 13 deletions pkg/formats/rtph265/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

func mergeBytes(vals ...[]byte) []byte {
size := 0
for _, v := range vals {
Expand Down Expand Up @@ -127,19 +135,10 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
PayloadType: 96,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
}
e.Init()

Expand Down
31 changes: 15 additions & 16 deletions pkg/formats/rtplpcm/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

var cases = []struct {
name string
samples []byte
Expand Down Expand Up @@ -64,22 +72,13 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
BitDepth: 24,
SampleRate: 48000,
ChannelCount: 2,
PayloadType: 96,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
BitDepth: 24,
SampleRate: 48000,
ChannelCount: 2,
}
e.Init()

Expand Down
23 changes: 11 additions & 12 deletions pkg/formats/rtpmjpeg/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

var cases = []struct {
name string
image []byte
Expand Down Expand Up @@ -509,18 +517,9 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(2289528607)
return &v
}(),
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(2289528607),
}
e.Init()

Expand Down
25 changes: 12 additions & 13 deletions pkg/formats/rtpmpeg2audio/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

var cases = []struct {
name string
frames [][]byte
Expand Down Expand Up @@ -464,19 +472,10 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
PayloadMaxSize: 400,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
PayloadMaxSize: 400,
}
e.Init()

Expand Down
33 changes: 16 additions & 17 deletions pkg/formats/rtpmpeg4audio/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

func mergeBytes(vals ...[]byte) []byte {
size := 0
for _, v := range vals {
Expand Down Expand Up @@ -474,23 +482,14 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SampleRate: 48000,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
SizeLength: ca.sizeLength,
IndexLength: ca.indexLength,
IndexDeltaLength: ca.indexDeltaLength,
PayloadType: 96,
SampleRate: 48000,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
SizeLength: ca.sizeLength,
IndexLength: ca.indexLength,
IndexDeltaLength: ca.indexDeltaLength,
}
e.Init()

Expand Down
27 changes: 13 additions & 14 deletions pkg/formats/rtpmpeg4video/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/stretchr/testify/require"
)

func uint16Ptr(v uint16) *uint16 {
return &v
}

func uint32Ptr(v uint32) *uint32 {
return &v
}

var cases = []struct {
name string
frame []byte
Expand Down Expand Up @@ -66,20 +74,11 @@ func TestEncode(t *testing.T) {
for _, ca := range cases {
t.Run(ca.name, func(t *testing.T) {
e := &Encoder{
PayloadType: 96,
SSRC: func() *uint32 {
v := uint32(0x9dbb7812)
return &v
}(),
InitialSequenceNumber: func() *uint16 {
v := uint16(0x44ed)
return &v
}(),
InitialTimestamp: func() *uint32 {
v := uint32(0x88776655)
return &v
}(),
PayloadMaxSize: 100,
PayloadType: 96,
SSRC: uint32Ptr(0x9dbb7812),
InitialSequenceNumber: uint16Ptr(0x44ed),
InitialTimestamp: uint32Ptr(0x88776655),
PayloadMaxSize: 100,
}
e.Init()

Expand Down
Loading

0 comments on commit b0947c1

Please sign in to comment.