Blame |
Last modification |
View Log
| RSS feed
/* Fast Frame Grabber for SHARK
*
* Giacomo Guidi
* <giacomo@gandalf.sssup.it>
*
*/
#include <drivers/bttv.h>
#include <kernel/kern.h>
extern void bttv_start(struct bttv *btv);
extern int bttv_ioctl(struct bttv *btv, unsigned int cmg, void *arg);
extern void bttv_close(struct bttv *btv);
extern unsigned int gbufsize;
static struct bttv btv;
static struct video_mmap vmm;
void * fbuf_pointer;
TASK FG_refresh(void)
{
while(1) {
if (vmm.frame == 0) {
vmm.frame = 1;
fbuf_pointer = btv.fbuffer;
} else {
vmm.frame = 0;
fbuf_pointer = btv.fbuffer+gbufsize;
}
bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
task_endcycle();
}
}
int FG_init(unsigned int period, unsigned int wcet, unsigned int width, unsigned int height) {
HARD_TASK_MODEL ht_refresh;
PID refresh_PID;
struct video_window vw;
struct video_picture p;
struct video_channel ch;
hard_task_default_model(ht_refresh);
hard_task_def_wcet(ht_refresh, wcet);
hard_task_def_mit(ht_refresh, period);
hard_task_def_ctrl_jet(ht_refresh);
refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL);
if (refresh_PID == -1) {
sys_end();
}
bttv_start(&btv);
bttv_ioctl(&btv, VIDIOCGWIN, &vw);
vw.x = 0;
vw.y = 0;
vw.width = width;
vw.height = height;
bttv_ioctl(&btv, VIDIOCSWIN, &vw);
bttv_ioctl(&btv, VIDIOCGPICT, &p);
p.palette = VIDEO_PALETTE_GREY; //GREY mode 8 bpp
p.depth = 8;
bttv_ioctl(&btv, VIDIOCSPICT, &p);
bttv_ioctl(&btv, VIDIOCGCHAN, &ch);
ch.channel = 0;
ch.norm = 3;
bttv_ioctl(&btv, VIDIOCSCHAN, &ch);
vmm.frame = 0;
vmm.height = vw.height;
vmm.width = vw.width;
vmm.format = p.palette;
bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
task_activate(refresh_PID);
return 0;
}
void FG_close(void)
{
bttv_close(&btv);
}
void * FG_getbuffer(void)
{
return fbuf_pointer;
}