Index: webcam.c
===================================================================
--- webcam.c	(revisión: 351)
+++ webcam.c	(copia de trabajo)
@@ -19,17 +19,13 @@
  */
 
 #include "picture.h"
-//#include <sys/time.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <sys/fcntl.h>
-//#include <sys/stat.h>
 
 
-
-
 /* This function sets up a TCP/IP socket for incoming requests. It is called only during
  * initialisation of Motion from the function webcam_init
  * The function sets up a a socket on the port number given by _port_.
Index: video_freebsd.c
===================================================================
--- video_freebsd.c	(revisión: 351)
+++ video_freebsd.c	(copia de trabajo)
@@ -8,12 +8,9 @@
  */
 
 /* Common stuff: */
-//#include "motion.h"
 /* for rotation */
 #include "rotate.h"     /* already includes motion.h */
 #include "video_freebsd.h"
-/* for rotation */
-//#include "rotate.h"
 
 #ifndef WITHOUT_V4L
 
Index: video.c
===================================================================
--- video.c	(revisión: 351)
+++ video.c	(copia de trabajo)
@@ -9,16 +9,10 @@
 #ifndef WITHOUT_V4L
 
 /* Common stuff: */
-//#include "motion.h"
-///* for rotation */
 #include "rotate.h"     /* already includes motion.h */
 #include "video.h"
-/* for rotation */
-//#include "rotate.h"
 
-
 /* for the v4l stuff: */
-//#include "pwc-ioctl.h"	/* not needed here only in track */
 #include <sys/mman.h>
 #include <math.h>
 #include <sys/utsname.h>
@@ -104,7 +98,7 @@
 */
 
 
-unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
+int v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
                                 int input, int norm, unsigned long freq, int tuner_number)
 {
 	int dev = viddev->fd;
@@ -113,11 +107,10 @@
 	struct video_tuner vid_tuner;
 	struct video_mbuf vid_buf;
 	struct video_mmap vid_mmap;
-	void *map;
 
 	if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) {
 		motion_log(LOG_ERR, 1, "ioctl (VIDIOCGCAP)");
-		return (NULL);
+		return 0;
 	}
 
 	if (vid_caps.type & VID_TYPE_MONOCHROME)
@@ -134,7 +127,7 @@
 			vid_chnl.norm    = norm;
 			if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) {
 				motion_log(LOG_ERR, 1, "ioctl (VIDIOCSCHAN)");
-				return (NULL);
+				return 0;
 			}
 		}
 	}
@@ -152,7 +145,7 @@
 			}
 			if (ioctl(dev, VIDIOCSFREQ, &freq) == -1) {
 				motion_log(LOG_ERR, 1, "ioctl (VIDIOCSFREQ)");
-				return (NULL);
+				return 0;
 			}
 			if (cnt->conf.setup_mode)
 				motion_log(-1, 0, "Frequency set");
@@ -163,23 +156,19 @@
 		motion_log(LOG_ERR, 0, "ioctl(VIDIOCGMBUF) - Error device does not support memory map");
 		motion_log(LOG_ERR, 0, "V4L capturing using read is deprecated!");
 		motion_log(LOG_ERR, 0, "Motion only supports mmap.");
-		return NULL;
+		return 0;
 	} else {
-		map = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
-		viddev->size_map = vid_buf.size;
-		if (vid_buf.frames > 1) {
-			viddev->v4l_maxbuffer = 2;
-			viddev->v4l_buffers[0] = map;
-			viddev->v4l_buffers[1] = (unsigned char *)map + vid_buf.offsets[1];
-		} else {
-			viddev->v4l_buffers[0] = map;
-			viddev->v4l_maxbuffer = 1;
-		}
+		/* Check number of buffers vid_buf.frames */
 
-		if (MAP_FAILED == map) {
+		viddev->v4l_buffers = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0);
+		viddev->v4l_maxbuffer = vid_buf.frames - 1;
+		viddev->size_map = vid_buf.size;
+		
+		if (MAP_FAILED == viddev->v4l_buffers) {
 			motion_log(LOG_ERR,1,"MAP_FAILED");
-			return (NULL);
+			return 0;
 		}
+
 		viddev->v4l_curbuffer = 0;
 		vid_mmap.format = viddev->v4l_fmt;
 		vid_mmap.frame = viddev->v4l_curbuffer;
@@ -209,7 +198,7 @@
 						if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) {
 							motion_log(LOG_ERR, 1, "Failed with all supported palettes "
 						                            "- giving up");
-							return (NULL);
+							return 0;
 						}
 					}
 				}
@@ -239,7 +228,7 @@
 			motion_log(LOG_DEBUG, 0, "Using VIDEO_PALETTE_GREY palette");
 			break;
 	}
