Commit c9717271 authored by François Laignel's avatar François Laignel Committed by Sebastian Dröge

Query: allow concrete query instantiation

Allow instantiating and dereferencing concrete queries. The motivation
for this proposal is to allow the following usability enhancements:

- Concrete queries mutability guaranteed by the borrow checker,
including for generic functions:
``` rust
    let mut p = Query::new_position(::Format::Time);
    p.get_mut_structure().set("check_mut", &true);
```

- Concrete queries functions available in place:
``` rust
    let mut q = gst::Query::new_duration(gst::Format::Time);
    let duration = if pipeline.query(&mut q) {
        Some(q.get_result())
    } else {
        None
    };
```
parent b4d5c988
......@@ -25,19 +25,14 @@ fn example_main() {
let pipeline_clone = pipeline.clone();
glib::timeout_add_seconds(1, move || {
use gst::QueryView;
let pipeline = &pipeline_clone;
//let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1);
//let dur = pipeline.query_duration(gst::Format::Time).unwrap_or(-1);
let pos = {
let mut q = gst::Query::new_position(gst::Format::Time);
if pipeline.query(q.get_mut().unwrap()) {
match q.view() {
QueryView::Position(ref p) => Some(p.get_result()),
_ => None,
}
if pipeline.query(&mut q) {
Some(q.get_result())
} else {
None
}
......@@ -46,11 +41,8 @@ fn example_main() {
let dur = {
let mut q = gst::Query::new_duration(gst::Format::Time);
if pipeline.query(q.get_mut().unwrap()) {
match q.view() {
QueryView::Duration(ref p) => Some(p.get_result()),
_ => None,
}
if pipeline.query(&mut q) {
Some(q.get_result())
} else {
None
}
......
This diff is collapsed.
......@@ -128,19 +128,14 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef
custom_data.playing = new_state == gst::State::Playing;
if custom_data.playing {
let mut query = gst::Query::new_seeking(gst::Format::Time);
if custom_data.playbin.query(query.get_mut().unwrap()) {
match query.view() {
gst::QueryView::Seeking(seek) => {
let (seekable, start, end) = seek.get_result();
custom_data.seek_enabled = seekable;
if seekable {
println!("Seeking is ENABLED from {:?} to {:?}", start, end)
} else {
println!("Seeking is DISABLED for this stream.")
}
}
_ => unreachable!(),
let mut seeking = gst::Query::new_seeking(gst::Format::Time);
if custom_data.playbin.query(&mut seeking) {
let (seekable, start, end) = seeking.get_result();
custom_data.seek_enabled = seekable;
if seekable {
println!("Seeking is ENABLED from {:?} to {:?}", start, end)
} else {
println!("Seeking is DISABLED for this stream.")
}
} else {
eprintln!("Seeking query failed.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment