Rev 179 | Rev 186 | 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 | |||
35 | while(1) { |
||
36 | |||
37 | if (vmm.frame == 0) { |
||
38 | vmm.frame = 1; |
||
39 | fbuf_pointer = btv.fbuffer; |
||
177 | giacomo | 40 | *(BYTE *)fbuf_pointer = 255; |
41 | *(BYTE *)(fbuf_pointer+1) = 0; |
||
170 | giacomo | 42 | } else { |
43 | vmm.frame = 0; |
||
44 | fbuf_pointer = btv.fbuffer+gbufsize; |
||
177 | giacomo | 45 | *(BYTE *)fbuf_pointer = 0; |
46 | *(BYTE *)(fbuf_pointer+1) = 255; |
||
170 | giacomo | 47 | } |
48 | |||
49 | bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm); |
||
173 | giacomo | 50 | |
51 | elaborate_frame_hook(fbuf_pointer); |
||
52 | |||
170 | giacomo | 53 | task_endcycle(); |
54 | |||
55 | } |
||
56 | |||
57 | } |
||
58 | |||
182 | giacomo | 59 | int FG_init(unsigned int period, unsigned int wcet, unsigned int width, |
60 | unsigned int height, unsigned int color, unsigned int channel) { |
||
170 | giacomo | 61 | |
62 | struct video_window vw; |
||
63 | struct video_picture p; |
||
64 | struct video_channel ch; |
||
65 | |||
66 | hard_task_default_model(ht_refresh); |
||
67 | hard_task_def_wcet(ht_refresh, wcet); |
||
68 | hard_task_def_mit(ht_refresh, period); |
||
69 | hard_task_def_ctrl_jet(ht_refresh); |
||
70 | |||
71 | refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL); |
||
72 | if (refresh_PID == -1) { |
||
73 | sys_end(); |
||
74 | } |
||
179 | giacomo | 75 | |
170 | giacomo | 76 | bttv_start(&btv); |
77 | |||
78 | bttv_ioctl(&btv, VIDIOCGWIN, &vw); |
||
79 | vw.x = 0; |
||
80 | vw.y = 0; |
||
81 | vw.width = width; |
||
82 | vw.height = height; |
||
83 | bttv_ioctl(&btv, VIDIOCSWIN, &vw); |
||
84 | |||
85 | bttv_ioctl(&btv, VIDIOCGPICT, &p); |
||
177 | giacomo | 86 | if (color == FG_RGB24) { |
87 | p.palette = VIDEO_PALETTE_RGB24; |
||
88 | p.depth = 24; |
||
89 | } |
||
90 | if (color == FG_MONO) { |
||
91 | p.palette = VIDEO_PALETTE_GREY; |
||
92 | p.depth = 8; |
||
93 | } |
||
170 | giacomo | 94 | bttv_ioctl(&btv, VIDIOCSPICT, &p); |
95 | |||
96 | bttv_ioctl(&btv, VIDIOCGCHAN, &ch); |
||
182 | giacomo | 97 | ch.channel = channel; |
170 | giacomo | 98 | ch.norm = 3; |
99 | bttv_ioctl(&btv, VIDIOCSCHAN, &ch); |
||
100 | |||
101 | vmm.frame = 0; |
||
102 | vmm.height = vw.height; |
||
103 | vmm.width = vw.width; |
||
104 | vmm.format = p.palette; |
||
105 | bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm); |
||
173 | giacomo | 106 | |
107 | elaborate_frame_hook = dummy_elaborate_frame; |
||
170 | giacomo | 108 | |
173 | giacomo | 109 | sleep(1); |
110 | |||
170 | giacomo | 111 | return 0; |
112 | |||
113 | } |
||
114 | |||
177 | giacomo | 115 | void FG_start_grabbing(void) |
116 | { |
||
117 | |||
118 | task_activate(refresh_PID); |
||
179 | giacomo | 119 | |
177 | giacomo | 120 | } |
121 | |||
178 | giacomo | 122 | void FG_close(void) |
177 | giacomo | 123 | { |
124 | |||
170 | giacomo | 125 | bttv_close(&btv); |
126 | |||
127 | } |
||
128 | |||
129 | void * FG_getbuffer(void) |
||
130 | { |
||
131 | |||
132 | return fbuf_pointer; |
||
133 | |||
134 | } |
||
135 | |||
173 | giacomo | 136 | void FG_set_hook(void * funptr) |
137 | { |
||
138 | |||
139 | elaborate_frame_hook = (void *)funptr; |
||
140 | |||
141 | } |