Changeset 87:06119944f38f in finroc_plugins_data_ports


Ignore:
Timestamp:
02.02.2015 01:11:32 (4 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Extensions for data_compression plugin. Standard data type buffers can now have a compressed version of their data attached.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • api/tPortDataPointerImplementation.h

    r69 r87  
    115115    std::swap(buffer_manager, other.buffer_manager); 
    116116    return *this; 
     117  } 
     118 
     119  void AttachCompressedData(const char* compression_format, void* data, size_t size, bool key_frame) 
     120  { 
     121    buffer_manager->AttachCompressedData(compression_format, data, size, key_frame); 
    117122  } 
    118123 
     
    387392  } 
    388393 
     394  void AttachCompressedData(const char* compression_format, void* data, size_t size, bool key_frame) 
     395  { 
     396    if (IsCheaplyCopiedType(object->GetType())) 
     397    { 
     398      FINROC_LOG_PRINT(WARNING, "Cannot attach compressed data to cheaply copied type"); 
     399    } 
     400    else 
     401    { 
     402      static_cast<standard::tPortBufferManager*>(buffer_manager)->AttachCompressedData(compression_format, data, size, key_frame); 
     403    } 
     404  } 
     405 
    389406  void Deserialize(rrlib::serialization::tInputStream& stream) 
    390407  { 
     
    414431  } 
    415432 
     433  common::tReferenceCountingBufferManager* GetBufferManager() const 
     434  { 
     435    return buffer_manager; 
     436  } 
     437 
     438 
    416439  inline rrlib::time::tTimestamp GetTimestamp() const 
    417440  { 
     
    452475private: 
    453476 
    454   /*! Locked buffer - if standard type */ 
     477  /*! Locked buffer */ 
    455478  common::tReferenceCountingBufferManager* buffer_manager; 
    456479 
  • standard/tPortBufferManager.cpp

    r46 r87  
    7272  unused(true), 
    7373  derived_from(NULL) 
     74#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     75  , compression_status(0), 
     76  compressed_data() 
     77#endif 
    7478{} 
    7579 
  • standard/tPortBufferManager.h

    r59 r87  
    5757namespace finroc 
    5858{ 
     59 
     60//---------------------------------------------------------------------- 
     61// Forward declarations / typedefs / enums 
     62//---------------------------------------------------------------------- 
     63namespace data_compression 
     64{ 
     65class tPlugin; 
     66} 
     67 
    5968namespace data_ports 
    6069{ 
    6170namespace standard 
    6271{ 
    63  
    64 //---------------------------------------------------------------------- 
    65 // Forward declarations / typedefs / enums 
    66 //---------------------------------------------------------------------- 
    67  
    6872//---------------------------------------------------------------------- 
    6973// Class declaration 
     
    9195 
    9296  /*! 
     97   * Attach compressed data to buffer. 
     98   * Components that have their data also available in compressed form, can attach this to their published data. 
     99   * E.g. a frame grabber might receive images in MJPG from a camera driver. 
     100   * Later, compression might be required for network connections or recording. 
     101   * Instead of recompressing the data, the original can be used. 
     102   * Must be called, before buffer is pusblished. 
     103   * 
     104   * Note: if Finroc data_compression plugin is not available, the data is discarded. 
     105   * 
     106   * (only available for data types that are not cheaply copied (they are small anyway) and not for buffers that contain const data) 
     107   * 
     108   * \param compression_format Format in which data was compressed (e.g. "jpg" - should be the same strings as used with rrlib_data_compression to allow decompression) 
     109   *                           Note that string is not copied and must remain valid as long as data 
     110   * \param data Pointer to compressed data (data is copied) 
     111   * \param size Size of compressed data 
     112   * \param key_frame Is this a key frame? (meaning that data be uncompressed without knowledge of any former data (frames)) 
     113   */ 
     114  void AttachCompressedData(const char* compression_format, void* data, size_t size, bool key_frame) 
     115  { 
     116    if (!unused) 
     117    { 
     118      FINROC_LOG_PRINT(WARNING, "Buffer has already been published. No data is attached."); 
     119      return; 
     120    } 
     121#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     122    if (!compressed_data) 
     123    { 
     124      compressed_data.reset(new std::tuple<rrlib::serialization::tMemoryBuffer, const char*, bool>()); 
     125    } 
     126    rrlib::serialization::tOutputStream stream(std::get<0>(*compressed_data)); 
     127    stream.Write(data, size); 
     128    std::get<1>(*compressed_data) = compression_format; 
     129    std::get<2>(*compressed_data) = key_frame; 
     130    this->compression_status = 3;  // Enum value for "data available" (see data_compression::tPlugin) 
     131#endif 
     132  } 
     133 
     134  /*! 
    93135   * Creates instance of tPortBufferManager containing a buffer 
    94136   * of the specified type 
     
    121163  { 
    122164    this->unused = unused; 
     165#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     166    this->compression_status = 0; 
     167#endif 
    123168  } 
    124169 
     
    134179  tPortBufferManager* derived_from; 
    135180 
     181#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     182 
     183  friend class data_compression::tPlugin; 
     184 
     185  /*! Compression status */ 
     186  std::atomic<uint8_t> compression_status; 
     187 
     188  /*! Info on compressed data (compressed data, compression format, key frame?) */ 
     189  std::unique_ptr<std::tuple<rrlib::serialization::tMemoryBuffer, const char*, bool>> compressed_data; 
     190 
     191#endif 
    136192 
    137193  tPortBufferManager(); 
  • standard/tStandardPort.cpp

    r80 r87  
    112112  current_value(0), 
    113113  standard_assign(!GetFlag(tFlag::NON_STANDARD_ASSIGN) && (!GetFlag(tFlag::HAS_QUEUE))), 
     114#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     115  compression_active_status(-2), 
     116  data_compressor_mutex("tStandardPort data compressor"), 
     117#endif 
    114118  input_queue(), 
    115119  pull_request_handler(NULL) 
  • standard/tStandardPort.h

    r80 r87  
    434434  const bool standard_assign; 
    435435 
     436#ifdef _LIB_FINROC_PLUGINS_DATA_COMPRESSION_PRESENT_ 
     437 
     438  friend class data_compression::tPlugin; 
     439 
     440  /*! Is compression enabled for this port? [31 bytes rule revision when this was checked, 1 byte enabled?] */ 
     441  std::atomic<uint32_t> compression_active_status; 
     442 
     443  /*! Mutex for data compressors attached to this port */ 
     444  rrlib::thread::tOrderedMutex data_compressor_mutex; 
     445 
     446#endif 
     447 
    436448  /*! Queue for ports with incoming value queue */ 
    437449  std::unique_ptr<common::tPortQueue<tLockingManagerPointer>> input_queue; 
  • tEvent.h

    r46 r87  
    3030 * \b tEvent 
    3131 * 
    32  * Simple data type that signals that an event has occured. 
     32 * Simple data type that signals that an event has occurred. 
    3333 * Event data types clearly indicate that ports are not used for transferring a 
    3434 * continuous flow of data, but only occasional events. 
     
    6767//! Event data type 
    6868/*! 
    69  * Simple data type that signals that an event has occured. 
     69 * Simple data type that signals that an event has occurred. 
    7070 * Event data types clearly indicate that ports are not used for transferring a 
    7171 * continuous flow of data, but only occasional events. 
  • tPortDataPointer.h

    r69 r87  
    8181  typedef typename std::remove_const<T>::type tPortData; 
    8282 
     83  enum { cCONST_DATA = !std::is_same<tPortData, T>::value }; 
     84 
    8385  /*! Port-related functionality for type T */ 
    8486  typedef api::tPortImplementation<tPortData, api::tPortImplementationTypeTrait<tPortData>::type> tPortImplementation; 
     
    119121 
    120122  // Move constructor for non-const pointers 
    121   template < bool ENABLE = !std::is_same<tPortData, T>::value > 
     123  template <bool ENABLE = cCONST_DATA> 
    122124  inline tPortDataPointer(typename std::enable_if<ENABLE, tPortDataPointer<tPortData>>::type && non_const_pointer) : 
    123125    implementation(std::move(non_const_pointer.implementation)) 
     
    130132    std::swap(implementation, other.implementation); 
    131133    return *this; 
     134  } 
     135 
     136  /*! 
     137   * Attach compressed data to buffer. 
     138   * Components that have their data also available in compressed form, can attach this to their published data. 
     139   * E.g. a frame grabber might receive images in MJPG from a camera driver. 
     140   * Later, compression might be required for network connections or recording. 
     141   * Instead of recompressing the data, the original can be used. 
     142   * Must be called, before buffer is pusblished. 
     143   * 
     144   * Note: if Finroc data_compression plugin is not available, the data is discarded. 
     145   * 
     146   * (only available for data types that are not cheaply copied (they are small anyway) and not for buffers that contain const data) 
     147   * 
     148   * \param compression_format Format in which data was compressed (e.g. "jpg" - should be the same strings as used with rrlib_data_compression to allow decompression) 
     149   *                           Note that string is not copied and must remain valid as long as data 
     150   * \param data Pointer to compressed data (data is copied) 
     151   * \param size Size of compressed data 
     152   * \param key_frame Is this a key frame? (meaning that data be uncompressed without knowledge of any former data (frames)) 
     153   */ 
     154  template < bool ENABLE = api::tPortImplementationTypeTrait<tPortData>::type == api::tPortImplementationType::STANDARD && (!cCONST_DATA) > 
     155  void AttachCompressedData(const char* compression_format, void* data, size_t size, typename std::enable_if<ENABLE, bool>::type key_frame = true) 
     156  { 
     157    implementation.AttachCompressedData(compression_format, data, size, key_frame); 
    132158  } 
    133159 
     
    204230  friend rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tPortDataPointer<U>& data); 
    205231 
     232  friend class data_compression::tPlugin; 
     233 
    206234  /*! Actual implementation of smart pointer class */ 
    207235  tImplementation implementation; 
Note: See TracChangeset for help on using the changeset viewer.