Subversion Repositories shark

Rev

Rev 267 | 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
 
177 giacomo 8
#include <drivers/fg.h>
170 giacomo 9
 
428 giacomo 10
#include <linuxcomp.h>
11
 
12
#include <drivers/bttv.h>
13
#include <drivers/bttvp.h>
14
 
170 giacomo 15
extern void bttv_start(struct bttv *btv);
16
extern int bttv_ioctl(struct bttv *btv, unsigned int cmg, void *arg);
17
extern void bttv_close(struct bttv *btv);
18
 
19
extern unsigned int gbufsize;
20
 
21
static struct bttv btv;
22
static struct video_mmap vmm;
173 giacomo 23
static void * fbuf_pointer;
170 giacomo 24
 
173 giacomo 25
static void (*elaborate_frame_hook)(void * ptrframe);
26
 
27
void dummy_elaborate_frame(void * ptrframe)
28
{
29
}
30
 
428 giacomo 31
void FG_refresh(void)
170 giacomo 32
{
33
 
231 giacomo 34
  int err;
35
 
170 giacomo 36
  while(1) {
37
 
38
    if (vmm.frame == 0) {
39
            vmm.frame = 1;
428 giacomo 40
           // fbuf_pointer = (void *)(btv.fbuffer);
267 giacomo 41
/*          *(BYTE *)fbuf_pointer = 255;
42
 *          *(BYTE *)(fbuf_pointer+1) = 0;
43
 */
170 giacomo 44
    } else {
45
            vmm.frame = 0;
428 giacomo 46
            //fbuf_pointer = btv.fbuffer+gbufsize;
267 giacomo 47
/*          *(BYTE *)fbuf_pointer = 0;
48
 *          *(BYTE *)(fbuf_pointer+1) = 255;
49
 */
170 giacomo 50
    }
256 giacomo 51
 
231 giacomo 52
    err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
428 giacomo 53
    if (err) //kern_printf("(BTTV_IOCTL Error: %d)",err);
231 giacomo 54
 
173 giacomo 55
    elaborate_frame_hook(fbuf_pointer);
56
 
170 giacomo 57
  }
58
 
59
}
60
 
182 giacomo 61
int FG_init(unsigned int period, unsigned int wcet, unsigned int width,
62
                unsigned int height, unsigned int color, unsigned int channel) {
170 giacomo 63
 
231 giacomo 64
  int err;
65
 
170 giacomo 66
  struct video_window vw;
67
  struct video_picture p;
68
  struct video_channel ch;
69
 
70
  bttv_start(&btv);
231 giacomo 71
 
72
  err = bttv_ioctl(&btv, VIDIOCGWIN, &vw);
267 giacomo 73
  if (err) {
428 giacomo 74
        //kern_printf("(BTTV_IOCTL VIDIOCGWIN Error: %d)",err);
267 giacomo 75
  }
170 giacomo 76
  vw.x = 0;
77
  vw.y = 0;
78
  vw.width = width;
79
  vw.height = height;
231 giacomo 80
  err = bttv_ioctl(&btv, VIDIOCSWIN, &vw);
267 giacomo 81
  if (err) {
428 giacomo 82
        //kern_printf("(BTTV_IOCTL VIDIOCSWIN Error: %d)",err);
83
        //sys_end();
267 giacomo 84
  }
85
 
231 giacomo 86
  err = bttv_ioctl(&btv, VIDIOCGPICT, &p);
267 giacomo 87
  if (err) {
428 giacomo 88
        //kern_printf("(BTTV_IOCTL VIDIOCGPICT Error: %d)",err);
89
        //sys_end();
267 giacomo 90
  }
91
 
177 giacomo 92
  if (color == FG_RGB24) {
93
    p.palette = VIDEO_PALETTE_RGB24;
94
    p.depth = 24;
95
  }
96
  if (color == FG_MONO) {
97
    p.palette = VIDEO_PALETTE_GREY;
98
    p.depth = 8;
99
  }    
267 giacomo 100
  if (color == FG_YUYV) {
101
    p.palette = VIDEO_PALETTE_YUYV;
102
    p.depth = 16;
103
  }
104
 
231 giacomo 105
  err = bttv_ioctl(&btv, VIDIOCSPICT, &p);
267 giacomo 106
  if (err) {
428 giacomo 107
        //kern_printf("(BTTV_IOCTL VIDIOCSPICT Error: %d)",err);
108
        //sys_end();
267 giacomo 109
  }
110
 
111
  ch.channel = channel;
231 giacomo 112
  err = bttv_ioctl(&btv, VIDIOCGCHAN, &ch);
267 giacomo 113
  if (err) {
428 giacomo 114
        //kern_printf("(BTTV_IOCTL VIDIOCGCHAN Error: %d)",err);
115
        //sys_end();
267 giacomo 116
  }
117
   ch.norm = VIDEO_MODE_PAL;
118
   ch.type = VIDEO_TYPE_CAMERA;
231 giacomo 119
  err = bttv_ioctl(&btv, VIDIOCSCHAN, &ch);
267 giacomo 120
  if (err) {
428 giacomo 121
        //kern_printf("(BTTV_IOCTL VIDIOCSCHAN Error: %d)",err);
122
        //sys_end();
267 giacomo 123
  }
170 giacomo 124
 
125
  vmm.frame = 0;
126
  vmm.height = vw.height;
127
  vmm.width = vw.width;
128
  vmm.format = p.palette;
231 giacomo 129
  err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
267 giacomo 130
  if (err) {
428 giacomo 131
        //kern_printf("(BTTV_IOCTL VIDIOCMCAPTURE Error: %d)",err);
132
        //sys_end();
267 giacomo 133
  }
173 giacomo 134
  elaborate_frame_hook = dummy_elaborate_frame;
170 giacomo 135
 
136
  return 0;
137
 
138
}
139
 
177 giacomo 140
void FG_start_grabbing(void)
141
{
142
 
179 giacomo 143
 
177 giacomo 144
}
145
 
178 giacomo 146
void FG_close(void)
177 giacomo 147
{
188 giacomo 148
 
170 giacomo 149
  bttv_close(&btv);
186 giacomo 150
 
170 giacomo 151
}
152
 
153
void * FG_getbuffer(void)
154
{
155
 
156
  return fbuf_pointer;
157
 
158
}
159
 
173 giacomo 160
void FG_set_hook(void * funptr)
161
{
162
 
163
  elaborate_frame_hook = (void *)funptr;
164
 
165
}