diff --git a/internal/conf/env/env_test.go b/internal/conf/env/env_test.go index 6f2b22ad..198e6d8e 100644 --- a/internal/conf/env/env_test.go +++ b/internal/conf/env/env_test.go @@ -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: "", diff --git a/internal/conf/path_test.go b/internal/conf/path_test.go index 1a7986e8..df41f34a 100644 --- a/internal/conf/path_test.go +++ b/internal/conf/path_test.go @@ -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", } diff --git a/internal/conf/rtsp_transport.go b/internal/conf/rtsp_transport.go index c1ca8ca7..94e3c549 100644 --- a/internal/conf/rtsp_transport.go +++ b/internal/conf/rtsp_transport.go @@ -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 diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go index 92ce23eb..b4c62947 100644 --- a/internal/metrics/metrics_test.go +++ b/internal/metrics/metrics_test.go @@ -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, diff --git a/internal/protocols/webrtc/from_stream.go b/internal/protocols/webrtc/from_stream.go index f127d98d..49c175ec 100644 --- a/internal/protocols/webrtc/from_stream.go +++ b/internal/protocols/webrtc/from_stream.go @@ -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 { diff --git a/internal/protocols/webrtc/outgoing_data_channel.go b/internal/protocols/webrtc/outgoing_data_channel.go index 9b4cd380..faa48c82 100644 --- a/internal/protocols/webrtc/outgoing_data_channel.go +++ b/internal/protocols/webrtc/outgoing_data_channel.go @@ -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 diff --git a/internal/recordstore/segment_test.go b/internal/recordstore/segment_test.go index 52d65951..768d3096 100644 --- a/internal/recordstore/segment_test.go +++ b/internal/recordstore/segment_test.go @@ -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( diff --git a/internal/servers/rtsp/server_test.go b/internal/servers/rtsp/server_test.go index 211a1922..9700c11d 100644 --- a/internal/servers/rtsp/server_test.go +++ b/internal/servers/rtsp/server_test.go @@ -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) diff --git a/internal/staticsources/rtsp/source_test.go b/internal/staticsources/rtsp/source_test.go index ff1f8393..4e8dc720 100644 --- a/internal/staticsources/rtsp/source_test.go +++ b/internal/staticsources/rtsp/source_test.go @@ -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}, }, }) diff --git a/internal/stream/rtp_encoder.go b/internal/stream/rtp_encoder.go index 15a6de82..c7beedfa 100644 --- a/internal/stream/rtp_encoder.go +++ b/internal/stream/rtp_encoder.go @@ -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 { diff --git a/internal/stream/sub_stream_format.go b/internal/stream/sub_stream_format.go index 2a9c3e7f..4b91a9da 100644 --- a/internal/stream/sub_stream_format.go +++ b/internal/stream/sub_stream_format.go @@ -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) {