Fixes/simplifications for GStreamer API changes

This commit is contained in:
Sebastian Dröge 2017-12-09 19:41:54 +02:00
parent 63380e023a
commit c6800e8a26
5 changed files with 82 additions and 145 deletions

View file

@ -205,8 +205,7 @@ impl Demuxer {
);
pad.push_event(gst::Event::new_caps(&caps).build());
let mut segment = gst::Segment::default();
segment.init(gst::Format::Time);
let segment = gst::FormattedSegment::<gst::ClockTime>::default();
pad.push_event(gst::Event::new_segment(&segment).build());
self.flow_combiner.lock().unwrap().add_pad(&pad);
@ -351,9 +350,8 @@ impl Demuxer {
if active {
let upstream_size = demuxer
.sinkpad
.peer_query_duration(gst::Format::Bytes)
.and_then(|d| d.try_to_bytes())
.and_then(|d| d);
.peer_query_duration::<gst::format::Bytes>()
.and_then(|v| v.0);
if !demuxer.start(&element, upstream_size, mode == gst::PadMode::Pull) {
return false;

View file

@ -277,15 +277,16 @@ impl BaseSrcImpl<BaseSrc> for Source {
fn do_seek(&self, src: &BaseSrc, segment: &mut gst::Segment) -> bool {
let source_impl = &mut self.imp.lock().unwrap();
if segment.get_format() != gst::Format::Bytes {
return false;
}
let segment = match segment.downcast_ref::<gst::format::Bytes>() {
None => return false,
Some(segment) => segment,
};
let start = match segment.get_start().try_to_bytes().unwrap() {
let start = match segment.get_start().0 {
None => return false,
Some(start) => start,
};
let stop = segment.get_stop().try_to_bytes().unwrap();
let stop = segment.get_stop().0;
gst_debug!(self.cat, obj: src, "Seeking to {:?}-{:?}", start, stop);

View file

@ -225,25 +225,13 @@ fn create_ui(app: &gtk::Application) {
let video_sink = &video_sink_clone;
let togglerecord = &togglerecord_clone;
let position = if let Some(gst::FormatValue::Time(position)) =
video_sink.query_position(gst::Format::Time)
{
position
} else {
0.into()
};
let position = video_sink.query_position::<gst::ClockTime>().unwrap_or(0.into());
position_label.set_text(&format!("Position: {:.0}", position));
let recording_duration = if let Some(gst::FormatValue::Time(recording_duration)) =
togglerecord
let recording_duration = togglerecord
.get_static_pad("src")
.unwrap()
.query_position(gst::Format::Time)
{
recording_duration
} else {
0.into()
};
.query_position::<gst::ClockTime>().unwrap_or(0.into());
recorded_duration_label.set_text(&format!("Recorded: {:.0}", recording_duration));
glib::Continue(true)

View file

@ -88,8 +88,8 @@ impl Stream {
}
struct StreamState {
in_segment: gst::Segment,
out_segment: gst::Segment,
in_segment: gst::FormattedSegment<gst::ClockTime>,
out_segment: gst::FormattedSegment<gst::ClockTime>,
segment_seqnum: gst::Seqnum,
current_running_time: gst::ClockTime,
eos: bool,
@ -101,8 +101,8 @@ struct StreamState {
impl Default for StreamState {
fn default() -> Self {
Self {
in_segment: gst::Segment::new(),
out_segment: gst::Segment::new(),
in_segment: gst::FormattedSegment::new(),
out_segment: gst::FormattedSegment::new(),
segment_seqnum: gst::util_seqnum_next(),
current_running_time: gst::CLOCK_TIME_NONE,
eos: false,
@ -343,30 +343,14 @@ impl ToggleRecord {
dts_or_pts
};
dts_or_pts = cmp::max(
state.in_segment.get_start().try_to_time().unwrap(),
dts_or_pts,
);
dts_or_pts_end = cmp::max(
state.in_segment.get_start().try_to_time().unwrap(),
dts_or_pts_end,
);
if state.in_segment.get_stop().try_to_time().unwrap().is_some() {
dts_or_pts = cmp::min(
state.in_segment.get_stop().try_to_time().unwrap(),
dts_or_pts,
);
dts_or_pts_end = cmp::min(
state.in_segment.get_stop().try_to_time().unwrap(),
dts_or_pts_end,
);
dts_or_pts = cmp::max(state.in_segment.get_start(), dts_or_pts);
dts_or_pts_end = cmp::max(state.in_segment.get_start(), dts_or_pts_end);
if state.in_segment.get_stop().is_some() {
dts_or_pts = cmp::min(state.in_segment.get_stop(), dts_or_pts);
dts_or_pts_end = cmp::min(state.in_segment.get_stop(), dts_or_pts_end);
}
let mut current_running_time = state
.in_segment
.to_running_time(dts_or_pts)
.try_to_time()
.unwrap();
let mut current_running_time = state.in_segment.to_running_time(dts_or_pts);
current_running_time = cmp::max(current_running_time, state.current_running_time);
state.current_running_time = current_running_time;
@ -376,11 +360,7 @@ impl ToggleRecord {
// get the wrong state
self.main_stream_cond.notify_all();
let current_running_time_end = state
.in_segment
.to_running_time(dts_or_pts_end)
.try_to_time()
.unwrap();
let current_running_time_end = state.in_segment.to_running_time(dts_or_pts_end);
gst_log!(
self.cat,
@ -552,40 +532,32 @@ impl ToggleRecord {
pts
};
pts = cmp::max(state.in_segment.get_start().try_to_time().unwrap(), pts);
if state.in_segment.get_stop().try_to_time().unwrap().is_some()
&& pts >= state.in_segment.get_stop().try_to_time().unwrap()
{
pts = cmp::max(state.in_segment.get_start(), pts);
if state.in_segment.get_stop().is_some() && pts >= state.in_segment.get_stop() {
state.current_running_time = state
.in_segment
.to_running_time(state.in_segment.get_stop())
.try_to_time()
.unwrap();
.to_running_time(state.in_segment.get_stop());
state.eos = true;
gst_debug!(
self.cat,
obj: pad,
"After segment end {} >= {}, EOS",
pts,
state.in_segment.get_stop().try_to_time().unwrap()
state.in_segment.get_stop()
);
return HandleResult::Eos;
}
pts_end = cmp::max(state.in_segment.get_start().try_to_time().unwrap(), pts_end);
if state.in_segment.get_stop().try_to_time().unwrap().is_some() {
pts_end = cmp::min(state.in_segment.get_stop().try_to_time().unwrap(), pts_end);
pts_end = cmp::max(state.in_segment.get_start(), pts_end);
if state.in_segment.get_stop().is_some() {
pts_end = cmp::min(state.in_segment.get_stop(), pts_end);
}
let mut current_running_time = state.in_segment.to_running_time(pts).try_to_time().unwrap();
let mut current_running_time = state.in_segment.to_running_time(pts);
current_running_time = cmp::max(current_running_time, state.current_running_time);
state.current_running_time = current_running_time;
let current_running_time_end = state
.in_segment
.to_running_time(pts_end)
.try_to_time()
.unwrap();
let current_running_time_end = state.in_segment.to_running_time(pts_end);
gst_log!(
self.cat,
obj: pad,
@ -762,18 +734,6 @@ impl ToggleRecord {
{
let state = stream.state.lock().unwrap();
if state.in_segment.get_format() != gst::Format::Time {
gst_element_error!(
element,
gst::StreamError::Format,
[
"Only Time segments supported, got {:?}",
state.in_segment.get_format()
]
);
return gst::FlowReturn::Error;
}
if state.eos {
return gst::FlowReturn::Eos;
}
@ -856,10 +816,8 @@ impl ToggleRecord {
// recording_duration
state.out_segment = state.in_segment.clone();
let offset: u64 = rec_state.running_time_offset.into();
let res = state
.out_segment
.offset_running_time(gst::Format::Time, -(offset as i64));
let offset = rec_state.running_time_offset.unwrap_or(0);
let res = state.out_segment.offset_running_time(-(offset as i64));
assert!(res);
events.push(
gst::Event::new_segment(&state.out_segment)
@ -881,11 +839,7 @@ impl ToggleRecord {
events.append(&mut state.pending_events);
let out_running_time = state
.out_segment
.to_running_time(buffer.get_pts())
.try_to_time()
.unwrap();
let out_running_time = state.out_segment.to_running_time(buffer.get_pts());
// Unlock before pushing
drop(state);
@ -950,18 +904,21 @@ impl ToggleRecord {
EventView::Segment(e) => {
let mut state = stream.state.lock().unwrap();
let segment = e.get_segment();
if segment.get_format() != gst::Format::Time {
gst_element_error!(
element,
gst::StreamError::Format,
[
"Only Time segments supported, got {:?}",
segment.get_format()
]
);
return false;
}
let segment = match e.get_segment().downcast::<gst::ClockTime>() {
Err(segment) => {
gst_element_error!(
element,
gst::StreamError::Format,
[
"Only Time segments supported, got {:?}",
segment.get_format()
]
);
return false;
}
Ok(segment) => segment,
};
if (segment.get_rate() - 1.0).abs() > f64::EPSILON {
gst_element_error!(
element,
@ -974,7 +931,7 @@ impl ToggleRecord {
return false;
}
state.in_segment = e.get_segment();
state.in_segment = segment;
state.segment_seqnum = event.get_seqnum();
state.segment_pending = true;
state.current_running_time = gst::CLOCK_TIME_NONE;
@ -1165,8 +1122,8 @@ impl ToggleRecord {
let format = q.get_format();
q.set(
false,
gst::FormatValue::new(format, -1),
gst::FormatValue::new(format, -1),
gst::GenericFormattedValue::new(format, -1),
gst::GenericFormattedValue::new(format, -1),
);
gst_log!(self.cat, obj: pad, "Returning {:?}", q.get_mut_query());

View file

@ -132,8 +132,7 @@ fn setup_sender_receiver(
while let Ok(send_data) = receiver_input.recv() {
if first {
assert!(sinkpad.send_event(gst::Event::new_stream_start("test").build()));
let mut segment = gst::Segment::new();
segment.init(gst::Format::Time);
let segment = gst::FormattedSegment::<gst::ClockTime>::new();
assert!(sinkpad.send_event(gst::Event::new_segment(&segment).build()));
let mut tags = gst::TagList::new();
@ -195,7 +194,7 @@ fn setup_sender_receiver(
fn recv_buffers(
receiver_output: &mpsc::Receiver<Either<gst::Buffer, gst::Event>>,
segment: &mut gst::Segment,
segment: &mut gst::FormattedSegment<gst::ClockTime>,
wait_buffers: usize,
) -> Vec<(gst::ClockTime, gst::ClockTime)> {
let mut res = Vec::new();
@ -204,10 +203,7 @@ fn recv_buffers(
match val {
Left(buffer) => {
res.push((
segment
.to_running_time(buffer.get_pts())
.try_to_time()
.unwrap(),
segment.to_running_time(buffer.get_pts()),
buffer.get_pts(),
));
n_buffers += 1;
@ -222,10 +218,7 @@ fn recv_buffers(
EventView::Gap(ref e) => {
let (ts, _) = e.get();
res.push((
segment.to_running_time(ts).try_to_time().unwrap(),
ts.into(),
));
res.push((segment.to_running_time(ts), ts.into()));
n_buffers += 1;
if wait_buffers > 0 && n_buffers == wait_buffers {
return res;
@ -235,7 +228,7 @@ fn recv_buffers(
return res;
}
EventView::Segment(ref e) => {
*segment = e.get_segment();
*segment = e.get_segment().downcast().unwrap();
}
_ => (),
}
@ -288,7 +281,7 @@ fn test_one_stream_open() {
sender_input.send(SendData::Buffers(10)).unwrap();
drop(sender_input);
let mut segment = gst::Segment::new();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers = recv_buffers(&receiver_output, &mut segment, 0);
assert_eq!(buffers.len(), 10);
for (index, &(running_time, pts)) in buffers.iter().enumerate() {
@ -323,7 +316,7 @@ fn test_one_stream_gaps_open() {
sender_input.send(SendData::Gaps(5)).unwrap();
drop(sender_input);
let mut segment = gst::Segment::new();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers = recv_buffers(&receiver_output, &mut segment, 0);
assert_eq!(buffers.len(), 10);
for (index, &(running_time, pts)) in buffers.iter().enumerate() {
@ -359,7 +352,7 @@ fn test_one_stream_close_open() {
sender_input.send(SendData::Buffers(10)).unwrap();
drop(sender_input);
let mut segment = gst::Segment::new();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers = recv_buffers(&receiver_output, &mut segment, 0);
assert_eq!(buffers.len(), 10);
for (index, &(running_time, pts)) in buffers.iter().enumerate() {
@ -396,7 +389,7 @@ fn test_one_stream_open_close() {
sender_input.send(SendData::Buffers(10)).unwrap();
drop(sender_input);
let mut segment = gst::Segment::new();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers = recv_buffers(&receiver_output, &mut segment, 0);
assert_eq!(buffers.len(), 10);
for (index, &(running_time, pts)) in buffers.iter().enumerate() {
@ -436,7 +429,7 @@ fn test_one_stream_open_close_open() {
sender_input.send(SendData::Buffers(10)).unwrap();
drop(sender_input);
let mut segment = gst::Segment::new();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers = recv_buffers(&receiver_output, &mut segment, 0);
assert_eq!(buffers.len(), 20);
for (index, &(running_time, pts)) in buffers.iter().enumerate() {
@ -485,7 +478,7 @@ fn test_two_stream_open() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -495,7 +488,7 @@ fn test_two_stream_open() {
assert_eq!(buffers_1.len(), 10);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -539,7 +532,7 @@ fn test_two_stream_open_shift() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -549,7 +542,7 @@ fn test_two_stream_open_shift() {
assert_eq!(buffers_1.len(), 10);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -594,7 +587,7 @@ fn test_two_stream_open_shift_main() {
receiver_input_done_2.recv().unwrap();
// PTS 5 maps to running time 0 now
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -604,7 +597,7 @@ fn test_two_stream_open_shift_main() {
assert_eq!(buffers_1.len(), 10);
// First and last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -664,7 +657,7 @@ fn test_two_stream_open_close() {
receiver_input_done_1.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -674,7 +667,7 @@ fn test_two_stream_open_close() {
assert_eq!(buffers_1.len(), 10);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -734,7 +727,7 @@ fn test_two_stream_close_open() {
receiver_input_done_1.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -744,7 +737,7 @@ fn test_two_stream_close_open() {
assert_eq!(buffers_1.len(), 10);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -817,7 +810,7 @@ fn test_two_stream_open_close_open() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let pts_off = if index >= 10 {
@ -833,7 +826,7 @@ fn test_two_stream_open_close_open() {
assert_eq!(buffers_1.len(), 20);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let pts_off = if index >= 10 {
@ -918,7 +911,7 @@ fn test_two_stream_open_close_open_gaps() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let pts_off = if index >= 10 {
@ -934,7 +927,7 @@ fn test_two_stream_open_close_open_gaps() {
assert_eq!(buffers_1.len(), 20);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let pts_off = if index >= 10 {
@ -1020,7 +1013,7 @@ fn test_two_stream_close_open_close_delta() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_2.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let index = index as u64;
@ -1030,7 +1023,7 @@ fn test_two_stream_close_open_close_delta() {
assert_eq!(buffers_1.len(), 10);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let index = index as u64;
@ -1117,7 +1110,7 @@ fn test_three_stream_open_close_open() {
receiver_input_done_2.recv().unwrap();
receiver_input_done_3.recv().unwrap();
let mut segment_1 = gst::Segment::new();
let mut segment_1 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_1 = recv_buffers(&receiver_output_1, &mut segment_1, 0);
for (index, &(running_time, pts)) in buffers_1.iter().enumerate() {
let pts_off = if index >= 10 {
@ -1133,7 +1126,7 @@ fn test_three_stream_open_close_open() {
assert_eq!(buffers_1.len(), 20);
// Last buffer should be dropped from second stream
let mut segment_2 = gst::Segment::new();
let mut segment_2 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_2 = recv_buffers(&receiver_output_2, &mut segment_2, 0);
for (index, &(running_time, pts)) in buffers_2.iter().enumerate() {
let pts_off = if index >= 10 {
@ -1148,7 +1141,7 @@ fn test_three_stream_open_close_open() {
}
assert_eq!(buffers_2.len(), 20);
let mut segment_3 = gst::Segment::new();
let mut segment_3 = gst::FormattedSegment::<gst::ClockTime>::new();
let buffers_3 = recv_buffers(&receiver_output_3, &mut segment_3, 0);
for (index, &(running_time, pts)) in buffers_3.iter().enumerate() {
let pts_off = if index >= 10 {