/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2007
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    Midnight Code is a registered trademark of Ian Latter.

    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, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    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.
  
    You should have received a copy of the GNU General Public License
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/


/* midnightcode-camera.h :: Midnight Code UVC camera library		*/

#include <linux/videodev2.h>

#ifndef __MIDNIGHTCODE_CAMERA_H
#define __MIDNIGHTCODE_CAMERA_H 1


#define MIDNIGHTCODE_CAMERA_BUFFERS 4

enum midnightcode_camera_cid_t
{
  MIDNIGHTCODE_CAMERA_CID_BACKLIGHT_COMPENSATION = V4L2_CID_PRIVATE_BASE,
  MIDNIGHTCODE_CAMERA_CID_POWER_LINE_FREQUENCY,
  MIDNIGHTCODE_CAMERA_CID_SHARPNESS,
  MIDNIGHTCODE_CAMERA_CID_HUE_AUTO,
  MIDNIGHTCODE_CAMERA_CID_FOCUS_AUTO,
  MIDNIGHTCODE_CAMERA_CID_FOCUS_ABSOLUTE,
  MIDNIGHTCODE_CAMERA_CID_FOCUS_RELATIVE,
  MIDNIGHTCODE_CAMERA_CID_PAN_RELATIVE,
  MIDNIGHTCODE_CAMERA_CID_TILT_RELATIVE,
  MIDNIGHTCODE_CAMERA_CID_PANTILT_RESET,
  MIDNIGHTCODE_CAMERA_CID_EXPOSURE_AUTO,
  MIDNIGHTCODE_CAMERA_CID_EXPOSURE_ABSOLUTE,
  MIDNIGHTCODE_CAMERA_CID_WHITE_BALANCE_TEMPERATURE_AUTO,
  MIDNIGHTCODE_CAMERA_CID_WHITE_BALANCE_TEMPERATURE
};

enum midnightcode_camera_transcode_t
{
  MIDNIGHTCODE_CAMERA_TRANSCODE_JPEG = 1,
  MIDNIGHTCODE_CAMERA_TRANSCODE_AVI
};

struct midnightcode_camera_element_t
{
  int fd;
  int enabled;
  int active;					// isstreaming
  char device[64];				// videodevice
  char status[128];				// status / 100
  char label[128];				// pictName / 80
  int width;
  int height;
  int fps;
  int method;					// grabmethod
  int format;					// formatIn
  int type;
  int framesize;				// framesizeIn
  struct v4l2_capability v4l_capability;	// cap
  struct v4l2_format v4l_format;		// fmt
  struct v4l2_streamparm v4l_parameters;
  struct v4l2_buffer v4l_buffer;		// buf
  struct v4l2_requestbuffers v4l_requestbuf;	// rb
  void * buffer[MIDNIGHTCODE_CAMERA_BUFFERS];	// mem[NB_BUFFERS]
  unsigned char * tmp_buffer;			// tmpbuffer
  unsigned char * frame_buffer;			// framebuffer
  int image_serial;

  int formatOut;
  int signalquit;
  int getpic;					// getPict;
  int rawFrameCapture;
  unsigned int fileCounter;
  unsigned int rfsFramesWritten;
  unsigned int rfsBytesWritten;
  unsigned int framesWritten;
  unsigned int bytesWritten;
  int framecount;
  int recordstart;
  int recordtime;
  midnightcode_list_entry(midnightcode_camera_element_t)
};

struct midnightcode_camera_device_t
{
  const char * device;
};

midnightcode_list_head(midnightcode_camera_head_t,
                     midnightcode_camera_element_t)


int midnightcode_camera_open(struct midnightcode_camera_element_t * camera,
                     int width, int height, int fps, int format, int method);
int midnightcode_camera_close(struct midnightcode_camera_element_t * camera);
int midnightcode_camera_read(struct midnightcode_camera_element_t * camera,
                     char ** buffer, int * buffer_size);
int midnightcode_camera_activate(
                     struct midnightcode_camera_element_t * camera);
int midnightcode_camera_deactivate(
                     struct midnightcode_camera_element_t * camera);
int midnightcode_camera_format(struct midnightcode_camera_element_t * camera);
int midnightcode_camera_fps(struct midnightcode_camera_element_t * camera);
int midnightcode_camera_buffers(struct midnightcode_camera_element_t * camera);
int midnightcode_camera_verifycontrol(
                     struct midnightcode_camera_element_t * camera,
                     int control, struct v4l2_queryctrl * v4l_queryctrl);
int midnightcode_camera_action_backlightcompensation(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_action_powerlinefrequency(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_action_sharpness(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_action_panrelative(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_action_tiltrelative(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_action_resetpantilt(
                     struct midnightcode_camera_element_t * camera,
                     int value);
int midnightcode_camera_transcode(
                     struct midnightcode_camera_element_t * camera,
                     int transcode, char * input_buffer, int input_size,
                     char ** output_buffer, int * output_size);
int midnightcode_camera_probe(struct midnightcode_camera_element_t * camera);
int midnightcode_camera_list(struct midnightcode_camera_head_t *elements);


#endif