-	return map;
+	return 1;
 }
 
 
@@ -282,7 +271,7 @@
 	sigaddset(&set, SIGHUP);
 	pthread_sigmask (SIG_BLOCK, &set, &old);
 
-	cap_map = viddev->v4l_buffers[viddev->v4l_curbuffer];
+	cap_map = (unsigned char *)viddev->v4l_buffers + (viddev->size_map * viddev->v4l_curbuffer);
 	viddev->v4l_curbuffer++;
 
 	if (viddev->v4l_curbuffer >= viddev->v4l_maxbuffer)
Index: video.h
===================================================================
--- video.h	(revisión: 351)
+++ video.h	(copia de trabajo)
@@ -60,12 +60,12 @@
 	int v4l2;
 	void *v4l2_private;
 
-	int size_map;
+	size_t size_map;
 	int v4l_fmt;
-	unsigned char *v4l_buffers[2];
+	void *v4l_buffers;
+	size_t v4l_bufsize;
 	int v4l_curbuffer;
 	int v4l_maxbuffer;
-	int v4l_bufsize;
 #endif
 };
 
@@ -90,7 +90,7 @@
 /* video functions, video.c */
 int vid_startpipe(const char *dev_name, int width, int height, int);
 int vid_putpipe(int dev, unsigned char *image, int);
-unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
+int v4l_start(struct context *cnt, struct video_dev *viddev, int width, int height,
 			 int input, int norm, unsigned long freq, int tuner_number);
 void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height, int input,
 		   int norm, int skip, unsigned long freq, int tuner_number);
Index: event.c
===================================================================
--- event.c	(revisión: 351)
+++ event.c	(copia de trabajo)
@@ -10,7 +10,6 @@
 */
 
 #include "ffmpeg.h"	/* must be first to avoid 'shadow' warning */
-//#include "motion.h"
 #include "picture.h"	/* already includes motion.h */
 #include "event.h"
 #if (!defined(BSD)) 
Index: video2.c
===================================================================
--- video2.c	(revisión: 351)
+++ video2.c	(copia de trabajo)
@@ -680,7 +680,7 @@
 	}
 
 	viddev->size_map = 0;
-	viddev->v4l_buffers[0] = NULL;
+	viddev->v4l_buffers = NULL;
 	viddev->v4l_maxbuffer = 1;
 	viddev->v4l_curbuffer = 0;
 
Index: video_common.c
===================================================================
--- video_common.c	(revisión: 351)
+++ video_common.c	(copia de trabajo)
@@ -9,12 +9,9 @@
  *
  */
 
-//#include "motion.h"
 /* for rotation */
 #include "rotate.h"	/* already includes motion.h */
 #include "video.h"
-/* for rotation */
-//#include "rotate.h"
 
 #ifdef MJPEGT 
 #include <mjpegtools/jpegutils.h>
@@ -590,8 +587,13 @@
 		} else {
 #endif
 			close(dev->fd);
-			munmap(viddevs->v4l_buffers[0], viddevs->size_map);
-			munmap(viddevs->v4l_buffers[1], viddevs->size_map);
+
+			if (dev->v4l_buffers) {
+				munmap(viddevs->v4l_buffers, viddevs->size_map);
+				motion_log(LOG_INFO, 0, "munmap dev->v4l_buffers properly");
+			} else {
+				motion_log(LOG_INFO, 1, "Error unmmaping dev->v4l_buffers");
+			}
 #ifdef MOTION_V4L2
 		}
 #endif
Index: webhttpd.c
===================================================================
--- webhttpd.c	(revisión: 351)
+++ webhttpd.c	(copia de trabajo)
@@ -10,10 +10,7 @@
  *      See also the file 'COPYING'.
  *
  */
-//#include "motion.h"
 #include "webhttpd.h"	/* already includes motion.h */
-//#include <sys/types.h>
-//#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
Index: netcam_ftp.c
===================================================================
--- netcam_ftp.c	(revisión: 351)
+++ netcam_ftp.c	(copia de trabajo)
@@ -11,19 +11,9 @@
 #include "motion.h"  /* needs to come first, because _GNU_SOURCE_ set there */
 
 #include <ctype.h>
-//#include <errno.h>
-//#include <fcntl.h>
 #include <netdb.h>
 #include <regex.h>
-//#include <stdarg.h>
-//#include <stdlib.h>
-//#include <stdio.h>
-//#include <string.h>
-//#include <syslog.h>
-//#include <unistd.h>
 #include <sys/socket.h>
-//#include <sys/stat.h>
-//#include <sys/types.h>
 #include <netinet/in.h>
 
 #include "netcam_ftp.h"
