Changeset 330 in flair-src for trunk/lib/FlairCore


Ignore:
Timestamp:
Sep 25, 2019, 3:29:26 PM (5 years ago)
Author:
Sanahuja Guillaume
Message:

use less bandwidth in vprnlite

Location:
trunk/lib/FlairCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/CMakeLists.txt

    r302 r330  
    99INCLUDE_DIRECTORIES(
    1010        ${LIBXML2_INCLUDE_DIR}
    11         ${CMAKE_SYSROOT}/usr/include/opencv1
    1211        ${CMAKE_SYSROOT}/usr/include/udt
    1312        ${CMAKE_CURRENT_SOURCE_DIR}/src
  • trunk/lib/FlairCore/src/ConditionVariable.cpp

    r15 r330  
    3131ConditionVariable::~ConditionVariable() { delete pimpl_; }
    3232
    33 void ConditionVariable::CondWait(void) { pimpl_->CondWait(); }
     33bool ConditionVariable::CondWait(Time timeout) { return pimpl_->CondWait(timeout); }
    3434
    3535bool ConditionVariable::CondWaitUntil(Time date) {
  • trunk/lib/FlairCore/src/ConditionVariable.h

    r15 r330  
    5555  * Upon successful return, the mutex has been locked and is owned by the
    5656  *calling thread which should unlock it (see Mutex::ReleaseMutex).
     57  *
     58  * \param timeout timeout
     59  * \return true if the condition variable is signaled before the tipeout specified
     60  *  in parameter elapses or if timeout elapses, false otherwise
    5761  */
    58   void CondWait(void);
     62  bool CondWait(Time timeout=TIME_INFINITE);
    5963
    6064  /*!
  • trunk/lib/FlairCore/src/ConditionVariable_impl.cpp

    r133 r330  
    5353}
    5454
    55 void ConditionVariable_impl::CondWait(void) {
     55bool ConditionVariable_impl::CondWait(Time timeout) {
    5656  int status;
     57  if(timeout==TIME_INFINITE) {
    5758#ifdef __XENO__
    58   status =
    59       rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
     59    status=rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE);
    6060#else
    61   status = pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
     61    status=pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);
    6262#endif
    63   if (status != 0) {
    64                 char errorMsg[256];
    65     self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    66         }
     63    if(status != 0) {
     64      char errorMsg[256];
     65      self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
     66      return false;
     67    }
     68    return true;
     69  } else {
     70    return CondWaitUntil(GetTime()+timeout);
     71  }
    6772}
    6873
     
    7277  status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date);
    7378#else
    74   struct timespec restrict;
    75   restrict.tv_sec = date / 1000000000;
    76   restrict.tv_nsec = date % 1000000000;
     79  struct timespec abstime;
     80  abstime.tv_sec = date / 1000000000;
     81  abstime.tv_nsec = date % 1000000000;
    7782  status = pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,
    78                                   &restrict);
     83                                  &abstime);
    7984#endif
    80   if (status == 0)
    81     return true;
     85  if (status == 0) return true;
    8286  if (status != ETIMEDOUT) {
    8387                char errorMsg[256];
  • trunk/lib/FlairCore/src/IODevice_impl.cpp

    r252 r330  
    225225
    226226  wake_mutex->GetMutex();
    227   if (thread_to_wake == NULL) {
    228     thread_to_wake = (Thread *)thread;
    229   } else {
    230     status = -1;
     227  if(thread==NULL) {
     228    thread_to_wake=NULL;
     229  } else {
     230    if (thread_to_wake == NULL) {
     231      thread_to_wake = (Thread *)thread;
     232    } else {
     233      status = -1;
     234    }
    231235  }
    232236  wake_mutex->ReleaseMutex();
  • trunk/lib/FlairCore/src/Picture.cpp

    r137 r330  
    2020#include "Layout.h"
    2121#include "LayoutPosition.h"
     22#include <string.h>
    2223
    2324using std::string;
     
    4546  if (image != NULL) {
    4647    image->GetMutex();
    47     memcpy(buf, image->img->imageData, image->GetDataType().GetSize());
     48    memcpy(buf, image->buffer, image->GetDataType().GetSize());
    4849    image->ReleaseMutex();
    4950  }
  • trunk/lib/FlairCore/src/Picture.h

    r15 r330  
    1515
    1616#include <SendData.h>
    17 #include <cxtypes.h>
    1817
    1918namespace flair {
  • trunk/lib/FlairCore/src/RangeFinderPlot.cpp

    r252 r330  
    2020#include "Matrix.h"
    2121#include "LayoutPosition.h"
    22 #include <cxcore.h>
    2322
    2423using std::string;
  • trunk/lib/FlairCore/src/Thread.cpp

    r313 r330  
    8282void Thread::Resume(void) { pimpl_->Resume(); }
    8383
    84 int Thread::WaitUpdate(const IODevice *device) {
    85   return pimpl_->WaitUpdate(device);
     84bool Thread::WaitUpdate(const IODevice *device,Time timeout) {
     85  return pimpl_->WaitUpdate(device,timeout);
    8686}
    8787
  • trunk/lib/FlairCore/src/Thread.h

    r213 r330  
    140140  *
    141141  * \param device IODevice to wait update from
    142   */
    143   int WaitUpdate(const IODevice *device);
     142  * \return true if device was updated, false otherwise (timeout, etc)
     143  */
     144  bool WaitUpdate(const IODevice *device,Time timeout=TIME_INFINITE);
    144145
    145146  /*!
  • trunk/lib/FlairCore/src/Thread_impl.cpp

    r307 r330  
    276276}
    277277
    278 int Thread_impl::WaitUpdate(const IODevice *device) {
    279   int status = 0;
     278bool Thread_impl::WaitUpdate(const IODevice *device,Time timeout) {
     279  bool status = true;
    280280
    281281  if (IsSuspended() == true) {
    282282    self->Err("thread is already supended\n");
    283     status = -1;
     283    status = false;
    284284  } else {
    285285    cond->GetMutex();
     
    287287    if (device->pimpl_->SetToWake(self) == 0) {
    288288      is_suspended = true;
    289       cond->CondWait();
     289      status=cond->CondWait(timeout);
     290      if(status==false) device->pimpl_->SetToWake(NULL);//condwait timedout
    290291      is_suspended = false;
    291292    } else {
    292       self->Err("%s is already waiting an update\n",
    293                 device->ObjectName().c_str());
    294       status = -1;
     293      self->Err("%s is already waiting an update\n", device->ObjectName().c_str());
     294      status = false;
    295295    }
    296296
  • trunk/lib/FlairCore/src/cvimage.cpp

    r252 r330  
    2222namespace core {
    2323
     24char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction;
     25void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction;
     26   
    2427cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height,
    2528                 Type::Format format, string name, bool allocate_data, int n)
    2629    : io_data(parent, name, n), dataType(width, height, format) {
    2730  this->allocate_data = allocate_data;
    28 
     31//Printf("cvimage %s\n",ObjectName().c_str());
    2932  if (allocate_data) {
    3033    switch (format) {
    3134    case Type::Format::YUYV:
    3235    case Type::Format::UYVY:
    33       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 2);
     36      buffer=allocFunction(width*height*2);
    3437      break;
    3538    case Type::Format::BGR:
    36       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
     39      buffer=allocFunction(width*height*3);
    3740      break;
    3841    case Type::Format::Gray:
    39       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
     42      buffer=allocFunction(width*height*1);
    4043      break;
    4144    default:
    42       Err("format no supported");
     45      Err("format not supported");
    4346      break;
    4447    }
     
    4750      Err("number of samples!=1 not possible when not allocating data\n");
    4851    n = 1;
    49     switch (format) {
    50     case Type::Format::YUYV:
    51     case Type::Format::UYVY:
    52       img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 2);
    53       break;
    54     case Type::Format::BGR:
    55       img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
    56       break;
    57     case Type::Format::Gray:
    58       img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);
    59       break;
    60     default:
    61       Err("format no supported");
    62       break;
    63     }
    6452  }
    6553
    66   SetPtrToCircle((void **)&img);
     54  SetPtrToCircle((void **)&buffer);
    6755
    6856  if (n > 1)
     
    7260cvimage::~cvimage() {
    7361  // printf("destructeur cvimage\n");
    74 
    75   cvReleaseImage(&img);
     62  if(allocate_data) freeFunction(buffer);
    7663}
    7764
    7865void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); }
    7966
     67void cvimage::RegisterAllocFunction(char*(*func)(ssize_t size)) {
     68  if(allocFunction==DefaultAllocFunction) allocFunction=func;
     69}
     70
     71void cvimage::RegisterFreeFunction(void(*func)(char* buffer)) {
     72  if(freeFunction==DefaultFreeFunction) freeFunction=func;
     73}
     74
     75char* cvimage::DefaultAllocFunction(ssize_t size){
     76  Printf("default alloc %i\n",size);
     77  return (char*)malloc(size);
     78}
     79
     80void cvimage::DefaultFreeFunction(char* buffer){
     81  Printf("default free\n");
     82  free(buffer);
     83}
     84
    8085} // end namespace core
    8186} // end namespace flair
  • trunk/lib/FlairCore/src/cvimage.h

    r252 r330  
    1414#define CVIMAGE_H
    1515
    16 #include <cxcore.h>
    1716#include <io_data.h>
    1817#include <stdint.h>
     18
     19
     20namespace flair {
     21namespace sensor {
     22class V4LCamera;
     23}
     24}
     25
    1926
    2027namespace flair {
     
    2835*/
    2936class cvimage : public io_data {
    30 public:
     37    public:
     38  friend class flair::sensor::V4LCamera;
    3139  class Type : public DataType {
    3240  public:
     
    97105  ~cvimage();
    98106
    99   /*!
    100   * \brief IplImage
    101   *
    102   * \return IplImage
    103   */
    104   IplImage *img;
     107 
     108  char *buffer;
    105109
    106110  Type const &GetDataType() const { return dataType; };
     111 
     112  static void RegisterAllocFunction(char*(*func)(ssize_t size));
     113  static void RegisterFreeFunction(void(*func)(char* buffer));
    107114
    108115private:
     
    119126  bool allocate_data;
    120127  Type dataType;
     128  static char* (*allocFunction)(ssize_t);
     129  static void (*freeFunction)(char*);
     130  static char* DefaultAllocFunction(ssize_t size);
     131  static void DefaultFreeFunction(char* buffer);
     132 
    121133};
    122134
  • trunk/lib/FlairCore/src/unexported/ConditionVariable_impl.h

    r15 r330  
    3737  ConditionVariable_impl(flair::core::ConditionVariable *self);
    3838  ~ConditionVariable_impl();
    39   void CondWait(void);
     39  bool CondWait(flair::core::Time timeout);
    4040  bool CondWaitUntil(flair::core::Time date);
    4141  void CondSignal(void);
  • trunk/lib/FlairCore/src/unexported/Thread_impl.h

    r213 r330  
    4747  void Resume(void);
    4848  bool IsSuspended(void);
    49   int WaitUpdate(const flair::core::IODevice *device);
     49  bool WaitUpdate(const flair::core::IODevice *device,flair::core::Time timeout);
    5050  bool period_set;
    5151   bool isRunning;
Note: See TracChangeset for help on using the changeset viewer.