-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tutorial 5, similar to the one from gst-docs. #41
Conversation
6657517
to
ad81ef1
Compare
ad81ef1
to
8b26400
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to run all this once through rustfmt-nightly :)
@@ -0,0 +1,377 @@ | |||
#[cfg(feature = "tutorial5")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to move all this into a sub-module so that you have to put the feature gate only once or twice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fn add_streams_info( | ||
playbin: &gst::Element, | ||
textbufcell: &SendCell<gtk::TextBuffer>, | ||
stype: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&str
would be nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// Extract metadata from all the streams and write it to the text widget in the GUI | ||
fn analyze_streams(playbin: &gst::Element, textbufcell: &SendCell<gtk::TextBuffer>) { | ||
let text = ""; | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text
is only used once, and only in this block here, not outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
match pipeline.query_duration(gst::Format::Time) { | ||
Some(x) => { | ||
let seconds = (x as u64) / gst::SECOND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(dur) = pipeline.query_...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT, | ||
((value * gst::SECOND) as i64), | ||
) | ||
.is_err() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Err(_) = pipeline.seek_simple(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
let position = pipeline.query_position(gst::Format::Time); | ||
if let Some(position) = position { | ||
let seconds = (position as u64) / gst::SECOND; | ||
signal::signal_handler_block(lslider, from_glib(slider_update_signal_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The from_glib
should not be needed at all here. If connect_value_changed
returns an u64
instead, you found a bug in gtk-rs and can submit a PR there :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns a SignalHandlerId
no a u64 as all other signals iiuc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fixed then :)
|
||
// Initialize GTK | ||
if gtk::init().is_err() { | ||
eprintln!("Failed to initialize GTK."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Err(err) = gtk::init()
and then also print the error. Same for GStreamer. is_err
, is_some
and all these are usually not nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
let playbin = gst::ElementFactory::make("playbin", None).unwrap(); | ||
if playbin | ||
.set_property("uri", &glib::Value::from(uri)) | ||
.is_err() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap()
, this never fails unless you fail to type :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
let bus = playbin.get_bus().unwrap(); | ||
let pipeline = playbin.clone(); | ||
bus.add_watch(gst::Bus::async_signal_func); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that the same as bus.add_signal_watch()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, not sure how I forgot and ended up adding the API :-)
Removed Bus::async_signal_func it should not be so useful, let me know if you want me to open a PR to re add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that's fine :) I didn't add it before because it seemed a bit useless
615458c
to
ec79ffd
Compare
.connect_value_changed(move |slider| { | ||
let pipeline = &pipeline; | ||
let value = slider.get_value() as u64; | ||
if let Err(_) = pipeline .seek_simple( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before .seek_simple
eprintln!("Seeking to {} failed", value); | ||
} | ||
}) | ||
.to_glib(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_glib() also shouldn't be here. The from_glib_* and to_glib_* functions are all meant for the bindings code only, or when you interact with the C functions directly
let pipeline = playbin.clone(); | ||
bus.add_signal_watch(); | ||
playbin.get_bus().unwrap().connect_message(move |_, msg| { | ||
//let streams_view = &streams_view; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented out, why?
ec79ffd
to
61c6f34
Compare
This now depends on gtk-rs/glib#240 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just need to get the glib change merged first
I'll merge this later, thanks a lot :) |
And "Add a Bus.async_signal_func helper function"