RidgeRun / gst-interpipe

GStreamer plug-in for interpipeline communication
Other
143 stars 64 forks source link

Memory corruption when setting listen-to to the same node #99

Open vzaluckis opened 3 years ago

vzaluckis commented 3 years ago

Hi! I am working on a custom WebRTC service, and there is a stream switching functionality where you switch which input stream gets broadcast to other participants. I have implemented this using the interpipe* elements version 1.1.5, making the actual switch by setting interpipesrc's listen-to property to point to the new stream. All works very well except for the case when the new listen-to node is actually the same as it was. In this case, I am seeing a memory corruption, best illustrated by log excerpt (captured with GST_DEBUG including interpipe*:4).

13:58:59.263516000 | setting encode pipeline inputs to test-input-audio and test-input-video
13:58:59.263554000 | INFO    | interpipe listener enc-audio-src listen to node test-input-audio
13:58:59.263575000 | INFO    | interpipe Already listening to node test-input-audio
13:58:59.263599000 | INFO    | interpipesrc <enc-audio-src> Listening to node test-input-audio
13:58:59.263628000 | INFO    | interpipe listener enc-video-src listen to node test-input-video
13:58:59.263646000 | INFO    | interpipe Already listening to node test-input-video
13:58:59.263665000 | INFO    | interpipesrc <enc-video-src> Listening to node test-input-video
13:58:59.485412000 | FIXME   | basesink <nicesink4> stream-start event without group-id. Consider implementing group-id handling in the upstream elements
13:59:15.960417000 | data channel message, id=1, label=presenter-control: PUSH_LIVE
13:59:15.960485000 | pushing presenter's #53 video and audio to live
13:59:15.960518000 | setting encode pipeline inputs to test-input-audio and test-input-video
13:59:15.960577000 | INFO    | interpipe listener enc-audio-src listen to node test-input-audio
13:59:15.960642000 | INFO    | interpipe listener enc-audio-src leaving node h�#p�
13:59:15.960707000 | INFO    | interpipe Adding new listener enc-audio-src to node test-input-audio
13:59:15.960740000 | INFO    | interpipesink <test-input-audio> Adding new listener enc-audio-src
13:59:15.961184000 | INFO    | interpipesink <test-input-audio> Renegotiated caps: audio/x-raw, format=(string)S16LE, layout=(string)interleaved, rate=(int)48000, channels=(int)1
13:59:15.961335000 | INFO    | interpipesrc <enc-audio-src> Listening to node test-input-audio
13:59:15.961402000 | INFO    | interpipe listener enc-video-src listen to node test-input-video
13:59:15.961431000 | INFO    | interpipe listener enc-video-src leaving node ��#p�
13:59:15.961500000 | INFO    | interpipe Adding new listener enc-video-src to node test-input-video
13:59:15.961548000 | INFO    | interpipesink <test-input-video> Adding new listener enc-video-src
13:59:15.961673000 | INFO    | interpipesink <test-input-video> Renegotiated caps: video/x-raw, format=(string)I420, width=(int)640, height=(int)360, framerate=(fraction)30/1, multiview-mode=(string)mono, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1
13:59:15.961794000 | INFO    | interpipesrc <enc-video-src> Listening to node test-input-video
13:59:15.960672000 | WARN    | interpipe Node h�#p� not found. Could not leave node.
13:59:15.961276000 | WARN    | interpipesink <test-input-audio> Listener enc-audio-src already registered in node test-input-audio
13:59:15.961457000 | WARN    | interpipe Node ��#p� not found. Could not leave node.
13:59:15.961737000 | WARN    | interpipesink <test-input-video> Listener enc-video-src already registered in node test-input-video

I have not been able to track the issue down myself so far, but I will definitely post a patch if/when I fix it. I am hoping that maybe someone (the authors?) will fix it sooner though.

vzaluckis commented 3 years ago

Checking the existing value and setting listen-to only if the new value differs, actually prevents memory corruption from happening.

michaelgruner commented 2 years ago

Oh thanks for this report. This should be an easy fix, let me take it internally and get back to you!

michaelgruner commented 2 years ago

@jsalas98 can you apply you magic here?

jsalas98 commented 2 years ago

@vzaluckis I have made the hotfix for this issue, it is already in master. Thanks for your report, please let us know if this new release fixes your issue.