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