Page 1 of 1

Memory leak while using libvlc imem module

Posted: 13 Dec 2016 08:21
by vlad-29
Hello, I have memory leak when I play or broadcast video from my camera with imem module.
I used this code:

Code: Select all

int myImemGetCallback(void *data, const char *cookie, int64_t *dts, int64_t *pts, unsigned *flags, size_t * bufferSize, void ** buffer) { int ret = 0; int size = globalsize; if(!bufferinit) *buffer = malloc(size);// malloc once memcpy(*buffer, data, size); *dts = globaldts; globaldts = globaldts + 33333; *pts = globalpts; globalpts = globalpts + 33333; *bufferSize = size; return ret; } int myImemReleaseCallback(void *data, const char *cookie, size_t bufferSize, void * buffer) { int ret = 0; return ret; }
My vlc arguments:

Code: Select all

vlc_args[0] = "-vvvvv"; vlc_args[1] = (char*)calloc(200, 1); sprintf(vlc_args[1], "--imem-get=%ld", myImemGetCallback); vlc_args[2] = (char*)calloc(200, 1); sprintf(vlc_args[2], "--imem-release=%ld", myImemReleaseCallback); vlc_args[3] = (char*)calloc(200, 1); sprintf(vlc_args[3], "--imem-cat=2"); //CAT 1 == AUDIO vlc_args[4] = (char*)calloc(200, 1); sprintf(vlc_args[4], "--imem-data=%ld", buffertobroadcast);/** my context custom data to be passed callbacks **/ vlc_args[5] = "--imem-id=0"; vlc_args[6] = (char*)calloc(200, 1); sprintf(vlc_args[6], "--imem-codec=RV24"); //CODEC, format of the data passed to vlc in the buffers vlc_args[7] = (char*)calloc(200, 1); sprintf(vlc_args[7], "--imem-width=640"); vlc_args[8] = (char*)calloc(200, 1); sprintf(vlc_args[8], "--imem-height=360"); vlc_args[9] = (char*)calloc(200, 1); sprintf(vlc_args[9], "--imem-channels=%d", mNumInputs); //number of channels vlc_args[10] = (char *)calloc(200, 1); sprintf(vlc_args[10], "--imem-samplerate=%d", mSampleFreq); //sample frequency vlc_args[11] = (char *)calloc(200, 1); sprintf(vlc_args[11], "--imem-fps=25.000000"); //sample frequency
My broadcast arguments:

Code: Select all

libvlc_vlm_add_broadcast(inst, "stream", "imem://", "#transcode{vcodec=h264,vb=3000,fps=25,scale=1,acodec=a52,ab=128,channels=2,samplerate=44100}:rtp{mux=ts,dst=127.0.0.1}", 0, NULL, 1, 0);
There is no memory leak while broadcasting or playing in window are not executed.
Also the message "late buffer for mux input" appear constantly.
imem works well and I can watch the video from camera and stream but memory leaks very fast. I don't see where it can leak in my code, maybe I miss something?

Re: Memory leak while using libvlc imem module

Posted: 27 Dec 2016 11:49
by Jean-Baptiste Kempf
Memleaks should be debugged with valgrind traces.

Re: Memory leak while using libvlc imem module

Posted: 06 Feb 2017 11:56
by vlad-29
I found the problem. This is unnecessary and makes memory leak. There is no need to allocate memory in imem-get function.

Code: Select all

if(!bufferinit) *buffer = malloc(size);// malloc once memcpy(*buffer, data, size);