Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept durations expressed as days (i.e. '1d') #4094

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type API struct {
ServerCert string
AllowOrigin string
TrustedProxies conf.IPNetworks
ReadTimeout conf.StringDuration
ReadTimeout conf.Duration
Conf *conf.Conf
AuthManager apiAuthManager
PathManager PathManager
Expand Down
34 changes: 17 additions & 17 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestPreflightRequest(t *testing.T) {
api := API{
Address: "localhost:9997",
AllowOrigin: "*",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
AuthManager: test.NilAuthManager,
Parent: &testParent{},
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestConfigGlobalGet(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand All @@ -138,7 +138,7 @@ func TestConfigGlobalPatch(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestConfigGlobalPatchUnknownField(t *testing.T) { //nolint:dupl

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestConfigPathDefaultsGet(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand All @@ -234,7 +234,7 @@ func TestConfigPathDefaultsPatch(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestConfigPathsList(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestConfigPathsGet(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand All @@ -337,7 +337,7 @@ func TestConfigPathsAdd(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestConfigPathsAddUnknownField(t *testing.T) { //nolint:dupl

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestConfigPathsPatch(t *testing.T) { //nolint:dupl

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestConfigPathsReplace(t *testing.T) { //nolint:dupl

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestConfigPathsReplaceNonExisting(t *testing.T) { //nolint:dupl

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -520,7 +520,7 @@ func TestConfigPathsDelete(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -565,7 +565,7 @@ func TestRecordingsList(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -634,7 +634,7 @@ func TestRecordingsGet(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestRecordingsDeleteSegment(t *testing.T) {

api := API{
Address: "localhost:9997",
ReadTimeout: conf.StringDuration(10 * time.Second),
ReadTimeout: conf.Duration(10 * time.Second),
Conf: cnf,
AuthManager: test.NilAuthManager,
Parent: &testParent{},
Expand Down
66 changes: 33 additions & 33 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ type Conf struct {
LogLevel LogLevel `json:"logLevel"`
LogDestinations LogDestinations `json:"logDestinations"`
LogFile string `json:"logFile"`
ReadTimeout StringDuration `json:"readTimeout"`
WriteTimeout StringDuration `json:"writeTimeout"`
ReadTimeout Duration `json:"readTimeout"`
WriteTimeout Duration `json:"writeTimeout"`
ReadBufferCount *int `json:"readBufferCount,omitempty"` // deprecated
WriteQueueSize int `json:"writeQueueSize"`
UDPMaxPayloadSize int `json:"udpMaxPayloadSize"`
Expand Down Expand Up @@ -246,22 +246,22 @@ type Conf struct {
RTMPServerCert string `json:"rtmpServerCert"`

// HLS server
HLS bool `json:"hls"`
HLSDisable *bool `json:"hlsDisable,omitempty"` // deprecated
HLSAddress string `json:"hlsAddress"`
HLSEncryption bool `json:"hlsEncryption"`
HLSServerKey string `json:"hlsServerKey"`
HLSServerCert string `json:"hlsServerCert"`
HLSAllowOrigin string `json:"hlsAllowOrigin"`
HLSTrustedProxies IPNetworks `json:"hlsTrustedProxies"`
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
HLSVariant HLSVariant `json:"hlsVariant"`
HLSSegmentCount int `json:"hlsSegmentCount"`
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
HLSPartDuration StringDuration `json:"hlsPartDuration"`
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
HLSDirectory string `json:"hlsDirectory"`
HLSMuxerCloseAfter StringDuration `json:"hlsMuxerCloseAfter"`
HLS bool `json:"hls"`
HLSDisable *bool `json:"hlsDisable,omitempty"` // deprecated
HLSAddress string `json:"hlsAddress"`
HLSEncryption bool `json:"hlsEncryption"`
HLSServerKey string `json:"hlsServerKey"`
HLSServerCert string `json:"hlsServerCert"`
HLSAllowOrigin string `json:"hlsAllowOrigin"`
HLSTrustedProxies IPNetworks `json:"hlsTrustedProxies"`
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
HLSVariant HLSVariant `json:"hlsVariant"`
HLSSegmentCount int `json:"hlsSegmentCount"`
HLSSegmentDuration Duration `json:"hlsSegmentDuration"`
HLSPartDuration Duration `json:"hlsPartDuration"`
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
HLSDirectory string `json:"hlsDirectory"`
HLSMuxerCloseAfter Duration `json:"hlsMuxerCloseAfter"`

// WebRTC server
WebRTC bool `json:"webrtc"`
Expand All @@ -278,8 +278,8 @@ type Conf struct {
WebRTCIPsFromInterfacesList []string `json:"webrtcIPsFromInterfacesList"`
WebRTCAdditionalHosts []string `json:"webrtcAdditionalHosts"`
WebRTCICEServers2 WebRTCICEServers `json:"webrtcICEServers2"`
WebRTCHandshakeTimeout StringDuration `json:"webrtcHandshakeTimeout"`
WebRTCTrackGatherTimeout StringDuration `json:"webrtcTrackGatherTimeout"`
WebRTCHandshakeTimeout Duration `json:"webrtcHandshakeTimeout"`
WebRTCTrackGatherTimeout Duration `json:"webrtcTrackGatherTimeout"`
WebRTCICEUDPMuxAddress *string `json:"webrtcICEUDPMuxAddress,omitempty"` // deprecated
WebRTCICETCPMuxAddress *string `json:"webrtcICETCPMuxAddress,omitempty"` // deprecated
WebRTCICEHostNAT1To1IPs *[]string `json:"webrtcICEHostNAT1To1IPs,omitempty"` // deprecated
Expand All @@ -290,12 +290,12 @@ type Conf struct {
SRTAddress string `json:"srtAddress"`

// Record (deprecated)
Record *bool `json:"record,omitempty"` // deprecated
RecordPath *string `json:"recordPath,omitempty"` // deprecated
RecordFormat *RecordFormat `json:"recordFormat,omitempty"` // deprecated
RecordPartDuration *StringDuration `json:"recordPartDuration,omitempty"` // deprecated
RecordSegmentDuration *StringDuration `json:"recordSegmentDuration,omitempty"` // deprecated
RecordDeleteAfter *StringDuration `json:"recordDeleteAfter,omitempty"` // deprecated
Record *bool `json:"record,omitempty"` // deprecated
RecordPath *string `json:"recordPath,omitempty"` // deprecated
RecordFormat *RecordFormat `json:"recordFormat,omitempty"` // deprecated
RecordPartDuration *Duration `json:"recordPartDuration,omitempty"` // deprecated
RecordSegmentDuration *Duration `json:"recordSegmentDuration,omitempty"` // deprecated
RecordDeleteAfter *Duration `json:"recordDeleteAfter,omitempty"` // deprecated

// Path defaults
PathDefaults Path `json:"pathDefaults"`
Expand All @@ -310,8 +310,8 @@ func (conf *Conf) setDefaults() {
conf.LogLevel = LogLevel(logger.Info)
conf.LogDestinations = LogDestinations{logger.DestinationStdout}
conf.LogFile = "mediamtx.log"
conf.ReadTimeout = 10 * StringDuration(time.Second)
conf.WriteTimeout = 10 * StringDuration(time.Second)
conf.ReadTimeout = 10 * Duration(time.Second)
conf.WriteTimeout = 10 * Duration(time.Second)
conf.WriteQueueSize = 512
conf.UDPMaxPayloadSize = 1472

Expand Down Expand Up @@ -387,10 +387,10 @@ func (conf *Conf) setDefaults() {
conf.HLSAllowOrigin = "*"
conf.HLSVariant = HLSVariant(gohlslib.MuxerVariantLowLatency)
conf.HLSSegmentCount = 7
conf.HLSSegmentDuration = 1 * StringDuration(time.Second)
conf.HLSPartDuration = 200 * StringDuration(time.Millisecond)
conf.HLSSegmentDuration = 1 * Duration(time.Second)
conf.HLSPartDuration = 200 * Duration(time.Millisecond)
conf.HLSSegmentMaxSize = 50 * 1024 * 1024
conf.HLSMuxerCloseAfter = 60 * StringDuration(time.Second)
conf.HLSMuxerCloseAfter = 60 * Duration(time.Second)

// WebRTC server
conf.WebRTC = true
Expand All @@ -403,8 +403,8 @@ func (conf *Conf) setDefaults() {
conf.WebRTCIPsFromInterfacesList = []string{}
conf.WebRTCAdditionalHosts = []string{}
conf.WebRTCICEServers2 = []WebRTCICEServer{}
conf.WebRTCHandshakeTimeout = 10 * StringDuration(time.Second)
conf.WebRTCTrackGatherTimeout = 2 * StringDuration(time.Second)
conf.WebRTCHandshakeTimeout = 10 * Duration(time.Second)
conf.WebRTCTrackGatherTimeout = 2 * Duration(time.Second)

// SRT server
conf.SRT = true
Expand Down
10 changes: 5 additions & 5 deletions internal/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func TestConfFromFile(t *testing.T) {
require.Equal(t, &Path{
Name: "cam1",
Source: "publisher",
SourceOnDemandStartTimeout: 10 * StringDuration(time.Second),
SourceOnDemandCloseAfter: 10 * StringDuration(time.Second),
SourceOnDemandStartTimeout: 10 * Duration(time.Second),
SourceOnDemandCloseAfter: 10 * Duration(time.Second),
RecordPath: "./recordings/%path/%Y-%m-%d_%H-%M-%S-%f",
RecordFormat: RecordFormatFMP4,
RecordPartDuration: StringDuration(1 * time.Second),
RecordPartDuration: Duration(1 * time.Second),
RecordSegmentDuration: 3600000000000,
RecordDeleteAfter: 86400000000000,
OverridePublisher: true,
Expand All @@ -78,8 +78,8 @@ func TestConfFromFile(t *testing.T) {
RPICameraBitrate: 5000000,
RPICameraProfile: "main",
RPICameraLevel: "4.1",
RunOnDemandStartTimeout: 5 * StringDuration(time.Second),
RunOnDemandCloseAfter: 10 * StringDuration(time.Second),
RunOnDemandStartTimeout: 5 * Duration(time.Second),
RunOnDemandCloseAfter: 10 * Duration(time.Second),
}, pa)
}()

Expand Down
Loading
Loading