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