mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
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:
parent
005f436631
commit
69af6a5975
21 changed files with 41 additions and 20 deletions
|
@ -165,7 +165,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.get_bus()
|
||||
.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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -147,7 +147,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.get_bus()
|
||||
.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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -253,7 +253,7 @@ fn example_main() -> Result<(), Error> {
|
|||
// 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
|
||||
// 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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -286,7 +286,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.get_bus()
|
||||
.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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -104,7 +104,7 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> {
|
|||
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
||||
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -502,7 +502,7 @@ impl App {
|
|||
fn gst_loop(bus: gst::Bus) -> Result<(), Error> {
|
||||
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() {
|
||||
MessageView::Eos(..) => break,
|
||||
MessageView::Error(err) => {
|
||||
|
|
|
@ -46,7 +46,7 @@ fn example_main() {
|
|||
let ret = pipeline.set_state(gst::State::Playing);
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -79,7 +79,7 @@ fn example_main() {
|
|||
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
||||
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -241,7 +241,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.get_bus()
|
||||
.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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -106,7 +106,7 @@ fn example_main() {
|
|||
let ret = playbin.set_state(gst::State::Playing);
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -249,7 +249,7 @@ fn example_main() -> Result<(), Error> {
|
|||
let ret = pipeline.set_state(gst::State::Playing);
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -180,7 +180,7 @@ fn example_main() -> Result<(), Error> {
|
|||
let ret = pipeline.set_state(gst::State::Playing);
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -96,7 +96,7 @@ fn example_main() -> Result<(), Error> {
|
|||
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -90,7 +90,7 @@ fn example_main() {
|
|||
// 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 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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -159,7 +159,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.get_bus()
|
||||
.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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -140,6 +140,27 @@ impl Bus {
|
|||
pub fn unset_sync_handler(&self) {
|
||||
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"))]
|
||||
|
|
|
@ -19,7 +19,7 @@ fn tutorial_main() {
|
|||
|
||||
// Wait until error or EOS
|
||||
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;
|
||||
|
||||
match msg.view() {
|
||||
|
|
|
@ -34,7 +34,7 @@ fn tutorial_main() {
|
|||
|
||||
// Wait until error or EOS
|
||||
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;
|
||||
match msg.view() {
|
||||
MessageView::Error(err) => {
|
||||
|
|
|
@ -94,7 +94,7 @@ fn tutorial_main() {
|
|||
|
||||
// Wait until error or EOS
|
||||
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;
|
||||
match msg.view() {
|
||||
MessageView::Error(err) => {
|
||||
|
|
|
@ -121,7 +121,7 @@ fn tutorial_main() {
|
|||
// Wait until error, EOS or State Change
|
||||
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() {
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
|
|
|
@ -68,7 +68,7 @@ fn tutorial_main() {
|
|||
.into_result()
|
||||
.expect("Unable to set the pipeline to the Playing state.");
|
||||
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;
|
||||
match msg.view() {
|
||||
MessageView::Error(err) => {
|
||||
|
|
Loading…
Reference in a new issue