bus: Add iter() and iter_timed() that return Iterators around the corresponding pop() functions

And make use of them in the examples where it makes sense.
This commit is contained in:
Sebastian Dröge 2018-12-28 00:06:03 +02:00
parent 005f436631
commit 69af6a5975
21 changed files with 41 additions and 20 deletions

View file

@ -165,7 +165,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -147,7 +147,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -253,7 +253,7 @@ fn example_main() -> Result<(), Error> {
// In the callback ("pad-added" on the decodebin), we sent better error information // In the callback ("pad-added" on the decodebin), we sent better error information
// using a bus message. This is the position where we get those messages and log // using a bus message. This is the position where we get those messages and log
// the contained information. // the contained information.
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -286,7 +286,7 @@ fn example_main() -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -104,7 +104,7 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> {
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -502,7 +502,7 @@ impl App {
fn gst_loop(bus: gst::Bus) -> Result<(), Error> { fn gst_loop(bus: gst::Bus) -> Result<(), Error> {
use gst::MessageView; use gst::MessageView;
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {

View file

@ -46,7 +46,7 @@ fn example_main() {
let ret = pipeline.set_state(gst::State::Playing); let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -79,7 +79,7 @@ fn example_main() {
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -241,7 +241,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -106,7 +106,7 @@ fn example_main() {
let ret = playbin.set_state(gst::State::Playing); let ret = playbin.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -249,7 +249,7 @@ fn example_main() -> Result<(), Error> {
let ret = pipeline.set_state(gst::State::Playing); let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -180,7 +180,7 @@ fn example_main() -> Result<(), Error> {
let ret = pipeline.set_state(gst::State::Playing); let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure); assert_ne!(ret, gst::StateChangeReturn::Failure);
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -96,7 +96,7 @@ fn example_main() -> Result<(), Error> {
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing).into_result()?;
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -90,7 +90,7 @@ fn example_main() {
// functionality like timeouts or GLib socket notifications, so this is sufficient. // functionality like timeouts or GLib socket notifications, so this is sufficient.
// The bus is manually operated by repeatedly calling timed_pop on the bus with // The bus is manually operated by repeatedly calling timed_pop on the bus with
// the desired timeout for when to stop waiting for new messages. (None = Wait forever) // the desired timeout for when to stop waiting for new messages. (None = Wait forever)
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -159,7 +159,7 @@ fn example_main() -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -140,6 +140,27 @@ impl Bus {
pub fn unset_sync_handler(&self) { pub fn unset_sync_handler(&self) {
unsafe { ffi::gst_bus_set_sync_handler(self.to_glib_none().0, None, ptr::null_mut(), None) } unsafe { ffi::gst_bus_set_sync_handler(self.to_glib_none().0, None, ptr::null_mut(), None) }
} }
pub fn iter(&self) -> Iter {
self.iter_timed(0.into())
}
pub fn iter_timed(&self, timeout: ::ClockTime) -> Iter {
Iter { bus: self, timeout }
}
}
pub struct Iter<'a> {
bus: &'a Bus,
timeout: ::ClockTime,
}
impl<'a> Iterator for Iter<'a> {
type Item = Message;
fn next(&mut self) -> Option<Message> {
self.bus.timed_pop(self.timeout)
}
} }
#[cfg(any(feature = "futures", feature = "dox"))] #[cfg(any(feature = "futures", feature = "dox"))]

View file

@ -19,7 +19,7 @@ fn tutorial_main() {
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {

View file

@ -34,7 +34,7 @@ fn tutorial_main() {
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {

View file

@ -94,7 +94,7 @@ fn tutorial_main() {
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {

View file

@ -121,7 +121,7 @@ fn tutorial_main() {
// Wait until error, EOS or State Change // Wait until error, EOS or State Change
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {
println!( println!(

View file

@ -68,7 +68,7 @@ fn tutorial_main() {
.into_result() .into_result()
.expect("Unable to set the pipeline to the Playing state."); .expect("Unable to set the pipeline to the Playing state.");
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {