63,17 → 63,13 |
|
void elaborate_image(void *imageptr); |
|
TASK grab_task(void *arg) { |
void start_frame_grabber(PID elaborate_task_PID, int channel, struct video_buffer *fbuf) { |
|
struct video_picture vpic; |
struct video_buffer fbuf[2]; |
struct video_window win; |
struct video_channel chan; |
struct video_tuner tuner; |
int on,display,temp,save; |
struct video_picture vpic; |
|
task_nopreempt(); |
|
/* Init videodev driver */ |
VIDEODEV26_open(FRAME_GRABBER_NUMBER); |
|
80,7 → 76,7 |
/* Select the input channel */ |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGCHAN,(unsigned long)&chan); |
|
chan.channel = (int)(arg); |
chan.channel = channel; |
chan.type = VIDEO_VC_TUNER; |
chan.norm = VIDEO_TYPE_CAMERA; |
|
111,38 → 107,6 |
|
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSPICT,(unsigned long)&vpic); |
|
/* Double Buffering Strategy */ |
|
#ifdef COLOR |
|
fbuf[0].base = malloc(FG_W*FG_H*3); |
fbuf[0].height = FG_H; |
fbuf[0].width = FG_W; |
fbuf[0].bytesperline = FG_W*3; |
fbuf[0].depth = 24; |
|
fbuf[1].base = malloc(FG_W*FG_H*3); |
fbuf[1].height = FG_H; |
fbuf[1].width = FG_W; |
fbuf[1].bytesperline = FG_W*3; |
fbuf[1].depth = 24; |
|
#else |
|
fbuf[0].base = malloc(FG_W*FG_H); |
fbuf[0].height = FG_H; |
fbuf[0].width = FG_W; |
fbuf[0].bytesperline = FG_W; |
fbuf[0].depth = 8; |
|
fbuf[1].base = malloc(FG_W*FG_H); |
fbuf[1].height = FG_H; |
fbuf[1].width = FG_W; |
fbuf[1].bytesperline = FG_W; |
fbuf[1].depth = 8; |
|
#endif |
|
/* Set grabbing window */ |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGWIN,(unsigned long)&win); |
|
153,35 → 117,55 |
|
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSWIN,(unsigned long)&win); |
|
task_preempt(); |
/* IMPORTANT: Set the aperiodic elaboration task |
* This is a SHARK change on VIDIOCSYNC. When the |
* new frame is ready, the task elaborate_task_PID |
* is activated. Elabortate_task must be aperiodic !! |
* To link the task to BTTV use this function: */ |
|
display = 1; |
save = 0; |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSYNC,(unsigned long)(elaborate_task_PID)); |
|
while(1) { |
} |
|
task_nopreempt(); |
|
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
/* Elaboration task, it is called when the frame |
grabber buffer is ready */ |
TASK elaborate_task(void *arg) { |
|
/* Start grabbing */ |
on = 1; |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCCAPTURE,(unsigned long)&on); |
struct video_buffer *fbuf = (struct video_buffer *)(arg); |
|
task_preempt(); |
while(1) { |
|
/* |
elaborate_image(fbuf->base); |
|
/* Text version |
printf_xy(1,20,WHITE,"%08x", |
*(unsigned int *)(fbuf[display].base+50*320*3+50*3)); |
*(unsigned int *)(fbuf->base+50*320*3+50*3)); |
*/ |
|
elaborate_image(fbuf[display].base); |
task_testcancel(); |
task_endcycle(); |
|
/* Buffer switch */ |
temp = display; |
display = save; |
save = temp; |
} |
|
return NULL; |
|
} |
|
/* Send the grab command */ |
TASK grab_task(void *arg) { |
|
struct video_buffer *fbuf = (struct video_buffer *)(arg); |
int on; |
|
while(1) { |
|
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSFBUF,(unsigned long)(fbuf)); |
|
/* Grab */ |
on = 1; |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCCAPTURE,(unsigned long)&on); |
|
task_testcancel(); |
task_endcycle(); |
|
226,26 → 210,65 |
int main(int argc, char **argv) |
{ |
|
SOFT_TASK_MODEL st; |
PID grab_task_pid; |
HARD_TASK_MODEL gt; |
SOFT_TASK_MODEL et; |
PID grab_task_pid,elaborate_task_pid; |
|
struct video_buffer fbuf; |
int channel = 0; |
|
if (argc < 2) { |
sys_shutdown_message("ERROR: Enter the input channel [ex> %s 0]\n",argv[0]); |
sys_end(); |
} |
|
soft_task_default_model(st); |
soft_task_def_period(st,40000); |
soft_task_def_met(st,30000); |
soft_task_def_arg(st, (void *)(atoi(argv[1]))); |
soft_task_def_ctrl_jet(st); |
channel = atoi(argv[1]); |
|
grab_task_pid = task_create("GrabTask",grab_task,&st,NULL); |
soft_task_default_model(et); |
soft_task_def_period(et,40000); |
soft_task_def_arg(et,(void *)(&fbuf)); |
soft_task_def_met(et,30000); |
soft_task_def_aperiodic(et); |
soft_task_def_ctrl_jet(et); |
|
hard_task_default_model(gt); |
hard_task_def_mit(gt,40000); |
hard_task_def_arg(gt,(void *)(&fbuf)); |
hard_task_def_wcet(gt,3000); |
hard_task_def_ctrl_jet(gt); |
|
grab_task_pid = task_create("GrabTask",grab_task,>,NULL); |
if (grab_task_pid == NIL) { |
sys_shutdown_message("ERROR: Cannot create grab task\n"); |
sys_end(); |
} |
|
elaborate_task_pid = task_create("ElaborateTask",elaborate_task,&et,NULL); |
if (grab_task_pid == NIL) { |
sys_shutdown_message("ERROR: Cannot create elaborate task\n"); |
sys_end(); |
} |
|
#ifdef COLOR |
|
fbuf.base = malloc(FG_W*FG_H*3); |
fbuf.height = FG_H; |
fbuf.width = FG_W; |
fbuf.bytesperline = FG_W*3; |
fbuf.depth = 24; |
|
#else |
|
fbuf.base = malloc(FG_W*FG_H); |
fbuf.height = FG_H; |
fbuf.width = FG_W; |
fbuf.bytesperline = FG_W; |
fbuf.depth = 8; |
|
#endif |
|
start_frame_grabber(elaborate_task_pid,channel,&fbuf); |
|
task_activate(grab_task_pid); |
|
while(keyb_getch(BLOCK) != ESC); |