|
|
|
@ -26,6 +26,9 @@ import ( |
|
|
|
"github.com/bluenviron/mediamtx/internal/unit" |
|
|
|
"github.com/bluenviron/mediamtx/internal/unit" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OnSegmentFunc is the prototype of the function passed as runOnSegmentStart / runOnSegmentComplete
|
|
|
|
|
|
|
|
type OnSegmentFunc = func(string) |
|
|
|
|
|
|
|
|
|
|
|
func durationGoToMp4(v time.Duration, timeScale uint32) uint64 { |
|
|
|
func durationGoToMp4(v time.Duration, timeScale uint32) uint64 { |
|
|
|
timeScale64 := uint64(timeScale) |
|
|
|
timeScale64 := uint64(timeScale) |
|
|
|
secs := v / time.Second |
|
|
|
secs := v / time.Second |
|
|
|
@ -111,7 +114,8 @@ type Agent struct { |
|
|
|
partDuration time.Duration |
|
|
|
partDuration time.Duration |
|
|
|
segmentDuration time.Duration |
|
|
|
segmentDuration time.Duration |
|
|
|
stream *stream.Stream |
|
|
|
stream *stream.Stream |
|
|
|
onSegmentComplete func(string) |
|
|
|
onSegmentCreate OnSegmentFunc |
|
|
|
|
|
|
|
onSegmentComplete OnSegmentFunc |
|
|
|
parent logger.Writer |
|
|
|
parent logger.Writer |
|
|
|
|
|
|
|
|
|
|
|
ctx context.Context |
|
|
|
ctx context.Context |
|
|
|
@ -125,7 +129,7 @@ type Agent struct { |
|
|
|
done chan struct{} |
|
|
|
done chan struct{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewAgent allocates a nAgent.
|
|
|
|
// NewAgent allocates an Agent.
|
|
|
|
func NewAgent( |
|
|
|
func NewAgent( |
|
|
|
writeQueueSize int, |
|
|
|
writeQueueSize int, |
|
|
|
recordPath string, |
|
|
|
recordPath string, |
|
|
|
@ -133,16 +137,13 @@ func NewAgent( |
|
|
|
segmentDuration time.Duration, |
|
|
|
segmentDuration time.Duration, |
|
|
|
pathName string, |
|
|
|
pathName string, |
|
|
|
stream *stream.Stream, |
|
|
|
stream *stream.Stream, |
|
|
|
onSegmentComplete func(string), |
|
|
|
onSegmentCreate OnSegmentFunc, |
|
|
|
|
|
|
|
onSegmentComplete OnSegmentFunc, |
|
|
|
parent logger.Writer, |
|
|
|
parent logger.Writer, |
|
|
|
) *Agent { |
|
|
|
) *Agent { |
|
|
|
recordPath = strings.ReplaceAll(recordPath, "%path", pathName) |
|
|
|
recordPath = strings.ReplaceAll(recordPath, "%path", pathName) |
|
|
|
recordPath += ".mp4" |
|
|
|
recordPath += ".mp4" |
|
|
|
|
|
|
|
|
|
|
|
if onSegmentComplete == nil { |
|
|
|
|
|
|
|
onSegmentComplete = func(_ string) {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx, ctxCancel := context.WithCancel(context.Background()) |
|
|
|
ctx, ctxCancel := context.WithCancel(context.Background()) |
|
|
|
|
|
|
|
|
|
|
|
r := &Agent{ |
|
|
|
r := &Agent{ |
|
|
|
@ -150,6 +151,7 @@ func NewAgent( |
|
|
|
partDuration: partDuration, |
|
|
|
partDuration: partDuration, |
|
|
|
segmentDuration: segmentDuration, |
|
|
|
segmentDuration: segmentDuration, |
|
|
|
stream: stream, |
|
|
|
stream: stream, |
|
|
|
|
|
|
|
onSegmentCreate: onSegmentCreate, |
|
|
|
onSegmentComplete: onSegmentComplete, |
|
|
|
onSegmentComplete: onSegmentComplete, |
|
|
|
parent: parent, |
|
|
|
parent: parent, |
|
|
|
ctx: ctx, |
|
|
|
ctx: ctx, |
|
|
|
|