add possibility to playback ts files without entry in recordings.epl or without meta...
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 6 Mar 2006 11:30:48 +0000 (11:30 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 6 Mar 2006 11:30:48 +0000 (11:30 +0000)
or with a incorrect servicereference (this just work when the TS file includes a PAT and a PMT)

lib/dvb/metaparser.cpp
lib/dvb/pmt.cpp

index 6fbc56d140e3001b03f6dd9693d3374fc56b2d02..aadc0bc839d8e8e8db086413d3407481604a309a 100644 (file)
@@ -75,14 +75,14 @@ int eDVBMetaParser::parseRecordings(const std::string &filename)
        FILE *f = fopen(recordings.c_str(), "r");
        if (!f)
        {
-               eDebug("no recordings.epl found: %s: %m", recordings.c_str());
+//             eDebug("no recordings.epl found: %s: %m", recordings.c_str());
                return -1;
        }
        
        std::string description;
        eServiceReferenceDVB ref;
        
-       eDebug("parsing recordings.epl..");
+//     eDebug("parsing recordings.epl..");
        
        while (1)
        {
@@ -103,7 +103,7 @@ int eDVBMetaParser::parseRecordings(const std::string &filename)
 
                if ((line[0] == '/') && (ref.path == filename))
                {
-                       eDebug("hit!");
+//                     eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
                        m_ref = ref;
                        m_name = description;
                        m_description = "";
index d1644e7a36a5bd6b8a173080958efac587c5b7ee..4ce35394ac1facb74c1211c9c8873fb41798bda7 100644 (file)
@@ -122,6 +122,84 @@ void eDVBServicePMTHandler::PATready(int)
                                if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID())
                                        pmtpid = (*program)->getProgramMapPid();
                }
+               if (pmtpid == -1)
+               {
+                       if ( m_reference.path.find(".ts") != std::string::npos ) // recorded ts
+                       {
+                               // we try to find manual the correct sid
+                               int fd = open( m_reference.path.c_str(), O_RDONLY|O_LARGEFILE );
+                               if ( fd < 0 )
+                                       eDebug("open %s failed");
+                               else
+                               {
+                                       eDebug("parse ts file for find the correct pmtpid");
+                                       unsigned char *buf = new unsigned char[256*1024]; // 256 kbyte
+                                       int rd=0;
+                                       while ( pmtpid == -1 && (rd < 1024*1024*5) )
+                                       {
+#define MAX_PIDS 64
+                                               int pids[MAX_PIDS];
+                                               int pididx=-1;
+                                               int r = ::read( fd, buf, 256*1024 );
+                                               if ( r <= 0 )
+                                                       break;
+                                               rd+=r;
+                                               int cnt=0;
+                                               while(cnt < r)
+                                               {
+                                                       while ( (buf[cnt] != 0x47) && ((cnt+188) < r) && (buf[cnt+188] != 0x47) )
+                                                       {
+//                                                             eDebug("search sync byte %02x %02x, %d %d", buf[cnt], buf[cnt+188], cnt+188, r);
+                                                               cnt++;
+                                                       }
+                                                       if ( buf[cnt] == 0x47 )
+                                                       {
+                                                               int pid = ((buf[cnt+1]&0x3F) << 8) | buf[cnt+2];
+                                                               int idx=0;
+                                                               while(idx <= pididx)  // check if we already have this pid
+                                                               {
+                                                                       if ( pids[idx] == pid )
+                                                                               break;
+                                                                       ++idx;
+                                                               }
+                                                               if (idx > pididx && (pididx+1) < MAX_PIDS)
+                                                               {
+                                                                       eDebug("found pid %04x", pid);
+                                                                       pids[++pididx]=pid;
+                                                               }
+                                                               cnt+=188;
+                                                       }
+                                                       else
+                                                               break;
+                                               }
+                                               while(pididx > -1 && pmtpid == -1)
+                                               {
+                                                       for (i = ptr->getSections().begin(); i != ptr->getSections().end() && pmtpid == -1; ++i)
+                                                       {
+                                                               const ProgramAssociationSection &pat = **i;
+                                                               ProgramAssociationConstIterator program;
+                                                               for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program)
+                                                               {
+                                                                       int pid = (*program)->getProgramMapPid();
+                                                                       if ( pid == pids[pididx])
+                                                                       {
+                                                                               int sid = (*program)->getProgramNumber();
+                                                                               pmtpid = pid;
+                                                                               m_reference.setServiceID(eServiceID(sid));
+                                                                               eDebug("found pmt for service id %04x with pid %04x", sid, pid);
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       }       
+                                                       --pididx;
+                                               }
+                                       }
+                                       delete [] buf;
+                                       close(fd);
+                               }
+                       }
+               }
+               
                if (pmtpid == -1)
                        serviceEvent(eventNoPATEntry);
                else
@@ -385,7 +463,9 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux,
                        eWarning("no .meta file found, trying original service ref.");
                else
                        m_reference = parser.m_ref;
-               
+
+//             eDebug("try %s", m_reference.toString().c_str());
+
                eDebug("alloc PVR");
                        /* allocate PVR */
                res = m_resourceManager->allocatePVRChannel(m_pvr_channel);