Subversion Repositories shark

Rev

Rev 256 | 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;
267 giacomo 42
/*          *(BYTE *)fbuf_pointer = 255;
43
 *          *(BYTE *)(fbuf_pointer+1) = 0;
44
 */
170 giacomo 45
    } else {
46
            vmm.frame = 0;
47
            fbuf_pointer = btv.fbuffer+gbufsize;
267 giacomo 48
/*          *(BYTE *)fbuf_pointer = 0;
49
 *          *(BYTE *)(fbuf_pointer+1) = 255;
50
 */
170 giacomo 51
    }
256 giacomo 52
 
53
    task_testcancel();
170 giacomo 54
 
231 giacomo 55
    err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
56
    if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
57
 
173 giacomo 58
    elaborate_frame_hook(fbuf_pointer);
59
 
170 giacomo 60
    task_endcycle();
61
 
62
  }
63
 
64
}
65
 
182 giacomo 66
int FG_init(unsigned int period, unsigned int wcet, unsigned int width,
67
                unsigned int height, unsigned int color, unsigned int channel) {
170 giacomo 68
 
231 giacomo 69
  int err;
70
 
170 giacomo 71
  struct video_window vw;
72
  struct video_picture p;
73
  struct video_channel ch;
74
 
75
  hard_task_default_model(ht_refresh);
76
  hard_task_def_wcet(ht_refresh, wcet);
77
  hard_task_def_mit(ht_refresh, period);
78
  hard_task_def_ctrl_jet(ht_refresh);
79
 
80
  refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL);
81
  if (refresh_PID == -1) {
267 giacomo 82
    cprintf("could not create task, err no=%d\n",errno);
170 giacomo 83
    sys_end();
84
  }
179 giacomo 85
 
170 giacomo 86
  bttv_start(&btv);
231 giacomo 87
 
88
  err = bttv_ioctl(&btv, VIDIOCGWIN, &vw);
267 giacomo 89
  if (err) {
90
        kern_printf("(BTTV_IOCTL VIDIOCGWIN Error: %d)",err);
91
        sys_end();
92
  }
170 giacomo 93
  vw.x = 0;
94
  vw.y = 0;
95
  vw.width = width;
96
  vw.height = height;
231 giacomo 97
  err = bttv_ioctl(&btv, VIDIOCSWIN, &vw);
267 giacomo 98
  if (err) {
99
        kern_printf("(BTTV_IOCTL VIDIOCSWIN Error: %d)",err);
100
        sys_end();
101
  }
102
 
231 giacomo 103
  err = bttv_ioctl(&btv, VIDIOCGPICT, &p);
267 giacomo 104
  if (err) {
105
        kern_printf("(BTTV_IOCTL VIDIOCGPICT Error: %d)",err);
106
        sys_end();
107
  }
108
 
177 giacomo 109
  if (color == FG_RGB24) {
110
    p.palette = VIDEO_PALETTE_RGB24;
111
    p.depth = 24;
112
  }
113
  if (color == FG_MONO) {
114
    p.palette = VIDEO_PALETTE_GREY;
115
    p.depth = 8;
116
  }    
267 giacomo 117
  if (color == FG_YUYV) {
118
    p.palette = VIDEO_PALETTE_YUYV;
119
    p.depth = 16;
120
  }
121
 
231 giacomo 122
  err = bttv_ioctl(&btv, VIDIOCSPICT, &p);
267 giacomo 123
  if (err) {
124
        kern_printf("(BTTV_IOCTL VIDIOCSPICT Error: %d)",err);
125
        sys_end();
126
  }
127
 
128
  ch.channel = channel;
231 giacomo 129
  err = bttv_ioctl(&btv, VIDIOCGCHAN, &ch);
267 giacomo 130
  if (err) {
131
        kern_printf("(BTTV_IOCTL VIDIOCGCHAN Error: %d)",err);
132
        sys_end();
133
  }
134
   ch.norm = VIDEO_MODE_PAL;
135
   ch.type = VIDEO_TYPE_CAMERA;
231 giacomo 136
  err = bttv_ioctl(&btv, VIDIOCSCHAN, &ch);
267 giacomo 137
  if (err) {
138
        kern_printf("(BTTV_IOCTL VIDIOCSCHAN Error: %d)",err);
139
        sys_end();
140
  }
170 giacomo 141
 
142
  vmm.frame = 0;
143
  vmm.height = vw.height;
144
  vmm.width = vw.width;
145
  vmm.format = p.palette;
231 giacomo 146
  err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
267 giacomo 147
  if (err) {
148
        kern_printf("(BTTV_IOCTL VIDIOCMCAPTURE Error: %d)",err);
149
        sys_end();
150
  }
173 giacomo 151
  elaborate_frame_hook = dummy_elaborate_frame;
170 giacomo 152
 
173 giacomo 153
  sleep(1);
154
 
170 giacomo 155
  return 0;
156
 
157
}
158
 
177 giacomo 159
void FG_start_grabbing(void)
160
{
161
 
162
  task_activate(refresh_PID);
179 giacomo 163
 
177 giacomo 164
}
165
 
178 giacomo 166
void FG_close(void)
177 giacomo 167
{
188 giacomo 168
 
169
  task_kill(refresh_PID);  
267 giacomo 170
/*   sleep(1);
171
 */
170 giacomo 172
  bttv_close(&btv);
186 giacomo 173
 
170 giacomo 174
}
175
 
176
void * FG_getbuffer(void)
177
{
178
 
179
  return fbuf_pointer;
180
 
181
}
182
 
173 giacomo 183
void FG_set_hook(void * funptr)
184
{
185
 
186
  elaborate_frame_hook = (void *)funptr;
187
 
188
}