From 927d5db29a3c7d5483bfc9c7e9c468dbfcf22602 Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 13 Sep 2006 18:52:25 +0000 Subject: [PATCH] Fixed bug in automatical generation of data timestamps. git-svn-id: http://voip.null.ro/svn/yate@1030 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/DataFormat.cpp | 21 +++++++++++++++------ yatephone.h | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/engine/DataFormat.cpp b/engine/DataFormat.cpp index 7d8fe0e0..644b6ff1 100644 --- a/engine/DataFormat.cpp +++ b/engine/DataFormat.cpp @@ -485,12 +485,19 @@ void DataSource::Forward(const DataBlock& data, unsigned long tStamp) DDebug(DebugInfo,"Forwarding on a dead DataSource! [%p]",this); return; } - // no timestamp provided - try to guess - if (tStamp == (unsigned long)-1) { - tStamp = m_timestamp; - const FormatInfo* f = m_format.getInfo(); - if (f) - tStamp += f->guessSamples(data.length()); + + // try to evaluate amount of samples in this packet + const FormatInfo* f = m_format.getInfo(); + unsigned long nSamp = f ? f->guessSamples(data.length()) : 0; + + // if no timestamp provided - try to use next expected + if (tStamp == invalidStamp()) + tStamp = m_nextStamp; + // still no timestamp known - wild guess based on this packet size + if (tStamp == invalidStamp()) { + DDebug(DebugNote,"Unknow timestamp - assuming %lu + %lu [%p]", + m_timestamp,nSamp,this); + tStamp = m_timestamp + nSamp; } ObjList *l = m_consumers.skipNull(); for (; l; l=l->skipNext()) { @@ -498,6 +505,7 @@ void DataSource::Forward(const DataBlock& data, unsigned long tStamp) c->Consume(data,tStamp,this); } m_timestamp = tStamp; + m_nextStamp = nSamp ? (tStamp + nSamp) : invalidStamp(); } bool DataSource::attach(DataConsumer* consumer, bool override) @@ -582,6 +590,7 @@ void DataSource::synchronize(unsigned long tStamp) return; } m_timestamp = tStamp; + m_nextStamp = invalidStamp(); ObjList *l = m_consumers.skipNull(); for (; l; l=l->skipNext()) { DataConsumer *c = static_cast(l->get()); diff --git a/yatephone.h b/yatephone.h index e5b1c8f7..428761ca 100644 --- a/yatephone.h +++ b/yatephone.h @@ -330,6 +330,13 @@ public: inline unsigned long timeStamp() const { return m_timestamp; } + /** + * Get the internal representation of an invalid or unknown timestamp + * @return Invalid timestamp - unsigned long conversion of -1 + */ + inline static unsigned long invalidStamp() + { return (unsigned long)-1; } + protected: DataFormat m_format; unsigned long m_timestamp; @@ -428,7 +435,7 @@ public: * @param format Name of the data format, default "slin" (Signed Linear) */ inline DataSource(const char* format = "slin") - : DataNode(format), m_translator(0) { } + : DataNode(format), m_nextStamp(invalidStamp()), m_translator(0) { } /** * Source's destructor - detaches all consumers @@ -447,7 +454,7 @@ public: * @param data The raw data block to forward; an empty block ends data * @param tStamp Timestamp of data - typically samples */ - void Forward(const DataBlock& data, unsigned long tStamp = (unsigned long)-1); + void Forward(const DataBlock& data, unsigned long tStamp = invalidStamp()); /** * Attach a data consumer @@ -489,7 +496,15 @@ public: */ void synchronize(unsigned long tStamp); + /** + * Get the next expected position in the data stream + * @return Timestamp of next expected data position, may be invalid/unknown + */ + inline unsigned long nextStamp() const + { return m_nextStamp; } + protected: + unsigned long m_nextStamp; DataTranslator* m_translator; ObjList m_consumers; Mutex m_mutex;