mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
simplify code with ptrOf (#5179)
This commit is contained in:
parent
569d457132
commit
8858bf1db9
2 changed files with 14 additions and 12 deletions
|
|
@ -8,6 +8,10 @@ import (
|
||||||
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
|
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ptrOf[T any](v T) *T {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
// RTSPTransport is the rtspTransport parameter.
|
// RTSPTransport is the rtspTransport parameter.
|
||||||
type RTSPTransport struct {
|
type RTSPTransport struct {
|
||||||
*gortsplib.Protocol
|
*gortsplib.Protocol
|
||||||
|
|
@ -44,16 +48,13 @@ func (d *RTSPTransport) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
switch in {
|
switch in {
|
||||||
case "udp":
|
case "udp":
|
||||||
v := gortsplib.ProtocolUDP
|
d.Protocol = ptrOf(gortsplib.ProtocolUDP)
|
||||||
d.Protocol = &v
|
|
||||||
|
|
||||||
case "multicast":
|
case "multicast":
|
||||||
v := gortsplib.ProtocolUDPMulticast
|
d.Protocol = ptrOf(gortsplib.ProtocolUDPMulticast)
|
||||||
d.Protocol = &v
|
|
||||||
|
|
||||||
case "tcp":
|
case "tcp":
|
||||||
v := gortsplib.ProtocolTCP
|
d.Protocol = ptrOf(gortsplib.ProtocolTCP)
|
||||||
d.Protocol = &v
|
|
||||||
|
|
||||||
case "automatic":
|
case "automatic":
|
||||||
d.Protocol = nil
|
d.Protocol = nil
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ptrOf[T any](v T) *T {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
func TestFindAllPathsWithSegments(t *testing.T) {
|
func TestFindAllPathsWithSegments(t *testing.T) {
|
||||||
dir, err := os.MkdirTemp("", "mediamtx-recordstore")
|
dir, err := os.MkdirTemp("", "mediamtx-recordstore")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -93,14 +97,11 @@ func TestFindSegments(t *testing.T) {
|
||||||
case "no filtering":
|
case "no filtering":
|
||||||
|
|
||||||
case "filtering":
|
case "filtering":
|
||||||
tmp1 := time.Date(2015, 5, 19, 22, 18, 25, 427000, time.Local)
|
start = ptrOf(time.Date(2015, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||||
start = &tmp1
|
end = ptrOf(start.Add(60 * time.Minute))
|
||||||
tmp2 := start.Add(60 * time.Minute)
|
|
||||||
end = &tmp2
|
|
||||||
|
|
||||||
case "start before first":
|
case "start before first":
|
||||||
tmp1 := time.Date(2014, 5, 19, 22, 18, 25, 427000, time.Local)
|
start = ptrOf(time.Date(2014, 5, 19, 22, 18, 25, 427000, time.Local))
|
||||||
start = &tmp1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
segments, err := FindSegments(
|
segments, err := FindSegments(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue