23461d352d4bb260681f6740a6a0e8b936caf786
[openblackhole/openblackhole-enigma2.git] / 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, bool renameBouquet=true);
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         static bool tryFallbackTuner(eServiceReferenceDVB &service,
75                         bool &is_stream, bool is_pvr, bool simulate);
76
77         eDVBServicePMTHandler m_service_handler;
78 public:
79                 // iFrontendInformation
80         int getFrontendInfo(int w);
81         ePtr<iDVBFrontendData> getFrontendData();
82         ePtr<iDVBFrontendStatus> getFrontendStatus();
83         ePtr<iDVBTransponderData> getTransponderData(bool);
84 };
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                 public iStreamedService
94 {
95         DECLARE_REF(eDVBServicePlay);
96 public:
97         virtual ~eDVBServicePlay();
98
99                 // iPlayableService
100         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
101         RESULT start();
102         RESULT stop();
103         RESULT setTarget(int target);
104
105         RESULT seek(ePtr<iSeekableService> &ptr);
106         RESULT pause(ePtr<iPauseableService> &ptr);
107         RESULT info(ePtr<iServiceInformation> &ptr);
108         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
109         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
110         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr);
111         RESULT subServices(ePtr<iSubserviceList> &ptr);
112         RESULT timeshift(ePtr<iTimeshiftService> &ptr);
113         RESULT cueSheet(ePtr<iCueSheet> &ptr);
114         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
115         RESULT audioDelay(ePtr<iAudioDelay> &ptr);
116         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr);
117         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
118
119                 // iStreamedService
120         RESULT streamed(ePtr<iStreamedService> &ptr);
121         ePtr<iStreamBufferInfo> getBufferCharge();
122         int setBufferSize(int size);
123
124
125                 // iPauseableService
126         RESULT pause();
127         RESULT unpause();
128         RESULT setSlowMotion(int ratio);
129         RESULT setFastForward(int ratio);
130
131                 // iSeekableService
132         RESULT getLength(pts_t &len);
133         RESULT seekTo(pts_t to);
134         RESULT seekRelative(int direction, pts_t to);
135         RESULT getPlayPosition(pts_t &pos);
136         RESULT setTrickmode(int trick=0);
137         RESULT isCurrentlySeekable();
138
139                 // iServiceInformation
140         RESULT getName(std::string &name);
141         RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
142         int getInfo(int w);
143         std::string getInfoString(int w);
144         ePtr<iDVBTransponderData> getTransponderData();
145         void getAITApplications(std::map<int, std::string> &aitlist);
146         void getCaIds(std::vector<int> &caids, std::vector<int> &ecmpids);
147
148                 // iAudioTrackSelection
149         int getNumberOfTracks();
150         RESULT selectTrack(unsigned int i);
151         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
152         int getCurrentTrack();
153
154                 // iAudioChannelSelection
155         int getCurrentChannel();
156         RESULT selectChannel(int i);
157
158                 // iRdsDecoder
159         std::string getText(int i=0);
160         void showRassSlidePicture();
161         void showRassInteractivePic(int page, int subpage);
162         ePyObject getRassInteractiveMask();
163
164                 // iSubserviceList
165         int getNumberOfSubservices();
166         RESULT getSubservice(eServiceReference &subservice, unsigned int n);
167
168                 // iTimeshiftService
169         RESULT startTimeshift();
170         RESULT stopTimeshift(bool swToLive=true);
171         int isTimeshiftActive();
172         int isTimeshiftEnabled();
173         RESULT activateTimeshift();
174         RESULT setNextPlaybackFile(const char *fn);
175         RESULT saveTimeshiftFile();
176         std::string getTimeshiftFilename();
177         void switchToLive();
178
179                 // iCueSheet
180         PyObject *getCutList();
181         void setCutList(SWIG_PYOBJECT(ePyObject));
182         void setCutListEnable(int enable);
183
184                 // iSubtitleOutput
185         RESULT enableSubtitles(iSubtitleUser *user, SubtitleTrack &track);
186         RESULT disableSubtitles();
187         RESULT getSubtitleList(std::vector<SubtitleTrack> &sublist);
188         RESULT getCachedSubtitle(SubtitleTrack &track);
189
190                 // iAudioDelay
191         int getAC3Delay();
192         int getPCMDelay();
193         void setAC3Delay(int);
194         void setPCMDelay(int);
195
196                 // iStreamableService
197         RESULT stream(ePtr<iStreamableService> &ptr);
198         ePtr<iStreamData> getStreamingData();
199
200 protected:
201         friend class eServiceFactoryDVB;
202         eServiceReference m_reference;
203
204         ePtr<eDVBService> m_dvb_service;
205
206         ePtr<iTSMPEGDecoder> m_decoder;
207         int m_decoder_index;
208         int m_have_video_pid;
209         int m_tune_state;
210
211                 /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
212         eDVBServicePMTHandler m_service_handler_timeshift;
213         eDVBServiceEITHandler m_event_handler;
214         int m_current_audio_pid;
215
216         eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
217
218                 /* events */
219         void gotNewEvent(int error);
220
221         void serviceEvent(int event);
222         void serviceEventTimeshift(int event);
223         Signal2<void,iPlayableService*,int> m_event;
224
225         bool m_is_stream;
226
227                 /* pvr */
228         bool m_is_pvr;
229         int m_is_paused, m_timeshift_enabled, m_timeshift_active, m_timeshift_changed, m_save_timeshift;
230         int m_first_program_info;
231
232         std::string m_timeshift_file, m_timeshift_file_next;
233         int m_timeshift_fd;
234         ePtr<iDVBDemux> m_decode_demux;
235
236         int m_current_audio_stream;
237         int selectAudioStream(int n = -1);
238         RESULT setFastForward_internal(int ratio, bool final_seek=false);
239
240                 /* timeshift */
241         ePtr<iDVBTSRecorder> m_record;
242         std::set<int> m_pids_active;
243
244         void updateTimeshiftPids();
245
246         void resetTimeshift(int start);
247         void switchToTimeshift();
248
249         void updateDecoder(bool sendSeekableStateChanged=false);
250
251         int m_skipmode;
252         int m_fastforward;
253         int m_slowmotion;
254
255                 /* cuesheet */
256
257         ePtr<eCueSheet> m_cue;
258
259         struct cueEntry
260         {
261                 pts_t where;
262                 unsigned int what;
263
264                 bool operator < (const struct cueEntry &o) const
265                 {
266                         return where < o.where;
267                 }
268                 cueEntry(const pts_t &where, unsigned int what) :
269                         where(where), what(what)
270                 {
271                 }
272         };
273
274         std::multiset<cueEntry> m_cue_entries;
275         int m_cuesheet_changed, m_cutlist_enabled;
276
277         void loadCuesheet();
278         void saveCuesheet();
279
280         void cutlistToCuesheet();
281
282         iSubtitleUser *m_subtitle_widget;
283
284                 /* teletext subtitles */
285         ePtr<eDVBTeletextParser> m_teletext_parser;
286         void newSubtitleStream();
287         ePtr<eConnection> m_new_subtitle_stream_connection;
288         void newSubtitlePage(const eDVBTeletextSubtitlePage &p);
289         ePtr<eConnection> m_new_subtitle_page_connection;
290         std::list<eDVBTeletextSubtitlePage> m_subtitle_pages;
291
292                 /* dvb subtitles */
293         ePtr<eDVBSubtitleParser> m_subtitle_parser;
294         void newDVBSubtitlePage(const eDVBSubtitlePage &p);
295         ePtr<eConnection> m_new_dvb_subtitle_page_connection;
296         std::list<eDVBSubtitlePage> m_dvb_subtitle_pages;
297
298         ePtr<eTimer> m_subtitle_sync_timer;
299         void checkSubtitleTiming();
300
301         ePtr<eTimer> m_nownext_timer;
302         void updateEpgCacheNowNext();
303
304                 /* radiotext */
305         ePtr<eDVBRdsDecoder> m_rds_decoder;
306         ePtr<eConnection> m_rds_decoder_event_connection;
307         void rdsDecoderEvent(int);
308
309         ePtr<eConnection> m_video_event_connection;
310         void video_event(struct iTSMPEGDecoder::videoEvent);
311
312         virtual ePtr<iTsSource> createTsSource(eServiceReferenceDVB &ref, int packetsize = 188);
313 };
314
315 class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
316 {
317         DECLARE_REF(eStaticServiceDVBBouquetInformation);
318         eServiceReference m_playable_service;
319 public:
320         eServiceReference &getPlayableService() { return m_playable_service; }
321         RESULT getName(const eServiceReference &ref, std::string &name);
322         int getLength(const eServiceReference &ref);
323         int isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate);
324         RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
325 };
326
327 #endif