1. --- uvccapture-0.5/uvccapture.c 2011-04-22 18:19:57.000000000 +1000
  2. +++ uvccapture-0.6/uvccapture.c 2011-09-23 21:13:09.000000000 +1000
  3. @@ -58,6 +58,8 @@
  4.    fprintf (stderr, "-o<filename>\tOutput filename(default: snap.jpg)\n");
  5.    fprintf (stderr, "-d<device>\tV4L2 Device(default: /dev/video0)\n");
  6.    fprintf (stderr,
  7. +      "-b\t\tRun in the background\n");
  8. +  fprintf (stderr,
  9.        "-x<width>\tImage Width(must be supported by device)\n");
  10.    fprintf (stderr,
  11.        "-y<height>\tImage Height(must be supported by device)\n");
  12. @@ -299,6 +301,7 @@
  13.    unsigned char* imageWithDHT = NULL;
  14.    int imageWithDHTSize = 0;
  15.    int preDelay = 0;
  16. +  boolean backGround = FALSE;
  17.  
  18.    (void) signal (SIGINT, sigcatch);
  19.    (void) signal (SIGQUIT, sigcatch);
  20. @@ -325,6 +328,10 @@
  21.        snprintf(outputfile, MAXFILENAMELENGTH, "%s", &argv[1][2]);
  22.        break;
  23.  
  24. +    case 'b':
  25. +      backGround = TRUE;
  26. +      break;
  27. +
  28.      case 'd':
  29.        videodevice = &argv[1][2];
  30.        break;
  31. @@ -410,6 +417,10 @@
  32.      if (post_capture_command[0])
  33.        fprintf (stderr, "Executing '%s' after each image capture\n",
  34.            post_capture_command[0]);
  35. +    if (backGround)
  36. +      fprintf (stderr, "Will switch to run in the background\n");
  37. +    else
  38. +      fprintf (stderr, "Will not switch to run in the background\n");
  39.    }
  40.    videoIn = (struct vdIn *) calloc (1, sizeof (struct vdIn));
  41.    if (init_videoIn
  42. @@ -456,17 +467,43 @@
  43.    } else if (verbose >= 1) {
  44.      fprintf (stderr, "Camera gain level is %d\n",
  45.          v4l2GetControl (videoIn, V4L2_CID_GAIN));
  46.    }*/
  47.    ref_time = time (NULL);
  48.  
  49. -  while (run) {
  50. -    if( preDelay ) {
  51. -      // allowing camera to adjust exposure
  52. -      uvcGrab(videoIn);
  53. -      videoIn->getPict = 0;
  54. -      if (verbose >= 0)
  55. +  if(backGround)
  56. +  {
  57. +    if(verbose > 0)
  58. +      fprintf (stderr, "starting the daemonising process\n");
  59. +
  60. +    verbose = 0;
  61. +    pid_t pid = fork();
  62. +    if(pid < 0)
  63. +    {
  64. +      fprintf (stderr, "Unable to daemonise the process\n");
  65. +      exit(EXIT_FAILURE);
  66. +    }
  67. +    if (pid > 0)
  68. +      exit(EXIT_SUCCESS);
  69. +
  70. +    close(STDIN_FILENO);
  71. +    close(STDOUT_FILENO);
  72. +    close(STDERR_FILENO);
  73. +  }
  74. +
  75. +  while(run)
  76. +  {
  77. +    if(preDelay)
  78. +    {
  79. +      if(verbose > 0)
  80.          fprintf (stderr, "Pre-delay: %d, sleeping...\n", preDelay);
  81. -      sleep(preDelay);
  82. +
  83. +      for(int i = 0; i < preDelay; i++)
  84. +      {
  85. +        // allowing camera to adjust exposure
  86. +        uvcGrab(videoIn);
  87. +        videoIn->getPict = 0;
  88. +        sleep(1);
  89. +      }
  90.      }
  91.  
  92.      if (verbose >= 2)