+ if( !id->b_ts_init )
+ {
+ sout_stream_sys_t *p_sys = id->p_stream->p_sys;
+ vlc_mutex_lock( &p_sys->lock_ts );
+ if( p_sys->i_npt_zero == VLC_TS_INVALID )
+ {
+ /* This is the first packet of any ES. We initialize the
+ * NPT=0 time reference, and the offset to match the
+ * arbitrary PTS reference. */
+ p_sys->i_npt_zero = i_pts + id->i_caching;
+ p_sys->i_pts_offset = p_sys->i_pts_zero - i_pts;
+ }
+ vlc_mutex_unlock( &p_sys->lock_ts );
+
+ /* And in any case this is the first packet of this ES, so we
+ * initialize the offset for this ES. */
+ id->i_ts_offset = rtp_compute_ts( id, p_sys->i_pts_offset );
+ id->b_ts_init = true;
+ }
+
+ uint32_t i_timestamp = rtp_compute_ts( id, i_pts ) + id->i_ts_offset;