Motion - Webcam Mempool

Mempool for webcam

Description of Patch

module webcam always mallocs and frees memory for each jpeg.

this patch implements a pool for unused memory.

if memory is needed first unused memory from the pool is used or malloced

Also fixed a small bug: webcam_add_client misses new->tmpbuffer->ref++

Installation of Patch

patch < webcam.diff

Then re-build Motion and test the patch.

Change History of Patch

  • 1.0 webcam mempool and small refcount bugfix

Discussion and Comments

Peter , your patch seems a nice idea , but has some errors.

webcam.c: En la función `webcam_tmpbuffer_unuse':
webcam.c:99: error: structure has no member named `next'
webcam.c: En la función `webcam_tmpbuffer':
webcam.c:212: error: structure has no member named `next'
webcam.c:213: error: structure has no member named `buffersize'
webcam.c:215: error: structure has no member named `buffersize'
webcam.c:221: error: structure has no member named `buffersize'
webcam.c: En la función `webcam_stop':
webcam.c:344: error: structure has no member named `next'
make: *** [webcam.o] Error 1

So please could you fix them ?

-- AngelCarpintero - 11 Jan 2006

Sorry, forgot to inlcude webcam.h

Also included a patch for initialising ffmpeg_deinterlace to 0 in config.c

-- PeterHolik - 12 Jan 2006

Thanks Peter , i assume that the patch is against last daily snapshot , isn't it?

-- AngelCarpintero - 13 Jan 2006

I am integrating this today and will try and run with it for a few days.

If it is stable and does not leak - it will be in 3.2.5.

Nice work

SVN 47 / Motion-daily 20060523

-- KennethLavrsen - 22 Feb 2006


I have reverted this patch. It turns out that it memory leaks. 2-4 MB in a day when you have 9 cameras.

It needs more work before we commit it again.

-- KennethLavrsen - 23 Feb 2006

  • Now i initialize tmpbuffer->next to NULL
  • log every new webcam_tmpbuffer: webcambuffer new (count %d size %d)
  • log every resize webcambuffer realloc (size from %d to %d)

please give it a try an patch to snapshot motion-20060711-051001

i have 3 webcams with 4fps running and pull all the time the mjpegstreams

-- PeterHolik - 12 Jul 2006

I have attached a 24 hour statistik of my PII-233Mhz with 3 cam's at 4fps streaming.

-- PeterHolik - 16 Jul 2006

Fixed patch to work with current svn ( svn r292 ). Not tested yet with valgrind though.

-- AngelCarpintero - 30 Dec 2007

Update patch , fixed segfault ( double free ).

-- AngelCarpintero - 31 Dec 2007

Pool of memory is increasing a never is freed, so it needs a kind of garbage collector.

-- AngelCarpintero - 06 Jan 2008
Topic attachments
I Attachment Action Size Date Who Comment
cpu.pngpng cpu.png manage 26 K 16 Jul 2006 - 07:46 PeterHolik  
load.pngpng load.png manage 29 K 16 Jul 2006 - 07:46 PeterHolik  
memory.pngpng memory.png manage 17 K 16 Jul 2006 - 07:45 PeterHolik  
webcam2.diffdiff webcam2.diff manage 4 K 12 Jan 2006 - 08:55 PeterHolik  
webcam3.diffdiff webcam3.diff manage 5 K 12 Jul 2006 - 13:24 PeterHolik  
webcampool.diffdiff webcampool.diff manage 6 K 31 Dec 2007 - 14:39 AngelCarpintero fixed to work against svn -r292 fixed double free
Topic revision: r12 - 06 Jan 2008, AngelCarpintero
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.