Rev 231 | Rev 267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
170 | giacomo | 1 | /* Fast Frame Grabber for SHARK |
2 | * |
||
3 | * Giacomo Guidi |
||
4 | * <giacomo@gandalf.sssup.it> |
||
5 | * |
||
6 | */ |
||
7 | |||
8 | #include <drivers/bttv.h> |
||
177 | giacomo | 9 | #include <drivers/fg.h> |
170 | giacomo | 10 | #include <kernel/kern.h> |
173 | giacomo | 11 | #include <unistd.h> |
170 | giacomo | 12 | |
13 | extern void bttv_start(struct bttv *btv); |
||
14 | extern int bttv_ioctl(struct bttv *btv, unsigned int cmg, void *arg); |
||
15 | extern void bttv_close(struct bttv *btv); |
||
16 | |||
17 | extern unsigned int gbufsize; |
||
18 | |||
19 | static struct bttv btv; |
||
20 | static struct video_mmap vmm; |
||
173 | giacomo | 21 | static void * fbuf_pointer; |
170 | giacomo | 22 | |
177 | giacomo | 23 | PID refresh_PID; |
24 | HARD_TASK_MODEL ht_refresh; |
||
25 | |||
173 | giacomo | 26 | static void (*elaborate_frame_hook)(void * ptrframe); |
27 | |||
28 | void dummy_elaborate_frame(void * ptrframe) |
||
29 | { |
||
30 | } |
||
31 | |||
170 | giacomo | 32 | TASK FG_refresh(void) |
33 | { |
||
34 | |||
231 | giacomo | 35 | int err; |
36 | |||
170 | giacomo | 37 | while(1) { |
38 | |||
39 | if (vmm.frame == 0) { |
||
40 | vmm.frame = 1; |
||
41 | fbuf_pointer = btv.fbuffer; |
||
177 | giacomo | 42 | *(BYTE *)fbuf_pointer = 255; |
43 | *(BYTE *)(fbuf_pointer+1) = 0; |
||
170 | giacomo | 44 | } else { |
45 | vmm.frame = 0; |
||
46 | fbuf_pointer = btv.fbuffer+gbufsize; |
||
177 | giacomo | 47 | *(BYTE *)fbuf_pointer = 0; |
48 | *(BYTE *)(fbuf_pointer+1) = 255; |
||
170 | giacomo | 49 | } |
256 | giacomo | 50 | |
51 | task_testcancel(); |
||
170 | giacomo | 52 | |
231 | giacomo | 53 | err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm); |
54 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
55 | |||
173 | giacomo | 56 | elaborate_frame_hook(fbuf_pointer); |
57 | |||
170 | giacomo | 58 | task_endcycle(); |
59 | |||
60 | } |
||
61 | |||
62 | } |
||
63 | |||
182 | giacomo | 64 | int FG_init(unsigned int period, unsigned int wcet, unsigned int width, |
65 | unsigned int height, unsigned int color, unsigned int channel) { |
||
170 | giacomo | 66 | |
231 | giacomo | 67 | int err; |
68 | |||
170 | giacomo | 69 | struct video_window vw; |
70 | struct video_picture p; |
||
71 | struct video_channel ch; |
||
72 | |||
73 | hard_task_default_model(ht_refresh); |
||
74 | hard_task_def_wcet(ht_refresh, wcet); |
||
75 | hard_task_def_mit(ht_refresh, period); |
||
76 | hard_task_def_ctrl_jet(ht_refresh); |
||
77 | |||
78 | refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL); |
||
79 | if (refresh_PID == -1) { |
||
80 | sys_end(); |
||
81 | } |
||
179 | giacomo | 82 | |
170 | giacomo | 83 | bttv_start(&btv); |
231 | giacomo | 84 | |
85 | err = bttv_ioctl(&btv, VIDIOCGWIN, &vw); |
||
86 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
170 | giacomo | 87 | vw.x = 0; |
88 | vw.y = 0; |
||
89 | vw.width = width; |
||
90 | vw.height = height; |
||
231 | giacomo | 91 | err = bttv_ioctl(&btv, VIDIOCSWIN, &vw); |
92 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
170 | giacomo | 93 | |
231 | giacomo | 94 | err = bttv_ioctl(&btv, VIDIOCGPICT, &p); |
95 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
177 | giacomo | 96 | if (color == FG_RGB24) { |
97 | p.palette = VIDEO_PALETTE_RGB24; |
||
98 | p.depth = 24; |
||
99 | } |
||
100 | if (color == FG_MONO) { |
||
101 | p.palette = VIDEO_PALETTE_GREY; |
||
102 | p.depth = 8; |
||
103 | } |
||
231 | giacomo | 104 | err = bttv_ioctl(&btv, VIDIOCSPICT, &p); |
105 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
170 | giacomo | 106 | |
231 | giacomo | 107 | err = bttv_ioctl(&btv, VIDIOCGCHAN, &ch); |
108 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
182 | giacomo | 109 | ch.channel = channel; |
170 | giacomo | 110 | ch.norm = 3; |
231 | giacomo | 111 | err = bttv_ioctl(&btv, VIDIOCSCHAN, &ch); |
112 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
170 | giacomo | 113 | |
114 | vmm.frame = 0; |
||
115 | vmm.height = vw.height; |
||
116 | vmm.width = vw.width; |
||
117 | vmm.format = p.palette; |
||
231 | giacomo | 118 | err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm); |
119 | if (err) kern_printf("(BTTV_IOCTL Error: %d)",err); |
||
173 | giacomo | 120 | |
121 | elaborate_frame_hook = dummy_elaborate_frame; |
||
170 | giacomo | 122 | |
173 | giacomo | 123 | sleep(1); |
124 | |||
170 | giacomo | 125 | return 0; |
126 | |||
127 | } |
||
128 | |||
177 | giacomo | 129 | void FG_start_grabbing(void) |
130 | { |
||
131 | |||
132 | task_activate(refresh_PID); |
||
179 | giacomo | 133 | |
177 | giacomo | 134 | } |
135 | |||
178 | giacomo | 136 | void FG_close(void) |
177 | giacomo | 137 | { |
188 | giacomo | 138 | |
139 | task_kill(refresh_PID); |
||
256 | giacomo | 140 | sleep(1); |
170 | giacomo | 141 | bttv_close(&btv); |
186 | giacomo | 142 | |
170 | giacomo | 143 | } |
144 | |||
145 | void * FG_getbuffer(void) |
||
146 | { |
||
147 | |||
148 | return fbuf_pointer; |
||
149 | |||
150 | } |
||
151 | |||
173 | giacomo | 152 | void FG_set_hook(void * funptr) |
153 | { |
||
154 | |||
155 | elaborate_frame_hook = (void *)funptr; |
||
156 | |||
157 | } |