Logo Search packages:      
Sourcecode: libffado version File versions  Download package

Util::TimestampedBuffer Class Reference

#include <TimestampedBuffer.h>

List of all members.

Detailed Description

Class implementing a frame buffer that is time-aware.

This class implements a buffer that is time-aware. Whenever new frames are written to the buffer, the timestamp corresponding to the last frame in the buffer is updated. This allows to calculate the timestamp of any other frame in the buffer.

The buffer is a frame buffer, having the following parameters defining it's behaviour:

The total size of the buffer (in bytes) is at least buff_size*events_per_frame*event_size.

Timestamp tracking is done by requiring that a timestamp is specified every time frames are added to the buffer. In combination with the buffer fill and the frame rate (calculated internally), this allows to calculate the timestamp of any frame in the buffer. In order to initialize the internal data structures, the setNominalRate() and setUpdatePeriod() functions are provided.

Currently the class only supports fixed size writes of size update_period. This can change in the future, implementation ideas are already in place.
The TimestampedBuffer class is time unit agnostic. It can handle any time unit as long as it fits in a 64 bit unsigned integer. The buffer supports wrapped timestamps using (...).

There are two methods of reading and writing to the buffer.

The first method uses conventional readFrames() and writeFrames() functions.

The second method makes use of the TimestampedBufferClient interface. When a TimestampedBuffer is created, it is required that a TimestampedBufferClient is registered. This client implements the processReadBlock and processWriteBlock functions. These are block processing 'callbacks' that allow zero-copy processing of the buffer contents. In order to initiate block processing, the blockProcessWriteFrames and blockProcessReadFrames functions are provided by TimestampedBuffer.

Definition at line 89 of file TimestampedBuffer.h.

Public Member Functions

bool blockProcessReadFrames (unsigned int nbframes)
 Performs block processing read of frames.
bool blockProcessWriteFrames (unsigned int nbframes, ffado_timestamp_t ts)
 Performs block processing write of frames.
bool clearBuffer ()
 Resets the TimestampedBuffer.
void disable ()
bool dropFrames (unsigned int nbframes)
 Drop frames from the head of the buffer.
void dumpInfo ()
 Print status info.
void enable ()
double getBandwidth ()
 Returns the current bandwidth of the DLL.
unsigned int getBufferFill ()
 Returns the current fill of the buffer.
void getBufferHeadTimestamp (ffado_timestamp_t *ts, signed int *fc)
 return the timestamp of the first frame in the buffer
unsigned int getBufferSize ()
unsigned int getBufferSpace ()
 Returns the current write space in the buffer.
void getBufferTailTimestamp (ffado_timestamp_t *ts, signed int *fc)
 return the timestamp of the last frame in the buffer
unsigned int getBytesPerFrame ()
int getFrameCounter ()
float getNominalRate ()
float getRate ()
 return the effective rate
ffado_timestamp_t getTimestampFromHead (int nframes)
 Get timestamp for a specific position from the buffer head.
ffado_timestamp_t getTimestampFromTail (int nframes)
 Get timestamp for a specific position from the buffer tail.
unsigned int getUpdatePeriod ()
 Get the nominal update period (in frames).
bool isEnabled ()
bool isTransparent ()
bool preloadFrames (unsigned int nbframes, char *data, bool keep_head_ts)
 Preload frames into the buffer.
bool prepare ()
 Prepares the TimestampedBuffer.
bool readFrames (unsigned int nbframes, char *data)
 Read frames from the buffer.
bool resizeBuffer (unsigned int size)
bool setBandwidth (double bw)
 Set the bandwidth of the DLL.
void setBufferHeadTimestamp (ffado_timestamp_t new_timestamp)
 Sets the buffer head timestamp.
bool setBufferSize (unsigned int s)
 Sets the buffer size in frames.
void setBufferTailTimestamp (ffado_timestamp_t new_timestamp)
 Sets the buffer tail timestamp.
bool setEventSize (unsigned int s)
 Sets the size of the events.
bool setEventsPerFrame (unsigned int s)
 Sets the number of events per frame.
bool setNominalRate (float r)
 Set the nominal rate in timeunits/frame.
void setRate (float rate)
 presets the effective rate
void setTransparent (bool v)
bool setUpdatePeriod (unsigned int t)
 Set the nominal update period (in frames).
void setVerboseLevel (int l)
bool setWrapValue (ffado_timestamp_t w)
 set the value at which timestamps should wrap around
 TimestampedBuffer (TimestampedBufferClient *)
bool writeDummyFrame ()
 Insert a dummy frame to the head buffer.
bool writeFrames (unsigned int nbframes, char *data, ffado_timestamp_t ts)
 Write frames to the buffer.

Protected Attributes

unsigned int m_buffer_size
unsigned int m_bytes_per_buffer
unsigned int m_bytes_per_frame
unsigned int m_cluster_size
bool m_enabled
ffado_ringbuffer_t * m_event_buffer
unsigned int m_event_size
unsigned int m_events_per_frame
unsigned int m_process_block_size
char * m_process_buffer
bool m_transparent
ffado_timestamp_t m_wrap_at

Private Member Functions

float calculateRate ()
 calculate the effective rate
void decrementFrameCounter (unsigned int nbframes)
void incrementFrameCounter (unsigned int nbframes, ffado_timestamp_t new_timestamp)
void resetFrameCounter ()

Private Attributes

ffado_timestamp_t m_buffer_next_tail_timestamp
ffado_timestamp_t m_buffer_tail_timestamp
float m_current_rate
float m_dll_b
float m_dll_c
double m_dll_e2
signed int m_framecounter
pthread_mutex_t m_framecounter_lock
float m_nominal_rate
unsigned int m_update_period

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index