1 #ifndef __lib_dvb_dvbmid_h
2 #define __lib_dvb_dvbmid_h
6 #include <lib/base/buffer.h>
7 #include <lib/dvb/idvb.h>
8 #include <lib/dvb/dvb.h>
9 #include <lib/dvb/idemux.h>
10 #include <lib/dvb/esection.h>
11 #include <lib/python/python.h>
12 #include <lib/python/connections.h>
13 #include <dvbsi++/program_map_section.h>
14 #include <dvbsi++/program_association_section.h>
16 #include <sys/socket.h>
17 #include <sys/types.h>
25 #include <dvbsi++/application_information_section.h>
26 class OCSection : public LongCrcSection
32 OCSection(const uint8_t * const buffer)
33 : LongCrcSection(buffer)
35 data = malloc(getSectionLength());
36 memcpy(data, buffer, getSectionLength());
42 void *getData() { return data; }
45 struct channel_data: public Object
47 ePtr<eDVBChannel> m_channel;
48 ePtr<eConnection> m_stateChangedConn;
49 int m_prevChannelState;
53 // TODO .. put all static stuff into a 'eDVBCAServiceHandler class'
55 typedef std::map<eServiceReferenceDVB, eDVBCAService*> CAServiceMap;
56 typedef std::map<iDVBChannel*, channel_data*> ChannelMap;
58 class eDVBCAService: public Object
61 ePtr<eSocketNotifier> m_sn;
62 eServiceReferenceDVB m_service;
63 uint8_t m_used_demux[32];
64 unsigned int m_prev_build_hash;
67 struct sockaddr_un m_servaddr;
68 unsigned int m_sendstate;
69 unsigned char m_capmt[2048];
70 ePtr<eTimer> m_retryTimer;
73 void socketCB(int what);
75 static void DVBChannelAdded(eDVBChannel*);
76 static void DVBChannelStateChanged(iDVBChannel*);
77 static CAServiceMap exist;
78 static ChannelMap exist_channels;
79 static ePtr<eConnection> m_chanAddedConn;
80 static channel_data *getChannelData(eDVBChannelID &chid);
85 static void registerChannelCallback(eDVBResourceManager *res_mgr);
86 static RESULT register_service( const eServiceReferenceDVB &ref, int demux_nums[2], eDVBCAService *&caservice );
87 static RESULT unregister_service( const eServiceReferenceDVB &ref, int demux_nums[2], eTable<ProgramMapSection> *ptr );
88 void buildCAPMT(eTable<ProgramMapSection> *ptr);
95 class HbbTVApplicationInfo
102 std::string m_HbbTVUrl;
103 std::string m_ApplicationName;
105 HbbTVApplicationInfo(int controlCode, int orgid, int appid, std::string hbbtvUrl, std::string applicationName, int profileCode)
106 : m_ControlCode(controlCode), m_HbbTVUrl(hbbtvUrl), m_ApplicationName(applicationName), m_OrgId(orgid),
107 m_AppId(appid), m_ProfileCode(profileCode)
110 typedef std::list<HbbTVApplicationInfo *> HbbTVApplicationInfoList;
111 typedef HbbTVApplicationInfoList::iterator HbbTVApplicationInfoListIterator;
112 typedef HbbTVApplicationInfoList::const_iterator HbbTVApplicationInfoListConstIterator;
114 class eDVBServicePMTHandler: public Object
117 friend class eDVBCAService;
118 eServiceReferenceDVB m_reference;
119 ePtr<eDVBService> m_service;
121 int m_last_channel_state;
122 eDVBCAService *m_ca_servicePtr;
123 ePtr<eDVBScan> m_dvb_scan; // for sdt scan
125 eAUTable<eTable<ProgramMapSection> > m_PMT;
126 eAUTable<eTable<ProgramAssociationSection> > m_PAT;
128 eUsePtr<iDVBChannel> m_channel;
129 eUsePtr<iDVBPVRChannel> m_pvr_channel;
130 ePtr<eDVBResourceManager> m_resourceManager;
131 ePtr<iDVBDemux> m_demux, m_pvr_demux_tmp;
133 void channelStateChanged(iDVBChannel *);
134 ePtr<eConnection> m_channelStateChanged_connection;
135 void channelEvent(iDVBChannel *, int event);
136 ePtr<eConnection> m_channelEvent_connection;
137 void SDTScanEvent(int);
138 ePtr<eConnection> m_scan_event_connection;
140 eAUTable<eTable<ApplicationInformationSection> > m_AIT;
141 eAUTable<eTable<OCSection> > m_OC;
143 void PMTready(int error);
144 void PATready(int error);
148 void AITready(int error);
149 void OCready(int error);
152 HbbTVApplicationInfoList m_HbbTVApplications;
153 std::string m_HBBTVUrl;
154 std::string m_ApplicationName;
155 unsigned char m_AITData[4096];
157 int m_use_decode_demux;
158 uint8_t m_decode_demux_num;
159 ePtr<eTimer> m_no_pat_entry_delay;
161 eDVBServicePMTHandler();
162 ~eDVBServicePMTHandler();
167 eDVBServicePMTHandler();
173 eventNoResources, // a requested resource couldn't be allocated
174 eventTuneFailed, // tune failed
175 eventNoPAT, // no pat could be received (timeout)
176 eventNoPATEntry, // no pat entry for the corresponding SID could be found
177 eventNoPMT, // no pmt could be received (timeout)
178 eventNewProgramInfo, // we just received a PMT
179 eventTuned, // a channel was sucessfully (re-)tuned in, you may start additional filters now
181 eventPreStart, // before start filepush thread
182 eventSOF, // seek pre start
183 eventEOF, // a file playback did end
185 eventHBBTVInfo, /* HBBTV information was detected in the AIT */
187 eventMisconfiguration, // a channel was not found in any list, or no frontend was found which could provide this channel
190 Signal1<void,int> serviceEvent;
196 enum { vtMPEG2, vtMPEG4_H264, vtMPEG1, vtMPEG4_Part2, vtVC1, vtVC1_SM };
203 rdsPid; // hack for some radio services which transmit radiotext on different pid (i.e. harmony fm, HIT RADIO FFH, ...)
204 enum { atMPEG, atAC3, atDTS, atAAC, atAACHE, atLPCM, atDTSHD, atDDP };
205 int type; // mpeg2, ac3, dts, ...
208 std::string language_code; /* iso-639, if available. */
211 struct subtitleStream
214 int subtitling_type; /* see ETSI EN 300 468 table 26 component_type
215 when stream_content is 0x03
216 0x10..0x13, 0x20..0x23 is used for dvb subtitles
217 0x01 is used for teletext subtitles */
220 int composition_page_id; // used for dvb subtitles
221 int teletext_page_number; // used for teletext subtitles
225 int ancillary_page_id; // used for dvb subtitles
226 int teletext_magazine_number; // used for teletext subtitles
228 std::string language_code;
229 bool operator<(const subtitleStream &s) const
233 if (teletext_page_number != s.teletext_page_number)
234 return teletext_page_number < s.teletext_page_number;
235 return teletext_magazine_number < s.teletext_magazine_number;
245 bool operator< (const struct capid_pair &t) const { return t.caid < caid; }
247 std::vector<videoStream> videoStreams;
248 std::vector<audioStream> audioStreams;
249 int defaultAudioStream;
250 std::vector<subtitleStream> subtitleStreams;
251 std::list<capid_pair> caids;
256 bool isCrypted() { return !caids.empty(); }
257 PyObject *createPythonObject();
260 int getProgramInfo(program &program);
261 int getDataDemux(ePtr<iDVBDemux> &demux);
262 int getDecodeDemux(ePtr<iDVBDemux> &demux);
263 PyObject *getCaIds(bool pair=false); // caid / ecmpid pair
264 PyObject *getHbbTVApplications(void);
266 int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
267 int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
268 int getService(ePtr<eDVBService> &service) { service = m_service; return 0; }
269 int getPMT(ePtr<eTable<ProgramMapSection> > &ptr) { return m_PMT.getCurrent(ptr); }
270 int getChannel(eUsePtr<iDVBChannel> &channel);
271 void resetCachedProgram() { m_have_cached_program = false; }
272 void sendEventNoPatEntry();
274 void getHBBTVUrl(std::string &ret) { ret = m_HBBTVUrl; }
276 /* deprecated interface */
277 int tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0);
280 int tuneExt(eServiceReferenceDVB &ref, int use_decode_demux, ePtr<iTsSource> &, const char *streaminfo_file, eCueSheet *sg=0, bool simulate=false, eDVBService *service = 0, bool isstreamclient=false);
284 bool m_have_cached_program;
285 program m_cached_program;
286 bool m_isstreamclient;