Re: Patch to regulate network output
Jean-Paul Saman <[email protected]>
| Newsgroups | gmane.comp.video.videolan.vls.devel |
|---|---|
| Message-ID | <[email protected]> |
Marian Durkovic wrote: > Hi all, > > > uff, first of all there's a fatal bug in WaitSendDate() which results > in m_dSlope being treated as (s64) which means values like 0.9 are > considered zero and all packets are outtputted immediately. > > The first line of WaitSendDate() should be changed to: > > s64 iSendDate = m_iLastTime + m_iDeltaClock + (s64)(m_dSlope*m_uiByteRead); > > i.e. parenthessis need to be added around m_dSlope*m_uiByteRead and only > the result changed to s64. > > After the above change the bigger blocks are only transmitted as a result > of extrapolation. Using interpolation as suggested by Jean-Paul > will solve it perfectly but I don't know how to find the next PCR in the > buffer. Could someone please help? > Try the patch I send you that does intrapolation if it can and falls back to extrapolation if there is no other choice. It already seeks the next PCR. > Now also the input from MPEG2 encoder board works fine, but usePCR flag > needs to be changed into true in videoinput.cpp > > In any case, high-resolution timers are desperately needed. > > greetings, Jean-Paul Saman.
vls_patch_for_marian_durkovic.patch
(text/plain, 3.6 KB)
--- src/core/stack.cpp.orig Tue Mar 4 23:12:05 2003
+++ src/core/stack.cpp Tue Mar 4 23:28:48 2003
@@ -177,6 +177,28 @@
//------------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------------
+// Take a peek at the data on position given.
+//------------------------------------------------------------------------------
+template <class T> T* C_Fifo<T>::Peek(unsigned int uiIndex)
+{
+ T* pData = NULL;
+
+ // Check that there is valid data stored a the given index.
+ ASSERT(uiIndex < Size());
+
+ unsigned int iElemPos = m_iWhereToPop + uiIndex;
+
+ if(iElemPos >= (m_iCapacity+1))
+ iElemPos = iElemPos - m_iCapacity - 1;
+
+ pData = m_apBuff[iElemPos];
+ return pData;
+}
+
+
+//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
//
--- src/core/stack.h.orig Tue Mar 4 23:12:12 2003
+++ src/core/stack.h Tue Mar 4 23:27:59 2003
@@ -43,6 +43,7 @@
int Push(T* pData);
T* Pop();
+ T* Peek(unsigned int uiIndex);
inline unsigned int Size() const
{ return (m_iCapacity + 1 + (m_iWhereToPush - m_iWhereToPop))
--- src/server/tsstreamer.cpp.orig Tue Mar 4 22:21:40 2003
+++ src/server/tsstreamer.cpp Tue Mar 4 23:35:41 2003
@@ -280,6 +280,7 @@
// Update the data for the next PCR
m_uiByteRead = 0;
m_iLastTime = iPCRTime;
+ m_iNextPCRTime = 0;
}
@@ -306,8 +307,8 @@
LogDbg(m_hLog, "Adjusting timer discontinuity for pgrm "+strPgrmName);
m_iDeltaClock = GetDate() - iPCRTime;
}
- else
- {
+ else if (!CalculateSlope(iPCRTime))
+ {
// (Re)evaluate the slope
ASSERT(m_uiByteRead > 0);
#ifdef _WIN32
@@ -316,7 +317,6 @@
m_dSlope = ((double)iPCRTime - m_iLastTime) / m_uiByteRead;
#endif
}
-
// Update the data for the next PCR
m_uiByteRead = 0;
m_iLastTime = iPCRTime;
@@ -351,6 +351,38 @@
}
}
+//------------------------------------------------------------------------------
+// Calculate the slope between two PCR's from the stream
+//------------------------------------------------------------------------------
+bool C_TsStreamer::CalculateSlope(s64 iPCRTime)
+{
+ ASSERT( iPCRTime>=m_iNextPCRTime );
+
+ bool result = false;
+ unsigned int uiIndex;
+ unsigned int uiBytesToSend = 0;
+
+ for (uiIndex = 1; uiIndex < m_pBuffer->Size(); uiIndex++)
+ {
+ // I do not refcount this packet so in theory a problem
+ // could result from this when the packet is released. At
+ // the moment I try to read it. For safety it should be refcounted.
+ C_TsPacket *pPacket = m_pBuffer->Peek(uiIndex);
+ ASSERT(pPacket);
+ uiBytesToSend += TS_PACKET_LEN;
+ if (pPacket->HasPCR())
+ {
+ // Remember the next PCR time, and use it in calculations for sending.
+ ASSERT(uiBytesToSend>0);
+
+ m_iNextPCRTime = pPacket->GetPCRTime();
+ m_dSlope = ((double) m_iNextPCRTime - iPCRTime) / (s64)uiBytesToSend;
+ result = true;
+ break;
+ }
+ }
+ return result;
+}
//------------------------------------------------------------------------------
// Returns the current date in microseconds
--- src/server/tsstreamer.h.orig Tue Mar 4 22:21:47 2003
+++ src/server/tsstreamer.h Tue Mar 4 23:02:17 2003
@@ -57,6 +57,8 @@
inline void InitClock(C_TsPacket* pPacket);
inline void WaitSendDate();
inline s64 GetDate();
+
+ bool CalculateSlope(s64 iPCRTime);
bool m_bStop;
bool m_bFirstPCR;
@@ -74,6 +76,7 @@
u64 m_uiByteRead;
s64 m_iLastTime;
+ s64 m_iNextPCRTime;
s64 m_iDeltaClock;
double m_dSlope;