In a h264 video pipeline, we are dynamically adding(and removing) a text overlay when video is in playing condition.
Please see the details
olcamerasrc->capsfilter->queue->appsink
olcamersrc is custom element - will produce H264 encoded video in its src
pad. It also have a sink pad to accept overlay buffer to be encoded with the
video.
After setting initial pipeline’s state to PLAYING I am trying to add below
mentioned pipeline dynamically to above one to display an overlay on the
video. overlay buffer will be fed to appsrc once new pipeline is added.
appsrc–>alphacolor–>queue–>capsfilter->overlaysink( sink pad of
olcamerasrc element)
After setting new elements state to PLAYING I printed the reference count of
each elements. It is suddenly changed to 6 from 1. When I trying to remove
these elements from pipeline reference count never reaching to zero. Seems
like it causing memory leak. I have done a performance testing by adding and
removing new pipeline elements and application got killed by OS due to
increase in memory usage.
My steps to add pipeline elements:
- Add a probe in source pad of olcamerasrc
- Inside the call back method of probe
a) Add new elements to pipeline using -gst_bin_add_many
b) Link new elements using - gst_element_link_many
c) Request new sink pad from olcamerasrc.
d) Link overlay sink pad of olcamerasrc and src pad of capsfilter
e) Set state to PLAYING for new elements - return pad drop
My steps to remove pipeline elements:
- Add a probe in source pad of olcamerasrc
- Inside the call back method of probe
a) Unlink overlay sink pad of olcamerasrc and src pad of capsfilter
b) Unlink new elements using - gst_element_unlink_many
c) Remove new elements from pipeline using -gst_bin_remove_many
d) Release new sink pad from olcamerasrc.
e) Set state to NULL for new elements - return pad drop
I have a few confusions here .
-
Is it required to add any probe( in pad of olcamerasrc) in order to
add/remove overlay ( above pipeline ) dynamically to initial pipeline? -
What would be the reason for the spike in reference count when state
changing to PLAYING? -
How can I properly reach zero reference count for elements after
removing from pipeline?
Could you please help me to identify the above mentioned issues ?