- add PMT pid to program info
[enigma2.git] / lib / dvb / pmt.h
1 #ifndef __lib_dvb_dvbmid_h
2 #define __lib_dvb_dvbmid_h
3
4 #include <lib/dvb/idvb.h>
5 #include <lib/dvb/dvb.h>
6 #include <lib/dvb/idemux.h>
7 #include <lib/dvb/esection.h>
8 #include <dvbsi++/program_map_section.h>
9 #include <dvbsi++/program_association_section.h>
10
11 #include <sys/socket.h>
12 #include <sys/types.h>
13 #include <sys/un.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16
17 class eDVBServicePMTHandler;
18
19 class eDVBCAService: public Object
20 {
21         eDVBServicePMTHandler &m_parent;
22         int m_sock, m_clilen;
23         struct sockaddr_un m_servaddr;
24         unsigned int m_sendstate;
25         unsigned char *m_capmt;
26         eTimer m_retryTimer;
27         void sendCAPMT();
28         void Connect();
29 public:
30         eDVBCAService( eDVBServicePMTHandler &parent )
31                 :m_parent(parent), m_sendstate(0), m_capmt(NULL), m_retryTimer(eApp)
32         {
33                 CONNECT(m_retryTimer.timeout, eDVBCAService::sendCAPMT);
34                 Connect();
35 //              eDebug("[eDVBCAHandler] new service %s", service.toString().c_str() );
36         }
37         ~eDVBCAService()
38         {
39                 delete [] m_capmt;
40                 ::close(m_sock);
41 //              eDebug("[eDVBCAHandler] leave service %s", me.toString().c_str() );
42         }
43         void buildCAPMT();
44 };
45
46 class eDVBServicePMTHandler: public Object
47 {
48         friend class eDVBCAService;
49         eServiceReferenceDVB m_reference;
50         ePtr<eDVBService> m_service;
51
52         int m_last_channel_state;
53         uint16_t m_pmt_pid;
54         eDVBCAService *m_ca_servicePtr;
55
56         eAUTable<eTable<ProgramMapSection> > m_PMT;
57         eAUTable<eTable<ProgramAssociationSection> > m_PAT;
58
59         eUsePtr<iDVBChannel> m_channel;
60         eUsePtr<iDVBPVRChannel> m_pvr_channel;
61         ePtr<eDVBResourceManager> m_resourceManager;
62         ePtr<iDVBDemux> m_demux;
63         
64         void channelStateChanged(iDVBChannel *);
65         ePtr<eConnection> m_channelStateChanged_connection;
66
67         void PMTready(int error);
68         void PATready(int error);
69         
70         int m_record;
71 public:
72         eDVBServicePMTHandler(int record);
73         ~eDVBServicePMTHandler();
74         
75         enum
76         {
77                 eventNoResources,  // a requested resource couldn't be allocated
78                 eventNoPAT,        // no pat could be received (timeout)
79                 eventNoPATEntry,   // no pat entry for the corresponding SID could be found
80                 eventNoPMT,        // no pmt could be received (timeout)
81                 eventNewProgramInfo, // we just received a PMT
82                 eventTuned         // a channel was sucessfully (re-)tuned in, you may start additional filters now
83         };
84
85         Signal1<void,int> serviceEvent;
86         
87         struct videoStream
88         {
89                 int pid;
90         };
91         
92         struct audioStream
93         {
94                 int pid;
95                 enum { atMPEG, atAC3, atDTS };
96                 int type; // mpeg2, ac3, dts, ...
97                 // language code, ...
98         };
99         
100         struct program
101         {
102                 std::vector<videoStream> videoStreams;
103                 std::vector<audioStream> audioStreams;
104                 // ca info
105                 int pcrPid;
106                 int pmtPid;
107         };
108         
109         int getProgramInfo(struct program &program);
110         int getDemux(ePtr<iDVBDemux> &demux);
111         int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
112         
113         int tune(eServiceReferenceDVB &ref);    
114 };
115
116 #endif