Show
Ignore:
Timestamp:
02/10/07 04:06:26 (16 years ago)
Author:
pieterpalmers
Message:

- document TimestampedBuffer? class
- partially ported timestamp handling to TimestampedBuffer?
- introduced test for TimestampedBuffer? class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/libutil/TimestampedBuffer.h

    r391 r392  
    3636class TimestampedBufferClient; 
    3737 
     38/** 
     39 * \brief Class implementing a frame buffer that is time-aware 
     40 * 
     41 * This class implements a buffer that is time-aware. Whenever new frames  
     42 * are written to the buffer, the timestamp corresponding to the last frame 
     43 * in the buffer is updated. This allows to calculate the timestamp of any 
     44 * other frame in the buffer. 
     45 * 
     46 * The buffer is a frame buffer, having the following parameters defining 
     47 * it's behaviour: 
     48 * - buff_size: buffer size in frames (setBufferSize()) 
     49 * - events_per_frame: the number of events per frame (setEventsPerFrame()) 
     50 * - event_size: the storage size of the events (in bytes) (setEventSize()) 
     51 * 
     52 * The total size of the buffer (in bytes) is at least  
     53 * buff_size*events_per_frame*event_size. 
     54 * 
     55 * Timestamp tracking is done by requiring that a timestamp is specified every 
     56 * time frames are added to the buffer. In combination with the buffer fill and 
     57 * the frame rate (calculated internally), this allows to calculate the timestamp 
     58 * of any frame in the buffer. In order to initialize the internal data structures, 
     59 * the setNominalRate() and setUpdatePeriod() functions are provided. 
     60 * 
     61 * \note Currently the class only supports fixed size writes of size update_period. 
     62 *       This can change in the future, implementation ideas are already in place. 
     63 * 
     64 * The TimestampedBuffer class is time unit agnostic. It can handle any time unit 
     65 * as long as it fits in a 64 bit unsigned integer. The buffer supports wrapped  
     66 * timestamps using (...). 
     67 * 
     68 * There are two methods of reading and writing to the buffer.  
     69 * 
     70 * The first method uses conventional readFrames() and writeFrames() functions. 
     71 * 
     72 * The second method makes use of the TimestampedBufferClient interface. When a  
     73 * TimestampedBuffer is created, it is required that a TimestampedBufferClient is 
     74 * registered. This client implements the processReadBlock and processWriteBlock 
     75 * functions. These are block processing 'callbacks' that allow zero-copy processing 
     76 * of the buffer contents. In order to initiate block processing, the 
     77 * blockProcessWriteFrames and blockProcessReadFrames functions are provided by  
     78 * TimestampedBuffer. 
     79 * 
     80 */ 
    3881class TimestampedBuffer { 
    3982 
    4083public: 
    4184 
     85 
    4286    TimestampedBuffer(TimestampedBufferClient *); 
    4387    virtual ~TimestampedBuffer(); 
    4488     
    45     bool writeFrames(unsigned int nbframes, char *data); 
     89    bool writeFrames(unsigned int nbframes, char *data, uint64_t ts); 
    4690    bool readFrames(unsigned int nbframes, char *data); 
    4791     
     
    57101    bool setBufferSize(unsigned int s); 
    58102     
     103    bool setWrapValue(uint64_t w); 
     104     
    59105    unsigned int getBufferFill(); 
    60106     
     
    62108    int getFrameCounter() {return m_framecounter;}; 
    63109 
    64     void decrementFrameCounter(int nbframes); 
    65     void incrementFrameCounter(int nbframes, uint64_t new_timestamp); 
    66     void resetFrameCounter(); 
    67      
    68110    void getBufferHeadTimestamp(uint64_t *ts, uint64_t *fc); 
    69111    void getBufferTailTimestamp(uint64_t *ts, uint64_t *fc); 
     
    72114    
    73115    // dll stuff 
    74     void setNominalRate(double r) {m_nominal_rate=r;}
    75     double getRate() {return m_dll_e2;}
     116    bool setNominalRate(float r)
     117    float getRate()
    76118     
    77     void setUpdatePeriod(unsigned int t) {m_update_period=t;}
     119    bool setUpdatePeriod(unsigned int t)
    78120     
    79121    // misc stuff 
    80122    void dumpInfo(); 
    81      
    82      
     123    void setVerboseLevel(int l) {setDebugLevel(l);}; 
     124 
     125private: 
     126    void decrementFrameCounter(int nbframes); 
     127    void incrementFrameCounter(int nbframes, uint64_t new_timestamp); 
     128    void resetFrameCounter(); 
     129 
    83130protected: 
    84131 
     
    91138    unsigned int m_bytes_per_frame; 
    92139    unsigned int m_bytes_per_buffer; 
     140     
     141    uint64_t m_wrap_at; // value to wrap at 
    93142     
    94143    TimestampedBufferClient *m_Client; 
     
    117166    double m_dll_c; 
    118167     
    119     double m_nominal_rate; 
     168    float m_nominal_rate; 
    120169    unsigned int m_update_period; 
    121170}; 
    122171 
     172/** 
     173 * \brief Interface to be implemented by TimestampedBuffer clients 
     174 */ 
    123175class TimestampedBufferClient { 
    124176    public: