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