image28

Record.c

Jul 21st, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.70 KB | None | 0 0
  1. // TCap v0.1
  2. // (C) Thomas Hargrove
  3. // http://toonarchive.com/tcap
  4.  
  5. /***************************************************************************
  6.  *                                                                         *
  7.  *   This program is free software; you can redistribute it and/or modify  *
  8.  *   it under the terms of the GNU General Public License as published by  *
  9.  *   the Free Software Foundation; either version 2 of the License, or     *
  10.  *   (at your option) any later version.                                   *
  11.  *                                                                         *
  12.  ***************************************************************************/
  13.  
  14. // Modified by Kevin 2004&2016
  15.  
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <fcntl.h>
  20. #include <sys/ioctl.h>
  21. #include <sys/mman.h>
  22. #include <errno.h>
  23. #include <libv4l1-videodev.h>
  24. #include "record.h"
  25.  
  26. //#define   WIDTH 640
  27. //#define   HEIGHT 480
  28. #define     p(x) printf("%d\n",x);
  29. #define     E(x) printf("%s\n",x);
  30.  
  31. static struct   video_capability  capability;
  32. static int  fd = -1;
  33. static struct   video_mbuf gb_buffers = { 2*WIDTH*HEIGHT*3, 0, {0,WIDTH*HEIGHT*3 }};
  34. static char     *map = NULL;
  35. static struct   video_mmap my_buf;
  36.  
  37. struct video_channel vch;
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.    char my_video_dev[100]  = "/dev/video0";
  42.  
  43.    // --------------------------------------------------------------------------
  44.    // Get the v4l capture set up
  45.    // --------------------------------------------------------------------------
  46.    if (-1 == (fd = open(my_video_dev, O_RDWR))) {
  47.     printf("Error opening device: %s\n", my_video_dev);
  48.     goto err;
  49.    }
  50.    if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
  51.     printf("Error: ioctl(fd,VIDIOCGCAP,&capability)\n");
  52.     goto err;
  53.    }
  54.  
  55.    vch.channel = 0;
  56.    vch.norm = VIDEO_MODE_PAL;
  57.    if(-1 == ioctl(fd, VIDIOCSCHAN,&vch)) {
  58.          perror("Setting channel\n");
  59.          goto err;
  60.    }
  61.  
  62.  
  63.    fcntl(fd,F_SETFD,FD_CLOEXEC);
  64.    if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
  65.     printf("Error: Error getting buffers\n");
  66.     goto err;
  67.    }
  68.  
  69.    map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
  70.    if (map == NULL) {
  71.     printf("Error: Mmap returned NULL\n");
  72.     goto err;
  73.    }
  74.    // Set up out capture to use the correct resolution
  75.    my_buf.width = WIDTH;
  76.    my_buf.height = HEIGHT;
  77.    my_buf.format = VIDEO_PALETTE_RGB24;
  78.  
  79.    // Tell the capture card to fill frame 0
  80.    my_buf.frame = 0;
  81.    if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
  82.     printf("Error: Grabber chip can't sync (no station tuned in?)\n");
  83.     goto err;
  84.    }
  85.  
  86.  
  87.    unsigned long freqlist[14]= {623250,45250,55250,62250,175250,182250,189250,196250,203250,210250,217250,224250};
  88.    unsigned long freq;
  89.    int chan;
  90.    if (argc >= 1)
  91.    {
  92.     //freq = (freqlist[argv[1]]*16)/1000;
  93.     //if ( -1 == ioctl(fd, VIDIOCSFREQ, freq) );
  94.    //}else{
  95.         //freq = (freqlist[0]*16)/1000;
  96.     //if ( -1 == ioctl(fd, VIDIOCSFREQ, freq) );
  97.    }
  98.  
  99.    int done=0;
  100.    while ( done < RECORD )
  101.    {
  102.     my_buf.frame = 1;
  103.     if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
  104.         printf("Error: Grabber chip can't sync (no station tuned in?)\n");
  105.         done=1;
  106.     }
  107.  
  108.     my_buf.frame = 0;
  109.     if (-1 == ioctl(fd, VIDIOCSYNC, &my_buf.frame)) {
  110.          printf("Error on sync!\n");
  111.          done=1;
  112.     }
  113.  
  114.     record(map,"video-output");
  115.     my_buf.frame = 0;
  116.     if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf)) {
  117.         printf("Error: Grabber chip can't sync (no station tuned in?)\n");
  118.         done=1;
  119.     }
  120.  
  121.     my_buf.frame = 1;
  122.     if (-1 == ioctl(fd, VIDIOCSYNC, &my_buf.frame)) {
  123.         printf("Error on sync!\n");
  124.         done=1;
  125.     }
  126.  
  127.     record(map,"video-output");
  128.     done++;
  129.    }
  130.  
  131.    // Return screen to text mode.
  132.    err:
  133.    return EXIT_SUCCESS;
  134. }
Add Comment
Please, Sign In to add comment