rename readBufferCount into writeQueueSize (#2248)

This commit is contained in:
Alessandro Ros
2023-08-26 13:25:21 +02:00
committed by GitHub
parent e0fb11040e
commit bf8e69ea89
19 changed files with 104 additions and 99 deletions

View File

@@ -1276,10 +1276,10 @@ rtsps://localhost:8322/mystream
In some scenarios, when publishing or reading from the server with RTSP, frames can get corrupted. This can be caused by multiple reasons: In some scenarios, when publishing or reading from the server with RTSP, frames can get corrupted. This can be caused by multiple reasons:
* the packet buffer of the server is too small and can't keep up with the stream throughput. A solution consists in increasing its size: * the write queue of the server is too small and can't keep up with the stream throughput. A solution consists in increasing its size:
```yml ```yml
readBufferCount: 1024 writeQueueSize: 1024
``` ```
* The stream throughput is too big and the stream can't be transmitted correctly with the UDP transport protocol. UDP is more performant, faster and more efficient than TCP, but doesn't have a retransmission mechanism, that is needed in case of streams that need a large bandwidth. A solution consists in switching to TCP: * The stream throughput is too big and the stream can't be transmitted correctly with the UDP transport protocol. UDP is more performant, faster and more efficient than TCP, but doesn't have a retransmission mechanism, that is needed in case of streams that need a large bandwidth. A solution consists in switching to TCP:

View File

@@ -31,7 +31,7 @@ components:
type: string type: string
writeTimeout: writeTimeout:
type: string type: string
readBufferCount: writeQueueSize:
type: integer type: integer
udpMaxPayloadSize: udpMaxPayloadSize:
type: integer type: integer

View File

@@ -95,7 +95,8 @@ type Conf struct {
LogFile string `json:"logFile"` LogFile string `json:"logFile"`
ReadTimeout StringDuration `json:"readTimeout"` ReadTimeout StringDuration `json:"readTimeout"`
WriteTimeout StringDuration `json:"writeTimeout"` WriteTimeout StringDuration `json:"writeTimeout"`
ReadBufferCount int `json:"readBufferCount"` ReadBufferCount int `json:"readBufferCount"` // deprecated
WriteQueueSize int `json:"writeQueueSize"`
UDPMaxPayloadSize int `json:"udpMaxPayloadSize"` UDPMaxPayloadSize int `json:"udpMaxPayloadSize"`
ExternalAuthenticationURL string `json:"externalAuthenticationURL"` ExternalAuthenticationURL string `json:"externalAuthenticationURL"`
API bool `json:"api"` API bool `json:"api"`
@@ -218,8 +219,11 @@ func (conf Conf) Clone() *Conf {
// Check checks the configuration for errors. // Check checks the configuration for errors.
func (conf *Conf) Check() error { func (conf *Conf) Check() error {
// general // general
if (conf.ReadBufferCount & (conf.ReadBufferCount - 1)) != 0 { if conf.ReadBufferCount != 0 {
return fmt.Errorf("'readBufferCount' must be a power of two") conf.WriteQueueSize = conf.ReadBufferCount
}
if (conf.WriteQueueSize & (conf.WriteQueueSize - 1)) != 0 {
return fmt.Errorf("'writeQueueSize' must be a power of two")
} }
if conf.UDPMaxPayloadSize > 1472 { if conf.UDPMaxPayloadSize > 1472 {
return fmt.Errorf("'udpMaxPayloadSize' must be less than 1472") return fmt.Errorf("'udpMaxPayloadSize' must be less than 1472")
@@ -317,7 +321,7 @@ func (conf *Conf) UnmarshalJSON(b []byte) error {
conf.LogFile = "mediamtx.log" conf.LogFile = "mediamtx.log"
conf.ReadTimeout = 10 * StringDuration(time.Second) conf.ReadTimeout = 10 * StringDuration(time.Second)
conf.WriteTimeout = 10 * StringDuration(time.Second) conf.WriteTimeout = 10 * StringDuration(time.Second)
conf.ReadBufferCount = 512 conf.WriteQueueSize = 512
conf.UDPMaxPayloadSize = 1472 conf.UDPMaxPayloadSize = 1472
conf.APIAddress = "127.0.0.1:9997" conf.APIAddress = "127.0.0.1:9997"
conf.MetricsAddress = "127.0.0.1:9998" conf.MetricsAddress = "127.0.0.1:9998"

View File

@@ -217,9 +217,9 @@ func TestConfErrors(t *testing.T) {
"json: unknown field \"invalid\"", "json: unknown field \"invalid\"",
}, },
{ {
"invalid readBufferCount", "invalid writeQueueSize",
"readBufferCount: 1001\n", "writeQueueSize: 1001\n",
"'readBufferCount' must be a power of two", "'writeQueueSize' must be a power of two",
}, },
{ {
"invalid udpMaxPayloadSize", "invalid udpMaxPayloadSize",

View File

@@ -246,7 +246,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.AuthMethods, p.conf.AuthMethods,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
p.conf.UDPMaxPayloadSize, p.conf.UDPMaxPayloadSize,
p.conf.Paths, p.conf.Paths,
p.externalCmdPool, p.externalCmdPool,
@@ -266,7 +266,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.AuthMethods, p.conf.AuthMethods,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
useUDP, useUDP,
useMulticast, useMulticast,
p.conf.RTPAddress, p.conf.RTPAddress,
@@ -301,7 +301,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.AuthMethods, p.conf.AuthMethods,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
false, false,
false, false,
"", "",
@@ -335,7 +335,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.RTMPAddress, p.conf.RTMPAddress,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
false, false,
"", "",
"", "",
@@ -361,7 +361,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.RTMPSAddress, p.conf.RTMPSAddress,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
true, true,
p.conf.RTMPServerCert, p.conf.RTMPServerCert,
p.conf.RTMPServerKey, p.conf.RTMPServerKey,
@@ -397,7 +397,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.HLSTrustedProxies, p.conf.HLSTrustedProxies,
p.conf.HLSDirectory, p.conf.HLSDirectory,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
p.pathManager, p.pathManager,
p.metrics, p.metrics,
p, p,
@@ -419,7 +419,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.WebRTCTrustedProxies, p.conf.WebRTCTrustedProxies,
p.conf.WebRTCICEServers2, p.conf.WebRTCICEServers2,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
p.conf.WebRTCICEHostNAT1To1IPs, p.conf.WebRTCICEHostNAT1To1IPs,
p.conf.WebRTCICEUDPMuxAddress, p.conf.WebRTCICEUDPMuxAddress,
p.conf.WebRTCICETCPMuxAddress, p.conf.WebRTCICETCPMuxAddress,
@@ -439,7 +439,7 @@ func (p *Core) createResources(initial bool) error {
p.conf.SRTAddress, p.conf.SRTAddress,
p.conf.ReadTimeout, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.WriteTimeout,
p.conf.ReadBufferCount, p.conf.WriteQueueSize,
p.conf.UDPMaxPayloadSize, p.conf.UDPMaxPayloadSize,
p.externalCmdPool, p.externalCmdPool,
p.pathManager, p.pathManager,
@@ -504,7 +504,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) || !reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize || newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize ||
closeMetrics closeMetrics
if !closePathManager && !reflect.DeepEqual(newConf.Paths, p.conf.Paths) { if !closePathManager && !reflect.DeepEqual(newConf.Paths, p.conf.Paths) {
@@ -518,7 +518,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) || !reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
!reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) || !reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) ||
newConf.RTPAddress != p.conf.RTPAddress || newConf.RTPAddress != p.conf.RTPAddress ||
newConf.RTCPAddress != p.conf.RTCPAddress || newConf.RTCPAddress != p.conf.RTCPAddress ||
@@ -539,7 +539,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) || !reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.ServerCert != p.conf.ServerCert || newConf.ServerCert != p.conf.ServerCert ||
newConf.ServerKey != p.conf.ServerKey || newConf.ServerKey != p.conf.ServerKey ||
newConf.RTSPAddress != p.conf.RTSPAddress || newConf.RTSPAddress != p.conf.RTSPAddress ||
@@ -555,7 +555,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.RTMPAddress != p.conf.RTMPAddress || newConf.RTMPAddress != p.conf.RTMPAddress ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.RTSPAddress != p.conf.RTSPAddress || newConf.RTSPAddress != p.conf.RTSPAddress ||
newConf.RunOnConnect != p.conf.RunOnConnect || newConf.RunOnConnect != p.conf.RunOnConnect ||
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart || newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
@@ -568,7 +568,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.RTMPSAddress != p.conf.RTMPSAddress || newConf.RTMPSAddress != p.conf.RTMPSAddress ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.RTMPServerCert != p.conf.RTMPServerCert || newConf.RTMPServerCert != p.conf.RTMPServerCert ||
newConf.RTMPServerKey != p.conf.RTMPServerKey || newConf.RTMPServerKey != p.conf.RTMPServerKey ||
newConf.RTSPAddress != p.conf.RTSPAddress || newConf.RTSPAddress != p.conf.RTSPAddress ||
@@ -594,7 +594,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.HLSTrustedProxies, p.conf.HLSTrustedProxies) || !reflect.DeepEqual(newConf.HLSTrustedProxies, p.conf.HLSTrustedProxies) ||
newConf.HLSDirectory != p.conf.HLSDirectory || newConf.HLSDirectory != p.conf.HLSDirectory ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
closePathManager || closePathManager ||
closeMetrics closeMetrics
@@ -608,7 +608,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.WebRTCTrustedProxies, p.conf.WebRTCTrustedProxies) || !reflect.DeepEqual(newConf.WebRTCTrustedProxies, p.conf.WebRTCTrustedProxies) ||
!reflect.DeepEqual(newConf.WebRTCICEServers2, p.conf.WebRTCICEServers2) || !reflect.DeepEqual(newConf.WebRTCICEServers2, p.conf.WebRTCICEServers2) ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
!reflect.DeepEqual(newConf.WebRTCICEHostNAT1To1IPs, p.conf.WebRTCICEHostNAT1To1IPs) || !reflect.DeepEqual(newConf.WebRTCICEHostNAT1To1IPs, p.conf.WebRTCICEHostNAT1To1IPs) ||
newConf.WebRTCICEUDPMuxAddress != p.conf.WebRTCICEUDPMuxAddress || newConf.WebRTCICEUDPMuxAddress != p.conf.WebRTCICEUDPMuxAddress ||
newConf.WebRTCICETCPMuxAddress != p.conf.WebRTCICETCPMuxAddress || newConf.WebRTCICETCPMuxAddress != p.conf.WebRTCICETCPMuxAddress ||
@@ -620,7 +620,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
newConf.SRTAddress != p.conf.SRTAddress || newConf.SRTAddress != p.conf.SRTAddress ||
newConf.ReadTimeout != p.conf.ReadTimeout || newConf.ReadTimeout != p.conf.ReadTimeout ||
newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteTimeout != p.conf.WriteTimeout ||
newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.WriteQueueSize != p.conf.WriteQueueSize ||
newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize || newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize ||
closePathManager closePathManager

View File

@@ -42,7 +42,7 @@ type hlsManager struct {
partDuration conf.StringDuration partDuration conf.StringDuration
segmentMaxSize conf.StringSize segmentMaxSize conf.StringSize
directory string directory string
readBufferCount int writeQueueSize int
pathManager *pathManager pathManager *pathManager
metrics *metrics metrics *metrics
parent hlsManagerParent parent hlsManagerParent
@@ -78,7 +78,7 @@ func newHLSManager(
trustedProxies conf.IPsOrCIDRs, trustedProxies conf.IPsOrCIDRs,
directory string, directory string,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
pathManager *pathManager, pathManager *pathManager,
metrics *metrics, metrics *metrics,
parent hlsManagerParent, parent hlsManagerParent,
@@ -94,7 +94,7 @@ func newHLSManager(
partDuration: partDuration, partDuration: partDuration,
segmentMaxSize: segmentMaxSize, segmentMaxSize: segmentMaxSize,
directory: directory, directory: directory,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
pathManager: pathManager, pathManager: pathManager,
parent: parent, parent: parent,
metrics: metrics, metrics: metrics,
@@ -241,7 +241,7 @@ func (m *hlsManager) createMuxer(pathName string, remoteAddr string) *hlsMuxer {
m.partDuration, m.partDuration,
m.segmentMaxSize, m.segmentMaxSize,
m.directory, m.directory,
m.readBufferCount, m.writeQueueSize,
&m.wg, &m.wg,
pathName, pathName,
m.pathManager, m.pathManager,

View File

@@ -66,7 +66,7 @@ type hlsMuxer struct {
partDuration conf.StringDuration partDuration conf.StringDuration
segmentMaxSize conf.StringSize segmentMaxSize conf.StringSize
directory string directory string
readBufferCount int writeQueueSize int
wg *sync.WaitGroup wg *sync.WaitGroup
pathName string pathName string
pathManager *pathManager pathManager *pathManager
@@ -96,7 +96,7 @@ func newHLSMuxer(
partDuration conf.StringDuration, partDuration conf.StringDuration,
segmentMaxSize conf.StringSize, segmentMaxSize conf.StringSize,
directory string, directory string,
readBufferCount int, writeQueueSize int,
wg *sync.WaitGroup, wg *sync.WaitGroup,
pathName string, pathName string,
pathManager *pathManager, pathManager *pathManager,
@@ -113,7 +113,7 @@ func newHLSMuxer(
partDuration: partDuration, partDuration: partDuration,
segmentMaxSize: segmentMaxSize, segmentMaxSize: segmentMaxSize,
directory: directory, directory: directory,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
wg: wg, wg: wg,
pathName: pathName, pathName: pathName,
pathManager: pathManager, pathManager: pathManager,
@@ -254,7 +254,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
defer m.path.removeReader(pathRemoveReaderReq{author: m}) defer m.path.removeReader(pathRemoveReaderReq{author: m})
m.ringBuffer, _ = ringbuffer.New(uint64(m.readBufferCount)) m.ringBuffer, _ = ringbuffer.New(uint64(m.writeQueueSize))
var medias media.Medias var medias media.Medias

View File

@@ -174,7 +174,7 @@ type path struct {
rtspAddress string rtspAddress string
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
udpMaxPayloadSize int udpMaxPayloadSize int
confName string confName string
conf *conf.PathConf conf *conf.PathConf
@@ -225,7 +225,7 @@ func newPath(
rtspAddress string, rtspAddress string,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
udpMaxPayloadSize int, udpMaxPayloadSize int,
confName string, confName string,
cnf *conf.PathConf, cnf *conf.PathConf,
@@ -241,7 +241,7 @@ func newPath(
rtspAddress: rtspAddress, rtspAddress: rtspAddress,
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
udpMaxPayloadSize: udpMaxPayloadSize, udpMaxPayloadSize: udpMaxPayloadSize,
confName: confName, confName: confName,
conf: cnf, conf: cnf,
@@ -310,7 +310,7 @@ func (pa *path) run() {
pa.conf, pa.conf,
pa.readTimeout, pa.readTimeout,
pa.writeTimeout, pa.writeTimeout,
pa.readBufferCount, pa.writeQueueSize,
pa) pa)
if !pa.conf.SourceOnDemand { if !pa.conf.SourceOnDemand {

View File

@@ -69,7 +69,7 @@ type pathManager struct {
authMethods conf.AuthMethods authMethods conf.AuthMethods
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
udpMaxPayloadSize int udpMaxPayloadSize int
pathConfs map[string]*conf.PathConf pathConfs map[string]*conf.PathConf
externalCmdPool *externalcmd.Pool externalCmdPool *externalcmd.Pool
@@ -103,7 +103,7 @@ func newPathManager(
authMethods conf.AuthMethods, authMethods conf.AuthMethods,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
udpMaxPayloadSize int, udpMaxPayloadSize int,
pathConfs map[string]*conf.PathConf, pathConfs map[string]*conf.PathConf,
externalCmdPool *externalcmd.Pool, externalCmdPool *externalcmd.Pool,
@@ -118,7 +118,7 @@ func newPathManager(
authMethods: authMethods, authMethods: authMethods,
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
udpMaxPayloadSize: udpMaxPayloadSize, udpMaxPayloadSize: udpMaxPayloadSize,
pathConfs: pathConfs, pathConfs: pathConfs,
externalCmdPool: externalCmdPool, externalCmdPool: externalCmdPool,
@@ -352,7 +352,7 @@ func (pm *pathManager) createPath(
pm.rtspAddress, pm.rtspAddress,
pm.readTimeout, pm.readTimeout,
pm.writeTimeout, pm.writeTimeout,
pm.readBufferCount, pm.writeQueueSize,
pm.udpMaxPayloadSize, pm.udpMaxPayloadSize,
pathConfName, pathConfName,
pathConf, pathConf,

View File

@@ -60,7 +60,7 @@ type rtmpConn struct {
rtspAddress string rtspAddress string
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
runOnConnect string runOnConnect string
runOnConnectRestart bool runOnConnectRestart bool
wg *sync.WaitGroup wg *sync.WaitGroup
@@ -85,7 +85,7 @@ func newRTMPConn(
rtspAddress string, rtspAddress string,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
runOnConnect string, runOnConnect string,
runOnConnectRestart bool, runOnConnectRestart bool,
wg *sync.WaitGroup, wg *sync.WaitGroup,
@@ -101,7 +101,7 @@ func newRTMPConn(
rtspAddress: rtspAddress, rtspAddress: rtspAddress,
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
runOnConnect: runOnConnect, runOnConnect: runOnConnect,
runOnConnectRestart: runOnConnectRestart, runOnConnectRestart: runOnConnectRestart,
wg: wg, wg: wg,
@@ -241,7 +241,7 @@ func (c *rtmpConn) runRead(conn *rtmp.Conn, u *url.URL) error {
c.pathName = pathName c.pathName = pathName
c.mutex.Unlock() c.mutex.Unlock()
ringBuffer, _ := ringbuffer.New(uint64(c.readBufferCount)) ringBuffer, _ := ringbuffer.New(uint64(c.writeQueueSize))
go func() { go func() {
<-c.ctx.Done() <-c.ctx.Done()
ringBuffer.Close() ringBuffer.Close()

View File

@@ -50,7 +50,7 @@ type rtmpServerParent interface {
type rtmpServer struct { type rtmpServer struct {
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
isTLS bool isTLS bool
rtspAddress string rtspAddress string
runOnConnect string runOnConnect string
@@ -79,7 +79,7 @@ func newRTMPServer(
address string, address string,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
isTLS bool, isTLS bool,
serverCert string, serverCert string,
serverKey string, serverKey string,
@@ -113,7 +113,7 @@ func newRTMPServer(
s := &rtmpServer{ s := &rtmpServer{
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
rtspAddress: rtspAddress, rtspAddress: rtspAddress,
runOnConnect: runOnConnect, runOnConnect: runOnConnect,
runOnConnectRestart: runOnConnectRestart, runOnConnectRestart: runOnConnectRestart,
@@ -185,7 +185,7 @@ outer:
s.rtspAddress, s.rtspAddress,
s.readTimeout, s.readTimeout,
s.writeTimeout, s.writeTimeout,
s.readBufferCount, s.writeQueueSize,
s.runOnConnect, s.runOnConnect,
s.runOnConnectRestart, s.runOnConnectRestart,
&s.wg, &s.wg,

View File

@@ -67,7 +67,7 @@ func newRTSPServer(
authMethods []headers.AuthMethod, authMethods []headers.AuthMethod,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
useUDP bool, useUDP bool,
useMulticast bool, useMulticast bool,
rtpAddress string, rtpAddress string,
@@ -111,8 +111,8 @@ func newRTSPServer(
Handler: s, Handler: s,
ReadTimeout: time.Duration(readTimeout), ReadTimeout: time.Duration(readTimeout),
WriteTimeout: time.Duration(writeTimeout), WriteTimeout: time.Duration(writeTimeout),
ReadBufferCount: readBufferCount, ReadBufferCount: writeQueueSize,
WriteBufferCount: readBufferCount, WriteBufferCount: writeQueueSize,
RTSPAddress: address, RTSPAddress: address,
} }

View File

@@ -66,23 +66,23 @@ type rtspSourceParent interface {
} }
type rtspSource struct { type rtspSource struct {
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
parent rtspSourceParent parent rtspSourceParent
} }
func newRTSPSource( func newRTSPSource(
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
parent rtspSourceParent, parent rtspSourceParent,
) *rtspSource { ) *rtspSource {
return &rtspSource{ return &rtspSource{
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
parent: parent, parent: parent,
} }
} }
@@ -95,12 +95,13 @@ func (s *rtspSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf cha
s.Log(logger.Debug, "connecting") s.Log(logger.Debug, "connecting")
c := &gortsplib.Client{ c := &gortsplib.Client{
Transport: cnf.SourceProtocol.Transport, Transport: cnf.SourceProtocol.Transport,
TLSConfig: tlsConfigForFingerprint(cnf.SourceFingerprint), TLSConfig: tlsConfigForFingerprint(cnf.SourceFingerprint),
ReadTimeout: time.Duration(s.readTimeout), ReadTimeout: time.Duration(s.readTimeout),
WriteTimeout: time.Duration(s.writeTimeout), WriteTimeout: time.Duration(s.writeTimeout),
ReadBufferCount: s.readBufferCount, ReadBufferCount: s.writeQueueSize,
AnyPortEnable: cnf.SourceAnyPortEnable, WriteBufferCount: s.writeQueueSize,
AnyPortEnable: cnf.SourceAnyPortEnable,
OnRequest: func(req *base.Request) { OnRequest: func(req *base.Request) {
s.Log(logger.Debug, "c->s %v", req) s.Log(logger.Debug, "c->s %v", req)
}, },

View File

@@ -49,7 +49,7 @@ func newSourceStatic(
cnf *conf.PathConf, cnf *conf.PathConf,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
parent sourceStaticParent, parent sourceStaticParent,
) *sourceStatic { ) *sourceStatic {
s := &sourceStatic{ s := &sourceStatic{
@@ -66,7 +66,7 @@ func newSourceStatic(
s.impl = newRTSPSource( s.impl = newRTSPSource(
readTimeout, readTimeout,
writeTimeout, writeTimeout,
readBufferCount, writeQueueSize,
s) s)
case strings.HasPrefix(cnf.Source, "rtmp://") || case strings.HasPrefix(cnf.Source, "rtmp://") ||

View File

@@ -50,7 +50,7 @@ type srtConnParent interface {
type srtConn struct { type srtConn struct {
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
udpMaxPayloadSize int udpMaxPayloadSize int
connReq srt.ConnRequest connReq srt.ConnRequest
wg *sync.WaitGroup wg *sync.WaitGroup
@@ -75,7 +75,7 @@ func newSRTConn(
parentCtx context.Context, parentCtx context.Context,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
udpMaxPayloadSize int, udpMaxPayloadSize int,
connReq srt.ConnRequest, connReq srt.ConnRequest,
wg *sync.WaitGroup, wg *sync.WaitGroup,
@@ -88,7 +88,7 @@ func newSRTConn(
c := &srtConn{ c := &srtConn{
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
udpMaxPayloadSize: udpMaxPayloadSize, udpMaxPayloadSize: udpMaxPayloadSize,
connReq: connReq, connReq: connReq,
wg: wg, wg: wg,
@@ -416,7 +416,7 @@ func (c *srtConn) runRead(req srtNewConnReq, pathName string, user string, pass
c.conn = sconn c.conn = sconn
c.mutex.Unlock() c.mutex.Unlock()
ringBuffer, _ := ringbuffer.New(uint64(c.readBufferCount)) ringBuffer, _ := ringbuffer.New(uint64(c.writeQueueSize))
go func() { go func() {
<-c.ctx.Done() <-c.ctx.Done()
ringBuffer.Close() ringBuffer.Close()

View File

@@ -59,7 +59,7 @@ type srtServerParent interface {
type srtServer struct { type srtServer struct {
readTimeout conf.StringDuration readTimeout conf.StringDuration
writeTimeout conf.StringDuration writeTimeout conf.StringDuration
readBufferCount int writeQueueSize int
udpMaxPayloadSize int udpMaxPayloadSize int
externalCmdPool *externalcmd.Pool externalCmdPool *externalcmd.Pool
pathManager *pathManager pathManager *pathManager
@@ -84,7 +84,7 @@ func newSRTServer(
address string, address string,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
writeTimeout conf.StringDuration, writeTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
udpMaxPayloadSize int, udpMaxPayloadSize int,
externalCmdPool *externalcmd.Pool, externalCmdPool *externalcmd.Pool,
pathManager *pathManager, pathManager *pathManager,
@@ -104,7 +104,7 @@ func newSRTServer(
s := &srtServer{ s := &srtServer{
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout, writeTimeout: writeTimeout,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
udpMaxPayloadSize: udpMaxPayloadSize, udpMaxPayloadSize: udpMaxPayloadSize,
externalCmdPool: externalCmdPool, externalCmdPool: externalCmdPool,
pathManager: pathManager, pathManager: pathManager,
@@ -161,7 +161,7 @@ outer:
s.ctx, s.ctx,
s.readTimeout, s.readTimeout,
s.writeTimeout, s.writeTimeout,
s.readBufferCount, s.writeQueueSize,
s.udpMaxPayloadSize, s.udpMaxPayloadSize,
req.connReq, req.connReq,
&s.wg, &s.wg,

View File

@@ -276,13 +276,13 @@ type webRTCManagerParent interface {
} }
type webRTCManager struct { type webRTCManager struct {
allowOrigin string allowOrigin string
trustedProxies conf.IPsOrCIDRs trustedProxies conf.IPsOrCIDRs
iceServers []conf.WebRTCICEServer iceServers []conf.WebRTCICEServer
readBufferCount int writeQueueSize int
pathManager *pathManager pathManager *pathManager
metrics *metrics metrics *metrics
parent webRTCManagerParent parent webRTCManagerParent
ctx context.Context ctx context.Context
ctxCancel func() ctxCancel func()
@@ -314,7 +314,7 @@ func newWebRTCManager(
trustedProxies conf.IPsOrCIDRs, trustedProxies conf.IPsOrCIDRs,
iceServers []conf.WebRTCICEServer, iceServers []conf.WebRTCICEServer,
readTimeout conf.StringDuration, readTimeout conf.StringDuration,
readBufferCount int, writeQueueSize int,
iceHostNAT1To1IPs []string, iceHostNAT1To1IPs []string,
iceUDPMuxAddress string, iceUDPMuxAddress string,
iceTCPMuxAddress string, iceTCPMuxAddress string,
@@ -328,7 +328,7 @@ func newWebRTCManager(
allowOrigin: allowOrigin, allowOrigin: allowOrigin,
trustedProxies: trustedProxies, trustedProxies: trustedProxies,
iceServers: iceServers, iceServers: iceServers,
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
pathManager: pathManager, pathManager: pathManager,
metrics: metrics, metrics: metrics,
parent: parent, parent: parent,
@@ -436,7 +436,7 @@ outer:
case req := <-m.chNewSession: case req := <-m.chNewSession:
sx := newWebRTCSession( sx := newWebRTCSession(
m.ctx, m.ctx,
m.readBufferCount, m.writeQueueSize,
m.api, m.api,
req, req,
&wg, &wg,

View File

@@ -175,12 +175,12 @@ type webRTCSessionPathManager interface {
} }
type webRTCSession struct { type webRTCSession struct {
readBufferCount int writeQueueSize int
api *webrtc.API api *webrtc.API
req webRTCNewSessionReq req webRTCNewSessionReq
wg *sync.WaitGroup wg *sync.WaitGroup
pathManager webRTCSessionPathManager pathManager webRTCSessionPathManager
parent *webRTCManager parent *webRTCManager
ctx context.Context ctx context.Context
ctxCancel func() ctxCancel func()
@@ -196,7 +196,7 @@ type webRTCSession struct {
func newWebRTCSession( func newWebRTCSession(
parentCtx context.Context, parentCtx context.Context,
readBufferCount int, writeQueueSize int,
api *webrtc.API, api *webrtc.API,
req webRTCNewSessionReq, req webRTCNewSessionReq,
wg *sync.WaitGroup, wg *sync.WaitGroup,
@@ -206,7 +206,7 @@ func newWebRTCSession(
ctx, ctxCancel := context.WithCancel(parentCtx) ctx, ctxCancel := context.WithCancel(parentCtx)
s := &webRTCSession{ s := &webRTCSession{
readBufferCount: readBufferCount, writeQueueSize: writeQueueSize,
api: api, api: api,
req: req, req: req,
wg: wg, wg: wg,
@@ -509,7 +509,7 @@ func (s *webRTCSession) runRead() (int, error) {
s.pc = pc s.pc = pc
s.mutex.Unlock() s.mutex.Unlock()
ringBuffer, _ := ringbuffer.New(uint64(s.readBufferCount)) ringBuffer, _ := ringbuffer.New(uint64(s.writeQueueSize))
defer ringBuffer.Close() defer ringBuffer.Close()
writeError := make(chan error) writeError := make(chan error)

View File

@@ -13,9 +13,9 @@ logFile: mediamtx.log
readTimeout: 10s readTimeout: 10s
# Timeout of write operations. # Timeout of write operations.
writeTimeout: 10s writeTimeout: 10s
# Number of read buffers. # Size of the queue of outgoing packets.
# A higher value allows to increase throughput, a lower value allows to save RAM. # A higher value allows to increase throughput, a lower value allows to save RAM.
readBufferCount: 512 writeQueueSize: 512
# Maximum size of outgoing UDP packets. # Maximum size of outgoing UDP packets.
# This can be decreased to avoid fragmentation on networks with a low UDP MTU. # This can be decreased to avoid fragmentation on networks with a low UDP MTU.
udpMaxPayloadSize: 1472 udpMaxPayloadSize: 1472