- add ts recorder to dvb record service
authorFelix Domke <tmbinc@elitedvb.net>
Sat, 30 Apr 2005 18:01:30 +0000 (18:01 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sat, 30 Apr 2005 18:01:30 +0000 (18:01 +0000)
lib/service/servicedvbrecord.cpp
lib/service/servicedvbrecord.h

index 368adb70b7ce4a239b73a429fa7e8425a7c0cfdf..c72b81d39e291a40c751e21df96279ed2e2edfa8 100644 (file)
@@ -1,17 +1,19 @@
 #include <lib/service/servicedvbrecord.h>
 #include <lib/base/eerror.h>
 
+#include <fcntl.h>
 
 DEFINE_REF(eDVBServiceRecord);
 
 eDVBServiceRecord::eDVBServiceRecord(const eServiceReferenceDVB &ref): m_ref(ref)
 {
        CONNECT(m_service_handler.serviceEvent, eDVBServiceRecord::serviceEvent);
+       m_recording = 0;
 }
 
 void eDVBServiceRecord::serviceEvent(int event)
 {
-       eDebug("service event %d", event);
+       eDebug("RECORD service event %d", event);
        switch (event)
        {
        case eDVBServicePMTHandler::eventTuned:
@@ -21,12 +23,44 @@ void eDVBServiceRecord::serviceEvent(int event)
        }
        case eDVBServicePMTHandler::eventNewProgramInfo:
        {
-               int vpid = -1, apid = -1, pcrpid = -1;
+                       /* allocate a ts recorder if we don't already have one. */
+               if (!m_recording)
+               {
+                       ::remove("recordings.ts");
+                       int fd = ::open("recording.ts", O_WRONLY|O_CREAT, 0644);
+                       if (fd == -1)
+                       {
+                               eDebug("eDVBServiceRecord - can't open hardcoded recording file!");
+                               return;
+                       }
+                       ePtr<iDVBDemux> demux;
+                       if (m_service_handler.getDemux(demux))
+                       {
+                               eDebug("eDVBServiceRecord - NO DEMUX available!");
+                               return;
+                       }
+                       demux->createTSRecorder(m_record);
+                       if (!m_record)
+                       {
+                               eDebug("eDVBServiceRecord - no ts recorder available.");
+                               return;
+                       }
+                       m_record->setTargetFD(fd);
+                       m_pids_active.clear();
+               } else
+               {
+                               /* when we're already recording, we already have a recorder allocated. */
+                       assert(m_record);
+               }
+               
+
                eDVBServicePMTHandler::program program;
                if (m_service_handler.getProgramInfo(program))
                        eDebug("getting program info failed.");
                else
                {
+                       std::set<int> pids_to_record;
+                       
                        eDebugNoNewLine("RECORD: have %d video stream(s)", program.videoStreams.size());
                        if (!program.videoStreams.empty())
                        {
@@ -35,8 +69,7 @@ void eDVBServiceRecord::serviceEvent(int event)
                                        i(program.videoStreams.begin()); 
                                        i != program.videoStreams.end(); ++i)
                                {
-                                       if (vpid == -1)
-                                               vpid = i->pid;
+                                       pids_to_record.insert(i->pid);
                                        if (i != program.videoStreams.begin())
                                                eDebugNoNewLine(", ");
                                        eDebugNoNewLine("%04x", i->pid);
@@ -51,8 +84,7 @@ void eDVBServiceRecord::serviceEvent(int event)
                                        i(program.audioStreams.begin()); 
                                        i != program.audioStreams.end(); ++i)
                                {
-                                       if (apid == -1)
-                                               apid = i->pid;
+                                       pids_to_record.insert(i->pid);
                                        if (i != program.audioStreams.begin())
                                                eDebugNoNewLine(", ");
                                        eDebugNoNewLine("%04x", i->pid);
@@ -61,7 +93,37 @@ void eDVBServiceRecord::serviceEvent(int event)
                        }
                        eDebug(", and the pcr pid is %04x", program.pcrPid);
                        if (program.pcrPid != 0x1fff)
-                               pcrpid = program.pcrPid;
+                               pids_to_record.insert(program.pcrPid);
+                       
+                               /* find out which pids are NEW and which pids are obsolete.. */
+                       std::set<int> new_pids, obsolete_pids;
+                       
+                       std::set_difference(pids_to_record.begin(), pids_to_record.end(), 
+                                       m_pids_active.begin(), m_pids_active.end(),
+                                       std::inserter(new_pids, new_pids.begin()));
+                       
+                       std::set_difference(
+                                       m_pids_active.begin(), m_pids_active.end(),
+                                       pids_to_record.begin(), pids_to_record.end(), 
+                                       std::inserter(new_pids, new_pids.begin())
+                                       );
+                       
+                       for (std::set<int>::iterator i(new_pids.begin()); i != new_pids.end(); ++i)
+                       {
+                               eDebug("ADD PID: %04x", *i);
+                               m_record->addPID(*i);
+                       }
+                       for (std::set<int>::iterator i(obsolete_pids.begin()); i != obsolete_pids.end(); ++i)
+                       {
+                               eDebug("REMOVED PID: %04x", *i);
+                               m_record->removePID(*i);
+                       }
+                       
+                       if (!m_recording)
+                       {
+                               m_record->start();
+                               m_recording = 1;
+                       }
                }
                
                                // notify record thread...              
@@ -79,6 +141,11 @@ RESULT eDVBServiceRecord::start()
 RESULT eDVBServiceRecord::stop()
 {
        eDebug("stop recording!!");
+       if (m_recording)
+       {
+               m_record->stop();
+               m_record = 0;
+               m_recording = 0;
+       }
        return 0;
 }
-
index 93118bed5456650dcccd1983db0be3b38524b9d4..6bd9fb96b756d6d43e16852c2fd92f93c834dc33 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <lib/dvb/pmt.h>
 #include <lib/dvb/eit.h>
+#include <set>
 
 #include <lib/service/servicedvb.h>
 
@@ -22,6 +23,11 @@ private:
        eDVBServicePMTHandler m_service_handler;
        eServiceReferenceDVB m_ref;
        void serviceEvent(int event);
+       
+       ePtr<iDVBTSRecorder> m_record;
+       
+       int m_recording;
+       std::set<int> m_pids_active;
 };
 
 #endif