Remove check legacy dvbapi version.
[vuplus_dvbapp] / lib / dvb / dvb.cpp
index bc79306..852c403 100644 (file)
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <fstream>
 
 DEFINE_REF(eDVBRegisteredFrontend);
 DEFINE_REF(eDVBRegisteredDemux);
@@ -93,6 +94,8 @@ eDVBResourceManager::eDVBResourceManager()
                num_adapter++;
        }
 
+       setUsbTuner();
+
        int fd = open("/proc/stb/info/model", O_RDONLY);
        char tmp[255];
        int rd = fd >= 0 ? read(fd, tmp, 255) : 0;
@@ -151,11 +154,7 @@ eDVBAdapterLinux::eDVBAdapterLinux(int nr): m_nr(nr)
        {
                struct stat s;
                char filename[128];
-#if HAVE_DVB_API_VERSION < 3
-               sprintf(filename, "/dev/dvb/card%d/frontend%d", m_nr, num_fe);
-#else
                sprintf(filename, "/dev/dvb/adapter%d/frontend%d", m_nr, num_fe);
-#endif
                if (stat(filename, &s))
                        break;
                eDVBFrontend *fe;
@@ -182,11 +181,7 @@ eDVBAdapterLinux::eDVBAdapterLinux(int nr): m_nr(nr)
        {
                struct stat s;
                char filename[128];
-#if HAVE_DVB_API_VERSION < 3
-               sprintf(filename, "/dev/dvb/card%d/demux%d", m_nr, num_demux);
-#else
                sprintf(filename, "/dev/dvb/adapter%d/demux%d", m_nr, num_demux);
-#endif
                if (stat(filename, &s))
                        break;
                ePtr<eDVBDemux> demux;
@@ -246,11 +241,7 @@ int eDVBAdapterLinux::exist(int nr)
 {
        struct stat s;
        char filename[128];
-#if HAVE_DVB_API_VERSION < 3
-       sprintf(filename, "/dev/dvb/card%d", nr);
-#else
        sprintf(filename, "/dev/dvb/adapter%d", nr);
-#endif
        if (!stat(filename, &s))
                return 1;
        return 0;
@@ -325,6 +316,59 @@ void eDVBResourceManager::addAdapter(iDVBAdapter *adapter)
 
 }
 
+void eDVBResourceManager::setUsbTuner()
+{
+       std::ifstream in("/proc/bus/nim_sockets");
+       std::string line;
+
+       int res = -1;
+       int fe_idx = -1;
+       int usbtuner_idx[8] = {0};
+       int usbtuner_count = 0;
+
+       if (in.is_open())
+       {
+               while(!in.eof())
+               {
+                       getline(in, line);
+                       if ((res = sscanf(line.c_str(), "NIM Socket %d:", &fe_idx)) == 1)
+                               continue;
+
+                       if ((fe_idx != -1) && (line.find("\tName: ") == 0) && (line.find("VTUNER") != -1))
+                               usbtuner_idx[usbtuner_count++] = fe_idx;
+               }
+               in.close();
+       }
+
+       if (usbtuner_count)
+       {
+               for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_frontend.begin()); it != m_frontend.end(); ++it)
+               {
+                       int slotid = it->m_frontend->getSlotID();
+                       for (int i=0; i < usbtuner_count ; i++)
+                       {
+                               if (slotid == usbtuner_idx[i])
+                               {
+                                       it->m_frontend->setUSBTuner(true);
+                                       break;
+                               }
+                       }
+               }
+               for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_simulate_frontend.begin()); it != m_simulate_frontend.end(); ++it)
+               {
+                       int slotid = it->m_frontend->getSlotID();
+                       for (int i=0; i < usbtuner_count ; i++)
+                       {
+                               if (slotid == usbtuner_idx[i])
+                               {
+                                       it->m_frontend->setUSBTuner(true);
+                                       break;
+                               }
+                       }
+               }
+       }
+}
+
 PyObject *eDVBResourceManager::setFrontendSlotInformations(ePyObject list)
 {
        if (!PyList_Check(list))
@@ -388,7 +432,7 @@ bool eDVBResourceManager::frontendIsCompatible(int index, const char *type)
                        }
                        else if (!strcmp(type, "DVB-C"))
                        {
-#if DVB_API_VERSION > 5 || DVB_API_VERSION == 5 && DVB_API_VERSION_MINOR >= 6
+#if defined SYS_DVBC_ANNEX_A
                                return i->m_frontend->supportsDeliverySystem(SYS_DVBC_ANNEX_A, false);
 #else
                                return i->m_frontend->supportsDeliverySystem(SYS_DVBC_ANNEX_AC, false);
@@ -420,7 +464,7 @@ void eDVBResourceManager::setFrontendType(int index, const char *type)
                        }
                        else if (!strcmp(type, "DVB-C"))
                        {
-#if DVB_API_VERSION > 5 || DVB_API_VERSION == 5 && DVB_API_VERSION_MINOR >= 6
+#if defined SYS_DVBC_ANNEX_A
                                whitelist.push_back(SYS_DVBC_ANNEX_A);
 #else
                                whitelist.push_back(SYS_DVBC_ANNEX_AC);
@@ -2044,14 +2088,6 @@ RESULT eDVBChannel::playSource(ePtr<iTsSource> &source, const char *streaminfo_f
        if (m_pvr_fd_dst < 0)
        {
                /* (this codepath needs to be improved anyway.) */
-#if HAVE_DVB_API_VERSION < 3
-               m_pvr_fd_dst = open("/dev/pvr", O_WRONLY);
-               if (m_pvr_fd_dst < 0)
-               {
-                       eDebug("can't open /dev/pvr - you need to buy the new(!) $$$ box! (%m)"); // or wait for the driver to be improved.
-                       return -ENODEV;
-               }
-#else
                ePtr<eDVBAllocatedDemux> &demux = m_demux ? m_demux : m_decoder_demux;
                if (demux)
                {
@@ -2067,7 +2103,6 @@ RESULT eDVBChannel::playSource(ePtr<iTsSource> &source, const char *streaminfo_f
                        eDebug("no demux allocated yet.. so its not possible to open the dvr device!!");
                        return -ENODEV;
                }
-#endif
        }
 
        m_pvr_thread = new eDVBChannelFilePush();