4.3.1r21
[enigma2.git] / usr / include / enigma2 / lib / dvb / pmt.h
1 #ifndef __lib_dvb_dvbmid_h
2 #define __lib_dvb_dvbmid_h
3
4 #ifndef SWIG
5 #include <map>
6 #include <set>
7 #include <lib/base/buffer.h>
8 #include <lib/components/file_monitor.h>
9 #include <lib/dvb/idvb.h>
10 #include <lib/dvb/dvb.h>
11 #include <lib/dvb/idemux.h>
12 #include <lib/dvb/esection.h>
13 #include <lib/python/python.h>
14 #include <dvbsi++/program_map_section.h>
15 #include <dvbsi++/program_association_section.h>
16
17 #include <sys/socket.h>
18 #include <sys/types.h>
19 #include <sys/un.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22
23 #include <boost/any.hpp>
24
25 class eDVBCAService;
26 class eDVBScan;
27
28 struct channel_data: public sigc::trackable
29  {
30         ePtr<eDVBChannel> m_channel;
31         ePtr<eConnection> m_stateChangedConn;
32         int m_prevChannelState;
33         int m_dataDemux;
34 };
35
36 typedef std::map<eServiceReferenceDVB, eDVBCAService*> CAServiceMap;
37 typedef std::map<iDVBChannel*, channel_data*> ChannelMap;
38
39 class eDVBCAServiceConn;
40 typedef std::list<eFileWatch *> FileWatchList;
41 typedef std::map<std::string, eDVBCAServiceConn*> CAServiceConnMap;
42 typedef std::set<std::string> CASocketSet;
43
44 class eDVBCAService: public sigc::trackable
45 {
46         friend class eDVBCAServiceConn;
47
48         eServiceReferenceDVB m_service;
49         uint8_t m_used_demux[32];
50
51         bool m_first;
52         unsigned char m_capmt[2048];
53
54         void recheckConnections();
55         void sendCAPMT();
56
57         static void DVBChannelAdded(eDVBChannel*);
58         static void DVBChannelStateChanged(iDVBChannel*);
59         static CAServiceMap exist;
60         static ChannelMap exist_channels;
61         static ePtr<eConnection> m_chanAddedConn;
62         static channel_data *getChannelData(eDVBChannelID &chid);
63         static FileWatchList active_watches;
64         static CASocketSet available_sockets;
65
66         CAServiceConnMap active_connections;
67
68         eDVBCAService();
69         ~eDVBCAService();
70 public:
71         static void fileWatchEventCB(eFileWatch *, eFileEvent);
72         static void registerChannelCallback(eDVBResourceManager *res_mgr);
73         static RESULT register_service( const eServiceReferenceDVB &ref, int demux_nums[2], eDVBCAService *&caservice );
74         static RESULT unregister_service( const eServiceReferenceDVB &ref, int demux_nums[2], eTable<ProgramMapSection> *ptr, int tuner_no );
75         void buildCAPMT(eTable<ProgramMapSection> *ptr, bool haveCaIds, int tuner_no);
76 };
77
78 #endif
79
80 class eDVBServicePMTHandler: public sigc::trackable
81 {
82 #ifndef SWIG
83         friend class eDVBCAService;
84         eServiceReferenceDVB m_reference;
85         ePtr<eDVBService> m_service;
86
87         static std::map<uint32_t, uint8_t> sdt_versions;
88         static bool ddp_support;
89
90         int m_last_channel_state;
91         eDVBCAService *m_ca_servicePtr;
92         ePtr<eDVBScan> m_dvb_scan; // for sdt scan
93
94         eAUTable<eTable<ProgramMapSection> > m_PMT;
95         eAUTable<eTable<ProgramAssociationSection> > m_PAT;
96
97         ePtr<eConnection> m_SDTConn;
98         ePtr<iDVBSectionReader> m_SDTReader;
99         void readSDTdata(const __u8 *data, int len);
100
101         eUsePtr<iDVBChannel> m_channel;
102         eUsePtr<iDVBPVRChannel> m_pvr_channel;
103         ePtr<eDVBResourceManager> m_resourceManager;
104         ePtr<iDVBDemux> m_demux;
105         bool m_first_tune;
106
107         void channelStateChanged(iDVBChannel *);
108         ePtr<eConnection> m_channelStateChanged_connection;
109         void channelEvent(iDVBChannel *, int event);
110         ePtr<eConnection> m_channelEvent_connection;
111         void SDTScanEvent(int);
112         ePtr<eConnection> m_scan_event_connection;
113         void channelSourceEvent(int, std::string);
114         ePtr<eConnection> m_channelSourceEvent_connection;
115
116         void PMTready(int error);
117         void PATready(int error);
118         
119         int m_pmt_pid;
120
121         int m_use_decode_demux;
122         uint8_t m_decode_demux_num;
123         ePtr<eTimer> m_no_pat_entry_delay;
124 public:
125         eDVBServicePMTHandler();
126         ~eDVBServicePMTHandler();
127 #endif
128
129 #ifdef SWIG
130 private:
131         eDVBServicePMTHandler();
132 public:
133 #endif
134         static void setDDPSupport(bool b) { ddp_support = b; }
135
136         enum
137         {
138                 eventNoResources,  // a requested resource couldn't be allocated
139                 eventTuneFailed,   // tune failed
140                 eventNoPAT,        // no pat could be received (timeout)
141                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
142                 eventNoPMT,        // no pmt could be received (timeout)
143                 eventNewProgramInfo, // we just received a PMT
144                 eventUpdateDecoder, // is sent directly after tune start to speedup picture view...
145                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
146                 eventNewSDT,
147
148                 eventPreStart,     // before start filepush thread
149                 eventSOF,          // seek pre start
150                 eventEOF,          // a file playback did end
151                 
152                 eventMisconfiguration, // a channel was not found in any list, or no frontend was found which could provide this channel
153         };
154 #ifndef SWIG
155         sigc::signal1<void,int> serviceEvent;
156         sigc::signal2<void,int,std::string> sourceEvent;
157
158         struct videoStream
159         {
160                 int pid;
161                 int component_tag;
162                 enum { vtMPEG2, vtMPEG4_H264, vtMPEG1, vtMPEG4_Part2, vtVC1, vtVC1_SM, vtH265 };
163                 int type;
164         };
165         
166         struct audioStream
167         {
168                 int pid,
169                     rdsPid; // hack for some radio services which transmit radiotext on different pid (i.e. harmony fm, HIT RADIO FFH, ...)
170                 int type; // mpeg2, ac3, dts, ... as defined in iAudioType_ENUMS
171                 int component_tag;
172                 std::string language_code; /* iso-639, if available. */
173         };
174
175         struct subtitleStream
176         {
177                 int pid;
178                 int subtitling_type;    /*  see ETSI EN 300 468 table 26 component_type
179                                                                         when stream_content is 0x03
180                                                                         0x10..0x13, 0x20..0x23 is used for dvb subtitles
181                                                                         0x01 is used for teletext subtitles */
182                 union
183                 {
184                         int composition_page_id;  // used for dvb subtitles
185                         int teletext_page_number;  // used for teletext subtitles
186                 };
187                 union
188                 {
189                         int ancillary_page_id;  // used for dvb subtitles
190                         int teletext_magazine_number;  // used for teletext subtitles
191                 };
192                 std::string language_code;
193                 bool operator<(const subtitleStream &s) const
194                 {
195                         if (pid != s.pid)
196                                 return pid < s.pid;
197                         if (teletext_page_number != s.teletext_page_number)
198                                 return teletext_page_number < s.teletext_page_number;
199                         return teletext_magazine_number < s.teletext_magazine_number;
200                 }
201         };
202
203         struct aitStream
204         {
205                 int pid;
206                 std::vector<std::pair<int, int> > type_version_pairs;
207         };
208
209         struct program
210         {
211                 struct capid_pair
212                 {
213                         uint16_t caid;
214                         int capid;
215                         bool operator< (const struct capid_pair &t) const { return t.caid < caid; }
216                 };
217                 std::vector<videoStream> videoStreams;
218                 std::vector<audioStream> audioStreams;
219                 int savedAudioStream;
220                 std::vector<subtitleStream> subtitleStreams;
221                 std::vector<aitStream> aitStreams;
222                 std::list<capid_pair> caids;
223                 int pcrPid;
224                 int pmtPid;
225                 int textPid;
226                 bool isCrypted() { return !caids.empty(); }
227                 std::map<std::string, boost::any> createDataMap(bool includeEit=true);
228         };
229
230         int getProgramInfo(program &program);
231         int getDataDemux(ePtr<iDVBDemux> &demux);
232         int getDecodeDemux(ePtr<iDVBDemux> &demux);
233         boost::any getCaIds(bool pair=false); // caid / ecmpid pair
234         
235         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
236         int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
237         int getService(ePtr<eDVBService> &service) { service = m_service; return 0; }
238         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
239         int getChannel(eUsePtr<iDVBChannel> &channel);
240         void resetCachedProgram() { m_have_cached_program = false; }
241         void sendEventNoPatEntry();
242
243         /* deprecated interface */
244         int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
245
246         /* new interface */
247         int tuneExt(eServiceReferenceDVB &ref, int use_decode_demux, sigc::slot1<ePtr<iTsSource>, const eServiceReferenceDVB&> createTsSource, const char *streaminfo_file, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
248
249         void free();
250 private:
251         bool m_have_cached_program;
252         program m_cached_program;
253 #endif
254 };
255
256 #endif