Store/Retrieve array of struct in GstStructure

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Store/Retrieve array of struct in GstStructure

Jimmy De Pauw

Hello all,

I have a custom plugin that need to send message.
The data for this message are an array of basic struct with only simple numeric types in it.

I can store and retrieve any simple thing in GstStructure without any issue but after more than 1 day of searching, i cannot manage to make an array work.
Even an array of int does not work at all.

I tried with a small test program :

GArray *garray = g_array_new(FALSE, FALSE, sizeof(cstruct));

cstruct it = {};
it.x = 10;
it.y = 20;

cstruct it2 = {};
it.x = 30;
it.y = 40;

g_array_append_val(garray, it);
g_array_append_val(garray, it2);

GstStructure *event_struct = gst_structure_new(
        "teststruct",
        "testint", G_TYPE_UINT, 1,
        "testarr", G_TYPE_ARRAY, garray,
        NULL
);

const GValue *arrval = gst_structure_get_value(event_struct, "testarr");
// No idea how to get my array back here
GArray *structarr = (GArray *)arrval;

cstruct *t = &g_array_index(structarr, cstruct, 0);

printf("%u\n", t->y);

The way to get my GArray back is most likely not the right way but i haven't found any leads on how to do it.
I also don't know if i can build the GstStructure that way.

I tried using a boxed GValue to store my GArray but it doesn't matter how i try to do it, it always segfault on gst_structure_new.

GValueArray is deprecated so i tried to do without it, maybe it's not currently possible with gstreamer.

Thanks


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Store/Retrieve array of struct in GstStructure

Thiago Sousa Santos-2


On Tue, Apr 2, 2019 at 2:11 AM De Pauw jimmy <[hidden email]> wrote:

Hello all,

I have a custom plugin that need to send message.
The data for this message are an array of basic struct with only simple numeric types in it.

I can store and retrieve any simple thing in GstStructure without any issue but after more than 1 day of searching, i cannot manage to make an array work.
Even an array of int does not work at all.


Hi, you can set a boxed type into a gvalue and put that into a GstStructure. I couldn't figure out how to do that directly from gst_structure_new (no time to read the source code now) but you can call gst_structure_set_value in the newly created structure and it works. Attached a modification of your snipped that works for me.
 

I tried with a small test program :

GArray *garray = g_array_new(FALSE, FALSE, sizeof(cstruct));

cstruct it = {};
it.x = 10;
it.y = 20;

cstruct it2 = {};
it.x = 30;
it.y = 40;

g_array_append_val(garray, it);
g_array_append_val(garray, it2);

GstStructure *event_struct = gst_structure_new(
        "teststruct",
        "testint", G_TYPE_UINT, 1,
        "testarr", G_TYPE_ARRAY, garray,
        NULL
);

const GValue *arrval = gst_structure_get_value(event_struct, "testarr");
// No idea how to get my array back here
GArray *structarr = (GArray *)arrval;

cstruct *t = &g_array_index(structarr, cstruct, 0);

printf("%u\n", t->y);

The way to get my GArray back is most likely not the right way but i haven't found any leads on how to do it.
I also don't know if i can build the GstStructure that way.

I tried using a boxed GValue to store my GArray but it doesn't matter how i try to do it, it always segfault on gst_structure_new.

GValueArray is deprecated so i tried to do without it, maybe it's not currently possible with gstreamer.

Thanks

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


--
Thiago Sousa Santos

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

test.c (1K) Download Attachment