add isTimeshiftActive, activateTimeshift functions
[vuplus_dvbapp] / lib / service / iservice.h
1 #ifndef __lib_dvb_iservice_h
2 #define __lib_dvb_iservice_h
3
4 #include <lib/python/swig.h>
5 #include <lib/base/object.h>
6 #include <string>
7 #include <connection.h>
8 #include <list>
9
10 class eServiceEvent;
11
12 class eServiceReference
13 {
14 public:
15         enum
16         {
17                 idInvalid=-1,
18                 idStructure,    // service_id == 0 is root
19                 idDVB,
20                 idFile,
21                 idUser=0x1000
22         };
23         int type;
24
25         enum
26         {
27                 isDirectory=1,          // SHOULD enter  (implies mustDescent)
28                 mustDescent=2,          // cannot be played directly - often used with "isDirectory" (implies canDescent)
29                 /*
30                         for example:
31                                 normal services have none of them - they can be fed directly into the "play"-handler.
32                                 normal directories have both of them set - you cannot play a directory directly and the UI should descent into it.
33                                 playlists have "mustDescent", but not "isDirectory" - you don't want the user to browse inside the playlist (unless he really wants)
34                                 services with sub-services have none of them, instead the have the "canDecsent" flag (as all of the above)
35                 */
36                 canDescent=4,                   // supports enterDirectory/leaveDirectory
37                 flagDirectory=isDirectory|mustDescent|canDescent,
38                 shouldSort=8,                   // should be ASCII-sorted according to service_name. great for directories.
39                 hasSortKey=16,          // has a sort key in data[3]. not having a sort key implies 0.
40                 sort1=32                                        // sort key is 1 instead of 0
41         };
42         int flags; // flags will NOT be compared.
43
44         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
45
46 #ifndef SWIG
47         int data[8];
48         std::string path;
49 #endif
50         std::string getPath() { return path; }
51         void setPath( const std::string &n ) { path=n; }
52
53         int getData(unsigned int num) const
54         {
55                 if ( num < sizeof(data)/sizeof(int) )
56                         return data[num];
57                 return 0;
58         }
59
60         void setData(unsigned int num, int val)
61         {
62                 if ( num < sizeof(data)/sizeof(int) )
63                         data[num] = val;
64         }
65
66 // only for override service names in bouquets or to give servicerefs a name which not have a
67 // real existing service ( for dvb eServiceDVB )
68 #ifndef SWIG
69         std::string name;
70 #endif
71         std::string getName() { return name; }
72         void setName( const std::string &n ) { name=n; }
73
74         eServiceReference()
75                 : type(idInvalid), flags(0)
76         {
77                 memset(data, 0, sizeof(data));
78         }
79 #ifndef SWIG
80         eServiceReference(int type, int flags)
81                 : type(type), flags(flags)
82         {
83                 memset(data, 0, sizeof(data));
84         }
85         eServiceReference(int type, int flags, int data0)
86                 : type(type), flags(flags)
87         {
88                 memset(data, 0, sizeof(data));
89                 data[0]=data0;
90         }
91         eServiceReference(int type, int flags, int data0, int data1)
92                 : type(type), flags(flags)
93         {
94                 memset(data, 0, sizeof(data));
95                 data[0]=data0;
96                 data[1]=data1;
97         }
98         eServiceReference(int type, int flags, int data0, int data1, int data2)
99                 : type(type), flags(flags)
100         {
101                 memset(data, 0, sizeof(data));
102                 data[0]=data0;
103                 data[1]=data1;
104                 data[2]=data2;
105         }
106         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
107                 : type(type), flags(flags)
108         {
109                 memset(data, 0, sizeof(data));
110                 data[0]=data0;
111                 data[1]=data1;
112                 data[2]=data2;
113                 data[3]=data3;
114         }
115         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
116                 : type(type), flags(flags)
117         {
118                 memset(data, 0, sizeof(data));
119                 data[0]=data0;
120                 data[1]=data1;
121                 data[2]=data2;
122                 data[3]=data3;
123                 data[4]=data4;
124         }
125         eServiceReference(int type, int flags, const std::string &path)
126                 : type(type), flags(flags), path(path)
127         {
128                 memset(data, 0, sizeof(data));
129         }
130 #endif
131         eServiceReference(const std::string &string);
132         std::string toString() const;
133         bool operator==(const eServiceReference &c) const
134         {
135                 if (type != c.type)
136                         return 0;
137                 return (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
138         }
139         bool operator!=(const eServiceReference &c) const
140         {
141                 return !(*this == c);
142         }
143         bool operator<(const eServiceReference &c) const
144         {
145                 if (type < c.type)
146                         return 1;
147
148                 if (type > c.type)
149                         return 0;
150
151                 int r=memcmp(data, c.data, sizeof(int)*8);
152                 if (r)
153                         return r < 0;
154                 return path < c.path;
155         }
156         operator bool() const
157         {
158                 return valid();
159         }
160         
161         int valid() const
162         {
163                 return type != idInvalid;
164         }
165 };
166
167 SWIG_ALLOW_OUTPUT_SIMPLE(eServiceReference);
168
169 typedef long long pts_t;
170
171         /* the reason we have the servicereference as additional argument is
172            that we don't have to create one object for every entry in a possibly
173            large list, provided that no state information is nessesary to deliver
174            the required information. Anyway - ref *must* be the same as the argument
175            to the info() or getIServiceInformation call! */
176
177         /* About the usage of SWIG_VOID:
178            SWIG_VOID(real_returntype_t) hides a return value from swig. This is used for
179            the "superflouus" RESULT return values.
180            
181            Python code has to check the returned pointer against 0. This works,
182            as all functions returning instances in smartpointers AND having a 
183            RESULT have to BOTH return non-zero AND set the pointer to zero.
184            
185            Python code thus can't check for the reason, but the reason isn't
186            user-servicable anyway. If you want to return a real reason which
187            goes beyong "it just doesn't work", use extra variables for this,
188            not the RESULT.
189            
190            Hide the result only if there is another way to check for failure! */
191            
192 class iStaticServiceInformation: public iObject
193 {
194 #ifdef SWIG
195         iStaticServiceInformation();
196         ~iStaticServiceInformation();
197 #endif
198 public:
199         virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
200         
201                 // doesn't need to be implemented, should return -1 then.
202         virtual int getLength(const eServiceReference &ref);
203         virtual SWIG_VOID(RESULT) getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &SWIG_OUTPUT, time_t start_time=-1);
204                 // returns true when not implemented
205         virtual bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
206
207         virtual int getInfo(const eServiceReference &ref, int w);
208         virtual std::string getInfoString(const eServiceReference &ref,int w);
209 };
210
211 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
212
213 TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
214
215 class iServiceInformation: public iObject
216 {
217 #ifdef SWIG
218         iServiceInformation();
219         ~iServiceInformation();
220 #endif
221 public:
222         virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
223         virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
224
225         enum { 
226                 sIsCrypted,  /* is encrypted (no indication if decrypt was possible) */
227                 sAspect,     /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */
228                 sIsMultichannel, /* multichannel *available* (probably not selected) */
229                 
230                         /* "user serviceable info" - they are not reliable. Don't use them for anything except the service menu!
231                            that's also the reason why they are so globally defined. 
232                            
233                            
234                            again - if somebody EVER tries to use this information for anything else than simply displaying it,
235                            i will change this to return a user-readable text like "zero x zero three three" (and change the
236                            exact spelling in every version) to stop that!
237                         */
238                 sVideoPID,
239                 sAudioPID,
240                 sPCRPID,
241                 sPMTPID,
242                 sTXTPID,
243                 
244                 sSID,
245                 sONID,
246                 sTSID,
247                 sNamespace,
248                 sProvider,
249                 
250                 sDescription,
251                 sTimeCreate,    // unix time or string
252         };
253         enum { resNA = -1, resIsString = -2 };
254
255         virtual int getInfo(int w);
256         virtual std::string getInfoString(int w);
257 };
258
259 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
260
261 class iFrontendStatusInformation: public iObject
262 {
263 #ifdef SWIG
264         iFrontendStatusInformation();
265         ~iFrontendStatusInformation();
266 #endif
267 public:
268         enum {
269                 bitErrorRate,
270                 signalPower,
271                 signalQuality
272         };
273         virtual int getFrontendInfo(int w)=0;
274 };
275
276 TEMPLATE_TYPEDEF(ePtr<iFrontendStatusInformation>, iFrontendStatusInformationPtr);
277
278 class iPauseableService: public iObject
279 {
280 #ifdef SWIG
281         iPausableService();
282         ~iPausableService();
283 #endif
284 public:
285         virtual RESULT pause()=0;
286         virtual RESULT unpause()=0;
287         
288                 /* hm. */
289         virtual RESULT setSlowMotion(int ratio=0)=0;
290         virtual RESULT setFastForward(int ratio=0)=0;
291 };
292
293 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
294
295 class iSeekableService: public iObject
296 {
297 #ifdef SWIG
298         iSeekableService();
299         ~iSeekableService();
300 #endif
301 public:
302         virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
303         virtual RESULT seekTo(pts_t to)=0;
304         enum { dirForward = +1, dirBackward = -1 };
305         virtual RESULT seekRelative(int direction, pts_t to)=0;
306         virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
307                 /* if you want to do several seeks in a row, you can enable the trickmode. 
308                    audio will be switched off, sync will be disabled etc. */
309         virtual RESULT setTrickmode(int trick=0)=0;
310 };
311
312 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
313
314 struct iAudioTrackInfo
315 {
316 #ifdef SWIG
317 private:
318         iAudioTrackInfo();
319         ~iAudioTrackInfo();
320 public:
321 #endif
322 #ifndef SWIG
323         std::string m_description;
324         std::string m_language; /* iso639 */
325 #endif
326         std::string getDescription() { return m_description; }
327         std::string getLanguage() { return m_language; }
328 };
329
330 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
331
332 class iAudioTrackSelection: public iObject
333 {
334 #ifdef SWIG
335         iAudioTrackSelection();
336         ~iAudioTrackSelection();
337 #endif
338 public:
339         virtual int getNumberOfTracks()=0;
340         virtual RESULT selectTrack(unsigned int i)=0;
341         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
342 };
343
344 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
345
346 class iSubserviceList: public iObject
347 {
348 #ifdef SWIG
349         iSubserviceList();
350         ~iSubserviceList();
351 #endif
352 public:
353         virtual int getNumberOfSubservices()=0;
354         virtual SWIG_VOID(RESULT) getSubservice(eServiceReference &SWIG_OUTPUT, unsigned int n)=0;
355 };
356
357 TEMPLATE_TYPEDEF(ePtr<iSubserviceList>, iSubserviceListPtr);
358
359 class iTimeshiftService: public iObject
360 {
361 #ifdef SWIG
362         iTimeshiftService();
363         ~iTimeshiftService();
364 #endif
365 public:
366         virtual RESULT startTimeshift()=0;
367         virtual RESULT stopTimeshift()=0;
368         
369         virtual int isTimeshiftActive()=0;
370                         /* this essentially seeks to the relative end of the timeshift buffer */
371         virtual RESULT activateTimeshift()=0;
372 };
373
374 TEMPLATE_TYPEDEF(ePtr<iTimeshiftService>, iTimeshiftServicePtr);
375
376 class iPlayableService: public iObject
377 {
378 #ifdef SWIG
379         iPlayableService();
380         ~iPlaybleService();
381 #endif
382         friend class iServiceHandler;
383 public:
384         enum
385         {
386                 evStart,
387                 evEnd,
388                 
389                 evTuneFailed,
390                         // when iServiceInformation is implemented:
391                 evUpdatedEventInfo,
392                 evUpdatedInfo,
393
394                         /* when seek() is implemented: */               
395                 evSeekableStatusChanged, /* for example when timeshifting */
396                 
397                 evEOF
398         };
399         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
400         virtual RESULT start()=0;
401         virtual RESULT stop()=0;
402         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
403         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
404         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
405         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
406         virtual SWIG_VOID(RESULT) subServices(ePtr<iSubserviceList> &SWIG_OUTPUT)=0;
407         virtual SWIG_VOID(RESULT) frontendStatusInfo(ePtr<iFrontendStatusInformation> &SWIG_OUTPUT)=0;
408         virtual SWIG_VOID(RESULT) timeshift(ePtr<iTimeshiftService> &SWIG_OUTPUT)=0;
409 };
410
411 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
412
413 class iRecordableService: public iObject
414 {
415 #ifdef SWIG
416         iRecordableService();
417         ~iRecordableService();
418 #endif
419 public:
420         virtual RESULT prepare(const char *filename)=0;
421         virtual RESULT start()=0;
422         virtual RESULT stop()=0;
423 };
424
425 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
426
427 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
428
429 class iMutableServiceList: public iObject
430 {
431 #ifdef SWIG
432         iMutableServiceList();
433         ~iMutableServiceList();
434 #endif
435 public:
436                 /* flush changes */
437         virtual RESULT flushChanges()=0;
438                 /* adds a service to a list */
439         virtual RESULT addService(eServiceReference &ref)=0;
440                 /* removes a service from a list */
441         virtual RESULT removeService(eServiceReference &ref)=0;
442                 /* moves a service in a list, only if list suppports a specific sort method. */
443                 /* pos is the new, absolute position from 0..size-1 */
444         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
445 };
446
447 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
448
449 class iListableService: public iObject
450 {
451 #ifdef SWIG
452         iListableService();
453         ~iListableService();
454 #endif
455 public:
456                 /* legacy interface: get a list */
457         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
458         
459                 /* new, shiny interface: streaming. */
460         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
461         
462                 /* use this for sorting. output is not sorted because of either
463                  - performance reasons: the whole list must be buffered or
464                  - the interface would be restricted to a list. streaming
465                    (as well as a future "active" extension) won't be possible.
466                 */
467         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
468         
469         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
470 };
471
472 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
473
474 #ifndef SWIG
475         /* a helper class which can be used as argument to stl's sort(). */
476 class iListableServiceCompare
477 {
478         ePtr<iListableService> m_list;
479 public:
480         iListableServiceCompare(iListableService *list): m_list(list) { }
481         bool operator()(const eServiceReference &a, const eServiceReference &b)
482         {
483                 return m_list->compareLessEqual(a, b);
484         }
485 };
486 #endif
487
488 class iServiceOfflineOperations: public iObject
489 {
490 #ifdef SWIG
491         iServiceOfflineOperations();
492         ~iServiceOfflineOperations();
493 #endif
494 public:
495                 /* to delete a service, forever. */
496         virtual RESULT deleteFromDisk(int simulate=1)=0;
497         
498                 /* for transferring a service... */
499         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
500         
501                 // TODO: additional stuff, like a conversion interface?
502 };
503
504 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
505
506 class iServiceHandler: public iObject
507 {
508 #ifdef SWIG
509         iServiceHandler();
510         ~iServiceHandler();
511 #endif
512 public:
513         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
514         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
515         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
516         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
517         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
518 };
519
520 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
521
522 #endif