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