mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-09 10:45:27 +00:00
fallbackswitch: factor out handle_main_timed_item()
No semantic change, I'll re-use this to handle GAP events.
This commit is contained in:
parent
e097feea1f
commit
4e7141f0e3
1 changed files with 88 additions and 19 deletions
|
@ -212,23 +212,23 @@ impl FallbackSwitch {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn handle_main_buffer(
|
fn handle_main_timed_item(
|
||||||
&self,
|
&self,
|
||||||
agg: &super::FallbackSwitch,
|
agg: &super::FallbackSwitch,
|
||||||
state: &mut OutputState,
|
state: &mut OutputState,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
mut buffer: gst::Buffer,
|
mut item: TimedItem,
|
||||||
preferred_pad: &gst_base::AggregatorPad,
|
preferred_pad: &gst_base::AggregatorPad,
|
||||||
backup_pad: &Option<&gst_base::AggregatorPad>,
|
backup_pad: &Option<&gst_base::AggregatorPad>,
|
||||||
cur_running_time: impl Into<Option<gst::ClockTime>>,
|
cur_running_time: impl Into<Option<gst::ClockTime>>,
|
||||||
) -> Result<Option<(gst::Buffer, gst::Caps, bool)>, gst::FlowError> {
|
) -> Result<Option<(TimedItem, gst::Caps, bool)>, gst::FlowError> {
|
||||||
// If we got a buffer on the sinkpad just handle it
|
|
||||||
gst_debug!(
|
gst_debug!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: preferred_pad,
|
obj: preferred_pad,
|
||||||
"Got buffer on pad {} - {:?}",
|
"Got {} on pad {} - {:?}",
|
||||||
|
item.name(),
|
||||||
preferred_pad.name(),
|
preferred_pad.name(),
|
||||||
buffer
|
item
|
||||||
);
|
);
|
||||||
|
|
||||||
let segment = preferred_pad
|
let segment = preferred_pad
|
||||||
|
@ -239,7 +239,7 @@ impl FallbackSwitch {
|
||||||
gst::FlowError::Error
|
gst::FlowError::Error
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let running_time = if buffer.pts().is_none() {
|
let running_time = if item.pts().is_none() {
|
||||||
// re-use ts from previous buffer
|
// re-use ts from previous buffer
|
||||||
let running_time = state
|
let running_time = state
|
||||||
.primary
|
.primary
|
||||||
|
@ -249,21 +249,17 @@ impl FallbackSwitch {
|
||||||
gst_debug!(
|
gst_debug!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: preferred_pad,
|
obj: preferred_pad,
|
||||||
"Buffer does not have PTS, re-use ts from previous buffer: {}",
|
"{} does not have PTS, re-use ts from previous buffer: {}",
|
||||||
|
item.name(),
|
||||||
running_time.display()
|
running_time.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
running_time
|
running_time
|
||||||
} else {
|
} else {
|
||||||
segment.to_running_time(buffer.pts())
|
segment.to_running_time(item.pts())
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
item.update_ts(running_time, &segment);
|
||||||
// FIXME: This will not work correctly for negative DTS
|
|
||||||
let buffer = buffer.make_mut();
|
|
||||||
buffer.set_pts(running_time);
|
|
||||||
buffer.set_dts(segment.to_running_time(buffer.dts()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if preferred_pad == &self.primary_sinkpad {
|
if preferred_pad == &self.primary_sinkpad {
|
||||||
state.primary.last_sinkpad_time = running_time;
|
state.primary.last_sinkpad_time = running_time;
|
||||||
|
@ -284,7 +280,8 @@ impl FallbackSwitch {
|
||||||
gst_debug!(
|
gst_debug!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: preferred_pad,
|
obj: preferred_pad,
|
||||||
"Buffer is too late: {} > {}",
|
"{} is too late: {} > {}",
|
||||||
|
item.name(),
|
||||||
cur_running_time.display(),
|
cur_running_time.display(),
|
||||||
deadline.display(),
|
deadline.display(),
|
||||||
);
|
);
|
||||||
|
@ -300,7 +297,8 @@ impl FallbackSwitch {
|
||||||
gst_debug!(
|
gst_debug!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: preferred_pad,
|
obj: preferred_pad,
|
||||||
"Buffer is too late and timeout reached: {} + {} <= {}",
|
"{} is too late and timeout reached: {} + {} <= {}",
|
||||||
|
item.name(),
|
||||||
state.last_output_time.display(),
|
state.last_output_time.display(),
|
||||||
settings.timeout,
|
settings.timeout,
|
||||||
running_time.display(),
|
running_time.display(),
|
||||||
|
@ -315,7 +313,7 @@ impl FallbackSwitch {
|
||||||
&& active_sinkpad.as_ref() != Some(preferred_pad.upcast_ref::<gst::Pad>());
|
&& active_sinkpad.as_ref() != Some(preferred_pad.upcast_ref::<gst::Pad>());
|
||||||
|
|
||||||
if pad_change {
|
if pad_change {
|
||||||
if buffer.flags().contains(gst::BufferFlags::DELTA_UNIT) {
|
if !item.is_keyframe() {
|
||||||
gst_info!(
|
gst_info!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: preferred_pad,
|
obj: preferred_pad,
|
||||||
|
@ -352,7 +350,32 @@ impl FallbackSwitch {
|
||||||
self.drain_pad_to_time(state, backup_pad, state.last_output_time)?;
|
self.drain_pad_to_time(state, backup_pad, state.last_output_time)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some((buffer, active_caps, pad_change)))
|
Ok(Some((item, active_caps, pad_change)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn handle_main_buffer(
|
||||||
|
&self,
|
||||||
|
agg: &super::FallbackSwitch,
|
||||||
|
state: &mut OutputState,
|
||||||
|
settings: &Settings,
|
||||||
|
buffer: gst::Buffer,
|
||||||
|
preferred_pad: &gst_base::AggregatorPad,
|
||||||
|
backup_pad: &Option<&gst_base::AggregatorPad>,
|
||||||
|
cur_running_time: impl Into<Option<gst::ClockTime>>,
|
||||||
|
) -> Result<Option<(gst::Buffer, gst::Caps, bool)>, gst::FlowError> {
|
||||||
|
// If we got a buffer on the sinkpad just handle it
|
||||||
|
let res = self.handle_main_timed_item(
|
||||||
|
agg,
|
||||||
|
state,
|
||||||
|
settings,
|
||||||
|
TimedItem::Buffer(buffer),
|
||||||
|
preferred_pad,
|
||||||
|
backup_pad,
|
||||||
|
cur_running_time,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(res.map(|res| (res.0.buffer(), res.1, res.2)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup_buffer(
|
fn backup_buffer(
|
||||||
|
@ -1262,3 +1285,49 @@ impl AggregatorImpl for FallbackSwitch {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum TimedItem {
|
||||||
|
Buffer(gst::Buffer),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TimedItem {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
TimedItem::Buffer(_) => "buffer",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pts(&self) -> Option<gst::ClockTime> {
|
||||||
|
match self {
|
||||||
|
TimedItem::Buffer(buffer) => buffer.pts(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_ts(
|
||||||
|
&mut self,
|
||||||
|
running_time: Option<gst::ClockTime>,
|
||||||
|
segment: &gst::FormattedSegment<gst::ClockTime>,
|
||||||
|
) {
|
||||||
|
match self {
|
||||||
|
TimedItem::Buffer(buffer) => {
|
||||||
|
// FIXME: This will not work correctly for negative DTS
|
||||||
|
let buffer = buffer.make_mut();
|
||||||
|
buffer.set_pts(running_time);
|
||||||
|
buffer.set_dts(segment.to_running_time(buffer.dts()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_keyframe(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
TimedItem::Buffer(buffer) => !buffer.flags().contains(gst::BufferFlags::DELTA_UNIT),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffer(self) -> gst::Buffer {
|
||||||
|
match self {
|
||||||
|
TimedItem::Buffer(buffer) => buffer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue