InfoBarGenerics.py: fix handling for unused key indication when two times the same...
[enigma2.git] / 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 <lib/base/buffer.h>
7 #include <lib/dvb/idvb.h>
8 #include <lib/dvb/dvb.h>
9 #include <lib/dvb/idemux.h>
10 #include <lib/dvb/esection.h>
11 #include <lib/python/python.h>
12 #include <dvbsi++/program_map_section.h>
13 #include <dvbsi++/program_association_section.h>
14
15 #include <sys/socket.h>
16 #include <sys/types.h>
17 #include <sys/un.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20
21 class eDVBCAService;
22 class eDVBScan;
23
24 struct channel_data: public Object
25 {
26         ePtr<eDVBChannel> m_channel;
27         ePtr<eConnection> m_stateChangedConn;
28         int m_prevChannelState;
29         int m_dataDemux;
30 };
31
32 // TODO .. put all static stuff into a 'eDVBCAServiceHandler class'
33
34 typedef std::map<eServiceReferenceDVB, eDVBCAService*> CAServiceMap;
35 typedef std::map<iDVBChannel*, channel_data*> ChannelMap;
36
37 class eDVBCAService: public Object
38 {
39         eIOBuffer m_buffer;
40         ePtr<eSocketNotifier> m_sn;
41         eServiceReferenceDVB m_service;
42         uint8_t m_used_demux[32];
43         unsigned int m_prev_build_hash;
44
45         int m_sock, m_clilen; 
46         struct sockaddr_un m_servaddr;
47         unsigned int m_sendstate;
48         unsigned char m_capmt[2048];
49         ePtr<eTimer> m_retryTimer;
50         void sendCAPMT();
51         void Connect();
52         void socketCB(int what);
53
54         static void DVBChannelAdded(eDVBChannel*);
55         static void DVBChannelStateChanged(iDVBChannel*);
56         static CAServiceMap exist;
57         static ChannelMap exist_channels;
58         static ePtr<eConnection> m_chanAddedConn;
59         static channel_data *getChannelData(eDVBChannelID &chid);
60
61         eDVBCAService();
62         ~eDVBCAService();
63 public:
64         static void registerChannelCallback(eDVBResourceManager *res_mgr);
65         static RESULT register_service( const eServiceReferenceDVB &ref, int demux_nums[2], eDVBCAService *&caservice );
66         static RESULT unregister_service( const eServiceReferenceDVB &ref, int demux_nums[2], eTable<ProgramMapSection> *ptr );
67         void buildCAPMT(eTable<ProgramMapSection> *ptr);
68 };
69
70 #endif
71
72 class eDVBServicePMTHandler: public Object
73 {
74 #ifndef SWIG
75         friend class eDVBCAService;
76         eServiceReferenceDVB m_reference;
77         ePtr<eDVBService> m_service;
78
79         int m_last_channel_state;
80         eDVBCAService *m_ca_servicePtr;
81         ePtr<eDVBScan> m_dvb_scan; // for sdt scan
82
83         eAUTable<eTable<ProgramMapSection> > m_PMT;
84         eAUTable<eTable<ProgramAssociationSection> > m_PAT;
85
86         eUsePtr<iDVBChannel> m_channel;
87         eUsePtr<iDVBPVRChannel> m_pvr_channel;
88         ePtr<eDVBResourceManager> m_resourceManager;
89         ePtr<iDVBDemux> m_demux;
90         
91         void channelStateChanged(iDVBChannel *);
92         ePtr<eConnection> m_channelStateChanged_connection;
93         void channelEvent(iDVBChannel *, int event);
94         ePtr<eConnection> m_channelEvent_connection;
95         void SDTScanEvent(int);
96         ePtr<eConnection> m_scan_event_connection;
97
98         void PMTready(int error);
99         void PATready(int error);
100         
101         int m_pmt_pid;
102         
103         int m_use_decode_demux;
104         uint8_t m_decode_demux_num;
105 public:
106         eDVBServicePMTHandler();
107         ~eDVBServicePMTHandler();
108 #endif
109
110 #ifdef SWIG
111 private:
112         eDVBServicePMTHandler();
113 public:
114 #endif
115
116         enum
117         {
118                 eventNoResources,  // a requested resource couldn't be allocated
119                 eventTuneFailed,   // tune failed
120                 eventNoPAT,        // no pat could be received (timeout)
121                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
122                 eventNoPMT,        // no pmt could be received (timeout)
123                 eventNewProgramInfo, // we just received a PMT
124                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
125                 
126                 eventPreStart,     // before start filepush thread
127                 eventSOF,          // seek pre start
128                 eventEOF,          // a file playback did end
129                 
130                 eventMisconfiguration, // a channel was not found in any list, or no frontend was found which could provide this channel
131         };
132 #ifndef SWIG
133         Signal1<void,int> serviceEvent;
134
135         struct videoStream
136         {
137                 int pid;
138                 int component_tag;
139                 enum { vtMPEG2, vtMPEG4_H264, vtMPEG1, vtMPEG4_Part2, vtVC1, vtVC1_SM };
140                 int type;
141         };
142         
143         struct audioStream
144         {
145                 int pid,
146                     rdsPid; // hack for some radio services which transmit radiotext on different pid (i.e. harmony fm, HIT RADIO FFH, ...)
147                 enum { atMPEG, atAC3, atDTS, atAAC, atAACHE, atLPCM };
148                 int type; // mpeg2, ac3, dts, ...
149                 
150                 int component_tag;
151                 std::string language_code; /* iso-639, if available. */
152         };
153
154         struct subtitleStream
155         {
156                 int pid;
157                 int subtitling_type;    /*  see ETSI EN 300 468 table 26 component_type
158                                                                         when stream_content is 0x03
159                                                                         0x10..0x13, 0x20..0x23 is used for dvb subtitles
160                                                                         0x01 is used for teletext subtitles */
161                 union
162                 {
163                         int composition_page_id;  // used for dvb subtitles
164                         int teletext_page_number;  // used for teletext subtitles
165                 };
166                 union
167                 {
168                         int ancillary_page_id;  // used for dvb subtitles
169                         int teletext_magazine_number;  // used for teletext subtitles
170                 };
171                 std::string language_code;
172                 bool operator<(const subtitleStream &s) const
173                 {
174                         if (pid != s.pid)
175                                 return pid < s.pid;
176                         if (teletext_page_number != s.teletext_page_number)
177                                 return teletext_page_number < s.teletext_page_number;
178                         return teletext_magazine_number < s.teletext_magazine_number;
179                 }
180         };
181
182         struct program
183         {
184                 std::vector<videoStream> videoStreams;
185                 std::vector<audioStream> audioStreams;
186                 int defaultAudioStream;
187                 std::vector<subtitleStream> subtitleStreams;
188                 std::set<uint16_t> caids;
189                 int pcrPid;
190                 int pmtPid;
191                 int textPid;
192                 bool isCrypted() { return !caids.empty(); }
193                 PyObject *createPythonObject();
194         };
195
196         int getProgramInfo(struct program &program);
197         int getDataDemux(ePtr<iDVBDemux> &demux);
198         int getDecodeDemux(ePtr<iDVBDemux> &demux);
199         PyObject *getCaIds();
200         
201         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
202         int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
203         int getService(ePtr<eDVBService> &service) { service = m_service; return 0; }
204         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
205         int getChannel(eUsePtr<iDVBChannel> &channel);
206         void resetCachedProgram() { m_have_cached_program = false; }
207
208         int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
209         void free();
210 private:
211         bool m_have_cached_program;
212         program m_cached_program;
213 #endif
214 };
215
216 #endif