Subversion Repositories shark

Rev

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