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