enigma2 (20101216 rel31 -> 20110928 rel32)
[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 <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, m_pvr_demux_tmp;
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         ePtr<eTimer> m_no_pat_entry_delay;
106 public:
107         eDVBServicePMTHandler();
108         ~eDVBServicePMTHandler();
109 #endif
110
111 #ifdef SWIG
112 private:
113         eDVBServicePMTHandler();
114 public:
115 #endif
116
117         enum
118         {
119                 eventNoResources,  // a requested resource couldn't be allocated
120                 eventTuneFailed,   // tune failed
121                 eventNoPAT,        // no pat could be received (timeout)
122                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
123                 eventNoPMT,        // no pmt could be received (timeout)
124                 eventNewProgramInfo, // we just received a PMT
125                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
126                 
127                 eventPreStart,     // before start filepush thread
128                 eventSOF,          // seek pre start
129                 eventEOF,          // a file playback did end
130                 
131                 eventMisconfiguration, // a channel was not found in any list, or no frontend was found which could provide this channel
132         };
133 #ifndef SWIG
134         Signal1<void,int> serviceEvent;
135
136         struct videoStream
137         {
138                 int pid;
139                 int component_tag;
140                 enum { vtMPEG2, vtMPEG4_H264, vtMPEG1, vtMPEG4_Part2, vtVC1, vtVC1_SM };
141                 int type;
142         };
143         
144         struct audioStream
145         {
146                 int pid,
147                     rdsPid; // hack for some radio services which transmit radiotext on different pid (i.e. harmony fm, HIT RADIO FFH, ...)
148                 enum { atMPEG, atAC3, atDTS, atAAC, atAACHE, atLPCM, atDTSHD };
149                 int type; // mpeg2, ac3, dts, ...
150                 
151                 int component_tag;
152                 std::string language_code; /* iso-639, if available. */
153         };
154
155         struct subtitleStream
156         {
157                 int pid;
158                 int subtitling_type;    /*  see ETSI EN 300 468 table 26 component_type
159                                                                         when stream_content is 0x03
160                                                                         0x10..0x13, 0x20..0x23 is used for dvb subtitles
161                                                                         0x01 is used for teletext subtitles */
162                 union
163                 {
164                         int composition_page_id;  // used for dvb subtitles
165                         int teletext_page_number;  // used for teletext subtitles
166                 };
167                 union
168                 {
169                         int ancillary_page_id;  // used for dvb subtitles
170                         int teletext_magazine_number;  // used for teletext subtitles
171                 };
172                 std::string language_code;
173                 bool operator<(const subtitleStream &s) const
174                 {
175                         if (pid != s.pid)
176                                 return pid < s.pid;
177                         if (teletext_page_number != s.teletext_page_number)
178                                 return teletext_page_number < s.teletext_page_number;
179                         return teletext_magazine_number < s.teletext_magazine_number;
180                 }
181         };
182
183         struct program
184         {
185                 struct capid_pair
186                 {
187                         uint16_t caid;
188                         int capid;
189                         bool operator< (const struct capid_pair &t) const { return t.caid < caid; }
190                 };
191                 std::vector<videoStream> videoStreams;
192                 std::vector<audioStream> audioStreams;
193                 int defaultAudioStream;
194                 std::vector<subtitleStream> subtitleStreams;
195                 std::list<capid_pair> caids;
196                 int pcrPid;
197                 int pmtPid;
198                 int textPid;
199                 bool isCrypted() { return !caids.empty(); }
200                 PyObject *createPythonObject();
201         };
202
203         int getProgramInfo(program &program);
204         int getDataDemux(ePtr<iDVBDemux> &demux);
205         int getDecodeDemux(ePtr<iDVBDemux> &demux);
206         PyObject *getCaIds(bool pair=false); // caid / ecmpid pair
207         
208         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
209         int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
210         int getService(ePtr<eDVBService> &service) { service = m_service; return 0; }
211         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
212         int getChannel(eUsePtr<iDVBChannel> &channel);
213         void resetCachedProgram() { m_have_cached_program = false; }
214         void sendEventNoPatEntry();
215
216         /* deprecated interface */
217         int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
218
219         /* new interface */
220         int tuneExt(eServiceReferenceDVB &ref, int use_decode_demux, Slot1<ePtr<iTsSource>, const eServiceReferenceDVB&> createTsSource, const char *streaminfo_file, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
221
222         void free();
223 private:
224         bool m_have_cached_program;
225         program m_cached_program;
226 #endif
227 };
228
229 #endif