Skip to content

Commit

Permalink
SDL support
Browse files Browse the repository at this point in the history
  • Loading branch information
sackmotion committed Sep 19, 2010
1 parent 75ad777 commit 1ffbc17
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ VIDEO_OBJ = @VIDEO@
OBJ = motion.o logger.o conf.o draw.o jpegutils.o vloopback_motion.o $(VIDEO_OBJ) \
netcam.o netcam_ftp.o netcam_jpeg.o netcam_wget.o track.o \
alg.o event.o picture.o rotate.o webhttpd.o \
stream.o md5.o @FFMPEG_OBJ@
stream.o md5.o @FFMPEG_OBJ@ @SDL_OBJ@
SRC = $(OBJ:.o=.c)
DOC = CHANGELOG COPYING CREDITS INSTALL README motion_guide.html
EXAMPLES = *.conf motion.init-Debian motion.init-Fedora motion.init-FreeBSD.sh
Expand Down
19 changes: 17 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct config conf_template = {
ffmpeg_bps: DEF_FFMPEG_BPS,
ffmpeg_vbr: DEF_FFMPEG_VBR,
ffmpeg_video_codec: DEF_FFMPEG_CODEC,
#ifdef HAVE_SDL
sdl_threadnr: 0,
#endif
ipv6_enabled: 0,
stream_port: 0,
stream_quality: 50,
Expand Down Expand Up @@ -757,6 +760,19 @@ config_param config_params[] = {
print_bool
},
#endif /* HAVE_FFMPEG */
#ifdef HAVE_SDL
{
"sdl_threadnr",
"\n############################################################\n"
"# SDL Window\n"
"############################################################\n\n"
"# Number of motion thread to show in SDL Window (default: 0 = disabled)",
1,
CONF_OFFSET(sdl_threadnr),
copy_int,
print_int
},
#endif /* HAVE_SDL */
{
"use_extpipe",
"\n############################################################\n"
Expand Down Expand Up @@ -2320,11 +2336,10 @@ static void usage()
printf("-d level\t\tLog level (1-9) (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). default: 6 / NTC.\n");
printf("-k type\t\t\tType of log (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). default: ALL.\n");
printf("-p process_id_file\tFull path and filename of process id file (pid file).\n");
printf("-l log file \t\tFull path and filename of log file. ( use -l syslog to log to stderr and syslog )\n");
printf("-l log file \t\tFull path and filename of log file.\n");
printf("-h\t\t\tShow this screen.\n");
printf("\n");
printf("Motion is configured using a config file only. If none is supplied,\n");
printf("it will read motion.conf from current directory, ~/.motion or %s.\n", sysconfdir);
printf("e.g run motion debugging video only , no daemon and logging to stderr and syslog :\n\n\t ./motion -n -l syslog -d 9 -k VID\n");
printf("\n");
}
3 changes: 3 additions & 0 deletions conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ struct config {
int ffmpeg_vbr;
int ffmpeg_deinterlace;
const char *ffmpeg_video_codec;
#ifdef HAVE_SDL
int sdl_threadnr;
#endif
int ipv6_enabled;
int stream_port;
int stream_quality;
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
/* Define to 1 if you have PostgreSQL support */
#undef HAVE_PGSQL

/* Define to 1 if you have SDL support */
#undef HAVE_SDL

/* Define to 1 if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H

Expand Down
45 changes: 45 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,45 @@ else
fi


#
# Check for sdl library
#
SDL_SUPPORT="yes"
AC_ARG_WITH(sdl,
[ --without-sdl Compile without sdl support to get stream in SDL window.],
[],
[])
AC_MSG_CHECKING(for sdl)
if test "x$withval" = "xno"; then
AC_MSG_RESULT(skipped)
SDL_SUPPORT="no"
else
if test "${FreeBSD}" != ""; then
CONFIG_SDL='sdl11-config'
else
CONFIG_SDL='sdl-config'
fi
if test -z "`($CONFIG_SDL --version) 2>/dev/null`" ;then
AC_MSG_RESULT(no)
if test "$withval" = "yes"; then
echo ""
echo "****************************************************"
echo "* sdl-config could not be found. Please install it *"
echo "* and remove the --with-sdl configure argument. *"
echo "* libSDL can be found at http://www.libsdl.org *"
echo "****************************************************"
echo ""
fi
else
AC_MSG_RESULT(yes)
SDL_SUPPORT="yes"
TEMP_LIBS="$TEMP_LIBS `${CONFIG_SDL} --libs`"
TEMP_CFLAGS="${TEMP_CFLAGS} `${CONFIG_SDL} --cflags`"
AC_DEFINE([HAVE_SDL],1,[Define to 1 if you have SDL support])
SDL_OBJ="sdl.o"
AC_SUBST(SDL_OBJ)
fi
fi

#
# Check for the special mmx accelerated jpeg library
Expand Down Expand Up @@ -1196,6 +1235,12 @@ else
fi
fi

if test "${SDL_SUPPORT}" = "yes"; then
echo "SDL support: Yes"
else
echo "SDL support: No"
fi

if test "${FFMPEG_OK}" = "found"; then
echo "FFmpeg support: Yes"
else
Expand Down
16 changes: 16 additions & 0 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ static void event_stream_put(struct context *cnt, int type ATTRIBUTE_UNUSED,
stream_put(cnt, img);
}

#ifdef HAVE_SDL
static void event_sdl_put(struct context *cnt, int type ATTRIBUTE_UNUSED,
unsigned char *img, char *dummy1 ATTRIBUTE_UNUSED,
void *dummy2 ATTRIBUTE_UNUSED, struct tm *tm ATTRIBUTE_UNUSED)
{
sdl_put(img, cnt->imgs.width, cnt->imgs.height);
}
#endif


#if !defined(WITHOUT_V4L) && !defined(BSD)
static void event_vid_putpipe(struct context *cnt, int type ATTRIBUTE_UNUSED,
unsigned char *img, char *dummy ATTRIBUTE_UNUSED, void *devpipe,
Expand Down Expand Up @@ -791,6 +801,12 @@ struct event_handlers event_handlers[] = {
EVENT_IMAGE_SNAPSHOT,
event_image_snapshot
},
#ifdef HAVE_SDL
{
EVENT_SDL_PUT,
event_sdl_put
},
#endif
#if !defined(WITHOUT_V4L) && !defined(BSD)
{
EVENT_IMAGE,
Expand Down
1 change: 1 addition & 0 deletions event.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define EVENT_AREA_DETECTED 17
#define EVENT_CAMERA_LOST 18
#define EVENT_FFMPEG_PUT 19
#define EVENT_SDL_PUT 20


typedef void(* event_handler)(struct context *, int, unsigned char *, char *, void *, struct tm *);
Expand Down
6 changes: 6 additions & 0 deletions motion-dist.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ ffmpeg_video_codec mpeg4
# (default: off)
ffmpeg_deinterlace off

############################################################
# SDL Window
############################################################

# Number of motion thread to show in SDL Window (default: 0 = disabled)
0

############################################################
# External pipe to video encoder
Expand Down
28 changes: 26 additions & 2 deletions motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -2064,13 +2064,22 @@ static void *motion_loop(void *arg)
if (cnt->conf.setup_mode) {
event(cnt, EVENT_IMAGE, cnt->imgs.out, NULL, &cnt->pipe, cnt->currenttime_tm);
event(cnt, EVENT_STREAM, cnt->imgs.out, NULL, NULL, cnt->currenttime_tm);
#ifdef HAVE_SDL
if (cnt_list[0]->conf.sdl_threadnr == cnt->threadnr)
event(cnt, EVENT_SDL_PUT, cnt->imgs.out, NULL, NULL, cnt->currenttime_tm);
#endif
} else {
event(cnt, EVENT_IMAGE, cnt->current_image->image, NULL,
&cnt->pipe, &cnt->current_image->timestamp_tm);

if (!cnt->conf.stream_motion || cnt->shots == 1)
event(cnt, EVENT_STREAM, cnt->current_image->image, NULL, NULL,
&cnt->current_image->timestamp_tm);
#ifdef HAVE_SDL
if (cnt_list[0]->conf.sdl_threadnr == cnt->threadnr)
event(cnt, EVENT_SDL_PUT, cnt->current_image->image, NULL, NULL,
&cnt->current_image->timestamp_tm);
#endif
}

event(cnt, EVENT_IMAGEM, cnt->imgs.out, NULL, &cnt->mpipe, cnt->currenttime_tm);
Expand Down Expand Up @@ -2435,8 +2444,12 @@ static void motion_startup(int daemonize, int argc, char *argv[])
}

set_log_level(cnt_list[0]->log_level);

MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started");

#ifdef HAVE_SDL
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started with SDL support");
#else
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started");
#endif

if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) {
set_log_mode(LOGMODE_FILE);
Expand Down Expand Up @@ -2696,6 +2709,12 @@ int main (int argc, char **argv)
start_motion_thread(cnt_list[i], &thread_attr);
}

#ifdef HAVE_SDL
if (cnt_list[0]->conf.sdl_threadnr > 0)
sdl_start(cnt_list[cnt_list[1] != NULL ? cnt_list[0]->conf.sdl_threadnr : 0]->conf.width,
cnt_list[cnt_list[1] != NULL ? cnt_list[0]->conf.sdl_threadnr : 0]->conf.height);
#endif

/*
* Create a thread for the control interface if requested. Create it
* detached and with 'motion_web_control' as the thread function.
Expand Down Expand Up @@ -2776,6 +2795,11 @@ int main (int argc, char **argv)

} while (restart); /* loop if we're supposed to restart */

#ifdef HAVE_SDL
sdl_stop();
#endif


// Be sure that http control exits fine
cnt_list[0]->finish = 1;
SLEEP(1, 0);
Expand Down
5 changes: 5 additions & 0 deletions motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
#include "stream.h"
#include "webhttpd.h"

#ifdef HAVE_SDL
#include "sdl.h"
#endif


/**
* ATTRIBUTE_UNUSED:
*
Expand Down

0 comments on commit 1ffbc17

Please sign in to comment.