-
Notifications
You must be signed in to change notification settings - Fork 0
/
fswebcam.c
executable file
·1387 lines (1171 loc) · 33.7 KB
/
fswebcam.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* fswebcam - Small and simple webcam for *nix */
/*============================================================*/
/* Copyright (C)2005-2011 Philip Heron <phil@sanslogic.co.uk> */
/* */
/* This program is distributed under the terms of the GNU */
/* General Public License, version 2. You may use, modify, */
/* and redistribute it under the terms of this license. A */
/* copy should be included with this source. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <gd.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fswebcam.h"
#include "log.h"
#include "src.h"
#include "dec.h"
#include "effects.h"
#include "parse.h"
#define ALIGN_LEFT (0)
#define ALIGN_CENTER (1)
#define ALIGN_RIGHT (2)
#define NO_BANNER (0)
#define TOP_BANNER (1)
#define BOTTOM_BANNER (2)
#define FORMAT_JPEG (0)
#define FORMAT_PNG (1)
enum fswc_options {
OPT_VERSION = 128,
OPT_INTERVAL,
OPT_PID,
OPT_OFFSET,
OPT_LIST_INPUTS,
OPT_LIST_TUNERS,
OPT_LIST_FORMATS,
OPT_LIST_CONTROLS,
OPT_LIST_FRAMESIZES,
OPT_LIST_FRAMERATES,
OPT_BRIGHTNESS,
OPT_HUE,
OPT_COLOUR,
OPT_CONTRAST,
OPT_WHITENESS,
OPT_REVERT,
OPT_FLIP,
OPT_CROP,
OPT_SCALE,
OPT_ROTATE,
OPT_DEINTERLACE,
OPT_INVERT,
OPT_GREYSCALE,
OPT_SWAPCHANNELS,
OPT_NO_BANNER,
OPT_TOP_BANNER,
OPT_BOTTOM_BANNER,
OPT_BG_COLOUR,
OPT_BL_COLOUR,
OPT_FG_COLOUR,
OPT_FONT,
OPT_NO_SHADOW,
OPT_SHADOW,
OPT_TITLE,
OPT_NO_TITLE,
OPT_SUBTITLE,
OPT_NO_SUBTITLE,
OPT_TIMESTAMP,
OPT_NO_TIMESTAMP,
OPT_GMT,
OPT_INFO,
OPT_NO_INFO,
OPT_UNDERLAY,
OPT_NO_UNDERLAY,
OPT_OVERLAY,
OPT_NO_OVERLAY,
OPT_JPEG,
OPT_PNG,
OPT_SAVE,
OPT_EXEC,
OPT_DUMPFRAME,
OPT_FPS,
};
typedef struct {
/* List of options. */
char *opts;
const struct option *long_opts;
/* When reading from the command line. */
int opt_index;
/* When reading from a configuration file. */
char *filename;
FILE *f;
size_t line;
} fswc_getopt_t;
typedef struct {
uint16_t id;
char *options;
} fswebcam_job_t;
typedef struct {
/* General options. */
unsigned long loop;
signed long offset;
unsigned char background;
char *pidfile;
char *logfile;
char gmt;
/* Capture start time. */
time_t start;
/* Device options. */
char *device;
char *input;
unsigned char tuner;
unsigned long frequency;
unsigned long delay;
char use_read;
uint8_t list;
/* Image capture options. */
unsigned int width;
unsigned int height;
unsigned int frames;
unsigned int fps;
unsigned int skipframes;
int palette;
src_option_t **option;
char *dumpframe;
/* Job queue. */
uint8_t jobs;
fswebcam_job_t **job;
/* Banner options. */
char banner;
uint32_t bg_colour;
uint32_t bl_colour;
uint32_t fg_colour;
char *title;
char *subtitle;
char *timestamp;
char *info;
char *font;
int fontsize;
char shadow;
/*Interval between taking two image*/
int interval;
/* Overlay options. */
char *underlay;
char *overlay;
/*Save path : /home/cubie/hello/*/
char *save;
/* Output options. */
char *filename;
char format;
char compression;
} fswebcam_config_t;
volatile char received_sigusr1 = 0;
volatile char received_sighup = 0;
volatile char received_sigterm = 0;
void fswc_signal_usr1_handler(int signum)
{
/* Catches SIGUSR1 */
INFO("Caught signal SIGUSR1.");
received_sigusr1 = 1;
}
void fswc_signal_hup_handler(int signum)
{
/* Catches SIGHUP */
INFO("Caught signal SIGHUP.");
received_sighup = 1;
}
void fswc_signal_term_handler(int signum)
{
char *signame;
/* Catches SIGTERM and SIGINT */
switch(signum)
{
case SIGTERM: signame = "SIGTERM"; break;
case SIGINT: signame = "SIGINT"; break;
default: signame = "Unknown"; break;
}
INFO("Caught signal %s", signame);
received_sigterm = 1;
}
int fswc_setup_signals()
{
signal(SIGUSR1, fswc_signal_usr1_handler);
signal(SIGHUP, fswc_signal_hup_handler);
signal(SIGTERM, fswc_signal_term_handler);
signal(SIGINT, fswc_signal_term_handler);
return(0);
}
char *fswc_strftime(char *dst, size_t max, char *src,
time_t timestamp, int gmt)
{
struct tm tm_timestamp;
/* Clear target string, and verify source is set */
*dst = '\0';
if(!src) return(dst);
/* Set the time structure. */
if(gmt) gmtime_r(×tamp, &tm_timestamp);
else localtime_r(×tamp, &tm_timestamp);
/* Create the string */
strftime(dst, max, src, &tm_timestamp);
return(dst);
}
char *fswc_strduptime(char *src, time_t timestamp, int gmt)
{
struct tm tm_timestamp;
char *dst;
size_t l;
if(!src) return(NULL);
/* Set the time structure. */
if(gmt) gmtime_r(×tamp, &tm_timestamp);
else localtime_r(×tamp, &tm_timestamp);
dst = NULL;
l = strlen(src) * 2;
while(1)
{
size_t r;
char *t = realloc(dst, l);
if(!t)
{
free(dst);
return(NULL);
}
dst = t;
*dst = 1;
r = strftime(dst, l, src, &tm_timestamp);
if(r > 0 && r < l) return(dst);
if(r == 0 && *dst == '\0') return(dst);
l *= 2;
}
return(NULL);
}
void fswc_DrawText(gdImagePtr im, char *font, double size,
int x, int y, char align,
uint32_t colour, char shadow, char *text)
{
char *err;
int brect[8];
if(!text) return;
if(shadow)
{
uint32_t scolour = colour & 0xFF000000;
fswc_DrawText(im, font, size, x + 1, y + 1,
align, scolour, 0, text);
}
/* Correct alpha value for GD. */
colour = (((colour & 0xFF000000) / 2) & 0xFF000000) +
(colour & 0xFFFFFF);
/* Pre-render the text. We use the results during alignment. */
err = gdImageStringFT(NULL, &brect[0], colour, font, size, 0.0, 0, 0, text);
if(err)
{
WARN("%s", err);
return;
}
/* Adjust the coordinates according to the alignment. */
switch(align)
{
case ALIGN_CENTER: x -= brect[4] / 2; break;
case ALIGN_RIGHT: x -= brect[4]; break;
}
/* Render the text onto the image. */
gdImageStringFT(im, NULL, colour, font, size, 0.0, x, y, text);
}
int fswc_draw_overlay(fswebcam_config_t *config, char *filename, gdImage *image){
FILE *f;
gdImage *overlay;
if(!filename) return(-1);
f = fopen(filename, "rb");
if(!f)
{
ERROR("Unable to open '%s'", filename);
ERROR("fopen: %s", strerror(errno));
return(-1);
}
overlay = gdImageCreateFromPng(f);
fclose(f);
if(!overlay)
{
ERROR("Unable to read '%s'. Not a PNG image?", filename);
return(-1);
}
gdImageCopy(image, overlay, 0, 0, 0, 0, overlay->sx, overlay->sy);
gdImageDestroy(overlay);
return(0);
}
int fswc_draw_banner(fswebcam_config_t *config, gdImage *image)
{
char timestamp[200];
int w, h;
int height;
int spacing;
int top;
int y;
w = gdImageSX(image);
h = gdImageSY(image);
/* Create the timestamp text. */
fswc_strftime(timestamp, 200, config->timestamp,
config->start, config->gmt);
/* Calculate the position and height of the banner. */
spacing = 4;
height = config->fontsize + (spacing * 2);
if(config->subtitle || config->info)
height += config->fontsize * 0.8 + spacing;
top = 0;
if(config->banner == BOTTOM_BANNER) top = h - height;
/* Draw the banner line. */
if(config->banner == TOP_BANNER)
{
gdImageFilledRectangle(image,
0, height + 1,
w, height + 2,
config->bl_colour);
}
else
{
gdImageFilledRectangle(image,
0, top - 2,
w, top - 1,
config->bl_colour);
}
/* Draw the background box. */
gdImageFilledRectangle(image,
0, top,
w, top + height,
config->bg_colour);
y = top + spacing + config->fontsize;
/* Draw the title. */
fswc_DrawText(image, config->font, config->fontsize,
spacing, y, ALIGN_LEFT,
config->fg_colour, config->shadow, config->title);
/* Draw the timestamp. */
fswc_DrawText(image, config->font, config->fontsize * 0.8,
w - spacing, y, ALIGN_RIGHT,
config->fg_colour, config->shadow, timestamp);
y += spacing + config->fontsize * 0.8;
/* Draw the sub-title. */
fswc_DrawText(image, config->font, config->fontsize * 0.8,
spacing, y, ALIGN_LEFT,
config->fg_colour, config->shadow, config->subtitle);
/* Draw the info text. */
fswc_DrawText(image, config->font, config->fontsize * 0.7,
w - spacing, y, ALIGN_RIGHT,
config->fg_colour, config->shadow, config->info);
return(0);
}
gdImage* fswc_gdImageDuplicate(gdImage* src)
{
gdImage *dst;
dst = gdImageCreateTrueColor(gdImageSX(src), gdImageSY(src));
if(!dst) return(NULL);
gdImageCopy(dst, src, 0, 0, 0, 0, gdImageSX(src), gdImageSY(src));
return(dst);
}
int fswc_output(fswebcam_config_t *config, char *name, gdImage *image)
{
char filename[FILENAME_MAX];
gdImage *im;
FILE *f;
if(!name) return(-1);
if(!strncmp(name, "-", 2) && config->background)
{
ERROR("stdout is unavailable in background mode.");
return(-1);
}
fswc_strftime(filename, FILENAME_MAX, name,
config->start, config->gmt);
/* Create a temporary image buffer. */
im = fswc_gdImageDuplicate(image);
if(!im)
{
ERROR("Out of memory.");
return(-1);
}
/* Draw the underlay. */
fswc_draw_overlay(config, config->underlay, im);
/* Draw the banner. */
if(config->banner != NO_BANNER)
{
char *err;
/* Check if drawing text works */
err = gdImageStringFT(NULL, NULL, 0, config->font, config->fontsize, 0.0, 0, 0, "");
if(!err) fswc_draw_banner(config, im);
else
{
/* Can't load the font - display a warning */
WARN("Unable to load font '%s': %s", config->font, err);
WARN("Disabling the the banner.");
}
}
/* Draw the overlay. */
fswc_draw_overlay(config, config->overlay, im);
/* Write to a file if a filename was given, otherwise stdout. */
if(strncmp(name, "-", 2)) f = fopen(filename, "wb");
else f = stdout;
if(!f)
{
ERROR("Error opening file for output: %s", filename);
ERROR("fopen: %s", strerror(errno));
gdImageDestroy(im);
return(-1);
}
/* Write the compressed image. */
MSG("Writing JPEG image to '%s'.", filename);
gdImageJpeg(im, f, config->compression);
//break;
if(f != stdout) fclose(f);
gdImageDestroy(im);
return(0);
}
int fswc_exec(fswebcam_config_t *config, char *cmd)
{
char *cmdline;
FILE *p;
cmdline = fswc_strduptime(cmd, config->start, config->gmt);
if(!cmdline) return(-1);
MSG("Executing '%s'...", cmdline);
p = popen(cmdline, "r");
free(cmdline);
if(p)
{
while(!feof(p))
{
char *n;
char line[1024];
if(!fgets(line, 1024, p)) break;
while((n = strchr(line, '\n'))) *n = '\0';
MSG("%s", line);
}
pclose(p);
}
else
{
ERROR("popen: %s", strerror(errno));
return(-1);
}
return(0);
}
int fswc_grab(fswebcam_config_t *config)
{
int countImages=0;
while(1){
char* deviceName="/dev/video0";//strdup("/dev/video0")
uint32_t frame;
uint32_t x, y;
avgbmp_t *abitmap, *pbitmap;
gdImage *image, *original;
uint8_t modified;
src_t src;
/* Set source options... */
memset(&src, 0, sizeof(src));
src.input = config->input;
src.tuner = config->tuner;
src.frequency = config->frequency;
src.delay = config->delay;
src.timeout = 15; /* seconds */
src.use_read = config->use_read;
src.list = config->list;
src.palette = config->palette;
src.width = config->width;
src.height = config->height;
src.fps = config->fps;
src.option = config->option;
HEAD("--- Opening %s...%s", deviceName, config->device);
printf("--- Opening %s...%s", deviceName, config->device);
if(src_open(&src, deviceName) == -1) return(-1);
//if(src_open(&src, config->device) == -1) return(-1);
/* The source may have adjusted the width and height we passed
* to it. Update the main config to match. */
//
char countImageStr[20];
while(1){
countImages++;
/* Record the start time. */
config->start = time(NULL);
/* Allocate memory for the average bitmap buffer. */
/* Allocate memory for the average bitmap buffer. */
abitmap = calloc(config->width * config->height * 3, sizeof(avgbmp_t));
if(!abitmap)
{
ERROR("Out of memory.");
return(-1);
}
HEAD("--- Capturing frame...");
//if required timeout , break
if(src_grab(&src) != -1) {
/* Add frame to the average bitmap. */
fswc_add_image_jpeg(&src, abitmap);
}else{
break;
}
HEAD("--- Processing captured image...");
/* Copy the average bitmap image to a gdImage. */
original = gdImageCreateTrueColor(config->width, config->height);
printf("height is %d, width is %d------\n", config->height, config->width);
if(!original)
{
ERROR("Out of memory.");
free(abitmap);
return(-1);
}
pbitmap = abitmap;
for(y = 0; y < config->height; y++)
for(x = 0; x < config->width; x++)
{
int px = x;
int py = y;
int colour;
colour = (*(pbitmap++) / config->frames) << 16;
colour += (*(pbitmap++) / config->frames) << 8;
colour += (*(pbitmap++) / config->frames);
gdImageSetPixel(original, px, py, colour);
}
free(abitmap);
/* Make a copy of the original image. */
image = fswc_gdImageDuplicate(original);
if(!image)
{
ERROR("Out of memory.");
gdImageDestroy(image);
return(-1);
}
/* Run through the jobs list. */
snprintf(countImageStr, 20, "%d", countImages);
printf("countImageStr = %s\n", countImageStr);
//Generate the imgName
char imgName[50];
char imgScaleName[50];
bzero(imgName, 50);
bzero(imgScaleName, 50);
strcat(imgName, config->save);
//strcat(imgName, "img");
strcat(imgName, countImageStr);
strcat(imgName, ".jpg");
strcat(imgScaleName, "scaleImg");
strcat(imgScaleName, countImageStr);
strcat(imgScaleName, ".jpg");
//rotate the image
//image = fx_rotate(image, "180");
usleep(config->interval);
//save file, and scale
fswc_output(config, imgName, image);
//image = fx_scale(image, "256x192");
//fswc_output(config, imgScaleName, image);
gdImageDestroy(image);
gdImageDestroy(original);
}
/* We are now finished with the capture card. */
src_close(&src);
}
return(0);
}
int fswc_openlog(fswebcam_config_t *config)
{
char *s;
int r;
/* Get the first part of the filename. */
s = argdup(config->logfile, ":", 0, 0);
if(!s)
{
ERROR("Out of memory.");
return(-1);
}
if(!strcasecmp(s, "file"))
{
free(s);
s = argdup(config->logfile, ":", 1, 0);
if(!s)
{
ERROR("No log file was specified.");
return(-1);
}
}
else if(!strcasecmp(s, "syslog"))
{
free(s);
log_syslog(1);
return(0);
}
r = log_open(s);
free(s);
return(r);
}
int fswc_background(fswebcam_config_t *config)
{
pid_t pid, sid;
/* Silence the output if not logging to a file. */
if(!config->logfile) log_set_fd(-1);
/* Fork into the background. */
pid = fork();
if(pid < 0)
{
ERROR("Error going into the background.");
ERROR("fork: %s", strerror(errno));
return(-1);
}
/* Is this the parent process? If so, end it. */
if(pid > 0) exit(0);
umask(0);
/* Create a new SID for the child process. */
sid = setsid();
if(sid < 0)
{
ERROR("Error going into the background.");
ERROR("setsid: %s", strerror(errno));
return(-1);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
return(0);
}
int fswc_savepid(fswebcam_config_t *config)
{
FILE *fpid = fopen(config->pidfile, "wt");
if(!fpid)
{
ERROR("Error saving PID to file '%s'",config->pidfile);
ERROR("fopen: %s", strerror(errno));
return(-1);
}
fprintf(fpid, "%i\n", getpid());
fclose(fpid);
return(0);
}
int fswc_find_palette(char *name)
{
int i;
/* Scan through the palette table until a match is found. */
for(i = 0; src_palette[i].name != NULL; i++)
{
/* If a match was found, return the index. */
if(!strcasecmp(src_palette[i].name, name)) return(i);
}
/* No match was found. */
ERROR("Unrecognised palette format \"%s\". Supported formats:", name);
for(i = 0; src_palette[i].name != NULL; i++)
ERROR("%s", src_palette[i].name);
return(-1);
}
int fswc_set_option(fswebcam_config_t *config, char *option)
{
char *name, *value;
if(!option) return(-1);
name = strdup(option);
if(!name)
{
ERROR("Out of memory.");
return(-1);
}
value = strchr(name, '=');
if(value)
{
*(value++) = '\0';
if(*value == '\0') value = NULL;
}
src_set_option(&config->option, name, value);
free(name);
return(0);
}
int fswc_getopt_file(fswc_getopt_t *s)
{
char line[1024];
char *arg, *val;
struct option *opt;
while(fgets(line, 1024, s->f))
{
s->line++;
strtrim(line, WHITESPACE);
arg = argdup(line, WHITESPACE, 0, 0);
if(!arg) continue;
if(*arg == '#') continue;
/* Find argument in the list. */
opt = (struct option *) s->long_opts;
while(opt->name)
{
if(!strcasecmp(opt->name, arg)) break;
opt++;
}
if(!opt->name)
{
ERROR("Unknown argument: %s", arg);
WARN("%s,%i: %s", s->filename, s->line, line);
free(arg);
return(-2);
}
if(opt->val == 'c')
{
ERROR("You can't use config from a configuration file.");
WARN("%s,%i: %s", s->filename, s->line, line);
free(arg);
return(-2);
}
if(opt->has_arg)
{
val = argdup(line, WHITESPACE, 1, 0);
optarg = val;
}
free(arg);
return(opt->val);
}
/* Have we reached the end of the file? */
if(feof(s->f)) return(-1);
/* No.. there has been an error. */
ERROR("fread: %s", strerror(errno));
return(-2);
}
int fswc_getopt(fswc_getopt_t *s, int argc, char *argv[])
{
int c;
/* If a conf file is opened, read from that. */
if(s->f)
{
/* Read until we find an argument, error or EOF. */
c = fswc_getopt_file(s);
if(c < 0)
{
/* EOF or error. */
fclose(s->f);
s->f = NULL;
if(c == -2) return('!');
}
else return(c);
}
/* Read from the command line. */
c = getopt_long(argc, argv, s->opts, s->long_opts, &s->opt_index);
return(c);
}
int fswc_add_job(fswebcam_config_t *config, uint16_t id, char *options)
{
fswebcam_job_t *job;
void *n;
job = malloc(sizeof(fswebcam_job_t));
if(!job)
{
ERROR("Out of memory.");
return(-1);
}
job->id = id;
if(options) job->options = strdup(options);
else job->options = NULL;
/* Increase the size of the job queue. */
n = realloc(config->job, sizeof(fswebcam_job_t *) * (config->jobs + 1));
if(!n)
{
ERROR("Out of memory.");
if(job->options) free(job->options);
free(job);
return(-1);
}
config->job = n;
/* Add the new job to the queue. */
config->job[config->jobs++] = job;
return(0);
}
int fswc_usage()
{
printf("Usage: fswebcam [<options>] <filename> [[<options>] <filename> ... ]\n"
"\n"
" Options:\n"
"\n"
" -?, --help Display this help page and exit.\n"
" -c, --config <filename> Load configuration from file.\n"
" -q, --quiet Hides all messages except for errors.\n"
" -v, --verbose Displays extra messages while capturing\n"
" --version Displays the version and exits.\n"
" -l, --loop <seconds> Run in loop mode.\n"
" -b, --background Run in the background.\n"
" -o, --output <filename> Output the log to a file.\n"
" -d, --device <name> Sets the source to use.\n"
" -i, --input <number/name> Selects the input to use.\n"
" -t, --tuner <number> Selects the tuner to use.\n"
" -f, --frequency <number> Selects the frequency use.\n"
" -p, --palette <name> Selects the palette format to use.\n"
" -D, --delay <number> Sets the pre-capture delay time. (seconds)\n"
" -r, --resolution <size> Sets the capture resolution, eg. 1024x768 \n"
" --fps <framerate> Sets the capture frame rate.\n"
" -F, --frames <number> Sets the number of frames to capture.\n"
" -S, --skip <number> Sets the number of frames to skip.\n"
" --dumpframe <filename> Dump a raw frame to file.\n"
" -s, --set <name>=<value> Sets a control value.\n"
" --revert Restores original captured image.\n"
" --flip <direction> Flips the image. (h, v)\n"
" --crop <size>[,<offset>] Crop a part of the image.\n"
" --scale <size> Scales the image.\n"
" --rotate <angle> Rotates the image in right angles.\n"
" --deinterlace Reduces interlace artifacts.\n"
" --invert Inverts the images colours.\n"
" --greyscale Removes colour from the image.\n"
" --interval <number> Time between taking two images."
" --swapchannels <c1c2> Swap channels c1 and c2.\n"
" --no-banner Hides the banner.\n"
" --top-banner Puts the banner at the top.\n"
" --bottom-banner Puts the banner at the bottom. (Default)\n"
" --banner-colour <colour> Sets the banner colour. (#AARRGGBB)\n"
" --line-colour <colour> Sets the banner line colour.\n"
" --text-colour <colour> Sets the text colour.\n"
" --font <[name][:size]> Sets the font and/or size.\n"
" --no-shadow Disables the text shadow.\n"
" --shadow Enables the text shadow.\n"
" --title <text> Sets the main title. (top left)\n"
" --no-title Clears the main title.\n"
" --subtitle <text> Sets the sub-title. (bottom left)\n"
" --no-subtitle Clears the sub-title.\n"
" --timestamp <format> Sets the timestamp format. (top right)\n"
" --no-timestamp Clears the timestamp.\n"
" --gmt Use GMT instead of local timezone.\n"
" --info <text> Sets the info text. (bottom right)\n"
" --no-info Clears the info text.\n"
" --underlay <PNG image> Sets the underlay image.\n"
" --no-underlay Clears the underlay.\n"
" --overlay <PNG image> Sets the overlay image.\n"
" --no-overlay Clears the overlay.\n"