c765e0e383ab00b39a5661609758b29c9cd5a2b9
[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);
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(bool);
79 };
80
81 class eSubtitleWidget; 
82
83 class eDVBServicePlay: public eDVBServiceBase,
84                 public iPlayableService, public iPauseableService, 
85                 public iSeekableService, public Object, public iServiceInformation, 
86                 public iAudioTrackSelection, public iAudioChannelSelection,
87                 public iSubserviceList, public iTimeshiftService,
88                 public iCueSheet, public iSubtitleOutput, public iAudioDelay,
89                 public iRadioText
90 {
91 DECLARE_REF(eDVBServicePlay);
92 public:
93         virtual ~eDVBServicePlay();
94
95                 // iPlayableService
96         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
97         RESULT start();
98         RESULT stop();
99         RESULT setTarget(int target);
100         
101         RESULT seek(ePtr<iSeekableService> &ptr);
102         RESULT pause(ePtr<iPauseableService> &ptr);
103         RESULT info(ePtr<iServiceInformation> &ptr);
104         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
105         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
106         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr);
107         RESULT subServices(ePtr<iSubserviceList> &ptr);
108         RESULT timeshift(ePtr<iTimeshiftService> &ptr);
109         RESULT cueSheet(ePtr<iCueSheet> &ptr);
110         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
111         RESULT audioDelay(ePtr<iAudioDelay> &ptr);
112         RESULT radioText(ePtr<iRadioText> &ptr);
113
114                 // iPauseableService
115         RESULT pause();
116         RESULT unpause();
117         RESULT setSlowMotion(int ratio);
118         RESULT setFastForward(int ratio);
119         
120                 // iSeekableService
121         RESULT getLength(pts_t &len);
122         RESULT seekTo(pts_t to);
123         RESULT seekRelative(int direction, pts_t to);
124         RESULT getPlayPosition(pts_t &pos);
125         RESULT setTrickmode(int trick=0);
126         RESULT isCurrentlySeekable();
127
128                 // iServiceInformation
129         RESULT getName(std::string &name);
130         RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
131         int getInfo(int w);
132         std::string getInfoString(int w);
133         PyObject *getInfoObject(int w);
134
135                 // iAudioTrackSelection 
136         int getNumberOfTracks();
137         RESULT selectTrack(unsigned int i);
138         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
139
140                 // iAudioChannelSelection       
141         int getCurrentChannel();
142         RESULT selectChannel(int i);
143
144                 // iRadioText
145         std::string getRadioText(int i=0);
146
147                 // iSubserviceList
148         int getNumberOfSubservices();
149         RESULT getSubservice(eServiceReference &subservice, unsigned int n);
150
151                 // iTimeshiftService
152         RESULT startTimeshift();
153         RESULT stopTimeshift();
154         int isTimeshiftActive();
155         RESULT activateTimeshift();
156
157                 // iCueSheet
158         PyObject *getCutList();
159         void setCutList(SWIG_PYOBJECT(ePyObject));
160         void setCutListEnable(int enable);
161         
162                 // iSubtitleOutput
163         RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry);
164         RESULT disableSubtitles(eWidget *parent);
165         PyObject *getSubtitleList();
166         PyObject *getCachedSubtitle();
167
168                 // iAudioDelay
169         int getAC3Delay();
170         int getPCMDelay();
171         void setAC3Delay(int);
172         void setPCMDelay(int);
173
174 private:
175         friend class eServiceFactoryDVB;
176         eServiceReference m_reference;
177         
178         ePtr<eDVBService> m_dvb_service;
179         
180         ePtr<iTSMPEGDecoder> m_decoder;
181         int m_is_primary;
182         int m_have_video_pid;
183         int m_tune_state;
184         
185                 /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
186         eDVBServicePMTHandler m_service_handler_timeshift;
187         eDVBServiceEITHandler m_event_handler;
188         
189         eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
190         
191                 /* events */
192         void gotNewEvent();
193         
194         void serviceEvent(int event);
195         void serviceEventTimeshift(int event);
196         Signal2<void,iPlayableService*,int> m_event;
197         
198                 /* pvr */
199         int m_is_pvr, m_is_paused, m_timeshift_enabled, m_timeshift_active;
200         int m_first_program_info;
201         
202         std::string m_timeshift_file;
203         int m_timeshift_fd;
204         
205         ePtr<iDVBDemux> m_decode_demux;
206
207         int m_current_audio_stream;
208         int selectAudioStream(int n);
209         
210                 /* timeshift */
211         ePtr<iDVBTSRecorder> m_record;
212         std::set<int> m_pids_active;
213
214         void updateTimeshiftPids();
215         void switchToLive();
216         void switchToTimeshift();
217         
218         void updateDecoder();
219         
220         int m_skipmode;
221         
222                 /* cuesheet */
223         
224         ePtr<eCueSheet> m_cue;
225         
226         struct cueEntry
227         {
228                 pts_t where;
229                 unsigned int what;
230                 
231                 bool operator < (const struct cueEntry &o) const
232                 {
233                         return where < o.where;
234                 }
235                 cueEntry(const pts_t &where, unsigned int what) :
236                         where(where), what(what)
237                 {
238                 }
239         };
240         
241         std::multiset<cueEntry> m_cue_entries;
242         int m_cuesheet_changed, m_cutlist_enabled;
243         
244         void loadCuesheet();
245         void saveCuesheet();
246         
247         void cutlistToCuesheet();
248         
249         eSubtitleWidget *m_subtitle_widget;
250         
251                 /* teletext subtitles */
252         ePtr<eDVBTeletextParser> m_teletext_parser;
253         void newSubtitlePage(const eDVBTeletextSubtitlePage &p);
254         ePtr<eConnection> m_new_subtitle_page_connection;
255         std::list<eDVBTeletextSubtitlePage> m_subtitle_pages;
256         
257                 /* dvb subtitles */
258         ePtr<eDVBSubtitleParser> m_subtitle_parser;
259         void newDVBSubtitlePage(const eDVBSubtitlePage &p);
260         ePtr<eConnection> m_new_dvb_subtitle_page_connection;
261         std::list<eDVBSubtitlePage> m_dvb_subtitle_pages;
262
263         eTimer m_subtitle_sync_timer;
264         void checkSubtitleTiming();
265
266                 /* radiotext */
267         ePtr<eDVBRadioTextParser> m_radiotext_parser;
268         ePtr<eConnection> m_radiotext_updated_connection;
269         void radioTextUpdated();
270
271         ePtr<eConnection> m_video_event_connection;
272         void video_event(struct iTSMPEGDecoder::videoEvent);
273         struct iTSMPEGDecoder::videoEvent m_videoEventData;
274 };
275
276 class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
277 {
278         DECLARE_REF(eStaticServiceDVBBouquetInformation);
279         eServiceReference m_playable_service;
280 public:
281         eServiceReference &getPlayableService() { return m_playable_service; }
282         RESULT getName(const eServiceReference &ref, std::string &name);
283         int getLength(const eServiceReference &ref);
284         int isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
285         RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
286 };
287
288 #endif