Ticket #2703: mythtv-add-tdt-parsing.patch

File mythtv-add-tdt-parsing.patch, 13.7 KB (added by david@…, 14 years ago)

Patch version 1

  • libs/libmythtv/dtvsignalmonitor.h

    diff -Nur -x .svn upstream/libs/libmythtv/dtvsignalmonitor.h trunk/libs/libmythtv/dtvsignalmonitor.h
    old new  
    101101    // DVB Main
    102102    void HandleNIT(const NetworkInformationTable*);
    103103    void HandleSDT(uint, const ServiceDescriptionTable*);
     104    void HandleTDT(const TimeDateTable*) {}
    104105
    105106  protected:
    106107    void UpdateMonitorValues(void);
  • libs/libmythtv/dvbcam.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/dvbcam.cpp trunk/libs/libmythtv/dvbcam.cpp
    old new  
    273273    pmt_updated = true;
    274274}
    275275
     276void DVBCam::SetTDT(const TimeDateTable *tdt)
     277{
     278    VERBOSE(VB_CHANNEL, LOC + "SetTDT() called");
     279    for (uint s = 0; s < (uint)ciHandler->NumSlots(); s++)
     280        ciHandler->SetTime(tdt->UTCtime(), s);
     281}
     282
    276283static const char *cplm_info[] =
    277284{
    278285    "CPLM_MORE",
  • libs/libmythtv/dvbcam.h

    diff -Nur -x .svn upstream/libs/libmythtv/dvbcam.h trunk/libs/libmythtv/dvbcam.h
    old new  
    2222    bool Stop();
    2323    bool IsRunning() const { return ciThreadRunning; }
    2424    void SetPMT(const ProgramMapTable *pmt);
     25    void SetTDT(const TimeDateTable *tdt);
    2526
    2627  private:
    2728    static void *CiHandlerThreadHelper(void*);
  • libs/libmythtv/dvbchannel.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/dvbchannel.cpp trunk/libs/libmythtv/dvbchannel.cpp
    old new  
    562562        dvbcam->SetPMT(pmt);
    563563}
    564564
     565/** \fn DVBChannel::SetTDT(const TimeDateTable *)
     566 *  \brief Tells the Conditional Access Module the time and date from the stream.
     567 */
     568void DVBChannel::SetTDT(const TimeDateTable *tdt)
     569{
     570    if (tdt && dvbcam->IsRunning())
     571        dvbcam->SetTDT(tdt);
     572}
     573
    565574/*****************************************************************************
    566575           Tuning functions for each of the four types of cards.
    567576 *****************************************************************************/
  • libs/libmythtv/dvbchannel.h

    diff -Nur -x .svn upstream/libs/libmythtv/dvbchannel.h trunk/libs/libmythtv/dvbchannel.h
    old new  
    4343
    4444    // Sets
    4545    void SetPMT(const ProgramMapTable*);
     46    void SetTDT(const TimeDateTable*);
    4647    void SetSlowTuning(uint how_slow_in_ms)
    4748        { tuning_delay = how_slow_in_ms; }
    4849
  • libs/libmythtv/dvbdev/dvbci.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/dvbdev/dvbci.cpp trunk/libs/libmythtv/dvbdev/dvbci.cpp
    old new  
    10171017private:
    10181018  int interval;
    10191019  time_t lastTime;
     1020  int timeOffset;
    10201021  bool SendDateTime(void);
    10211022public:
    10221023  cCiDateTime(int SessionId, cCiTransportConnection *Tc);
    10231024  virtual bool Process(int Length = 0, const uint8_t *Data = NULL);
     1025  void SetTime(time_t t);
    10241026  };
    10251027
    10261028cCiDateTime::cCiDateTime(int SessionId, cCiTransportConnection *Tc)
     
    10281030{
    10291031  interval = 0;
    10301032  lastTime = 0;
     1033  timeOffset = 0;
    10311034  dbgprotocol("New Date Time (session id %d)\n", SessionId);
    10321035}
    10331036
     1037void cCiDateTime::SetTime(time_t t)
     1038{
     1039    timeOffset = (int)(t - time(NULL));
     1040    dbgprotocol("New Time Offset: %i secs\n", timeOffset);
     1041}
     1042
    10341043bool cCiDateTime::SendDateTime(void)
    10351044{
    10361045  time_t t = time(NULL);
    10371046  struct tm tm_gmt;
    10381047  struct tm tm_loc;
     1048
     1049  // Avoid using signed time_t types
     1050  if (timeOffset < 0)
     1051      t -= (time_t)(-timeOffset);
     1052  else
     1053      t += (time_t)timeOffset;
     1054 
    10391055  if (gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc)) {
    10401056     int Y = tm_gmt.tm_year;
    10411057     int M = tm_gmt.tm_mon + 1;
     
    17341750  return cas && cas->SendPMT(CaPmt);
    17351751}
    17361752
     1753void cLlCiHandler::SetTime(time_t t, int Slot)
     1754{
     1755  cMutexLock MutexLock(&mutex);
     1756  cCiDateTime *dt = (cCiDateTime *)GetSessionByResourceId(RI_DATE_TIME, Slot);
     1757  if (dt)
     1758    dt->SetTime(t);
     1759}
     1760
    17371761bool cLlCiHandler::Reset(int Slot)
    17381762{
    17391763  cMutexLock MutexLock(&mutex);
  • libs/libmythtv/dvbdev/dvbci.h

    diff -Nur -x .svn upstream/libs/libmythtv/dvbdev/dvbci.h trunk/libs/libmythtv/dvbdev/dvbci.h
    old new  
    153153  virtual cCiEnquiry *GetEnquiry(void) = 0;
    154154  virtual const unsigned short *GetCaSystemIds(int Slot) = 0;
    155155  virtual bool SetCaPmt(cCiCaPmt &CaPmt, int Slot) = 0;
     156  virtual void SetTime(time_t t, int Slot) = 0;
    156157  };
    157158
    158159class cLlCiHandler : public cCiHandler {
     
    188189  bool SetCaPmt(cCiCaPmt &CaPmt);
    189190  const unsigned short *GetCaSystemIds(int Slot);
    190191  bool SetCaPmt(cCiCaPmt &CaPmt, int Slot);
     192  void SetTime(time_t t, int Slot);
    191193  bool Reset(int Slot);
    192194  bool connected() const;
    193195  };
     
    217219    bool SetCaPmt(cCiCaPmt &CaPmt);
    218220    const unsigned short *GetCaSystemIds(int Slot);
    219221    bool SetCaPmt(cCiCaPmt &CaPmt, int Slot);
     222    void SetTime(time_t t, int Slot) {}
    220223    bool Reset(int Slot);
    221224    bool connected() const;
    222225};
  • libs/libmythtv/dvbrecorder.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/dvbrecorder.cpp trunk/libs/libmythtv/dvbrecorder.cpp
    old new  
    5656#include "programinfo.h"
    5757#include "mpegtables.h"
    5858#include "iso639.h"
     59#include "dvbstreamdata.h"
    5960#include "atscstreamdata.h"
    6061#include "cardutil.h"
    6162#include "tv_rec.h"
     
    238239    }
    239240}
    240241
     242void DVBRecorder::HandleTDT(const TimeDateTable *tdt)
     243{
     244    VERBOSE(VB_RECORD, LOC + "SetTDT()");
     245    dvbchannel->SetTDT(tdt);
     246}
     247
    241248bool DVBRecorder::Open(void)
    242249{
    243250    if (IsOpen())
     
    296303    {
    297304        data->AddMPEGListener(this);
    298305
     306        DVBStreamData *dvb = dynamic_cast<DVBStreamData*>(data);
     307        if (dvb)
     308            dvb->AddDVBMainListener(this);
     309
    299310        ATSCStreamData *atsc = dynamic_cast<ATSCStreamData*>(data);
    300311
    301312        if (atsc && atsc->DesiredMinorChannel())
     
    495506    add_stream_type.push_back(StreamID::PrivSec);
    496507    _stream_data->AddListeningPID(MPEG_PAT_PID);
    497508
     509    add_pid.push_back(DVB_TDT_PID);
     510    add_stream_type.push_back(StreamID::PrivSec);
     511    _stream_data->AddListeningPID(DVB_TDT_PID);
     512
    498513    // Record the streams in the PMT...
    499514    bool need_pcr_pid = true;
    500515    for (uint i = 0; i < _input_pmt->StreamCount(); i++)
  • libs/libmythtv/dvbrecorder.h

    diff -Nur -x .svn upstream/libs/libmythtv/dvbrecorder.h trunk/libs/libmythtv/dvbrecorder.h
    old new  
    5757 */
    5858class DVBRecorder : public DTVRecorder,
    5959                    private ReaderPausedCB,
    60                     public MPEGStreamListener
     60                    public MPEGStreamListener,
     61                    public DVBMainStreamListener
    6162{
    6263  public:
    6364    DVBRecorder(TVRec *rec, DVBChannel* dvbchannel);
     
    8283    void HandleCAT(const ConditionalAccessTable*) {}
    8384    void HandlePMT(uint pid, const ProgramMapTable*);
    8485
     86    // DVBMainStreamListener
     87    void HandleNIT(const NetworkInformationTable*) {}
     88    void HandleSDT(uint tsid, const ServiceDescriptionTable*) {}
     89    void HandleTDT(const TimeDateTable*);
     90
    8591    void SetStreamData(MPEGStreamData*);
    8692    MPEGStreamData* GetStreamData(void) { return _stream_data; }
    8793
  • libs/libmythtv/dvbtypes.h

    diff -Nur -x .svn upstream/libs/libmythtv/dvbtypes.h trunk/libs/libmythtv/dvbtypes.h
    old new  
    5050
    5151#include "mpegdescriptors.h"
    5252#include "mpegtables.h"
     53#include "dvbtables.h"
    5354
    5455#define MPEG_TS_PKT_SIZE 188
    5556#define DEF_DMX_BUF_SIZE  64 * 1024
  • libs/libmythtv/mpeg/dvbstreamdata.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/dvbstreamdata.cpp trunk/libs/libmythtv/mpeg/dvbstreamdata.cpp
    old new  
    1919    SetVersionNITo(-1,0);
    2020    AddListeningPID(DVB_NIT_PID);
    2121    AddListeningPID(DVB_SDT_PID);
     22    AddListeningPID(DVB_TDT_PID);
    2223}
    2324
    2425DVBStreamData::~DVBStreamData()
     
    8990        return SDTSectionSeen(psip.TableIDExtension(), psip.Section());
    9091    }
    9192
     93    if (TableID::TDT == table_id)
     94        return false;
     95
    9296    bool is_eit = false;
    9397    if (DVB_EIT_PID == pid)
    9498    {
     
    183187    }
    184188    AddListeningPID(DVB_NIT_PID);
    185189    AddListeningPID(DVB_SDT_PID);
     190    AddListeningPID(DVB_TDT_PID);
    186191}
    187192
    188193/** \fn DVBStreamData::HandleTables(uint pid, const PSIPTable&)
     
    244249
    245250            return true;
    246251        }
     252        case TableID::TDT:
     253        {
     254            TimeDateTable tdt(psip);
     255            QMutexLocker locker(&_listener_lock);
     256            for (uint i = 0; i < _dvb_main_listeners.size(); i++)
     257                _dvb_main_listeners[i]->HandleTDT(&tdt);
     258            return true;
     259        }
    247260        case TableID::NITo:
    248261        {
    249262            SetVersionNITo(psip.Version(), psip.LastSection());
  • libs/libmythtv/mpeg/dvbtables.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/dvbtables.cpp trunk/libs/libmythtv/mpeg/dvbtables.cpp
    old new  
    236236               (byteBCD2int(buf[4]))); // 17 bits
    237237    return (dt | (tm>>1)) ^ ((tm & 1)<<31);
    238238}
     239
     240time_t TimeDateTable::UTCtime(void) const
     241{
     242    const unsigned char *buf = UTCdata();
     243
     244    // Modified Julian date as number of days since 17th November 1858.
     245    // The unix epoch, 1st Jan 1970, was day 40587.
     246    time_t mjd = (buf[0] << 8) | buf[1];
     247    if (mjd < 40587)
     248        return 0; // we don't handle pre-unix dates..
     249
     250    time_t secsSince1970 = (mjd - 40587)   * 86400;
     251    secsSince1970 += byteBCD2int(buf[2]) * 3600;
     252    secsSince1970 += byteBCD2int(buf[3]) * 60;
     253    secsSince1970 += byteBCD2int(buf[4]);
     254    return secsSince1970;
     255    VERBOSE(VB_RECORD, "UTCtime");
     256}
  • libs/libmythtv/mpeg/dvbtables.h

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/dvbtables.h trunk/libs/libmythtv/mpeg/dvbtables.h
    old new  
    286286    mutable vector<const unsigned char*> _ptrs; // used to parse
    287287};
    288288
     289/** \class TimeDateTable
     290 *  \brief This table gives the current DVB stream time
     291 */
     292class TimeDateTable : public PSIPTable
     293{
     294  public:
     295    TimeDateTable(const PSIPTable& table)
     296        : PSIPTable(table)
     297    {
     298        assert(TableID::TDT == TableID());
     299    }
     300    ~TimeDateTable() { ; }
     301
     302    // table_id                 8   0.0       0x70
     303    // section_syntax_indicator 1   1.0          0
     304    // reserved_future_use      1   1.1          1
     305    // reserved                 2   1.2          3
     306    // section_length          12   1.4         40
     307    // UTC_time                40   3.0          0
     308    const unsigned char* UTCdata(void) const
     309        { return pesdata() + 3; }
     310
     311    time_t UTCtime(void) const;
     312};
    289313
    290314#endif // _DVB_TABLES_H_
  • libs/libmythtv/mpeg/mpegstreamdata.cpp

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/mpegstreamdata.cpp trunk/libs/libmythtv/mpeg/mpegstreamdata.cpp
    old new  
    639639    PSIPTable *psip = AssemblePSIP(tspacket, morePSIPPackets);
    640640    if (!psip)
    641641       return;
     642   
     643    // dont do the usual checks on TDT - it has no CRC, etc...
     644    if (TableID::TDT == psip->TableID()) {
     645        HandleTables(tspacket->PID(), *psip);
     646        DONE_WITH_PES_PACKET();
     647    }
    642648
    643649    // drop stuffing packets
    644650    if ((TableID::ST       == psip->TableID()) ||
  • libs/libmythtv/mpeg/mpegtables.h

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/mpegtables.h trunk/libs/libmythtv/mpeg/mpegtables.h
    old new  
    181181    DVB_SDT_PID   = 0x0011,
    182182    DVB_EIT_PID   = 0x0012,
    183183    DVB_RST_PID   = 0x0013,
    184     DVB_TOT_PID   = 0x0013,
     184    DVB_TDT_PID   = 0x0014,
    185185
    186186    // Dishnet longterm EIT is on pid 0x300
    187187    DVB_DNLONG_EIT_PID = 0x0300,
  • libs/libmythtv/mpeg/streamlisteners.h

    diff -Nur -x .svn upstream/libs/libmythtv/mpeg/streamlisteners.h trunk/libs/libmythtv/mpeg/streamlisteners.h
    old new  
    3131
    3232class NetworkInformationTable;
    3333class ServiceDescriptionTable;
     34class TimeDateTable;
    3435class DVBEventInformationTable;
    3536
    3637class MPEGStreamListener
     
    9192  public:
    9293    virtual void HandleNIT(const NetworkInformationTable*) = 0;
    9394    virtual void HandleSDT(uint tsid, const ServiceDescriptionTable*) = 0;
     95    virtual void HandleTDT(const TimeDateTable*) = 0;
    9496};
    9597
    9698class DVBOtherStreamListener
  • libs/libmythtv/siscan.h

    diff -Nur -x .svn upstream/libs/libmythtv/siscan.h trunk/libs/libmythtv/siscan.h
    old new  
    8787    // DVB Main
    8888    void HandleNIT(const NetworkInformationTable*);
    8989    void HandleSDT(uint tsid, const ServiceDescriptionTable*);
     90    void HandleTDT(const TimeDateTable*) {}
    9091
    9192  signals:
    9293    // Values from 1-100 of scan completion