remove unneeded caching of caids, use an array for pidcache instead of std::map ...
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sun, 14 May 2006 12:23:23 +0000 (12:23 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Sun, 14 May 2006 12:23:23 +0000 (12:23 +0000)
prepare for different video stream types.. (H264) ( NOT for dm7025 )

lib/dvb/db.cpp
lib/dvb/decoder.cpp
lib/dvb/decoder.h
lib/dvb/idvb.h
lib/dvb/pmt.cpp
lib/dvb/pmt.h
lib/dvb/scan.cpp
lib/service/servicedvb.cpp

index 22b6267..64ef6ed 100644 (file)
@@ -116,20 +116,29 @@ RESULT eBouquet::setListName(const std::string &name)
 eDVBService::eDVBService()
        :m_flags(0)
 {
+       memset(m_cache, -1, sizeof(m_cache));
 }
 
 eDVBService::~eDVBService()
 {
 }
 
+bool eDVBService::cacheEmpty()
+{
+       for (int i=0; i < cacheMax; ++i)
+               if (m_cache[i] != -1)
+                       return false;
+       return true;
+}
+
 eDVBService &eDVBService::operator=(const eDVBService &s)
 {
        m_service_name = s.m_service_name;
        m_service_name_sort = s.m_service_name_sort;
        m_provider_name = s.m_provider_name;
        m_flags = s.m_flags;
-       m_ca = s.m_ca;
-       m_cache = s.m_cache;
+//     m_ca = s.m_ca;
+       memcpy(m_cache, s.m_cache, sizeof(m_cache));
        return *this;
 }
 
@@ -225,17 +234,14 @@ int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQ
 
 int eDVBService::getCachePID(cacheID id)
 {
-       std::map<int, int>::iterator it = m_cache.find(id);
-       if ( it != m_cache.end() )
-               return it->second;
-       return -1;
+       if (id >= cacheMax)
+               return -1;
+       return m_cache[id];
 }
 
 void eDVBService::setCachePID(cacheID id, int pid)
 {
-       if (pid == -1)
-               m_cache.erase(id);
-       else
+       if (id < cacheMax)
                m_cache[id] = pid;
 }
 
@@ -421,12 +427,12 @@ void eDVBDB::reloadServicelist()
                                        int cid, val;
                                        sscanf(v.c_str(), "%02d%04x", &cid, &val);
                                        s->m_cache[cid]=val;
-                               } else if (p == 'C')
+                               }/* else if (p == 'C')
                                {
                                        int val;
                                        sscanf(v.c_str(), "%04x", &val);
                                        s->m_ca.insert(val);
-                               }
+                               }*/
                        }
                addService(ref, s);
        }
@@ -510,14 +516,16 @@ void eDVBDB::saveServicelist()
                fprintf(f, "p:%s", i->second->m_provider_name.c_str());
 
                // write cached pids
-               for (std::map<int,int>::const_iterator ca(i->second->m_cache.begin());
-                       ca != i->second->m_cache.end(); ++ca)
-                       fprintf(f, ",c:%02d%04x", ca->first, ca->second);
+               for (int x=0; x < eDVBService::cacheMax; ++x)
+                       if (i->second->m_cache[x] != -1)
+                               fprintf(f, ",c:%02d%04x", x, i->second->m_cache[x]);
 
+/*
                // write cached ca pids
                for (std::set<int>::const_iterator ca(i->second->m_ca.begin());
                        ca != i->second->m_ca.end(); ++ca)
                        fprintf(f, ",C:%04x", *ca);
+*/
 
                if (i->second->m_flags)
                        fprintf(f, ",f:%x", i->second->m_flags);
index a6537e8..1bec997 100644 (file)
@@ -175,13 +175,21 @@ eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
                eWarning("%s: %m", filename);
        eDebug("demux device: %s", filename);
 }
-       
-int eDVBVideo::startPid(int pid)
+
+// not finally values i think.. !!
+#define VIDEO_STREAMTYPE_MPEG2 0
+#define VIDEO_STREAMTYPE_MPEG4_H264 1
+
+int eDVBVideo::startPid(int pid, int type)
 {      
        if ((m_fd < 0) || (m_fd_demux < 0))
                return -1;
        dmx_pes_filter_params pes;
 
+       if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE,
+               type == MPEG4_H264 ? VIDEO_STREAMTYPE_MPEG4_H264 : VIDEO_STREAMTYPE_MPEG2) < 0)
+               eWarning("video: VIDEO_SET_STREAMTYPE: %m");
+
        pes.pid      = pid;
        pes.input    = DMX_IN_FRONTEND;
        pes.output   = DMX_OUT_DECODER;
