Update EPG Cache(thanks to open source community)
[vuplus_dvbapp] / lib / service / servicemp3.cpp
old mode 100755 (executable)
new mode 100644 (file)
index b3281a9..fbc8811
@@ -6,6 +6,7 @@
 #include <lib/base/init.h>
 #include <lib/base/nconfig.h>
 #include <lib/base/object.h>
+#include <lib/dvb/epgcache.h>
 #include <lib/dvb/decoder.h>
 #include <lib/components/file_eraser.h>
 #include <lib/gui/esubtitle.h>
@@ -228,14 +229,28 @@ int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
        }
        return iServiceInformation::resNA;
 }
+
+RESULT eStaticServiceMP3Info::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
+{
+       if (ref.path.find("://") != std::string::npos)
+       {
+               eServiceReference equivalentref(ref);
+               equivalentref.type = eServiceFactoryMP3::id;
+               equivalentref.path.clear();
+               return eEPGCache::getInstance()->lookupEventTime(equivalentref, start_time, evt);
+       }
+       evt = 0;
+       return -1;
+}
 
 // eServiceMP3
 int eServiceMP3::ac3_delay,
     eServiceMP3::pcm_delay;
 
 eServiceMP3::eServiceMP3(eServiceReference ref)
-       :m_ref(ref), m_pump(eApp, 1)
+       :m_ref(ref),
+       m_pump(eApp, 1),
+       m_nownext_timer(eTimer::create(eApp))
 {
        m_subtitle_sync_timer = eTimer::create(eApp);
        m_streamingsrc_timeout = 0;
@@ -252,6 +267,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
        audioSink = videoSink = NULL;
        CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
        CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
+       CONNECT(m_nownext_timer->timeout, eServiceMP3::updateEpgCacheNowNext);
        m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
 
        m_state = stIdle;
@@ -462,6 +478,53 @@ eServiceMP3::~eServiceMP3()
        }
 }
 
+void eServiceMP3::updateEpgCacheNowNext()
+{
+       bool update = false;
+       ePtr<eServiceEvent> next = 0;
+       ePtr<eServiceEvent> ptr = 0;
+       eServiceReference ref(m_ref);
+       ref.type = eServiceFactoryMP3::id;
+       ref.path.clear();
+
+       if (eEPGCache::getInstance() && eEPGCache::getInstance()->lookupEventTime(ref, -1, ptr) >= 0)
+       {
+               ePtr<eServiceEvent> current = m_event_now;
+               if (!current || !ptr || current->getEventId() != ptr->getEventId())
+               {
+                       update = true;
+                       m_event_now = ptr;
+                       time_t next_time = ptr->getBeginTime() + ptr->getDuration();
+                       if (eEPGCache::getInstance()->lookupEventTime(ref, next_time, ptr) >= 0)
+                       {
+                               next = ptr;
+                               m_event_next = ptr;
+                       }
+               }
+       }
+
+       int refreshtime = 60;
+       if (!next)
+       {
+               next = m_event_next;
+       }
+       if (next)
+       {
+               time_t now = ::time(0);
+               refreshtime = (int)(next->getBeginTime() - now) + 3;
+               if (refreshtime <= 0 || refreshtime > 60)
+               {
+                       refreshtime = 60;
+               }
+       }
+
+       m_nownext_timer->startLongTimer(refreshtime);
+       if (update)
+       {
+               m_event((iPlayableService*)this, evUpdatedEventInfo);
+       }
+}
+
 DEFINE_REF(eServiceMP3);
 
 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
@@ -504,6 +567,7 @@ RESULT eServiceMP3::stop()
        //eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
        gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
        m_state = stStopped;
+       m_nownext_timer->stop();
 
        return 0;
 }
@@ -786,6 +850,14 @@ RESULT eServiceMP3::getName(std::string &name)
        return 0;
 }
 
+RESULT eServiceMP3::getEvent(ePtr<eServiceEvent> &evt, int nownext)
+{
+       evt = nownext ? m_event_next : m_event_now;
+       if (!evt)
+               return -1;
+       return 0;
+}
+
 int eServiceMP3::getInfo(int w)
 {
        const gchar *tag = 0;
@@ -888,6 +960,24 @@ int eServiceMP3::getInfo(int w)
 
 std::string eServiceMP3::getInfoString(int w)
 {
+       if ( m_sourceinfo.is_streaming )
+       {
+               switch (w)
+               {
+               case sProvider:
+                       return "IPTV";
+               case sServiceref:
+               {
+                       eServiceReference ref(m_ref);
+                       ref.type = eServiceFactoryMP3::id;
+                       ref.path.clear();
+                       return ref.toString();
+               }
+               default:
+                       break;
+               }
+       }
+
        if ( !m_stream_tags && w < sUser && w > 26 )
                return "";
        const gchar *tag = 0;
@@ -1373,6 +1463,8 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                                        setAC3Delay(ac3_delay);
                                        setPCMDelay(pcm_delay);
 
+                                       updateEpgCacheNowNext();
+
                                }       break;
                                case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
                                {