fb16ea5cf7703e99f109b885d0f764b2b78f15fe
[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 <dvbsi++/program_map_section.h>
10 #include <dvbsi++/program_association_section.h>
11
12 #include <sys/socket.h>
13 #include <sys/types.h>
14 #include <sys/un.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17
18 class eDVBServicePMTHandler;
19
20 typedef std::map<eServiceReferenceDVB, eDVBCAService*> CAServiceMap;
21
22 class eDVBCAService: public Object
23 {
24         eServiceReferenceDVB m_service;
25         uint8_t m_used_demux[10];
26         unsigned int m_prev_build_hash;
27
28         int m_sock, m_clilen; 
29         struct sockaddr_un m_servaddr;
30         unsigned int m_sendstate;
31         unsigned char m_capmt[2048];
32         eTimer m_retryTimer;
33         void sendCAPMT();
34         void Connect();
35
36         static CAServiceMap exist;
37         eDVBCAService();
38         ~eDVBCAService();
39 public:
40         static RESULT register_service( const eServiceReferenceDVB &ref, int demux_num, eDVBCAService *&caservice );
41         static RESULT unregister_service( const eServiceReferenceDVB &ref, int demux_num, eTable<ProgramMapSection> *ptr );
42         void buildCAPMT(eTable<ProgramMapSection> *ptr);
43 };
44
45 class eDVBServicePMTHandler: public Object
46 {
47         friend class eDVBCAService;
48         eServiceReferenceDVB m_reference;
49         ePtr<eDVBService> m_service;
50
51         int m_last_channel_state;
52         eDVBCAService *m_ca_servicePtr;
53
54         eAUTable<eTable<ProgramMapSection> > m_PMT;
55         eAUTable<eTable<ProgramAssociationSection> > m_PAT;
56
57         eUsePtr<iDVBChannel> m_channel;
58         eUsePtr<iDVBPVRChannel> m_pvr_channel;
59         ePtr<eDVBResourceManager> m_resourceManager;
60         ePtr<iDVBDemux> m_demux;
61         
62         void channelStateChanged(iDVBChannel *);
63         ePtr<eConnection> m_channelStateChanged_connection;
64         void channelEvent(iDVBChannel *, int event);
65         ePtr<eConnection> m_channelEvent_connection;
66
67         void PMTready(int error);
68         void PATready(int error);
69         
70         int m_use_decode_demux;
71         
72 public:
73         eDVBServicePMTHandler();
74         ~eDVBServicePMTHandler();
75         
76         enum
77         {
78                 eventNoResources,  // a requested resource couldn't be allocated
79                 eventTuneFailed,   // tune failed
80                 eventNoPAT,        // no pat could be received (timeout)
81                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
82                 eventNoPMT,        // no pmt could be received (timeout)
83                 eventNewProgramInfo, // we just received a PMT
84                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
85                 
86                 eventEOF,          // a file playback did end
87         };
88
89         Signal1<void,int> serviceEvent;
90
91         struct videoStream
92         {
93                 int pid;
94                 int component_tag;
95         };
96         
97         struct audioStream
98         {
99                 int pid;
100                 enum { atMPEG, atAC3, atDTS };
101                 int type; // mpeg2, ac3, dts, ...
102                 
103                 int component_tag;
104                 std::string language_code; /* iso-639, if available. */
105         };
106         
107         struct program
108         {
109                 std::vector<videoStream> videoStreams;
110                 std::vector<audioStream> audioStreams;
111                 // ca info
112                 int pcrPid;
113                 int pmtPid;
114                 int textPid;
115                 bool isCrypted;
116         };
117         
118         int getProgramInfo(struct program &program);
119         int getDataDemux(ePtr<iDVBDemux> &demux);
120         int getDecodeDemux(ePtr<iDVBDemux> &demux);
121         
122         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
123         int getService(eServiceReferenceDVB &service) { service = m_reference; return 0; }
124         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
125         int getChannel(eUsePtr<iDVBChannel> &channel);
126
127         int tune(eServiceReferenceDVB &ref, int use_decode_demux);
128         void free();
129 };
130
131 #endif