I would like to check for whether buffer has flowed through a branch of my code when I have reattached a branch of the pipeline. The conventional (or at least the tutorial method) method is to attach a probe at one point to probe it for buffer flowing (a way of sanity check) through the branch. If there is buffer flowing, I would then change the internal state for it to be able to process another command (another "if" state)
Conventional or mine code
static GstPadProbeReturn
have_buff( GstPad *pad,
GstPadProbeInfo* info,
gpointer data)
{
b_haveBuffer = TRUE;
return GST_PAD_PROBE_REMOVE;
}
void loop_run():
{
if(reattach)
{
// after completing some actions to reattach the branch
// i would like to check for whether buffer has flowed through
b_haveBuffer = FALSE;
gulong padID = gst_pad_add_probe ( srcpad,
GST_PAD_PROBE_TYPE_BUFFER,
(GstPadProbeCallback)have_buff,
NULL,
NULL);
sleep(1); // my naive solution
/// blocking code
while(!b_haveBuffer)
{
g_usleep(100000);
}
/// there is buffer
gst_pad_remove_probe(srcpad, padID);
/// then proceed on with operation
}
}
Problem is at times (only for few times), the callback would return much later and the program would then be trapped in while loop. Well my "solution" is to have the application sleep for a while (that did not exactly work for me... I guess that it is because the callback and main loop exist under same thread and sleep will for both application to go to sleep.
I have thought of some methods to proceed.
making the callback to handle the rest of code in reattached, ie altering the loop state within callback. However that would be a bit ugly as there are other "if" code for other state change and I would like their state to be formally change in one single places (for debugging ease)
Using some function to check for buffer flowing if there is one I could change/replace my code to look like
while( gst_buffer_flow_is_false()) { g_usleep(100000); }
would like to know if there is such a function or any other methods to circumvent it. Or is there a conventional technique/approach to deal with in such situation
Regards