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