Merge branch 'master' of /home/tmbinc/enigma2-git into tmbinc/FixTimingBugs
[vuplus_dvbapp] / lib / service / servicedvb.h
1 #ifndef __servicedvb_h
2 #define __servicedvb_h
3
4 #include <lib/service/iservice.h>
5 #include <lib/dvb/idvb.h>
6
7 #include <lib/dvb/pmt.h>
8 #include <lib/dvb/eit.h>
9 #include <lib/dvb/subtitle.h>
10 #include <lib/dvb/teletext.h>
11 #include <lib/dvb/radiotext.h>
12 #include <lib/base/filepush.h>
13
14 class eStaticServiceDVBInformation;
15 class eStaticServiceDVBBouquetInformation;
16
17 class eServiceFactoryDVB: public iServiceHandler
18 {
19         DECLARE_REF(eServiceFactoryDVB);
20         ePtr<eStaticServiceDVBInformation> m_StaticServiceDVBInfo;
21         ePtr<eStaticServiceDVBBouquetInformation> m_StaticServiceDVBBouquetInfo;
22 public:
23         eServiceFactoryDVB();
24         virtual ~eServiceFactoryDVB();
25         enum { id = 0x1 };
26
27                 // iServiceHandler
28         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
29         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
30         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
31         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
32         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
33 private:
34         RESULT lookupService(ePtr<eDVBService> &ptr, const eServiceReference &ref);
35 };
36
37 class eBouquet;
38
39 class eDVBServiceList: public iListableService, public iMutableServiceList
40 {
41         DECLARE_REF(eDVBServiceList);
42 public:
43         virtual ~eDVBServiceList();
44         PyObject *getContent(const char* formatstr, bool sorted=false);
45         RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
46         RESULT getNext(eServiceReference &ptr);
47         inline int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
48         
49         RESULT startEdit(ePtr<iMutableServiceList> &);
50         RESULT flushChanges();
51         RESULT addService(eServiceReference &ref, eServiceReference before);
52         RESULT removeService(eServiceReference &ref);
53         RESULT moveService(eServiceReference &ref, int pos);
54         RESULT setListName(const std::string &name);
55 private:
56         RESULT startQuery();
57         eServiceReference m_parent;
58         friend class eServiceFactoryDVB;
59         eDVBServiceList(const eServiceReference &parent);
60         ePtr<iDVBChannelListQuery> m_query;
61         
62                 /* for editing purposes. WARNING: lifetime issue! */
63         eBouquet *m_bouquet;
64 };
65
66 inline int eDVBServiceList::compareLessEqual(const eServiceReference &a, const eServiceReference &b)
67 {
68         return m_query->compareLessEqual((const eServiceReferenceDVB&)a, (const eServiceReferenceDVB&)b);
69 }
70
71 class eDVBServiceBase: public iFrontendInformation
72 {
73 protected:
74         eDVBServicePMTHandler m_service_handler;
75 public:
76                 // iFrontendInformation
77         int getFrontendInfo(int w);
78         PyObject *getFrontendData();
79         PyObject *getFrontendStatus();
80         PyObject *getTransponderData(bool);
81         PyObject *getAll(bool original); // a sum of getFrontendData/Status/TransponderData
82 };
83
84 class eSubtitleWidget;
85
86 class eDVBServicePlay: public eDVBServiceBase,
87                 public iPlayableService, public iPauseableService, 
88                 public iSeekableService, public Object, public iServiceInformation, 
89                 public iAudioTrackSelection, public iAudioChannelSelection,
90                 public iSubserviceList, public iTimeshiftService,
91                 public iCueSheet, public iSubtitleOutput, public iAudioDelay,
92                 public iRdsDecoder, public iStreamableService
93 {
94         DECLARE_REF(eDVBServicePlay);
95 public:
96         virtual ~eDVBServicePlay();
97
98                 // iPlayableService
99         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
100         RESULT start();
101         RESULT stop();
102         RESULT setTarget(int target);
103         
104         RESULT seek(ePtr<iSeekableService> &ptr);
105         RESULT pause(ePtr<iPauseableService> &ptr);
106         RESULT info(ePtr<iServiceInformation> &ptr);
107         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
108         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
109         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr);
110         RESULT subServices(ePtr<iSubserviceList> &ptr);
111         RESULT timeshift(ePtr<iTimeshiftService> &ptr);
112         RESULT cueSheet(ePtr<iCueSheet> &ptr);
113         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
114         RESULT audioDelay(ePtr<iAudioDelay> &ptr);
115         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr);
116         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
117
118                 // iPauseableService
119         RESULT pause();
120         RESULT unpause();
121         RESULT setSlowMotion(int ratio);
122         RESULT setFastForward(int ratio);
123         
124                 // iSeekableService
125         RESULT getLength(pts_t &len);
126         RESULT seekTo(pts_t to);
127         RESULT seekRelative(int direction, pts_t to);
128         RESULT getPlayPosition(pts_t &pos);
129         RESULT setTrickmode(int trick=0);
130         RESULT isCurrentlySeekable();
131
132                 // iServiceInformation
133         RESULT getName(std::string &name);
134         RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
135         int getInfo(int w);
136         std::string getInfoString(int w);
137         PyObject *getInfoObject(int w);
138
139                 // iAudioTrackSelection 
140         int getNumberOfTracks();
141         RESULT selectTrack(unsigned int i);
142         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
143         int getCurrentTrack();
144
145                 // iAudioChannelSelection       
146         int getCurrentChannel();
147         RESULT selectChannel(int i);
148
149                 // iRdsDecoder
150         std::string getText(int i=0);
151         void showRassSlidePicture();
152         void showRassInteractivePic(int page, int subpage);
153         ePyObject getRassInteractiveMask();
154
155                 // iSubserviceList
156         int getNumberOfSubservices();
157         RESULT getSubservice(eServiceReference &subservice, unsigned int n);
158
159                 // iTimeshiftService
160         RESULT startTimeshift();
161         RESULT stopTimeshift();
162         int isTimeshiftActive();
163         RESULT activateTimeshift();
164
165                 // iCueSheet
166         PyObject *getCutList();
167         void setCutList(SWIG_PYOBJECT(ePyObject));
168         void setCutListEnable(int enable);
169         
170                 // iSubtitleOutput
171         RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry);
172         RESULT disableSubtitles(eWidget *parent);
173         PyObject *getSubtitleList();
174         PyObject *getCachedSubtitle();
175
176                 // iAudioDelay
177         int getAC3Delay();
178         int getPCMDelay();
179         void setAC3Delay(int);
180         void setPCMDelay(int);
181         
182                 // iStreamableService
183         RESULT stream(ePtr<iStreamableService> &ptr);
184         PyObject *getStreamingData();
185 private:
186         friend class eServiceFactoryDVB;
187         eServiceReference m_reference;
188         
189         ePtr<eDVBService> m_dvb_service;
190         
191         ePtr<iTSMPEGDecoder> m_decoder;
192         int m_is_primary;
193         int m_have_video_pid;
194         int m_tune_state;
195         
196                 /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
197         eDVBServicePMTHandler m_service_handler_timeshift;
198         eDVBServiceEITHandler m_event_handler;
199         int m_current_audio_pid;
200         
201         eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
202         
203                 /* events */
204         void gotNewEvent();
205         
206         void serviceEvent(int event);
207         void serviceEventTimeshift(int event);
208         Signal2<void,iPlayableService*,int> m_event;
209         
210                 /* pvr */
211         int m_is_pvr, m_is_paused, m_timeshift_enabled, m_timeshift_active;
212         int m_first_program_info;
213         
214         std::string m_timeshift_file;
215         int m_timeshift_fd;
216         
217         ePtr<iDVBDemux> m_decode_demux;
218
219         int m_current_audio_stream;
220         int selectAudioStream(int n = -1);
221         RESULT setFastForward_internal(int ratio);
222         
223                 /* timeshift */
224         ePtr<iDVBTSRecorder> m_record;
225         std::set<int> m_pids_active;
226
227         void updateTimeshiftPids();
228         void switchToLive();
229         void switchToTimeshift();
230         
231         void updateDecoder();
232         
233         int m_skipmode;
234         
235                 /* cuesheet */
236         
237         ePtr<eCueSheet> m_cue;
238         
239         struct cueEntry
240         {
241                 pts_t where;
242                 unsigned int what;
243                 
244                 bool operator < (const struct cueEntry &o) const
245                 {
246                         return where < o.where;
247                 }
248                 cueEntry(const pts_t &where, unsigned int what) :
249                         where(where), what(what)
250                 {
251                 }
252         };
253         
254         std::multiset<cueEntry> m_cue_entries;
255         int m_cuesheet_changed, m_cutlist_enabled;
256         
257         void loadCuesheet();
258         void saveCuesheet();
259         
260         void cutlistToCuesheet();
261         
262         eSubtitleWidget *m_subtitle_widget;
263         
264                 /* teletext subtitles */
265         ePtr<eDVBTeletextParser> m_teletext_parser;
266         void newSubtitlePage(const eDVBTeletextSubtitlePage &p);
267         ePtr<eConnection> m_new_subtitle_page_connection;
268         std::list<eDVBTeletextSubtitlePage> m_subtitle_pages;
269         
270                 /* dvb subtitles */
271         ePtr<eDVBSubtitleParser> m_subtitle_parser;
272         void newDVBSubtitlePage(const eDVBSubtitlePage &p);
273         ePtr<eConnection> m_new_dvb_subtitle_page_connection;
274         std::list<eDVBSubtitlePage> m_dvb_subtitle_pages;
275
276         ePtr<eTimer> m_subtitle_sync_timer;
277         void checkSubtitleTiming();
278
279                 /* radiotext */
280         ePtr<eDVBRdsDecoder> m_rds_decoder;
281         ePtr<eConnection> m_rds_decoder_event_connection;
282         void rdsDecoderEvent(int);
283
284         ePtr<eConnection> m_video_event_connection;
285         void video_event(struct iTSMPEGDecoder::videoEvent);
286 };
287
288 class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
289 {
290         DECLARE_REF(eStaticServiceDVBBouquetInformation);
291         eServiceReference m_playable_service;
292 public:
293         eServiceReference &getPlayableService() { return m_playable_service; }
294         RESULT getName(const eServiceReference &ref, std::string &name);
295         int getLength(const eServiceReference &ref);
296         int isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate=false);
297         RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
298 };
299
300 #endif