Motion - Motion Code Webcam

Motion Code - Webcam

This topic is describes the code that makes up the Motion webcam feature.

Not completed yet

It is created so that one does not have to re-invent the code each time you come back to it after a long time.

Functions

int webcam_init(struct context *cnt)

Is called during setup of each thread in motion.c when Motion is started. The function setup the incomming tcp socket that the clients connect to. webcam_init calls the function http_bindsock. The function returns an integer representing the socket.

int http_bindsock(int port, int local)

This function sets up a TCP/IP socket for incomming requests. It is used by two features.
  • webcam - called only during initiatization of Motion from the function webcam_init
  • xmlrpc - called from the function xmlrpc_httpd_run()
The function sets up a a socket on the port number given by port. If the parameter local is not zero the socket is setup to only accept connects from localhost. Otherwise any client IP address is accepted. The function returns an integer representing the socket.

static void event_webcam_put(int type, struct context *cnt, char *img, void *devpipe, struct tm *tm)

Only the parameters cnt and img are used. The rest are there to be compatible with the generic event function.

The function calls the function webcam_put(cnt, img) but only ...
  • If cnt->conf.webcam_motion is set only when the event type is EVENT_IMAGE_DETECTED
  • If cnt->conf.webcam_motion is not set only when the event type is EVENT_IMAGE

This also means that when a client connects and cnt->conf.webcam_motion is set no image is received until motion is detected. Even worse the client is not accepted until an image is detected. This needs to be changed

int webcam_put(struct context *cnt, char *image)

Not described yet!!!

Initialization

The webcam feature is initialized in motion.c

In the main() - as part of starting the threads - Motion first checks that the webcam port for each webcam is unique. If not the webcam feature is disabled for the remaining threads that has a conflict.

After the threads have been started the webcam is setup to accept incomming requests from clients. This happens in the first part of the motion_loop() before the actual loop. The webcam feature is initialized by calling webcam_init()

Sending images to the clients

Sending images to the webcam clients can be triggered by two events (in event.c)
  • Image captured (EVENT_IMAGE)
  • Image detected (EVENT_IMAGE_DETECTED)

Both events calls the function event_webcam_put.

event_webcam_put calls webcam_put when...
  • If cnt->conf.webcam_motion is set only when the event type is EVENT_IMAGE_DETECTED
  • If cnt->conf.webcam_motion is not set only when the event type is EVENT_IMAGE

This also means that when a client connects and cnt->conf.webcam_motion is set no image is received until motion is detected. Even worse the client is not accepted until a motion image is detected. This needs to be changed

-- KennethLavrsen - 19 Dec 2004
Topic revision: r1 - 19 Dec 2004, KennethLavrsen
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.