dvb patch for ignoring timeouts

Andrew de Quincey <[email protected]>
Newsgroups gmane.comp.video.videolan.vls.devel
Message-ID <[email protected]>
Sigh. This time I've even included the patch


-- 
Andrew de Quincey <[email protected]>
vls.patch (text/x-patch, 7.1 KB)
diff -Naur vls.ORIGINAL/src/modules/dvbinput/dvbinput.cpp vls/src/modules/dvbinput/dvbinput.cpp
--- vls.ORIGINAL/src/modules/dvbinput/dvbinput.cpp	2002-12-08 15:55:29.000000000 +0000
+++ vls/src/modules/dvbinput/dvbinput.cpp	2003-01-12 20:38:15.000000000 +0000
@@ -114,8 +114,9 @@
                                 m_cCurrentPat(0, 0, true)
 {
   dvb = new DVB;
-  m_iGotPat = 0;   // Did not get the first PAT yet
   m_iGotTpid = 0;  // Did not set the transponder yet
+  demuxUsageCount = 0; // nothing using the demux yet
+  m_bIgnoreTimeout = false;
   m_pConverter = NULL;
   for(int i =0; i < 512; i++)
     m_iDemuxes[i] = -1;
@@ -137,6 +138,7 @@
 {
   int iNumber;
   C_String strType;
+  C_String dvbrc;
   char filen[FILELEN];
 
   // Retrieve config
@@ -144,6 +146,12 @@
   ASSERT(pApp);
 
   iNumber = pApp->GetSetting(GetName() + ".DeviceNumber", "0").ToInt();
+  m_iSendMethod = pApp->GetSetting(GetName() + ".SendMethod", "0").ToInt();
+  m_bIgnoreTimeout = pApp->GetSetting(GetName() + ".IgnoreTimeout", "0").ToInt();
+  dvbrc = pApp->GetSetting(GetName() + ".Dvbrc", "");
+  if (dvbrc.Length() != 0) {
+    strncpy(filen, dvbrc.GetString(), dvbrc.Length()+1);
+  }
 
   dvb->init("", "", iNumber);
   
@@ -199,6 +207,7 @@
   ASSERT(pReaderModule);
 
   m_cInputBroadcast.SetOption("device", m_strDVR);
+  m_cInputBroadcast.SetOption("ignoreTimeout", m_bIgnoreTimeout);
   m_pReader = pReaderModule->NewMpegReader(&m_cInputBroadcast);
   ASSERT(m_pReader);
 
@@ -219,10 +228,6 @@
   cConfig.m_pEventHandler = this;
   m_pConverter = pConverterModule->NewMpegConverter(cConfig);
   ASSERT(m_pConverter);
-  
-  // Launch the demux
-  m_pConverter->Create();
-
 }
 
 
@@ -237,16 +242,18 @@
 
   if(m_pConverter)
   {
-    // Stop the input stream
-    try
-    {
-      m_pConverter->Stop();
-    }
-    catch(E_Exception e)
-    {
-      m_cEndInit.Release();
-      delete m_pConverter;
-      throw e;
+    // Stop the input converter if necessary
+    if (m_pConverter->IsRunning()) {
+      try
+	{
+	  m_pConverter->Stop();
+	}
+      catch(E_Exception e)
+	{
+	  m_cEndInit.Release();
+	  delete m_pConverter;
+	  throw e;
+	}
     }
 
     delete m_pConverter;
@@ -455,7 +462,6 @@
 
     // Kludge: signal the first PAT arrival.
     m_cEndInit.Protect();
-    m_iGotPat = 1;
     m_cEndInit.Signal();
     m_cEndInit.Release();
   }
@@ -471,31 +477,50 @@
   int iIndex=m_vProgramNames.Find(pBroadcast->GetProgram()->GetName());
   LogDbg(m_hLog, "DVB Channel found: "+dvb->chans[iIndex].name);
 
-  // Check that if we have already got one broadcast going that this
-  // new one is on the same mux (transponder)
-  if(m_iGotPat && m_iGotTpid != dvb->chans[iIndex].tpid)
-  {
-    LogDbg(m_hLog, "Attempting to start reception from different transponder." \
-           "Existing transponder is " + m_iGotTpid + " asked transponder is " +
-            dvb->chans[iIndex].tpid);
-    return;
-  }
-  
-  if (!m_iGotPat)
-  {
+  // lock the demux usage 
+  demuxUsageM.Lock();
+
+  // If we've not already started the demux, do so, and wait for the first
+  // PAT
+  if (demuxUsageCount == 0) {
     // Set the frontend up
     dvb->SetTP(dvb->chans[iIndex].tpid, dvb->chans[iIndex].satid);
     dvb->set_front();
 
-    // Put a filter on PAT
-    SelectPid(&m_cPatDecoder, 0x0000, TS_TYPE_NULL);
+     
+     sleep(3);
 
+     
+    // Launch the demux
+    m_pConverter->Create();
+    
+    // Add a filter for PAT
+    SelectPid(&m_cPatDecoder, 0x0000, TS_TYPE_NULL);
+    
     // Wait for the first PAT
     m_cEndInit.Wait();
     m_cEndInit.Release();
     m_iGotTpid = dvb->chans[iIndex].tpid; // Remember the transponder
+
+    // update demux counter and unlock
+    demuxUsageCount++;
+    demuxUsageM.UnLock();
+  } else {
+    // Check that if we have already got one broadcast going that this
+    // new one is on the same mux (transponder)
+    if (m_iGotTpid != dvb->chans[iIndex].tpid) {
+      LogDbg(m_hLog, "Attempting to start reception from different " +
+	     "transponder. Exiting transponder is " + m_iGotTpid + 
+	     " new transponder is " + dvb->chans[iIndex].tpid);
+      demuxUsageM.UnLock();
+      return;
+    }
+    
+    // update counter and unlock
+    demuxUsageCount++;
+    demuxUsageM.UnLock();
   }
-  
+
   // Get the program
   dvbpsi_pat_program_t *pProgram =
         m_cCurrentPat.GetProgram(dvb->chans[iIndex].pnr);
@@ -516,19 +541,21 @@
                                                m_pEventHandler, false, false);
 
     C_TsMux *pMux = new C_TsMux(m_pTsProvider, this, pBuffer);
-  
 
     try
     {
+
+      u16 iNumber = pBroadcast->GetProgram()->GetName().ToInt();
+
       pStreamer->Create();
 
       pMux->Attach();
 
       pMux->AttachProgram(pProgram->i_number, pProgram->i_pid);
 
-      m_cMuxes.Add(pProgram->i_number, pMux);
+      m_cMuxes.Add(iNumber, pMux);
 
-      m_cStreamers.Add(pProgram->i_number, pStreamer);
+      m_cStreamers.Add(iNumber, pStreamer);
 
     }
     catch(E_Exception e)
@@ -573,8 +600,19 @@
 {
   m_cLock.Lock();
 
-  //Unset the filter on PAT
-  UnselectPid(&m_cPatDecoder, 0x0000);
+  // lock demux counter and decrement usage counter
+  demuxUsageM.Lock();
+  demuxUsageCount--;    
+
+  // if the usage counter is 0, we'll have to remove the PAT filter
+  // and suspend the demux
+  if (demuxUsageCount == 0) {
+    UnselectPid(&m_cPatDecoder, 0x0000);
+    m_pConverter->Stop();
+  }
+  
+  // unlock
+  demuxUsageM.UnLock();
 
   u16 iNumber = pBroadcast->GetProgram()->GetName().ToInt();
 
diff -Naur vls.ORIGINAL/src/modules/dvbinput/dvbinput.h vls/src/modules/dvbinput/dvbinput.h
--- vls.ORIGINAL/src/modules/dvbinput/dvbinput.h	2002-12-08 15:55:29.000000000 +0000
+++ vls/src/modules/dvbinput/dvbinput.h	2003-01-12 20:35:49.000000000 +0000
@@ -85,10 +85,13 @@
   int m_iLnbSLof;
 
   int m_iSendMethod;
-  
+
+  bool m_bIgnoreTimeout;
+   
   // Kludge: signal the first PAT arrival.
-  int m_iGotPat;
-  int m_iGotTpid;
+  int demuxUsageCount;
+  int m_iGotTpid; 
+  C_Mutex demuxUsageM;
   C_Condition m_cEndInit;
 
   // Demuxes' file descriptors
diff -Naur vls.ORIGINAL/src/modules/dvbreader/dvbreader.cpp vls/src/modules/dvbreader/dvbreader.cpp
--- vls.ORIGINAL/src/modules/dvbreader/dvbreader.cpp	2002-11-19 14:08:07.000000000 +0000
+++ vls/src/modules/dvbreader/dvbreader.cpp	2003-01-12 20:39:37.000000000 +0000
@@ -85,6 +85,7 @@
                         C_MpegReader(pModule, pBroadcast)
 {
   m_strDeviceName=pBroadcast->GetOption("device");
+  m_bIgnoreTimeout=pBroadcast->GetOption("ignoreTimeout").ToInt();
 }
 
 
@@ -124,9 +125,9 @@
     if(poll(pfd, 1, 10000))
     { 
       if(pfd[0].revents & POLLIN) { iRc=read(m_hFd, pBuff, 188);}
-      else return MPEG_STREAMERROR;
+      else if (!m_bIgnoreTimeout) return MPEG_STREAMERROR;
     }
-    else
+    else if (!m_bIgnoreTimeout)
     {
           printf("Time out !\n");
           return MPEG_STREAMERROR;
diff -Naur vls.ORIGINAL/src/modules/dvbreader/dvbreader.h vls/src/modules/dvbreader/dvbreader.h
--- vls.ORIGINAL/src/modules/dvbreader/dvbreader.h	2002-12-27 00:18:14.000000000 +0000
+++ vls/src/modules/dvbreader/dvbreader.h	2003-01-12 20:35:23.000000000 +0000
@@ -54,6 +54,8 @@
   C_String m_strDeviceName;
   int m_hFd;
 
+  bool m_bIgnoreTimeout;
+   
   bool m_bLoop;
   bool m_bEnd;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.