Yate
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
DataTranslator Class Reference

An unidirectional data translator (codec) More...

#include <yatephone.h>

Inheritance diagram for DataTranslator:
DataConsumer DataNode RefObject GenObject

Public Member Functions

 DataTranslator (const char *sFormat, const char *dFormat)
 
 DataTranslator (const char *sFormat, DataSource *source=0)
 
 ~DataTranslator ()
 
virtual void * getObject (const String &name) const
 
virtual bool valid () const
 
virtual DataSourcegetTransSource () const
 
DataTranslatorgetFirstTranslator ()
 
const DataTranslatorgetFirstTranslator () const
 
- Public Member Functions inherited from DataConsumer
 DataConsumer (const char *format="slin")
 
virtual void destroyed ()
 
virtual unsigned long Consume (const DataBlock &data, unsigned long tStamp, unsigned long flags)=0
 
DataSourcegetConnSource () const
 
DataSourcegetOverSource () const
 
- Public Member Functions inherited from DataNode
 DataNode (const char *format=0)
 
virtual int costFormat (const DataFormat &format)
 
virtual bool setFormat (const DataFormat &format)
 
const DataFormatgetFormat () const
 
unsigned long timeStamp () const
 
virtual bool control (NamedList &params)
 
virtual void attached (bool added)
 
- Public Member Functions inherited from RefObject
 RefObject ()
 
virtual ~RefObject ()
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtoString () const
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static ObjListsrcFormats (const DataFormat &dFormat="slin", int maxCost=-1, unsigned int maxLen=0, ObjList *lst=0)
 
static ObjListdestFormats (const DataFormat &sFormat="slin", int maxCost=-1, unsigned int maxLen=0, ObjList *lst=0)
 
static ObjListallFormats (const ObjList *formats, bool existing=true, bool sameRate=true, bool sameChans=true)
 
static ObjListallFormats (const String &formats, bool existing=true, bool sameRate=true, bool sameChans=true)
 
static bool canConvert (const DataFormat &fmt1, const DataFormat &fmt2="slin")
 
static int cost (const DataFormat &sFormat, const DataFormat &dFormat)
 
static DataTranslatorcreate (const DataFormat &sFormat, const DataFormat &dFormat)
 
static bool attachChain (DataSource *source, DataConsumer *consumer, bool override=false)
 
static bool detachChain (DataSource *source, DataConsumer *consumer)
 
static void setMaxChain (unsigned int maxChain)
 
- Static Public Member Functions inherited from DataNode
static unsigned long invalidStamp ()
 
- Static Public Member Functions inherited from RefObject
static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Protected Member Functions

ObjListgetConsumers () const
 
virtual bool synchronize (DataSource *source)
 
- Protected Member Functions inherited from RefObject
virtual void zeroRefs ()
 
bool resurrect ()
 

Static Protected Member Functions

static void install (TranslatorFactory *factory)
 
static void uninstall (TranslatorFactory *factory)
 

Friends

class TranslatorFactory
 

Additional Inherited Members

- Public Types inherited from DataNode
enum  DataFlags {
  DataStart = 0x0001, DataEnd = 0x0002, DataMark = 0x0004, DataSilent = 0x0008,
  DataMissed = 0x0010, DataError = 0x0020, DataPrivate = 0x0100
}
 
- Protected Attributes inherited from DataNode
DataFormat m_format
 
unsigned long m_timestamp
 

Detailed Description

An unidirectional data translator (codec)

The DataTranslator holds a translator (codec) capable of unidirectional conversion of data from one type to another.

Constructor & Destructor Documentation

DataTranslator ( const char *  sFormat,
const char *  dFormat 
)

Construct a data translator.

Parameters
sFormatName of the source format (data received from the consumer)
dFormatName of the destination format (data supplied to the source)
DataTranslator ( const char *  sFormat,
DataSource source = 0 
)
explicit

Creates a data translator from an existing source, does not increment the source's reference counter.

Parameters
sFormatName of the source format (data received from the consumer)
sourceOptional pointer to a DataSource object

Destroys the translator and its source

Member Function Documentation

static ObjList* allFormats ( const ObjList formats,
bool  existing = true,
bool  sameRate = true,
bool  sameChans = true 
)
static

Get a list of formats supported by transcoding for a given format list

Parameters
formatsList of data format names
existingAlso return formats already existing in the initial list
sameRateOnly return formats with same sampling rate
sameChansOnly return formats with same number of channels
Returns
List of format names, must be freed by the caller
static ObjList* allFormats ( const String formats,
bool  existing = true,
bool  sameRate = true,
bool  sameChans = true 
)
static

