Patch 5/10 doesn't make much sense by itself. Looking ahead, it seems to be used to send segment-done events, but this seems like an unclear way to achieve that—clearer would be to explicitly store the last pts separately and just use that.
However, stepping back, the segment-done logic is concerning. GStreamer is annoyingly underdocumented here, and it's not clear to me that it's actually legal to send segment-done with a different timestamp than the previous segment event. Moreover, though, it's not actually clear to me why we need to?