modernize code (#5814)
This commit is contained in:
Vendored
+6
-12
@@ -8,12 +8,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
type myDuration time.Duration
|
||||
|
||||
func (d *myDuration) UnmarshalJSON(b []byte) error {
|
||||
@@ -87,17 +81,17 @@ func TestLoadPrimitives(t *testing.T) {
|
||||
|
||||
require.Equal(t, testStruct{
|
||||
MyString: "testcontent",
|
||||
MyStringOpt: ptrOf("testcontent2"),
|
||||
MyStringOpt: new("testcontent2"),
|
||||
MyInt: 123,
|
||||
MyIntOpt: ptrOf(456),
|
||||
MyIntOpt: new(456),
|
||||
MyUint: 8910,
|
||||
MyUintOpt: ptrOf(uint(112313)),
|
||||
MyUintOpt: new(uint(112313)),
|
||||
MyFloat: 15.2,
|
||||
MyFloatOpt: ptrOf(16.2),
|
||||
MyFloatOpt: new(16.2),
|
||||
MyBool: true,
|
||||
MyBoolOpt: ptrOf(false),
|
||||
MyBoolOpt: new(false),
|
||||
MyDuration: 22000000000,
|
||||
MyDurationOpt: ptrOf(myDuration(30000000000)),
|
||||
MyDurationOpt: new(myDuration(30000000000)),
|
||||
MyMap: map[string]*mapEntry{
|
||||
"mykey": {
|
||||
MyValue: "",
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
func TestPathClone(t *testing.T) {
|
||||
original := &Path{
|
||||
Name: "example",
|
||||
RTSPTransport: RTSPTransport{ptrOf(gortsplib.ProtocolUDP)},
|
||||
SourceAnyPortEnable: ptrOf(true),
|
||||
RTSPTransport: RTSPTransport{new(gortsplib.ProtocolUDP)},
|
||||
SourceAnyPortEnable: new(true),
|
||||
RecordPath: "/var/recordings",
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,6 @@ import (
|
||||
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
// RTSPTransport is the rtspTransport parameter.
|
||||
type RTSPTransport struct {
|
||||
*gortsplib.Protocol
|
||||
@@ -50,13 +44,13 @@ func (d *RTSPTransport) UnmarshalJSON(b []byte) error {
|
||||
|
||||
switch in {
|
||||
case "udp":
|
||||
d.Protocol = ptrOf(gortsplib.ProtocolUDP)
|
||||
d.Protocol = new(gortsplib.ProtocolUDP)
|
||||
|
||||
case "multicast":
|
||||
d.Protocol = ptrOf(gortsplib.ProtocolUDPMulticast)
|
||||
d.Protocol = new(gortsplib.ProtocolUDPMulticast)
|
||||
|
||||
case "tcp":
|
||||
d.Protocol = ptrOf(gortsplib.ProtocolTCP)
|
||||
d.Protocol = new(gortsplib.ProtocolTCP)
|
||||
|
||||
case "automatic":
|
||||
d.Protocol = nil
|
||||
|
||||
@@ -19,12 +19,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
type dummyPathManager struct{}
|
||||
|
||||
func (dummyPathManager) APIPathsList() (*defs.APIPathList, error) {
|
||||
@@ -39,7 +33,7 @@ func (dummyPathManager) APIPathsList() (*defs.APIPathList, error) {
|
||||
ID: "123324354",
|
||||
},
|
||||
Ready: true,
|
||||
ReadyTime: ptrOf(time.Date(2003, 11, 4, 23, 15, 7, 0, time.UTC)),
|
||||
ReadyTime: new(time.Date(2003, 11, 4, 23, 15, 7, 0, time.UTC)),
|
||||
Tracks: []defs.APIPathTrackCodec{formatlabel.H264, formatlabel.H265},
|
||||
InboundBytes: 123,
|
||||
OutboundBytes: 456,
|
||||
|
||||
@@ -42,12 +42,6 @@ var errNoSupportedCodecsFrom = errors.New(
|
||||
"the stream doesn't contain any supported codec, which are currently " +
|
||||
"AV1, VP9, VP8, H265, H264, Opus, G722, G711, LPCM")
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
func randUint32() (uint32, error) {
|
||||
var b [4]byte
|
||||
_, err := rand.Read(b[:])
|
||||
@@ -131,7 +125,7 @@ func setupVideoTrack(
|
||||
encoder := &rtpvp9.Encoder{
|
||||
PayloadType: 96,
|
||||
PayloadMaxSize: webrtcPayloadMaxSize,
|
||||
InitialPictureID: ptrOf(uint16(8445)),
|
||||
InitialPictureID: new(uint16(8445)),
|
||||
}
|
||||
err := encoder.Init()
|
||||
if err != nil {
|
||||
|
||||
@@ -14,7 +14,7 @@ type OutgoingDataChannel struct {
|
||||
func (c *OutgoingDataChannel) setup(p *PeerConnection) error {
|
||||
var err error
|
||||
c.dataChan, err = p.wr.CreateDataChannel(c.Label, &webrtc.DataChannelInit{
|
||||
Ordered: ptrOf(false),
|
||||
Ordered: new(false),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,12 +11,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
func TestFindAllPathsWithSegments(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
@@ -93,11 +87,11 @@ func TestFindSegments(t *testing.T) {
|
||||
case "no filtering":
|
||||
|
||||
case "filtering":
|
||||
start = ptrOf(time.Date(2015, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||
end = ptrOf(start.Add(60 * time.Minute))
|
||||
start = new(time.Date(2015, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||
end = new(start.Add(60 * time.Minute))
|
||||
|
||||
case "start before first":
|
||||
start = ptrOf(time.Date(2014, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||
start = new(time.Date(2014, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||
}
|
||||
|
||||
segments, err := FindSegments(
|
||||
|
||||
@@ -27,12 +27,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
type dummyPath struct{}
|
||||
|
||||
func (p *dummyPath) Name() string {
|
||||
@@ -201,8 +195,8 @@ func TestServerPublish(t *testing.T) {
|
||||
BytesSent: list.Items[0].BytesSent,
|
||||
Conns: list.Items[0].Conns,
|
||||
RTPPacketsReceived: list.Items[0].RTPPacketsReceived,
|
||||
Transport: ptrOf("TCP"),
|
||||
Profile: ptrOf("AVP"),
|
||||
Transport: new("TCP"),
|
||||
Profile: new("AVP"),
|
||||
},
|
||||
},
|
||||
}, list)
|
||||
@@ -525,8 +519,8 @@ func TestServerRead(t *testing.T) {
|
||||
Conns: list.Items[0].Conns,
|
||||
RTPPacketsReceived: list.Items[0].RTPPacketsReceived,
|
||||
RTPPacketsSent: list.Items[0].RTPPacketsSent,
|
||||
Transport: ptrOf("TCP"),
|
||||
Profile: ptrOf("AVP"),
|
||||
Transport: new("TCP"),
|
||||
Profile: new("AVP"),
|
||||
},
|
||||
},
|
||||
}, list)
|
||||
|
||||
@@ -19,12 +19,6 @@ import (
|
||||
"github.com/bluenviron/mediamtx/internal/test"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
type testServer struct {
|
||||
onDescribe func(*gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error)
|
||||
onSetup func(*gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error)
|
||||
@@ -514,7 +508,7 @@ func TestSkipBackChannel(t *testing.T) {
|
||||
Context: ctx,
|
||||
ResolvedSource: "rtsp://127.0.0.1:8555/teststream",
|
||||
Conf: &conf.Path{
|
||||
RTSPTransport: conf.RTSPTransport{Protocol: ptrOf(gortsplib.ProtocolTCP)},
|
||||
RTSPTransport: conf.RTSPTransport{Protocol: new(gortsplib.ProtocolTCP)},
|
||||
RTSPUDPSourcePortRange: []uint{10000, 65535},
|
||||
},
|
||||
})
|
||||
@@ -590,7 +584,7 @@ func TestOnlyBackChannelsError(t *testing.T) {
|
||||
Context: ctx,
|
||||
ResolvedSource: "rtsp://127.0.0.1:8555/teststream",
|
||||
Conf: &conf.Path{
|
||||
RTSPTransport: conf.RTSPTransport{Protocol: ptrOf(gortsplib.ProtocolTCP)},
|
||||
RTSPTransport: conf.RTSPTransport{Protocol: new(gortsplib.ProtocolTCP)},
|
||||
RTSPUDPSourcePortRange: []uint{10000, 65535},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -24,12 +24,6 @@ import (
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
func ptrOf[T any](v T) *T {
|
||||
p := new(T)
|
||||
*p = v
|
||||
return p
|
||||
}
|
||||
|
||||
type rtpEncoderNotAvailableError struct {
|
||||
format format.Format
|
||||
}
|
||||
@@ -219,7 +213,7 @@ func newRTPEncoder(
|
||||
PayloadType: forma.PayloadTyp,
|
||||
SSRC: ssrc,
|
||||
InitialSequenceNumber: initialSequenceNumber,
|
||||
InitialPictureID: ptrOf(uint16(0x35af)),
|
||||
InitialPictureID: new(uint16(0x35af)),
|
||||
}
|
||||
err := wrapped.Init()
|
||||
if err != nil {
|
||||
|
||||
@@ -126,7 +126,7 @@ func (ssf *subStreamFormat) writeUnitInner(u *unit.Unit) error {
|
||||
if len(pkt.Payload) > ssf.streamFormat.rtpMaxPayloadSize {
|
||||
var err error
|
||||
ssf.streamFormat.rtpEncoder, err = newRTPEncoder(ssf.streamFormat.format, ssf.streamFormat.rtpMaxPayloadSize,
|
||||
ptrOf(pkt.SSRC), ptrOf(pkt.SequenceNumber))
|
||||
new(pkt.SSRC), new(pkt.SequenceNumber))
|
||||
if err != nil {
|
||||
var err2 rtpEncoderNotAvailableError
|
||||
if errors.As(err, &err2) {
|
||||
|
||||
Reference in New Issue
Block a user