Ticket #1907: sr2.diff

File sr2.diff, 6.9 KB (added by mythdev@…, 14 years ago)
  • mythtv/libs/libmythtv/mpeg/mpegstreamdata.cpp

     
    655655}
    656656#undef DONE_WITH_PES_PACKET
    657657
     658/** \fn MPEGStreamData::HandlePESTables(const TSPacket*, const unsigned char* , const int)
     659 *  \brief handles complete SI table passed as buffer
     660 */
     661void MPEGStreamData::HandlePESTables(const TSPacket* tspkt, const unsigned char* buffer, const int len)
     662{
     663    PSIPTable *psip =  new PSIPTable(*tspkt, buffer, len);
     664    if (!psip)
     665       return;
     666
     667    // Validate PSIP
     668    // but don't validate PMT/PAT if our driver has the PMT/PAT CRC bug.
     669    bool buggy = _have_CRC_bug &&
     670        ((TableID::PMT == psip->TableID()) ||
     671         (TableID::PAT == psip->TableID()));
     672    if (!buggy && !psip->IsGood())
     673    {
     674        VERBOSE(VB_RECORD, QString("HandlePESTable packet failed CRC check. "
     675                                   "pid(0x%1) type(0x%2)")
     676                .arg(tspkt->PID(),0,16).arg(psip->TableID(),0,16));
     677        delete psip;
     678        return;
     679    }
     680
     681    if (!psip->IsCurrent()) // we don't cache the next table, for now
     682    {
     683        delete psip;
     684        return;
     685    }
     686
     687    // Don't decode redundant packets,
     688    // but if it is a desired PAT or PMT emit a "heartbeat" signal.
     689    if (IsRedundant(tspkt->PID(), *psip))
     690    {
     691        if (TableID::PAT == psip->TableID())
     692        {
     693            QMutexLocker locker(&_listener_lock);
     694            ProgramAssociationTable *pat_sp = PATSingleProgram();
     695            for (uint i = 0; i < _mpeg_sp_listeners.size(); i++)
     696                _mpeg_sp_listeners[i]->HandleSingleProgramPAT(pat_sp);
     697        }
     698        if (TableID::PMT == psip->TableID() &&
     699            tspkt->PID() == _pid_pmt_single_program)
     700        {
     701            QMutexLocker locker(&_listener_lock);
     702            ProgramMapTable *pmt_sp = PMTSingleProgram();
     703            for (uint i = 0; i < _mpeg_sp_listeners.size(); i++)
     704                _mpeg_sp_listeners[i]->HandleSingleProgramPMT(pmt_sp);
     705        }
     706        delete psip;            // already parsed this table, toss it.
     707        return;
     708    }
     709    HandleTables(tspkt->PID(), *psip);
     710    if(psip) delete psip;
     711}
     712
    658713int MPEGStreamData::ProcessData(unsigned char *buffer, int len)
    659714{
    660715    int pos = 0;
  • mythtv/libs/libmythtv/mpeg/mpegtables.h

     
    282282        // section_syntax_ind   1       1.0       8   should always be 1
    283283        // private_indicator    1       1.1       9   should always be 1
    284284    }
     285    PSIPTable(const TSPacket &tspacket,
     286              const unsigned char *pesdata, uint pes_size)
     287             : PESPacket( tspacket, pesdata, pes_size )
     288    {
     289    }
    285290
    286291
    287292    static const PSIPTable View(const TSPacket& tspacket)
  • mythtv/libs/libmythtv/mpeg/mpegstreamdata.h

     
    6262    virtual bool IsRedundant(uint pid, const PSIPTable&) const;
    6363    virtual bool HandleTables(uint pid, const PSIPTable &psip);
    6464    virtual void HandleTSTables(const TSPacket* tspacket);
     65    virtual void HandlePESTables(const TSPacket* tspacket,
     66                                 const unsigned char* buffer, const int len);
    6567    virtual bool ProcessTSPacket(const TSPacket& tspacket);
    6668    virtual int  ProcessData(unsigned char *buffer, int len);
    6769    inline  void HandleAdaptationFieldControl(const TSPacket* tspacket);
  • mythtv/libs/libmythtv/mpeg/pespacket.h

     
    114114        _fullbuffer = pes_alloc(_allocSize);
    115115        _pesdata    = _fullbuffer + _psiOffset + 1;
    116116        memcpy(_fullbuffer, tspacket.data(), 188);
    117         memcpy(_pesdata, pesdata, pes_size-1);
     117        memcpy(_pesdata, pesdata, pes_size);
     118        _badPacket = !VerifyCRC();
    118119    }
    119120
    120121    virtual ~PESPacket()
  • mythtv/libs/libmythtv/dvbsignalmonitor.cpp

     
    380380 */
    381381void DVBSignalMonitor::RunTableMonitorSR(void)
    382382{
    383     int remainder   = 0;
     383    TSPacket *tspkt = new TSPacket(); // Header only is not possible
     384    if (!tspkt) return;
     385
    384386    int buffer_size = 4192;  // maximum size of Section we handle
    385     int header_size = 5;     // TSPacket::HEADER_SIZE + 1 for data pointer
    386     unsigned char *buffer = new unsigned char[header_size + buffer_size];
     387    unsigned char *buffer = new unsigned char[buffer_size];
    387388    if (!buffer)
     389    {
     390        delete tspkt;
    388391        return;
     392    }
    389393
    390     // "Constant" parts of stream header
    391     buffer[0] = SYNC_BYTE;
    392     buffer[3] = 0x10;   // Adaptation = 01 Scrambled = 00
    393     buffer[4] = 0x00;   // Pointer to data in buffer
     394    tspkt->SetPayloadStart(true);
     395    tspkt->SetScrambled(0);
     396    tspkt->SetAdaptationFieldControl(0x01);
     397    tspkt->SetContinuityCounter(0);
     398    tspkt->SetStartOfFieldPointer(0);
    394399
    395400    VERBOSE(VB_CHANNEL, LOC + "RunTableMonitorSR(): " +
    396401            QString("begin (# of pids %1)")
     
    406411        for (; fit != filters.end(); ++fit)
    407412        {
    408413            int mux_fd = fit.data();
    409             len = read(mux_fd, &(buffer[header_size]),
    410                        buffer_size - header_size);
    411 
     414            len = read(mux_fd, &buffer[0], buffer_size);
    412415            if (len <= 0)
    413416                continue;
    414417
    415418            readSomething = true;
    416             // set pid and section start flag
    417             // then pad buffer to next 188 byte boundary
    418             buffer[1] = ( fit.key() >> 8 ) | 0x40;
    419             buffer[2] = ( fit.key() & 0xff );
    420             int pktEnd = ((len + 188 + header_size) / 188) * 188 ;
    421             memset(&buffer[header_size + len], 0xFF, pktEnd - len);
    422 
    423             remainder = GetStreamData()->ProcessData(buffer, pktEnd);
    424             if (remainder > 0)
    425             {
    426                 // only happens on fragmented packet reads
    427                 VERBOSE(VB_CHANNEL, LOC + "RunTableMonitorSR(): " +
    428                         QString("unhandled data (# bytes: %1)")
    429                         .arg(remainder));
    430             }
     419            tspkt->SetPID(fit.key());
     420            GetStreamData()->HandlePESTables(tspkt, buffer, len);
    431421        }
    432422        if (!readSomething)
    433423        {
     
    449439    }
    450440
    451441    delete[] buffer;
     442    delete tspkt;
    452443
    453444    VERBOSE(VB_CHANNEL, LOC + "RunTableMonitorSR(): " + "end");
    454445}