Ticket #1564: pnum_lock.patch

File pnum_lock.patch, 5.1 KB (added by cizek@…, 18 years ago)
  • libs/libmythtv/siparser.cpp

     
    5757    atsc_stream_data(NULL),         dvb_stream_data(NULL),
    5858    // Mutex Locks
    5959    pmap_lock(false),
     60    pnum_lock(false),
    6061    // State variables
    6162    ThreadRunning(false),           exitParserThread(false),
    6263    standardChange(false),
     
    172173    // for MPEG PAT
    173174    AddPid(MPEG_PAT_PID, 0xFF, TableID::PAT, true, 10 /*bufferFactor*/);
    174175    // for MPEG PMT
    175     if (!pnum_pid.empty())
    176176    {
    177         uint pnum = 0xFFFFFFFF;
    178         if (SI_STANDARD_ATSC == table_standard)
    179             pnum = atsc_stream_data->DesiredProgram();
    180         if (SI_STANDARD_DVB == table_standard)
    181             pnum = dvb_stream_data->DesiredProgram();
     177        QMutexLocker lock (&pnum_lock);
     178        if (!pnum_pid.empty())
     179        {
     180            uint pnum = 0xFFFFFFFF;
     181            if (SI_STANDARD_ATSC == table_standard)
     182                pnum = atsc_stream_data->DesiredProgram();
     183            if (SI_STANDARD_DVB == table_standard)
     184                pnum = dvb_stream_data->DesiredProgram();
    182185
    183         pnum_pid_map_t::const_iterator it = pnum_pid.begin();
    184         for (; it != pnum_pid.end(); ++it)
    185         {
    186             if (it.key() == pnum)
    187                 AddPid(*it, 0xFF, TableID::PMT, true, 10 /*bufferFactor*/);
     186            pnum_pid_map_t::const_iterator it = pnum_pid.begin();
     187            for (; it != pnum_pid.end(); ++it)
     188            {
     189                if (it.key() == pnum)
     190                    AddPid(*it, 0xFF, TableID::PMT, true, 10 /*bufferFactor*/);
     191            }
     192            //pnum_pid.clear();
    188193        }
    189         //pnum_pid.clear();
    190194    }
    191195    // for DVB NIT
    192196    if (SI_STANDARD_DVB == table_standard && need_nit)
     
    688692            .arg(pat->Version()).arg(pat->TransportStreamID()));
    689693
    690694    PrivateTypes.CurrentTransportID = pat->TransportStreamID();
    691     pnum_pid.clear();
    692     for (uint i = 0; i < pat->ProgramCount(); ++i)
    693695    {
    694         // DVB Program 0 in the PAT represents the location of the NIT
    695         if (0 == pat->ProgramNumber(i) && SI_STANDARD_ATSC != table_standard)
     696        QMutexLocker lock(&pnum_lock);
     697        pnum_pid.clear();
     698        for (uint i = 0; i < pat->ProgramCount(); ++i)
    696699        {
    697             VERBOSE(VB_SIPARSER, LOC + "NIT Present on this transport " +
    698                     QString(" on PID 0x%1").arg(NITPID,0,16));
     700            // DVB Program 0 in the PAT represents the location of the NIT
     701            if (0 == pat->ProgramNumber(i) && SI_STANDARD_ATSC != table_standard)
     702            {
     703                VERBOSE(VB_SIPARSER, LOC + "NIT Present on this transport " +
     704                        QString(" on PID 0x%1").arg(NITPID,0,16));
    699705
    700             NITPID = pat->ProgramPID(i);
    701             continue;
     706                NITPID = pat->ProgramPID(i);
     707                continue;
     708            }
     709
     710            pnum_pid[pat->ProgramNumber(i)] = pat->ProgramPID(i);
    702711        }
    703 
    704         pnum_pid[pat->ProgramNumber(i)] = pat->ProgramPID(i);
    705712    }
    706713}
    707714
     
    728735//       to retune to correct transport or send an error tuning the channel
    729736void SIParser::HandlePMT(uint pnum, const ProgramMapTable *pmt)
    730737{
    731     VERBOSE(VB_SIPARSER, LOC + QString(
    732                 "PMT pn(%1) version(%2) cnt(%3) pid(0x%4)")
    733             .arg(pnum).arg(pmt->Version()).arg(pmt->StreamCount())
    734             .arg(pnum_pid[pmt->ProgramNumber()],0,16));
     738    {
     739        QMutexLocker lock(&pnum_lock);
     740        VERBOSE(VB_SIPARSER, LOC + QString(
     741                    "PMT pn(%1) version(%2) cnt(%3) pid(0x%4)")
     742                .arg(pnum).arg(pmt->Version()).arg(pmt->StreamCount())
     743                .arg(pnum_pid[pmt->ProgramNumber()],0,16));
    735744
    736     if (SI_STANDARD_ATSC == table_standard)
    737     {
    738         if ((int)pmt->ProgramNumber() == atsc_stream_data->DesiredProgram())
    739             emit UpdatePMT(pnum_pid[pmt->ProgramNumber()], pmt);
     745        if (SI_STANDARD_ATSC == table_standard)
     746        {
     747            if ((int)pmt->ProgramNumber() == atsc_stream_data->DesiredProgram())
     748                emit UpdatePMT(pnum_pid[pmt->ProgramNumber()], pmt);
     749        }
     750        if (SI_STANDARD_DVB == table_standard)
     751        {
     752            if ((int)pmt->ProgramNumber() == dvb_stream_data->DesiredProgram())
     753                emit UpdatePMT(pnum_pid[pmt->ProgramNumber()], pmt);
     754        }
    740755    }
    741     if (SI_STANDARD_DVB == table_standard)
    742     {
    743         if ((int)pmt->ProgramNumber() == dvb_stream_data->DesiredProgram())
    744             emit UpdatePMT(pnum_pid[pmt->ProgramNumber()], pmt);
    745     }
    746756}
    747757
    748758/*------------------------------------------------------------------------
  • libs/libmythtv/siparser.h

     
    219219    // Mutex Locks
    220220    // TODO: Lock Events, and Services, Transports, etc
    221221    QMutex              pmap_lock;
     222    QMutex              pnum_lock;
    222223    pnum_pid_map_t      pnum_pid;
    223224    dvb_srv_eit_on_t    dvb_srv_collect_eit;
    224225    atsc_eit_pid_map_t  atsc_eit_pid;