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