Skip to content

examples: discoverer: Fix panic due to null stream_id of container type

kwange e requested to merge ekwange/gstreamer-rs:example into main

When I run discoverer in example, I meet panic as shown below. The stream_id can be null and there is no consideration for it.

$ RUST_BACKTRACE=1 ./discoverer https://media.w3.org/2010/05/sintel/trailer.mp4
...
thread 'main' panicked at 'assertion failed: !ptr.is_null()', /home/ekwang/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/a6e97cc/glib/src/gstring.rs:1940:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: core::panicking::panic
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:111:5
   3: <glib::gstring::GString as glib::translate::FromGlibPtrNone<*const u8>>::from_glib_none
             at /home/ekwang/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/a6e97cc/glib/src/gstring.rs:1940:9
   4: glib::translate::from_glib_none
             at /home/ekwang/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/a6e97cc/glib/src/translate.rs:1622:5
   5: <glib::gstring::GString as glib::translate::FromGlibPtrNone<*const i8>>::from_glib_none
             at /home/ekwang/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/a6e97cc/glib/src/gstring.rs:1949:9
   6: glib::translate::from_glib_none
             at /home/ekwang/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/a6e97cc/glib/src/translate.rs:1622:5
   7: <O as gstreamer_pbutils::auto::discoverer_stream_info::DiscovererStreamInfoExt>::stream_id
             at /home/ekwang/project/gstreamer-rs/gstreamer-pbutils/src/auto/discoverer_stream_info.rs:101:13
   8: discoverer::print_stream_info
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/discoverer.rs:40:33
   9: discoverer::print_discoverer_info
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/discoverer.rs:52:5
  10: discoverer::run_discoverer
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/discoverer.rs:81:5
  11: discoverer::example_main
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/discoverer.rs:86:11
  12: core::ops::function::FnOnce::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5
  13: discoverer::examples_common::run
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/../examples-common.rs:12:5
  14: discoverer::main
             at /home/ekwang/project/gstreamer-rs/examples/src/bin/discoverer.rs:95:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5

Since there is no macro like GST_IS_DISCOVERER_CONTAINER_INFO, I checked whether the value of stream_type_nick is a container and handled the exception. Is there a better way?

Merge request reports

Loading