Update to latest gstreamer-rs master API changes

This commit is contained in:
Sebastian Dröge 2017-11-11 13:02:55 +01:00
parent 768b68f94a
commit 323bf3ea08
3 changed files with 46 additions and 58 deletions

View file

@ -27,8 +27,8 @@ use byte_slice_cast::*;
use num_traits::float::Float; use num_traits::float::Float;
use num_traits::cast::{FromPrimitive, ToPrimitive}; use num_traits::cast::{FromPrimitive, ToPrimitive};
const DEFAULT_MAX_DELAY: u64 = 1 * gst::SECOND; const DEFAULT_MAX_DELAY: u64 = 1 * gst::SECOND_VAL;
const DEFAULT_DELAY: u64 = 500 * gst::MSECOND; const DEFAULT_DELAY: u64 = 500 * gst::MSECOND_VAL;
const DEFAULT_INTENSITY: f64 = 0.5; const DEFAULT_INTENSITY: f64 = 0.5;
const DEFAULT_FEEDBACK: f64 = 0.0; const DEFAULT_FEEDBACK: f64 = 0.0;
@ -165,7 +165,7 @@ impl AudioEcho {
settings: &Settings, settings: &Settings,
) { ) {
let delay_frames = (settings.delay as usize) * (state.info.channels() as usize) let delay_frames = (settings.delay as usize) * (state.info.channels() as usize)
* (state.info.rate() as usize) / (gst::SECOND as usize); * (state.info.rate() as usize) / (gst::SECOND_VAL as usize);
for (i, (o, e)) in data.iter_mut().zip(state.buffer.iter(delay_frames)) { for (i, (o, e)) in data.iter_mut().zip(state.buffer.iter(delay_frames)) {
let inp = (*i).to_f64().unwrap(); let inp = (*i).to_f64().unwrap();
@ -283,7 +283,7 @@ impl BaseTransformImpl<RsBaseTransform> for AudioEcho {
}; };
let max_delay = self.settings.lock().unwrap().max_delay; let max_delay = self.settings.lock().unwrap().max_delay;
let size = max_delay * (info.rate() as u64) / gst::SECOND; let size = max_delay * (info.rate() as u64) / gst::SECOND_VAL;
let buffer_size = size * (info.channels() as u64); let buffer_size = size * (info.channels() as u64);
*self.state.lock().unwrap() = Some(State { *self.state.lock().unwrap() = Some(State {

View file

@ -19,8 +19,6 @@ use gst_plugin::adapter::*;
use gst_plugin::bytes::*; use gst_plugin::bytes::*;
use gst_plugin_simple::demuxer::*; use gst_plugin_simple::demuxer::*;
use muldiv::*;
use gst; use gst;
use gst::prelude::*; use gst::prelude::*;
@ -48,7 +46,7 @@ struct StreamingState {
video: Option<VideoFormat>, video: Option<VideoFormat>,
expect_video: bool, expect_video: bool,
got_all_streams: bool, got_all_streams: bool,
last_position: Option<u64>, last_position: gst::ClockTime,
metadata: Option<Metadata>, metadata: Option<Metadata>,
@ -64,7 +62,7 @@ impl StreamingState {
video: None, video: None,
expect_video: video, expect_video: video,
got_all_streams: false, got_all_streams: false,
last_position: None, last_position: gst::CLOCK_TIME_NONE,
metadata: None, metadata: None,
aac_sequence_header: None, aac_sequence_header: None,
avc_sequence_header: None, avc_sequence_header: None,
@ -385,7 +383,7 @@ impl PartialEq for VideoFormat {
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
struct Metadata { struct Metadata {
duration: Option<u64>, duration: gst::ClockTime,
creation_date: Option<String>, creation_date: Option<String>,
creator: Option<String>, creator: Option<String>,
@ -407,7 +405,7 @@ impl Metadata {
assert_eq!(script_data.name, "onMetaData"); assert_eq!(script_data.name, "onMetaData");
let mut metadata = Metadata { let mut metadata = Metadata {
duration: None, duration: gst::CLOCK_TIME_NONE,
creation_date: None, creation_date: None,
creator: None, creator: None,
title: None, title: None,
@ -432,7 +430,7 @@ impl Metadata {
for arg in args { for arg in args {
match (arg.name, &arg.data) { match (arg.name, &arg.data) {
("duration", &flavors::ScriptDataValue::Number(duration)) => { ("duration", &flavors::ScriptDataValue::Number(duration)) => {
metadata.duration = Some((duration * 1000.0 * 1000.0 * 1000.0) as u64); metadata.duration = ((duration * 1000.0 * 1000.0 * 1000.0) as u64).into();
} }
("creationdate", &flavors::ScriptDataValue::String(date)) => { ("creationdate", &flavors::ScriptDataValue::String(date)) => {
metadata.creation_date = Some(String::from(date)); metadata.creation_date = Some(String::from(date));
@ -733,11 +731,7 @@ impl FlvDemux {
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
buffer.set_pts( buffer.set_pts(gst::ClockTime::from_mseconds(tag_header.timestamp as u64));
(tag_header.timestamp as u64)
.mul_div_floor(1000_000, 1)
.unwrap(),
);
} }
gst_trace!( gst_trace!(
@ -926,11 +920,7 @@ impl FlvDemux {
if !is_keyframe { if !is_keyframe {
buffer.set_flags(gst::BufferFlags::DELTA_UNIT); buffer.set_flags(gst::BufferFlags::DELTA_UNIT);
} }
buffer.set_dts( buffer.set_dts(gst::ClockTime::from_mseconds(tag_header.timestamp as u64));
(tag_header.timestamp as u64)
.mul_div_floor(1000_000, 1)
.unwrap(),
);
// Prevent negative numbers // Prevent negative numbers
let pts = if cts < 0 && tag_header.timestamp < (-cts) as u32 { let pts = if cts < 0 && tag_header.timestamp < (-cts) as u32 {
@ -938,7 +928,7 @@ impl FlvDemux {
} else { } else {
((tag_header.timestamp as i64) + (cts as i64)) as u64 ((tag_header.timestamp as i64) + (cts as i64)) as u64
}; };
buffer.set_pts(pts.mul_div_floor(1000_000, 1).unwrap()); buffer.set_pts(gst::ClockTime::from_mseconds(pts));
} }
gst_trace!( gst_trace!(
@ -1080,14 +1070,14 @@ impl FlvDemux {
let pts = buffer.get_pts(); let pts = buffer.get_pts();
streaming_state.last_position = streaming_state streaming_state.last_position = streaming_state
.last_position .last_position
.map(|last| cmp::max(last, pts)) .map(|last| cmp::max(last.into(), pts))
.or_else(|| Some(pts)); .unwrap_or(pts);
} else if buffer.get_dts() != gst::CLOCK_TIME_NONE { } else if buffer.get_dts() != gst::CLOCK_TIME_NONE {
let dts = buffer.get_dts(); let dts = buffer.get_dts();
streaming_state.last_position = streaming_state streaming_state.last_position = streaming_state
.last_position .last_position
.map(|last| cmp::max(last, dts)) .map(|last| cmp::max(last.into(), dts))
.or_else(|| Some(dts)); .unwrap_or(dts);
} }
} }
@ -1120,8 +1110,8 @@ impl DemuxerImpl for FlvDemux {
fn seek( fn seek(
&mut self, &mut self,
demuxer: &RsDemuxer, demuxer: &RsDemuxer,
start: u64, start: gst::ClockTime,
stop: Option<u64>, stop: gst::ClockTime,
) -> Result<SeekResult, ErrorMessage> { ) -> Result<SeekResult, ErrorMessage> {
unimplemented!(); unimplemented!();
} }
@ -1147,15 +1137,15 @@ impl DemuxerImpl for FlvDemux {
false false
} }
fn get_position(&self, demuxer: &RsDemuxer) -> Option<u64> { fn get_position(&self, demuxer: &RsDemuxer) -> gst::ClockTime {
if let Some(StreamingState { last_position, .. }) = self.streaming_state { if let Some(StreamingState { last_position, .. }) = self.streaming_state {
return last_position; return last_position;
} }
None gst::CLOCK_TIME_NONE
} }
fn get_duration(&self, demuxer: &RsDemuxer) -> Option<u64> { fn get_duration(&self, demuxer: &RsDemuxer) -> gst::ClockTime {
if let Some(StreamingState { if let Some(StreamingState {
metadata: Some(Metadata { duration, .. }), metadata: Some(Metadata { duration, .. }),
.. ..
@ -1164,6 +1154,6 @@ impl DemuxerImpl for FlvDemux {
return duration; return duration;
} }
None gst::CLOCK_TIME_NONE
} }
} }

View file

@ -60,8 +60,8 @@ pub trait DemuxerImpl: Send + 'static {
fn seek( fn seek(
&mut self, &mut self,
demuxer: &RsDemuxer, demuxer: &RsDemuxer,
start: u64, start: gst::ClockTime,
stop: Option<u64>, stop: gst::ClockTime,
) -> Result<SeekResult, ErrorMessage>; ) -> Result<SeekResult, ErrorMessage>;
fn handle_buffer( fn handle_buffer(
&mut self, &mut self,
@ -71,8 +71,8 @@ pub trait DemuxerImpl: Send + 'static {
fn end_of_stream(&mut self, demuxer: &RsDemuxer) -> Result<(), ErrorMessage>; fn end_of_stream(&mut self, demuxer: &RsDemuxer) -> Result<(), ErrorMessage>;
fn is_seekable(&self, demuxer: &RsDemuxer) -> bool; fn is_seekable(&self, demuxer: &RsDemuxer) -> bool;
fn get_position(&self, demuxer: &RsDemuxer) -> Option<u64>; fn get_position(&self, demuxer: &RsDemuxer) -> gst::ClockTime;
fn get_duration(&self, demuxer: &RsDemuxer) -> Option<u64>; fn get_duration(&self, demuxer: &RsDemuxer) -> gst::ClockTime;
} }
#[derive(Debug)] #[derive(Debug)]
@ -351,17 +351,11 @@ impl Demuxer {
let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap(); let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap();
if active { if active {
let mut query = gst::Query::new_duration(gst::Format::Bytes); let upstream_size = demuxer
let upstream_size = if demuxer.sinkpad.peer_query(query.get_mut().unwrap()) { .sinkpad
use gst::QueryView; .peer_query_duration(gst::Format::Bytes)
.and_then(|d| d.try_to_bytes())
match query.view() { .and_then(|d| d);
QueryView::Duration(ref d) => Some(d.get().1 as u64),
_ => unreachable!(),
}
} else {
None
};
if !demuxer.start(&element, upstream_size, mode == gst::PadMode::Pull) { if !demuxer.start(&element, upstream_size, mode == gst::PadMode::Pull) {
return false; return false;
@ -530,7 +524,7 @@ impl Demuxer {
match query.view_mut() { match query.view_mut() {
QueryView::Position(ref mut q) => { QueryView::Position(ref mut q) => {
let (fmt, _) = q.get(); let fmt = q.get_format();
if fmt == gst::Format::Time { if fmt == gst::Format::Time {
let demuxer_impl = &demuxer.imp.lock().unwrap(); let demuxer_impl = &demuxer.imp.lock().unwrap();
@ -542,10 +536,10 @@ impl Demuxer {
position position
); );
match position { match *position {
None => return false, None => return false,
Some(position) => { Some(_) => {
q.set(fmt, position as i64); q.set(position);
return true; return true;
} }
} }
@ -554,7 +548,7 @@ impl Demuxer {
} }
} }
QueryView::Duration(ref mut q) => { QueryView::Duration(ref mut q) => {
let (fmt, _) = q.get(); let fmt = q.get_format();
if fmt == gst::Format::Time { if fmt == gst::Format::Time {
let demuxer_impl = &demuxer.imp.lock().unwrap(); let demuxer_impl = &demuxer.imp.lock().unwrap();
@ -566,10 +560,10 @@ impl Demuxer {
duration duration
); );
match duration { match *duration {
None => return false, None => return false,
Some(duration) => { Some(_) => {
q.set(fmt, duration as i64); q.set(duration);
return true; return true;
} }
} }
@ -597,9 +591,13 @@ impl Demuxer {
} }
} }
fn seek(&self, element: &RsDemuxer, start: u64, stop: u64, offset: &mut u64) -> bool { fn seek(
let stop = if stop == u64::MAX { None } else { Some(stop) }; &self,
element: &RsDemuxer,
start: gst::ClockTime,
stop: gst::ClockTime,
offset: &mut u64,
) -> bool {
gst_debug!(self.cat, obj: element, "Seeking to {:?}-{:?}", start, stop); gst_debug!(self.cat, obj: element, "Seeking to {:?}-{:?}", start, stop);
let res = { let res = {