src/vapiCameraSettings.c

Ir para a documentação deste ficheiro.
00001 #include <stdio.h>
00002 #include "vapiTypes.h"
00003 #include "vapiAux.h"
00004 #include "vapiCameraSettings.h"
00005 #ifndef VAPI_OS_LINUX
00006 #define VAPI_EXE "vapi.exe"
00007 #else
00008 #define VAPI_EXE "./vapi"
00009 #endif
00010 
00012 static vCameraSettings *GlobalCameraSettings;
00013 
00014 /*
00015  * Funções definidas mais abaixo e utilizadas internamente:
00016  */
00017 void vapiCameraSettingsResetCameraType (vCameraSettings * CameraSettings);
00018 
00019 void vapiCameraSettingsFreeTypeRemoteIp (vCameraSettings * CameraSettings);
00020 
00021 void
00022 vapiGlobalCameraSettingsInit()
00023 {
00024         GlobalCameraSettings = vapiCameraSettingsInit();
00025 }
00026 
00027 vCameraSettings *
00028 vapiCameraSettingsRetrieveGlobal()
00029 {
00030         return GlobalCameraSettings;
00031 }
00032 
00033 vCameraSettings *
00034 vapiCameraSettingsInit ()
00035 {
00036         vCameraSettings *CameraSettings = malloc (sizeof (vCameraSettings));
00037         CameraSettings->LocalCameraFirstCapture = vTRUE;
00038         CameraSettings->LocalCameraCapture = NULL;
00039         vapiCameraSettingsSetCalibrationConstant (CameraSettings, -1);
00040         CameraSettings->CameraType = vCameraNONE;
00041         CameraSettings->LocalCameraIndex = -2;
00042         CameraSettings->RemoteCameraIP = NULL;
00043         CameraSettings->RemoteCameraURL = NULL;
00044         CameraSettings->LocalFileName = NULL;
00045         return CameraSettings;
00046 }
00047 
00048 void
00049 vapiCameraSettingsSetNoCapture (vCameraSettings * CameraSettings)
00050 {
00051         if (!CameraSettings->LocalCameraFirstCapture)
00052         {
00053                 cvReleaseCapture (&CameraSettings->LocalCameraCapture);
00054                 CameraSettings->LocalCameraCapture = NULL;
00055         }
00056         CameraSettings->LocalCameraFirstCapture = vTRUE;
00057 }
00058 
00059 void
00060 vapiCameraSettingsSetCapture (vCameraSettings * CameraSettings,
00061                               CvCapture * Capture)
00062 {
00063         CameraSettings->LocalCameraFirstCapture = vFALSE;
00064         CameraSettings->LocalCameraCapture = Capture;
00065 }
00066 
00067 void
00068 vapiCameraSettingsSetCalibrationConstant (vCameraSettings * CameraSettings,
00069                                           double Constant)
00070 {
00071         CameraSettings->CalibrationConstant = Constant;
00072 }
00073 
00074 CvCapture *
00075 vapiCameraSettingsGetCapture (vCameraSettings * CameraSettings)
00076 {
00077         if (CameraSettings->LocalCameraFirstCapture)
00078         {
00079                 return NULL;
00080         }
00081         return CameraSettings->LocalCameraCapture;
00082 }
00083 
00084 void
00085 vapiCameraSettingsSetTypeLocal (vCameraSettings * CameraSettings,
00086                                 int LocalCameraIndex)
00087 {
00088         vapiCameraSettingsResetCameraType (CameraSettings);
00089 
00090         CameraSettings->CameraType = vCameraLocal;
00091         CameraSettings->LocalCameraIndex = LocalCameraIndex;
00092 }
00093 
00094 void
00095 vapiCameraSettingsSetTypeLocalFile (vCameraSettings * CameraSettings,
00096                                     const char *LocalFileName)
00097 {
00098         vapiCameraSettingsResetCameraType (CameraSettings);
00099         CameraSettings->LocalFileName =
00100                 vapiReturnStringPointer (LocalFileName);
00101         CameraSettings->CameraType = vCameraLocalFile;
00102 
00103         if (strlen (LocalFileName) < 4)
00104         {
00105                 CameraSettings->LocalFileName = NULL;
00106         }
00107         else
00108         {
00109                 CameraSettings->LocalFileName =
00110                         vapiReturnStringPointer (LocalFileName);
00111         }
00112 }
00113 
00114 void
00115 vapiCameraSettingsSetTypeRemoteIP (vCameraSettings * CameraSettings,
00116                                    const char *IPAddress, const char *URL)
00117 {
00118         vapiCameraSettingsResetCameraType (CameraSettings);
00119 
00120         CameraSettings->CameraType = vCameraRemoteIP;
00121         CameraSettings->RemoteCameraIP = vapiReturnStringPointer (IPAddress);
00122         CameraSettings->RemoteCameraURL = vapiReturnStringPointer (URL);
00123 }
00124 
00125 int
00126 vapiCameraSettingsGetType (vCameraSettings * CameraSettings)
00127 {
00128         return CameraSettings->CameraType;
00129 }
00130 
00131 char *
00132 vapiCameraSettingsGetLocalFilename (vCameraSettings * CameraSettings)
00133 {
00134         if (vapiCameraSettingsGetType (CameraSettings) == vCameraLocalFile
00135             && CameraSettings->LocalFileName != NULL
00136             && vapiFileIsReadable (CameraSettings->LocalFileName))
00137         {
00138                 return CameraSettings->LocalFileName;
00139         }
00140         else
00141         {
00142 
00143                 return "./pixmaps/vapiErroDeCamara.png";
00144 
00145         }
00146 }
00147 
00148 void
00149 vapiCameraSettingsResetCameraType (vCameraSettings * CameraSettings)
00150 {
00151         if (CameraSettings->CameraType == vCameraRemoteIP)
00152         {
00153                 vapiCameraSettingsFreeTypeRemoteIp (CameraSettings);
00154         }
00155         if (CameraSettings->CameraType == vCameraLocal)
00156         {
00157                 vapiCameraSettingsSetNoCapture (CameraSettings);
00158                 CameraSettings->LocalCameraIndex = -2;
00159         }
00160         if (CameraSettings->CameraType == vCameraLocalFile)
00161         {
00162                 free (CameraSettings->LocalFileName);
00163                 CameraSettings->LocalFileName = NULL;
00164         }
00165         CameraSettings->CameraType = vCameraNONE;
00166 }
00167 
00168 void
00169 vapiCameraSettingsFreeTypeRemoteIp (vCameraSettings * CameraSettings)
00170 {
00171         if (CameraSettings->RemoteCameraIP != NULL)
00172         {
00173                 free (CameraSettings->RemoteCameraIP);
00174                 CameraSettings->RemoteCameraIP = NULL;
00175         }
00176         if (CameraSettings->RemoteCameraURL != NULL)
00177         {
00178                 free (CameraSettings->RemoteCameraURL);
00179                 CameraSettings->RemoteCameraURL = NULL;
00180         }
00181 
00182 }
00183 
00184 /*
00185  * Não Actualizada.
00186  */
00187 void
00188 vCameraSettingsFree (vCameraSettings * vFree)
00189 {
00190         vapiCameraSettingsResetCameraType (vFree);
00191         free (vFree);
00192 
00193 }
00194 
00195 int
00196 vapiCameraSettingsGetLocalCameraNumber (vCameraSettings * CameraSettings)
00197 {
00198         if (vapiCameraSettingsGetType (CameraSettings) == vCameraLocal)
00199         {
00200                 return CameraSettings->LocalCameraIndex;
00201         }
00202         else
00203         {
00204                 return -2;
00205         }
00206 }
00207 
00208 int
00209 vapiCameraSettingsStartNewVapi (vCameraSettings * CameraSettings)
00210 {
00211         char *VAPI_SYSTEM_CALL;
00212 
00213         switch (CameraSettings->CameraType)
00214         {
00215         case vCameraLocal:
00216 
00217                 VAPI_SYSTEM_CALL = v_printf ("%s -lc %d &", VAPI_EXE,
00218                                              CameraSettings->
00219                                              LocalCameraIndex);
00220                 v_debug (VAPI_SYSTEM_CALL);
00221                 system (VAPI_SYSTEM_CALL);
00222                 break;
00223 
00224         case vCameraLocalFile:
00225                 VAPI_SYSTEM_CALL = v_printf ("%s -lf %s &", VAPI_EXE,
00226                                              CameraSettings->LocalFileName);
00227                 v_debug (VAPI_SYSTEM_CALL);
00228                 system (VAPI_SYSTEM_CALL);
00229                 break;
00230 
00231         default:
00232                 return 1;
00233                 break;
00234         }
00235         free (VAPI_SYSTEM_CALL);
00236         return 0;
00237 }

Gerado em Tue Jul 24 10:34:59 2007 para Vapi por  doxygen 1.5.1