Get a list of formats supported by transcoding for a given format list

Parameters
formatsData format names as comma separated list
existingAlso return formats already existing in the initial list
sameRateOnly return formats with same sampling rate
sameChansOnly return formats with same number of channels
Returns
List of format names, must be freed by the caller
static bool attachChain ( DataSource source,
DataConsumer consumer,
bool  override = false 
)
static

Attach a consumer to a source, possibly trough a chain of translators

Parameters
sourceSource to attach the chain to
consumerConsumer where the chain ends
overrideAttach chain for temporary source override
Returns
True if successfull, false if no translator chain could be built
static bool canConvert ( const DataFormat fmt1,
const DataFormat fmt2 = "slin" 
)
static

Check if bidirectional conversion can be performed by installed translators

Parameters
fmt1Name of the first data format
fmt2Name of the second data format
Returns
True if translators can be created for both directions
static int cost ( const DataFormat sFormat,
const DataFormat dFormat 
)
static

Finds the cost of a translator given the source and destination format names

Parameters
sFormatName of the source format (data received from the consumer)
dFormatName of the destination format (data supplied to the source)
Returns
Cost of best (cheapest) codec or -1 if no known codec exists
static DataTranslator* create ( const DataFormat sFormat,
const DataFormat dFormat 
)
static

Creates a translator given the source and destination format names

Parameters
sFormatName of the source format (data received from the consumer)
dFormatName of the destination format (data supplied to the source)
Returns
A pointer to a DataTranslator object or NULL if no known codec exists
static ObjList* destFormats ( const DataFormat sFormat = "slin",
int  maxCost = -1,
unsigned int  maxLen = 0,
ObjList lst = 0 
)
static

Get a list of formats supported for a given input format

Parameters
sFormatName of source format
maxCostMaximum cost of candidates to consider, -1 to accept all
maxLenMaximum length of codec chains to consider, 0 to accept all
lstInitial list, will append to it if not empty
Returns
List of destination format names, must be freed by the caller
static bool detachChain ( DataSource source,
DataConsumer consumer 
)
static

Detach a consumer from a source, possibly trough a chain of translators

Parameters
sourceSource to dettach the chain from
consumerConsumer where the chain ends
Returns
True if successfull, false if source and consumers were not attached
ObjList* getConsumers ( ) const
inlineprotected

Get access to the list of consumers of the data source

Returns
Pointer to list entry of first consumer, NULL if none attached

References ObjList::skipNull().

DataTranslator* getFirstTranslator ( )

Get the first translator from a chain

Returns
Pointer to the first translator in a chain
const DataTranslator* getFirstTranslator ( ) const

Constant version to get the first translator from a chain

Returns
Pointer to the first translator in a chain
virtual void* getObject ( const String name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from DataConsumer.

virtual DataSource* getTransSource ( ) const
inlinevirtual

Get the data source of a translator object

Returns
A pointer to the DataSource object or NULL

Reimplemented from DataConsumer.

static void install ( TranslatorFactory factory)
staticprotected

Install a Translator Factory in the list of known codecs

Parameters
factoryA pointer to a TranslatorFactory instance

Referenced by TranslatorFactory::TranslatorFactory().

static void setMaxChain ( unsigned int  maxChain)
static

Set the length of the longest translator chain we are allowed to create

Parameters
maxChainDesired longest chain length
static ObjList* srcFormats ( const DataFormat dFormat = "slin",
int  maxCost = -1,
unsigned int  maxLen = 0,
ObjList lst = 0 
)
static

Get a list of formats supported for a given output format.

Parameters
dFormatName of destination format
maxCostMaximum cost of candidates to consider, -1 to accept all
maxLenMaximum length of codec chains to consider, 0 to accept all
lstInitial list, will append to it if not empty
Returns
List of source format names, must be freed by the caller
virtual bool synchronize ( DataSource source)
protectedvirtual

Synchronize the consumer with a source

Parameters
sourceData source to copy the timestamp from
Returns
True if we could synchronize with the source

Reimplemented from DataConsumer.

static void uninstall ( TranslatorFactory factory)
staticprotected

Remove a Translator Factory from the list of known codecs

Parameters
factoryA pointer to a TranslatorFactory instance
virtual bool valid ( ) const
inlinevirtual

Check if the data translator has a valid source

Returns
True if still valid, false if node should be removed

Reimplemented from DataNode.

References DataSource::valid().


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