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)
60 fprintf(stderr, "No source was specified.......");
66 int r = src_v4l2.flags;
67 if(S_ISCHR(st.st_mode) && r & SRC_TYPE_DEVICE) r = -1;
68 else if(!S_ISCHR(st.st_mode) && r & SRC_TYPE_FILE) r = -1;
71 r = src_v4l2.open(src);
72 if(r == -2) return(-1);
76 for(frame = 0; frame < config->skipframes; frame++)
77 if(src_grab(src) == -1) break;*/
82 const char *src_query(src_t *src, char *source, uint *width, uint *height, char **pixelformatdescription)
85 return src_v4l2.query(src, width, height, pixelformatdescription);
88 int src_close(src_t *src)
92 if(src->captured_frames)
95 (src->tv_last.tv_sec + src->tv_last.tv_usec / 1000000.0) -
96 (src->tv_first.tv_sec + src->tv_first.tv_usec / 1000000.0);
98 /* Display FPS if enough frames where captured. */
99 if(src->captured_frames == 1)
101 /*MSG("Captured frame in %0.2f seconds.", seconds);*/
103 else if(src->captured_frames < 3)
105 /*MSG("Captured %i frames in %0.2f seconds.",
106 src->captured_frames, seconds);*/
110 /*MSG("Captured %i frames in %0.2f seconds. (%i fps)",
111 src->captured_frames, seconds,
112 (int) (src->captured_frames / seconds));*/
116 r = src_v4l2.close(src);
118 if(src->source) free(src->source);
123 int src_grab(src_t *src)
125 int r = src_v4l2.grab(src);
129 if(!src->captured_frames) gettimeofday(&src->tv_first, NULL);
130 gettimeofday(&src->tv_last, NULL);
132 src->captured_frames++;
138 /* Pointers are great things. Terrible things yes, but great. */
139 /* These work but are very ugly and will be re-written soon. */
141 int src_set_option(src_option_t ***options, char *name, char *value)
143 src_option_t **opts, *opt;
146 if(!options) return(-1);
149 *options = malloc(sizeof(src_option_t *));
152 /*ERROR("Out of memory.");*/
163 if((*opts)->name) if(!strcasecmp(name, (*opts)->name)) break;
172 opt = (src_option_t *) malloc(sizeof(src_option_t));
175 /*ERROR("Out of memory.");*/
179 new = realloc(*options, sizeof(src_option_t *) * (count + 2));
183 /*ERROR("Out of memory.");*/
187 *options = (src_option_t **) new;
188 (*options)[count++] = opt;
189 (*options)[count++] = NULL;
191 opt->name = strdup(name);
201 if(value) opt->value = strdup(value);
206 int src_get_option_by_number(src_option_t **opt, int number,
207 char **name, char **value)
211 if(!opt || !name || !value) return(-1);
218 *name = (*opt)->name;
219 *value = (*opt)->value;
229 int src_get_option_by_name(src_option_t **opt, char *name, char **value)
231 if(!opt || !name || !value) return(-1);
237 if(!strcasecmp(name, (*opt)->name))
239 *value = (*opt)->value;
250 int src_free_options(src_option_t ***options)
254 if(!options || !*options) return(-1);
259 if((*opts)->name) free((*opts)->name);
260 if((*opts)->value) free((*opts)->value);