add function to get a comparable service reference string (useable to
[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/teletext.h>
10 #include <lib/dvb/radiotext.h>
11 #include <lib/base/filepush.h>
12
13 class eStaticServiceDVBInformation;
14 class eStaticServiceDVBBouquetInformation;
15
16 class eServiceFactoryDVB: public iServiceHandler
17 {
18         DECLARE_REF(eServiceFactoryDVB);
19         ePtr<eStaticServiceDVBInformation> m_StaticServiceDVBInfo;
20         ePtr<eStaticServiceDVBBouquetInformation> m_StaticServiceDVBBouquetInfo;
21 public:
22         eServiceFactoryDVB();
23         virtual ~eServiceFactoryDVB();
24         enum { id = 0x1 };
25
26                 // iServiceHandler
27         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
28         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
29         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
30         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
31         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
32 private:
33         RESULT lookupService(ePtr<eDVBService> &ptr, const eServiceReference &ref);
34 };
35
36 class eBouquet;
37
38 class eDVBServiceList: public iListableService, public iMutableServiceList
39 {
40 DECLARE_REF(eDVBServiceList);
41 public:
42         virtual ~eDVBServiceList();
43         PyObject *getContent(const char* formatstr, bool sorted=false);
44         RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
45         RESULT getNext(eServiceReference &ptr);
46         int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
47         
48         RESULT startEdit(ePtr<iMutableServiceList> &);
49         RESULT flushChanges();
50         RESULT addService(eServiceReference &ref, eServiceReference before);
51         RESULT removeService(eServiceReference &ref);
52         RESULT moveService(eServiceReference &ref, int pos);
53         RESULT setListName(const std::string &name);
54 private:
55         RESULT startQuery();
56         eServiceReference m_parent;
57         friend class eServiceFactoryDVB;
58         eDVBServiceList(const eServiceReference &parent);
59         ePtr<iDVBChannelListQuery> m_query;
60         
61                 /* for editing purposes. WARNING: lifetime issue! */
62         eBouquet *m_bouquet;
63 };
64
65 class eDVBServiceBase: public iFrontendInformation
66 {
67 protected:
68         eDVBServicePMTHandler m_service_handler ;
69 public:
70                 // iFrontendInformation
71         int getFrontendInfo(int w);
72         PyObject *getFrontendData(bool);
73 };
74
75 class eSubtitleWidget; 
76
77 class eDVBServicePlay: public eDVBServiceBase,
78                 public iPlayableService, public iPauseableService, 
79                 public iSeekableService, public Object, public iServiceInformation, 
80                 public iAudioTrackSelection, public iAudioChannelSelection,
81                 public iSubserviceList, public iTimeshiftService,
82                 public iCueSheet, public iSubtitleOutput, public iAudioDelay,
83                 public iRadioText
84 {
85 DECLARE_REF(eDVBServicePlay);
86 public:
87         virtual ~eDVBServicePlay();
88
89                 // iPlayableService
90         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
91         RESULT start();
92         RESULT stop();
93         RESULT setTarget(int target);
94         
95         RESULT seek(ePtr<iSeekableService> &ptr);
96         RESULT pause(ePtr<iPauseableService> &ptr);
97         RESULT info(ePtr<iServiceInformation> &ptr);
98         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
99         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
100         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr);
101         RESULT subServices(ePtr<iSubserviceList> &ptr);
102         RESULT timeshift(ePtr<iTimeshiftService> &ptr);
103         RESULT cueSheet(ePtr<iCueSheet> &ptr);
104         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
105         RESULT audioDelay(ePtr<iAudioDelay> &ptr);
106         RESULT radioText(ePtr<iRadioText> &ptr);
107
108                 // iPauseableService
109         RESULT pause();
110         RESULT unpause();
111         RESULT setSlowMotion(int ratio);
112         RESULT setFastForward(int ratio);
113         
114                 // iSeekableService
115         RESULT getLength(pts_t &len);
116         RESULT seekTo(pts_t to);
117         RESULT seekRelative(int direction, pts_t to);
118         RESULT getPlayPosition(pts_t &pos);
119         RESULT setTrickmode(int trick=0);
120         RESULT isCurrentlySeekable();
121
122                 // iServiceInformation
123         RESULT getName(std::string &name);
124         RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
125         int getInfo(int w);
126         std::string getInfoString(int w);
127         PyObject *getInfoObject(int w);
128
129                 // iAudioTrackSelection 
130         int getNumberOfTracks();
131         RESULT selectTrack(unsigned int i);
132         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
133
134                 // iAudioChannelSelection       
135         int getCurrentChannel();
136         RESULT selectChannel(int i);
137
138                 // iRadioText
139         std::string getRadioText(int i=0);
140
141                 // iSubserviceList
142         int getNumberOfSubservices();
143         RESULT getSubservice(eServiceReference &subservice, unsigned int n);
144
145                 // iTimeshiftService
146         RESULT startTimeshift();
147         RESULT stopTimeshift();
148         int isTimeshiftActive();
149         RESULT activateTimeshift();
150
151                 // iCueSheet
152         PyObject *getCutList();
153         void setCutList(PyObject *);
154         void setCutListEnable(int enable);
155         
156                 // iSubtitleOutput
157         RESULT enableSubtitles(eWidget *parent, PyObject *entry);
158         RESULT disableSubtitles(eWidget *parent);
159         PyObject *getSubtitleList();
160
161                 // iAudioDelay
162         int getAC3Delay();
163         int getPCMDelay();
164         void setAC3Delay(int);
165         void setPCMDelay(int);
166
167 private:
168         friend class eServiceFactoryDVB;
169         eServiceReference m_reference;
170         
171         ePtr<eDVBService> m_dvb_service;
172         
173         ePtr<iTSMPEGDecoder> m_decoder;
174         int m_is_primary;
175         int m_have_video_pid;
176         
177                 /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
178         eDVBServicePMTHandler m_service_handler_timeshift;
179         eDVBServiceEITHandler m_event_handler;
180         
181         eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
182         
183                 /* events */
184         void gotNewEvent();
185         
186         void serviceEvent(int event);
187         void serviceEventTimeshift(int event);
188         Signal2<void,iPlayableService*,int> m_event;
189         
190                 /* pvr */
191         int m_is_pvr, m_is_paused, m_timeshift_enabled, m_timeshift_active;
192         int m_first_program_info;
193         
194         std::string m_timeshift_file;
195         int m_timeshift_fd;
196         
197         ePtr<iDVBDemux> m_decode_demux;
198
199         int m_current_audio_stream;
200         int selectAudioStream(int n);
201         
202                 /* timeshift */
203         ePtr<iDVBTSRecorder> m_record;
204         std::set<int> m_pids_active;
205
206         void updateTimeshiftPids();
207         void switchToLive();
208         void switchToTimeshift();
209         
210         void updateDecoder();
211         
212         int m_skipmode;
213         
214                 /* cuesheet */
215         
216         ePtr<eCueSheet> m_cue;
217         
218         struct cueEntry
219         {
220                 pts_t where;
221                 unsigned int what;
222                 
223                 bool operator < (const struct cueEntry &o) const
224                 {
225                         return where < o.where;
226                 }
227                 cueEntry(const pts_t &where, unsigned int what) :
228                         where(where), what(what)
229                 {
230                 }
231         };
232         
233         std::multiset<cueEntry> m_cue_entries;
234         int m_cuesheet_changed, m_cutlist_enabled;
235         
236         void loadCuesheet();
237         void saveCuesheet();
238         
239         void cutlistToCuesheet();
240         
241                 /* teletext subtitles */
242         void newSubtitlePage(const eDVBTeletextSubtitlePage &p);
243         ePtr<eConnection> m_new_subtitle_page_connection;
244         
245         ePtr<eDVBTeletextParser> m_teletext_parser;
246         ePtr<eDVBRadioTextParser> m_radiotext_parser;
247         eSubtitleWidget *m_subtitle_widget;
248         eTimer m_subtitle_sync_timer;
249         std::list<eDVBTeletextSubtitlePage> m_subtitle_pages;
250         
251         void checkSubtitleTiming();
252
253                 /* radiotext */
254         ePtr<eConnection> m_radiotext_updated_connection;
255         void radioTextUpdated();
256 };
257
258 #endif