Playbin flags in Rust
Sebastian Dröge
sebastian at centricular.com
Thu Feb 22 17:01:46 UTC 2018
On Thu, 2018-02-22 at 15:30 +0000, Russel Winder wrote:
> I need to fiddle with the text flag of a playbin, so as to ensure no
> subtitles. In C I believe (I have no experience) the useful symbol is
> GST_PLAY_FLAGS_TEXT in the GstPlayFlags enum.
In C you would either set the enum by string in the
gst_util_set_object_arg() function (e.g. "text+native-audio"), or by
integer (check gst-inspect-1.0 for the integer values of the flags), or
by defining your own version of the GstPlayFlags enum, or by using the
GObject enum/flags API directly.
Plugin headers are not installed and not usable by applications.
> In C++ (which I have
> used) there is Gst::PlayFlags::PLAY_FLAG_TEXT to select out the
> relevant bit.
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.
See also https://bugzilla.gnome.org/show_bug.cgi?id=755395
> The question is what is the right way of doing things in
> Rust. There is a commented out bit in:
>
> GStreamer_Rs/examples/src/bin/playbin.rs
>
> but it looks mightily manual and complex.
The following are your options right now:
1)
The commented out code here
https://github.com/sdroege/gstreamer-rs/blob/4117c01ff2c9ce9b46b8f63315af4dc284788e9b/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.
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.
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.
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.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1000 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20180222/9b9d0a5b/attachment.sig>
More information about the gstreamer-devel
mailing list