int video_capture(struct video_device * device_wrapper, void*mem) { struct video_internal*device = (struct video_internal*)(device_wrapper->internal); int f,nf; if(!device->frame) { int n; for(n=0;n<device->mbuf.frames;n++) { myioctl(device->dev, VIDIOCMCAPTURE, &device->map[n]); } } f = device->frame % device->mbuf.frames; again: /* returns -1 in case of a sigint interrupting */ if(ioctl(device->dev, VIDIOCSYNC, &device->map[f].frame)<0) { perror("video_capture()"); if(errno == 4) /* interrupted system call */ goto again; return 0; } memcpy(mem, device->mem+device->mbuf.offsets[f], device->picsize); myioctl(device->dev, VIDIOCMCAPTURE, &device->map[f]); device_wrapper->frame ++; device->frame ++; return 1; }
int video_capture_image(struct video_device * device_wrapper, image_t*img) { struct video_internal*device = (struct video_internal*)(device_wrapper->internal); int f,nf; if(!device->frame) { int n; for(n=0;n<device->mbuf.frames;n++) { myioctl(device->dev, VIDIOCMCAPTURE, &device->map[n]); } } f = device->frame % device->mbuf.frames; again: /* returns -1 in case of a sigint interrupting */ if(ioctl(device->dev, VIDIOCSYNC, &device->map[f].frame)<0) { perror("video_capture()"); if(errno == 4) /* interrupted system call */ goto again; return 0; } assert(img->width*img->height*3==device->picsize); // memcpy(mem, device->mem+device->mbuf.offsets[f], device->picsize); unsigned char*src = device->mem+device->mbuf.offsets[f]; int s=0,t; for(t=0;t<device->picsize;t+=3) { img->data[s].r = src[t]; img->data[s].g = src[t+1]; img->data[s].b = src[t+2]; img->data[s].a = 0xff; s++; } myioctl(device->dev, VIDIOCMCAPTURE, &device->map[f]); device_wrapper->frame ++; device->frame ++; return 1; }
void I_InitSound ( int samplerate, int samplesize ) { int i; audio_fd = open("/dev/dsp", O_WRONLY); if (audio_fd<0) fprintf(stderr, "Could not open /dev/dsp\n"); i = 11 | (2<<16); myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i); myioctl(audio_fd, SNDCTL_DSP_RESET, 0); i=11025; myioctl(audio_fd, SNDCTL_DSP_SPEED, &i); i=1; myioctl(audio_fd, SNDCTL_DSP_STEREO, &i); myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i); if (i&=AFMT_S16_LE) myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i); else fprintf(stderr, "Could not play signed 16 data\n"); }
struct video_device* init_video(char*devname,int x,int y) { char* channel = "Composite1"; const int zero = 0; const int one = 1; const int two = 2; const int three = 3; const int four = 4; const int five = 5; int t; struct video_internal* device; struct video_device* device_wrapper; device_wrapper = (struct video_device*)malloc(sizeof(struct video_device)); device = (struct video_internal*)malloc(sizeof(struct video_internal)); device_wrapper->internal = device; /* VIDEO */ printf("Opening %s\n", devname); device->dev = open(devname, O_RDWR); if(device->dev < 0) { char buf[64]; sprintf(buf, "open %s", devname); perror(buf); exit(1); } if(verbose) printf("CAPABILITIES:\n"); myioctl(device->dev, VIDIOCGCAP, &device->cap); if(verbose) info_capabilities(&device->cap); if(verbose) printf("CHANNELS:\n"); for(t=0;t<device->cap.channels;t++) { struct video_channel chan; int set = 0; chan.channel = t; myioctl(device->dev, VIDIOCGCHAN, &chan); if(verbose) info_channel(&chan); if(t==0) memcpy(&device->chan, &chan, sizeof(chan)); if(!strcmp(chan.name, channel)) { set = 1; memcpy(&device->chan, &chan, sizeof(chan)); if(verbose) { printf("^^^^^^^^^^^^^^^^^^^^^^^^ selecting channel %d\n", chan.channel); } } if(chan.type&VIDEO_VC_TUNER) { unsigned long freq; device->tuner.tuner = 0; myioctl(device->dev, VIDIOCGTUNER, &device->tuner); if(verbose) { info_tuner(&device->tuner); } myioctl(device->dev, VIDIOCGFREQ, &freq); if(verbose) { printf("tuner frequency: %d\n", freq); } } } if(verbose) printf("setting channel \"%s\"...\n", device->chan.name); myioctl(device->dev, VIDIOCSCHAN, &device->chan); if(verbose) printf("device->picture:\n"); myioctl(device->dev, VIDIOCGPICT, &device->picture); if(verbose) info_picture(&device->picture); device->picture.brightness = 2; device->picture.contrast = 49152; myioctl(device->dev, VIDIOCSPICT, &device->picture); if(verbose) printf("device->window:\n"); myioctl(device->dev, VIDIOCGWIN, &device->window); if(verbose) info_window(&device->window); /* ? framebuffer overlay: myioctl(device->dev, VIDIOCSWIN, &device->window);*/ if(verbose) printf("device->buffer:\n"); myioctl(device->dev, VIDIOCGFBUF, &device->buffer); if(verbose) info_buffer(&device->buffer); if(verbose) printf("device->audio:\n"); for(t=0;t<device->cap.audios;t++) { myioctl(device->dev, VIDIOCGAUDIO, &device->audio); if(verbose) info_audio(&device->audio); } if(verbose) printf("device->mbuf:\n"); myioctl(device->dev, VIDIOCGMBUF, &device->mbuf); if(verbose) info_mbuf(&device->mbuf); device->mem =(unsigned char *)mmap(0,device->mbuf.size,PROT_READ|PROT_WRITE,MAP_SHARED,device->dev,0); if((unsigned char*)-1 == device->mem) { fprintf(stderr, "Unable to allocate memory!\n"); } if(verbose) printf("Memory: %08x\n", device->mem); device->map[0].frame = 0; device->map[1].frame = 1; device->map[0].width = device->map[1].width = x; device->map[0].height = device->map[1].height = y; //device->map[0].format = device->map[1].format = VIDEO_PALETTE_GREY; device->map[0].format = device->map[1].format = VIDEO_PALETTE_RGB24; //RGB32 device->picsize = ((3 * x + 3)&~3) * y; device_wrapper->frame = 0; device->frame = 0; return device_wrapper; }