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

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

v3 of 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
     
    4647void MPEGStreamData::Reset(int desiredProgram)
    4748{
    4849    _desired_program = desiredProgram;
     50    _invalid_pat_seen = false;
    4951
    5052    SetPATSingleProgram(0);
    5153    SetPMTSingleProgram(0);
     
    406408
    407409void MPEGStreamData::ProcessPAT(const ProgramAssociationTable *pat)
    408410{
    409     emit UpdatePAT(pat);
    410     if ((_desired_program >= 0) && CreatePATSingleProgram(*pat))
    411         emit UpdatePATSingleProgram(PATSingleProgram());
     411    bool foundProgram = pat->FindPID(_desired_program);
     412
     413    if (_desired_program < 0)
     414        emit UpdatePAT(pat);
     415    if (_desired_program >= 0)
     416    {
     417        if (!_invalid_pat_seen && !foundProgram)
     418        {
     419            _invalid_pat_seen = true;
     420            _invalid_pat_timer.start();
     421            VERBOSE(VB_IMPORTANT, "ProcesPAT -> PAT is missing program, setting timeout");
     422        }
     423        else if (_invalid_pat_seen && (_invalid_pat_timer.elapsed() > 400))
     424        {
     425            // After 400ms emit error if we haven't found correct PAT.
     426            VERBOSE(VB_IMPORTANT, "Program not found in PAT. Rescan your transports.");
     427            // This will trigger debug PAT print
     428            emit UpdatePAT(pat);
     429            if (CreatePATSingleProgram(*pat))
     430                emit UpdatePATSingleProgram(PATSingleProgram());
     431            _invalid_pat_seen = false;
     432        }
     433        else if (foundProgram)
     434        {
     435            if (_invalid_pat_seen)
     436            {
     437                _invalid_pat_seen = false;
     438                VERBOSE(VB_IMPORTANT, "ProcesPAT -> PAT updated");
     439            }
     440            emit UpdatePAT(pat);
     441            if (CreatePATSingleProgram(*pat))
     442                emit UpdatePATSingleProgram(PATSingleProgram());
     443        }
     444    }
    412445}
    413446
    414447void MPEGStreamData::ProcessPMT(const uint pid, const ProgramMapTable *pmt)
  • libs/libmythtv/mpeg/mpegstreamdata.h

    old new  
    88
    99#include <qmap.h>
    1010#include "tspacket.h"
     11#include "util.h"
    1112
    1213class ProgramAssociationTable;
    1314class ProgramMapTable;
     
    179180    uint                      _pmt_single_program_num_audio;
    180181    ProgramAssociationTable  *_pat_single_program;
    181182    ProgramMapTable          *_pmt_single_program;
     183
     184  // PAT Timeout handling.
     185  private:
     186    bool                     _invalid_pat_seen;
     187    MythTimer                _invalid_pat_timer;
    182188};
    183189
    184190#include "mpegtables.h"