@@ -465,7 +473,7 @@ int eTSMPEGDecoder::setState()
                {
                        eDebug("new video");
                        m_video = new eDVBVideo(m_demux, m_decoder);
-                       if (m_video->startPid(m_vpid))
+                       if (m_video->startPid(m_vpid, m_vtype))
                        {
                                eWarning("video: startpid failed!");
                                res = -1;
@@ -522,12 +530,13 @@ eTSMPEGDecoder::~eTSMPEGDecoder()
        setState();
 }
 
-RESULT eTSMPEGDecoder::setVideoPID(int vpid)
+RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
 {
        if (m_vpid != vpid)
        {
                m_changed |= changeVideo;
                m_vpid = vpid;
+               m_vtype = type;
        }
        return 0;
 }
index bceca04..834499b 100644 (file)
@@ -11,7 +11,7 @@ private:
        ePtr<eDVBDemux> m_demux;
        int m_fd, m_fd_demux, m_dev;
 public:
-       enum {aMPEG, aAC3, aDTS };
+       enum { aMPEG, aAC3, aDTS, aAAC };
        eDVBAudio(eDVBDemux *demux, int dev);
        int startPid(int pid, int type);
        void stop();
@@ -35,8 +35,9 @@ private:
        
        int m_is_slow_motion, m_is_fast_forward;
 public:
+       enum { MPEG2, MPEG4_H264 };
        eDVBVideo(eDVBDemux *demux, int dev);
-       int startPid(int pid);
+       int startPid(int pid, int type);
        void stop();
 #if HAVE_DVB_API_VERSION < 3
        void start();
@@ -86,7 +87,7 @@ private:
        ePtr<eDVBVideo> m_video;
        ePtr<eDVBPCR> m_pcr;
        ePtr<eDVBTText> m_text;
-       int m_vpid, m_apid, m_atype, m_pcrpid, m_textpid;
+       int m_vpid, m_vtype, m_apid, m_atype, m_pcrpid, m_textpid;
        enum
        {
                changeVideo = 1, 
@@ -104,7 +105,7 @@ public:
        enum { pidNone = -1 };
        eTSMPEGDecoder(eDVBDemux *demux, int decoder);
        virtual ~eTSMPEGDecoder();
-       RESULT setVideoPID(int vpid);
+       RESULT setVideoPID(int vpid, int type);
        RESULT setAudioPID(int apid, int type);
        RESULT setSyncPCR(int pcrpid);
        RESULT setTextPID(int textpid);
index 0608042..ecf8bb9 100644 (file)
@@ -223,12 +223,13 @@ class eDVBService: public iStaticServiceInformation
 public:
        enum cacheID
        {
-               cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cacheMax
+               cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cVTYPE, cacheMax
        };
 
        int getCachePID(cacheID);
        void setCachePID(cacheID, int);
-       bool cacheEmpty() { return m_cache.empty(); }
+
+       bool cacheEmpty();
 
        eDVBService();
                /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
@@ -249,8 +250,9 @@ public:
 
        bool usePMT() const { return !(m_flags & dxNoDVB); }
 
-       std::set<int> m_ca;
-       std::map<int,int> m_cache;
+//     std::set<int> m_ca;
+
+       int m_cache[cacheMax];
        virtual ~eDVBService();
        
        eDVBService &operator=(const eDVBService &);
@@ -572,8 +574,8 @@ class iTSMPEGDecoder: public iObject
 {
 public:
        enum { pidDisabled = -1 };
-               /** Set Displayed Video PID */
-       virtual RESULT setVideoPID(int vpid)=0;
+               /** Set Displayed Video PID and type */
+       virtual RESULT setVideoPID(int vpid, int type)=0;
 
        enum { af_MPEG, af_AC3, af_DTS };
                /** Set Displayed Audio PID and type */
index 4af1802..11cda12 100644 (file)
@@ -250,9 +250,12 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
 
                                video.pid = (*es)->getPid();
                                audio.pid = (*es)->getPid();
+                               video.type = videoStream::vtMPEG2;
 
                                switch ((*es)->getType())
                                {
+                               case 0x1b: // AVC Video Stream (MPEG4 H264)
+                                       video.type = videoStream::vtMPEG4_H264;
                                case 0x01: // MPEG 1 video
                                case 0x02: // MPEG 2 video
                                        isvideo = 1;
@@ -277,6 +280,13 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                        if ( program.textPid == -1 || (*es)->getPid() == cached_tpid )
                                                                program.textPid = (*es)->getPid();
                                                        break;
+                                               case DTS_DESCRIPTOR:
+                                                       if (!isvideo)
+                                                       {
+                                                               isaudio = 1;
+                                                               audio.type = audioStream::atDTS;
+                                                       }
+                                                       break;
                                                case AC3_DESCRIPTOR:
                                                        if (!isvideo)
                                                        {
@@ -354,11 +364,15 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                        apid_mpeg = m_service->getCachePID(eDVBService::cAPID),
                        pcrpid = m_service->getCachePID(eDVBService::cPCRPID),
                        tpid = m_service->getCachePID(eDVBService::cTPID),
+                       vpidtype = m_service->getCachePID(eDVBService::cVTYPE),
                        cnt=0;
+               if ( vpidtype == -1 )
+                       vpidtype = videoStream::vtMPEG2;
                if ( vpid != -1 )
                {
                        videoStream s;
                        s.pid = vpid;
+                       s.type = vpidtype;
                        program.videoStreams.push_back(s);
                        ++cnt;
                }
index 6a5b00d..b6a3743 100644 (file)
@@ -99,12 +99,14 @@ public:
        {
                int pid;
                int component_tag;
+               enum { vtMPEG2, vtMPEG4_H264 };
+               int type;
        };
        
        struct audioStream
        {
                int pid;
-               enum { atMPEG, atAC3, atDTS };
+               enum { atMPEG, atAC3, atDTS, atAAC };
                int type; // mpeg2, ac3, dts, ...
                
                int component_tag;
index ade63d8..3bfbe57 100644 (file)
@@ -580,6 +580,7 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription
                                SCAN_eDebug("name '%s', provider_name '%s'", service->m_service_name.c_str(), service->m_provider_name.c_str());
                                break;
                        }
+/*
                        case CA_IDENTIFIER_DESCRIPTOR:
                        {
                                CaIdentifierDescriptor &d = (CaIdentifierDescriptor&)**desc;
@@ -593,6 +594,7 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription
                                SCAN_eDebug("");
                                break;
                        }
+*/
                        default:
                                SCAN_eDebug("descr<%x>", (*desc)->getTag());
                                break;
index 192d3a6..742d60e 100644 (file)
@@ -1559,7 +1559,7 @@ void eDVBServicePlay::switchToTimeshift()
 
 void eDVBServicePlay::updateDecoder()
 {
-       int vpid = -1, apid = -1, apidtype = -1, pcrpid = -1, tpid = -1;
+       int vpid = -1, vpidtype = -1, apid = -1, apidtype = -1, pcrpid = -1, tpid = -1;
        eDVBServicePMTHandler &h = m_timeshift_active ? m_service_handler_timeshift : m_service_handler;
 
        bool defaultac3=false;
@@ -1582,7 +1582,10 @@ void eDVBServicePlay::updateDecoder()
                                i != program.videoStreams.end(); ++i)
                        {
                                if (vpid == -1)
+                               {
                                        vpid = i->pid;
+                                       vpidtype = i->type;
+                               }
                                if (i != program.videoStreams.begin())
                                        eDebugNoNewLine(", ");
                                eDebugNoNewLine("%04x", i->pid);
@@ -1631,7 +1634,7 @@ void eDVBServicePlay::updateDecoder()
 
        if (m_decoder)
        {
-               m_decoder->setVideoPID(vpid);
+               m_decoder->setVideoPID(vpid, vpidtype);
                m_current_audio_stream = 0;
                m_decoder->setAudioPID(apid, apidtype);
                if (!(m_is_pvr || m_timeshift_active || !m_is_primary))
@@ -1666,6 +1669,7 @@ void eDVBServicePlay::updateDecoder()
                                m_dvb_service->setCachePID(eDVBService::cAC3PID, apid);
                        }
                        m_dvb_service->setCachePID(eDVBService::cVPID, vpid);
+                       m_dvb_service->setCachePID(eDVBService::cVTYPE, vpidtype);
                        m_dvb_service->setCachePID(eDVBService::cPCRPID, pcrpid);
                        m_dvb_service->setCachePID(eDVBService::cTPID, tpid);
                }