cameraUVC.cc

00001 /****************************************************************************\
00002  *  CameraUVC version 0.1a                                                  *
00003  *  A Camera Plugin Driver for the Player/Stage robot server                *
00004  *                                                                          *
00005  *  Copyright (C) 2006 Raymond Sheh                                         *
00006  *  rsheh at cse dot unsw dot edu dot au     http://rsheh.cse.unsw.edu.au/  *
00007  *                                                                          *
00008  *  A Player/Stage plugin driver for cameras compatible with the Linux      *
00009  *  UVC camera driver (see http://linux-uvc.berlios.de/), such as the       *
00010  *  Logitech QuickCam Pro 5000.                                             *
00011  *                                                                          *
00012  *                                                                          *
00013  *  This program is free software; you can redistribute it and/or modify    *
00014  *  it under the terms of the GNU General Public License as published by    *
00015  *  the Free Software Foundation; either version 2 of the License, or       *
00016  *  (at your option) any later version.                                     *
00017  *                                                                          *
00018  *  This program is distributed in the hope that it will be useful,         *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
00021  *  GNU General Public License for more details.                            *
00022  *                                                                          *
00023  *  You should have received a copy of the GNU General Public License       *
00024  *  along with this program; if not, write to the Free Software             *
00025  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,                   *
00026  *  MA  02111-1307  USA                                                     *
00027  *                                                                          *
00028  *                                                                          *
00029  *  Portions based on the Player/Stage Sample Plugin Driver                 *
00030  *  Portions based on luvcview by Laurent Pinchart and Michel Xhaard        *
00031  *                                                                          *
00032  * Updated in September 2006 by Luke Gumbley to enhance stability
00033  *                                                                          *
00034  *                                                                          *
00035 \****************************************************************************/
00036 
00089 #include "cameraUVC.h"
00090 
00091 Driver* CameraUvc_Init(ConfigFile* cf, int section)
00092 {
00093         return((Driver*)(new CameraUvc(cf, section)));
00094 }
00095 
00096 void CameraUVC_Register(DriverTable* table)
00097 {
00098         table->AddDriver("camerauvc", CameraUvc_Init);
00099 }
00100 
00101 /*
00102 extern "C"
00103 {
00104         int player_driver_init(DriverTable* table)
00105         {
00106                 CameraUVC_Register(table);
00107                 return(0);
00108         } 
00109 }
00110 */
00111 
00112 CameraUvc::CameraUvc(ConfigFile* cf, int section)
00113     : Driver(cf, section, true, PLAYER_MSGQUEUE_DEFAULT_MAXLEN, PLAYER_CAMERA_CODE)
00114 {
00115         ui=new UvcInterface(cf->ReadString(section, "port", "/dev/video0"),
00116                                                 cf->ReadTupleInt( section, "size", 0, 320),
00117                                                 cf->ReadTupleInt( section, "size", 1, 240));
00118 }
00119 
00120 CameraUvc::~CameraUvc()
00121 {
00122   delete ui;
00123 }
00124 
00125 
00127 // Set up the device.  Return 0 if things go well, and -1 otherwise.
00128 // Also starts the mainloop. 
00130 int CameraUvc::Setup()
00131 {   
00132         printf("CameraUvc: Driver initialising\n");
00133 
00134         if(ui->Open()==-1)
00135         {
00136                 PLAYER_ERROR("CameraUvc: Error setting up video capture!");
00137                 SetError(-1);
00138                 return -1; 
00139         }
00140 
00141         StartThread();
00142         printf("CameraUvc: Driver initialisation done\n");
00143         
00144         return 0;
00145 }
00146 
00148 // Shutdown the device. 
00149 // Also stops the mainloop. 
00151 int CameraUvc::Shutdown()
00152 {
00153         printf("CameraUvc: Driver shutting down\n");
00154 
00155         StopThread();
00156         ui->Close();
00157 
00158         printf("CameraUvc: Driver shutdown complete\n");
00159         return 0;
00160 }
00161 
00163 // Main function (mainloop)
00165 void CameraUvc::Main() 
00166 {
00167         while (true)
00168         {
00169                 // Test if we are supposed to cancel this thread.
00170                 pthread_testcancel();
00171 
00172                 // Process any pending requests.
00173                 ProcessMessages();
00174 
00175                 ui->Read();
00176 
00177                 // Store image details
00178                 data.width=ui->GetWidth(); 
00179                 data.height=ui->GetHeight(); 
00180                 data.bpp=24; 
00181                 data.format=PLAYER_CAMERA_FORMAT_RGB888;
00182                 data.fdiv=1; 
00183                 data.compression=PLAYER_CAMERA_COMPRESS_JPEG;
00184                 data.image_count=ui->GetFrameSize();
00185                 data.image = new unsigned char[data.image_count];
00186                 ui->CopyFrame(data.image);
00187 
00188                 // Write data to the client (through the server)
00189                 Publish (device_addr,PLAYER_MSGTYPE_DATA,PLAYER_CAMERA_DATA_STATE,&data);
00190                 delete [] data.image;
00191         }
00192 }
00193 
00195 // Process requests.  Returns 1 if the configuration has changed.
00196 // Ignore all requests for now. 
00198 int CameraUvc::ProcessMessage (QueuePointer &resp_queue, player_msghdr *hdr, void *data)
00199 {
00200   return -1;
00201 }

Last updated 12 September 2005 21:38:45