├── .gitignore
├── motion_guide.html
├── git-commit-version.sh
├── INSTALL
├── commit-version.sh
├── version.sh
├── sdl.h
├── motion.init-FreeBSD.sh.in
├── vloopback_motion.h
├── README.axis_2100
├── webhttpd.h
├── netcam_rtsp.h
├── picture.h
├── FAQ
├── README.MacOSX
├── event.h
├── alg.h
├── stream.h
├── motion.init-Debian.in
├── netcam_ftp.h
├── rotate.h
├── ffmpeg-0.4.8-macosx.patch
├── thread1.conf.in
├── thread2.conf.in
├── thread3.conf.in
├── README.FreeBSD
├── md5.h
├── README
├── thread4.conf.in
├── ffmpeg.h
├── logger.h
├── jpegutils.h
├── motion.init-Fedora.in
├── netcam_wget.h
├── config.h.in
├── video_freebsd.h
├── video.h
├── conf.h
├── track.h
├── motion.spec.in
├── sdl.c
├── logger.c
├── CODE_STANDARD
├── vloopback_motion.c
├── pwc-ioctl.h-pwc8.0
├── pwc-ioctl.h-pwc9.0.1
├── netcam_rtsp.c
├── pwc-ioctl.h-10.0.5
├── netcam_wget.c
├── md5.c
├── pwc-ioctl.h
├── pwc-ioctl.h-10.0.10
└── mmx.h
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | .svn/
3 | *.o
4 |
--------------------------------------------------------------------------------
/motion_guide.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sackmotion/motion/HEAD/motion_guide.html
--------------------------------------------------------------------------------
/git-commit-version.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SNV_VERSION=`git show -s --format=%H`
4 | echo -n "Git-$SNV_VERSION"
5 |
6 |
--------------------------------------------------------------------------------
/INSTALL:
--------------------------------------------------------------------------------
1 | Very simple:
2 |
3 | type:
4 |
5 | ./configure
6 |
7 | followed by:
8 |
9 | make
10 |
11 | And
12 |
13 | make install
14 |
15 |
16 | Next read the README
17 |
--------------------------------------------------------------------------------
/commit-version.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SNV_VERSION=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2`
4 | SNV_VERSION=`expr $SNV_VERSION + 1`
5 | echo -n "trunkREV$SNV_VERSION"
6 |
--------------------------------------------------------------------------------
/version.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SNV_VERSION=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2`
4 | test $SNV_VERSION || SNV_VERSION=`cd "$1" && grep revision .svn/entries 2>/dev/null | cut -d '"' -f2`
5 | test $SNV_VERSION || SNV_VERSION=UNKNOWN
6 | echo -n "trunkREV$SNV_VERSION"
7 |
--------------------------------------------------------------------------------
/sdl.h:
--------------------------------------------------------------------------------
1 | /* sdl.h
2 | *
3 | * Include file for sdl.c
4 | * Copyright 2009 by Peter Holik (peter@holik.at)
5 | * This software is distributed under the GNU public license version 2
6 | * See also the file 'COPYING'.
7 | */
8 | #ifndef _INCLUDE_SDL_H
9 | #define _INCLUDE_SDL_H
10 |
11 | #include "motion.h"
12 |
13 | int sdl_start(int width, int height);
14 | void sdl_put(unsigned char *image, int width, int height);
15 | void sdl_stop(void);
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/motion.init-FreeBSD.sh.in:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # motion.sh for rc.d usage 2006 Angel Carpintero
4 | #
5 | # Add the following line in /etc/rc.conf to enable @PACKAGE_NAME@ at startup
6 | #
7 | # motion_enable="YES"
8 | #
9 |
10 | # PROVIDE: @PACKAGE_NAME@
11 | # REQUIRE: DAEMON
12 | # KEYWORD: shutdown
13 |
14 | . /etc/rc.subr
15 |
16 | motion_enable="${motion_enable-NO}"
17 |
18 | name="@PACKAGE_NAME@"
19 | rcvar=`set_rcvar`
20 |
21 | command="@BIN_PATH@/${name}"
22 | pidfile="/var/run/${name}.pid"
23 | required_files="/usr/local/etc/${name}.conf"
24 |
25 | load_rc_config $name
26 | run_rc_command "$1"
27 |
--------------------------------------------------------------------------------
/vloopback_motion.h:
--------------------------------------------------------------------------------
1 | /* vloopback_motion.h
2 | *
3 | * Include file for vloopback_motion.c
4 | * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org)
5 | * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com)
6 | * This software is distributed under the GNU public license version 2
7 | * See also the file 'COPYING'.
8 | *
9 | */
10 | #ifndef _INCLUDE_VLOOPBACK_MOTION_H
11 | #define _INCLUDE_VLOOPBACK_MOTION_H
12 |
13 | #include "motion.h"
14 |
15 | int vid_startpipe(const char *dev_name, int width, int height, int);
16 | int vid_putpipe(int dev, unsigned char *image, int);
17 | #endif
18 |
--------------------------------------------------------------------------------
/README.axis_2100:
--------------------------------------------------------------------------------
1 | Using motion with the Axis 2100 network camera
2 |
3 | First compile the motion binary as described in README and INSTALL
4 | Then edit motion.conf: Add your axis cameras ip address to the netcam_url
5 | paramter in the "Captute Device Options" section.
6 |
7 | To increase the performance use this urls :
8 |
9 | # for multipart jpeg
10 | http://192.168.1.10/axis-cgi/mjpg/video.cgi?showlength=1
11 |
12 | or
13 |
14 | # for single jpeg
15 | http://192.168.1.10/axis-cgi/jpg/image.cgi?showlength=1
16 |
17 | There are only two valid picture sizes for the axis camera: 320x240 and 640x480
18 |
19 | TODO:
20 |
21 | - Make the IP changeable at run-time.
22 |
--------------------------------------------------------------------------------
/webhttpd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * webhttpd.h
3 | *
4 | * Include file for webhttpd.c
5 | *
6 | * Specs : http://www.lavrsen.dk/twiki/bin/view/Motion/MotionHttpAPI
7 | *
8 | * Copyright 2004-2005 by Angel Carpintero (motiondevelop@gmail.com)
9 | * This software is distributed under the GNU Public License Version 2
10 | * See also the file 'COPYING'.
11 | *
12 | */
13 | #ifndef _INCLUDE_WEBHTTPD_H_
14 | #define _INCLUDE_WEBHTTPD_H_
15 |
16 | #include "motion.h"
17 |
18 | #define TWIKI_URL "http://www.lavrsen.dk/twiki/bin/view/Motion/MotionGuideAlphabeticalOptionReferenceManual"
19 |
20 | void * motion_web_control(void *arg);
21 | void httpd_run(struct context **);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/netcam_rtsp.h:
--------------------------------------------------------------------------------
1 | #include "netcam.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 |
9 | struct rtsp_context {
10 | AVFormatContext* format_context;
11 | AVCodecContext* codec_context;
12 | int video_stream_index;
13 | char* path;
14 | char* user;
15 | char* pass;
16 | };
17 |
18 | //int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url);
19 | struct rtsp_context *rtsp_new_context(void);
20 | void netcam_shutdown_rtsp(netcam_context_ptr netcam);
21 | int rtsp_connect(netcam_context_ptr netcam);
22 | int netcam_read_rtsp_image(netcam_context_ptr netcam);
23 |
--------------------------------------------------------------------------------
/picture.h:
--------------------------------------------------------------------------------
1 | /*
2 | * picture.h
3 | *
4 | * Copyright 2002 by Jeroen Vreeken (pe1rxq@amsat.org)
5 | * Portions of this file are Copyright by Lionnel Maugis
6 | * This software is distributed under the GNU public license version 2
7 | * See also the file 'COPYING'.
8 | *
9 | */
10 | #ifndef _INCLUDE_PICTURE_H_
11 | #define _INCLUDE_PICTURE_H_
12 |
13 | #include "motion.h"
14 |
15 | void overlay_smartmask(struct context *, unsigned char *);
16 | void overlay_fixed_mask(struct context *, unsigned char *);
17 | void put_fixed_mask(struct context *, const char *);
18 | void overlay_largest_label(struct context *, unsigned char *);
19 | void put_picture_fd(struct context *, FILE *, unsigned char *, int);
20 | int put_picture_memory(struct context *, unsigned char*, int, unsigned char *, int);
21 | void put_picture(struct context *, char *, unsigned char *, int);
22 | unsigned char *get_pgm(FILE *, int, int);
23 | void preview_save(struct context *);
24 |
25 | #endif /* _INCLUDE_PICTURE_H_ */
26 |
--------------------------------------------------------------------------------
/FAQ:
--------------------------------------------------------------------------------
1 | This FAQ is no longer kept up to date
2 | Look at this URL for a more up to date wiki based FAQ
3 | http://www.lavrsen.dk/twiki/bin/view/Motion/FrequentlyAskedQuestions
4 |
5 | Q: motion crashes while parsing the config file.
6 |
7 | A: Appearantly the behaviour of strtok in glibc has changed somewhat.
8 | This problem should be fixed as of 2.3
9 |
10 |
11 | Q: Were does motion look for the config file?
12 |
13 | A: First it will look for 'motion.conf' in the current directory, next it will
14 | try to find '.motion/motion.conf' in your home directory (pointed to by
15 | the HOME environment variable). If these don't exist it will try to open
16 | '/usr/local/etc/motion.conf' if you specified /usr/local as the prefix to
17 | configure (this is the default).
18 |
19 | Q: What codingstyle is used for motion?
20 |
21 | A: Motion follows the same style as the linux kernel.
22 | Read Documentation/Codingstyle in the kernel tree for some good reasons.
23 | Also be aware that motion is multithreaded and as such all functions should
24 | be reentrant, using static variables is usually a bad idea.
25 |
--------------------------------------------------------------------------------
/README.MacOSX:
--------------------------------------------------------------------------------
1 | The motion port to MacOSX is only working with network cameras.
2 |
3 | Tested in latest MacOSX
4 |
5 | Packages needed :
6 |
7 | * autoconf-2.57 or above.
8 | * make-3.79 or above.
9 | * This port has been made using some packages from Fink and DarwinPorts :
10 | o ffmpeg-0.4.8 from DarwinPorts ( but it needs to be patched with ffmpeg-0.4.8-macosx.patch ).
11 | o libjpeg-6b-16, libjpeg-shlibs-6b-16 from Fink
12 |
13 | How to Install
14 |
15 | * Get/Patch/Install ffmpeg
16 | o Download the ffmpeg from sourceforge ( the same version used in Darwinports ).
17 | o Get the patch-ffmpeg
18 |
19 | tar xfvz ffmpeg-0.4.8.tar.gz
20 | cd ffmpeg-0.4.8/
21 | patch -p1 < ../ffmpeg-0.4.8-macosx.patch
22 | ./configure --prefix=/path_to_install_ffmpeg ; make ; make install ; make installlib
23 | ldconfig
24 |
25 | To install motion follow the standard procedure :
26 |
27 | ./configure --with-ffmpeg=/path_where_you_installed_ffmpeg ; make ; make install
28 |
29 | Any question / fix / suggestion please send it to motion mailing list.
30 |
31 |
32 | Angel Carpintero
33 | ack@telefonica.net
34 |
--------------------------------------------------------------------------------
/event.h:
--------------------------------------------------------------------------------
1 | /*
2 | * event.h
3 | *
4 | * Include file for event.c
5 | *
6 | * Copyright Jeroen Vreeken, 2002
7 | * This software is distributed under the GNU Public License Version 2
8 | * see also the file 'COPYING'.
9 | *
10 | */
11 | #ifndef _INCLUDE_EVENT_H_
12 | #define _INCLUDE_EVENT_H_
13 |
14 | #define EVENT_FILECREATE 1
15 | #define EVENT_MOTION 2
16 | #define EVENT_FIRSTMOTION 3
17 | #define EVENT_ENDMOTION 4
18 | #define EVENT_STOP 5
19 | #define EVENT_TIMELAPSE 6
20 | #define EVENT_TIMELAPSEEND 7
21 | #define EVENT_STREAM 8
22 | #define EVENT_IMAGE_DETECTED 9
23 | #define EVENT_IMAGEM_DETECTED 10
24 | #define EVENT_IMAGE_SNAPSHOT 11
25 | #define EVENT_IMAGE 12
26 | #define EVENT_IMAGEM 13
27 | #define EVENT_FILECLOSE 14
28 | #define EVENT_DEBUG 15
29 | #define EVENT_CRITICAL 16
30 | #define EVENT_AREA_DETECTED 17
31 | #define EVENT_CAMERA_LOST 18
32 | #define EVENT_FFMPEG_PUT 19
33 | #define EVENT_SDL_PUT 20
34 |
35 |
36 | typedef void(* event_handler)(struct context *, int, unsigned char *, char *, void *, struct tm *);
37 |
38 | void event(struct context *, int, unsigned char *, char *, void *, struct tm *);
39 | const char * imageext(struct context *);
40 |
41 | #endif /* _INCLUDE_EVENT_H_ */
42 |
--------------------------------------------------------------------------------
/alg.h:
--------------------------------------------------------------------------------
1 | /* alg.h
2 | *
3 | * Detect changes in a video stream.
4 | * Copyright 2001 by Jeroen Vreeken (pe1rxq@amsat.org)
5 | * This software is distributed under the GNU public license version 2
6 | * See also the file 'COPYING'.
7 | *
8 | */
9 |
10 | #ifndef _INCLUDE_ALG_H
11 | #define _INCLUDE_ALG_H
12 |
13 | #include "motion.h"
14 |
15 | struct coord {
16 | int x;
17 | int y;
18 | int width;
19 | int height;
20 | int minx;
21 | int maxx;
22 | int miny;
23 | int maxy;
24 | };
25 |
26 | struct segment {
27 | struct coord coord;
28 | int width;
29 | int height;
30 | int open;
31 | int count;
32 | };
33 |
34 | void alg_locate_center_size(struct images *, int width, int height, struct coord *);
35 | void alg_draw_location(struct coord *, struct images *, int width, unsigned char *, int, int, int);
36 | void alg_draw_red_location(struct coord *, struct images *, int width, unsigned char *, int, int, int);
37 | int alg_diff(struct context *, unsigned char *);
38 | int alg_diff_standard(struct context *, unsigned char *);
39 | int alg_lightswitch(struct context *, int diffs);
40 | int alg_switchfilter(struct context *, int, unsigned char *);
41 | void alg_noise_tune(struct context *, unsigned char *);
42 | void alg_threshold_tune(struct context *, int, int);
43 | int alg_despeckle(struct context *, int);
44 | void alg_tune_smartmask(struct context *);
45 | void alg_update_reference_frame(struct context *, int);
46 |
47 | #endif /* _INCLUDE_ALG_H */
48 |
--------------------------------------------------------------------------------
/stream.h:
--------------------------------------------------------------------------------
1 | /*
2 | * stream.h
3 | *
4 | * Include file for stream.c
5 | * Copyright (C) 2002 Jeroen Vreeken (pe1rxq@amsat.org)
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 2 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program; if not, write to the Free Software
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 | */
21 | #ifndef _INCLUDE_STREAM_H_
22 | #define _INCLUDE_STREAM_H_
23 |
24 | struct stream_buffer {
25 | unsigned char *ptr;
26 | int ref;
27 | long size;
28 | };
29 |
30 | struct stream {
31 | int socket;
32 | FILE *fwrite;
33 | struct stream_buffer *tmpbuffer;
34 | long filepos;
35 | int nr;
36 | unsigned long int last;
37 | struct stream *prev;
38 | struct stream *next;
39 | };
40 |
41 | int stream_init(struct context *);
42 | void stream_put(struct context *, unsigned char *);
43 | void stream_stop(struct context *);
44 |
45 | #endif /* _INCLUDE_STREAM_H_ */
46 |
--------------------------------------------------------------------------------
/motion.init-Debian.in:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #
3 | # @PACKAGE_NAME@ @PACKAGE_VERSION@
4 | # Start the motion detection .
5 | #
6 |
7 | NAME=@PACKAGE_NAME@
8 | PATH=/bin:/usr/bin:/sbin:/usr/sbin
9 | DAEMON=@BIN_PATH@/@PACKAGE_NAME@
10 | PIDFILE=/var/run/@PACKAGE_NAME@/$NAME.pid
11 |
12 |
13 | trap "" 1
14 | export LANG=C
15 | export PATH
16 |
17 | test -f $DAEMON || exit 0
18 |
19 |
20 | case "$1" in
21 | start)
22 | echo "Starting @PACKAGE_NAME@ detection : $NAME"
23 | start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --chuid motion
24 | ;;
25 |
26 | stop)
27 | echo "Stopping @PACKAGE_NAME@ detection : $NAME"
28 | start-stop-daemon --stop --pidfile $PIDFILE --oknodo --exec $DAEMON --retry 30
29 | ;;
30 |
31 | status)
32 | echo "Status @PACKAGE_NAME@ detection : $NAME"
33 | if (test -f $PIDFILE); then
34 | echo -n "Running process for $NAME : "
35 | pidof $NAME
36 | else
37 | echo "Stopped"
38 | fi
39 | ;;
40 |
41 | reload-config)
42 | echo "Reloading $NAME configuration"
43 | start-stop-daemon --stop --pidfile $PIDFILE --signal HUP --exec $DAEMON
44 | ;;
45 |
46 | restart-motion)
47 | echo "Restarting $NAME"
48 | start-stop-daemon --stop --pidfile $PIDFILE --oknodo --exec $DAEMON --retry 30
49 | start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --chuid motion
50 | ;;
51 |
52 | restart)
53 | $0 restart-motion
54 | exit $?
55 | ;;
56 |
57 | *)
58 | echo "Usage: /etc/init.d/$NAME {start|stop|status|reload-config|restart}"
59 | exit 1
60 | ;;
61 | esac
62 |
63 | if [ $? == 0 ]; then
64 | echo .
65 | exit 0
66 | else
67 | echo failed
68 | exit 1
69 | fi
70 |
--------------------------------------------------------------------------------
/netcam_ftp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Much of the FTP routines was inspired by the nanoftp.c module from
3 | * libxml2 (Copyright Daniel Veillard, 2003). The routines have been
4 | * modified to fit the needs of the Motion project.
5 | *
6 | * Copyright 2005, William M. Brack
7 | * This software is distributed under the GNU Public license Version 2.
8 | * See also the file 'COPYING'.
9 | *
10 | */
11 | #ifndef _INCLUDE_NETCAM_FTP_H
12 | #define _INCLUDE_NETCAM_FTP_H
13 |
14 | #define FTP_BUF_SIZE 1024
15 |
16 | typedef struct ftp_context {
17 | char *path; /* the path within the URL */
18 | char *user; /* user string */
19 | char *passwd; /* passwd string */
20 | struct sockaddr_in ftp_address; /* the socket addr structure */
21 | int passive; /* flag show passive/active mode used */
22 | int control_file_desc; /* file descriptor for the control socket */
23 | int data_file_desc; /* file descriptor for the data socket */
24 | int state; /* WRITE / READ / CLOSED */
25 | int returnValue; /* the protocol return value */
26 |
27 | /* buffer for data received from the control connection */
28 | char control_buffer[FTP_BUF_SIZE + 1];
29 | int control_buffer_index;
30 | int control_buffer_used;
31 | int control_buffer_answer;
32 | } ftp_context, *ftp_context_pointer;
33 |
34 | /* The public interface */
35 | ftp_context_pointer ftp_new_context(void);
36 | void ftp_free_context(ftp_context_pointer);
37 | ftp_context_pointer ftpOpen(const char *);
38 | int ftp_connect(netcam_context_ptr);
39 | int ftp_send_type(ftp_context_pointer, const char);
40 | int ftp_get_socket(ftp_context_pointer);
41 | int ftp_read(ftp_context_pointer, void *, int);
42 | int ftp_close(ftp_context_pointer);
43 | #endif
44 |
--------------------------------------------------------------------------------
/rotate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * rotate.h
3 | *
4 | * Include file for handling image rotation.
5 | *
6 | * Copyright 2004-2005, Per Jonsson (per@pjd.nu)
7 | *
8 | * This software is distributed under the GNU Public license
9 | * Version 2. See also the file 'COPYING'.
10 | */
11 | #ifndef _INCLUDE_ROTATE_H
12 | #define _INCLUDE_ROTATE_H
13 |
14 | #include "motion.h" /* for struct context */
15 |
16 | /**
17 | * rotate_init
18 | *
19 | * Sets up rotation data by allocating a temporary buffer for 90/270 degrees
20 | * rotation, and by determining the right rotate-180-degrees function.
21 | *
22 | * Parameters:
23 | *
24 | * cnt - current thread's context structure
25 | *
26 | * Returns: nothing
27 | */
28 | void rotate_init(struct context *cnt);
29 |
30 | /**
31 | * rotate_deinit
32 | *
33 | * Frees memory allocated by rotate_init.
34 | *
35 | * Parameters:
36 | *
37 | * cnt - current thread's context structure
38 | */
39 | void rotate_deinit(struct context *cnt);
40 |
41 | /**
42 | * rotate_map
43 | *
44 | * Rotates the image stored in map according to the rotation data
45 | * available in cnt. Rotation is performed clockwise. Supports 90,
46 | * 180 and 270 degrees rotation. 180 degrees rotation is performed
47 | * in-place by simply reversing the image data, which is a very
48 | * fast operation. 90 and 270 degrees rotation are performed using
49 | * a temporary buffer and a somewhat more complicated algorithm,
50 | * which makes them slower.
51 | *
52 | * Note that to the caller, all rotations will seem as they are
53 | * performed in-place.
54 | *
55 | * Parameters:
56 | *
57 | * map - the image map/data to rotate
58 | * cnt - current thread's context structure
59 | *
60 | * Returns:
61 | *
62 | * 0 - success
63 | * -1 - failure (rare, shouldn't happen)
64 | */
65 | int rotate_map(struct context *cnt, unsigned char *map);
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/ffmpeg-0.4.8-macosx.patch:
--------------------------------------------------------------------------------
1 | diff -Naupr ffmpeg-0.4.8/configure ffmpeg-0.4.8-macosx/configure
2 | --- ffmpeg-0.4.8/configure 2003-09-28 08:26:39.000000000 -0700
3 | +++ ffmpeg-0.4.8-macosx/configure 2005-10-06 15:49:33.000000000 -0700
4 | @@ -84,7 +84,7 @@ debug="yes"
5 | extralibs="-lm"
6 | simpleidct="yes"
7 | bigendian="no"
8 | -vhook="default"
9 | +vhook="no"
10 | dlfcn="no"
11 | dlopen="no"
12 | mpegaudio_hp="yes"
13 | @@ -163,6 +163,7 @@ extralibs="-lpoll -lgnugetopt -lm"
14 | make="gmake"
15 | ;;
16 | Darwin)
17 | +SLIBSUF=".dylib"
18 | cc="cc"
19 | v4l="no"
20 | audio_oss="no"
21 | @@ -177,13 +178,13 @@ FFSLDFLAGS=-Wl,-bind_at_load
22 | gcc_version="$($cc -v 2>&1 | grep version | cut -d ' ' -f3-)"
23 | case "$gcc_version" in
24 | *2.95*)
25 | -CFLAGS="-no-cpp-precomp -pipe -fomit-frame-pointer"
26 | +CFLAGS="$CFLAGS -no-cpp-precomp -pipe -fomit-frame-pointer"
27 | ;;
28 | *3.3*)
29 | -CFLAGS="-no-cpp-precomp -pipe -fomit-frame-pointer -mdynamic-no-pic -force_cpusubtype_ALL"
30 | +CFLAGS="$CFLAGS -no-cpp-precomp -pipe -fomit-frame-pointer -mdynamic-no-pic -force_cpusubtype_ALL"
31 | ;;
32 | *)
33 | -CFLAGS="-no-cpp-precomp -pipe -fomit-frame-pointer -mdynamic-no-pic"
34 | +CFLAGS="$CFLAGS -no-cpp-precomp -pipe -fomit-frame-pointer -mdynamic-no-pic"
35 | ;;
36 | esac
37 | ;;
38 | diff -Naupr ffmpeg-0.4.8/libavcodec/Makefile ffmpeg-0.4.8-macosx/libavcodec/Makefile
39 | --- ffmpeg-0.4.8/libavcodec/Makefile 2003-09-28 08:26:39.000000000 -0700
40 | +++ ffmpeg-0.4.8-macosx/libavcodec/Makefile 2005-10-06 17:22:21.000000000 -0700
41 | @@ -239,6 +239,8 @@ install:
42 | endif
43 |
44 | installlib: all install-headers
45 | + ranlib $(LIB)
46 | + install -d $(prefix)/lib
47 | install -m 644 $(LIB) $(prefix)/lib
48 |
49 | install-headers:
50 | diff -Naupr ffmpeg-0.4.8/libavformat/Makefile ffmpeg-0.4.8-macosx/libavformat/Makefile
51 | --- ffmpeg-0.4.8/libavformat/Makefile 2003-09-28 08:26:40.000000000 -0700
52 | +++ ffmpeg-0.4.8-macosx/libavformat/Makefile 2005-10-06 15:42:53.000000000 -0700
53 | @@ -102,6 +102,7 @@ install:
54 | endif
55 |
56 | installlib: all install-headers
57 | + ranlib $(LIB)
58 | install -m 644 $(LIB) $(prefix)/lib
59 |
60 | install-headers:
61 |
--------------------------------------------------------------------------------
/thread1.conf.in:
--------------------------------------------------------------------------------
1 | # /usr/local/etc/thread1.conf
2 | #
3 | # This config file was generated by @PACKAGE_NAME@ @PACKAGE_VERSION@
4 |
5 |
6 |
7 | ###########################################################
8 | # Capture device options
9 | ############################################################
10 |
11 | # Videodevice to be used for capturing (default /dev/video0)
12 | # for FreeBSD default is /dev/bktr0
13 | videodevice /dev/video0
14 |
15 | # The video input to be used (default: -1)
16 | # Should normally be set to 1 for video/TV cards, and -1 for USB cameras
17 | input -1
18 |
19 | # Draw a user defined text on the images using same options as C function strftime(3)
20 | # Default: Not defined = no text
21 | # Text is placed in lower left corner
22 | text_left CAMERA 1
23 |
24 |
25 | ############################################################
26 | # Target Directories and filenames For Images And Films
27 | # For the options snapshot_, picture_, mpeg_ and timelapse_filename
28 | # you can use conversion specifiers
29 | # %Y = year, %m = month, %d = date,
30 | # %H = hour, %M = minute, %S = second,
31 | # %v = event, %q = frame number, %t = thread (camera) number,
32 | # %D = changed pixels, %N = noise level,
33 | # %i and %J = width and height of motion area,
34 | # %K and %L = X and Y coordinates of motion center
35 | # %C = value defined by text_event
36 | # Quotation marks round string are allowed.
37 | ############################################################
38 |
39 | # Target base directory for pictures and films
40 | # Recommended to use absolute patch. (Default: current working directory)
41 | target_dir /usr/local/apache2/htdocs/cam1
42 |
43 |
44 | ############################################################
45 | # Live Stream Server
46 | ############################################################
47 |
48 | # The mini-http server listens to this port for requests (default: 0 = disabled)
49 | stream_port 8081
50 |
51 | # Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
52 | # The filename of the picture is appended as an argument for the command.
53 | on_picture_save /usr/local/motion-extras/camparse1.pl
54 |
55 | # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
56 | # Filename of movie is appended as an argument for the command.
57 | on_movie_end /usr/local/motion-extras/mpegparse1.pl
58 |
--------------------------------------------------------------------------------
/thread2.conf.in:
--------------------------------------------------------------------------------
1 | # /usr/local/etc/thread2.conf
2 | #
3 | # This config file was generated by @PACKAGE_NAME@ @PACKAGE_VERSION@
4 |
5 |
6 |
7 | ###########################################################
8 | # Capture device options
9 | ############################################################
10 |
11 | # Videodevice to be used for capturing (default /dev/video0)
12 | # for FreeBSD default is /dev/bktr0
13 | videodevice /dev/video1
14 |
15 | # The video input to be used (default: -1)
16 | # Should normally be set to 1 for video/TV cards, and -1 for USB cameras
17 | input 1
18 |
19 | # Draw a user defined text on the images using same options as C function strftime(3)
20 | # Default: Not defined = no text
21 | # Text is placed in lower left corner
22 | text_left CAMERA 2
23 |
24 |
25 | ############################################################
26 | # Target Directories and filenames For Images And Films
27 | # For the options snapshot_, picture_, mpeg_ and timelapse_filename
28 | # you can use conversion specifiers
29 | # %Y = year, %m = month, %d = date,
30 | # %H = hour, %M = minute, %S = second,
31 | # %v = event, %q = frame number, %t = thread (camera) number,
32 | # %D = changed pixels, %N = noise level,
33 | # %i and %J = width and height of motion area,
34 | # %K and %L = X and Y coordinates of motion center
35 | # %C = value defined by text_event
36 | # Quotation marks round string are allowed.
37 | ############################################################
38 |
39 | # Target base directory for pictures and films
40 | # Recommended to use absolute patch. (Default: current working directory)
41 | target_dir /usr/local/apache2/htdocs/cam2
42 |
43 |
44 | ############################################################
45 | # Live Stream Server
46 | ############################################################
47 |
48 | # The mini-http server listens to this port for requests (default: 0 = disabled)
49 | stream_port 8082
50 |
51 | # Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
52 | # The filename of the picture is appended as an argument for the command.
53 | on_picture_save /usr/local/motion-extras/camparse2.pl
54 |
55 | # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
56 | # Filename of movie is appended as an argument for the command.
57 | on_movie_end /usr/local/motion-extras/mpegparse2.pl
58 |
59 |
--------------------------------------------------------------------------------
/thread3.conf.in:
--------------------------------------------------------------------------------
1 | # /usr/local/etc/thread3.conf
2 | #
3 | # This config file was generated by @PACKAGE_NAME@ @PACKAGE_VERSION@
4 |
5 |
6 |
7 | ###########################################################
8 | # Capture device options
9 | ############################################################
10 |
11 | # Videodevice to be used for capturing (default /dev/video0)
12 | # for FreeBSD default is /dev/bktr0
13 | videodevice /dev/video2
14 |
15 | # The video input to be used (default: -1)
16 | # Should normally be set to 1 for video/TV cards, and -1 for USB cameras
17 | input -1
18 |
19 | # Draw a user defined text on the images using same options as C function strftime(3)
20 | # Default: Not defined = no text
21 | # Text is placed in lower left corner
22 | text_left CAMERA 3
23 |
24 |
25 | ############################################################
26 | # Target Directories and filenames For Images And Films
27 | # For the options snapshot_, picture_, mpeg_ and timelapse_filename
28 | # you can use conversion specifiers
29 | # %Y = year, %m = month, %d = date,
30 | # %H = hour, %M = minute, %S = second,
31 | # %v = event, %q = frame number, %t = thread (camera) number,
32 | # %D = changed pixels, %N = noise level,
33 | # %i and %J = width and height of motion area,
34 | # %K and %L = X and Y coordinates of motion center
35 | # %C = value defined by text_event
36 | # Quotation marks round string are allowed.
37 | ############################################################
38 |
39 | # Target base directory for pictures and films
40 | # Recommended to use absolute patch. (Default: current working directory)
41 | target_dir /usr/local/apache2/htdocs/cam3
42 |
43 |
44 | ############################################################
45 | # Live Stream Server
46 | ############################################################
47 |
48 | # The mini-http server listens to this port for requests (default: 0 = disabled)
49 | stream_port 8083
50 |
51 | # Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
52 | # The filename of the picture is appended as an argument for the command.
53 | on_picture_save /usr/local/motion-extras/camparse3.pl
54 |
55 | # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
56 | # Filename of movie is appended as an argument for the command.
57 | on_movie_end /usr/local/motion-extras/mpegparse3.pl
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/README.FreeBSD:
--------------------------------------------------------------------------------
1 | The motion port to *BSD is still in very beta state, but
2 | has been tested with network cameras support successfully.
3 | This version has been tested with TV Card ( Miro PCTV pro ),
4 | but should work by any framegrabber supported by bktr driver.
5 |
6 | * How configure your capture card *
7 |
8 | 1-. Load the bktr modules
9 | type as root :
10 |
11 | kldload bktr_mem.ko
12 | kldload bktr.ko
13 |
14 | You can setup this in your /boot/loader.conf adding :
15 |
16 | bktr_mem_load="YES"
17 | bktr_load="YES"
18 |
19 | 2-. Configure your card settings ( tuner type , format and card ).
20 |
21 | Type as root :
22 |
23 | sysctl hw.bt848.card=1 ( Miro pctv )
24 | sysctl hw.bt848.tuner=10 ( PHILIPS_FR1216_PAL )
25 | sysctl hw.bt848.format=0 ( PAL )
26 |
27 | or add to /etc/sysctl.conf adding :
28 |
29 | hw.bt848.card=1
30 | hw.bt848.tuner=10
31 | hw.bt848.format=0
32 |
33 | * To compile motion in FreeBSD ( should work in OpenBSD and NetBSD ) :
34 |
35 | autoconf
36 | ./configure
37 | of
38 | CC=gcc34 ./configure ( to override the default gcc version)
39 | gmake
40 | gmake install
41 |
42 | ( ./configure --without-bktr , to work only with network cameras ).
43 |
44 | Tested in FreeBSD 4.9/4.1x/5.x/6.x .
45 |
46 | Packages needed (dependencies for 6.x):
47 |
48 | - autoconf-2.59_2
49 | - gcc-3.4.6_20051206
50 | - m4-1.4.4
51 | - linuxthreads-2.2.3_19 only if you don't want native freebsd pthread
52 | - jpeg-6b_4 or above
53 | - gmake-3.80_2 ( GNU Make )
54 | - ffmpeg-0.4.9.p1_6 ( mpeg1/4 video encoders ).
55 | - mysql-server , mysql-client ( database backend support ).
56 | - postgresql-devel , postgresql ( database backend support ).
57 |
58 | - kernel with bktr support ( GENERIC kernel has by default support ).
59 |
60 |
61 | * webcams pwc based
62 |
63 | - pwcbsd-1.4.1_1 ( with mmap support )
64 | - v4l_compat-1.0.20060801
65 |
66 | run : ./configure --with-pwcbsd ; gmake ; gmake install
67 |
68 |
69 | * TODO *
70 | --------
71 |
72 | - Improve the capture method ( double buffer , async capture ).
73 | - Detect pixelformat , palettes format , etc ...
74 | - Implement tuner capture ( now only video / svideo capture implemented ).
75 | - Code clean up.
76 | - And many others ...
77 |
78 | Any question / fix / suggestion please send it to motion mailing list.
79 |
80 |
81 | http://www.lavrsen.dk/twiki/bin/view/Motion/FreeBSD
82 |
83 | * WEBCAMS
84 | ----------
85 | http://www.lavrsen.dk/twiki/bin/view/Motion/HowtoMotionPwcFreeBSD
86 |
87 | Angel Carpintero
88 | ack@telefonica.net
89 |
--------------------------------------------------------------------------------
/md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * MD5.H - header file for MD5C.C
3 | * taken from RFC 1321
4 | */
5 |
6 | #ifndef MD5_H
7 | #define MD5_H
8 |
9 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
10 | rights reserved.
11 |
12 | License to copy and use this software is granted provided that it
13 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest
14 | Algorithm" in all material mentioning or referencing this software
15 | or this function.
16 |
17 | License is also granted to make and use derivative works provided
18 | that such works are identified as "derived from the RSA Data
19 | Security, Inc. MD5 Message-Digest Algorithm" in all material
20 | mentioning or referencing the derived work.
21 |
22 | RSA Data Security, Inc. makes no representations concerning either
23 | the merchantability of this software or the suitability of this
24 | software for any particular purpose. It is provided "as is"
25 | without express or implied warranty of any kind.
26 |
27 | These notices must be retained in any copies of any part of this
28 | documentation and/or software.
29 | */
30 |
31 | /* GLOBAL.H - RSAREF types and constants
32 | */
33 |
34 | /*
35 | * PROTOTYPES should be set to one if and only if the compiler supports
36 | * function argument prototyping.
37 | * The following makes PROTOTYPES default to 0 if it has not already
38 | * been defined with C compiler flags.
39 | */
40 |
41 | #ifndef PROTOTYPES
42 | #define PROTOTYPES 0
43 | #endif
44 |
45 | /* POINTER defines a generic pointer type */
46 | typedef unsigned char *POINTER;
47 |
48 | /* UINT2 defines a two byte word */
49 | typedef unsigned short int UINT2;
50 |
51 | /* UINT4 defines a four byte word */
52 | typedef unsigned int UINT4;
53 |
54 | /*
55 | * PROTO_LIST is defined depending on how PROTOTYPES is defined above.
56 | * If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
57 | * returns an empty list.
58 | */
59 | #if PROTOTYPES
60 | #define PROTO_LIST(list) list
61 | #else
62 | #define PROTO_LIST(list) ()
63 | #endif
64 |
65 | /* MD5 context. */
66 | typedef struct {
67 | UINT4 state[4]; /* state (ABCD) */
68 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
69 | unsigned char buffer[64]; /* input buffer */
70 | } MD5_CTX;
71 |
72 | void MD5Init(MD5_CTX *);
73 | void MD5Update(MD5_CTX *, unsigned char *, unsigned int);
74 | void MD5Final(unsigned char [16], MD5_CTX *);
75 | void MD5(unsigned char *message, unsigned long message_length, unsigned char *md);
76 |
77 | #endif // MD5_H
78 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Motion up to version 3.1.8 was created and maintained by Jeroen Vreeken.
2 | Versions 3.1.9-3.1.12 was maintained by Kenneth Lavrsen (http://www.lavrsen.dk/)
3 | and Folkert van Heusden (http://www.vanheusden.com/).
4 |
5 | From 3.1.12 Motion is project managed by Kenneth Lavrsen and maintained by
6 | a large number of people.
7 |
8 | See the file CREDITS for the list of people having made contributions to the
9 | Motion code.
10 |
11 | Copyright 2000-2005 by Jeroen Vreeken/Folkert Van Heusden/Kenneth Lavrsen
12 | and the contributors mentioned in the file CREDITS.
13 |
14 | The source file netcam_wget.c and netcam_wget.h contains code reused from
15 | GNU Wget. It has been merged and modified for use in the program Motion which
16 | is also released under the terms of the GNU General Public License.
17 | Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002
18 | Free Software Foundation, Inc.
19 | The code contains additional modifications
20 | Additional Copyright (C) 2004-2005 Christopher Price,
21 | Angel Carpintero, and other contributing authors.
22 |
23 | GNU Wget and Motion is free software; you can redistribute it and/or
24 | modify it under the terms of the GNU General Public License as published
25 | by the Free Software Foundation; either version 2 of the License, or
26 | (at your option) any later version.
27 |
28 | GNU Wget and Motion is distributed in the hope that it will be useful,
29 | but WITHOUT ANY WARRANTY; without even the implied warranty of
30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 | GNU General Public License for more details.
32 |
33 | You should have received a copy of the GNU General Public License
34 | along with Wget; if not, write to the Free Software
35 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
36 |
37 |
38 | Installing:
39 |
40 | Read the motion.1 manpage for more info
41 |
42 | And most of all read the Motion Guide for very detailed description of both
43 | installation and use.
44 | The Motion Guide is part of the distribution (motion_guide.htm).
45 | You are encouraged to look up an up to date version by visiting the Motion
46 | homepage at
47 | http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome
48 | and specifically the Motion Guide at
49 | http://www.lavrsen.dk/twiki/bin/view/Motion/MotionGuide
50 |
51 |
52 | Support:
53 |
54 | Lots of resources at http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome
55 |
56 | Please join the mailing list
57 | http://www.lavrsen.dk/twiki/bin/view/Motion/MailingList
58 | Newbies and silly questions are welcome. We prefer support through the mailing
59 | list because more will have benefit from the answers.
60 |
61 |
62 | Jeroen Vreeken
63 | pe1rxq@amsat.org
64 |
65 | Kenneth Lavrsen
66 | kenneth@lavrsen.dk
67 |
--------------------------------------------------------------------------------
/thread4.conf.in:
--------------------------------------------------------------------------------
1 | # /usr/local/etc/thread4.conf
2 | #
3 | # This config file was generated by @PACKAGE_NAME@ @PACKAGE_VERSION@
4 |
5 | ###########################################################
6 | # Capture device options
7 | ############################################################
8 |
9 | # URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// or file:///)
10 | # Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined
11 | netcam_url http://192.168.1.6:8093/
12 |
13 | # The setting for keep-alive of network socket, should improve performance on compatible net cameras.
14 | # off: The historical implementation using HTTP/1.0, closing the socket after each http request.
15 | # force: Use HTTP/1.0 requests with keep alive header to reuse the same connection.
16 | # on: Use HTTP/1.1 requests that support keep alive as default.
17 | # Default: off
18 | netcam_keepalive force
19 |
20 | # Set less strict jpeg checks for network cameras with a poor/buggy firmware.
21 | # Default: off
22 | netcam_tolerant_check on
23 |
24 | # Draw a user defined text on the images using same options as C function strftime(3)
25 | # Default: Not defined = no text
26 | # Text is placed in lower left corner
27 | text_left CAMERA 4
28 |
29 | ############################################################
30 | # Target Directories and filenames For Images And Films
31 | # For the options snapshot_, picture_, mpeg_ and timelapse_filename
32 | # you can use conversion specifiers
33 | # %Y = year, %m = month, %d = date,
34 | # %H = hour, %M = minute, %S = second,
35 | # %v = event, %q = frame number, %t = thread (camera) number,
36 | # %D = changed pixels, %N = noise level,
37 | # %i and %J = width and height of motion area,
38 | # %K and %L = X and Y coordinates of motion center
39 | # %C = value defined by text_event
40 | # Quotation marks round string are allowed.
41 | ############################################################
42 |
43 | # Target base directory for pictures and films
44 | # Recommended to use absolute patch. (Default: current working directory)
45 | target_dir /usr/local/apache2/htdocs/cam4
46 |
47 |
48 | ############################################################
49 | # Live Stream Server
50 | ############################################################
51 |
52 | # The mini-http server listens to this port for requests (default: 0 = disabled)
53 | stream_port 8084
54 |
55 | # Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
56 | # The filename of the picture is appended as an argument for the command.
57 | on_picture_save /usr/local/motion-extras/camparse4.pl
58 |
59 | # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
60 | # Filename of movie is appended as an argument for the command.
61 | on_movie_end /usr/local/motion-extras/mpegparse4.pl
62 |
63 |
--------------------------------------------------------------------------------
/ffmpeg.h:
--------------------------------------------------------------------------------
1 | #ifndef _INCLUDE_FFMPEG_H_
2 | #define _INCLUDE_FFMPEG_H_
3 |
4 | #ifdef HAVE_FFMPEG
5 | #include
6 |
7 | #ifdef FFMPEG_NEW_INCLUDES
8 | #include
9 | #else
10 | #include
11 | #endif
12 |
13 | #ifndef AVERROR /* 0.4.8 & 0.4.9-pre1 */
14 |
15 | #if EINVAL > 0
16 | #define AVERROR(e) (-(e))
17 | #define AVUNERROR(e) (-(e))
18 | #else
19 | /* Some platforms have E* and errno already negated. */
20 | #define AVERROR(e) (e)
21 | #define AVUNERROR(e) (e)
22 | #endif
23 |
24 | #endif /* AVERROR */
25 |
26 | #endif /* HAVE_FFMPEG */
27 |
28 |
29 | #include
30 | #include
31 |
32 | /*
33 | * Define a codec name/identifier for timelapse videos, so that we can
34 | * differentiate between normal mpeg1 videos and timelapse videos.
35 | */
36 | #define TIMELAPSE_CODEC "mpeg1_tl"
37 |
38 | struct ffmpeg {
39 | #ifdef HAVE_FFMPEG
40 | AVFormatContext *oc;
41 | AVStream *video_st;
42 | AVCodecContext *c;
43 |
44 | AVFrame *picture; /* contains default image pointers */
45 | uint8_t *video_outbuf;
46 | int video_outbuf_size;
47 |
48 | void *udata; /* U & V planes for greyscale images */
49 | int vbr; /* variable bitrate setting */
50 | char codec[20]; /* codec name */
51 | #else
52 | int dummy;
53 | #endif
54 | };
55 |
56 | /* Initialize FFmpeg stuff. Needs to be called before ffmpeg_open. */
57 | void ffmpeg_init(void);
58 |
59 | /*
60 | * Open an mpeg file. This is a generic interface for opening either an mpeg1 or
61 | * an mpeg4 video. If non-standard mpeg1 isn't supported (FFmpeg build > 4680),
62 | * calling this function with "mpeg1" as codec results in an error. To create a
63 | * timelapse video, use TIMELAPSE_CODEC as codec name.
64 | */
65 | struct ffmpeg *ffmpeg_open(
66 | char *ffmpeg_video_codec,
67 | char *filename,
68 | unsigned char *y, /* YUV420 Y plane */
69 | unsigned char *u, /* YUV420 U plane */
70 | unsigned char *v, /* YUV420 V plane */
71 | int width,
72 | int height,
73 | int rate, /* framerate, fps */
74 | int bps, /* bitrate; bits per second */
75 | int vbr /* variable bitrate */
76 | );
77 |
78 | /* Puts the image pointed to by the picture member of struct ffmpeg. */
79 | int ffmpeg_put_image(struct ffmpeg *);
80 |
81 | /* Puts the image defined by u, y and v (YUV420 format). */
82 | int ffmpeg_put_other_image(
83 | struct ffmpeg *ffmpeg,
84 | unsigned char *y,
85 | unsigned char *u,
86 | unsigned char *v
87 | );
88 |
89 | /* Closes the mpeg file. */
90 | void ffmpeg_close(struct ffmpeg *);
91 |
92 | /* Deinterlace the image. */
93 | void ffmpeg_deinterlace(unsigned char *, int, int);
94 |
95 | /* Setup an avcodec log handler. */
96 | void ffmpeg_avcodec_log(void *, int, const char *, va_list);
97 |
98 | #endif /* _INCLUDE_FFMPEG_H_ */
99 |
--------------------------------------------------------------------------------
/logger.h:
--------------------------------------------------------------------------------
1 | /*
2 | * logger.h
3 | *
4 | * Include file for logger.c
5 | *
6 | * Copyright 2005, William M. Brack
7 | * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com)
8 | * This software is distributed under the GNU Public License Version 2
9 | * See also the file 'COPYING'.
10 | *
11 | */
12 | #ifndef _INCLUDE_LOGGER_H_
13 | #define _INCLUDE_LOGGER_H_
14 |
15 | #include "motion.h"
16 | #include
17 |
18 | /* Logging mode */
19 | #define LOGMODE_FILE 0 /* Log messages to file */
20 | #define LOGMODE_SYSLOG 1 /* Log messages to syslog */
21 |
22 | #define NO_ERRNO 0 /* Flag to avoid how message associated to errno */
23 | #define SHOW_ERRNO 1 /* Flag to show message associated to errno */
24 |
25 | /* Log levels */
26 | #define LOG_ALL 9
27 | #define EMG LOG_EMERG /* syslog 0 motion 1 */
28 | #define ALR LOG_ALERT /* syslog 1 motion 2 */
29 | #define CRT LOG_CRIT /* syslog 2 motion 3 */
30 | #define ERR LOG_ERR /* syslog 3 motion 4 */
31 | #define WRN LOG_WARNING /* syslog 4 motion 5 */
32 | #define NTC LOG_NOTICE /* syslog 5 motion 6 */
33 | #define INF LOG_INFO /* syslog 6 motion 7 */
34 | #define DBG LOG_DEBUG /* syslog 7 motion 8 */
35 | #define ALL LOG_ALL /* syslog 8 motion 9 */
36 | #define LEVEL_DEFAULT NTC /* syslog 5 motion 6 default */
37 | #define SHOW_LEVEL_VALUE(x) (x+1)
38 |
39 | /* Log types */
40 | #define TYPE_CORE 1 /* Core logs */
41 | #define TYPE_STREAM 2 /* Stream logs */
42 | #define TYPE_ENCODER 3 /* Encoder logs */
43 | #define TYPE_NETCAM 4 /* Netcam logs */
44 | #define TYPE_DB 5 /* Database logs */
45 | #define TYPE_EVENTS 6 /* Events logs */
46 | #define TYPE_TRACK 7 /* Track logs */
47 | #define TYPE_VIDEO 8 /* V4L1/2 Bktr logs */
48 | #define TYPE_ALL 9 /* All type logs */
49 | #define TYPE_DEFAULT TYPE_ALL /* Default type */
50 | #define TYPE_DEFAULT_STR "ALL" /* Default name logs */
51 |
52 | #define MOTION_LOG(x, y, z, format, args...) motion_log(x, y, z, format, __FUNCTION__, ##args)
53 |
54 | int get_log_type(const char* type);
55 | const char* get_log_type_str(unsigned int type);
56 | void set_log_type(unsigned int type);
57 | const char* get_log_level_str(unsigned int level);
58 | void set_log_level(unsigned int level);
59 | void set_log_mode(int mode);
60 | FILE * set_logfile(const char *logfile_name);
61 | void motion_log(int, unsigned int, int, const char *, ...);
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/jpegutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jpegutils.h: Some Utility programs for dealing with
3 | * JPEG encoded images
4 | *
5 | * Copyright (C) 1999 Rainer Johanni
6 | * Copyright (C) 2001 pHilipp Zabel
7 | * Copyright (C) 2008 Angel Carpintero
8 | *
9 | */
10 |
11 | #ifndef __JPEGUTILS_H__
12 | #define __JPEGUTILS_H__
13 |
14 | /*
15 | * jpeg_data: buffer with input / output jpeg
16 | * len: Length of jpeg buffer
17 | * itype: Y4M_ILACE_NONE: Not interlaced
18 | * Y4M_ILACE_TOP_FIRST: Interlaced, top-field-first
19 | * Y4M_ILACE_BOTTOM_FIRST: Interlaced, bottom-field-first
20 | * ctype Chroma format for decompression.
21 | * Currently always 420 and hence ignored.
22 | * raw0 buffer with input / output raw Y channel
23 | * raw1 buffer with input / output raw U/Cb channel
24 | * raw2 buffer with input / output raw V/Cr channel
25 | * width width of Y channel (width of U/V is width/2)
26 | * height height of Y channel (height of U/V is height/2)
27 | */
28 |
29 |
30 | #define Y4M_ILACE_NONE 0 /* non-interlaced, progressive frame */
31 | #define Y4M_ILACE_TOP_FIRST 1 /* interlaced, top-field first */
32 | #define Y4M_ILACE_BOTTOM_FIRST 2 /* interlaced, bottom-field first */
33 | #define Y4M_ILACE_MIXED 3 /* mixed, "refer to frame header" */
34 |
35 | #define Y4M_CHROMA_420JPEG 0 /* 4:2:0, H/V centered, for JPEG/MPEG-1 */
36 | #define Y4M_CHROMA_420MPEG2 1 /* 4:2:0, H cosited, for MPEG-2 */
37 | #define Y4M_CHROMA_420PALDV 2 /* 4:2:0, alternating Cb/Cr, for PAL-DV */
38 | #define Y4M_CHROMA_444 3 /* 4:4:4, no subsampling, phew. */
39 | #define Y4M_CHROMA_422 4 /* 4:2:2, H cosited */
40 | #define Y4M_CHROMA_411 5 /* 4:1:1, H cosited */
41 | #define Y4M_CHROMA_MONO 6 /* luma plane only */
42 | #define Y4M_CHROMA_444ALPHA 7 /* 4:4:4 with an alpha channel */
43 |
44 |
45 |
46 | int decode_jpeg_raw(unsigned char *jpeg_data, int len,
47 | int itype, int ctype, unsigned int width,
48 | unsigned int height, unsigned char *raw0,
49 | unsigned char *raw1, unsigned char *raw2);
50 |
51 | int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len,
52 | int itype, int ctype, unsigned int width,
53 | unsigned int height, unsigned char *raw0,
54 | unsigned char *raw1, unsigned char *raw2);
55 |
56 | int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality,
57 | int itype, int ctype, unsigned int width,
58 | unsigned int height, unsigned char *raw0,
59 | unsigned char *raw1, unsigned char *raw2);
60 | #endif
61 |
--------------------------------------------------------------------------------
/motion.init-Fedora.in:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # motion Startup script for the Motion Detection System
4 | #
5 | # chkconfig: - 85 15
6 | # description: Motion detection system. It is used to detect movement based \
7 | # on compare images.
8 | # processname: @PACKAGE_NAME@
9 | # pidfile: /var/run/@PACKAGE_NAME@.pid
10 | # config: /etc/@PACKAGE_NAME@.conf
11 | #
12 | ### BEGIN INIT INFO
13 | # Provides: motion
14 | # Required-Start: $local_fs
15 | # Required-Stop: $local_fs
16 | # Default-Start:
17 | # Default-Stop:
18 | # Short-Description: Start and stop motion detection system
19 | # Description: The Motion detection system is used to detect movement based
20 | # on image comparison.
21 | ### END INIT INFO
22 |
23 | # Source function library.
24 | . /etc/rc.d/init.d/functions
25 |
26 | motion=${MOTION-/usr/bin/motion}
27 | prog=motion
28 | pidfile=/var/run/motion.pid
29 | lockfile=/var/lock/subsys/motion
30 |
31 | start() {
32 | [ -x $exec ] || exit 5
33 | [ -f $config ] || exit 6
34 | echo -n $"Starting $prog: "
35 | # We try to determine which architecture we have so we can
36 | # load libv4l to support more USB cameras. x86_64 and ppc64
37 | # are both supported by rpmfusion.
38 | case $(uname -i) in
39 | "x86_64" )
40 | #We load libv4l for 64 Bit x86 architectures
41 | LD_PRELOAD=/usr/lib64/libv4l/v4l2convert.so daemon $motion 2> /dev/null ;;
42 | "ppc64" )
43 | #We load libv4l for 64 Bit PPC architectures
44 | LD_PRELOAD=/usr/lib64/libv4l/v4l2convert.so daemon $motion 2> /dev/null ;;
45 | * )
46 | #Default case, we load libv4l for all 32 Bit architectures
47 | LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so daemon $motion 2> /dev/null ;;
48 | esac
49 | retval=$?
50 | echo
51 | [ $retval -eq 0 ] && touch $lockfile
52 | return $retval
53 | }
54 |
55 | stop() {
56 | echo -n $"Stopping $prog: "
57 | killproc $motion
58 | retval=$?
59 | echo
60 | [ $retval = 0 ] && rm -f $lockfile
61 | }
62 |
63 | restart() {
64 | stop
65 | start
66 | }
67 |
68 | reload() {
69 | echo -n $"Reloading $prog configuration: "
70 | killproc $motion -HUP
71 | retval=$?
72 | echo
73 | return $retval
74 | }
75 |
76 | rh_status() {
77 | # run checks to determine if the service is running or use generic status
78 | status $prog
79 | }
80 |
81 | rh_status_q() {
82 | rh_status >/dev/null 2>&1
83 | }
84 |
85 |
86 | # See how we were called.
87 | case "$1" in
88 | start)
89 | rh_status_q && exit 0
90 | $1
91 | ;;
92 | stop)
93 | rh_status_q || exit 0
94 | $1
95 | ;;
96 | restart)
97 | $1
98 | ;;
99 | reload)
100 | rh_status_q || exit 7
101 | $1
102 | ;;
103 | force-reload)
104 | #force_reload
105 | reload
106 | ;;
107 | status)
108 | rh_status
109 | ;;
110 | condrestart|try-restart)
111 | rh_status_q || exit 0
112 | restart
113 | ;;
114 | *)
115 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
116 | exit 1
117 | esac
118 | exit $?
119 |
--------------------------------------------------------------------------------
/netcam_wget.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002
3 | Free Software Foundation, Inc.
4 |
5 | Additional Copyright (C) 2004-2005 Christopher Price,
6 | Angel Carpintero, and other contributing authors.
7 |
8 | Major part of this file is reused code from GNU Wget. It has been
9 | merged and modified for use in the program Motion which is also
10 | released under the terms of the GNU General Public License.
11 |
12 | GNU Wget and Motion is free software; you can redistribute it and/or
13 | modify it under the terms of the GNU General Public License as published
14 | by the Free Software Foundation; either version 2 of the License, or
15 | (at your option) any later version.
16 |
17 | GNU Wget is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | GNU General Public License for more details.
21 |
22 | You should have received a copy of the GNU General Public License
23 | along with Wget; if not, write to the Free Software
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 |
26 | #ifndef NETCAM_WGET_H
27 | #define NETCAM_WGET_H
28 |
29 | #include "netcam.h"
30 |
31 | /* Retrieval stream */
32 | struct rbuf
33 | {
34 | char buffer[4096]; /* the input buffer */
35 | char *buffer_pos; /* current position in the buffer */
36 | size_t buffer_left; /* number of bytes left in the buffer:
37 | buffer_left = buffer_end - buffer_pos */
38 | int ret; /* used by RBUF_READCHAR macro */
39 | };
40 |
41 | /* Read a character from RBUF. If there is anything in the buffer,
42 | the character is returned from the buffer. Otherwise, refill the
43 | buffer and return the first character.
44 |
45 | The return value is the same as with read(2). On buffered read,
46 | the function returns 1.
47 |
48 | #### That return value is totally screwed up, and is a direct
49 | result of historical implementation of header code. The macro
50 | should return the character or EOF, and in case of error store it
51 | to rbuf->err or something. */
52 |
53 | #define RBUF_READCHAR(netcam, store) \
54 | ((netcam)->response->buffer_left ? (--(netcam)->response->buffer_left, \
55 | *((char *) (store)) = *(netcam)->response->buffer_pos++, 1) \
56 | : ((netcam)->response->buffer_pos = (netcam)->response->buffer, \
57 | ((((netcam)->response->ret = rbuf_read_bufferful (netcam)) <= 0) \
58 | ? (netcam)->response->ret : ((netcam)->response->buffer_left = (netcam->response)->ret - 1, \
59 | *((char *) (store)) = *(netcam)->response->buffer_pos++,1))))
60 |
61 | /* Function declarations */
62 | void rbuf_initialize(netcam_context_ptr);
63 | int rbuf_initialized_p(netcam_context_ptr);
64 | void rbuf_uninitialize(netcam_context_ptr);
65 | int rbuf_readchar(netcam_context_ptr, char *);
66 | int rbuf_peek(netcam_context_ptr, char *);
67 | int rbuf_flush(netcam_context_ptr, char *, int);
68 |
69 | /* Internal, but used by the macro. */
70 | int rbuf_read_bufferful(netcam_context_ptr);
71 |
72 | /* How many bytes it will take to store LEN bytes in base64. */
73 | #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
74 |
75 | void base64_encode(const char *, char *, int);
76 | char *strdupdelim(const char *, const char *);
77 | int http_process_type(const char *, void *);
78 |
79 | enum {
80 | HG_OK,
81 | HG_ERROR,
82 | HG_EOF
83 | };
84 |
85 | enum header_get_flags{
86 | HG_NONE = 0,
87 | HG_NO_CONTINUATIONS = 0x2
88 | };
89 |
90 | int header_get (netcam_context_ptr, char **, enum header_get_flags);
91 | int header_process (const char *, const char *,
92 | int (*) (const char *, void *), void *);
93 |
94 | int header_extract_number(const char *, void *);
95 | int header_strdup(const char *, void *);
96 | int skip_lws(const char *);
97 | int http_result_code(const char *);
98 |
99 | #endif /* NETCAM_WGET_H */
100 |
--------------------------------------------------------------------------------
/config.h.in:
--------------------------------------------------------------------------------
1 | /* config.h.in. Generated from configure.in by autoheader. */
2 |
3 | /* Define to 1 if you have the header file. */
4 | #undef HAVE_FCNTL_H
5 |
6 | /* Define to 1 if you have the `get_current_dir_name' function. */
7 | #undef HAVE_GET_CURRENT_DIR_NAME
8 |
9 | /* Define to 1 if you have the header file. */
10 | #undef HAVE_INTTYPES_H
11 |
12 | /* Define to 1 if you have the header file. */
13 | #undef HAVE_LINUX_VIDEODEV2_H
14 |
15 | /* Define to 1 if you have the header file. */
16 | #undef HAVE_LINUX_VIDEODEV_H
17 |
18 | /* Define to 1 if you have the header file. */
19 | #undef HAVE_MEMORY_H
20 |
21 | /* Define to 1 if you have MySQL support */
22 | #undef HAVE_MYSQL
23 |
24 | /* Define to 1 if you have PostgreSQL support */
25 | #undef HAVE_PGSQL
26 |
27 | /* Define to 1 if you have SDL support */
28 | #undef HAVE_SDL
29 |
30 | /* Define to 1 if you have the header file. */
31 | #undef HAVE_SIGNAL_H
32 |
33 | /* Define to 1 if you have SQLITE3 support */
34 | #undef HAVE_SQLITE3
35 |
36 | /* Define to 1 if you have the header file. */
37 | #undef HAVE_STDINT_H
38 |
39 | /* Define to 1 if you have the header file. */
40 | #undef HAVE_STDIO_H
41 |
42 | /* Define to 1 if you have the header file. */
43 | #undef HAVE_STDLIB_H
44 |
45 | /* Define to 1 if you have the header file. */
46 | #undef HAVE_STRINGS_H
47 |
48 | /* Define to 1 if you have the header file. */
49 | #undef HAVE_STRING_H
50 |
51 | /* Define to 1 if you have the header file. */
52 | #undef HAVE_SYS_IOCTL_H
53 |
54 | /* Define to 1 if you have the header file. */
55 | #undef HAVE_SYS_MMAN_H
56 |
57 | /* Define to 1 if you have the header file. */
58 | #undef HAVE_SYS_PARAM_H
59 |
60 | /* Define to 1 if you have the header file. */
61 | #undef HAVE_SYS_STAT_H
62 |
63 | /* Define to 1 if you have the header file. */
64 | #undef HAVE_SYS_TYPES_H
65 |
66 | /* Define to 1 if you have the header file. */
67 | #undef HAVE_TIME_H
68 |
69 | /* Define to 1 if you have the header file. */
70 | #undef HAVE_UNISTD_H
71 |
72 | /* Define to the address where bug reports for this package should be sent. */
73 | #undef PACKAGE_BUGREPORT
74 |
75 | /* Define to the full name of this package. */
76 | #undef PACKAGE_NAME
77 |
78 | /* Define to the full name and version of this package. */
79 | #undef PACKAGE_STRING
80 |
81 | /* Define to the one symbol short name of this package. */
82 | #undef PACKAGE_TARNAME
83 |
84 | /* Define to the home page for this package. */
85 | #undef PACKAGE_URL
86 |
87 | /* Define to the version of this package. */
88 | #undef PACKAGE_VERSION
89 |
90 | /* The size of `int', as computed by sizeof. */
91 | #undef SIZEOF_INT
92 |
93 | /* The size of `int *', as computed by sizeof. */
94 | #undef SIZEOF_INT_P
95 |
96 | /* The size of `long int', as computed by sizeof. */
97 | #undef SIZEOF_LONG_INT
98 |
99 | /* The size of `long long', as computed by sizeof. */
100 | #undef SIZEOF_LONG_LONG
101 |
102 | /* The size of `short', as computed by sizeof. */
103 | #undef SIZEOF_SHORT
104 |
105 | /* The size of `void *', as computed by sizeof. */
106 | #undef SIZEOF_VOID_P
107 |
108 | /* Define to 1 if you have the ANSI C header files. */
109 | #undef STDC_HEADERS
110 |
111 | /* Define to empty if `const' does not conform to ANSI C. */
112 | #undef const
113 |
114 | /* Define to 1 if you have av_avformat_alloc_context support */
115 | #undef have_av_avformat_alloc_context
116 |
117 | /* Define to 1 if you have av_get_media_type_string support */
118 | #undef have_av_get_media_type_string
119 |
120 | /* Define to 1 if you have av_register_protocol support */
121 | #undef have_av_register_protocol
122 |
123 | /* Define to 1 if you have av_register_protocol2 support */
124 | #undef have_av_register_protocol2
125 |
126 | /* Define to 1 if you have avformat_alloc_context support */
127 | #undef have_avformat_alloc_context
128 |
--------------------------------------------------------------------------------
/video_freebsd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * video_freebsd.h
3 | *
4 | * Include file for video_freebsd.c
5 | * Copyright 2004 by Angel Carpintero (motiondevelop@gmail.com)
6 | * This software is distributed under the GNU public license version 2
7 | * See also the file 'COPYING'.
8 | *
9 | */
10 |
11 | #ifndef _INCLUDE_VIDEO_FREEBSD_H
12 | #define _INCLUDE_VIDEO_FREEBSD_H
13 |
14 | #ifndef WITHOUT_V4L
15 |
16 | #ifdef __NetBSD__
17 | #include
18 | #elif __OpenBSD__
19 | #include
20 | #elif defined(OLD_BKTR)
21 | #include
22 | #include
23 | #else
24 | #include
25 | #include
26 | #endif
27 |
28 | #endif /* !WITHOUT_V4L */
29 |
30 | /* bktr (video4linux) stuff FIXME more modes not only these */
31 |
32 | /* not used yet FIXME ! only needed for tuner use */
33 | /*
34 | #define TV_INPUT_NTSCM BT848_IFORM_F_NTSCM
35 | #define TV_INPUT_NTSCJ BT848_IFORM_F_NTSCJ
36 | #define TV_INPUT_PALBDGHI BT848_IFORM_F_PALBDGHI
37 | #define TV_INPUT_PALM BT848_IFORM_F_PALM
38 | #define TV_INPUT_PALN BT848_IFORM_F_PALN
39 | #define TV_INPUT_SECAM BT848_IFORM_F_SECAM
40 | #define TV_INPUT_PALNCOMB BT848_IFORM_F_RSVD
41 | */
42 |
43 | /* video4linux error codes */
44 | #define V4L_GENERAL_ERROR 0x01 /* binary 000001 */
45 | #define V4L_BTTVLOST_ERROR 0x05 /* binary 000101 */
46 | #define V4L_FATAL_ERROR -1
47 |
48 | #define NORM_DEFAULT 0x00800 // METEOR_FMT_AUTOMODE
49 | #define NORM_PAL 0x00200 // METEOR_FMT_PAL
50 | #define NORM_NTSC 0x00100 // METEOR_FMT_NTSC
51 | #define NORM_SECAM 0x00400 // METEOR_FMT_SECAM
52 | #define NORM_PAL_NC 0x00200 // METEOR_FMT_PAL /* Greyscale howto ?! FIXME */
53 |
54 | #define NORM_DEFAULT_NEW BT848_IFORM_F_AUTO
55 | #define NORM_PAL_NEW BT848_IFORM_F_PALBDGHI
56 | #define NORM_NTSC_NEW BT848_IFORM_F_NTSCM
57 | #define NORM_SECAM_NEW BT848_IFORM_F_SECAM
58 | #define NORM_PAL_NC_NEW BT848_IFORM_F_AUTO /* FIXME */
59 |
60 | #define PAL 0
61 | #define NTSC 1
62 | #define SECAM 2
63 | #define PAL_NC 3
64 |
65 | #define PAL_HEIGHT 576
66 | #define SECAM_HEIGHT 576
67 | #define NTSC_HEIGHT 480
68 |
69 | #define BSD_VIDFMT_NONE 0
70 | #define BSD_VIDFMT_YV12 1
71 | #define BSD_VIDFMT_I420 2
72 | #define BSD_VIDFMT_YV16 3
73 | #define BSD_VIDFMT_YUY2 4
74 | #define BSD_VIDFMT_UYVY 5
75 | #define BSD_VIDFMT_RV15 6
76 | #define BSD_VIDFMT_RV16 7
77 | #define BSD_VIDFMT_LAST 8
78 |
79 |
80 | #define IN_DEFAULT 0
81 | #define IN_COMPOSITE 0
82 | #define IN_TV 1
83 | #define IN_COMPOSITE2 2
84 | #define IN_SVIDEO 3
85 |
86 | #define CAPTURE_SINGLE 0
87 | #define CAPTURE_CONTINOUS 1
88 |
89 | #define VIDEO_DEVICE "/dev/bktr0"
90 | #define TUNER_DEVICE "/dev/tuner0"
91 |
92 | struct video_dev {
93 | struct video_dev *next;
94 | int usage_count;
95 | int fd_bktr;
96 | int fd_tuner;
97 | const char *video_device;
98 | const char *tuner_device;
99 | unsigned input;
100 | unsigned norm;
101 | int width;
102 | int height;
103 | int contrast;
104 | int saturation;
105 | int hue;
106 | int brightness;
107 | int channel;
108 | int channelset;
109 | unsigned long freq;
110 |
111 | pthread_mutex_t mutex;
112 | pthread_mutexattr_t attr;
113 | int owner;
114 | int frames;
115 |
116 | /* Device type specific stuff: */
117 | #ifndef WITHOUT_V4L
118 | int capture_method;
119 | int v4l_fmt;
120 | unsigned char *v4l_buffers[2];
121 | int v4l_curbuffer;
122 | int v4l_maxbuffer;
123 | int v4l_bufsize;
124 | #endif
125 | };
126 |
127 | /* video functions, video_freebsd.c */
128 | int vid_start(struct context *);
129 | int vid_next(struct context *, unsigned char *);
130 | void vid_close(struct context *);
131 |
132 | #ifndef WITHOUT_V4L
133 | void vid_init(void);
134 | void vid_cleanup(void);
135 | #endif
136 |
137 | #endif /* _INCLUDE_VIDEO_FREEBSD_H */
138 |
--------------------------------------------------------------------------------
/video.h:
--------------------------------------------------------------------------------
1 | /* video.h
2 | *
3 | * Include file for video.c
4 | * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org)
5 | * This software is distributed under the GNU public license version 2
6 | * See also the file 'COPYING'.
7 | *
8 | */
9 |
10 | #ifndef _INCLUDE_VIDEO_H
11 | #define _INCLUDE_VIDEO_H
12 |
13 | #define _LINUX_TIME_H 1
14 | #include
15 |
16 |
17 | #if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L))
18 | #include
19 | #include "vloopback_motion.h"
20 | #include "pwc-ioctl.h"
21 | #endif
22 |
23 | /* video4linux stuff */
24 | #define NORM_DEFAULT 0
25 | #define NORM_PAL 0
26 | #define NORM_NTSC 1
27 | #define NORM_SECAM 2
28 | #define NORM_PAL_NC 3
29 | #define IN_DEFAULT -1
30 | #define IN_TV 0
31 | #define IN_COMPOSITE 1
32 | #define IN_COMPOSITE2 2
33 | #define IN_SVIDEO 3
34 |
35 | /* video4linux error codes */
36 | #define V4L_GENERAL_ERROR 0x01 /* binary 000001 */
37 | #define V4L_BTTVLOST_ERROR 0x05 /* binary 000101 */
38 | #define V4L_FATAL_ERROR -1
39 |
40 | #define VIDEO_DEVICE "/dev/video0"
41 |
42 | typedef struct video_image_buff {
43 | unsigned char *ptr;
44 | int content_length;
45 | size_t size; /* total allocated size */
46 | size_t used; /* bytes already used */
47 | struct timeval image_time; /* time this image was received */
48 | } video_buff;
49 |
50 |
51 | struct video_dev {
52 | struct video_dev *next;
53 | int usage_count;
54 | int fd;
55 | const char *video_device;
56 | int input;
57 | int norm;
58 | int width;
59 | int height;
60 | int brightness;
61 | int contrast;
62 | int saturation;
63 | int hue;
64 | unsigned long freq;
65 | int tuner_number;
66 | int fps;
67 |
68 | pthread_mutex_t mutex;
69 | pthread_mutexattr_t attr;
70 | int owner;
71 | int frames;
72 |
73 | /* Device type specific stuff: */
74 | #ifndef WITHOUT_V4L
75 | /* v4l */
76 | int v4l2;
77 | void *v4l2_private;
78 |
79 | int size_map;
80 | int v4l_fmt;
81 | unsigned char *v4l_buffers[2];
82 | int v4l_curbuffer;
83 | int v4l_maxbuffer;
84 | int v4l_bufsize;
85 | #endif
86 | };
87 |
88 | /* video functions, video_common.c */
89 | int vid_start(struct context *cnt);
90 | int vid_next(struct context *cnt, unsigned char *map);
91 | void vid_close(struct context *cnt);
92 | void vid_cleanup(void);
93 | void vid_init(void);
94 | void conv_yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, int height);
95 | void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int width, unsigned int height);
96 | void conv_rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height);
97 | int sonix_decompress(unsigned char *outp, unsigned char *inp, int width, int height);
98 | void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long int height);
99 | int vid_do_autobright(struct context *cnt, struct video_dev *viddev);
100 | int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height, unsigned int size);
101 |
102 | #ifndef WITHOUT_V4L
103 | /* video functions, video.c */
104 | unsigned char *v4l_start(struct video_dev *viddev, int width, int height,
105 | int input, int norm, unsigned long freq, int tuner_number);
106 | void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height,
107 | struct config *conf);
108 | int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height);
109 |
110 | /* video2.c */
111 | unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int width, int height,
112 | int input, int norm, unsigned long freq, int tuner_number);
113 | void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height,
114 | struct config *conf);
115 | int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height);
116 | void v4l2_close(struct video_dev *viddev);
117 | void v4l2_cleanup(struct video_dev *viddev);
118 | #endif /* WITHOUT_V4L */
119 |
120 | #endif /* _INCLUDE_VIDEO_H */
121 |
--------------------------------------------------------------------------------
/conf.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * conf.h - function prototypes for the config handling routines
4 | *
5 | * Originally written for the dproxy package by Matthew Pratt.
6 | *
7 | * Copyright 2000 Jeroen Vreeken (pe1rxq@chello.nl)
8 | *
9 | * This software is licensed under the terms of the GNU General
10 | * Public License (GPL). Please see the file COPYING for details.
11 | *
12 | *
13 | */
14 |
15 | #ifndef _INCLUDE_CONF_H
16 | #define _INCLUDE_CONF_H
17 |
18 | /*
19 | * More parameters may be added later.
20 | */
21 | struct config {
22 | unsigned int log_level;
23 | char *log_type_str;
24 | char *log_file;
25 | int setup_mode;
26 | int width;
27 | int height;
28 | int quality;
29 | int rotate_deg;
30 | int max_changes;
31 | int threshold_tune;
32 | const char *output_pictures;
33 | int motion_img;
34 | int emulate_motion;
35 | int event_gap;
36 | int max_movie_time;
37 | int snapshot_interval;
38 | const char *locate_motion_mode;
39 | const char *locate_motion_style;
40 | int input;
41 | int norm;
42 | int frame_limit;
43 | int quiet;
44 | int useextpipe; /* ext_pipe on or off */
45 | const char *extpipe; /* full Command-line for pipe -- must accept YUV420P images */
46 | const char *picture_type;
47 | int noise;
48 | int noise_tune;
49 | int minimum_frame_time;
50 | int lightswitch;
51 | int autobright;
52 | int brightness;
53 | int contrast;
54 | int saturation;
55 | int hue;
56 | int roundrobin_frames;
57 | int roundrobin_skip;
58 | int pre_capture;
59 | int post_capture;
60 | int switchfilter;
61 | int ffmpeg_output;
62 | int ffmpeg_output_debug;
63 | int ffmpeg_bps;
64 | int ffmpeg_vbr;
65 | int ffmpeg_deinterlace;
66 | const char *ffmpeg_video_codec;
67 | #ifdef HAVE_SDL
68 | int sdl_threadnr;
69 | #endif
70 | int ipv6_enabled;
71 | int stream_port;
72 | int stream_quality;
73 | int stream_motion;
74 | int stream_maxrate;
75 | int stream_localhost;
76 | int stream_limit;
77 | int stream_auth_method;
78 | const char *stream_authentication;
79 | int webcontrol_port;
80 | int webcontrol_localhost;
81 | int webcontrol_html_output;
82 | const char *webcontrol_authentication;
83 | unsigned long frequency;
84 | int tuner_number;
85 | int timelapse;
86 | const char *timelapse_mode;
87 | #if (defined(BSD))
88 | const char *tuner_device;
89 | #endif
90 | const char *video_device;
91 | int v4l2_palette;
92 | const char *vidpipe;
93 | const char *filepath;
94 | const char *imagepath;
95 | const char *moviepath;
96 | const char *snappath;
97 | const char *timepath;
98 | char *on_event_start;
99 | char *on_event_end;
100 | const char *mask_file;
101 | int smart_mask_speed;
102 | int sql_log_image;
103 | int sql_log_snapshot;
104 | int sql_log_movie;
105 | int sql_log_timelapse;
106 | const char *sql_query;
107 | const char *database_type;
108 | const char *database_dbname;
109 | const char *database_host;
110 | const char *database_user;
111 | const char *database_password;
112 | const char *sqlite3_db;
113 | int database_port;
114 | char *on_picture_save;
115 | char *on_area_detected;
116 | char *on_motion_detected;
117 | char *on_movie_start;
118 | char *on_movie_end;
119 | char *on_camera_lost;
120 | const char *motionvidpipe;
121 | const char *netcam_url;
122 | const char *netcam_userpass;
123 | const char *netcam_keepalive;
124 | const char *netcam_proxy;
125 | unsigned int netcam_tolerant_check;
126 | int text_changes;
127 | const char *text_left;
128 | const char *text_right;
129 | const char *text_event;
130 | int text_double;
131 | const char *despeckle_filter;
132 | const char *area_detect;
133 | int minimum_motion_frames;
134 | const char *exif_text;
135 | char *pid_file;
136 | int argc;
137 | char **argv;
138 | };
139 |
140 | /**
141 | * typedef for a param copy function.
142 | */
143 | typedef struct context ** (* conf_copy_func)(struct context **, const char *, int);
144 | typedef const char *(* conf_print_func)(struct context **, char **, int, unsigned int);
145 |
146 | /**
147 | * description for parameters in the config file
148 | */
149 | typedef struct {
150 | const char *param_name; /* name for this parameter */
151 | const char *param_help; /* short explanation for parameter */
152 | unsigned int main_thread; /* belong only to main thread when value>0 */
153 | int conf_value; /* pointer to a field in struct context */
154 | conf_copy_func copy; /* a function to set the value in 'config' */
155 | conf_print_func print; /* a function to output the value to a file */
156 | } config_param;
157 |
158 | extern config_param config_params[];
159 |
160 | struct context **conf_load(struct context **);
161 | struct context **conf_cmdparse(struct context **, const char *, const char *);
162 | const char *config_type(config_param *);
163 | void conf_print(struct context **);
164 | void malloc_strings(struct context *);
165 | char *mystrdup(const char *);
166 | char *mystrcpy(char *, const char *);
167 | struct context **copy_string(struct context **, const char *, int);
168 |
169 | #ifndef HAVE_GET_CURRENT_DIR_NAME
170 | char *get_current_dir_name(void);
171 | #endif
172 |
173 | #endif /* _INCLUDE_CONF_H */
174 |
--------------------------------------------------------------------------------
/track.h:
--------------------------------------------------------------------------------
1 | /* track.h
2 | *
3 | * Experimental motion tracking.
4 | *
5 | * Copyright 2000, Jeroen Vreeken
6 | * This program is published under the GNU Public license
7 | */
8 |
9 | #ifndef _INCLUDE_TRACK_H
10 | #define _INCLUDE_TRACK_H
11 |
12 | #include "alg.h"
13 | #include
14 |
15 | struct trackoptions {
16 | int dev;
17 | /* Config options: */
18 | unsigned int type;
19 | char *port;
20 | unsigned int motorx;
21 | unsigned int motory;
22 | int maxx;
23 | int maxy;
24 | int minx;
25 | int miny;
26 | unsigned int stepsize;
27 | unsigned int speed;
28 | unsigned int homex;
29 | unsigned int homey;
30 | unsigned int iomojo_id;
31 | unsigned int active;
32 | unsigned int motorx_reverse;
33 | unsigned int motory_reverse;
34 | unsigned int minmaxfound;
35 | unsigned int step_angle_x;
36 | unsigned int step_angle_y;
37 | unsigned int move_wait;
38 | /* UVC */
39 | int pan_angle; // degrees
40 | int tilt_angle; // degrees
41 | };
42 |
43 | extern struct trackoptions track_template;
44 |
45 | unsigned int track_center(struct context *, int, unsigned int, int, int);
46 | unsigned int track_move(struct context *, int, struct coord *, struct images *, unsigned int);
47 |
48 | /*
49 | * Some default values:
50 | */
51 | #define TRACK_SPEED 255
52 | #define TRACK_STEPSIZE 40
53 |
54 | #define TRACK_TYPE_STEPPER 1
55 | #define TRACK_TYPE_IOMOJO 2
56 | #define TRACK_TYPE_PWC 3
57 | #define TRACK_TYPE_GENERIC 4
58 | #define TRACK_TYPE_UVC 5
59 | #define TRACK_TYPE_SERVO 6
60 |
61 | /*
62 | * Some defines for the Serial stepper motor:
63 | */
64 |
65 | #define STEPPER_BAUDRATE B9600
66 |
67 | #define STEPPER_STATUS_LEFT 1
68 | #define STEPPER_STATUS_RIGHT 2
69 | #define STEPPER_STATUS_SAFETYL 4
70 | #define STEPPER_STATUS_SAFETYR 8
71 |
72 | #define STEPPER_STATUS_UP 1
73 | #define STEPPER_STATUS_DOWN 2
74 | #define STEPPER_STATUS_SAFETYU 4
75 | #define STEPPER_STATUS_SAFETYD 8
76 |
77 |
78 |
79 | #define STEPPER_COMMAND_STATUS 0
80 | #define STEPPER_COMMAND_LEFT_N 1
81 | #define STEPPER_COMMAND_RIGHT_N 2
82 | #define STEPPER_COMMAND_LEFT 3
83 | #define STEPPER_COMMAND_RIGHT 4
84 | #define STEPPER_COMMAND_SWEEP 5
85 | #define STEPPER_COMMAND_STOP 6
86 | #define STEPPER_COMMAND_SPEED 7
87 |
88 | #define STEPPER_COMMAND_UP_N 1
89 | #define STEPPER_COMMAND_DOWN_N 2
90 | #define STEPPER_COMMAND_UP 3
91 | #define STEPPER_COMMAND_DOWN 4
92 |
93 |
94 |
95 | /*
96 | * Some defines for the Serial servo motor:
97 | */
98 |
99 | /*
100 | * Controlling:
101 | * Three bytes are sent to the servo - BYTE1=SERVO_COMMAND BYTE2=COMMAND BYTE3=DATA
102 | * eg, sending the command 01 02 08 would Command SERVO_COMMAND1 to move LEFT a total of 8 STEPS
103 | *
104 | * An extra command 0x08 has been added but here is the basic command set.
105 | *
106 | * 0x00 STATUS - Current status byte will be returned, data byte ignored
107 | * 0x01 LEFT_N - Servo will take N Steps to the Left until it reaches the Servos safety limit
108 | * 0x02 RIGHT_N - Servo will take N Steps to the Right until it reaches the Servos safety limit
109 | * 0x03 LEFT - Servo will move to Left most position, data byte ignored.
110 | * 0x04 RIGHT - Servo will move to Right most position, data byte ignored.
111 | * 0x05 SWEEP - Servo will sweep between its extremes, data byte ignored.
112 | * 0x06 STOP - Servo will Stop, data byte ignored
113 | * 0x07 SPEED - Set servos speed between 0 and 255.
114 | * 0x08 ABSOLUTE - Set servo to absolute position between 0 and 255
115 | * 0x09 POSITION - Get servo to absolute position between 0 and 255
116 | * */
117 |
118 | #define SERVO_BAUDRATE B9600
119 |
120 | #define SERVO_COMMAND_STATUS 0
121 | #define SERVO_COMMAND_LEFT_N 1
122 | #define SERVO_COMMAND_RIGHT_N 2
123 | #define SERVO_COMMAND_LEFT 3
124 | #define SERVO_COMMAND_RIGHT 4
125 | #define SERVO_COMMAND_SWEEP 5
126 | #define SERVO_COMMAND_STOP 6
127 | #define SERVO_COMMAND_SPEED 7
128 | #define SERVO_COMMAND_ABSOLUTE 8
129 | #define SERVO_COMMAND_POSITION 9
130 |
131 |
132 | #define SERVO_COMMAND_UP_N 1
133 | #define SERVO_COMMAND_DOWN_N 2
134 | #define SERVO_COMMAND_UP 3
135 | #define SERVO_COMMAND_DOWN 4
136 |
137 |
138 |
139 | /*
140 | * Some defines for the Iomojo Smilecam:
141 | */
142 |
143 | #define IOMOJO_BAUDRATE B19200
144 |
145 | #define IOMOJO_CHECKPOWER_CMD 0xff
146 | #define IOMOJO_CHECKPOWER_RET 'Q'
147 | #define IOMOJO_MOVEOFFSET_CMD 0xfe
148 | #define IOMOJO_SETSPEED_CMD 0xfd
149 | #define IOMOJO_SETSPEED_RET 'P'
150 | #define IOMOJO_MOVEHOME 0xf9
151 | #define IOMOJO_RESTART 0xf7
152 |
153 | #define IOMOJO_DIRECTION_RIGHT 0x01
154 | #define IOMOJO_DIRECTION_LEFT 0x02
155 | #define IOMOJO_DIRECTION_DOWN 0x04
156 | #define IOMOJO_DIRECTION_UP 0x08
157 |
158 | #ifndef WITHOUT_V4L
159 |
160 | /*
161 | * Defines for the Logitech QuickCam Orbit/Sphere USB webcam
162 | */
163 |
164 | #define LQOS_VERTICAL_DEGREES 180
165 | #define LQOS_HORIZONAL_DEGREES 120
166 |
167 | /*
168 | * UVC
169 | */
170 |
171 | #ifdef MOTION_V4L2
172 |
173 | #ifndef V4L2_CID_PAN_RELATIVE
174 | #define V4L2_CID_PAN_RELATIVE (V4L2_CID_PRIVATE_BASE+7)
175 | #endif
176 |
177 | #ifndef V4L2_CID_TILT_RELATIVE
178 | #define V4L2_CID_TILT_RELATIVE (V4L2_CID_PRIVATE_BASE+8)
179 | #endif
180 |
181 | #ifndef V4L2_CID_PANTILT_RESET
182 | #define V4L2_CID_PANTILT_RESET (V4L2_CID_PRIVATE_BASE+9)
183 | #endif
184 |
185 | #define INCPANTILT 64 // 1 degree
186 | #endif /* MOTION_V4L2 */
187 |
188 |
189 | #endif /* WITHOUT_V4L */
190 |
191 | #endif /* _INCLUDE_TRACK_H */
192 |
--------------------------------------------------------------------------------
/motion.spec.in:
--------------------------------------------------------------------------------
1 | Name: @PACKAGE_NAME@
2 | Version: @PACKAGE_VERSION@
3 | Release: 1%{?dist}
4 | Summary: A motion detection system
5 |
6 | Group: Applications/Multimedia
7 | License: GPLv2+
8 | URL: http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome
9 | Source0: http://prdownloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz
10 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
11 |
12 | BuildRequires: libjpeg-devel ffmpeg-devel zlib-devel
13 | #This requires comes from the startup script, it will be there until motion supports libv4l calls in the code
14 | Requires: libv4l
15 | Requires(post): chkconfig
16 | Requires(preun): chkconfig initscripts
17 | Requires(postun): initscripts
18 |
19 | %description
20 | Motion is a software motion detector. It grabs images from video4linux devices
21 | and/or from webcams (such as the axis network cameras). Motion is the perfect
22 | tool for keeping an eye on your property keeping only those images that are
23 | interesting. Motion is strictly command line driven and can run as a daemon
24 | with a rather small footprint. This version is built with ffmpeg support but
25 | without MySQL and PostgreSQL support.
26 |
27 | %prep
28 | %setup -q
29 |
30 | %build
31 | %configure --sysconfdir=%{_sysconfdir}/%{name} --without-optimizecpu --with-ffmpeg --without-mysql --without-pgsql
32 | make %{?_smp_mflags}
33 |
34 | %install
35 | rm -rf %{buildroot}
36 | make install DESTDIR=%{buildroot}
37 | #We rename the configuration file
38 | mv %{buildroot}%{_sysconfdir}/%{name}/motion-dist.conf %{buildroot}%{_sysconfdir}/%{name}/motion.conf
39 | #We change the PID file path to match the one in the startup script
40 | sed -i 's|/var/run/motion/motion.pid|/var/run/motion.pid|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
41 | #We remove SQL directives in the configuration file, as we don't use them
42 | sed -i 's|sql_log_image|; sql_log_image|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
43 | sed -i 's|sql_log_snapshot|; sql_log_snapshot|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
44 | sed -i 's|sql_log_mpeg|; sql_log_mpeg|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
45 | sed -i 's|sql_log_timelapse|; sql_log_timelapse|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
46 | sed -i 's|sql_query|; sql_query|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
47 | #We set the log file and target directory - logging is for 3.3 branch
48 | sed -i 's|;logfile|logfile /var/log/motion.log|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
49 | sed -i 's|target_dir /usr/local/apache2/htdocs/cam1|target_dir /var/motion|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
50 | #We install our startup script
51 | install -D -m 0755 motion.init-Fedora %{buildroot}%{_initrddir}/%{name}
52 |
53 | %post
54 | #We add the motion init script to the services when installing
55 | /sbin/chkconfig --add %{name}
56 |
57 | %preun
58 | #We stop the service and remove it from init scripts when erasing
59 | if [ $1 = 0 ] ; then
60 | /sbin/service %{name} stop >/dev/null 2>&1
61 | /sbin/chkconfig --del %{name}
62 | fi
63 |
64 | %postun
65 | #We restart the service during an upgrade
66 | if [ "$1" -ge "1" ] ; then
67 | /sbin/service %{name} condrestart >/dev/null 2>&1
68 | fi
69 |
70 | %clean
71 | rm -rf %{buildroot}
72 |
73 | %files
74 | #Permissions are bogus upstream, we need to be sure to set them here
75 | %defattr (-,root,root,-)
76 | %dir %{_sysconfdir}/%{name}
77 | %dir %{_datadir}/%{name}-%{version}
78 | %dir %{_datadir}/%{name}-%{version}/examples
79 | %doc CHANGELOG COPYING CREDITS INSTALL README motion_guide.html
80 | %attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/motion-dist.conf
81 | %attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-Debian
82 | %attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-FreeBSD.sh
83 | %attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-Fedora
84 | %attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread1.conf
85 | %attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread2.conf
86 | %attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread3.conf
87 | %attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread4.conf
88 | %attr(0644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/motion.conf
89 | %attr(0755,root,root) %{_bindir}/motion
90 | %attr(0644,root,root) %{_mandir}/man1/motion.1*
91 | %attr(0755,root,root) %{_initrddir}/%{name}
92 |
93 | %changelog
94 | * Thu Mar 06 2010 Steven Moix - 3.2.12-1
95 | - New upstream release, important bugfixes only
96 |
97 | * Wed Oct 21 2009 Thorsten Leemhuis - 3.2.11.1-3
98 | - rebuild for new ffmpeg
99 |
100 | * Tue Aug 11 2009 Steven Moix - 3.2.11.1-1
101 | - Drop patch for ffmpeg 0.5 compatibility
102 | - Drop ffmpeg detection patch
103 | - Moved default output directory to /var/motion
104 | - New startup script with added v4l2convert to support more cameras - https://bugzilla.rpmfusion.org/show_bug.cgi?id=681
105 | - Fix Segfault on reload or quit for vloopback (maybe other v4l1 devices too)
106 | - Fix fd leaks in external pipe
107 | - Avoid possible stack smashing in v4l_open_vidpipe()
108 | - Fix segfault for new libjpeg v7
109 |
110 | * Mon Jul 06 2009 Steven Moix - 3.3.0-1
111 | - SPEC Preparation for the 3.3 branch
112 |
113 | * Sun Jun 05 2009 Steven Moix - 3.2.11-5
114 | - Patch and rebuild for ffmpeg 0.5
115 |
116 | * Sun Mar 29 2009 Thorsten Leemhuis - 3.2.11-4
117 | - rebuild for new F11 features
118 |
119 | * Wed Mar 18 2009 Steven Moix - 3.2.11-3
120 | - Even more corrected init script thanks to Stewart Adam
121 |
122 | * Sun Mar 15 2009 Steven Moix - 3.2.11-2
123 | - Removed the ffmpeg requires
124 | - Corrected the spec file
125 | - New init script with a corrected start() function and LSB header support
126 |
127 | * Tue Mar 03 2009 Steven Moix - 3.2.11-1
128 | - Updated to Fedora 10 standard
129 |
130 | * Sun Sep 18 2005 Kenneth Lavrsen - 3.2.4-1
131 | - Generic version of livna spec file replacing the old less optimal specfile.
132 |
133 | * Thu Sep 15 2005 Dams - 3.2.3-0.lvn.1
134 | - Initial released based upon upstream spec file
135 |
--------------------------------------------------------------------------------
/sdl.c:
--------------------------------------------------------------------------------
1 | /*
2 | * sdl.c
3 | *
4 | * sdl functions for motion.
5 | * Copyright 2009 by Peter Holik (peter@holik.at)
6 | * This software is distributed under the GNU public license version 2
7 | * See also the file 'COPYING'.
8 | */
9 | #include "sdl.h"
10 | #include
11 |
12 | static int cur_width;
13 | static int cur_height;
14 | static int is_full_screen;
15 | static int fs_screen_width;
16 | static int fs_screen_height;
17 |
18 | static SDL_Surface *screen;
19 | static SDL_Overlay *overlay;
20 |
21 | static int sdl_video_open(int width, int height)
22 | {
23 | int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
24 | int w,h;
25 |
26 | if (is_full_screen) flags |= SDL_FULLSCREEN;
27 | else flags |= SDL_RESIZABLE;
28 |
29 | if (is_full_screen && fs_screen_width) {
30 | w = fs_screen_width;
31 | h = fs_screen_height;
32 | } else if (width > fs_screen_width || height > fs_screen_height) {
33 | w = fs_screen_width;
34 | h = fs_screen_height;
35 | } else {
36 | w = width;
37 | h = height;
38 | }
39 | /* 32 because framebuffer is usually initalized to 8 and
40 | you have to use fbset with -depth to make it working */
41 | screen = SDL_SetVideoMode(w, h, 32, flags);
42 |
43 | if (!screen) {
44 | MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO,"%s: Unable to set video mode: %s",
45 | SDL_GetError());
46 | return -1;
47 | }
48 |
49 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: SDL dimension %d x %d fullscreen %d BytesPerPixel %d",
50 | screen->w, screen->h, is_full_screen,
51 | screen->format->BytesPerPixel);
52 |
53 | SDL_WM_SetCaption("motion", "motion");
54 | SDL_ShowCursor(SDL_DISABLE);
55 |
56 | if (cur_width != width || cur_height != height) {
57 | cur_width = width;
58 | cur_height = height;
59 |
60 | if (overlay) SDL_FreeYUVOverlay(overlay);
61 |
62 | overlay = SDL_CreateYUVOverlay(cur_width, cur_height,
63 | SDL_YV12_OVERLAY, screen);
64 | if (!overlay) {
65 | MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not create overlay: %s",
66 | SDL_GetError());
67 | sdl_stop();
68 | } else
69 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: SDL created %dx%dx%d %s overlay",
70 | overlay->w,overlay->h,overlay->planes,
71 | overlay->hw_overlay?"hardware":"software");
72 | }
73 | return overlay == NULL;
74 | }
75 |
76 | int sdl_start(int width, int height)
77 | {
78 | //putenv("SDL_NOMOUSE=1");
79 | setenv("SDL_NOMOUSE", "1", 1);
80 |
81 | if (screen) return 0;
82 |
83 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: SDL start");
84 |
85 | if (SDL_Init(SDL_INIT_VIDEO)) {
86 | MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not initialize SDL - %s",
87 | SDL_GetError());
88 | return -1;
89 | }
90 | const SDL_VideoInfo *vi = SDL_GetVideoInfo();
91 | fs_screen_width = vi->current_w;
92 | fs_screen_height = vi->current_h;
93 |
94 | if (sdl_video_open(width, height)) return -1;
95 |
96 | SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
97 | SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
98 | SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
99 | SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
100 | SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
101 | SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
102 | SDL_EventState(SDL_KEYUP, SDL_IGNORE);
103 | SDL_EventState(SDL_JOYBUTTONDOWN, SDL_IGNORE);
104 | SDL_EventState(SDL_JOYBUTTONUP, SDL_IGNORE);
105 | SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
106 | SDL_EventState(SDL_JOYBALLMOTION, SDL_IGNORE);
107 | SDL_EventState(SDL_JOYHATMOTION, SDL_IGNORE);
108 | SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE);
109 |
110 | return 0;
111 | }
112 |
113 | void sdl_put(unsigned char *image, int width, int height)
114 | {
115 | SDL_Event event;
116 |
117 | if (screen && overlay) {
118 | SDL_Rect rect;
119 | float aspect_ratio = (float)width / height;
120 | int pic_width, pic_height;
121 |
122 | if (width != cur_width || height != cur_height)
123 | sdl_video_open(width, height);
124 |
125 | if (SDL_MUSTLOCK(screen))
126 | if (SDL_LockSurface(screen) < 0) return;
127 |
128 | SDL_LockYUVOverlay(overlay);
129 | memcpy(overlay->pixels[0], image, width * height);
130 | memcpy(overlay->pixels[2], image + (width * height), (width * height / 4));
131 | memcpy(overlay->pixels[1], image + (width * height * 5 / 4), (width * height / 4));
132 | SDL_UnlockYUVOverlay(overlay);
133 |
134 | if (SDL_MUSTLOCK(screen))
135 | SDL_UnlockSurface(screen);
136 |
137 | pic_height = screen->h;
138 | pic_width = pic_height * aspect_ratio;
139 | if (pic_width > screen->w) {
140 | pic_width = screen->w;
141 | pic_height = pic_width / aspect_ratio;
142 | }
143 | rect.x = (screen->w - pic_width) / 2;
144 | rect.y = (screen->h - pic_height) / 2;
145 | rect.w = pic_width;
146 | rect.h = pic_height;
147 |
148 | if (SDL_DisplayYUVOverlay(overlay, &rect))
149 | MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: SDL_DisplayYUVOverlay: %s",
150 | SDL_GetError());
151 |
152 | if (SDL_PollEvent(&event)) {
153 | if ((event.type == SDL_QUIT ||
154 | (event.type == SDL_KEYDOWN &&
155 | event.key.keysym.sym == SDLK_ESCAPE)))
156 | sdl_stop();
157 | else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f) {
158 | is_full_screen = !is_full_screen;
159 | sdl_video_open(width, height);
160 | }
161 | else if (event.type == SDL_VIDEORESIZE)
162 | screen = SDL_SetVideoMode(event.resize.w, event.resize.h,
163 | screen->format->BitsPerPixel,
164 | screen->flags);
165 | }
166 | }
167 | }
168 |
169 | void sdl_stop(void)
170 | {
171 | if (screen) {
172 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: SDL quit");
173 | SDL_ShowCursor(SDL_ENABLE);
174 | if (overlay) {
175 | SDL_FreeYUVOverlay(overlay);
176 | overlay = NULL;
177 | }
178 | SDL_Quit();
179 | screen = NULL;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/logger.c:
--------------------------------------------------------------------------------
1 | /*
2 | * logger.c
3 | *
4 | * Logger for motion
5 | *
6 | * Copyright 2005, William M. Brack
7 | * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com)
8 | * This software is distributed under the GNU Public License Version 2
9 | * See also the file 'COPYING'.
10 | *
11 | */
12 |
13 | #include "logger.h" /* already includes motion.h */
14 | #include
15 |
16 | static int log_mode = LOGMODE_SYSLOG;
17 | static FILE *logfile;
18 | static unsigned int log_level = LEVEL_DEFAULT;
19 | static unsigned int log_type = TYPE_DEFAULT;
20 |
21 | static const char *log_type_str[] = {NULL, "COR", "STR", "ENC", "NET", "DBL", "EVT", "TRK", "VID", "ALL"};
22 | static const char *log_level_str[] = {"EMG", "ALR", "CRT", "ERR", "WRN", "NTC", "INF", "DBG", "ALL", NULL};
23 |
24 |
25 | /**
26 | * get_log_type
27 | *
28 | *
29 | * Returns: index of log type or 0 if not valid type.
30 | */
31 | int get_log_type(const char *type)
32 | {
33 | unsigned int i, ret = 0;
34 | unsigned int maxtype = sizeof(log_type_str)/sizeof(const char *);
35 |
36 | for (i = 1;i < maxtype; i++) {
37 | if (!strncasecmp(type, log_type_str[i], 3)) {
38 | ret = i;
39 | break;
40 | }
41 | }
42 |
43 | return ret;
44 | }
45 |
46 | /**
47 | * get_log_type_str
48 | * Gets string value for type log level.
49 | *
50 | * Returns: name of type log level.
51 | */
52 | const char* get_log_type_str(unsigned int type)
53 | {
54 | return log_type_str[type];
55 | }
56 |
57 | /**
58 | * set_log_type
59 | * Sets log type level.
60 | *
61 | * Returns: nothing.
62 | */
63 | void set_log_type(unsigned int type)
64 | {
65 | log_type = type;
66 | //printf("set log type %d\n", type);
67 | }
68 |
69 | /**
70 | * get_log_level_str
71 | * Gets string value for log level.
72 | *
73 | * Returns: name of log level.
74 | */
75 | const char* get_log_level_str(unsigned int level)
76 | {
77 | return log_level_str[level];
78 | }
79 |
80 | /**
81 | * set_log_level
82 | * Sets log level.
83 | *
84 | * Returns nothing.
85 | */
86 | void set_log_level(unsigned int level)
87 | {
88 | log_level = level;
89 | //printf("set log level %d\n", level);
90 | }
91 |
92 | /**
93 | * set_log_mode
94 | * Sets mode of logging , could be using syslog or files.
95 | *
96 | * Returns: nothing.
97 | */
98 | void set_log_mode(int mode)
99 | {
100 | log_mode = mode;
101 | //printf("set log mode %d\n", mode);
102 | }
103 |
104 | /**
105 | * set_logfile
106 | * Sets logfile to be used instead of syslog.
107 | *
108 | * Returns: pointer to log file.
109 | */
110 | FILE * set_logfile(const char *logfile_name)
111 | {
112 | log_mode = LOGMODE_SYSLOG; /* Setup temporary to let log if myfopen fails */
113 | logfile = myfopen(logfile_name, "a", 0);
114 |
115 | /* If logfile was opened correctly */
116 | if (logfile)
117 | log_mode = LOGMODE_FILE;
118 |
119 | return logfile;
120 | }
121 |
122 | /**
123 | * str_time
124 | *
125 | * Return: string with human readable time
126 | */
127 | static char *str_time(void)
128 | {
129 | static char buffer[16];
130 | time_t now = 0;
131 |
132 | now = time(0);
133 | strftime(buffer, 16, "%b %d %H:%M:%S", localtime(&now));
134 | return buffer;
135 | }
136 |
137 | /**
138 | * MOTION_LOG
139 | *
140 | * This routine is used for printing all informational, debug or error
141 | * messages produced by any of the other motion functions. It always
142 | * produces a message of the form "[n] {message}", and (if the param
143 | * 'errno_flag' is set) follows the message with the associated error
144 | * message from the library.
145 | *
146 | * Parameters:
147 | *
148 | * level logging level for the 'syslog' function
149 | *
150 | * type logging type.
151 | *
152 | * errno_flag if set, the log message should be followed by the
153 | * error message.
154 | * fmt the format string for producing the message
155 | * ap variable-length argument list
156 | *
157 | * Returns:
158 | * Nothing
159 | */
160 | void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, ...)
161 | {
162 | int errno_save, n;
163 | char buf[1024];
164 | /* GNU-specific strerror_r() */
165 | #if (!defined(XSI_STRERROR_R))
166 | char msg_buf[100];
167 | #endif
168 | va_list ap;
169 | int threadnr;
170 |
171 | /* Exit if level is greater than log_level */
172 | if ((unsigned int)level > log_level)
173 | return;
174 |
175 | /* Exit if type is not equal to log_type and not TYPE_ALL */
176 | if ((log_type != TYPE_ALL) && (type != log_type))
177 | return;
178 |
179 | //printf("log_type %d, type %d level %d\n", log_type, type, level);
180 |
181 | /*
182 | * If pthread_getspecific fails (e.g., because the thread's TLS doesn't
183 | * contain anything for thread number, it returns NULL which casts to zero,
184 | * which is nice because that's what we want in that case.
185 | */
186 | threadnr = (unsigned long)pthread_getspecific(tls_key_threadnr);
187 |
188 | /*
189 | * First we save the current 'error' value. This is required because
190 | * the subsequent calls to vsnprintf could conceivably change it!
191 | */
192 | errno_save = errno;
193 |
194 | /*
195 | * Prefix the message with the log level string, log type string,
196 | * time and thread number. e.g. [1] [ERR] [ENC] [Apr 03 00:08:44] blah
197 | *
198 | */
199 | if (!log_mode) {
200 | n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] [%s] ",
201 | threadnr, get_log_level_str(level), get_log_type_str(type),
202 | str_time());
203 | } else {
204 | /*
205 | * Prefix the message with the log level string, log type string
206 | * and thread number. e.g. [1] [DBG] [TRK] blah
207 | */
208 | n = snprintf(buf, sizeof(buf), "[%d] [%s] [%s] ",
209 | threadnr, get_log_level_str(level), get_log_type_str(type));
210 | }
211 |
212 | /* Next add the user's message. */
213 | va_start(ap, fmt);
214 | n += vsnprintf(buf + n, sizeof(buf) - n, fmt, ap);
215 |
216 | /* If errno_flag is set, add on the library error message. */
217 | if (errno_flag) {
218 | strncat(buf, ": ", 1024 - strlen(buf));
219 | n += 2;
220 | /*
221 | * This is bad - apparently gcc/libc wants to use the non-standard GNU
222 | * version of strerror_r, which doesn't actually put the message into
223 | * my buffer :-(. I have put in a 'hack' to get around this.
224 | */
225 | #if defined(XSI_STRERROR_R)
226 | #warning "************************************"
227 | #warning "* Using XSI-COMPLIANT strerror_r() *"
228 | #warning "************************************"
229 | /* XSI-compliant strerror_r() */
230 | strerror_r(errno_save, buf + n, sizeof(buf) - n); /* 2 for the ': ' */
231 | #else
232 | #warning "************************************"
233 | #warning "* Using GNU-COMPLIANT strerror_r() *"
234 | #warning "************************************"
235 | /* GNU-specific strerror_r() */
236 | strncat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)), 1024 - strlen(buf));
237 | #endif
238 | }
239 |
240 | if (!log_mode) {
241 | strncat(buf, "\n", 1024 - strlen(buf));
242 | fputs(buf, logfile);
243 | fflush(logfile);
244 |
245 | /* If log_mode, send the message to the syslog. */
246 | } else {
247 | syslog(level, "%s", buf);
248 | strncat(buf, "\n", 1024 - strlen(buf));
249 | fputs(buf, stderr);
250 | fflush(stderr);
251 | }
252 |
253 | /* Clean up the argument list routine. */
254 | va_end(ap);
255 | }
256 |
257 |
--------------------------------------------------------------------------------
/CODE_STANDARD:
--------------------------------------------------------------------------------
1 | Formatting rules for Motion code.
2 | Version 2.0 - 15 Jul 2008
3 |
4 | Note: To understand them you must view this document with spaces and tabs
5 | visible.
6 |
7 | --------------------
8 | RULE 1
9 | Code is generally indented using 4 spaces
10 |
11 | Example
12 | /* allocate some memory and check if that succeeded or not. If it failed
13 | * do some error logging and bail out
14 | */
15 | void * mymalloc(size_t nbytes)
16 | {
17 | void *dummy = malloc(nbytes);
18 | if (!dummy) {
19 | printf("Could not allocate %llu bytes of memory!\n", (unsigned long long) nbytes);
20 | syslog(EMERG, TYPE_ALL, "%s: Could not allocate %llu bytes of memory!",
21 | __FUNCTION__, (unsigned long long) nbytes);
22 | exit(1);
23 | }
24 |
25 | return dummy;
26 | }
27 |
28 | --------------------
29 | RULE 2
30 | If a line or statement is broken into two lines you will normally want the text
31 | in the 2nd line to align with text in the first line. The alignment is done
32 | using spaces making the code on the following lines appear in a natural way below
33 | the corresponding code above. Use common sense to enhance readability.
34 |
35 | Example
36 | /* allocate some memory and check if that succeeded or not. If it failed
37 | * do some error logging and bail out
38 | */
39 | void * mymalloc(size_t nbytes)
40 | {
41 | void *dummy = malloc(nbytes);
42 | if (!dummy) {
43 | printf("Could not allocate %llu bytes of memory!\n",
44 | (unsigned long long) nbytes);
45 | syslog(EMERG, TYPE_ALL,"Could not allocate %llu bytes of memory!",
46 | __FUNCTION__, (unsigned long long) nbytes);
47 | exit(1);
48 | }
49 |
50 | return dummy;
51 | }
52 |
53 | Example
54 | cnt->sql_mask = cnt->conf.sql_log_image * (FTYPE_IMAGE + FTYPE_IMAGE_MOTION) +
55 | cnt->conf.sql_log_snapshot * FTYPE_IMAGE_SNAPSHOT +
56 | cnt->conf.sql_log_mpeg * (FTYPE_MPEG + FTYPE_MPEG_MOTION) +
57 | cnt->conf.sql_log_timelapse * FTYPE_MPEG_TIMELAPSE;
58 |
59 |
60 |
61 | Example
62 | char msg[] = "This is a very long message which we would like to break"
63 | "into two lines or more because otherwise the line gets"
64 | "too long to read. We align them below each other for readability"
65 |
66 | --------------------
67 | RULE 3
68 | Never use TABS to align anything. A tab may be 4 positions in one editor
69 | and 8 in another. A space is always a space.
70 |
71 | --------------------
72 | RULE 4
73 | Functions should be written with this syntax.
74 |
75 | GOOD EXAMPLE
76 | /* Comment block
77 | * A comment block should be at least one line saying what the function does.
78 | * It is better to make several lines explaining what it does, what it takes
79 | * for arguments and what it returns. It is a bad idea to try to use tabs to
80 | * align text in the comment block
81 | */
82 | type function_name(parameters)
83 | {
84 | declarations
85 | declarations
86 |
87 | statements
88 | statements
89 | }
90 |
91 | Do not split the function declaration into two lines.
92 | Do not put the '{' after the function declaration. Put it on an empty line
93 | right after. Note that this rule is only for functions.
94 |
95 | BAD EXAMPLE
96 |
97 | type
98 | function_name(parameters) {
99 | declarations
100 | declarations
101 |
102 | statements
103 | statements
104 | }
105 |
106 | --------------------
107 | RULE 5
108 | Blocks follow K&R.
109 |
110 | GOOD EXAMPLE
111 |
112 | if ((picture=fopen(cnt->conf.mask_file, "r"))) {
113 | cnt->imgs.mask=get_pgm(cnt, picture, cnt->imgs.width, cnt->imgs.height);
114 | fclose(picture);
115 | } else {
116 | put_fixed_mask(cnt, cnt->conf.mask_file);
117 | printf("Hello world\n");
118 | }
119 |
120 |
121 | BAD EXAMPLE (even though Kenneth loves this one personally)
122 |
123 | if ((picture=fopen(cnt->conf.mask_file, "r")))
124 | {
125 | cnt->imgs.mask=get_pgm(cnt, picture, cnt->imgs.width, cnt->imgs.height);
126 | fclose(picture);
127 | }
128 | else
129 | {
130 | put_fixed_mask(cnt, cnt->conf.mask_file);
131 | printf("Hello world\n");
132 | }
133 |
134 |
135 |
136 | GOOD EXAMPLE
137 |
138 | switch (expr) {
139 | case ABC:
140 | case DEF:
141 | statement;
142 | break;
143 | case UVW:
144 | statement;
145 | break;
146 | default:
147 | /* default case */
148 | statement;
149 | }
150 |
151 | BAD EXAMPLE
152 |
153 | switch (expr) {
154 | case ABC:
155 | case DEF:
156 | statement;
157 | break;
158 | case UVW:
159 | statement;
160 | break;
161 | default:
162 | /* default case */
163 | statement;
164 | }
165 |
166 |
167 |
168 | --------------------
169 | RULE 6
170 | Whitespace.
171 | To ensure that Motion code looks homogeneous and to enhance readability:
172 | 1. Do not use a space before a comma
173 | 2. Always leave at least one space after a comma
174 | 3. Use one space between a block start statement and a '{'
175 | 4. Do not use a space between a function name and the '('
176 | 5. Use spaces to enhance readability (a non objective rule but at least
177 | think about it)
178 | 6. The '*' for pointers should be just before the variable name with no
179 | space.
180 |
181 | GOOD EXAMPLES
182 | int function_name(int *par1, int par2, int par3) {
183 | if (var1==2 || var2==3) {
184 |
185 | BAD EXAMPLES
186 | int function_name (int * par1 , int par2,int par3){
187 | if (var1==2||var2==3){
188 |
189 | --------------------
190 | RULE 7
191 | Comment your code
192 | That's worth repeating - PLEASE, PLEASE comment your code.
193 | We receive far too much code which is completely uncommented and where
194 | variable names are short and say nothing about their function.
195 | Use /* This style of comment for permament comments */ or
196 | /*
197 | * This style of comment for comments which
198 | * require more that one line
199 | */
200 | Use // this style comments for something you add temporarily while testing and
201 | FIXME type comments. It is much easier to spot the temporary comments this way.
202 |
203 | --------------------
204 | RULE 8
205 | Use variable names that say what the variable is used for.
206 | Avoid x,t,vt type variable names.
207 | Use names like image, image_buffer, image_height, output_buffer
208 | Short names like i and j for loop index variable are a known good practice.
209 | Variable and function names are in lower case. Use '_' to separate words.
210 | MACROS are in uppercase.
211 | camelCase (mix of upper and lower case) is not allowed because it creates too
212 | many typos for many two finger typers.
213 |
214 |
215 | --------------------
216 |
217 | BEST PRACTICES
218 | Not rules, but these suggestions make code easier to read.
219 |
220 | Use lots of white space and empty lines to group code.
221 | For example, large if statements are easier to read when there is an empty
222 | line before and after them.
223 |
224 | Use an empty line before a comment which describes the code lines below.
225 |
226 | Always use spaces in statements like
227 | thisvar->thismember>thisvar->thisothermember (bad)
228 | thisvar->thismember > thisvar->thisothermember (good)
229 |
230 | if (cnt->event_nr==cnt->prev_event||cnt->makemovie) (bad)
231 | if (cnt->event_nr == cnt->prev_event || cnt->makemovie) (good)
232 |
233 | frame_delay=(1000000L/cnt->conf.low_cpu)-frame_delay-elapsedtime; (bad)
234 | frame_delay = (1000000L / cnt->conf.low_cpu) - frame_delay - elapsedtime; (good)
235 |
236 |
237 | --------------------
238 |
239 | This document can probably be enhanced more as time goes by.
240 | Hope it helps developers to understand the ideas.
241 |
242 | What happens if I do not follow the rules?
243 | Your code will probably be accepted, but developers will have to spend a lot of
244 | time rewriting the code to follow the standard. If this happens, he may make
245 | a less-than-complimentary remark. Please help the developers by at least trying
246 | to follow the spirit of this document. We all have our coding preferences, but
247 | if Motion is coded in 40 different styles, readability (and at the end
248 | quality) will become bad.
249 |
--------------------------------------------------------------------------------
/vloopback_motion.c:
--------------------------------------------------------------------------------
1 | /*
2 | * vloopback_motion.c
3 | *
4 | * Video loopback functions for motion.
5 | * Copyright 2000 by Jeroen Vreeken (pe1rxq@amsat.org)
6 | * Copyright 2008 by Angel Carpintero (motiondevelop@gmail.com)
7 | * This software is distributed under the GNU public license version 2
8 | * See also the file 'COPYING'.
9 | *
10 | */
11 | #include "vloopback_motion.h"
12 | #if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L)) && (!defined(BSD))
13 | #include
14 | #include
15 |
16 | /**
17 | * v4l_open_vidpipe
18 | *
19 | */
20 | static int v4l_open_vidpipe(void)
21 | {
22 | int pipe_fd = -1;
23 | char pipepath[255];
24 | char buffer[255];
25 | char *major;
26 | char *minor;
27 | struct utsname uts;
28 |
29 | if (uname(&uts) < 0) {
30 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname");
31 | return -1;
32 | }
33 |
34 | major = strtok(uts.release, ".");
35 | minor = strtok(NULL, ".");
36 |
37 | if ((major == NULL) || (minor == NULL) || (strcmp(major, "2"))) {
38 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version");
39 | return -1;
40 | }
41 |
42 | if (strcmp(minor, "5") < 0) {
43 | FILE *vloopbacks;
44 | char *loop;
45 | char *input;
46 | char *istatus;
47 | char *output;
48 | char *ostatus;
49 |
50 | vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r");
51 |
52 | if (!vloopbacks) {
53 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open "
54 | "'/proc/video/vloopback/vloopbacks'");
55 | return -1;
56 | }
57 |
58 | /* Read vloopback version*/
59 | if (!fgets(buffer, sizeof(buffer), vloopbacks)) {
60 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version");
61 | myfclose(vloopbacks);
62 | return -1;
63 | }
64 |
65 | fprintf(stderr, "\t%s", buffer);
66 |
67 | /* Read explanation line */
68 |
69 | if (!fgets(buffer, sizeof(buffer), vloopbacks)) {
70 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback"
71 | " explanation line");
72 | myfclose(vloopbacks);
73 | return -1;
74 | }
75 |
76 | while (fgets(buffer, sizeof(buffer), vloopbacks)) {
77 | if (strlen(buffer) > 1) {
78 | buffer[strlen(buffer)-1] = 0;
79 | loop = strtok(buffer, "\t");
80 | input = strtok(NULL, "\t");
81 | istatus = strtok(NULL, "\t");
82 | output = strtok(NULL, "\t");
83 | ostatus = strtok(NULL, "\t");
84 |
85 | if (istatus[0] == '-') {
86 | snprintf(pipepath, sizeof(pipepath), "/dev/%s", input);
87 | pipe_fd = open(pipepath, O_RDWR);
88 |
89 | if (pipe_fd >= 0) {
90 | MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s "
91 | "\tOutput: /dev/%s", input, output);
92 | break;
93 | }
94 | }
95 | }
96 | }
97 |
98 | myfclose(vloopbacks);
99 | } else {
100 | DIR *dir;
101 | struct dirent *dirp;
102 | const char prefix[] = "/sys/class/video4linux/";
103 | char *ptr, *io;
104 | int fd;
105 | int low = 9999;
106 | int tfd;
107 | int tnum;
108 |
109 | if ((dir = opendir(prefix)) == NULL) {
110 | MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'",
111 | prefix);
112 | return -1;
113 | }
114 |
115 | while ((dirp = readdir(dir)) != NULL) {
116 | if (!strncmp(dirp->d_name, "video", 5)) {
117 | strncpy(buffer, prefix, sizeof(buffer));
118 | strncat(buffer, dirp->d_name, sizeof(buffer) - strlen(buffer));
119 | strncat(buffer, "/name", sizeof(buffer) - strlen(buffer));
120 |
121 | if ((fd = open(buffer, O_RDONLY)) >= 0) {
122 | if ((read(fd, buffer, sizeof(buffer)-1)) < 0) {
123 | close(fd);
124 | continue;
125 | }
126 |
127 | ptr = strtok(buffer, " ");
128 |
129 | if (strcmp(ptr, "Video")) {
130 | close(fd);
131 | continue;
132 | }
133 |
134 | major = strtok(NULL, " ");
135 | minor = strtok(NULL, " ");
136 | io = strtok(NULL, " \n");
137 |
138 | if (strcmp(major, "loopback") || strcmp(io, "input")) {
139 | close(fd);
140 | continue;
141 | }
142 |
143 | if ((ptr = strtok(buffer, " ")) == NULL) {
144 | close(fd);
145 | continue;
146 | }
147 |
148 | tnum = atoi(minor);
149 |
150 | if (tnum < low) {
151 | mystrcpy(buffer, "/dev/");
152 | strncat(buffer, dirp->d_name, sizeof(buffer) - strlen(buffer));
153 | if ((tfd = open(buffer, O_RDWR)) >= 0) {
154 | strncpy(pipepath, buffer, sizeof(pipepath));
155 |
156 | if (pipe_fd >= 0)
157 | close(pipe_fd);
158 |
159 | pipe_fd = tfd;
160 | low = tnum;
161 | }
162 | }
163 | close(fd);
164 | }
165 | }
166 | }
167 |
168 | closedir(dir);
169 |
170 | if (pipe_fd >= 0)
171 | MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input",
172 | pipepath);
173 | }
174 |
175 | return pipe_fd;
176 | }
177 |
178 | /**
179 | * v4l_startpipe
180 | *
181 | */
182 | static int v4l_startpipe(const char *dev_name, int width, int height, int type)
183 | {
184 | int dev;
185 | struct video_picture vid_pic;
186 | struct video_window vid_win;
187 |
188 | if (!strcmp(dev_name, "-")) {
189 | dev = v4l_open_vidpipe();
190 | } else {
191 | dev = open(dev_name, O_RDWR);
192 | MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input",
193 | dev_name);
194 | }
195 |
196 | if (dev < 0) {
197 | MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed",
198 | dev_name);
199 | return -1;
200 | }
201 |
202 | if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) {
203 | MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)");
204 | return -1;
205 | }
206 |
207 | vid_pic.palette = type;
208 |
209 | if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) {
210 | MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)");
211 | return -1;
212 | }
213 |
214 | if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) {
215 | MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)");
216 | return -1;
217 | }
218 |
219 | vid_win.height = height;
220 | vid_win.width = width;
221 |
222 | if (ioctl(dev, VIDIOCSWIN, &vid_win) == -1) {
223 | MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)");
224 | return -1;
225 | }
226 |
227 | return dev;
228 | }
229 |
230 | /**
231 | * v4l_putpipe
232 | *
233 | */
234 | static int v4l_putpipe(int dev, unsigned char *image, int size)
235 | {
236 | return write(dev, image, size);
237 | }
238 |
239 | /**
240 | * vid_startpipe
241 | *
242 | */
243 | int vid_startpipe(const char *dev_name, int width, int height, int type)
244 | {
245 | return v4l_startpipe(dev_name, width, height, type);
246 | }
247 |
248 | /**
249 | * vid_putpipe
250 | *
251 | */
252 | int vid_putpipe (int dev, unsigned char *image, int size)
253 | {
254 | return v4l_putpipe(dev, image, size);
255 | }
256 | #endif /* !WITHOUT_V4L && !BSD */
257 |
--------------------------------------------------------------------------------
/pwc-ioctl.h-pwc8.0:
--------------------------------------------------------------------------------
1 | #ifndef PWC_IOCTL_H
2 | #define PWC_IOCTL_H
3 |
4 | /* (C) 2001-2003 Nemosoft Unv. webcam@smcc.demon.nl
5 |
6 | This program is free software; you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation; either version 2 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program; if not, write to the Free Software
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 | */
20 |
21 | /* This is pwc-ioctl.h belonging to PWC 8.10 */
22 |
23 | /*
24 | Changes
25 | 2001/08/03 Alvarado Added ioctl constants to access methods for
26 | changing white balance and red/blue gains
27 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
28 | */
29 |
30 | /* These are private ioctl() commands, specific for the Philips webcams.
31 | They contain functions not found in other webcams, and settings not
32 | specified in the Video4Linux API.
33 |
34 | The #define names are built up like follows:
35 | VIDIOC VIDeo IOCtl prefix
36 | PWC Philps WebCam
37 | G optional: Get
38 | S optional: Set
39 | ... the function
40 | */
41 |
42 |
43 |
44 |
45 | /* The frame rate is encoded in the video_window.flags parameter using
46 | the upper 16 bits, since some flags are defined nowadays. The following
47 | defines provide a mask and shift to filter out this value.
48 |
49 | In 'Snapshot' mode the camera freezes its automatic exposure and colour
50 | balance controls.
51 | */
52 | #define PWC_FPS_SHIFT 16
53 | #define PWC_FPS_MASK 0x00FF0000
54 | #define PWC_FPS_FRMASK 0x003F0000
55 | #define PWC_FPS_SNAPSHOT 0x00400000
56 |
57 |
58 |
59 | struct pwc_probe
60 | {
61 | char name[32];
62 | int type;
63 | };
64 |
65 |
66 | /* pwc_whitebalance.mode values */
67 | #define PWC_WB_INDOOR 0
68 | #define PWC_WB_OUTDOOR 1
69 | #define PWC_WB_FL 2
70 | #define PWC_WB_MANUAL 3
71 | #define PWC_WB_AUTO 4
72 |
73 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
74 | Set mode to one of the PWC_WB_* values above.
75 | *red and *blue are the respective gains of these colour components inside
76 | the camera; range 0..65535
77 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
78 | otherwise undefined.
79 | 'read_red' and 'read_blue' are read-only.
80 | */
81 |
82 | struct pwc_whitebalance
83 | {
84 | int mode;
85 | int manual_red, manual_blue; /* R/W */
86 | int read_red, read_blue; /* R/O */
87 | };
88 |
89 | /*
90 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
91 | and tell the camera how fast it should react to changes in lighting, and
92 | with how much delay. Valid values are 0..65535.
93 | */
94 | struct pwc_wb_speed
95 | {
96 | int control_speed;
97 | int control_delay;
98 |
99 | };
100 |
101 | /* Used with VIDIOCPWC[SG]LED */
102 | struct pwc_leds
103 | {
104 | int led_on; /* Led on-time; range = 0..25000 */
105 | int led_off; /* Led off-time; range = 0..25000 */
106 | };
107 |
108 | /* Image size (used with GREALSIZE) */
109 | struct pwc_imagesize
110 | {
111 | int width;
112 | int height;
113 | };
114 |
115 | /* Defines and structures for Motorized Pan & Tilt */
116 | #define PWC_MPT_PAN 0x01
117 | #define PWC_MPT_TILT 0x02
118 | #define PWC_MPT_TIMEOUT 0x04 /* for status */
119 |
120 | /* Set angles; when absolute = 1, the angle is absolute and the
121 | driver calculates the relative offset for you. This can only
122 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
123 | absolute angles.
124 | */
125 | struct pwc_mpt_angles
126 | {
127 | int absolute; /* write-only */
128 | int pan; /* degrees * 100 */
129 | int tilt; /* degress * 100 */
130 | int zoom; /* N/A, set to -1 */
131 | };
132 |
133 | /* Range of angles of the camera, both horizontally and vertically.
134 | The zoom is not used, maybe in the future...
135 |
136 | */
137 | struct pwc_mpt_range
138 | {
139 | int pan_min, pan_max; /* degrees * 100 */
140 | int tilt_min, tilt_max;
141 | int zoom_min, zoom_max; /* -1, -1 */
142 | };
143 |
144 | struct pwc_mpt_status
145 | {
146 | int status;
147 | int time_pan;
148 | int time_tilt;
149 | };
150 |
151 |
152 | /* Restore user settings */
153 | #define VIDIOCPWCRUSER _IO('v', 192)
154 | /* Save user settings */
155 | #define VIDIOCPWCSUSER _IO('v', 193)
156 | /* Restore factory settings */
157 | #define VIDIOCPWCFACTORY _IO('v', 194)
158 |
159 | /* You can manipulate the compression factor. A compression preference of 0
160 | means use uncompressed modes when available; 1 is low compression, 2 is
161 | medium and 3 is high compression preferred. Of course, the higher the
162 | compression, the lower the bandwidth used but more chance of artefacts
163 | in the image. The driver automatically chooses a higher compression when
164 | the preferred mode is not available.
165 | */
166 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
167 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int)
168 | /* Get preferred compression quality */
169 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int)
170 |
171 |
172 | /* This is a probe function; since so many devices are supported, it
173 | becomes difficult to include all the names in programs that want to
174 | check for the enhanced Philips stuff. So in stead, try this PROBE;
175 | it returns a structure with the original name, and the corresponding
176 | Philips type.
177 | To use, fill the structure with zeroes, call PROBE and if that succeeds,
178 | compare the name with that returned from VIDIOCGCAP; they should be the
179 | same. If so, you can be assured it is a Philips (OEM) cam and the type
180 | is valid.
181 | */
182 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
183 |
184 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
185 | #define VIDIOCPWCSAGC _IOW('v', 200, int)
186 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
187 | #define VIDIOCPWCGAGC _IOR('v', 200, int)
188 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
189 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
190 |
191 | /* Color compensation (Auto White Balance) */
192 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
193 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
194 |
195 | /* Auto WB speed */
196 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
197 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
198 |
199 | /* LEDs on/off/blink; int range 0..65535 */
200 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
201 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
202 |
203 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
204 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
205 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
206 |
207 | /* Backlight compensation; 0 = off, otherwise on */
208 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
209 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
210 |
211 | /* Flickerless mode; = 0 off, otherwise on */
212 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int)
213 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int)
214 |
215 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
216 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
217 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
218 |
219 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
220 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
221 |
222 | /* Motorized pan & tilt functions */
223 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int)
224 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
225 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
226 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles)
227 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status)
228 |
229 | #endif
230 |
--------------------------------------------------------------------------------
/pwc-ioctl.h-pwc9.0.1:
--------------------------------------------------------------------------------
1 | #ifndef PWC_IOCTL_H
2 | #define PWC_IOCTL_H
3 |
4 | /* (C) 2001-2004 Nemosoft Unv. webcam@smcc.demon.nl
5 |
6 | This program is free software; you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation; either version 2 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program; if not, write to the Free Software
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 | */
20 |
21 | /* This is pwc-ioctl.h belonging to PWC 8.12.1
22 | It contains structures and defines to communicate from user space
23 | directly to the driver.
24 | */
25 |
26 | /*
27 | Changes
28 | 2001/08/03 Alvarado Added ioctl constants to access methods for
29 | changing white balance and red/blue gains
30 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
31 | 2003/12/13 Nemosft Unv. Some modifications to make interfacing to
32 | PWCX easier
33 | */
34 |
35 | /* These are private ioctl() commands, specific for the Philips webcams.
36 | They contain functions not found in other webcams, and settings not
37 | specified in the Video4Linux API.
38 |
39 | The #define names are built up like follows:
40 | VIDIOC VIDeo IOCtl prefix
41 | PWC Philps WebCam
42 | G optional: Get
43 | S optional: Set
44 | ... the function
45 | */
46 |
47 |
48 | /* Enumeration of image sizes */
49 | #define PSZ_SQCIF 0x00
50 | #define PSZ_QSIF 0x01
51 | #define PSZ_QCIF 0x02
52 | #define PSZ_SIF 0x03
53 | #define PSZ_CIF 0x04
54 | #define PSZ_VGA 0x05
55 | #define PSZ_MAX 6
56 |
57 |
58 | /* The frame rate is encoded in the video_window.flags parameter using
59 | the upper 16 bits, since some flags are defined nowadays. The following
60 | defines provide a mask and shift to filter out this value.
61 |
62 | In 'Snapshot' mode the camera freezes its automatic exposure and colour
63 | balance controls.
64 | */
65 | #define PWC_FPS_SHIFT 16
66 | #define PWC_FPS_MASK 0x00FF0000
67 | #define PWC_FPS_FRMASK 0x003F0000
68 | #define PWC_FPS_SNAPSHOT 0x00400000
69 |
70 |
71 | /* structure for transfering x & y coordinates */
72 | struct pwc_coord
73 | {
74 | int x, y; /* guess what */
75 | int size; /* size, or offset */
76 | };
77 |
78 |
79 | /* Used with VIDIOCPWCPROBE */
80 | struct pwc_probe
81 | {
82 | char name[32];
83 | int type;
84 | };
85 |
86 | struct pwc_serial
87 | {
88 | char serial[30]; /* String with serial number. Contains terminating 0 */
89 | };
90 |
91 | /* pwc_whitebalance.mode values */
92 | #define PWC_WB_INDOOR 0
93 | #define PWC_WB_OUTDOOR 1
94 | #define PWC_WB_FL 2
95 | #define PWC_WB_MANUAL 3
96 | #define PWC_WB_AUTO 4
97 |
98 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
99 | Set mode to one of the PWC_WB_* values above.
100 | *red and *blue are the respective gains of these colour components inside
101 | the camera; range 0..65535
102 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
103 | otherwise undefined.
104 | 'read_red' and 'read_blue' are read-only.
105 | */
106 | struct pwc_whitebalance
107 | {
108 | int mode;
109 | int manual_red, manual_blue; /* R/W */
110 | int read_red, read_blue; /* R/O */
111 | };
112 |
113 | /*
114 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
115 | and tell the camera how fast it should react to changes in lighting, and
116 | with how much delay. Valid values are 0..65535.
117 | */
118 | struct pwc_wb_speed
119 | {
120 | int control_speed;
121 | int control_delay;
122 |
123 | };
124 |
125 | /* Used with VIDIOCPWC[SG]LED */
126 | struct pwc_leds
127 | {
128 | int led_on; /* Led on-time; range = 0..25000 */
129 | int led_off; /* Led off-time; range = 0..25000 */
130 | };
131 |
132 | /* Image size (used with GREALSIZE) */
133 | struct pwc_imagesize
134 | {
135 | int width;
136 | int height;
137 | };
138 |
139 | /* Defines and structures for Motorized Pan & Tilt */
140 | #define PWC_MPT_PAN 0x01
141 | #define PWC_MPT_TILT 0x02
142 | #define PWC_MPT_TIMEOUT 0x04 /* for status */
143 |
144 | /* Set angles; when absolute != 0, the angle is absolute and the
145 | driver calculates the relative offset for you. This can only
146 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
147 | absolute angles.
148 | */
149 | struct pwc_mpt_angles
150 | {
151 | int absolute; /* write-only */
152 | int pan; /* degrees * 100 */
153 | int tilt; /* degress * 100 */
154 | };
155 |
156 | /* Range of angles of the camera, both horizontally and vertically.
157 | */
158 | struct pwc_mpt_range
159 | {
160 | int pan_min, pan_max; /* degrees * 100 */
161 | int tilt_min, tilt_max;
162 | };
163 |
164 | struct pwc_mpt_status
165 | {
166 | int status;
167 | int time_pan;
168 | int time_tilt;
169 | };
170 |
171 |
172 | /* This is used for out-of-kernel decompression. With it, you can get
173 | all the necessary information to initialize and use the decompressor
174 | routines in standalone applications.
175 | */
176 | struct pwc_video_command
177 | {
178 | int type; /* camera type (645, 675, 730, etc.) */
179 | int release; /* release number */
180 |
181 | int size; /* one of PSZ_* */
182 | int alternate;
183 | int command_len; /* length of USB video command */
184 | unsigned char command_buf[13]; /* Actual USB video command */
185 | int bandlength; /* >0 = compressed */
186 | int frame_size; /* Size of one (un)compressed frame */
187 | };
188 |
189 | /* Flags for PWCX subroutines. Not all modules honour all flags. */
190 | #define PWCX_FLAG_PLANAR 0x0001
191 | #define PWCX_FLAG_BAYER 0x0008
192 |
193 |
194 | /* IOCTL definitions */
195 |
196 | /* Restore user settings */
197 | #define VIDIOCPWCRUSER _IO('v', 192)
198 | /* Save user settings */
199 | #define VIDIOCPWCSUSER _IO('v', 193)
200 | /* Restore factory settings */
201 | #define VIDIOCPWCFACTORY _IO('v', 194)
202 |
203 | /* You can manipulate the compression factor. A compression preference of 0
204 | means use uncompressed modes when available; 1 is low compression, 2 is
205 | medium and 3 is high compression preferred. Of course, the higher the
206 | compression, the lower the bandwidth used but more chance of artefacts
207 | in the image. The driver automatically chooses a higher compression when
208 | the preferred mode is not available.
209 | */
210 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
211 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int)
212 | /* Get preferred compression quality */
213 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int)
214 |
215 |
216 | /* Retrieve serial number of camera */
217 | #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial)
218 |
219 | /* This is a probe function; since so many devices are supported, it
220 | becomes difficult to include all the names in programs that want to
221 | check for the enhanced Philips stuff. So in stead, try this PROBE;
222 | it returns a structure with the original name, and the corresponding
223 | Philips type.
224 | To use, fill the structure with zeroes, call PROBE and if that succeeds,
225 | compare the name with that returned from VIDIOCGCAP; they should be the
226 | same. If so, you can be assured it is a Philips (OEM) cam and the type
227 | is valid.
228 | */
229 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
230 |
231 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
232 | #define VIDIOCPWCSAGC _IOW('v', 200, int)
233 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
234 | #define VIDIOCPWCGAGC _IOR('v', 200, int)
235 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
236 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
237 |
238 | /* Color compensation (Auto White Balance) */
239 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
240 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
241 |
242 | /* Auto WB speed */
243 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
244 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
245 |
246 | /* LEDs on/off/blink; int range 0..65535 */
247 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
248 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
249 |
250 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
251 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
252 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
253 |
254 | /* Backlight compensation; 0 = off, otherwise on */
255 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
256 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
257 |
258 | /* Flickerless mode; = 0 off, otherwise on */
259 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int)
260 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int)
261 |
262 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
263 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
264 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
265 |
266 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
267 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
268 |
269 | /* Motorized pan & tilt functions */
270 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int)
271 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
272 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
273 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles)
274 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status)
275 |
276 | /* Get the USB set-video command; needed for initializing libpwcx */
277 | #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command)
278 |
279 | #endif
280 |
--------------------------------------------------------------------------------
/netcam_rtsp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "netcam_rtsp.h"
3 | #include "motion.h"
4 |
5 | #ifdef have_av_get_media_type_string
6 |
7 | /****************************************************
8 | * Duplicated static functions - FIXME
9 | ****************************************************/
10 |
11 | /**
12 | * netcam_check_buffsize
13 | *
14 | * This routine checks whether there is enough room in a buffer to copy
15 | * some additional data. If there is not enough room, it will re-allocate
16 | * the buffer and adjust it's size.
17 | *
18 | * Parameters:
19 | * buff Pointer to a netcam_image_buffer structure.
20 | * numbytes The number of bytes to be copied.
21 | *
22 | * Returns: Nothing
23 | */
24 | static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes)
25 | {
26 | int min_size_to_alloc;
27 | int real_alloc;
28 | int new_size;
29 |
30 | if ((buff->size - buff->used) >= numbytes)
31 | return;
32 |
33 | min_size_to_alloc = numbytes - (buff->size - buff->used);
34 | real_alloc = ((min_size_to_alloc / NETCAM_BUFFSIZE) * NETCAM_BUFFSIZE);
35 |
36 | if ((min_size_to_alloc - real_alloc) > 0)
37 | real_alloc += NETCAM_BUFFSIZE;
38 |
39 | new_size = buff->size + real_alloc;
40 |
41 | MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.",
42 | (int) buff->used, (int) buff->size,
43 | (int) buff->used, new_size);
44 |
45 | buff->ptr = myrealloc(buff->ptr, new_size,
46 | "netcam_check_buf_size");
47 | buff->size = new_size;
48 | }
49 |
50 | /****************************************************
51 | * End Duplicated static functions - FIXME
52 | ****************************************************/
53 |
54 | static int decode_packet(AVPacket *packet, netcam_buff_ptr buffer, AVFrame *frame, AVCodecContext *cc)
55 | {
56 | int check = 0;
57 | int ret = avcodec_decode_video2(cc, frame, &check, packet);
58 |
59 | if (ret < 0) {
60 | MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error decoding video packet");
61 | return 0;
62 | }
63 |
64 | if (check == 0) {
65 | // no frame could be decoded...keep trying
66 | return 0;
67 | }
68 |
69 | int frame_size = av_image_get_buffer_size(cc->pix_fmt, cc->width, cc->height, 1);
70 |
71 | /* Assure there's enough room in the buffer. */
72 | netcam_check_buffsize(buffer, frame_size);
73 |
74 | av_image_copy_to_buffer((uint8_t *)buffer->ptr, frame_size,
75 | (const uint8_t **)(frame->data), frame->linesize,
76 | cc->pix_fmt, cc->width, cc->height, 1);
77 |
78 | buffer->used = frame_size;
79 |
80 | return frame_size;
81 | }
82 |
83 | static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type)
84 | {
85 | int ret;
86 | AVStream *st;
87 | AVCodecContext *dec_ctx = NULL;
88 | AVCodec *dec = NULL;
89 | ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);
90 | if (ret < 0) {
91 | MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Could not find stream %s in input!", av_get_media_type_string(type));
92 | return ret;
93 | } else {
94 | *stream_idx = ret;
95 | st = fmt_ctx->streams[*stream_idx];
96 | /* find decoder for the stream */
97 | dec_ctx = st->codec;
98 | dec = avcodec_find_decoder(dec_ctx->codec_id);
99 | if (!dec) {
100 | MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to find %s codec!", av_get_media_type_string(type));
101 | return ret;
102 | }
103 | if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
104 | MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to open %s codec!", av_get_media_type_string(type));
105 | return ret;
106 | }
107 | }
108 | return 0;
109 | }
110 |
111 | /**
112 | * rtsp_new_context
113 | *
114 | * Create a new RTSP context structure.
115 | *
116 | * Parameters
117 | *
118 | * None
119 | *
120 | * Returns: Pointer to the newly-created structure, NULL if error.
121 | *
122 | */
123 | struct rtsp_context *rtsp_new_context(void)
124 | {
125 | struct rtsp_context *ret;
126 |
127 | /* Note that mymalloc will exit on any problem. */
128 | ret = mymalloc(sizeof(struct rtsp_context));
129 |
130 | memset(ret, 0, sizeof(struct rtsp_context));
131 |
132 | return ret;
133 | }
134 |
135 | /**
136 | * rtsp_free_context
137 | *
138 | * Free the resources allocated for this context.
139 | *
140 | * Parameters
141 | *
142 | * ctxt Pointer to the rtsp_context structure.
143 | *
144 | * Returns: Nothing
145 | *
146 | */
147 | static void rtsp_free_context(struct rtsp_context *ctxt)
148 | {
149 | if (ctxt == NULL)
150 | return;
151 |
152 | if (ctxt->path != NULL)
153 | free(ctxt->path);
154 |
155 | if (ctxt->user)
156 | free(ctxt->user);
157 |
158 | if (ctxt->pass)
159 | free(ctxt->pass);
160 |
161 | if (ctxt->format_context != NULL) {
162 | avformat_close_input(&ctxt->format_context);
163 | }
164 |
165 | if (ctxt->codec_context != NULL) {
166 | avcodec_close(ctxt->codec_context);
167 | }
168 |
169 | free(ctxt);
170 | }
171 |
172 | int rtsp_connect(netcam_context_ptr netcam)
173 | {
174 | if (netcam->rtsp == NULL) {
175 | netcam->rtsp = rtsp_new_context();
176 |
177 | if (netcam->rtsp == NULL) {
178 | MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to create context(%s)", netcam->rtsp->path);
179 | return -1;
180 | }
181 | }
182 |
183 | // open the network connection
184 | AVDictionary *opts = 0;
185 | av_dict_set(&opts, "rtsp_transport", "tcp", 0);
186 |
187 | int ret = avformat_open_input(&netcam->rtsp->format_context, netcam->rtsp->path, NULL, &opts);
188 | if (ret < 0) {
189 | MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open input(%s): %d - %s", netcam->rtsp->path, ret, av_err2str(ret));
190 | rtsp_free_context(netcam->rtsp);
191 | netcam->rtsp = NULL;
192 | return -1;
193 | }
194 |
195 | // fill out stream information
196 | ret = avformat_find_stream_info(netcam->rtsp->format_context, NULL);
197 | if (ret < 0) {
198 | MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to find stream info: %d", ret);
199 | rtsp_free_context(netcam->rtsp);
200 | netcam->rtsp = NULL;
201 | return -1;
202 | }
203 |
204 | ret = open_codec_context(&netcam->rtsp->video_stream_index, netcam->rtsp->format_context, AVMEDIA_TYPE_VIDEO);
205 | if (ret < 0) {
206 | MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open codec context: %d", ret);
207 | rtsp_free_context(netcam->rtsp);
208 | netcam->rtsp = NULL;
209 | return -1;
210 | }
211 |
212 | netcam->rtsp->codec_context = netcam->rtsp->format_context->streams[netcam->rtsp->video_stream_index]->codec;
213 |
214 | // start up the feed
215 | av_read_play(netcam->rtsp->format_context);
216 |
217 | return 0;
218 | }
219 |
220 | int netcam_read_rtsp_image(netcam_context_ptr netcam)
221 | {
222 | if (netcam->rtsp == NULL) {
223 | if (rtsp_connect(netcam) < 0) {
224 | return -1;
225 | }
226 | }
227 |
228 | AVCodecContext *cc = netcam->rtsp->codec_context;
229 | AVFormatContext *fc = netcam->rtsp->format_context;
230 | netcam_buff_ptr buffer;
231 |
232 | /* Point to our working buffer. */
233 | buffer = netcam->receiving;
234 | buffer->used = 0;
235 |
236 | AVFrame *frame = avcodec_alloc_frame();
237 |
238 | AVPacket packet;
239 |
240 | av_init_packet(&packet);
241 |
242 | packet.data = NULL;
243 | packet.size = 0;
244 |
245 | int size_decoded = 0;
246 | static int usual_size_decoded = 0;
247 |
248 | while (size_decoded == 0 && av_read_frame(fc, &packet) >= 0) {
249 |
250 | if(packet.stream_index != netcam->rtsp->video_stream_index) {
251 | // not our packet, skip
252 | continue;
253 | }
254 |
255 | size_decoded = decode_packet(&packet, buffer, frame, cc);
256 | }
257 |
258 | if (size_decoded == 0) {
259 | // something went wrong, end of stream?
260 | MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: invalid frame!");
261 | return -1;
262 | }
263 |
264 | if (size_decoded != usual_size_decoded) {
265 | MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: unusual frame size of %d!", size_decoded);
266 | usual_size_decoded = size_decoded;
267 | }
268 |
269 | // at this point, we are finished with the packet and frame, so free them.
270 | av_free_packet(&packet);
271 | av_free(frame);
272 |
273 | struct timeval curtime;
274 |
275 | if (gettimeofday(&curtime, NULL) < 0) {
276 | MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday");
277 | }
278 |
279 | netcam->receiving->image_time = curtime;
280 |
281 | /*
282 | * Calculate our "running average" time for this netcam's
283 | * frame transmissions (except for the first time).
284 | * Note that the average frame time is held in microseconds.
285 | */
286 | if (netcam->last_image.tv_sec) {
287 | netcam->av_frame_time = ((9.0 * netcam->av_frame_time) + 1000000.0 *
288 | (curtime.tv_sec - netcam->last_image.tv_sec) +
289 | (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0;
290 |
291 | MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f",
292 | netcam->av_frame_time);
293 | }
294 |
295 | netcam->last_image = curtime;
296 |
297 | netcam_buff *xchg;
298 |
299 | /*
300 | * read is complete - set the current 'receiving' buffer atomically
301 | * as 'latest', and make the buffer previously in 'latest' become
302 | * the new 'receiving'.
303 | */
304 | pthread_mutex_lock(&netcam->mutex);
305 |
306 | xchg = netcam->latest;
307 | netcam->latest = netcam->receiving;
308 | netcam->receiving = xchg;
309 | netcam->imgcnt++;
310 |
311 | /*
312 | * We have a new frame ready. We send a signal so that
313 | * any thread (e.g. the motion main loop) waiting for the
314 | * next frame to become available may proceed.
315 | */
316 | pthread_cond_signal(&netcam->pic_ready);
317 |
318 | pthread_mutex_unlock(&netcam->mutex);
319 |
320 | return 0;
321 | }
322 |
323 |
324 | void netcam_shutdown_rtsp(netcam_context_ptr netcam)
325 | {
326 | if (netcam->rtsp != NULL) {
327 | rtsp_free_context(netcam->rtsp);
328 | netcam->rtsp = NULL;
329 | }
330 | }
331 |
332 | #endif
333 |
--------------------------------------------------------------------------------
/pwc-ioctl.h-10.0.5:
--------------------------------------------------------------------------------
1 | #ifndef PWC_IOCTL_H
2 | #define PWC_IOCTL_H
3 |
4 | /* (C) 2001-2004 Nemosoft Unv.
5 | (C) 2004 Luc Saillard (luc@saillard.org)
6 |
7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
8 | driver and thus may have bugs that are not present in the original version.
9 | Please send bug reports and support requests to .
10 | The decompression routines have been implemented by reverse-engineering the
11 | Nemosoft binary pwcx module. Caveat emptor.
12 |
13 | This program is free software; you can redistribute it and/or modify
14 | it under the terms of the GNU General Public License as published by
15 | the Free Software Foundation; either version 2 of the License, or
16 | (at your option) any later version.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | GNU General Public License for more details.
22 |
23 | You should have received a copy of the GNU General Public License
24 | along with this program; if not, write to the Free Software
25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 | */
27 |
28 | /* This is pwc-ioctl.h belonging to PWC 8.12.1
29 | It contains structures and defines to communicate from user space
30 | directly to the driver.
31 | */
32 |
33 | /*
34 | Changes
35 | 2001/08/03 Alvarado Added ioctl constants to access methods for
36 | changing white balance and red/blue gains
37 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
38 | 2003/12/13 Nemosft Unv. Some modifications to make interfacing to
39 | PWCX easier
40 | */
41 |
42 | /* These are private ioctl() commands, specific for the Philips webcams.
43 | They contain functions not found in other webcams, and settings not
44 | specified in the Video4Linux API.
45 |
46 | The #define names are built up like follows:
47 | VIDIOC VIDeo IOCtl prefix
48 | PWC Philps WebCam
49 | G optional: Get
50 | S optional: Set
51 | ... the function
52 | */
53 |
54 |
55 | /* Enumeration of image sizes */
56 | #define PSZ_SQCIF 0x00
57 | #define PSZ_QSIF 0x01
58 | #define PSZ_QCIF 0x02
59 | #define PSZ_SIF 0x03
60 | #define PSZ_CIF 0x04
61 | #define PSZ_VGA 0x05
62 | #define PSZ_MAX 6
63 |
64 |
65 | /* The frame rate is encoded in the video_window.flags parameter using
66 | the upper 16 bits, since some flags are defined nowadays. The following
67 | defines provide a mask and shift to filter out this value.
68 |
69 | In 'Snapshot' mode the camera freezes its automatic exposure and colour
70 | balance controls.
71 | */
72 | #define PWC_FPS_SHIFT 16
73 | #define PWC_FPS_MASK 0x00FF0000
74 | #define PWC_FPS_FRMASK 0x003F0000
75 | #define PWC_FPS_SNAPSHOT 0x00400000
76 |
77 |
78 | /* structure for transfering x & y coordinates */
79 | struct pwc_coord
80 | {
81 | int x, y; /* guess what */
82 | int size; /* size, or offset */
83 | };
84 |
85 |
86 | /* Used with VIDIOCPWCPROBE */
87 | struct pwc_probe
88 | {
89 | char name[32];
90 | int type;
91 | };
92 |
93 | struct pwc_serial
94 | {
95 | char serial[30]; /* String with serial number. Contains terminating 0 */
96 | };
97 |
98 | /* pwc_whitebalance.mode values */
99 | #define PWC_WB_INDOOR 0
100 | #define PWC_WB_OUTDOOR 1
101 | #define PWC_WB_FL 2
102 | #define PWC_WB_MANUAL 3
103 | #define PWC_WB_AUTO 4
104 |
105 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
106 | Set mode to one of the PWC_WB_* values above.
107 | *red and *blue are the respective gains of these colour components inside
108 | the camera; range 0..65535
109 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
110 | otherwise undefined.
111 | 'read_red' and 'read_blue' are read-only.
112 | */
113 | struct pwc_whitebalance
114 | {
115 | int mode;
116 | int manual_red, manual_blue; /* R/W */
117 | int read_red, read_blue; /* R/O */
118 | };
119 |
120 | /*
121 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
122 | and tell the camera how fast it should react to changes in lighting, and
123 | with how much delay. Valid values are 0..65535.
124 | */
125 | struct pwc_wb_speed
126 | {
127 | int control_speed;
128 | int control_delay;
129 |
130 | };
131 |
132 | /* Used with VIDIOCPWC[SG]LED */
133 | struct pwc_leds
134 | {
135 | int led_on; /* Led on-time; range = 0..25000 */
136 | int led_off; /* Led off-time; range = 0..25000 */
137 | };
138 |
139 | /* Image size (used with GREALSIZE) */
140 | struct pwc_imagesize
141 | {
142 | int width;
143 | int height;
144 | };
145 |
146 | /* Defines and structures for Motorized Pan & Tilt */
147 | #define PWC_MPT_PAN 0x01
148 | #define PWC_MPT_TILT 0x02
149 | #define PWC_MPT_TIMEOUT 0x04 /* for status */
150 |
151 | /* Set angles; when absolute != 0, the angle is absolute and the
152 | driver calculates the relative offset for you. This can only
153 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
154 | absolute angles.
155 | */
156 | struct pwc_mpt_angles
157 | {
158 | int absolute; /* write-only */
159 | int pan; /* degrees * 100 */
160 | int tilt; /* degress * 100 */
161 | };
162 |
163 | /* Range of angles of the camera, both horizontally and vertically.
164 | */
165 | struct pwc_mpt_range
166 | {
167 | int pan_min, pan_max; /* degrees * 100 */
168 | int tilt_min, tilt_max;
169 | };
170 |
171 | struct pwc_mpt_status
172 | {
173 | int status;
174 | int time_pan;
175 | int time_tilt;
176 | };
177 |
178 |
179 | /* This is used for out-of-kernel decompression. With it, you can get
180 | all the necessary information to initialize and use the decompressor
181 | routines in standalone applications.
182 | */
183 | struct pwc_video_command
184 | {
185 | int type; /* camera type (645, 675, 730, etc.) */
186 | int release; /* release number */
187 |
188 | int size; /* one of PSZ_* */
189 | int alternate;
190 | int command_len; /* length of USB video command */
191 | unsigned char command_buf[13]; /* Actual USB video command */
192 | int bandlength; /* >0 = compressed */
193 | int frame_size; /* Size of one (un)compressed frame */
194 | };
195 |
196 | /* Flags for PWCX subroutines. Not all modules honour all flags. */
197 | #define PWCX_FLAG_PLANAR 0x0001
198 | #define PWCX_FLAG_BAYER 0x0008
199 |
200 |
201 | /* IOCTL definitions */
202 |
203 | /* Restore user settings */
204 | #define VIDIOCPWCRUSER _IO('v', 192)
205 | /* Save user settings */
206 | #define VIDIOCPWCSUSER _IO('v', 193)
207 | /* Restore factory settings */
208 | #define VIDIOCPWCFACTORY _IO('v', 194)
209 |
210 | /* You can manipulate the compression factor. A compression preference of 0
211 | means use uncompressed modes when available; 1 is low compression, 2 is
212 | medium and 3 is high compression preferred. Of course, the higher the
213 | compression, the lower the bandwidth used but more chance of artefacts
214 | in the image. The driver automatically chooses a higher compression when
215 | the preferred mode is not available.
216 | */
217 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
218 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int)
219 | /* Get preferred compression quality */
220 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int)
221 |
222 |
223 | /* Retrieve serial number of camera */
224 | #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial)
225 |
226 | /* This is a probe function; since so many devices are supported, it
227 | becomes difficult to include all the names in programs that want to
228 | check for the enhanced Philips stuff. So in stead, try this PROBE;
229 | it returns a structure with the original name, and the corresponding
230 | Philips type.
231 | To use, fill the structure with zeroes, call PROBE and if that succeeds,
232 | compare the name with that returned from VIDIOCGCAP; they should be the
233 | same. If so, you can be assured it is a Philips (OEM) cam and the type
234 | is valid.
235 | */
236 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
237 |
238 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
239 | #define VIDIOCPWCSAGC _IOW('v', 200, int)
240 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
241 | #define VIDIOCPWCGAGC _IOR('v', 200, int)
242 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
243 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
244 |
245 | /* Color compensation (Auto White Balance) */
246 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
247 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
248 |
249 | /* Auto WB speed */
250 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
251 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
252 |
253 | /* LEDs on/off/blink; int range 0..65535 */
254 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
255 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
256 |
257 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
258 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
259 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
260 |
261 | /* Backlight compensation; 0 = off, otherwise on */
262 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
263 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
264 |
265 | /* Flickerless mode; = 0 off, otherwise on */
266 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int)
267 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int)
268 |
269 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
270 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
271 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
272 |
273 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
274 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
275 |
276 | /* Motorized pan & tilt functions */
277 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int)
278 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
279 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
280 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles)
281 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status)
282 |
283 | /* Get the USB set-video command; needed for initializing libpwcx */
284 | #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command)
285 | struct pwc_table_init_buffer {
286 | int len;
287 | char *buffer;
288 |
289 | };
290 | #define VIDIOCPWCGVIDTABLE _IOR('v', 216, struct pwc_table_init_buffer)
291 |
292 | #endif
293 |
--------------------------------------------------------------------------------
/netcam_wget.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002
3 | Free Software Foundation, Inc.
4 |
5 | Additional Copyright (C) 2004-2005 Christopher Price,
6 | Angel Carpintero, and other contributing authors.
7 |
8 | Major part of this file is reused code from GNU Wget. It has been
9 | merged and modified for use in the program Motion which is also
10 | released under the terms of the GNU General Public License.
11 |
12 | GNU Wget and Motion is free software; you can redistribute it and/or
13 | modify it under the terms of the GNU General Public License as published
14 | by the Free Software Foundation; either version 2 of the License, or
15 | (at your option) any later version.
16 |
17 | GNU Wget is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | GNU General Public License for more details.
21 |
22 | You should have received a copy of the GNU General Public License
23 | along with Wget; if not, write to the Free Software
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 |
26 | #include "motion.h"
27 | #include
28 | #include
29 | #include
30 |
31 | #define MINVAL(x, y) ((x) < (y) ? (x) : (y))
32 |
33 | /* This file contains the generic routines for work with headers.
34 | Currently they are used only by HTTP in http.c, but they can be
35 | used by anything that cares about RFC822-style headers.
36 |
37 | Header is defined in RFC2068, as quoted below. Note that this
38 | definition is not HTTP-specific -- it is virtually
39 | indistinguishable from the one given in RFC822 or RFC1036.
40 |
41 | message-header = field-name ":" [ field-value ] CRLF
42 |
43 | field-name = token
44 | field-value = *( field-content | LWS )
45 |
46 | field-content =
49 |
50 | The public functions are header_get() and header_process(), which
51 | see. */
52 |
53 |
54 | /* Get a header from read-buffer RBUF and return it in *HDR.
55 |
56 | As defined in RFC2068 and elsewhere, a header can be folded into
57 | multiple lines if the continuation line begins with a space or
58 | horizontal TAB. Also, this function will accept a header ending
59 | with just LF instead of CRLF.
60 |
61 | The header may be of arbitrary length; the function will allocate
62 | as much memory as necessary for it to fit. It need not contain a
63 | `:', thus you can use it to retrieve, say, HTTP status line.
64 |
65 | All trailing whitespace is stripped from the header, and it is
66 | zero-terminated.
67 | */
68 | int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flags)
69 | {
70 | int i;
71 | int bufsize = 80;
72 |
73 | *hdr = (char *)mymalloc(bufsize);
74 |
75 | for (i = 0; 1; i++) {
76 | int res;
77 | /* #### Use DO_REALLOC? */
78 | if (i > bufsize - 1)
79 | *hdr = (char *)myrealloc(*hdr, (bufsize <<= 1), "");
80 |
81 | res = RBUF_READCHAR (netcam, *hdr + i);
82 |
83 | if (res == 1) {
84 | if ((*hdr)[i] == '\n') {
85 | if (!((flags & HG_NO_CONTINUATIONS) || i == 0
86 | || (i == 1 && (*hdr)[0] == '\r'))) {
87 | char next;
88 | /*
89 | * If the header is non-empty, we need to check if
90 | * it continues on to the other line. We do that by
91 | * peeking at the next character.
92 | */
93 | res = rbuf_peek(netcam, &next);
94 |
95 | if (res == 0) {
96 | (*hdr)[i] = '\0';
97 | return HG_EOF;
98 | } else if (res == -1) {
99 | (*hdr)[i] = '\0';
100 | return HG_ERROR;
101 | }
102 | /* If the next character is HT or SP, just continue. */
103 | if (next == '\t' || next == ' ')
104 | continue;
105 | }
106 |
107 | /*
108 | * Strip trailing whitespace. (*hdr)[i] is the newline;
109 | * decrement I until it points to the last available
110 | * whitespace.
111 | */
112 | while (i > 0 && isspace((*hdr)[i - 1]))
113 | --i;
114 |
115 | (*hdr)[i] = '\0';
116 | break;
117 | }
118 | } else if (res == 0) {
119 | (*hdr)[i] = '\0';
120 | return HG_EOF;
121 | } else {
122 | (*hdr)[i] = '\0';
123 | return HG_ERROR;
124 | }
125 | }
126 |
127 | return HG_OK;
128 | }
129 |
130 | /**
131 | * header_process
132 | *
133 | * Check whether HEADER begins with NAME and, if yes, skip the `:' and
134 | * the whitespace, and call PROCFUN with the arguments of HEADER's
135 | * contents (after the `:' and space) and ARG. Otherwise, return 0.
136 | */
137 | int header_process(const char *header, const char *name,
138 | int (*procfun)(const char *, void *), void *arg)
139 | {
140 | /* Check whether HEADER matches NAME. */
141 | while (*name && (tolower (*name) == tolower (*header)))
142 | ++name, ++header;
143 |
144 | if (*name || *header++ != ':')
145 | return 0;
146 |
147 | header += skip_lws (header);
148 | return ((*procfun) (header, arg));
149 | }
150 |
151 | /* Helper functions for use with header_process(). */
152 |
153 | /**
154 | * header_extract_number
155 | *
156 | * Extract a long integer from HEADER and store it to CLOSURE. If an
157 | * error is encountered, return 0, else 1.
158 | */
159 | int header_extract_number(const char *header, void *closure)
160 | {
161 | const char *p = header;
162 | long result;
163 |
164 | for (result = 0; isdigit (*p); p++)
165 | result = 10 * result + (*p - '0');
166 |
167 | /* Failure if no number present. */
168 | if (p == header)
169 | return 0;
170 |
171 | /* Skip trailing whitespace. */
172 | p += skip_lws (p);
173 |
174 | /* We return the value, even if a format error follows. */
175 | *(long *)closure = result;
176 |
177 | /* Indicate failure if trailing garbage is present. */
178 | if (*p)
179 | return 0;
180 |
181 | return 1;
182 | }
183 |
184 | /**
185 | * header_strdup
186 | *
187 | * Strdup HEADER, and place the pointer to CLOSURE.
188 | */
189 | int header_strdup(const char *header, void *closure)
190 | {
191 | *(char **)closure = mystrdup(header);
192 | return 1;
193 | }
194 |
195 |
196 | /**
197 | * skip_lws
198 | * Skip LWS (linear white space), if present. Returns number of
199 | * characters to skip.
200 | */
201 | int skip_lws(const char *string)
202 | {
203 | const char *p = string;
204 |
205 | while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
206 | ++p;
207 |
208 | return p - string;
209 | }
210 |
211 |
212 | /**
213 | * base64_encode
214 | *
215 | * Encode the string S of length LENGTH to base64 format and place it
216 | * to STORE. STORE will be 0-terminated, and must point to a writable
217 | * buffer of at least 1+BASE64_LENGTH(length) bytes.
218 | */
219 | void base64_encode(const char *s, char *store, int length)
220 | {
221 | /* Conversion table. */
222 | static const char tbl[64] = {
223 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
224 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
225 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
226 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
227 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
228 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
229 | 'w', 'x', 'y', 'z', '0', '1', '2', '3',
230 | '4', '5', '6', '7', '8', '9', '+', '/'
231 | };
232 |
233 | int i;
234 | unsigned char *p = (unsigned char *)store;
235 |
236 | /* Transform the 3x8 bits to 4x6 bits, as required by base64. */
237 | for (i = 0; i < length; i += 3) {
238 | *p++ = tbl[s[0] >> 2];
239 | *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
240 | *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
241 | *p++ = tbl[s[2] & 0x3f];
242 | s += 3;
243 | }
244 |
245 | /* Pad the result if necessary... */
246 | if (i == length + 1)
247 | *(p - 1) = '=';
248 | else if (i == length + 2)
249 | *(p - 1) = *(p - 2) = '=';
250 |
251 | /* ...and zero-terminate it. */
252 | *p = '\0';
253 | }
254 |
255 | /**
256 | * strdupdelim
257 | */
258 | char *strdupdelim(const char *beg, const char *end)
259 | {
260 | char *res = (char *)mymalloc(end - beg + 1);
261 | memcpy (res, beg, end - beg);
262 |
263 | res[end - beg] = '\0';
264 | return res;
265 | }
266 |
267 | /**
268 | * http_process_type
269 | */
270 | int http_process_type(const char *hdr, void *arg)
271 | {
272 | char **result = (char **)arg;
273 | /* Locate P on `;' or the terminating zero, whichever comes first. */
274 | const char *p = strchr (hdr, ';');
275 |
276 | if (!p)
277 | p = hdr + strlen (hdr);
278 |
279 | while (p > hdr && isspace (*(p - 1)))
280 | --p;
281 |
282 | *result = strdupdelim (hdr, p);
283 | return 1;
284 | }
285 |
286 | /**
287 | * rbuf_initialize
288 | *
289 | * This is a simple implementation of buffering IO-read functions.
290 | */
291 | void rbuf_initialize(netcam_context_ptr netcam)
292 | {
293 | netcam->response->buffer_pos = netcam->response->buffer;
294 | netcam->response->buffer_left = 0;
295 | }
296 |
297 | int rbuf_read_bufferful(netcam_context_ptr netcam)
298 | {
299 | return netcam_recv(netcam, netcam->response->buffer,
300 | sizeof (netcam->response->buffer));
301 | }
302 |
303 | /**
304 | * rbuf_peek
305 | *
306 | * Like rbuf_readchar(), only don't move the buffer position.
307 | */
308 | int rbuf_peek(netcam_context_ptr netcam, char *store)
309 | {
310 | if (!netcam->response->buffer_left) {
311 | int res;
312 | rbuf_initialize(netcam);
313 | res = netcam_recv (netcam, netcam->response->buffer,
314 | sizeof (netcam->response->buffer));
315 |
316 | if (res <= 0) {
317 | *store = '\0';
318 | return res;
319 | }
320 |
321 | netcam->response->buffer_left = res;
322 | }
323 |
324 | *store = *netcam->response->buffer_pos;
325 | return 1;
326 | }
327 |
328 | /**
329 | * rbuf_flush
330 | *
331 | * Flush RBUF's buffer to WHERE. Flush MAXSIZE bytes at most.
332 | * Returns the number of bytes actually copied. If the buffer is
333 | * empty, 0 is returned.
334 | */
335 | int rbuf_flush(netcam_context_ptr netcam, char *where, int maxsize)
336 | {
337 | if (!netcam->response->buffer_left) {
338 | return 0;
339 | } else {
340 | int howmuch = MINVAL ((int)netcam->response->buffer_left, maxsize);
341 |
342 | if (where)
343 | memcpy(where, netcam->response->buffer_pos, howmuch);
344 |
345 | netcam->response->buffer_left -= howmuch;
346 | netcam->response->buffer_pos += howmuch;
347 | return howmuch;
348 | }
349 | }
350 |
351 | /**
352 | * http_result_code
353 | *
354 | * Get the HTTP result code
355 | */
356 | int http_result_code(const char *header)
357 | {
358 | char *cptr;
359 |
360 | /* Assure the header starts out right. */
361 | if (strncmp(header, "HTTP", 4))
362 | return -1;
363 |
364 | /* Find the space following the HTTP/1.x */
365 | if ((cptr = strchr(header+4, ' ')) == NULL)
366 | return -1;
367 |
368 | return atoi(cptr + 1);
369 | }
370 |
371 |
--------------------------------------------------------------------------------
/md5.c:
--------------------------------------------------------------------------------
1 | /*
2 | * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
3 | * taken from RFC 1321
4 | */
5 |
6 | /*
7 | Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
8 | rights reserved.
9 |
10 | License to copy and use this software is granted provided that it
11 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest
12 | Algorithm" in all material mentioning or referencing this software
13 | or this function.
14 |
15 | License is also granted to make and use derivative works provided
16 | that such works are identified as "derived from the RSA Data
17 | Security, Inc. MD5 Message-Digest Algorithm" in all material
18 | mentioning or referencing the derived work.
19 |
20 | RSA Data Security, Inc. makes no representations concerning either
21 | the merchantability of this software or the suitability of this
22 | software for any particular purpose. It is provided "as is"
23 | without express or implied warranty of any kind.
24 |
25 | These notices must be retained in any copies of any part of this
26 | documentation and/or software.
27 | */
28 |
29 | #include "md5.h"
30 |
31 | /*
32 | * Constants for MD5Transform routine.
33 | */
34 |
35 | #define S11 7
36 | #define S12 12
37 | #define S13 17
38 | #define S14 22
39 | #define S21 5
40 | #define S22 9
41 | #define S23 14
42 | #define S24 20
43 | #define S31 4
44 | #define S32 11
45 | #define S33 16
46 | #define S34 23
47 | #define S41 6
48 | #define S42 10
49 | #define S43 15
50 | #define S44 21
51 |
52 | static void MD5Transform(UINT4 [4], unsigned char [64]);
53 | static void Encode(unsigned char *, UINT4 *, unsigned int);
54 | static void Decode(UINT4 *, unsigned char *, unsigned int);
55 | static void MD5_memcpy(POINTER, POINTER, unsigned int);
56 | static void MD5_memset(POINTER, int, unsigned int);
57 |
58 | static unsigned char PADDING[64] = {
59 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
62 | };
63 |
64 | /*
65 | * F, G, H and I are basic MD5 functions.
66 | */
67 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
68 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
69 | #define H(x, y, z) ((x) ^ (y) ^ (z))
70 | #define I(x, y, z) ((y) ^ ((x) | (~z)))
71 |
72 | /*
73 | * ROTATE_LEFT rotates x left n bits.
74 | */
75 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
76 |
77 | /*
78 | * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
79 | * Rotation is separate from addition to prevent recomputation.
80 | */
81 | #define FF(a, b, c, d, x, s, ac) { \
82 | (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
83 | (a) = ROTATE_LEFT ((a), (s)); \
84 | (a) += (b); \
85 | }
86 | #define GG(a, b, c, d, x, s, ac) { \
87 | (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
88 | (a) = ROTATE_LEFT ((a), (s)); \
89 | (a) += (b); \
90 | }
91 | #define HH(a, b, c, d, x, s, ac) { \
92 | (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
93 | (a) = ROTATE_LEFT ((a), (s)); \
94 | (a) += (b); \
95 | }
96 | #define II(a, b, c, d, x, s, ac) { \
97 | (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
98 | (a) = ROTATE_LEFT ((a), (s)); \
99 | (a) += (b); \
100 | }
101 |
102 | /*
103 | * MD5 initialization. Begins an MD5 operation, writing a new context.
104 | */
105 | void MD5Init(MD5_CTX *context)
106 | {
107 | context->count[0] = context->count[1] = 0;
108 | /* Load magic initialization constants. */
109 | context->state[0] = 0x67452301;
110 | context->state[1] = 0xefcdab89;
111 | context->state[2] = 0x98badcfe;
112 | context->state[3] = 0x10325476;
113 | }
114 |
115 | /*
116 | * MD5 block update operation. Continues an MD5 message-digest
117 | * operation, processing another message block, and updating the
118 | * context.
119 | */
120 | void MD5Update (
121 | MD5_CTX *context, /* context */
122 | unsigned char *input, /* input block */
123 | unsigned int inputLen) /* length of input block */
124 | {
125 | unsigned int i, index, partLen;
126 |
127 | /* Compute number of bytes mod 64 */
128 | index = (unsigned int)((context->count[0] >> 3) & 0x3F);
129 |
130 | /* Update number of bits */
131 | if ((context->count[0] += ((UINT4)inputLen << 3))
132 | < ((UINT4)inputLen << 3))
133 | context->count[1]++;
134 | context->count[1] += ((UINT4)inputLen >> 29);
135 |
136 | partLen = 64 - index;
137 |
138 | /* Transform as many times as possible. */
139 | if (inputLen >= partLen) {
140 | MD5_memcpy
141 | ((POINTER)&context->buffer[index], (POINTER)input, partLen);
142 | MD5Transform (context->state, context->buffer);
143 |
144 | for (i = partLen; i + 63 < inputLen; i += 64)
145 | MD5Transform (context->state, &input[i]);
146 |
147 | index = 0;
148 | }
149 | else
150 | i = 0;
151 |
152 | /* Buffer remaining input */
153 | MD5_memcpy
154 | ((POINTER)&context->buffer[index], (POINTER)&input[i],
155 | inputLen-i);
156 | }
157 |
158 | /*
159 | * MD5 finalization. Ends an MD5 message-digest operation, writing the
160 | * the message digest and zeroizing the context.
161 | */
162 | void MD5Final (
163 | unsigned char digest[16], /* message digest */
164 | MD5_CTX *context) /* context */
165 | {
166 | unsigned char bits[8];
167 | unsigned int index, padLen;
168 |
169 | /* Save number of bits */
170 | Encode (bits, context->count, 8);
171 |
172 | /* Pad out to 56 mod 64. */
173 | index = (unsigned int)((context->count[0] >> 3) & 0x3f);
174 | padLen = (index < 56) ? (56 - index) : (120 - index);
175 | MD5Update (context, PADDING, padLen);
176 |
177 | /* Append length (before padding) */
178 | MD5Update (context, bits, 8);
179 |
180 | /* Store state in digest */
181 | Encode (digest, context->state, 16);
182 |
183 | /* Zeroize sensitive information. */
184 | MD5_memset ((POINTER)context, 0, sizeof (*context));
185 | }
186 |
187 | /*
188 | * MD5 basic transformation. Transforms state based on block.
189 | */
190 | static void MD5Transform (state, block)
191 | UINT4 state[4];
192 | unsigned char block[64];
193 | {
194 | UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
195 |
196 | Decode (x, block, 64);
197 |
198 | /* Round 1 */
199 | FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
200 | FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
201 | FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
202 | FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
203 | FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
204 | FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
205 | FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
206 | FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
207 | FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
208 | FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
209 | FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
210 | FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
211 | FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
212 | FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
213 | FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
214 | FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
215 |
216 | /* Round 2 */
217 | GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
218 | GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
219 | GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
220 | GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
221 | GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
222 | GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
223 | GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
224 | GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
225 | GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
226 | GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
227 | GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
228 | GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
229 | GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
230 | GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
231 | GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
232 | GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
233 |
234 | /* Round 3 */
235 | HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
236 | HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
237 | HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
238 | HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
239 | HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
240 | HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
241 | HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
242 | HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
243 | HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
244 | HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
245 | HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
246 | HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
247 | HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
248 | HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
249 | HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
250 | HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
251 |
252 | /* Round 4 */
253 | II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
254 | II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
255 | II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
256 | II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
257 | II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
258 | II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
259 | II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
260 | II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
261 | II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
262 | II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
263 | II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
264 | II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
265 | II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
266 | II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
267 | II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
268 | II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
269 |
270 | state[0] += a;
271 | state[1] += b;
272 | state[2] += c;
273 | state[3] += d;
274 |
275 | /* Zeroize sensitive information. */
276 | MD5_memset ((POINTER)x, 0, sizeof (x));
277 | }
278 |
279 | /*
280 | * Encodes input (UINT4) into output (unsigned char). Assumes len is
281 | * a multiple of 4.
282 | */
283 | static void Encode (output, input, len)
284 | unsigned char *output;
285 | UINT4 *input;
286 | unsigned int len;
287 | {
288 | unsigned int i, j;
289 |
290 | for (i = 0, j = 0; j < len; i++, j += 4) {
291 | output[j] = (unsigned char)(input[i] & 0xff);
292 | output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
293 | output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
294 | output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
295 | }
296 | }
297 |
298 | /*
299 | * Decodes input (unsigned char) into output (UINT4). Assumes len is
300 | * a multiple of 4.
301 | */
302 | static void Decode (output, input, len)
303 | UINT4 *output;
304 | unsigned char *input;
305 | unsigned int len;
306 | {
307 | unsigned int i, j;
308 |
309 | for (i = 0, j = 0; j < len; i++, j += 4)
310 | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
311 | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
312 | }
313 |
314 | /* Note: Replace "for loop" with standard memcpy if possible. */
315 |
316 | static void MD5_memcpy (output, input, len)
317 | POINTER output;
318 | POINTER input;
319 | unsigned int len;
320 | {
321 | unsigned int i;
322 |
323 | for (i = 0; i < len; i++)
324 | output[i] = input[i];
325 | }
326 |
327 | /* Note: Replace "for loop" with standard memset if possible. */
328 | static void MD5_memset (output, value, len)
329 | POINTER output;
330 | int value;
331 | unsigned int len;
332 | {
333 | unsigned int i;
334 |
335 | for (i = 0; i < len; i++)
336 | ((char *)output)[i] = (char)value;
337 | }
338 |
339 | void MD5(unsigned char *message,unsigned long message_length,unsigned char *md)
340 | {
341 | MD5_CTX state;
342 |
343 | MD5Init(&state);
344 | MD5Update(&state,message,message_length);
345 | MD5Final(md,&state);
346 |
347 | return;
348 | }
349 |
--------------------------------------------------------------------------------
/pwc-ioctl.h:
--------------------------------------------------------------------------------
1 | #ifndef PWC_IOCTL_H
2 | #define PWC_IOCTL_H
3 |
4 | /* (C) 2001-2004 Nemosoft Unv.
5 | (C) 2004-2006 Luc Saillard (luc@saillard.org)
6 |
7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
8 | driver and thus may have bugs that are not present in the original version.
9 | Please send bug reports and support requests to .
10 | The decompression routines have been implemented by reverse-engineering the
11 | Nemosoft binary pwcx module. Caveat emptor.
12 |
13 | This program is free software; you can redistribute it and/or modify
14 | it under the terms of the GNU General Public License as published by
15 | the Free Software Foundation; either version 2 of the License, or
16 | (at your option) any later version.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | GNU General Public License for more details.
22 |
23 | You should have received a copy of the GNU General Public License
24 | along with this program; if not, write to the Free Software
25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 | */
27 |
28 | /* This is pwc-ioctl.h belonging to PWC 10.0.10
29 | It contains structures and defines to communicate from user space
30 | directly to the driver.
31 | */
32 |
33 | /*
34 | Changes
35 | 2001/08/03 Alvarado Added ioctl constants to access methods for
36 | changing white balance and red/blue gains
37 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
38 | 2003/12/13 Nemosft Unv. Some modifications to make interfacing to
39 | PWCX easier
40 | 2006/01/01 Luc Saillard Add raw format definition
41 | */
42 |
43 | /* These are private ioctl() commands, specific for the Philips webcams.
44 | They contain functions not found in other webcams, and settings not
45 | specified in the Video4Linux API.
46 |
47 | The #define names are built up like follows:
48 | VIDIOC VIDeo IOCtl prefix
49 | PWC Philps WebCam
50 | G optional: Get
51 | S optional: Set
52 | ... the function
53 | */
54 |
55 | #if (!defined(BSD))
56 | #include
57 | #include
58 |
59 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 10)
60 | /* Compatibility for older kernel */
61 | typedef __u16 __le16;
62 | #endif
63 |
64 | #endif /* ( !BSD ) */
65 |
66 | /* Enumeration of image sizes */
67 | #define PSZ_SQCIF 0x00
68 | #define PSZ_QSIF 0x01
69 | #define PSZ_QCIF 0x02
70 | #define PSZ_SIF 0x03
71 | #define PSZ_CIF 0x04
72 | #define PSZ_VGA 0x05
73 | #define PSZ_MAX 6
74 |
75 |
76 | /* The frame rate is encoded in the video_window.flags parameter using
77 | the upper 16 bits, since some flags are defined nowadays. The following
78 | defines provide a mask and shift to filter out this value.
79 | This value can also be passing using the private flag when using v4l2 and
80 | VIDIOC_S_FMT ioctl.
81 |
82 | In 'Snapshot' mode the camera freezes its automatic exposure and colour
83 | balance controls.
84 | */
85 | #define PWC_FPS_SHIFT 16
86 | #define PWC_FPS_MASK 0x00FF0000
87 | #define PWC_FPS_FRMASK 0x003F0000
88 | #define PWC_FPS_SNAPSHOT 0x00400000
89 | #define PWC_QLT_MASK 0x03000000
90 | #define PWC_QLT_SHIFT 24
91 |
92 |
93 | /* structure for transferring x & y coordinates */
94 | struct pwc_coord
95 | {
96 | int x, y; /* guess what */
97 | int size; /* size, or offset */
98 | };
99 |
100 |
101 | /* Used with VIDIOCPWCPROBE */
102 | struct pwc_probe
103 | {
104 | char name[32];
105 | int type;
106 | };
107 |
108 | struct pwc_serial
109 | {
110 | char serial[30]; /* String with serial number. Contains terminating 0 */
111 | };
112 |
113 | /* pwc_whitebalance.mode values */
114 | #define PWC_WB_INDOOR 0
115 | #define PWC_WB_OUTDOOR 1
116 | #define PWC_WB_FL 2
117 | #define PWC_WB_MANUAL 3
118 | #define PWC_WB_AUTO 4
119 |
120 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
121 | Set mode to one of the PWC_WB_* values above.
122 | *red and *blue are the respective gains of these colour components inside
123 | the camera; range 0..65535
124 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
125 | otherwise undefined.
126 | 'read_red' and 'read_blue' are read-only.
127 | */
128 | struct pwc_whitebalance
129 | {
130 | int mode;
131 | int manual_red, manual_blue; /* R/W */
132 | int read_red, read_blue; /* R/O */
133 | };
134 |
135 | /*
136 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
137 | and tell the camera how fast it should react to changes in lighting, and
138 | with how much delay. Valid values are 0..65535.
139 | */
140 | struct pwc_wb_speed
141 | {
142 | int control_speed;
143 | int control_delay;
144 |
145 | };
146 |
147 | /* Used with VIDIOCPWC[SG]LED */
148 | struct pwc_leds
149 | {
150 | int led_on; /* Led on-time; range = 0..25000 */
151 | int led_off; /* Led off-time; range = 0..25000 */
152 | };
153 |
154 | /* Image size (used with GREALSIZE) */
155 | struct pwc_imagesize
156 | {
157 | int width;
158 | int height;
159 | };
160 |
161 | /* Defines and structures for Motorized Pan & Tilt */
162 | #define PWC_MPT_PAN 0x01
163 | #define PWC_MPT_TILT 0x02
164 | #define PWC_MPT_TIMEOUT 0x04 /* for status */
165 |
166 | /* Set angles; when absolute != 0, the angle is absolute and the
167 | driver calculates the relative offset for you. This can only
168 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
169 | absolute angles.
170 | */
171 | struct pwc_mpt_angles
172 | {
173 | int absolute; /* write-only */
174 | int pan; /* degrees * 100 */
175 | int tilt; /* degress * 100 */
176 | };
177 |
178 | /* Range of angles of the camera, both horizontally and vertically.
179 | */
180 | struct pwc_mpt_range
181 | {
182 | int pan_min, pan_max; /* degrees * 100 */
183 | int tilt_min, tilt_max;
184 | };
185 |
186 | struct pwc_mpt_status
187 | {
188 | int status;
189 | int time_pan;
190 | int time_tilt;
191 | };
192 |
193 |
194 | /* This is used for out-of-kernel decompression. With it, you can get
195 | all the necessary information to initialize and use the decompressor
196 | routines in standalone applications.
197 | */
198 | struct pwc_video_command
199 | {
200 | int type; /* camera type (645, 675, 730, etc.) */
201 | int release; /* release number */
202 |
203 | int size; /* one of PSZ_* */
204 | int alternate;
205 | int command_len; /* length of USB video command */
206 | unsigned char command_buf[13]; /* Actual USB video command */
207 | int bandlength; /* >0 = compressed */
208 | int frame_size; /* Size of one (un)compressed frame */
209 | };
210 |
211 | /* Flags for PWCX subroutines. Not all modules honour all flags. */
212 | #define PWCX_FLAG_PLANAR 0x0001
213 | #define PWCX_FLAG_BAYER 0x0008
214 |
215 |
216 | /* IOCTL definitions */
217 |
218 | /* Restore user settings */
219 | #define VIDIOCPWCRUSER _IO('v', 192)
220 | /* Save user settings */
221 | #define VIDIOCPWCSUSER _IO('v', 193)
222 | /* Restore factory settings */
223 | #define VIDIOCPWCFACTORY _IO('v', 194)
224 |
225 | /* You can manipulate the compression factor. A compression preference of 0
226 | means use uncompressed modes when available; 1 is low compression, 2 is
227 | medium and 3 is high compression preferred. Of course, the higher the
228 | compression, the lower the bandwidth used but more chance of artefacts
229 | in the image. The driver automatically chooses a higher compression when
230 | the preferred mode is not available.
231 | */
232 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
233 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int)
234 | /* Get preferred compression quality */
235 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int)
236 |
237 |
238 | /* Retrieve serial number of camera */
239 | #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial)
240 |
241 | /* This is a probe function; since so many devices are supported, it
242 | becomes difficult to include all the names in programs that want to
243 | check for the enhanced Philips stuff. So in stead, try this PROBE;
244 | it returns a structure with the original name, and the corresponding
245 | Philips type.
246 | To use, fill the structure with zeroes, call PROBE and if that succeeds,
247 | compare the name with that returned from VIDIOCGCAP; they should be the
248 | same. If so, you can be assured it is a Philips (OEM) cam and the type
249 | is valid.
250 | */
251 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
252 |
253 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
254 | #define VIDIOCPWCSAGC _IOW('v', 200, int)
255 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
256 | #define VIDIOCPWCGAGC _IOR('v', 200, int)
257 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
258 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
259 |
260 | /* Color compensation (Auto White Balance) */
261 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
262 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
263 |
264 | /* Auto WB speed */
265 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
266 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
267 |
268 | /* LEDs on/off/blink; int range 0..65535 */
269 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
270 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
271 |
272 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
273 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
274 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
275 |
276 | /* Backlight compensation; 0 = off, otherwise on */
277 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
278 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
279 |
280 | /* Flickerless mode; = 0 off, otherwise on */
281 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int)
282 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int)
283 |
284 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
285 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
286 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
287 |
288 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
289 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
290 |
291 | /* Motorized pan & tilt functions */
292 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int)
293 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
294 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
295 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles)
296 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status)
297 |
298 | /* Get the USB set-video command; needed for initializing libpwcx */
299 | #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command)
300 | struct pwc_table_init_buffer {
301 | int len;
302 | char *buffer;
303 | };
304 | #define VIDIOCPWCGVIDTABLE _IOR('v', 216, struct pwc_table_init_buffer)
305 |
306 | /*
307 | * This is private command used when communicating with v4l2.
308 | * In the future all private ioctl will be remove/replace to
309 | * use interface offer by v4l2.
310 | */
311 |
312 | #if (defined(MOTION_V4L2)) && (!defined(BSD))
313 |
314 | #define V4L2_CID_PRIVATE_SAVE_USER (V4L2_CID_PRIVATE_BASE + 0)
315 | #define V4L2_CID_PRIVATE_RESTORE_USER (V4L2_CID_PRIVATE_BASE + 1)
316 | #define V4L2_CID_PRIVATE_RESTORE_FACTORY (V4L2_CID_PRIVATE_BASE + 2)
317 | #define V4L2_CID_PRIVATE_COLOUR_MODE (V4L2_CID_PRIVATE_BASE + 3)
318 | #define V4L2_CID_PRIVATE_AUTOCONTOUR (V4L2_CID_PRIVATE_BASE + 4)
319 | #define V4L2_CID_PRIVATE_CONTOUR (V4L2_CID_PRIVATE_BASE + 5)
320 | #define V4L2_CID_PRIVATE_BACKLIGHT (V4L2_CID_PRIVATE_BASE + 6)
321 | #define V4L2_CID_PRIVATE_FLICKERLESS (V4L2_CID_PRIVATE_BASE + 7)
322 | #define V4L2_CID_PRIVATE_NOISE_REDUCTION (V4L2_CID_PRIVATE_BASE + 8)
323 |
324 | struct pwc_raw_frame {
325 | __le16 type; /* type of the webcam */
326 | __le16 vbandlength; /* Size of 4lines compressed (used by the decompressor) */
327 | __u8 cmd[4]; /* the four byte of the command (in case of nala,
328 | only the first 3 bytes is filled) */
329 | __u8 rawframe[0]; /* frame_size = H/4*vbandlength */
330 | } __attribute__ ((packed));
331 |
332 | #endif /* MOTION_V4L2 && (! BSD ) */
333 |
334 | #endif
335 |
--------------------------------------------------------------------------------
/pwc-ioctl.h-10.0.10:
--------------------------------------------------------------------------------
1 | #ifndef PWC_IOCTL_H
2 | #define PWC_IOCTL_H
3 |
4 | /* (C) 2001-2004 Nemosoft Unv.
5 | (C) 2004-2006 Luc Saillard (luc@saillard.org)
6 |
7 | NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
8 | driver and thus may have bugs that are not present in the original version.
9 | Please send bug reports and support requests to .
10 | The decompression routines have been implemented by reverse-engineering the
11 | Nemosoft binary pwcx module. Caveat emptor.
12 |
13 | This program is free software; you can redistribute it and/or modify
14 | it under the terms of the GNU General Public License as published by
15 | the Free Software Foundation; either version 2 of the License, or
16 | (at your option) any later version.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | GNU General Public License for more details.
22 |
23 | You should have received a copy of the GNU General Public License
24 | along with this program; if not, write to the Free Software
25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 | */
27 |
28 | /* This is pwc-ioctl.h belonging to PWC 10.0.10
29 | It contains structures and defines to communicate from user space
30 | directly to the driver.
31 | */
32 |
33 | /*
34 | Changes
35 | 2001/08/03 Alvarado Added ioctl constants to access methods for
36 | changing white balance and red/blue gains
37 | 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE
38 | 2003/12/13 Nemosft Unv. Some modifications to make interfacing to
39 | PWCX easier
40 | 2006/01/01 Luc Saillard Add raw format definition
41 | */
42 |
43 | /* These are private ioctl() commands, specific for the Philips webcams.
44 | They contain functions not found in other webcams, and settings not
45 | specified in the Video4Linux API.
46 |
47 | The #define names are built up like follows:
48 | VIDIOC VIDeo IOCtl prefix
49 | PWC Philps WebCam
50 | G optional: Get
51 | S optional: Set
52 | ... the function
53 | */
54 |
55 | #if (!defined(BSD))
56 | #include
57 | #include
58 |
59 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 10)
60 | /* Compatibility for older kernel */
61 | typedef __u16 __le16;
62 | #endif
63 |
64 | #endif /* ( !BSD ) */
65 |
66 | /* Enumeration of image sizes */
67 | #define PSZ_SQCIF 0x00
68 | #define PSZ_QSIF 0x01
69 | #define PSZ_QCIF 0x02
70 | #define PSZ_SIF 0x03
71 | #define PSZ_CIF 0x04
72 | #define PSZ_VGA 0x05
73 | #define PSZ_MAX 6
74 |
75 |
76 | /* The frame rate is encoded in the video_window.flags parameter using
77 | the upper 16 bits, since some flags are defined nowadays. The following
78 | defines provide a mask and shift to filter out this value.
79 | This value can also be passing using the private flag when using v4l2 and
80 | VIDIOC_S_FMT ioctl.
81 |
82 | In 'Snapshot' mode the camera freezes its automatic exposure and colour
83 | balance controls.
84 | */
85 | #define PWC_FPS_SHIFT 16
86 | #define PWC_FPS_MASK 0x00FF0000
87 | #define PWC_FPS_FRMASK 0x003F0000
88 | #define PWC_FPS_SNAPSHOT 0x00400000
89 | #define PWC_QLT_MASK 0x03000000
90 | #define PWC_QLT_SHIFT 24
91 |
92 |
93 | /* structure for transferring x & y coordinates */
94 | struct pwc_coord
95 | {
96 | int x, y; /* guess what */
97 | int size; /* size, or offset */
98 | };
99 |
100 |
101 | /* Used with VIDIOCPWCPROBE */
102 | struct pwc_probe
103 | {
104 | char name[32];
105 | int type;
106 | };
107 |
108 | struct pwc_serial
109 | {
110 | char serial[30]; /* String with serial number. Contains terminating 0 */
111 | };
112 |
113 | /* pwc_whitebalance.mode values */
114 | #define PWC_WB_INDOOR 0
115 | #define PWC_WB_OUTDOOR 1
116 | #define PWC_WB_FL 2
117 | #define PWC_WB_MANUAL 3
118 | #define PWC_WB_AUTO 4
119 |
120 | /* Used with VIDIOCPWC[SG]AWB (Auto White Balance).
121 | Set mode to one of the PWC_WB_* values above.
122 | *red and *blue are the respective gains of these colour components inside
123 | the camera; range 0..65535
124 | When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read;
125 | otherwise undefined.
126 | 'read_red' and 'read_blue' are read-only.
127 | */
128 | struct pwc_whitebalance
129 | {
130 | int mode;
131 | int manual_red, manual_blue; /* R/W */
132 | int read_red, read_blue; /* R/O */
133 | };
134 |
135 | /*
136 | 'control_speed' and 'control_delay' are used in automatic whitebalance mode,
137 | and tell the camera how fast it should react to changes in lighting, and
138 | with how much delay. Valid values are 0..65535.
139 | */
140 | struct pwc_wb_speed
141 | {
142 | int control_speed;
143 | int control_delay;
144 |
145 | };
146 |
147 | /* Used with VIDIOCPWC[SG]LED */
148 | struct pwc_leds
149 | {
150 | int led_on; /* Led on-time; range = 0..25000 */
151 | int led_off; /* Led off-time; range = 0..25000 */
152 | };
153 |
154 | /* Image size (used with GREALSIZE) */
155 | struct pwc_imagesize
156 | {
157 | int width;
158 | int height;
159 | };
160 |
161 | /* Defines and structures for Motorized Pan & Tilt */
162 | #define PWC_MPT_PAN 0x01
163 | #define PWC_MPT_TILT 0x02
164 | #define PWC_MPT_TIMEOUT 0x04 /* for status */
165 |
166 | /* Set angles; when absolute != 0, the angle is absolute and the
167 | driver calculates the relative offset for you. This can only
168 | be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns
169 | absolute angles.
170 | */
171 | struct pwc_mpt_angles
172 | {
173 | int absolute; /* write-only */
174 | int pan; /* degrees * 100 */
175 | int tilt; /* degress * 100 */
176 | };
177 |
178 | /* Range of angles of the camera, both horizontally and vertically.
179 | */
180 | struct pwc_mpt_range
181 | {
182 | int pan_min, pan_max; /* degrees * 100 */
183 | int tilt_min, tilt_max;
184 | };
185 |
186 | struct pwc_mpt_status
187 | {
188 | int status;
189 | int time_pan;
190 | int time_tilt;
191 | };
192 |
193 |
194 | /* This is used for out-of-kernel decompression. With it, you can get
195 | all the necessary information to initialize and use the decompressor
196 | routines in standalone applications.
197 | */
198 | struct pwc_video_command
199 | {
200 | int type; /* camera type (645, 675, 730, etc.) */
201 | int release; /* release number */
202 |
203 | int size; /* one of PSZ_* */
204 | int alternate;
205 | int command_len; /* length of USB video command */
206 | unsigned char command_buf[13]; /* Actual USB video command */
207 | int bandlength; /* >0 = compressed */
208 | int frame_size; /* Size of one (un)compressed frame */
209 | };
210 |
211 | /* Flags for PWCX subroutines. Not all modules honour all flags. */
212 | #define PWCX_FLAG_PLANAR 0x0001
213 | #define PWCX_FLAG_BAYER 0x0008
214 |
215 |
216 | /* IOCTL definitions */
217 |
218 | /* Restore user settings */
219 | #define VIDIOCPWCRUSER _IO('v', 192)
220 | /* Save user settings */
221 | #define VIDIOCPWCSUSER _IO('v', 193)
222 | /* Restore factory settings */
223 | #define VIDIOCPWCFACTORY _IO('v', 194)
224 |
225 | /* You can manipulate the compression factor. A compression preference of 0
226 | means use uncompressed modes when available; 1 is low compression, 2 is
227 | medium and 3 is high compression preferred. Of course, the higher the
228 | compression, the lower the bandwidth used but more chance of artefacts
229 | in the image. The driver automatically chooses a higher compression when
230 | the preferred mode is not available.
231 | */
232 | /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */
233 | #define VIDIOCPWCSCQUAL _IOW('v', 195, int)
234 | /* Get preferred compression quality */
235 | #define VIDIOCPWCGCQUAL _IOR('v', 195, int)
236 |
237 |
238 | /* Retrieve serial number of camera */
239 | #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial)
240 |
241 | /* This is a probe function; since so many devices are supported, it
242 | becomes difficult to include all the names in programs that want to
243 | check for the enhanced Philips stuff. So in stead, try this PROBE;
244 | it returns a structure with the original name, and the corresponding
245 | Philips type.
246 | To use, fill the structure with zeroes, call PROBE and if that succeeds,
247 | compare the name with that returned from VIDIOCGCAP; they should be the
248 | same. If so, you can be assured it is a Philips (OEM) cam and the type
249 | is valid.
250 | */
251 | #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe)
252 |
253 | /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */
254 | #define VIDIOCPWCSAGC _IOW('v', 200, int)
255 | /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */
256 | #define VIDIOCPWCGAGC _IOR('v', 200, int)
257 | /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */
258 | #define VIDIOCPWCSSHUTTER _IOW('v', 201, int)
259 |
260 | /* Color compensation (Auto White Balance) */
261 | #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance)
262 | #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance)
263 |
264 | /* Auto WB speed */
265 | #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed)
266 | #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed)
267 |
268 | /* LEDs on/off/blink; int range 0..65535 */
269 | #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds)
270 | #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds)
271 |
272 | /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */
273 | #define VIDIOCPWCSCONTOUR _IOW('v', 206, int)
274 | #define VIDIOCPWCGCONTOUR _IOR('v', 206, int)
275 |
276 | /* Backlight compensation; 0 = off, otherwise on */
277 | #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int)
278 | #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int)
279 |
280 | /* Flickerless mode; = 0 off, otherwise on */
281 | #define VIDIOCPWCSFLICKER _IOW('v', 208, int)
282 | #define VIDIOCPWCGFLICKER _IOR('v', 208, int)
283 |
284 | /* Dynamic noise reduction; 0 off, 3 = high noise reduction */
285 | #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int)
286 | #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int)
287 |
288 | /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
289 | #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize)
290 |
291 | /* Motorized pan & tilt functions */
292 | #define VIDIOCPWCMPTRESET _IOW('v', 211, int)
293 | #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range)
294 | #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles)
295 | #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles)
296 | #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status)
297 |
298 | /* Get the USB set-video command; needed for initializing libpwcx */
299 | #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command)
300 | struct pwc_table_init_buffer {
301 | int len;
302 | char *buffer;
303 | };
304 | #define VIDIOCPWCGVIDTABLE _IOR('v', 216, struct pwc_table_init_buffer)
305 |
306 | /*
307 | * This is private command used when communicating with v4l2.
308 | * In the future all private ioctl will be remove/replace to
309 | * use interface offer by v4l2.
310 | */
311 |
312 | #if (defined(MOTION_V4L2)) && (!defined(BSD))
313 |
314 | #define V4L2_CID_PRIVATE_SAVE_USER (V4L2_CID_PRIVATE_BASE + 0)
315 | #define V4L2_CID_PRIVATE_RESTORE_USER (V4L2_CID_PRIVATE_BASE + 1)
316 | #define V4L2_CID_PRIVATE_RESTORE_FACTORY (V4L2_CID_PRIVATE_BASE + 2)
317 | #define V4L2_CID_PRIVATE_COLOUR_MODE (V4L2_CID_PRIVATE_BASE + 3)
318 | #define V4L2_CID_PRIVATE_AUTOCONTOUR (V4L2_CID_PRIVATE_BASE + 4)
319 | #define V4L2_CID_PRIVATE_CONTOUR (V4L2_CID_PRIVATE_BASE + 5)
320 | #define V4L2_CID_PRIVATE_BACKLIGHT (V4L2_CID_PRIVATE_BASE + 6)
321 | #define V4L2_CID_PRIVATE_FLICKERLESS (V4L2_CID_PRIVATE_BASE + 7)
322 | #define V4L2_CID_PRIVATE_NOISE_REDUCTION (V4L2_CID_PRIVATE_BASE + 8)
323 |
324 | struct pwc_raw_frame {
325 | __le16 type; /* type of the webcam */
326 | __le16 vbandlength; /* Size of 4lines compressed (used by the decompressor) */
327 | __u8 cmd[4]; /* the four byte of the command (in case of nala,
328 | only the first 3 bytes is filled) */
329 | __u8 rawframe[0]; /* frame_size = H/4*vbandlength */
330 | } __attribute__ ((packed));
331 |
332 | #endif /* MOTION_V4L2 && (! BSD ) */
333 |
334 | #endif
335 |
--------------------------------------------------------------------------------
/mmx.h:
--------------------------------------------------------------------------------
1 | /*
2 | * mmx.h
3 | * Copyright (C) 1997-2001 H. Dietz and R. Fisher
4 | */
5 | #ifndef I386MMX_H
6 | #define I386MMX_H
7 |
8 | /*
9 | * The type of an value that fits in an MMX register (note that long
10 | * long constant values MUST be suffixed by LL and unsigned long long
11 | * values by ULL, lest they be truncated by the compiler)
12 | */
13 |
14 | typedef union {
15 | long long q; /* Quadword (64-bit) value */
16 | unsigned long long uq; /* Unsigned Quadword */
17 | int d[2]; /* 2 Doubleword (32-bit) values */
18 | unsigned int ud[2]; /* 2 Unsigned Doubleword */
19 | short w[4]; /* 4 Word (16-bit) values */
20 | unsigned short uw[4]; /* 4 Unsigned Word */
21 | char b[8]; /* 8 Byte (8-bit) values */
22 | unsigned char ub[8]; /* 8 Unsigned Byte */
23 | float s[2]; /* Single-precision (32-bit) value */
24 | } mmx_t; /* On an 8-byte (64-bit) boundary */
25 |
26 |
27 | #define mmx_i2r(op,imm,reg) \
28 | __asm__ __volatile__ (#op " %0, %%" #reg \
29 | : /* nothing */ \
30 | : "i" (imm))
31 |
32 | #define mmx_m2r(op,mem,reg) \
33 | __asm__ __volatile__ (#op " %0, %%" #reg \
34 | : /* nothing */ \
35 | : "m" (mem))
36 |
37 | #define mmx_r2m(op,reg,mem) \
38 | __asm__ __volatile__ (#op " %%" #reg ", %0" \
39 | : "=m" (mem) \
40 | : /* nothing */ )
41 |
42 | #define mmx_r2r(op,regs,regd) \
43 | __asm__ __volatile__ (#op " %" #regs ", %" #regd)
44 |
45 |
46 | #define emms() __asm__ __volatile__ ("emms")
47 |
48 | #define movd_m2r(var,reg) mmx_m2r (movd, var, reg)
49 | #define movd_r2m(reg,var) mmx_r2m (movd, reg, var)
50 | #define movd_r2r(regs,regd) mmx_r2r (movd, regs, regd)
51 |
52 | #define movq_m2r(var,reg) mmx_m2r (movq, var, reg)
53 | #define movq_r2m(reg,var) mmx_r2m (movq, reg, var)
54 | #define movq_r2r(regs,regd) mmx_r2r (movq, regs, regd)
55 |
56 | #define packssdw_m2r(var,reg) mmx_m2r (packssdw, var, reg)
57 | #define packssdw_r2r(regs,regd) mmx_r2r (packssdw, regs, regd)
58 | #define packsswb_m2r(var,reg) mmx_m2r (packsswb, var, reg)
59 | #define packsswb_r2r(regs,regd) mmx_r2r (packsswb, regs, regd)
60 |
61 | #define packuswb_m2r(var,reg) mmx_m2r (packuswb, var, reg)
62 | #define packuswb_r2r(regs,regd) mmx_r2r (packuswb, regs, regd)
63 |
64 | #define paddb_m2r(var,reg) mmx_m2r (paddb, var, reg)
65 | #define paddb_r2r(regs,regd) mmx_r2r (paddb, regs, regd)
66 | #define paddd_m2r(var,reg) mmx_m2r (paddd, var, reg)
67 | #define paddd_r2r(regs,regd) mmx_r2r (paddd, regs, regd)
68 | #define paddw_m2r(var,reg) mmx_m2r (paddw, var, reg)
69 | #define paddw_r2r(regs,regd) mmx_r2r (paddw, regs, regd)
70 |
71 | #define paddsb_m2r(var,reg) mmx_m2r (paddsb, var, reg)
72 | #define paddsb_r2r(regs,regd) mmx_r2r (paddsb, regs, regd)
73 | #define paddsw_m2r(var,reg) mmx_m2r (paddsw, var, reg)
74 | #define paddsw_r2r(regs,regd) mmx_r2r (paddsw, regs, regd)
75 |
76 | #define paddusb_m2r(var,reg) mmx_m2r (paddusb, var, reg)
77 | #define paddusb_r2r(regs,regd) mmx_r2r (paddusb, regs, regd)
78 | #define paddusw_m2r(var,reg) mmx_m2r (paddusw, var, reg)
79 | #define paddusw_r2r(regs,regd) mmx_r2r (paddusw, regs, regd)
80 |
81 | #define pand_m2r(var,reg) mmx_m2r (pand, var, reg)
82 | #define pand_r2r(regs,regd) mmx_r2r (pand, regs, regd)
83 |
84 | #define pandn_m2r(var,reg) mmx_m2r (pandn, var, reg)
85 | #define pandn_r2r(regs,regd) mmx_r2r (pandn, regs, regd)
86 |
87 | #define pcmpeqb_m2r(var,reg) mmx_m2r (pcmpeqb, var, reg)
88 | #define pcmpeqb_r2r(regs,regd) mmx_r2r (pcmpeqb, regs, regd)
89 | #define pcmpeqd_m2r(var,reg) mmx_m2r (pcmpeqd, var, reg)
90 | #define pcmpeqd_r2r(regs,regd) mmx_r2r (pcmpeqd, regs, regd)
91 | #define pcmpeqw_m2r(var,reg) mmx_m2r (pcmpeqw, var, reg)
92 | #define pcmpeqw_r2r(regs,regd) mmx_r2r (pcmpeqw, regs, regd)
93 |
94 | #define pcmpgtb_m2r(var,reg) mmx_m2r (pcmpgtb, var, reg)
95 | #define pcmpgtb_r2r(regs,regd) mmx_r2r (pcmpgtb, regs, regd)
96 | #define pcmpgtd_m2r(var,reg) mmx_m2r (pcmpgtd, var, reg)
97 | #define pcmpgtd_r2r(regs,regd) mmx_r2r (pcmpgtd, regs, regd)
98 | #define pcmpgtw_m2r(var,reg) mmx_m2r (pcmpgtw, var, reg)
99 | #define pcmpgtw_r2r(regs,regd) mmx_r2r (pcmpgtw, regs, regd)
100 |
101 | #define pmaddwd_m2r(var,reg) mmx_m2r (pmaddwd, var, reg)
102 | #define pmaddwd_r2r(regs,regd) mmx_r2r (pmaddwd, regs, regd)
103 |
104 | #define pmulhw_m2r(var,reg) mmx_m2r (pmulhw, var, reg)
105 | #define pmulhw_r2r(regs,regd) mmx_r2r (pmulhw, regs, regd)
106 |
107 | #define pmullw_m2r(var,reg) mmx_m2r (pmullw, var, reg)
108 | #define pmullw_r2r(regs,regd) mmx_r2r (pmullw, regs, regd)
109 |
110 | #define por_m2r(var,reg) mmx_m2r (por, var, reg)
111 | #define por_r2r(regs,regd) mmx_r2r (por, regs, regd)
112 |
113 | #define pslld_i2r(imm,reg) mmx_i2r (pslld, imm, reg)
114 | #define pslld_m2r(var,reg) mmx_m2r (pslld, var, reg)
115 | #define pslld_r2r(regs,regd) mmx_r2r (pslld, regs, regd)
116 | #define psllq_i2r(imm,reg) mmx_i2r (psllq, imm, reg)
117 | #define psllq_m2r(var,reg) mmx_m2r (psllq, var, reg)
118 | #define psllq_r2r(regs,regd) mmx_r2r (psllq, regs, regd)
119 | #define psllw_i2r(imm,reg) mmx_i2r (psllw, imm, reg)
120 | #define psllw_m2r(var,reg) mmx_m2r (psllw, var, reg)
121 | #define psllw_r2r(regs,regd) mmx_r2r (psllw, regs, regd)
122 |
123 | #define psrad_i2r(imm,reg) mmx_i2r (psrad, imm, reg)
124 | #define psrad_m2r(var,reg) mmx_m2r (psrad, var, reg)
125 | #define psrad_r2r(regs,regd) mmx_r2r (psrad, regs, regd)
126 | #define psraw_i2r(imm,reg) mmx_i2r (psraw, imm, reg)
127 | #define psraw_m2r(var,reg) mmx_m2r (psraw, var, reg)
128 | #define psraw_r2r(regs,regd) mmx_r2r (psraw, regs, regd)
129 |
130 | #define psrld_i2r(imm,reg) mmx_i2r (psrld, imm, reg)
131 | #define psrld_m2r(var,reg) mmx_m2r (psrld, var, reg)
132 | #define psrld_r2r(regs,regd) mmx_r2r (psrld, regs, regd)
133 | #define psrlq_i2r(imm,reg) mmx_i2r (psrlq, imm, reg)
134 | #define psrlq_m2r(var,reg) mmx_m2r (psrlq, var, reg)
135 | #define psrlq_r2r(regs,regd) mmx_r2r (psrlq, regs, regd)
136 | #define psrlw_i2r(imm,reg) mmx_i2r (psrlw, imm, reg)
137 | #define psrlw_m2r(var,reg) mmx_m2r (psrlw, var, reg)
138 | #define psrlw_r2r(regs,regd) mmx_r2r (psrlw, regs, regd)
139 |
140 | #define psubb_m2r(var,reg) mmx_m2r (psubb, var, reg)
141 | #define psubb_r2r(regs,regd) mmx_r2r (psubb, regs, regd)
142 | #define psubd_m2r(var,reg) mmx_m2r (psubd, var, reg)
143 | #define psubd_r2r(regs,regd) mmx_r2r (psubd, regs, regd)
144 | #define psubw_m2r(var,reg) mmx_m2r (psubw, var, reg)
145 | #define psubw_r2r(regs,regd) mmx_r2r (psubw, regs, regd)
146 |
147 | #define psubsb_m2r(var,reg) mmx_m2r (psubsb, var, reg)
148 | #define psubsb_r2r(regs,regd) mmx_r2r (psubsb, regs, regd)
149 | #define psubsw_m2r(var,reg) mmx_m2r (psubsw, var, reg)
150 | #define psubsw_r2r(regs,regd) mmx_r2r (psubsw, regs, regd)
151 |
152 | #define psubusb_m2r(var,reg) mmx_m2r (psubusb, var, reg)
153 | #define psubusb_r2r(regs,regd) mmx_r2r (psubusb, regs, regd)
154 | #define psubusw_m2r(var,reg) mmx_m2r (psubusw, var, reg)
155 | #define psubusw_r2r(regs,regd) mmx_r2r (psubusw, regs, regd)
156 |
157 | #define punpckhbw_m2r(var,reg) mmx_m2r (punpckhbw, var, reg)
158 | #define punpckhbw_r2r(regs,regd) mmx_r2r (punpckhbw, regs, regd)
159 | #define punpckhdq_m2r(var,reg) mmx_m2r (punpckhdq, var, reg)
160 | #define punpckhdq_r2r(regs,regd) mmx_r2r (punpckhdq, regs, regd)
161 | #define punpckhwd_m2r(var,reg) mmx_m2r (punpckhwd, var, reg)
162 | #define punpckhwd_r2r(regs,regd) mmx_r2r (punpckhwd, regs, regd)
163 |
164 | #define punpcklbw_m2r(var,reg) mmx_m2r (punpcklbw, var, reg)
165 | #define punpcklbw_r2r(regs,regd) mmx_r2r (punpcklbw, regs, regd)
166 | #define punpckldq_m2r(var,reg) mmx_m2r (punpckldq, var, reg)
167 | #define punpckldq_r2r(regs,regd) mmx_r2r (punpckldq, regs, regd)
168 | #define punpcklwd_m2r(var,reg) mmx_m2r (punpcklwd, var, reg)
169 | #define punpcklwd_r2r(regs,regd) mmx_r2r (punpcklwd, regs, regd)
170 |
171 | #define pxor_m2r(var,reg) mmx_m2r (pxor, var, reg)
172 | #define pxor_r2r(regs,regd) mmx_r2r (pxor, regs, regd)
173 |
174 |
175 | /* 3DNOW extensions */
176 |
177 | #define pavgusb_m2r(var,reg) mmx_m2r (pavgusb, var, reg)
178 | #define pavgusb_r2r(regs,regd) mmx_r2r (pavgusb, regs, regd)
179 |
180 |
181 | /* AMD MMX extensions - also available in intel SSE */
182 |
183 |
184 | #define mmx_m2ri(op,mem,reg,imm) \
185 | __asm__ __volatile__ (#op " %1, %0, %%" #reg \
186 | : /* nothing */ \
187 | : "X" (mem), "X" (imm))
188 | #define mmx_r2ri(op,regs,regd,imm) \
189 | __asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
190 | : /* nothing */ \
191 | : "X" (imm))
192 |
193 | #define mmx_fetch(mem,hint) \
194 | __asm__ __volatile__ ("prefetch" #hint " %0" \
195 | : /* nothing */ \
196 | : "X" (mem))
197 |
198 |
199 | #define maskmovq(regs,maskreg) mmx_r2ri (maskmovq, regs, maskreg)
200 |
201 | #define movntq_r2m(mmreg,var) mmx_r2m (movntq, mmreg, var)
202 |
203 | #define pavgb_m2r(var,reg) mmx_m2r (pavgb, var, reg)
204 | #define pavgb_r2r(regs,regd) mmx_r2r (pavgb, regs, regd)
205 | #define pavgw_m2r(var,reg) mmx_m2r (pavgw, var, reg)
206 | #define pavgw_r2r(regs,regd) mmx_r2r (pavgw, regs, regd)
207 |
208 | #define pextrw_r2r(mmreg,reg,imm) mmx_r2ri (pextrw, mmreg, reg, imm)
209 |
210 | #define pinsrw_r2r(reg,mmreg,imm) mmx_r2ri (pinsrw, reg, mmreg, imm)
211 |
212 | #define pmaxsw_m2r(var,reg) mmx_m2r (pmaxsw, var, reg)
213 | #define pmaxsw_r2r(regs,regd) mmx_r2r (pmaxsw, regs, regd)
214 |
215 | #define pmaxub_m2r(var,reg) mmx_m2r (pmaxub, var, reg)
216 | #define pmaxub_r2r(regs,regd) mmx_r2r (pmaxub, regs, regd)
217 |
218 | #define pminsw_m2r(var,reg) mmx_m2r (pminsw, var, reg)
219 | #define pminsw_r2r(regs,regd) mmx_r2r (pminsw, regs, regd)
220 |
221 | #define pminub_m2r(var,reg) mmx_m2r (pminub, var, reg)
222 | #define pminub_r2r(regs,regd) mmx_r2r (pminub, regs, regd)
223 |
224 | #define pmovmskb(mmreg,reg) \
225 | __asm__ __volatile__ ("movmskps %" #mmreg ", %" #reg)
226 |
227 | #define pmulhuw_m2r(var,reg) mmx_m2r (pmulhuw, var, reg)
228 | #define pmulhuw_r2r(regs,regd) mmx_r2r (pmulhuw, regs, regd)
229 |
230 | #define prefetcht0(mem) mmx_fetch (mem, t0)
231 | #define prefetcht1(mem) mmx_fetch (mem, t1)
232 | #define prefetcht2(mem) mmx_fetch (mem, t2)
233 | #define prefetchnta(mem) mmx_fetch (mem, nta)
234 |
235 | #define psadbw_m2r(var,reg) mmx_m2r (psadbw, var, reg)
236 | #define psadbw_r2r(regs,regd) mmx_r2r (psadbw, regs, regd)
237 |
238 | #define pshufw_m2r(var,reg,imm) mmx_m2ri(pshufw, var, reg, imm)
239 | #define pshufw_r2r(regs,regd,imm) mmx_r2ri(pshufw, regs, regd, imm)
240 |
241 | #define sfence() __asm__ __volatile__ ("sfence\n\t")
242 |
243 | /* SSE2 */
244 | #define pshufhw_m2r(var,reg,imm) mmx_m2ri(pshufhw, var, reg, imm)
245 | #define pshufhw_r2r(regs,regd,imm) mmx_r2ri(pshufhw, regs, regd, imm)
246 | #define pshuflw_m2r(var,reg,imm) mmx_m2ri(pshuflw, var, reg, imm)
247 | #define pshuflw_r2r(regs,regd,imm) mmx_r2ri(pshuflw, regs, regd, imm)
248 |
249 | #define pshufd_r2r(regs,regd,imm) mmx_r2ri(pshufd, regs, regd, imm)
250 |
251 | #define movdqa_m2r(var,reg) mmx_m2r (movdqa, var, reg)
252 | #define movdqa_r2m(reg,var) mmx_r2m (movdqa, reg, var)
253 | #define movdqa_r2r(regs,regd) mmx_r2r (movdqa, regs, regd)
254 | #define movdqu_m2r(var,reg) mmx_m2r (movdqu, var, reg)
255 | #define movdqu_r2m(reg,var) mmx_r2m (movdqu, reg, var)
256 | #define movdqu_r2r(regs,regd) mmx_r2r (movdqu, regs, regd)
257 |
258 | #define pmullw_r2m(reg,var) mmx_r2m (pmullw, reg, var)
259 |
260 | #define pslldq_i2r(imm,reg) mmx_i2r (pslldq, imm, reg)
261 | #define psrldq_i2r(imm,reg) mmx_i2r (psrldq, imm, reg)
262 |
263 | #define punpcklqdq_r2r(regs,regd) mmx_r2r (punpcklqdq, regs, regd)
264 | #define punpckhqdq_r2r(regs,regd) mmx_r2r (punpckhqdq, regs, regd)
265 |
266 |
267 | #endif /* I386MMX_H */
268 |
--------------------------------------------------------------------------------