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

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

Find correct PAT with time limit of 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), _invalid_pat(NULL)
    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;
     53    if (_invalid_pat)
     54    {
     55        delete _invalid_pat;
     56        _invalid_pat = NULL;
     57    }
    4958
    5059    SetPATSingleProgram(0);
    5160    SetPMTSingleProgram(0);
     
    372381            SetVersionPAT(psip.Version());
    373382            ProgramAssociationTable *pat =
    374383                new ProgramAssociationTable(psip);
    375             if (_cache_tables)
    376                 CachePAT(pat);
    377             emit UpdatePAT(pat);
    378             if ((_desired_program >= 0) && CreatePATSingleProgram(*pat))
    379                 emit UpdatePATSingleProgram(PATSingleProgram());
     384
     385            bool foundProgram = pat->FindPID(_desired_program);
     386
     387            if (_desired_program < 0)
     388            {
     389                if (_cache_tables)
     390                    CachePAT(pat);
     391                emit UpdatePAT(pat);
     392            }
     393            if (_desired_program >= 0)
     394            {
     395                if (!_invalid_pat_seen && !foundProgram)
     396                {
     397                    _invalid_pat_seen = true;
     398                    _invalid_pat = pat;
     399                    _invalid_pat_timer.start(400, TRUE); // 400ms timeout.
     400                    VERBOSE(VB_RECORD, "HandleTables -> PAT is missing program, setting timeout");
     401                }
     402                else if (foundProgram)
     403                {
     404                    if (_invalid_pat_seen)
     405                    {
     406                        _invalid_pat_seen = false;
     407                        _invalid_pat_timer.stop();
     408                        VERBOSE(VB_RECORD, "HandleTables -> PAT updated");
     409                    }
     410                    if (_cache_tables)
     411                        CachePAT(pat);
     412                    emit UpdatePAT(pat);
     413                    if (CreatePATSingleProgram(*pat))
     414                        emit UpdatePATSingleProgram(PATSingleProgram());
     415                }
     416            }
    380417            if (!_cache_tables)
    381418                delete pat;
    382419            return true;
     
    401438    return false;
    402439}
    403440
     441void MPEGStreamData::ProcessInvalidPAT(void)
     442{
     443    VERBOSE(VB_IMPORTANT, "Program not found in PAT. Rescan your transports.");
     444    CreatePATSingleProgram(*_invalid_pat);
     445}
    404446
    405447#define DONE_WITH_PES_PACKET() { if (psip) delete psip; \
    406448    if (morePSIPPackets) goto HAS_ANOTHER_PES; else return; }
  • 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;
     
    177178    uint                      _pmt_single_program_num_audio;
    178179    ProgramAssociationTable  *_pat_single_program;
    179180    ProgramMapTable          *_pmt_single_program;
     181
     182  // PAT Timeout handling.
     183  protected slots:
     184    void                     ProcessInvalidPAT();
     185  private:
     186    bool                     _invalid_pat_seen;
     187    QTimer                   _invalid_pat_timer;
     188    ProgramAssociationTable *_invalid_pat;
    180189};
    181190
    182191#include "mpegtables.h"