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