# Gstreamer bindings

**URL:** <https://users.rust-lang.org/t/gstreamer-bindings/591>\
**Category:** uncategorized\
**Created:** [March 9, 2015, 2:17pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591 "2015-03-09T14:17:54Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 2:17pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/1 "2015-03-09T14:17:54Z")

</div>

Just published bindings for gstreamer 1.x: [https://github.com/arturoc/gstreamer1.0-rs](https://github.com/arturoc/gstreamer1.0-rs)

There's some examples that demo how to use it. Of course not all the library is wrapped but the most useful bits are there. Probably the most useful for rust applications, appsink, allows to get data from a pipeline into a Rust application to use it from there.

The objects in gstreamer are reference counted, while in the c api that reference count is explicitly managed, this rust bindings take care of it by unrefing the corresponding gobject when the rust reference is dropped

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 4:56pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/2 "2015-03-09T16:56:09Z")

</div>

Why put `Arc` on top of pointers that already are reference counted (and are far from being `Unique` by the way)?

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 5:17pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/3 "2015-03-09T17:17:57Z")

</div>

i need to pass the \*mut accross threads in a couple of places and that's the only way i managed to pass it, is there a better way?

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 5:24pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/4 "2015-03-09T17:24:12Z")

</div>

I believe you're allowed to `impl Send` for the wrapper struct that contains a pointer. That's what you send to other threads then. (Assuming it's safe to use the underlying objects from different threads.)

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 5:32pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/5 "2015-03-09T17:32:38Z")

</div>

oh, great, yeah that seems to work. was looking into this for a while but didn't managed to make it work without the Unique,

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 5:36pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/6 "2015-03-09T17:36:08Z")

</div>

Another thing: if you manage reference count explicitly (`g_object_unref` in the destructor), when you get a 'floating' object from an FFI call, you need to ~~`g_object_sink`~~ `g_object_ref_sink` it.

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 5:40pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/7 "2015-03-09T17:40:42Z")

</div>

do you mean g\_object\_ref?

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 5:45pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/8 "2015-03-09T17:45:13Z")

</div>

Sorry, I mean `g_object_ref_sink` in general but in your case it would be `gst_object_ref_sink`.

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 5:58pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/9 "2015-03-09T17:58:12Z")

</div>

yes the problem is that if the object is already ref'd then it'll be a memory leak, i'm assuming that the object is ref'd for elements and other full g\_objects which is usually the case in gstreamer i think, for mini objects like samples... there's an owned flag that tells the object if it needs to ref or not since it's more common to get non ref'd objects in that case.

i've removed the Uniques and the Arcs, thanks for the hint!

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 6:02pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/10 "2015-03-09T18:02:42Z")

</div>

No need to assume, ownership transfers in `GObject` world are documented.  
For example, `gst_element_factory_make` returns an object with `transfer floating`.  
The notion of floating references is explained here: [GObject – 2.0](https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#gobject-The-Base-Object-Type.description)

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 6:21pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/11 "2015-03-09T18:21:28Z")

</div>

oh yeah, i was refering to the constructors accepting a `*mut` but didn't realized that `gst_element_factory_make` and others return floating references. i think it's fixed now in every case. thanks again!

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 6:30pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/12 "2015-03-09T18:30:51Z")

</div>

This might be subjective but to me doing  
`use ffi::*;`  
hurts readability a lot because it's not so apparent when you're calling the foreign functions. It's easier to read code that says `ffi::gst_foo_bar()`.

---

<div class="post-metadata">

**Author:** ![arturo](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/arturo/32/397_2.png) [@arturo](https://users.rust-lang.org/u/arturo)\
**Post date:** [March 9, 2015, 6:41pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/13 "2015-03-09T18:41:44Z")

</div>

mmh not sure about that, everything that doesn't belong to the ffi is `gst::` oposed to `gst_` and internally in the library everything that starts with gst\_ refers to the ffi (as oposed to no prefix). even methods to access the ffi objects are named as `gst_*` like in `fn gst_element() -> *const GstElement`.

i've been using this for a while and usually had to access functions from the ffi from outside the library mixed with the bindings so i might be used to that, now that the library is more stable it might be a good idea to differentiate better the ffi calls. perhaps even change the `gst_*` methods to something else

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/gkoz/32/319_2.png) [@gkoz](https://users.rust-lang.org/u/gkoz)\
**Post date:** [March 9, 2015, 7:02pm UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/14 "2015-03-09T19:02:24Z")

</div>

Using `Weak` for callbacks -- cool trick. 👍  
I was wondering how to do that properly.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:36am UTC](https://users.rust-lang.org/t/gstreamer-bindings/591/15 "2023-01-12T08:36:23Z")

</div>

Closed on January 12, 2023, 8:36am UTC


