00001
00002
00003 #ifndef DVBSTREAMDATA_H_
00004 #define DVBSTREAMDATA_H_
00005
00006 #include "mpegstreamdata.h"
00007 #include "mythtvexp.h"
00008
00009 typedef NetworkInformationTable* nit_ptr_t;
00010 typedef vector<const NetworkInformationTable*> nit_vec_t;
00011 typedef QMap<uint, nit_ptr_t> nit_cache_t;
00012
00013 typedef ServiceDescriptionTable* sdt_ptr_t;
00014 typedef vector<const ServiceDescriptionTable*> sdt_vec_t;
00015 typedef QMap<uint, sdt_ptr_t> sdt_cache_t;
00016 typedef QMap<uint, sdt_vec_t> sdt_map_t;
00017
00018 typedef vector<DVBMainStreamListener*> dvb_main_listener_vec_t;
00019 typedef vector<DVBOtherStreamListener*> dvb_other_listener_vec_t;
00020 typedef vector<DVBEITStreamListener*> dvb_eit_listener_vec_t;
00021
00022 typedef QMap<uint, bool> dvb_has_eit_t;
00023
00024 class MTV_PUBLIC DVBStreamData : virtual public MPEGStreamData
00025 {
00026 public:
00027 DVBStreamData(uint desired_netid, uint desired_tsid,
00028 int desired_program, bool cacheTables = false);
00029 virtual ~DVBStreamData();
00030
00031 void Reset(void) { Reset(0, 0, -1); }
00032 void Reset(uint desired_netid, uint desired_tsid, int desired_sid);
00033
00034
00035 void SetDesiredService(uint netid, uint tsid, int serviceid);
00036 uint DesiredNetworkID(void) const { return _desired_netid; }
00037 uint DesiredTransportID(void) const { return _desired_tsid; }
00038
00039
00040 bool HandleTables(uint pid, const PSIPTable&);
00041 bool IsRedundant(uint pid, const PSIPTable&) const;
00042 void ProcessSDT(uint tsid, const ServiceDescriptionTable*);
00043
00044
00045 inline void SetDishNetEIT(bool);
00046 inline bool HasAnyEIT(void) const;
00047 inline bool HasEIT(uint serviceid) const;
00048 bool HasEITPIDChanges(const uint_vec_t &in_use_pids) const;
00049 bool GetEITPIDChanges(const uint_vec_t &in_use_pids,
00050 uint_vec_t &add_pids,
00051 uint_vec_t &del_pids) const;
00052
00053
00054 void SetVersionNIT(int version, uint last_section)
00055 {
00056 if (_nit_version == version)
00057 return;
00058 _nit_version = version;
00059 init_sections(_nit_section_seen, last_section);
00060 }
00061 int VersionNIT() const { return _nit_version; }
00062
00063 void SetVersionNITo(int version, uint last_section)
00064 {
00065 if (_nito_version == version)
00066 return;
00067 _nito_version = version;
00068 init_sections(_nito_section_seen, last_section);
00069 }
00070 int VersionNITo() const { return _nito_version; }
00071
00072 void SetVersionSDT(uint tsid, int version, uint last_section)
00073 {
00074 if (VersionSDT(tsid) == version)
00075 return;
00076 _sdt_versions[tsid] = version;
00077 init_sections(_sdt_section_seen[tsid], last_section);
00078 }
00079 int VersionSDT(uint tsid) const
00080 {
00081 const QMap<uint, int>::const_iterator it = _sdt_versions.find(tsid);
00082 if (it == _sdt_versions.end())
00083 return -1;
00084 return *it;
00085 }
00086
00087 void SetVersionSDTo(uint tsid, int version, uint last_section)
00088 {
00089 if (_sdto_versions[tsid] == version)
00090 return;
00091 _sdto_versions[tsid] = version;
00092 init_sections(_sdto_section_seen[tsid], last_section);
00093 }
00094 int VersionSDTo(uint tsid) const
00095 {
00096 const QMap<uint, int>::const_iterator it = _sdto_versions.find(tsid);
00097 if (it == _sdto_versions.end())
00098 return -1;
00099 return *it;
00100 }
00101
00102 void SetVersionEIT(uint tableid, uint serviceid, int version, uint last_section)
00103 {
00104 if (VersionEIT(tableid, serviceid) == version)
00105 return;
00106 uint key = (tableid << 16) | serviceid;
00107 _eit_version[key] = version;
00108 init_sections(_eit_section_seen[key], last_section);
00109 }
00110
00111 int VersionEIT(uint tableid, uint serviceid) const
00112 {
00113 uint key = (tableid << 16) | serviceid;
00114 const QMap<uint, int>::const_iterator it = _eit_version.find(key);
00115 if (it == _eit_version.end())
00116 return -1;
00117 return *it;
00118 }
00119
00120 void SetVersionBAT(uint bid, int version, uint last_section)
00121 {
00122 if (_bat_versions[bid] == version)
00123 return;
00124 _bat_versions[bid] = version;
00125 init_sections(_bat_section_seen[bid], last_section);
00126 }
00127 int VersionBAT(uint bid) const
00128 {
00129 const QMap<uint, int>::const_iterator it = _bat_versions.find(bid);
00130 if (it == _bat_versions.end())
00131 return -1;
00132 return *it;
00133 }
00134
00135
00136 void SetVersionCIT(uint contentid, int version)
00137 {
00138 if (VersionCIT(contentid) == version)
00139 return;
00140 _cit_version[contentid] = version;
00141 }
00142
00143 int VersionCIT(uint contentid) const
00144 {
00145 const QMap<uint, int>::const_iterator it = _cit_version.find(contentid);
00146 if (it == _cit_version.end())
00147 return -1;
00148 return *it;
00149 }
00150
00151
00152 void SetNITSectionSeen(uint section);
00153 bool NITSectionSeen(uint section) const;
00154 bool HasAllNITSections(void) const;
00155
00156 void SetNIToSectionSeen(uint section);
00157 bool NIToSectionSeen(uint section) const;
00158 bool HasAllNIToSections(void) const;
00159
00160 void SetSDTSectionSeen(uint tsid, uint section);
00161 bool SDTSectionSeen(uint tsid, uint section) const;
00162 bool HasAllSDTSections(uint tsid) const;
00163
00164 void SetSDToSectionSeen(uint tsid, uint section);
00165 bool SDToSectionSeen(uint tsid, uint section) const;
00166 bool HasAllSDToSections(uint tsid) const;
00167
00168 void SetEITSectionSeen(uint tableid, uint serviceid, uint section);
00169 bool EITSectionSeen(uint tableid, uint serviceid, uint section) const;
00170
00171 void SetBATSectionSeen(uint bid, uint section);
00172 bool BATSectionSeen(uint bid, uint section) const;
00173 bool HasAllBATSections(uint bid) const;
00174
00175
00176 void SetCITSectionSeen(uint contentid, uint section);
00177 bool CITSectionSeen(uint contentid, uint section) const;
00178
00179
00180 bool HasCachedAnyNIT(bool current = true) const;
00181 bool HasCachedAllNIT(bool current = true) const;
00182 bool HasCachedAnySDT(uint tsid, bool current = true) const;
00183 bool HasCachedAllSDT(uint tsid, bool current = true) const;
00184 bool HasCachedSDT(bool current = true) const;
00185 bool HasCachedAnySDTs(bool current = true) const;
00186 bool HasCachedAllSDTs(bool current = true) const;
00187
00188 const nit_ptr_t GetCachedNIT(uint section_num, bool current = true) const;
00189 const nit_vec_t GetCachedNIT(bool current = true) const;
00190 const sdt_ptr_t GetCachedSDT(uint tsid, uint section_num,
00191 bool current = true) const;
00192 const sdt_vec_t GetCachedSDTs(bool current = true) const;
00193
00194 void ReturnCachedSDTTables(sdt_vec_t&) const;
00195
00196 void AddDVBMainListener(DVBMainStreamListener*);
00197 void AddDVBOtherListener(DVBOtherStreamListener*);
00198 void AddDVBEITListener(DVBEITStreamListener*);
00199
00200 void RemoveDVBMainListener(DVBMainStreamListener*);
00201 void RemoveDVBOtherListener(DVBOtherStreamListener*);
00202 void RemoveDVBEITListener(DVBEITStreamListener*);
00203
00204 private:
00205
00206 void CacheNIT(NetworkInformationTable*);
00207 void CacheSDT(ServiceDescriptionTable*);
00208 protected:
00209 virtual bool DeleteCachedTable(PSIPTable *psip) const;
00210
00211 private:
00213 uint _desired_netid;
00214 uint _desired_tsid;
00215
00217 bool _dvb_eit_dishnet_long;
00219 dvb_has_eit_t _dvb_has_eit;
00220
00221
00222 dvb_main_listener_vec_t _dvb_main_listeners;
00223 dvb_other_listener_vec_t _dvb_other_listeners;
00224 dvb_eit_listener_vec_t _dvb_eit_listeners;
00225
00226
00227 int _nit_version;
00228 QMap<uint, int> _sdt_versions;
00229 sections_t _nit_section_seen;
00230 sections_map_t _sdt_section_seen;
00231 QMap<uint, int> _eit_version;
00232 sections_map_t _eit_section_seen;
00233
00234 QMap<uint, int> _cit_version;
00235 sections_map_t _cit_section_seen;
00236
00237 int _nito_version;
00238 QMap<uint, int> _sdto_versions;
00239 sections_t _nito_section_seen;
00240 sections_map_t _sdto_section_seen;
00241 QMap<uint, int> _bat_versions;
00242 sections_map_t _bat_section_seen;
00243
00244
00245 mutable nit_cache_t _cached_nit;
00246 mutable sdt_cache_t _cached_sdts;
00247 };
00248
00249 inline void DVBStreamData::SetDishNetEIT(bool use_dishnet_eit)
00250 {
00251 QMutexLocker locker(&_listener_lock);
00252 _dvb_eit_dishnet_long = use_dishnet_eit;
00253 }
00254
00255 inline bool DVBStreamData::HasAnyEIT(void) const
00256 {
00257 QMutexLocker locker(&_listener_lock);
00258 return _dvb_has_eit.size();
00259 }
00260
00261 inline bool DVBStreamData::HasEIT(uint serviceid) const
00262 {
00263 QMutexLocker locker(&_listener_lock);
00264
00265 dvb_has_eit_t::const_iterator it = _dvb_has_eit.find(serviceid);
00266 if (it != _dvb_has_eit.end())
00267 return *it;
00268
00269 return false;
00270 }
00271
00272 #endif // DVBSTREAMDATA_H_