dynamic streams patch for dvb-t

Andrew de Quincey <[email protected]>
Newsgroups gmane.comp.video.videolan.vls.devel
Message-ID <[email protected]>
Hi, I've fixed the remaining problems in my DVB-T patch, and updated it
for todays CVS.

It now allows/fixes:
  DVB-T streams can be started and stopped dynamically.
  The timeout if you started vls, but didn't start a DVB-T stream.
  Segfaults on shutdown fixed.
  You can optionally specify the path to the dvbrc file in the dvb input
config section. (e.g. /etc/dvbrc)


--- CUT HERE ---
diff -Naur vls.ORIGINAL/src/modules/dvbinput/dvbinput.cpp vls/src/modules/dvbinput/dvbinput.cpp
--- vls.ORIGINAL/src/modules/dvbinput/dvbinput.cpp	2002-12-10 21:55:00.000000000 +0000
+++ vls/src/modules/dvbinput/dvbinput.cpp	2002-12-10 22:18:09.000000000 +0000
@@ -114,8 +114,8 @@
                                 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_pConverter = NULL;
   for(int i =0; i < 512; i++)
     m_iDemuxes[i] = -1;
@@ -137,6 +137,7 @@
 {
   int iNumber;
   C_String strType;
+  C_String dvbrc;
   char filen[FILELEN];
 
   // Retrieve config
@@ -144,6 +145,10 @@
   ASSERT(pApp);
 
   iNumber = pApp->GetSetting(GetName() + ".DeviceNumber", "0").ToInt();
+  dvbrc = pApp->GetSetting(GetName() + ".Dvbrc", "");
+  if (dvbrc.Length() != 0) {
+    strncpy(filen, dvbrc.GetString(), dvbrc.Length()+1);
+  }
 
   dvb->init("", "", iNumber);
   
@@ -219,10 +224,6 @@
   cConfig.m_pEventHandler = this;
   m_pConverter = pConverterModule->NewMpegConverter(cConfig);
   ASSERT(m_pConverter);
-  
-  // Launch the demux
-  m_pConverter->Create();
-
 }
 

@@ -237,16 +238,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 +458,6 @@
 
     // Kludge: signal the first PAT arrival.
     m_cEndInit.Protect();
-    m_iGotPat = 1;
     m_cEndInit.Signal();
     m_cEndInit.Release();
   }
@@ -471,31 +473,46 @@
   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
+    // 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);
@@ -520,15 +537,18 @@
 
     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 +593,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-10 21:55:00.000000000 +0000
+++ vls/src/modules/dvbinput/dvbinput.h	2002-12-10 22:05:12.000000000 +0000
@@ -87,8 +87,9 @@
   int m_iSendMethod;
   
   // 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
--- CUT HERE ---


-- 
This is the vls-devel mailing-list, see http://www.videolan.org/vls-devel/
To unsubscribe, please read http://www.videolan.org/lists.html
If you are in trouble, please contact <[email protected]>
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.