00001
00002
00003 #ifndef ATSCSTREAMDATA_H_
00004 #define ATSCSTREAMDATA_H_
00005
00006 #include "mpegstreamdata.h"
00007 #include "mythtvexp.h"
00008
00009 typedef QMap<uint, uint_vec_t> pid_tsid_vec_t;
00010 typedef TerrestrialVirtualChannelTable* tvct_ptr_t;
00011 typedef CableVirtualChannelTable* cvct_ptr_t;
00012 typedef vector<const TerrestrialVirtualChannelTable*> tvct_vec_t;
00013 typedef vector<const CableVirtualChannelTable*> cvct_vec_t;
00014 typedef QMap<uint, tvct_ptr_t> tvct_cache_t;
00015 typedef QMap<uint, cvct_ptr_t> cvct_cache_t;
00016 typedef QMap<uint, uint> atsc_eit_pid_map_t;
00017 typedef QMap<uint, uint> atsc_ett_pid_map_t;
00018
00019 typedef vector<ATSCMainStreamListener*> atsc_main_listener_vec_t;
00020 typedef vector<SCTEMainStreamListener*> scte_main_listener_vec_t;
00021 typedef vector<ATSCAuxStreamListener*> atsc_aux_listener_vec_t;
00022 typedef vector<ATSCEITStreamListener*> atsc_eit_listener_vec_t;
00023 typedef vector<ATSC81EITStreamListener*> atsc81_eit_listener_vec_t;
00024
00025 class MTV_PUBLIC ATSCStreamData : virtual public MPEGStreamData
00026 {
00027 public:
00028 ATSCStreamData(int desiredMajorChannel,
00029 int desiredMinorChannel,
00030 bool cacheTables = false);
00031 virtual ~ATSCStreamData();
00032
00033 void Reset(void) { Reset(-1, -1); }
00034 void Reset(int desiredProgram);
00035 void Reset(int desiredMajorChannel, int desiredMinorChannel);
00036 void SetDesiredChannel(int major, int minor);
00037
00038
00039 virtual bool HandleTables(uint pid, const PSIPTable &psip);
00040 virtual bool IsRedundant(uint, const PSIPTable&) const;
00041
00043 uint GPSOffset(void) const { return _GPS_UTC_offset; }
00044
00045 inline uint GetATSCMajorMinor(uint eit_sourceid) const;
00046 inline bool HasATSCMajorMinorMap(void) const;
00047 bool HasEITPIDChanges(const uint_vec_t &in_use_pid) const;
00048 bool GetEITPIDChanges(const uint_vec_t &in_use_pid,
00049 uint_vec_t &pids_to_add,
00050 uint_vec_t &pids_to_del) const;
00051
00052
00053 void SetVersionMGT(int version)
00054 { _mgt_version = version; }
00055 void SetVersionTVCT(uint tsid, int version)
00056 { _tvct_version[tsid] = version; }
00057 void SetVersionCVCT(uint tsid, int version)
00058 { _cvct_version[tsid] = version; }
00059 void SetVersionRRT(uint region, int version)
00060 { _rrt_version[region&0xff] = version; }
00061 void SetVersionEIT(uint pid, uint atsc_source_id, int version)
00062 {
00063 if (VersionEIT(pid, atsc_source_id) == version)
00064 return;
00065 uint key = (pid<<16) | atsc_source_id;
00066 _eit_version[key] = version;
00067 _eit_section_seen[key].clear();
00068 _eit_section_seen[key].resize(32, 0);
00069 }
00070 void SetEITSectionSeen(uint pid, uint atsc_source_id, uint section);
00071
00072 int VersionMGT() const { return _mgt_version; }
00073 inline int VersionTVCT(uint tsid) const;
00074 inline int VersionCVCT(uint tsid) const;
00075 inline int VersionRRT(uint region) const;
00076 inline int VersionEIT(uint pid, uint atsc_sourceid) const;
00077 bool EITSectionSeen(uint pid, uint atsc_source_id, uint section) const;
00078
00079
00080 bool HasCachedMGT(bool current = true) const;
00081 bool HasCachedTVCT(uint pid, bool current = true) const;
00082 bool HasCachedCVCT(uint pid, bool current = true) const;
00083
00084 bool HasCachedAllTVCTs(bool current = true) const;
00085 bool HasCachedAllCVCTs(bool current = true) const;
00086 bool HasCachedAllVCTs(bool current = true) const
00087 { return HasCachedAllTVCTs(current) && HasCachedAllCVCTs(current); }
00088
00089 bool HasCachedAnyTVCTs(bool current = true) const;
00090 bool HasCachedAnyCVCTs(bool current = true) const;
00091 bool HasCachedAnyVCTs(bool current = true) const
00092 { return HasCachedAnyTVCTs(current) || HasCachedAnyCVCTs(current); }
00093
00094 const MasterGuideTable *GetCachedMGT(bool current = true) const;
00095 const tvct_ptr_t GetCachedTVCT(uint pid, bool current = true) const;
00096 const cvct_ptr_t GetCachedCVCT(uint pid, bool current = true) const;
00097
00098 tvct_vec_t GetCachedTVCTs(bool current = true) const;
00099 cvct_vec_t GetCachedCVCTs(bool current = true) const;
00100
00101 void ReturnCachedTVCTTables(tvct_vec_t&) const;
00102 void ReturnCachedCVCTTables(cvct_vec_t&) const;
00103
00104 bool HasChannel(uint major, uint minor) const;
00105
00106
00107 int DesiredMajorChannel(void) const { return _desired_major_channel; }
00108 int DesiredMinorChannel(void) const { return _desired_minor_channel; }
00109
00110 void AddATSCMainListener(ATSCMainStreamListener*);
00111 void AddSCTEMainListener(SCTEMainStreamListener*);
00112 void AddATSCAuxListener(ATSCAuxStreamListener*);
00113 void AddATSCEITListener(ATSCEITStreamListener*);
00114 void AddATSC81EITListener(ATSC81EITStreamListener*);
00115
00116 void RemoveATSCMainListener(ATSCMainStreamListener*);
00117 void RemoveSCTEMainListener(SCTEMainStreamListener*);
00118 void RemoveATSCAuxListener(ATSCAuxStreamListener*);
00119 void RemoveATSCEITListener(ATSCEITStreamListener*);
00120 void RemoveATSC81EITListener(ATSC81EITStreamListener*);
00121
00122 private:
00123 void ProcessMGT(const MasterGuideTable*);
00124 void ProcessVCT(uint tsid, const VirtualChannelTable*);
00125 void ProcessTVCT(uint tsid, const TerrestrialVirtualChannelTable*);
00126 void ProcessCVCT(uint tsid, const CableVirtualChannelTable*);
00127
00128
00129 void CacheMGT(MasterGuideTable*);
00130 void CacheTVCT(uint pid, TerrestrialVirtualChannelTable*);
00131 void CacheCVCT(uint pid, CableVirtualChannelTable*);
00132 protected:
00133 virtual bool DeleteCachedTable(PSIPTable *psip) const;
00134
00135 private:
00136 uint _GPS_UTC_offset;
00137 mutable bool _atsc_eit_reset;
00138 atsc_eit_pid_map_t _atsc_eit_pids;
00139 atsc_ett_pid_map_t _atsc_ett_pids;
00140
00141 QMap<uint,uint> _sourceid_to_atsc_maj_min;
00142
00143
00144
00145 atsc_main_listener_vec_t _atsc_main_listeners;
00146 scte_main_listener_vec_t _scte_main_listeners;
00147 atsc_aux_listener_vec_t _atsc_aux_listeners;
00148 atsc_eit_listener_vec_t _atsc_eit_listeners;
00149 atsc81_eit_listener_vec_t _atsc81_eit_listeners;
00150
00151
00152 int _mgt_version;
00153 QMap<uint, int> _tvct_version;
00154 QMap<uint, int> _cvct_version;
00155 QMap<uint, int> _rrt_version;
00156 QMap<uint, int> _eit_version;
00157 sections_map_t _eit_section_seen;
00158
00159
00160 mutable MasterGuideTable *_cached_mgt;
00161 mutable tvct_cache_t _cached_tvcts;
00162 mutable cvct_cache_t _cached_cvcts;
00163
00164
00165 int _desired_major_channel;
00166 int _desired_minor_channel;
00167 };
00168
00169
00170 inline uint ATSCStreamData::GetATSCMajorMinor(uint eit_sourceid) const
00171 {
00172 QMutexLocker locker(&_listener_lock);
00173 return _sourceid_to_atsc_maj_min[eit_sourceid];
00174 }
00175
00176 inline bool ATSCStreamData::HasATSCMajorMinorMap(void) const
00177 {
00178 QMutexLocker locker(&_listener_lock);
00179 return !_sourceid_to_atsc_maj_min.empty();
00180 }
00181
00182 inline int ATSCStreamData::VersionTVCT(uint tsid) const
00183 {
00184 const QMap<uint, int>::const_iterator it = _tvct_version.find(tsid);
00185 if (it == _tvct_version.end())
00186 return -1;
00187 return *it;
00188 }
00189
00190 inline int ATSCStreamData::VersionCVCT(uint tsid) const
00191 {
00192 const QMap<uint, int>::const_iterator it = _cvct_version.find(tsid);
00193 if (it == _cvct_version.end())
00194 return -1;
00195 return *it;
00196 }
00197
00198 inline int ATSCStreamData::VersionRRT(uint region) const
00199 {
00200 const QMap<uint, int>::const_iterator it = _rrt_version.find(region&0xff);
00201 if (it == _rrt_version.end())
00202 return -1;
00203 return *it;
00204 }
00205
00206 inline int ATSCStreamData::VersionEIT(uint pid, uint atsc_source_id) const
00207 {
00208 uint key = (pid<<16) | atsc_source_id;
00209 const QMap<uint, int>::const_iterator it = _eit_version.find(key);
00210 if (it == _eit_version.end())
00211 return -1;
00212 return *it;
00213 }
00214
00215 #endif