better error/retry handling for recorder
authorFelix Domke <tmbinc@elitedvb.net>
Sun, 15 Jan 2006 12:08:42 +0000 (12:08 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sun, 15 Jan 2006 12:08:42 +0000 (12:08 +0000)
lib/service/servicedvbrecord.cpp
lib/service/servicedvbrecord.h

index cfcfe8b41acf258f8e9956ef968e2710edffd367..10ab8ae7279c572ba3583432955064f01f0a26fe 100644 (file)
@@ -5,11 +5,12 @@
 
 DEFINE_REF(eDVBServiceRecord);
 
-eDVBServiceRecord::eDVBServiceRecord(const eServiceReferenceDVB &ref): m_ref(ref), m_service_handler(1)
+eDVBServiceRecord::eDVBServiceRecord(const eServiceReferenceDVB &ref): m_ref(ref)
 {
        CONNECT(m_service_handler.serviceEvent, eDVBServiceRecord::serviceEvent);
        m_state = stateIdle;
        m_want_record = 0;
+       m_tuned = 0;
 }
 
 void eDVBServiceRecord::serviceEvent(int event)
@@ -20,33 +21,9 @@ void eDVBServiceRecord::serviceEvent(int event)
        case eDVBServicePMTHandler::eventTuned:
        {
                eDebug("tuned..");
-               if (!m_record)
-               {
-                       eDebug("Recording to %s...", m_filename.c_str());
-                       ::remove(m_filename.c_str());
-                       int fd = ::open(m_filename.c_str(), O_WRONLY|O_CREAT|O_LARGEFILE, 0644);
-                       if (fd == -1)
-                       {
-                               eDebug("eDVBServiceRecord - can't open hardcoded recording file!");
-                               return;
-//                             return -1;
-                       }
-                       ePtr<iDVBDemux> demux;
-                       if (m_service_handler.getDemux(demux))
-                       {
-                               eDebug("eDVBServiceRecord - NO DEMUX available!");
-                               return;
-//                             return -2;
-                       }
-                       demux->createTSRecorder(m_record);
-                       if (!m_record)
-                       {
-                               eDebug("eDVBServiceRecord - no ts recorder available.");
-                               return;
-//                             return -3;
-                       }
-                       m_record->setTargetFD(fd);
-               }
+               m_tuned = 1;
+               if (m_state == stateRecording && m_want_record)
+                       doRecord();
                break;
        }
        case eDVBServicePMTHandler::eventNewProgramInfo:
@@ -60,7 +37,6 @@ void eDVBServiceRecord::serviceEvent(int event)
        }
 }
 
-
 RESULT eDVBServiceRecord::prepare(const char *filename)
 {
        m_filename = filename;
@@ -83,7 +59,8 @@ RESULT eDVBServiceRecord::stop()
        eDebug("stop recording!!");
        if (m_state == stateRecording)
        {
-               m_record->stop();
+               if (m_record)
+                       m_record->stop();
                m_state = statePrepared;
        }
        
@@ -103,7 +80,7 @@ int eDVBServiceRecord::doPrepare()
        {
                m_pids_active.clear();
                m_state = statePrepared;
-               return m_service_handler.tune(m_ref);
+               return m_service_handler.tune(m_ref, 0);
        }
        return 0;
 }
@@ -114,10 +91,33 @@ int eDVBServiceRecord::doRecord()
        if (err)
                return err;
        
-       if (!m_record)
+       if (!m_tuned)
+               return 0; /* try it again when we are tuned in */
+       
+       if (!m_record && m_tuned)
        {
-               eDebug("demux not available (tune failed?). cannot record.");
-               return -1;
+
+               eDebug("Recording to %s...", m_filename.c_str());
+               ::remove(m_filename.c_str());
+               int fd = ::open(m_filename.c_str(), O_WRONLY|O_CREAT|O_LARGEFILE, 0644);
+               if (fd == -1)
+               {
+                       eDebug("eDVBServiceRecord - can't open hardcoded recording file!");
+                       return -1;
+               }
+               ePtr<iDVBDemux> demux;
+               if (m_service_handler.getDataDemux(demux))
+               {
+                       eDebug("eDVBServiceRecord - NO DEMUX available!");
+                       return -2;
+               }
+               demux->createTSRecorder(m_record);
+               if (!m_record)
+               {
+                       eDebug("eDVBServiceRecord - no ts recorder available.");
+                       return -3;
+               }
+               m_record->setTargetFD(fd);
        }
        eDebug("starting recording..");
        
@@ -191,6 +191,8 @@ int eDVBServiceRecord::doRecord()
                        m_record->removePID(*i);
                }
                
+               m_pids_active = pids_to_record;
+               
                if (m_state != stateRecording)
                {
                        m_record->start();
index 7d5a4fb3f7ebe7b8f3e8297d410424b8aef59c81..7f08c55486c66a314a142461d504f959335b5061 100644 (file)
@@ -29,7 +29,7 @@ private:
        
        ePtr<iDVBTSRecorder> m_record;
        
-       int m_recording;
+       int m_recording, m_tuned;
        std::set<int> m_pids_active;
        std::string m_filename;