livesync: invalid output running time when changing segment
I'm running an audio live pipeline using the sytem clock with 0
as base time.
It's basically appsrc ! livesync ! audiobuffersplit gapless=true
, my goal here is to have silence
generated if no buffers are pushed to appsrc
.
I start by pushing a single 0 buffer to appsrc
with pts=0
so livesync
starts producing buffer.
appsrc
generates a default segment with base=0
and livesync
repeats it until we receive actual audio.
Then the first buffer audio arrives, it has pts=0
but uses a segment with base=$now
, as buffers are synced on the
system clock. livesync
changes this buffer pts
as we can see in these logs:
0:00:37.169403386 377789 0x55dc81171d20 TRACE livesync imp.rs:806:gstlivesync::livesync::imp::LiveSync::sink_chain:<10-0-encoder-audio-audio-livesync> Incoming Buffer { ptr: 0x7f724c14aea0, pts: 0:00:00.394016156, dts: --:--:--.---------, duration: 0:00:00.023229167, size: 8920, offset: 18446744073709551615, offset_end: 18446744073709551615, flags: BufferFlags(0x0), metas: [] }
0:00:37.169428583 377789 0x55dc81171d20 DEBUG livesync imp.rs:1251:gstlivesync::livesync::imp::LiveSync::buffer_is_backwards:<10-0-encoder-audio-audio-livesync> Timestamp regresses: buffer ends at 16:25:44.387453270, expected 16:26:16.635827761
0:00:37.169447108 377789 0x55dc81171d20 DEBUG livesync imp.rs:935:gstlivesync::livesync::imp::LiveSync::sink_chain:<10-0-encoder-audio-audio-livesync> Accepting late Buffer { ptr: 0x7f7208005240, pts: 0:00:00.394016156, dts: --:--:--.---------, duration: 0:00:00.023229167, size: 8920, offset: 18446744073709551615, offset_end: 18446744073709551615, flags: BufferFlags(DISCONT), metas: [] }
0:00:37.169485601 377789 0x55dc81171d20 TRACE livesync imp.rs:961:gstlivesync::livesync::imp::LiveSync::sink_chain:<10-0-encoder-audio-audio-livesync> Queueing Buffer { ptr: 0x7f7208005240, pts: 16:26:15.635827761, dts: --:--:--.---------, duration: 0:00:00.023229167, size: 8920, offset: 18446744073709551615, offset_end: 18446744073709551615, flags: BufferFlags(DISCONT | GAP | TAG_MEMORY), metas: [] } (LateOve>
Problem is, this buffer is pushed after pushing the new segment having a new base
:
0:00:37.176040705 377789 0x7f724401cf60 TRACE livesync imp.rs:1068:gstlivesync::livesync::imp::LiveSync::src_loop_inner:<10-0-encoder-audio-audio-livesync> Unqueueing Some(Buffer(Buffer { ptr: 0x7f7208005240, pts: 16:26:15.635827761, dts: --:--:--.---------, duration: 0:00:00.023229167, size: 8920, offset: 18446744073709551615, offset_end: 18446744073709551615, flags: BufferFlags(DISCONT | GAP | TAG_MEMORY), m>
0:00:37.176071102 377789 0x7f724401cf60 DEBUG livesync imp.rs:1202:gstlivesync::livesync::imp::LiveSync::src_loop_inner:<10-0-encoder-audio-audio-livesync> Forwarding segment: Segment { format: Time, start: 0:00:00.047891156, offset: 0:00:00.000000000, stop: 0:08:21.972891156, rate: 1.0, applied_rate: 1.0, flags: SegmentFlags(0x0), time: 0:00:00.000000000, base: 16:25:43.018099103, position: 0:00:00.047891156,>
0:00:37.176094867 377789 0x7f724401cf60 DEBUG audiobuffersplit gstaudiobuffersplit.c:830:gst_audio_buffer_split_sink_event:<10-0-encoder-audio-audiobuffersplit> Received new input segment time segment start=0:00:00.047891156, offset=0:00:00.000000000, stop=0:08:21.972891156, rate=1.000000, applied_rate=1.000000, flags=0x00, time=0:00:00.000000000, base=16:25:43.018099103, position 0:00:00.047891156, duration 99:99:99.>
0:00:37.176110687 377789 0x7f724401cf60 TRACE livesync imp.rs:1232:gstlivesync::livesync::imp::LiveSync::src_loop_inner:<10-0-encoder-audio-audio-livesync> Pushing Buffer { ptr: 0x7f7208005240, pts: 16:26:15.635827761, dts: --:--:--.---------, duration: 0:00:00.023229167, size: 8920, offset: 18446744073709551615, offset_end: 18446744073709551615, flags: BufferFlags(DISCONT | GAP | TAG_MEMORY), metas: [] }
As a result audiobuffersplit
receives a buffer with base~=now
and pts~=now
(while it should be pts=0
) resulting in an invalid running-time:
0:00:37.176119775 377789 0x7f724401cf60 LOG audiobuffersplit gstaudiobuffersplit.c:718:gst_audio_buffer_split_sink_chain:<10-0-encoder-audio-audiobuffersplit> Processing buffer at running time 99:99:99.999999999 with timestamp 16:26:15.635827761 with duration 0:00:00.023229167 (1115 samples)
@heftig : any suggestion about how this should be handled to prevent this problem?