Skip to content

Commit

Permalink
update pts
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 committed Oct 23, 2023
1 parent b6e86a4 commit 8c84866
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/pipeline/builder/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func BuildSegmentBin(pipeline *gstreamer.Pipeline, p *config.PipelineConfig) (*g
_, err = sink.Connect("format-location-full", func(self *gst.Element, fragmentId uint, firstSample *gst.Sample) string {
var pts time.Duration
if firstSample != nil && firstSample.GetBuffer() != nil {
pts = firstSample.GetBuffer().PresentationTimestamp()
pts = *firstSample.GetBuffer().PresentationTimestamp().AsDuration()
} else {
logger.Infow("nil sample passed into 'format-location-full' event handler, assuming 0 pts")
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/pipeline/builder/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,11 @@ func (b *VideoBin) createSrcPad(trackID string) {
for b.nextPTS.Load() != 0 {
time.Sleep(time.Millisecond * 100)
}
if buffer.PresentationTimestamp() < b.lastPTS.Load() {
pts := *buffer.PresentationTimestamp().AsDuration()
if pts < b.lastPTS.Load() {
return gst.PadProbeDrop
}
b.lastPTS.Store(buffer.PresentationTimestamp())
b.lastPTS.Store(pts)
return gst.PadProbeOK
})
b.pads[trackID] = pad
Expand All @@ -703,10 +704,11 @@ func (b *VideoBin) createTestSrcPad() {
pad := b.selector.GetRequestPad("sink_%u")
pad.AddProbe(gst.PadProbeTypeBuffer, func(pad *gst.Pad, info *gst.PadProbeInfo) gst.PadProbeReturn {
buffer := info.GetBuffer()
if buffer.PresentationTimestamp() < b.lastPTS.Load() {
pts := *buffer.PresentationTimestamp().AsDuration()
if pts < b.lastPTS.Load() {
return gst.PadProbeDrop
}
if nextPTS := b.nextPTS.Load(); nextPTS != 0 && buffer.PresentationTimestamp() >= nextPTS {
if nextPTS := b.nextPTS.Load(); nextPTS != 0 && pts >= nextPTS {
if err := b.setSelectorPad(b.nextPad); err != nil {
logger.Errorw("failed to unmute", err)
return gst.PadProbeDrop
Expand All @@ -715,7 +717,7 @@ func (b *VideoBin) createTestSrcPad() {
b.nextPTS.Store(0)
}
if b.selectedPad == videoTestSrcName {
b.lastPTS.Store(buffer.PresentationTimestamp())
b.lastPTS.Store(pts)
}
return gst.PadProbeOK
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/source/sdk/appwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (w *AppWriter) pushPacket(pkt *rtp.Packet, pts time.Duration) error {
}

b := gst.NewBufferFromBytes(p)
b.SetPresentationTimestamp(pts)
b.SetPresentationTimestamp(gst.ClockTime(uint64(pts)))
if flow := w.src.PushBuffer(b); flow != gst.FlowOK {
w.logger.Infow("unexpected flow return", "flow", flow)
}
Expand Down

0 comments on commit 8c84866

Please sign in to comment.