I am trying to pass a variable by reference into a void pointer in order to update the original value. When I try it, the old value is never updated. Any help will be appreciated.
gst_filter_chain is like the main function (Gstreamer)
void update_value(void *oldValue, void *newValue)
{
oldValue = newValue;
}
void update_struct(myStruct *oldStruct, myStruct newStruct)
{
update_value((void *)&oldStruct->a, (void *)&newStruct.a)
}
static GstFlowReturn
gst_filter_chain (GstPad * pad, GstBuffer * buf)
{
GstFilter *filter= GST_FILTER (gst_pad_get_parent (pad));
myStruct temp_data;
int buf_size = GST_BUFFER_SIZE(buf);
if(buf_size > 1) //if buffer is not empty
{
if(!filter->is_init)
{
memcpy(&filter->data, GST_BUFFER_DATA(buf), sizeof(myStruct));
filter->is_init = TRUE;
}
else
{
memcpy(&temp_data, GST_BUFFER_DATA(buf), sizeof(myStruct));
update_struct(&filter->data, temp_data);
}
}
gst_buffer_unref(buf);
return GST_FLOW_OK;
}
In this snippet, you are only updating the pointer variable, not the value it points to.
You have to de-reference the pointer to access the actual data. If you want a really generic setter solution, you could use memcpy, but you’d need to pass to update_value a size parameter, to tell memcpy what’s the size of the datatype pointed by oldValue and newValue.