rotor fix
[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 eDVBCAService;
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[32];
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_nums[2], eDVBCAService *&caservice );
41         static RESULT unregister_service( const eServiceReferenceDVB &ref, int demux_nums[2], 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         uint8_t m_decode_demux_num;
72         
73 public:
74         eDVBServicePMTHandler();
75         ~eDVBServicePMTHandler();
76         
77         enum
78         {
79                 eventNoResources,  // a requested resource couldn't be allocated
80                 eventTuneFailed,   // tune failed
81                 eventNoPAT,        // no pat could be received (timeout)
82                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
83                 eventNoPMT,        // no pmt could be received (timeout)
84                 eventNewProgramInfo, // we just received a PMT
85                 eventTuned,        // a channel was sucessfully (re-)tuned in, you may start additional filters now
86                 
87                 eventSOF,          // seek pre start
88                 eventEOF,          // a file playback did end
89         };
90
91         Signal1<void,int> serviceEvent;
92
93         struct videoStream
94         {
95                 int pid;
96                 int component_tag;
97         };
98         
99         struct audioStream
100         {
101                 int pid;
102                 enum { atMPEG, atAC3, atDTS };
103                 int type; // mpeg2, ac3, dts, ...
104                 
105                 int component_tag;
106                 std::string language_code; /* iso-639, if available. */
107         };
108         
109         struct program
110         {
111                 std::vector<videoStream> videoStreams;
112                 std::vector<audioStream> audioStreams;
113                 // ca info
114                 int pcrPid;
115                 int pmtPid;
116                 int textPid;
117                 bool isCrypted;
118         };
119         
120         int getProgramInfo(struct program &program);
121         int getDataDemux(ePtr<iDVBDemux> &demux);
122         int getDecodeDemux(ePtr<iDVBDemux> &demux);
123         
124         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
125         int getService(eServiceReferenceDVB &service) { service = m_reference; return 0; }
126         int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
127         int getChannel(eUsePtr<iDVBChannel> &channel);
128
129         int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0);
130         void free();
131 };
132
133 #endif