mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 06:50:59 +00:00
mpegtslivesrc: Rename variables to make it clear which time domain they refer to
We have the internal time domain (monotonic clock) and the external time domain (scaled monotonic clock in the rate of the PCR). Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1933>
This commit is contained in:
parent
25bb2a12f1
commit
d32d499856
1 changed files with 43 additions and 38 deletions
|
@ -167,9 +167,9 @@ struct State {
|
||||||
// Last observed PCR (for handling wraparound)
|
// Last observed PCR (for handling wraparound)
|
||||||
last_seen_pcr: Option<MpegTsPcr>,
|
last_seen_pcr: Option<MpegTsPcr>,
|
||||||
|
|
||||||
// First observed PCR and associated timestamp
|
// First observed PCR since discont and associated external clock time
|
||||||
base_pcr: Option<MpegTsPcr>,
|
base_pcr: Option<MpegTsPcr>,
|
||||||
base_monotonic: Option<gst::ClockTime>,
|
base_external: Option<gst::ClockTime>,
|
||||||
|
|
||||||
// If the next outgoing packet should have the discont flag set
|
// If the next outgoing packet should have the discont flag set
|
||||||
discont_pending: bool,
|
discont_pending: bool,
|
||||||
|
@ -377,50 +377,55 @@ impl FromBitStream for ProgramMappingTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
/// Store PCR / monotonic time observation
|
/// Store PCR / internal (monotonic) clock time observation
|
||||||
fn store_observation(
|
fn store_observation(
|
||||||
&mut self,
|
&mut self,
|
||||||
imp: &MpegTsLiveSource,
|
imp: &MpegTsLiveSource,
|
||||||
pcr: u64,
|
pcr: u64,
|
||||||
monotonic_time: gst::ClockTime,
|
observation_internal: gst::ClockTime,
|
||||||
) {
|
) {
|
||||||
// If this is the first PCR we observe:
|
// If this is the first PCR we observe:
|
||||||
// * Remember the PCR *and* the associated monotonic clock value when capture
|
// * Remember the PCR *and* the associated internal (monotonic) == external (scaled
|
||||||
// * `base_pcr` `base_monotonic`
|
// monotonic) clock value when capture
|
||||||
|
// * Store base_pcr = pcr, base_external = observation_internal
|
||||||
|
|
||||||
// If we have a PCR we need to store an observation
|
// If we have a PCR we need to store an observation
|
||||||
// * Subtract the base PCR from that value and add the base monotonic value
|
// * Subtract the base PCR from that value and add the base external clock value
|
||||||
// * observation_monotonic = pcr - base_pcr + base_monotonic
|
// * observation_external = pcr - base_pcr + base_external
|
||||||
// * Store (observation_monotonic, buffer_pts)
|
// * Store (observation_internal, observation_external)
|
||||||
|
|
||||||
let new_pcr: MpegTsPcr;
|
let new_pcr: MpegTsPcr;
|
||||||
|
|
||||||
if let (Some(base_pcr), Some(base_monotonic), Some(last_seen_pcr)) =
|
if let (Some(base_pcr), Some(base_external), Some(last_seen_pcr)) =
|
||||||
(self.base_pcr, self.base_monotonic, self.last_seen_pcr)
|
(self.base_pcr, self.base_external, self.last_seen_pcr)
|
||||||
{
|
{
|
||||||
gst::trace!(CAT, imp = imp, "pcr:{pcr}, monotonic_time:{monotonic_time}");
|
gst::trace!(
|
||||||
|
CAT,
|
||||||
|
imp = imp,
|
||||||
|
"pcr:{pcr}, observation_internal:{observation_internal}"
|
||||||
|
);
|
||||||
|
|
||||||
let mut handled_pcr = MpegTsPcr::new_with_reference(imp, pcr, &last_seen_pcr);
|
let mut handled_pcr = MpegTsPcr::new_with_reference(imp, pcr, &last_seen_pcr);
|
||||||
if let Some(new_pcr) = handled_pcr {
|
if let Some(new_pcr) = handled_pcr {
|
||||||
// First check if this is more than 1s off from the current clock calibration and
|
// First check if this is more than 1s off from the current clock calibration and
|
||||||
// if so consider it a discontinuity too.
|
// if so consider it a discontinuity too.
|
||||||
let (internal, external, num, denom) = imp.external_clock.calibration();
|
let (cinternal, cexternal, cnum, cdenom) = imp.external_clock.calibration();
|
||||||
|
|
||||||
let expected_external = gst::Clock::adjust_with_calibration(
|
let expected_external = gst::Clock::adjust_with_calibration(
|
||||||
monotonic_time,
|
observation_internal,
|
||||||
internal,
|
cinternal,
|
||||||
external,
|
cexternal,
|
||||||
num,
|
cnum,
|
||||||
denom,
|
cdenom,
|
||||||
);
|
);
|
||||||
let new_external =
|
let observation_external =
|
||||||
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_monotonic;
|
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_external;
|
||||||
if expected_external.absdiff(new_external) >= gst::ClockTime::SECOND {
|
if expected_external.absdiff(observation_external) >= gst::ClockTime::SECOND {
|
||||||
gst::warning!(
|
gst::warning!(
|
||||||
CAT,
|
CAT,
|
||||||
imp = imp,
|
imp = imp,
|
||||||
"New PCR clock estimation {new_external} too far from old estimation {expected_external}: {}",
|
"New PCR clock estimation {observation_external} too far from old estimation {expected_external}: {}",
|
||||||
new_external.into_positive() - expected_external,
|
observation_external.into_positive() - expected_external,
|
||||||
);
|
);
|
||||||
handled_pcr = None;
|
handled_pcr = None;
|
||||||
}
|
}
|
||||||
|
@ -432,41 +437,41 @@ impl State {
|
||||||
CAT,
|
CAT,
|
||||||
imp = imp,
|
imp = imp,
|
||||||
"Adding new observation internal: {} -> external: {}",
|
"Adding new observation internal: {} -> external: {}",
|
||||||
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_monotonic,
|
observation_internal,
|
||||||
monotonic_time,
|
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_external,
|
||||||
);
|
);
|
||||||
imp.external_clock.add_observation(
|
imp.external_clock.add_observation(
|
||||||
monotonic_time,
|
observation_internal,
|
||||||
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_monotonic,
|
gst::ClockTime::from(new_pcr.saturating_sub(base_pcr)) + base_external,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let (internal, external, num, denom) = imp.external_clock.calibration();
|
let (cinternal, cexternal, cnum, cdenom) = imp.external_clock.calibration();
|
||||||
let scaled_monotonic = gst::Clock::adjust_with_calibration(
|
let base_external = gst::Clock::adjust_with_calibration(
|
||||||
monotonic_time,
|
observation_internal,
|
||||||
internal,
|
cinternal,
|
||||||
external,
|
cexternal,
|
||||||
num,
|
cnum,
|
||||||
denom,
|
cdenom,
|
||||||
);
|
);
|
||||||
gst::warning!(
|
gst::warning!(
|
||||||
CAT,
|
CAT,
|
||||||
imp = imp,
|
imp = imp,
|
||||||
"DISCONT detected, Picking new reference times (pcr:{pcr:#?}, monotonic:{monotonic_time}, scaled monotonic:{scaled_monotonic}",
|
"DISCONT detected, Picking new reference times (pcr:{pcr:#?}, observation_internal:{observation_internal}, base_external:{base_external}",
|
||||||
);
|
);
|
||||||
new_pcr = MpegTsPcr::new(pcr);
|
new_pcr = MpegTsPcr::new(pcr);
|
||||||
self.base_pcr = Some(new_pcr);
|
self.base_pcr = Some(new_pcr);
|
||||||
self.base_monotonic = Some(monotonic_time);
|
self.base_external = Some(observation_internal);
|
||||||
self.discont_pending = true;
|
self.discont_pending = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gst::debug!(
|
gst::debug!(
|
||||||
CAT,
|
CAT,
|
||||||
imp = imp,
|
imp = imp,
|
||||||
"Picking initial reference times (pcr:{pcr:#?}, monotonic:{monotonic_time}"
|
"Picking initial reference times (pcr:{pcr:#?}, observation_internal:{observation_internal}"
|
||||||
);
|
);
|
||||||
new_pcr = MpegTsPcr::new(pcr);
|
new_pcr = MpegTsPcr::new(pcr);
|
||||||
self.base_pcr = Some(new_pcr);
|
self.base_pcr = Some(new_pcr);
|
||||||
self.base_monotonic = Some(monotonic_time);
|
self.base_external = Some(observation_internal);
|
||||||
self.discont_pending = true;
|
self.discont_pending = true;
|
||||||
}
|
}
|
||||||
self.last_seen_pcr = Some(new_pcr);
|
self.last_seen_pcr = Some(new_pcr);
|
||||||
|
|
Loading…
Reference in a new issue