fix standby
[enigma2.git] / lib / service / servicedvb.cpp
index a29b77ce74d160dbb93e82c559a78e5ef8524e46..b1c18a1d719360311ad8b1ac591e2f68d62c6426 100644 (file)
 #include <lib/dvb/metaparser.h>
 #include <lib/dvb/tstools.h>
 
+class eStaticServiceDVBInformation: public iStaticServiceInformation
+{
+       DECLARE_REF(eStaticServiceDVBInformation);
+public:
+       RESULT getName(const eServiceReference &ref, std::string &name);
+       int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBInformation);
+
+RESULT eStaticServiceDVBInformation::getName(const eServiceReference &ref, std::string &name)
+{
+       if ( ref.name.length() )
+       {
+               name = ref.name;
+               return 0;
+       }
+       else
+               return -1;
+}
+
+int eStaticServiceDVBInformation::getLength(const eServiceReference &ref)
+{
+       return -1;
+}
+
+class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
+{
+       DECLARE_REF(eStaticServiceDVBBouquetInformation);
+public:
+       RESULT getName(const eServiceReference &ref, std::string &name);
+       int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBBouquetInformation);
+
+RESULT eStaticServiceDVBBouquetInformation::getName(const eServiceReference &ref, std::string &name)
+{
+       ePtr<iDVBChannelList> db;
+       ePtr<eDVBResourceManager> res;
+
+       int err;
+       if ((err = eDVBResourceManager::getInstance(res)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no resource manager!");
+               return err;
+       }
+       if ((err = res->getChannelList(db)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no channel list!");
+               return err;
+       }
+
+       eBouquet *bouquet=0;
+       if ((err = db->getBouquet(ref, bouquet)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. getBouquet failed!");
+               return -1;
+       }
+
+       if ( bouquet && bouquet->m_bouquet_name.length() )
+       {
+               name = "[Bouquet] " + bouquet->m_bouquet_name;
+               return 0;
+       }
+       else
+               return -1;
+}
+
+int eStaticServiceDVBBouquetInformation::getLength(const eServiceReference &ref)
+{
+       return -1;
+}
+
 class eStaticServiceDVBPVRInformation: public iStaticServiceInformation
 {
        DECLARE_REF(eStaticServiceDVBPVRInformation);
@@ -99,11 +173,10 @@ RESULT eDVBPVRServiceOfflineOperations::getListOfFilenames(std::list<std::string
 {
        res.clear();
        res.push_back(m_ref.path);
+       res.push_back(m_ref.path + ".meta");
        return 0;
 }
 
-
-
 DEFINE_REF(eServiceFactoryDVB)
 
 eServiceFactoryDVB::eServiceFactoryDVB()
@@ -153,7 +226,7 @@ RESULT eDVBServiceList::startQuery()
        
        ePtr<eDVBChannelQuery> q;
        
-       if (m_parent.path.size())
+       if (!m_parent.path.empty())
        {
                eDVBChannelQuery::compile(q, m_parent.path);
                if (!q)
@@ -163,7 +236,7 @@ RESULT eDVBServiceList::startQuery()
                }
        }
        
-       if ((err = db->startQuery(m_query, q)) != 0)
+       if ((err = db->startQuery(m_query, q, m_parent)) != 0)
        {
                eDebug("startQuery failed");
                return err;
@@ -197,6 +270,48 @@ int eDVBServiceList::compareLessEqual(const eServiceReference &a, const eService
        return m_query->compareLessEqual((const eServiceReferenceDVB&)a, (const eServiceReferenceDVB&)b);
 }
 
+RESULT eDVBServiceList::startEdit(ePtr<iMutableServiceList> &res)
+{
+       if (m_parent.flags & eServiceReference::flagDirectory) // bouquet
+       {
+               ePtr<iDVBChannelList> db;
+               ePtr<eDVBResourceManager> resm;
+
+               if (eDVBResourceManager::getInstance(resm) || resm->getChannelList(db))
+                       return -1;
+
+               if (db->getBouquet(m_parent, m_bouquet) != 0)
+                       return -1;
+
+               res = this;
+               
+               return 0;
+       }
+       res = 0;
+       return -1;
+}
+
+RESULT eDVBServiceList::addService(eServiceReference &ref)
+{
+       if (!m_bouquet)
+               return -1;
+       return m_bouquet->addService(ref);
+}
+
+RESULT eDVBServiceList::removeService(eServiceReference &ref)
+{
+       if (!m_bouquet)
+               return -1;
+       return m_bouquet->removeService(ref);
+}
+
+RESULT eDVBServiceList::moveService(eServiceReference &ref, int pos)
+{
+       if (!m_bouquet)
+               return -1;
+       return m_bouquet->moveService(ref, pos);
+}
+
 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
 {
        ePtr<eDVBService> service;
@@ -210,8 +325,15 @@ RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableServ
 
 RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
 {
-       ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
-       return 0;
+       if (ref.path.empty())
+       {
+               ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
+               return 0;
+       } else
+       {
+               ptr = 0;
+               return -1;
+       }
 }
 
 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
@@ -230,26 +352,40 @@ RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableServ
 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
 {
                /* do we have a PVR service? */
-       if (ref.path.size())
+       if (ref.flags & eServiceReference::flagDirectory) // bouquet
+       {
+               ptr = new eStaticServiceDVBBouquetInformation;
+               return 0;
+       }
+       else if (!ref.path.empty())
        {
                ptr = new eStaticServiceDVBPVRInformation(ref);
                return 0;
-       } else
+       }
+       else
        {
                ePtr<eDVBService> service;
                int r = lookupService(service, ref);
                if (r)
-                       return r;
+                       ptr = new eStaticServiceDVBInformation;
+               else
                        /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
-               ptr = service;
+                       ptr = service;
                return 0;
        }
 }
 
-RESULT eServiceFactoryDVB::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
+RESULT eServiceFactoryDVB::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
 {
-       ptr = 0;
-       return -1;
+       if (ref.path.empty())
+       {
+               ptr = 0;
+               return -1;
+       } else
+       {
+               ptr = new eDVBPVRServiceOfflineOperations(ref);
+               return 0;
+       }
 }
 
 RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServiceReference &ref)
@@ -284,18 +420,16 @@ RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServ
 }
 
 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *service): 
-       m_reference(ref), m_dvb_service(service)
+       m_reference(ref), m_dvb_service(service), m_service_handler(0), m_is_paused(0)
 {
        m_is_pvr = !ref.path.empty();
        
        CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
        CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
-       eDebug("DVB start (play)");
 }
 
 eDVBServicePlay::~eDVBServicePlay()
 {
-       eDebug("DVB stop (play)");
 }
 
 void eDVBServicePlay::gotNewEvent()
@@ -316,7 +450,6 @@ void eDVBServicePlay::gotNewEvent()
 
 void eDVBServicePlay::serviceEvent(int event)
 {
-       eDebug("service event %d", event);
        switch (event)
        {
        case eDVBServicePMTHandler::eventTuned:
@@ -326,11 +459,16 @@ void eDVBServicePlay::serviceEvent(int event)
                {
 //                     eventStartedEventAcquisition
                        m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
-               } else
-                       eDebug("no event data available :( ");
+               }
 //                     eventNoEvent
                break;
        }
+       case eDVBServicePMTHandler::eventTuneFailed:
+       {
+               eDebug("DVB service failed to tune");
+               m_event((iPlayableService*)this, evTuneFailed);
+               break;
+       }
        case eDVBServicePMTHandler::eventNewProgramInfo:
        {
                int vpid = -1, apid = -1, pcrpid = -1;
@@ -416,6 +554,7 @@ RESULT eDVBServicePlay::start()
        int r;
        eDebug("starting DVB service");
        r = m_service_handler.tune((eServiceReferenceDVB&)m_reference);
+       eDebug("tune result: %d", r);
        m_event(this, evStart);
        return 0;
 }
@@ -434,7 +573,12 @@ RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &ev
 
 RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr)
 {
-               // not yet possible, maybe later...
+       if (m_is_pvr)
+       {
+               ptr = this;
+               return 0;
+       }
+
        ptr = 0;
        return -1;
 }
@@ -464,11 +608,43 @@ RESULT eDVBServicePlay::getLength(pts_t &len)
        return pvr_channel->getLength(len);
 }
 
+RESULT eDVBServicePlay::pause()
+{
+       if (!m_is_paused && m_decoder)
+       {
+               m_is_paused = 1;
+               return m_decoder->freeze(0);
+       } else
+               return -1;
+}
+
+RESULT eDVBServicePlay::unpause()
+{
+       if (m_is_paused && m_decoder)
+       {
+               m_is_paused = 0;
+               return m_decoder->unfreeze();
+       } else
+               return -1;
+}
+
 RESULT eDVBServicePlay::seekTo(pts_t to)
 {
        return -1;
 }
 
+RESULT eDVBServicePlay::seekRelative(int direction, pts_t to)
+{
+       eDebug("eDVBServicePlay::seekRelative: jump %d, %lld", direction, to);
+
+       ePtr<iDVBPVRChannel> pvr_channel;
+       
+       if (m_service_handler.getPVRChannel(pvr_channel))
+               return -1;
+       
+       return pvr_channel->seekToPosition(SEEK_CUR, to);
+}
+
 RESULT eDVBServicePlay::getPlayPosition(pts_t &pos)
 {
        ePtr<iDVBPVRChannel> pvr_channel;