1 /* fswebcam - FireStorm.cx's webcam generator */
2 /*============================================================*/
3 /* Copyright (C)2005-2010 Philip Heron <phil@sanslogic.co.uk> */
5 /* This program is distributed under the terms of the GNU */
6 /* General Public License, version 2. You may use, modify, */
7 /* and redistribute it under the terms of this license. A */
8 /* copy should be included with this source. */
22 extern src_mod_t src_v4l2;
25 extern src_mod_t src_v4l1;
28 /* Supported palette types. */
29 src_palette_t src_palette[] = {
53 int src_open(src_t *src, char *source)
62 fprintf(stderr, "No source was specified.......");
66 sl = strlen(source) + 1;
70 fprintf(stderr, "Out of memory.");
77 int r = src_v4l2.flags;
78 if(S_ISCHR(st.st_mode) && r & SRC_TYPE_DEVICE) r = -1;
79 else if(!S_ISCHR(st.st_mode) && r & SRC_TYPE_FILE) r = -1;
82 r = src_v4l2.open(src);
83 if(r == -2) return(-1);
87 for(frame = 0; frame < config->skipframes; frame++)
88 if(src_grab(src) == -1) break;*/
93 int src_close(src_t *src)
97 if(src->captured_frames)
100 (src->tv_last.tv_sec + src->tv_last.tv_usec / 1000000.0) -
101 (src->tv_first.tv_sec + src->tv_first.tv_usec / 1000000.0);
103 /* Display FPS if enough frames where captured. */
104 if(src->captured_frames == 1)
106 /*MSG("Captured frame in %0.2f seconds.", seconds);*/
108 else if(src->captured_frames < 3)
110 /*MSG("Captured %i frames in %0.2f seconds.",
111 src->captured_frames, seconds);*/
115 /*MSG("Captured %i frames in %0.2f seconds. (%i fps)",
116 src->captured_frames, seconds,
117 (int) (src->captured_frames / seconds));*/
121 r = src_v4l2.close(src);
123 if(src->source) free(src->source);
128 int src_grab(src_t *src)
130 int r = src_v4l2.grab(src);
134 if(!src->captured_frames) gettimeofday(&src->tv_first, NULL);
135 gettimeofday(&src->tv_last, NULL);
137 src->captured_frames++;
143 /* Pointers are great things. Terrible things yes, but great. */
144 /* These work but are very ugly and will be re-written soon. */
146 int src_set_option(src_option_t ***options, char *name, char *value)
148 src_option_t **opts, *opt;
151 if(!options) return(-1);
154 *options = malloc(sizeof(src_option_t *));
157 /*ERROR("Out of memory.");*/
168 if((*opts)->name) if(!strcasecmp(name, (*opts)->name)) break;
177 opt = (src_option_t *) malloc(sizeof(src_option_t));
180 /*ERROR("Out of memory.");*/
184 new = realloc(*options, sizeof(src_option_t *) * (count + 2));
188 /*ERROR("Out of memory.");*/
192 *options = (src_option_t **) new;
193 (*options)[count++] = opt;
194 (*options)[count++] = NULL;
196 opt->name = strdup(name);
206 if(value) opt->value = strdup(value);
211 int src_get_option_by_number(src_option_t **opt, int number,
212 char **name, char **value)
216 if(!opt || !name || !value) return(-1);
223 *name = (*opt)->name;
224 *value = (*opt)->value;
234 int src_get_option_by_name(src_option_t **opt, char *name, char **value)
236 if(!opt || !name || !value) return(-1);
242 if(!strcasecmp(name, (*opt)->name))
244 *value = (*opt)->value;
255 int src_free_options(src_option_t ***options)
259 if(!options || !*options) return(-1);
264 if((*opts)->name) free((*opts)->name);
265 if((*opts)->value) free((*opts)->value);