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