work on ci support
[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
65         void PMTready(int error);
66         void PATready(int error);
67         
68         int m_record;
69 public:
70         eDVBServicePMTHandler(int record);
71         ~eDVBServicePMTHandler();
72         
73         enum
74         {
75                 eventNoResources,  // a requested resource couldn't be allocated
76                 eventTuneFailed,   // tune failed
77                 eventNoPAT,        // no pat could be received (timeout)
78                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
79                 eventNoPMT,        // no pmt could be received (timeout)
80                 eventNewProgramInfo, // we just received a PMT
81                 eventTuned         // a channel was sucessfully (re-)tuned in, you may start additional filters now
82         };
83
84         Signal1<void,int> serviceEvent;
85         
86         struct videoStream
87         {
88                 int pid;
89         };
90         
91         struct audioStream
92         {
93                 int pid;
94                 enum { atMPEG, atAC3, atDTS };
95                 int type; // mpeg2, ac3, dts, ...
96                 // language code, ...
97         };
98         
99         struct program
100         {
101                 std::vector<videoStream> videoStreams;
102                 std::vector<audioStream> audioStreams;
103                 // ca info
104                 int pcrPid;
105                 int pmtPid;
106         };
107         
108         int getProgramInfo(struct program &program);
109         int getDemux(ePtr<iDVBDemux> &demux);
110         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
111         int getService(eServiceReferenceDVB &service) { service = m_reference; return 0; }
112         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
113         int getChannel(eUsePtr<iDVBChannel> &channel);
114
115         int tune(eServiceReferenceDVB &ref);
116 };
117
118 #endif