/*------------------------------------------------------------------------
 *
 *  File:	o1k_video.h
 *  Revision:	1.15
 *  Last Mod:	12:05:49, 05/21/97
 *
 *  Description:
 *     Defines O1kVideo object.
 *     
 *----------------------------------------------------------------------*/
#pragma ident	"@(#)o1k_video.h	1.15\t97/05/21  "
#ifndef _O1K_VIDEO_H
#define _O1K_VIDEO_H

#include "o1k_thread.h"

typedef enum _VideoType { H261,  CELLB, JPEG, VID_NONE }  VideoType;
typedef enum _VideoPort { SVIDEO, COMP1  } VideoPort;
typedef enum _VideoSize { SIZE_CIF, SIZE_QCIF, SIZE_NONE }   VideoSize;
typedef enum _VideoOutput { VID_WINDOW, VID_OUT  } VideoOutput;

typedef enum _VideoStatus { VS_BITRATE_T,   VS_BITRATE_R,
                            VS_FRAMERATE_T, VS_FRAMERATE_R }   VideoStatus;

extern char* VideoTypeStr[];
extern char* VideoPortStr[];
extern char* VideoSizeStr[];

typedef struct _VideoParamsH261 {
  unsigned int  framerate;
  unsigned int  bitrate;
  unsigned int  maxquant;
  unsigned int  refreshperiod;
  unsigned char pip_on;
  VideoSize     size;    
} VideoParamsH261;

typedef struct _VideoParamsCellB {
  unsigned int  framerate;
  VideoSize     size;    
} VideoParamsCellB;

typedef struct _VideoParamsJpeg {
  unsigned int  framerate;
  unsigned int  quality;
  VideoSize     size;    
} VideoParamsJpeg;

/*------------------------------------------------------------------------
 *
 *  Class:  O1kVideo	
 *
 * Description:
 *     
 *     The O1kVideo object contains the state for the video portion
 *     of the conference. This includes video format, ports, brightness,
 *     etc. It also contains two O1kThread thread objects which are
 *     used for video transmit and receive.    
 *     
 *     !!! The current version of XIL (1.2) is not MT-safe. XIL 1.3
 *     to be introduced in Solaris 2.6 promises to be MT-safe (as 
 *     well as MT-hot). In the interim, one must be very careful
 *     about making XIL calls via multiple threads. A mutex is used
 *     in this object to help with this problem. 
 *     
 *----------------------------------------------------------------------*/

class O1kVideo {
  
private:
  VideoType         type;
  VideoParamsH261   h261;
  VideoParamsCellB  cellb;  
  VideoParamsJpeg   jpeg;  
  VideoPort         port;
  VideoOutput       output;
  
  int brightness;
  int contrast;
  int hue;
  int gainu;
  int gainv;

  Boolean view_local;
  Boolean view_far;  

  mutex_t xil_mutex;
  
public:

  int bitrate_t;
  int bitrate_r;  
  int framerate_t;
  int framerate_r;
  
  /* video codec threads */
  O1kThread* thread_t;
  O1kThread* thread_r;
  
private:
  createXilLock();
  
public:
  
  O1kVideo();
  ~O1kVideo();
  
  void settings();

  void setFormat(VideoType t);
  void setCellbSize(VideoSize s)    { cellb.size = s; }
  void setCellbFrameRate(int r)     { cellb.framerate = r; }
  void setJpegSize(VideoSize s)     { jpeg.size = s; }
  void setJpegFrameRate(int r)      { jpeg.framerate = r; }
  void setJpegQuality(int q)        { jpeg.quality = q; }
  void setH261Size(VideoSize s)     { h261.size = s; }
  void setH261FrameRate(int r)      { h261.framerate = r; }
  void setH261BitRate(int r)        { h261.bitrate = r; }
  void setH261Pip(int p)            { h261.pip_on = p; }
  void setH261MaxQuant(int mq)      { h261.maxquant = mq; }
  void setH261RefreshPeriod(int rp) { h261.refreshperiod = rp; }
  void setInputPort(VideoPort p)    { port = p; }
  void setOutput(VideoOutput o)     { output = o; }  
  void setBrightness(int v)         { brightness = v; }  
  void setContrast(int v)           { contrast = v; }  
  void setHue(int v)                { hue = v; }  
  void setGainU(int v)              { gainu = v; }  
  void setGainV(int v)              { gainv = v; }  
  void setViewLocal(Boolean flag)   { view_local = flag; }
  void setViewFar(Boolean flag)     { view_far = flag; }

  VideoType getFormat()            const { return type; }
  VideoSize getCellbSize()         const { return cellb.size; }
  int       getCellbFrameRate()    const { return cellb.framerate; }
  VideoSize getJpegSize()          const { return jpeg.size; }
  int       getJpegFrameRate()     const { return jpeg.framerate; }
  int       getJpegQuality()       const { return jpeg.quality; }
  VideoSize getH261Size()          const { return h261.size; }
  int       getH261FrameRate()     const { return h261.framerate; }
  int       getH261BitRate()       const { return h261.bitrate; }
  int       getH261Pip()           const { return h261.pip_on; }
  int       getH261MaxQuant()      const { return h261.maxquant; }
  int       getH261RefreshPeriod() const { return h261.refreshperiod; }
  VideoPort getInputPort()         const { return port; }
  VideoOutput getOutput()          const { return output; }    
  int       getBrightness()        const { return brightness; }  
  int       getContrast()          const { return contrast; }  
  int       getHue()               const { return hue; }  
  int       getGainU()             const { return gainu; }  
  int       getGainV()             const { return gainv; }  
  Boolean   getViewLocal()         const { return view_local; }
  Boolean   getViewFar()           const { return view_far; }

  int       getFrameRate();
  VideoSize getSize();
  
  int start();
  int stop();

  int lockXil();
  int releaseXil();  

  char* getStatus(VideoStatus vs);
  
};

#endif
