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