Ticket #12932: atscstreamdata.h

File atscstreamdata.h, 7.0 KB (added by Roger James <roger@…>, 7 years ago)
Line 
1// -*- Mode: c++ -*-
2// Copyright (c) 2003-2004, Daniel Thor Kristjansson
3#ifndef ATSCSTREAMDATA_H_
4#define ATSCSTREAMDATA_H_
5
6#include "mpegstreamdata.h"
7#include "mythtvexp.h"
8
9typedef QMap<uint, uint_vec_t>          pid_tsid_vec_t;
10typedef TerrestrialVirtualChannelTable* tvct_ptr_t;
11typedef TerrestrialVirtualChannelTable const* tvct_const_ptr_t;
12typedef CableVirtualChannelTable*       cvct_ptr_t;
13typedef CableVirtualChannelTable const* cvct_const_ptr_t;
14typedef vector<const TerrestrialVirtualChannelTable*> tvct_vec_t;
15typedef vector<const CableVirtualChannelTable*>       cvct_vec_t;
16typedef QMap<uint, tvct_ptr_t>          tvct_cache_t;
17typedef QMap<uint, cvct_ptr_t>          cvct_cache_t;
18typedef QMap<uint, uint>                atsc_eit_pid_map_t;
19typedef QMap<uint, uint>                atsc_ett_pid_map_t;
20
21typedef vector<ATSCMainStreamListener*> atsc_main_listener_vec_t;
22typedef vector<SCTEMainStreamListener*> scte_main_listener_vec_t;
23typedef vector<ATSCAuxStreamListener*>  atsc_aux_listener_vec_t;
24typedef vector<ATSCEITStreamListener*>  atsc_eit_listener_vec_t;
25typedef vector<ATSC81EITStreamListener*> atsc81_eit_listener_vec_t;
26
27class MTV_PUBLIC ATSCStreamData : virtual public MPEGStreamData
28{
29  public:
30    ATSCStreamData(int desiredMajorChannel,
31                   int desiredMinorChannel,
32                   int cardnum, bool cacheTables = false);
33    virtual ~ATSCStreamData();
34
35    void Reset(void) { Reset(-1, -1); }
36    void Reset(int desiredProgram);
37    void Reset(int desiredMajorChannel, int desiredMinorChannel);
38    void SetDesiredChannel(int major, int minor);
39
40    // Table processing
41    virtual bool HandleTables(uint pid, const PSIPTable &psip);
42    virtual bool IsRedundant(uint, const PSIPTable&) const;
43
44    /// Current UTC to GPS time offset in seconds
45    uint GPSOffset(void) const { return _GPS_UTC_offset; }
46
47    inline uint GetATSCMajorMinor(uint eit_sourceid) const;
48    inline bool HasATSCMajorMinorMap(void) const;
49    bool HasEITPIDChanges(const uint_vec_t &in_use_pid) const;
50    bool GetEITPIDChanges(const uint_vec_t &in_use_pid,
51                          uint_vec_t &pids_to_add,
52                          uint_vec_t &pids_to_del) const;
53
54    // Table versions
55    void SetVersionMGT(int version)
56        {    _mgt_version     = version; }
57    void SetVersionTVCT(uint tsid, int version)
58        { _tvct_version[tsid] = version; }
59    void SetVersionCVCT(uint tsid, int version)
60        { _cvct_version[tsid] = version; }
61    void SetVersionRRT(uint region, int version)
62        { _rrt_version[region&0xff] = version; }
63
64    int VersionMGT() const { return _mgt_version; }
65    inline int VersionTVCT(uint tsid) const;
66    inline int VersionCVCT(uint tsid) const;
67    inline int VersionRRT(uint region) const;
68
69    // Caching
70    bool HasCachedMGT(bool current = true) const;
71    bool HasCachedTVCT(uint pid, bool current = true) const;
72    bool HasCachedCVCT(uint pid, bool current = true) const;
73
74    bool HasCachedAllTVCTs(bool current = true) const;
75    bool HasCachedAllCVCTs(bool current = true) const;
76    bool HasCachedAllVCTs(bool current = true) const
77        { return HasCachedAllTVCTs(current) && HasCachedAllCVCTs(current); }
78
79    bool HasCachedAnyTVCTs(bool current = true) const;
80    bool HasCachedAnyCVCTs(bool current = true) const;
81    bool HasCachedAnyVCTs(bool current = true) const
82        { return HasCachedAnyTVCTs(current) || HasCachedAnyCVCTs(current); }
83
84    const MasterGuideTable *GetCachedMGT(bool current = true) const;
85    tvct_const_ptr_t GetCachedTVCT(uint pid, bool current = true) const;
86    cvct_const_ptr_t GetCachedCVCT(uint pid, bool current = true) const;
87
88    tvct_vec_t GetCachedTVCTs(bool current = true) const;
89    cvct_vec_t GetCachedCVCTs(bool current = true) const;
90
91    void ReturnCachedTVCTTables(tvct_vec_t&) const;
92    void ReturnCachedCVCTTables(cvct_vec_t&) const;
93
94    bool HasChannel(uint major, uint minor) const;
95
96    // Single channel stuff
97    int DesiredMajorChannel(void) const { return _desired_major_channel; }
98    int DesiredMinorChannel(void) const { return _desired_minor_channel; }
99
100    void AddATSCMainListener(ATSCMainStreamListener*);
101    void AddSCTEMainListener(SCTEMainStreamListener*);
102    void AddATSCAuxListener(ATSCAuxStreamListener*);
103    void AddATSCEITListener(ATSCEITStreamListener*);
104    void AddATSC81EITListener(ATSC81EITStreamListener*);
105
106    void RemoveATSCMainListener(ATSCMainStreamListener*);
107    void RemoveSCTEMainListener(SCTEMainStreamListener*);
108    void RemoveATSCAuxListener(ATSCAuxStreamListener*);
109    void RemoveATSCEITListener(ATSCEITStreamListener*);
110    void RemoveATSC81EITListener(ATSC81EITStreamListener*);
111
112  private:
113    void ProcessMGT(const MasterGuideTable*);
114    void ProcessVCT(uint tsid, const VirtualChannelTable*);
115    void ProcessTVCT(uint tsid, const TerrestrialVirtualChannelTable*);
116    void ProcessCVCT(uint tsid, const CableVirtualChannelTable*);
117
118    // Caching
119    void CacheMGT(MasterGuideTable*);
120    void CacheTVCT(uint pid, TerrestrialVirtualChannelTable*);
121    void CacheCVCT(uint pid, CableVirtualChannelTable*);
122  protected:
123    virtual bool DeleteCachedTable(PSIPTable *psip) const;
124
125  private:
126    uint                      _GPS_UTC_offset;
127    mutable bool              _atsc_eit_reset;
128    atsc_eit_pid_map_t        _atsc_eit_pids;
129    atsc_ett_pid_map_t        _atsc_ett_pids;
130
131    QMap<uint,uint>           _sourceid_to_atsc_maj_min;
132
133
134    // Signals
135    atsc_main_listener_vec_t  _atsc_main_listeners;
136    scte_main_listener_vec_t  _scte_main_listeners;
137    atsc_aux_listener_vec_t   _atsc_aux_listeners;
138    atsc_eit_listener_vec_t   _atsc_eit_listeners;
139    atsc81_eit_listener_vec_t _atsc81_eit_listeners;
140
141    // Table versions
142    int             _mgt_version;
143    QMap<uint, int> _tvct_version;
144    QMap<uint, int> _cvct_version;
145    QMap<uint, int> _rrt_version;
146    TableStatusMap  _eit_status;
147
148    // Caching
149    mutable MasterGuideTable *_cached_mgt;
150    mutable tvct_cache_t      _cached_tvcts; // pid->tvct
151    mutable cvct_cache_t      _cached_cvcts; // pid->cvct
152
153    // Single program variables
154    int _desired_major_channel;
155    int _desired_minor_channel;
156};
157
158
159inline uint ATSCStreamData::GetATSCMajorMinor(uint eit_sourceid) const
160{
161    QMutexLocker locker(&_listener_lock);
162    return _sourceid_to_atsc_maj_min[eit_sourceid];
163}
164
165inline bool ATSCStreamData::HasATSCMajorMinorMap(void) const
166{
167    QMutexLocker locker(&_listener_lock);
168    return !_sourceid_to_atsc_maj_min.empty();
169}
170
171inline int ATSCStreamData::VersionTVCT(uint tsid) const
172{
173    const QMap<uint, int>::const_iterator it = _tvct_version.find(tsid);
174    if (it == _tvct_version.end())
175        return -1;
176    return *it;
177}
178
179inline int ATSCStreamData::VersionCVCT(uint tsid) const
180{
181    const QMap<uint, int>::const_iterator it = _cvct_version.find(tsid);
182    if (it == _cvct_version.end())
183        return -1;
184    return *it;
185}
186
187inline int ATSCStreamData::VersionRRT(uint region) const
188{
189    const QMap<uint, int>::const_iterator it = _rrt_version.find(region&0xff);
190    if (it == _rrt_version.end())
191        return -1;
192    return *it;
193}
194
195#endif