Revision: 8941
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8941&view=rev
Author:   jpgr87
Date:     2010-10-13 00:46:29 +0000 (Wed, 13 Oct 2010)

Log Message:
-----------
Updated unicapimage to Player 3.0 ThreadedDriver model.  Changed unicapimage 
CMakeLists.txt to look for libunicap.pc.  Fixed bogus assertion that was 
causing PlayerCam to crash.

Modified Paths:
--------------
    code/player/trunk/server/drivers/camera/unicap/CMakeLists.txt
    code/player/trunk/server/drivers/camera/unicap/unicapImage.cc
    code/player/trunk/utils/playercam/playercam.c

Modified: code/player/trunk/server/drivers/camera/unicap/CMakeLists.txt
===================================================================
--- code/player/trunk/server/drivers/camera/unicap/CMakeLists.txt       
2010-10-12 00:46:54 UTC (rev 8940)
+++ code/player/trunk/server/drivers/camera/unicap/CMakeLists.txt       
2010-10-13 00:46:29 UTC (rev 8941)
@@ -1,20 +1,13 @@
 PLAYERDRIVER_OPTION (unicapimage build_unicapimage ON)
 
-SET (UNICAP_DIR "" CACHE STRING "Directory containing the UniCap headers and 
libraries")
-MARK_AS_ADVANCED (UNICAP_DIR)
-IF ("${UNICAP_DIR}" STREQUAL "")
-    SET (unicapReqHeader "unicap.h")
-    SET (unicapExtraFlags "")
-    SET (unicapExtraLibs "-lunicap -lrt")
-ELSE ("${UNICAP_DIR}" STREQUAL "")
-    SET (unicapReqHeader "${UNICAP_DIR}/include/unicap/unicap.h")
-    SET (unicapExtraFlags "-I${UNICAP_DIR}/include/unicap")
-    SET (unicapExtraLibs "-L${UNICAP_DIR}/lib -lcanlib -lrt")
-ENDIF ("${UNICAP_DIR}" STREQUAL "")
+PLAYERDRIVER_REQUIRE_PKG (unicapimage build_unicapimage libunicap 
unicap_includeDirs
+    unicap_libDirs unicap_linkLibs unicap_linkFlags unicap_cFlags)
 
-PLAYERDRIVER_REQUIRE_HEADER (unicapimage build_unicapimage ${unicapReqHeader})
 
 PLAYERDRIVER_ADD_DRIVER (unicapimage build_unicapimage
-                         LINKFLAGS -L{UNICAP_DIR}/lib -lunicap -lrt
-                         CFLAGS -I${UNICAP_DIR}/include 
-I${UNICAP_DIR}/include/unicap
+                         INCLUDEDIRS ${unicap_includeDirs} 
+                         LIBDIRS ${unicap_libDirs} 
+                         LINKLIBS ${unicap_linkLibs}
+                         LINKFLAGS ${unicap_linkFlags} 
+                         CFLAGS ${unicap_cFlags}
                          SOURCES unicapImage.cc)

Modified: code/player/trunk/server/drivers/camera/unicap/unicapImage.cc
===================================================================
--- code/player/trunk/server/drivers/camera/unicap/unicapImage.cc       
2010-10-12 00:46:54 UTC (rev 8940)
+++ code/player/trunk/server/drivers/camera/unicap/unicapImage.cc       
2010-10-13 00:46:29 UTC (rev 8941)
@@ -92,7 +92,7 @@
 
 
////////////////////////////////////////////////////////////////////////////////
 // The UniCap_Image device class.
-class UniCap_Image : public Driver
+class UniCap_Image : public ThreadedDriver
 {
   public:
     // Constructor
@@ -102,17 +102,21 @@
     ~UniCap_Image ();
 
     // Implementations of virtual functions
-    virtual int Setup ();
-    virtual int Shutdown ();
+    virtual int MainSetup ();
+    virtual void MainQuit ();
+    virtual int ProcessMessage(QueuePointer & resp_queue,
+                                     player_msghdr * hdr,
+                                     void * data);
 
     // Camera interface (provides)
     player_devaddr_t         cam_id;
     player_camera_data_t     cam_data;
+
   private:
 
     // Main function for device thread.
     virtual void Main ();
-    virtual void RefreshData  ();
+    void PublishCamera  ();
 
     int color_space, video_format, device_id;
     
@@ -145,7 +149,7 @@
 // Constructor.  Retrieve options from the configuration file and do any
 // pre-Setup() setup.
 UniCap_Image::UniCap_Image (ConfigFile* cf, int section)
-    : Driver (cf, section)
+    : ThreadedDriver (cf, section)
 {
   memset (&this->cam_id, 0, sizeof (player_devaddr_t));
 
@@ -189,7 +193,7 @@
 
 
////////////////////////////////////////////////////////////////////////////////
 // Set up the device.  Return 0 if things go well, and -1 otherwise.
-int UniCap_Image::Setup ()
+int UniCap_Image::MainSetup ()
 {
   PLAYER_MSG0 (1, "> UniCap_Image starting up... [done]");
 
@@ -226,6 +230,9 @@
    }
    PLAYER_MSG3 (2, "Selected video format %d: [%dx%d]", this->video_format, 
format.size.width, format.size.height);
 
+   // Set Unicap to use a user buffer
+   format.buffer_type = UNICAP_BUFFER_TYPE_USER;
+
    if (!SUCCESS (unicap_set_format (handle, &format) ) )
    {
      PLAYER_ERROR1 ("Failed to set video format to %d!", this->video_format);
@@ -246,20 +253,14 @@
   // Allocate buffer data
   buffer.data = (unsigned char*)(malloc (format.size.width * 
format.size.height * format.bpp / 8));
   buffer.buffer_size = format.size.width * format.size.height * format.bpp / 8;
-  
-  // Start the device thread
-  StartThread ();
 
   return (0);
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 // Shutdown the device
-int UniCap_Image::Shutdown ()
+void UniCap_Image::MainQuit ()
 {
-  // Stop the driver thread
-  StopThread ();
-
   // Stop the device
   if ( !SUCCESS (unicap_stop_capture (handle) ) )
     PLAYER_ERROR1 ("Failed to stop capture on device: %s\n", 
device.identifier);
@@ -270,29 +271,33 @@
 
   free (buffer.data);
   PLAYER_MSG0 (1, "> UniCap_Image driver shutting down... [done]");
-  return (0);
+  return;
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 // Main function for device thread
 void UniCap_Image::Main ()
 {
-  timespec sleepTime = {0, 1000};
 
   // The main loop; interact with the device here
   while (true)
   {
-      nanosleep (&sleepTime, NULL);
-
       // test if we are supposed to cancel
       pthread_testcancel ();
 
       // Refresh data
-      this->RefreshData ();
+      this->PublishCamera ();
+
+      // Sleep the thread
+      usleep(1000);
+
+      printf("Loop\n");
   }
 }
 
-void UniCap_Image::RefreshData ()
+/////////////////////////////////////////////////////////////////////////////////
+// Grab and publish a frame
+void UniCap_Image::PublishCamera ()
 {
   // Queue the buffer
   // The buffer now gets filled with image data by the capture device
@@ -305,14 +310,26 @@
 
   cam_data.width  = buffer.format.size.width;
   cam_data.height = buffer.format.size.height;
+  cam_data.compression = PLAYER_CAMERA_COMPRESS_RAW;
+  cam_data.fdiv = 1;
+  cam_data.bpp = format.bpp;
   
   // To do: implement the code for different formats later
-  cam_data.format = PLAYER_CAMERA_FORMAT_MONO8;
+  cam_data.format = PLAYER_CAMERA_FORMAT_RGB888;
   cam_data.image_count = buffer.buffer_size;
   cam_data.image = new unsigned char [cam_data.image_count];
-  for (int i = 0; i < cam_data.image_count; i++)
+  for (unsigned int i = 0; i < cam_data.image_count; i++)
     cam_data.image[i] = buffer.data[i];
   
   Publish (this->cam_id, PLAYER_MSGTYPE_DATA, PLAYER_CAMERA_DATA_STATE, 
&cam_data);
   delete [] cam_data.image;
 }
+
+///////////////////////////////////////////////////////////////////////////////////
+// Message handling
+int UniCap_Image::ProcessMessage(QueuePointer & resp_queue, player_msghdr * 
hdr,
+                                     void * data)
+{
+  // No messages to process
+  return -1;
+}

Modified: code/player/trunk/utils/playercam/playercam.c
===================================================================
--- code/player/trunk/utils/playercam/playercam.c       2010-10-12 00:46:54 UTC 
(rev 8940)
+++ code/player/trunk/utils/playercam/playercam.c       2010-10-13 00:46:29 UTC 
(rev 8941)
@@ -467,7 +467,7 @@
     {
       // Decompress the image if necessary
       playerc_camera_decompress(g_camera);
-      assert(allocated_size > g_camera->image_count*3);
+      assert(allocated_size >= g_camera->image_count);
       // figure out the colorspace
       switch (g_camera->format)
       {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to