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