/*
  1394.cc
  By Wayne Piekarski - wayne@cs.unisa.edu.au
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  See the file LICENSE included in this directory for more information.
*/


/* Rather than writing a direct 1394 driver myself, I instead use the ARToolKit capture libraries
   to do this for me. Writing 1394 code turned out to be quite complex, and this works pretty well
   so its easier just to use ARToolKit */


/* Make sure ARToolkit is in the -I path */
#include <AR/video.h>
#include <AR/config.h>
#include <AR/ar.h>

#include "1394.h"

/* Include internal ARtk structures */
AR2VideoParamT *artk_params;

/* Configuration variables */
int ar_width, ar_height;




int open_1394 (char *nothing, int *out_width, int *out_height)
{
  /* Get ARtoolkit to open up the device */
  artk_params = ar2VideoOpen ("");
  if (artk_params == NULL)
    {
      fprintf (stderr, "Could not open up a camera device with ar2VideoOpen\n");
      return (-1);
    }
  
  /* Store in width and height info */
  ar2VideoInqSize (artk_params, &ar_width, &ar_height);
  *out_width = ar_width;
  *out_height = ar_height;
  
  /* Success */
  return (0);
}




void start_1394 (void)
{
  /* Get ARtoolkit to start the capture */
  ar2VideoCapStart (artk_params);  
}




void capture_1394 (void)
{
  /* Use ARtoolkit to get the next frame started */
  ar2VideoCapNext (artk_params);
}




char *get_1394 (void)
{
  /* Return back a pointer to the current memory buffer */
  return ((char *)ar2VideoGetImage (artk_params));
}
