Playbin flags in Rust

Russel Winder russel at winder.org.uk
Fri Feb 23 18:49:54 UTC 2018


On Thu, 2018-02-22 at 18:01 +0100, Sebastian Dröge wrote:
> […]
> 
> It's IMHO a mistake that the gstreamermm bindings are providing
> bindings for plugin types directly inside the bindings. As their
> existence is not guaranteed, which leads to all kinds of funny
> problems.

Ah, good point. I was seduced by the presence of the enum in the library
headers. Querying the plugin for the values is clearly the right way forward.

> 
[…]
> 1)
> The commented out code here
>   https://github.com/sdroege/gstreamer-rs/blob/4117c01ff2c9ce9b46b8f63315af4
> dc284788e9b/examples/src/bin/playbin.rs#L27-L35
> would be the safe way of doing it and being able to know that you
> actually did things correctly. It also allows you to use any flag
> values that were added after the bindings release, etc.
> 
> Check the Flags API in glib-rs for more details and some variations.

OK this gives me the confidence to go this route. Whilst a bit verbose it is
the right thing to do.

> 2)
> Alternatively you can do something like
>   playbin.set_property_from_str("flags", "text+native-audio")
> or similar. But that has the problem that you won't know if any of the
> flags you set don't exist or you did typos. Also it does not easily
> allow you to set/unset specific flags, you always set the whole thing.

This is though a quite intriguing, and arguably more self-documenting way of
doing it.

> 3)
> Or if you feel adventurous you can define your own copy of that
> specific C enum via the bitflags crate and then implement direct
> translation from that to GValues (requires all the relevant traits to
> be implemented). Then you can directly use
>   playbin.set_property("flags", YourFlagsType::TEXT |
> YourFlagsType::NATIVE_AUDIO)
> 
> That's the equivalent of "copying the enum" in C.

I am constraining my adventurousness just now. I still do not know Rust well
enough to be within my comfort zone, especially as I do not have a Rust expert
to give me feedback on my code.

> 4)
> Or you can just set it by integer with two lines of unsafe code.
> 
> 
> It could make sense for doing a separate crate that provides such
> flags/enum types and wrappers around well-known plugin element types
> (playbin etc), but it should not be part of the main bindings.
> Maybe you want to start such a crate?
> 
> Most of it could also be completely autogenerated by doing basically
> the same gst-inspect-1.0 is doing and then outputting code based on
> that.

Definitely not a for now thing!

Thanks for keeping me on the straight and narrow with this. Much appreciated.
I will soon have to tackle the MPEGTS API in GStreamer_Rs but not just yet, I
need to get the playbin working as required which means tinkering with source
events given the C++ code that works. 

-- 
Russel.
==========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20180223/a01a7e7f/attachment.sig>


More information about the gstreamer-devel mailing list