Ticket #743: find-correct-pat-in-400ms-v2.diff

File find-correct-pat-in-400ms-v2.diff, 3.3 KB (added by Stuart Auchterlonie, 18 years ago)

New find correct PAT in 400ms

  • libs/libmythtv/mpeg/mpegstreamdata.cpp

    old new  
    2424      _cached_pat(NULL), _desired_program(desiredProgram),
    2525      _pmt_single_program_num_video(1),
    2626      _pmt_single_program_num_audio(0),
    27       _pat_single_program(NULL), _pmt_single_program(NULL)
     27      _pat_single_program(NULL), _pmt_single_program(NULL),
     28      _invalid_pat_seen(false)
    2829{
    2930    AddListeningPID(MPEG_PAT_PID);
    3031
    3132    _pid_video_single_program = _pid_pmt_single_program = 0xffffffff;
     33
     34    connect(&_invalid_pat_timer, SIGNAL(timeout()), this, SLOT(ProcessInvalidPAT()));
    3235}
    3336
    3437MPEGStreamData::~MPEGStreamData()
     
    4649void MPEGStreamData::Reset(int desiredProgram)
    4750{
    4851    _desired_program = desiredProgram;
     52    _invalid_pat_seen = false;
    4953
    5054    SetPATSingleProgram(0);
    5155    SetPMTSingleProgram(0);
     
    406410
    407411void MPEGStreamData::ProcessPAT(const ProgramAssociationTable *pat)
    408412{
    409     emit UpdatePAT(pat);
    410     if ((_desired_program >= 0) && CreatePATSingleProgram(*pat))
    411         emit UpdatePATSingleProgram(PATSingleProgram());
     413    bool foundProgram = pat->FindPID(_desired_program);
     414
     415    if (_desired_program < 0)
     416        emit UpdatePAT(pat);
     417    if (_desired_program >= 0)
     418    {
     419        if (!_invalid_pat_seen && !foundProgram)
     420        {
     421            _invalid_pat_seen = true;
     422            _invalid_pat_timer.start(400, TRUE); // 400ms timeout.
     423            VERBOSE(VB_IMPORTANT, "HandleTables -> PAT is missing program, setting timeout");
     424        }
     425        else if (foundProgram)
     426        {
     427            if (_invalid_pat_seen)
     428            {
     429                _invalid_pat_seen = false;
     430                _invalid_pat_timer.stop();
     431                VERBOSE(VB_IMPORTANT, "HandleTables -> PAT updated");
     432            }
     433            emit UpdatePAT(pat);
     434            if (CreatePATSingleProgram(*pat))
     435                emit UpdatePATSingleProgram(PATSingleProgram());
     436        }
     437    }
    412438}
    413439
    414440void MPEGStreamData::ProcessPMT(const uint pid, const ProgramMapTable *pmt)
     
    421447    }
    422448}
    423449
     450void MPEGStreamData::ProcessInvalidPAT(void)
     451{
     452    VERBOSE(VB_IMPORTANT, "Program not found in PAT. Rescan your transports.");
     453}
     454
    424455#define DONE_WITH_PES_PACKET() { if (psip) delete psip; \
    425456    if (morePSIPPackets) goto HAS_ANOTHER_PES; else return; }
    426457
  • libs/libmythtv/mpeg/mpegstreamdata.h

    old new  
    77using namespace std;
    88
    99#include <qmap.h>
     10#include <qtimer.h>
    1011#include "tspacket.h"
    1112
    1213class ProgramAssociationTable;
     
    179180    uint                      _pmt_single_program_num_audio;
    180181    ProgramAssociationTable  *_pat_single_program;
    181182    ProgramMapTable          *_pmt_single_program;
     183
     184  // PAT Timeout handling.
     185  protected slots:
     186    void                     ProcessInvalidPAT();
     187  private:
     188    bool                     _invalid_pat_seen;
     189    QTimer                   _invalid_pat_timer;
    182190};
    183191
    184192#include "mpegtables.h"