dvb subtitles are working now
[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
162                 // iAudioDelay
163         int getAC3Delay();
164         int getPCMDelay();
165         void setAC3Delay(int);
166         void setPCMDelay(int);
167
168 private:
169         friend class eServiceFactoryDVB;
170         eServiceReference m_reference;
171         
172         ePtr<eDVBService> m_dvb_service;
173         
174         ePtr<iTSMPEGDecoder> m_decoder;
175         int m_is_primary;
176         int m_have_video_pid;
177         
178                 /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
179         eDVBServicePMTHandler m_service_handler_timeshift;
180         eDVBServiceEITHandler m_event_handler;
181         
182         eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
183         
184                 /* events */
185         void gotNewEvent();
186         
187         void serviceEvent(int event);
188         void serviceEventTimeshift(int event);
189         Signal2<void,iPlayableService*,int> m_event;
190         
191                 /* pvr */
192         int m_is_pvr, m_is_paused, m_timeshift_enabled, m_timeshift_active;
193         int m_first_program_info;
194         
195         std::string m_timeshift_file;
196         int m_timeshift_fd;
197         
198         ePtr<iDVBDemux> m_decode_demux;
199
200         int m_current_audio_stream;
201         int selectAudioStream(int n);
202         
203                 /* timeshift */
204         ePtr<iDVBTSRecorder> m_record;
205         std::set<int> m_pids_active;
206
207         void updateTimeshiftPids();
208         void switchToLive();
209         void switchToTimeshift();
210         
211         void updateDecoder();
212         
213         int m_skipmode;
214         
215                 /* cuesheet */
216         
217         ePtr<eCueSheet> m_cue;
218         
219         struct cueEntry
220         {
221                 pts_t where;
222                 unsigned int what;
223                 
224                 bool operator < (const struct cueEntry &o) const
225                 {
226                         return where < o.where;
227                 }
228                 cueEntry(const pts_t &where, unsigned int what) :
229                         where(where), what(what)
230                 {
231                 }
232         };
233         
234         std::multiset<cueEntry> m_cue_entries;
235         int m_cuesheet_changed, m_cutlist_enabled;
236         
237         void loadCuesheet();
238         void saveCuesheet();
239         
240         void cutlistToCuesheet();
241         
242         eSubtitleWidget *m_subtitle_widget;
243         
244                 /* teletext subtitles */
245         ePtr<eDVBTeletextParser> m_teletext_parser;
246         void newSubtitlePage(const eDVBTeletextSubtitlePage &p);
247         ePtr<eConnection> m_new_subtitle_page_connection;
248         std::list<eDVBTeletextSubtitlePage> m_subtitle_pages;
249         
250                 /* dvb subtitles */
251         ePtr<eDVBSubtitleParser> m_subtitle_parser;
252         void newDVBSubtitlePage(const eDVBSubtitlePage &p);
253         ePtr<eConnection> m_new_dvb_subtitle_page_connection;
254         std::list<eDVBSubtitlePage> m_dvb_subtitle_pages;
255
256         eTimer m_subtitle_sync_timer;
257         void checkSubtitleTiming();
258
259                 /* radiotext */
260         ePtr<eDVBRadioTextParser> m_radiotext_parser;
261         ePtr<eConnection> m_radiotext_updated_connection;
262         void radioTextUpdated();
263 };
264
265 #endif