golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.1 KiB
57 lines
1.1 KiB
package record |
|
|
|
import ( |
|
"github.com/bluenviron/mediacommon/pkg/formats/fmp4" |
|
) |
|
|
|
type track struct { |
|
r *Agent |
|
initTrack *fmp4.InitTrack |
|
|
|
nextSample *sample |
|
} |
|
|
|
func newTrack( |
|
r *Agent, |
|
initTrack *fmp4.InitTrack, |
|
) *track { |
|
return &track{ |
|
r: r, |
|
initTrack: initTrack, |
|
} |
|
} |
|
|
|
func (t *track) record(sample *sample) error { |
|
// wait the first video sample before setting hasVideo |
|
if t.initTrack.Codec.IsVideo() { |
|
t.r.hasVideo = true |
|
} |
|
|
|
if t.r.currentSegment == nil { |
|
t.r.currentSegment = newSegment(t.r, sample.dts) |
|
} |
|
|
|
sample, t.nextSample = t.nextSample, sample |
|
if sample == nil { |
|
return nil |
|
} |
|
sample.Duration = uint32(durationGoToMp4(t.nextSample.dts-sample.dts, t.initTrack.TimeScale)) |
|
|
|
err := t.r.currentSegment.record(t, sample) |
|
if err != nil { |
|
return err |
|
} |
|
|
|
if (!t.r.hasVideo || t.initTrack.Codec.IsVideo()) && |
|
!t.nextSample.IsNonSyncSample && |
|
(t.nextSample.dts-t.r.currentSegment.startDTS) >= t.r.segmentDuration { |
|
err := t.r.currentSegment.close() |
|
if err != nil { |
|
return err |
|
} |
|
|
|
t.r.currentSegment = newSegment(t.r, t.nextSample.dts) |
|
} |
|
|
|
return nil |
|
}
|
|
|