4.5.0r6
[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*, CompareService> 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         static bool truehd_support;
90
91         int m_last_channel_state;
92         eDVBCAService *m_ca_servicePtr;
93         ePtr<eDVBScan> m_dvb_scan; // for sdt scan
94
95         eAUTable<eTable<ProgramMapSection> > m_PMT;
96         eAUTable<eTable<ProgramAssociationSection> > m_PAT;
97
98         ePtr<eConnection> m_SDTConn;
99         ePtr<iDVBSectionReader> m_SDTReader;
100         void readSDTdata(const __u8 *data, int len);
101
102         eUsePtr<iDVBChannel> m_channel;
103         eUsePtr<iDVBPVRChannel> m_pvr_channel;
104         ePtr<eDVBResourceManager> m_resourceManager;
105         ePtr<iDVBDemux> m_demux;
106         bool m_first_tune;
107
108         void channelStateChanged(iDVBChannel *);
109         ePtr<eConnection> m_channelStateChanged_connection;
110         void channelEvent(iDVBChannel *, int event);
111         ePtr<eConnection> m_channelEvent_connection;
112         void SDTScanEvent(int);
113         ePtr<eConnection> m_scan_event_connection;
114         void channelSourceEvent(int, std::string);
115         ePtr<eConnection> m_channelSourceEvent_connection;
116
117         void PMTready(int error);
118         void PATready(int error);
119         
120         int m_pmt_pid;
121
122         int m_use_decode_demux;
123         uint8_t m_decode_demux_num;
124         ePtr<eTimer> m_no_pat_entry_delay;
125 public:
126         eDVBServicePMTHandler();
127         ~eDVBServicePMTHandler();
128 #endif
129
130 #ifdef SWIG
131 private:
132         eDVBServicePMTHandler();
133 public:
134 #endif
135         static void setDDPSupport(bool b) { ddp_support = b; }
136         static void setTrueHDSupport(bool b) { truehd_support = b; }
137
138         enum
139         {
140                 eventNoResources,  // a requested resource couldn't be allocated
141                 eventTuneFailed,   // tune failed
142                 eventNoPAT,        // no pat could be received (timeout)
143                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
144                 eventNoPMT,        // no pmt could be received (timeout)
145                 eventNewProgramInfo, // we just received a PMT
146                 eventUpdateDecoder, // is sent directly after tune start to speedup picture view...
147                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
148                 eventNewSDT,
149
150                 eventPreStart,     // before start filepush thread
151                 eventSOF,          // seek pre start
152                 eventEOF,          // a file playback did end
153                 
154                 eventMisconfiguration, // a channel was not found in any list, or no frontend was found which could provide this channel
155         };
156 #ifndef SWIG
157         sigc::signal1<void,int> serviceEvent;
158         sigc::signal2<void,int,std::string> sourceEvent;
159
160         struct videoStream
161         {
162                 int pid;
163                 int component_tag;
164                 enum { vtMPEG2, vtMPEG4_H264, vtMPEG1, vtMPEG4_Part2, vtVC1, vtVC1_SM, vtH265 };
165                 int type;
166         };
167         
168         struct audioStream
169         {
170                 int pid,
171                     rdsPid; // hack for some radio services which transmit radiotext on different pid (i.e. harmony fm, HIT RADIO FFH, ...)
172                 int type; // mpeg2, ac3, dts, ... as defined in iAudioType_ENUMS
173                 int component_tag;
174                 std::string language_code; /* iso-639, if available. */
175         };
176
177         struct subtitleStream
178         {
179                 int pid;
180                 int subtitling_type;    /*  see ETSI EN 300 468 table 26 component_type
181                                                                         when stream_content is 0x03
182                                                                         0x10..0x13, 0x20..0x23 is used for dvb subtitles
183                                                                         0x01 is used for teletext subtitles */
184                 union
185                 {
186                         int composition_page_id;  // used for dvb subtitles
187                         int teletext_page_number;  // used for teletext subtitles
188                 };
189                 union
190                 {
191                         int ancillary_page_id;  // used for dvb subtitles
192                         int teletext_magazine_number;  // used for teletext subtitles
193                 };
194                 std::string language_code;
195                 bool operator<(const subtitleStream &s) const
196                 {
197                         if (pid != s.pid)
198                                 return pid < s.pid;
199                         if (teletext_page_number != s.teletext_page_number)
200                                 return teletext_page_number < s.teletext_page_number;
201                         return teletext_magazine_number < s.teletext_magazine_number;
202                 }
203         };
204
205         struct aitStream
206         {
207                 int pid;
208                 std::vector<std::pair<int, int> > type_version_pairs;
209         };
210
211         struct program
212         {
213                 struct capid_pair
214                 {
215                         uint16_t caid;
216                         int capid;
217                         bool operator< (const struct capid_pair &t) const { return t.caid < caid; }
218                 };
219                 std::vector<videoStream> videoStreams;
220                 std::vector<audioStream> audioStreams;
221                 int savedAudioStream;
222                 std::vector<subtitleStream> subtitleStreams;
223                 std::vector<aitStream> aitStreams;
224                 std::list<capid_pair> caids;
225                 int pcrPid;
226                 int pmtPid;
227                 int textPid;
228                 bool isCrypted() { return !caids.empty(); }
229                 std::map<std::string, boost::any> createDataMap(bool includeAitEit=true);
230         };
231
232         int getProgramInfo(program &program);
233         int getDataDemux(ePtr<iDVBDemux> &demux);
234         int getDecodeDemux(ePtr<iDVBDemux> &demux);
235         boost::any getCaIds(bool pair=false); // caid / ecmpid pair
236         
237         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
238         int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
239         int getService(ePtr<eDVBService> &service) { service = m_service; return 0; }
240         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
241         int getChannel(eUsePtr<iDVBChannel> &channel);
242         void resetCachedProgram() { m_have_cached_program = false; }
243         void sendEventNoPatEntry();
244
245         /* deprecated interface */
246         int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
247
248         /* new interface */
249         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);
250
251         void free();
252 private:
253         bool m_have_cached_program;
254         program m_cached_program;
255 #endif
256 };
257
258 #endif