use eit component tags to get language info of audio streams (premiere)
[enigma2.git] / 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 <lib/service/event.h>
7 #include <string>
8 #include <connection.h>
9 #include <list>
10
11 class eServiceReference
12 {
13 public:
14         enum
15         {
16                 idInvalid=-1,
17                 idStructure,    // service_id == 0 is root
18                 idDVB,
19                 idFile,
20                 idUser=0x1000
21         };
22         int type;
23
24         int flags; // flags will NOT be compared.
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
43         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
44
45         int data[8];
46         std::string path;
47         std::string getPath() { return path; }
48
49 // only for override service names in bouquets or to give servicerefs a name which not have a
50 // real existing service ( for dvb eServiceDVB )
51         std::string name;
52         std::string getName() { return name; }
53
54         eServiceReference()
55                 : type(idInvalid), flags(0)
56         {
57         }
58
59         eServiceReference(int type, int flags)
60                 : type(type), flags(flags)
61         {
62                 memset(data, 0, sizeof(data));
63         }
64         eServiceReference(int type, int flags, int data0)
65                 : type(type), flags(flags)
66         {
67                 memset(data, 0, sizeof(data));
68                 data[0]=data0;
69         }
70         eServiceReference(int type, int flags, int data0, int data1)
71                 : type(type), flags(flags)
72         {
73                 memset(data, 0, sizeof(data));
74                 data[0]=data0;
75                 data[1]=data1;
76         }
77         eServiceReference(int type, int flags, int data0, int data1, int data2)
78                 : type(type), flags(flags)
79         {
80                 memset(data, 0, sizeof(data));
81                 data[0]=data0;
82                 data[1]=data1;
83                 data[2]=data2;
84         }
85         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
86                 : type(type), flags(flags)
87         {
88                 memset(data, 0, sizeof(data));
89                 data[0]=data0;
90                 data[1]=data1;
91                 data[2]=data2;
92                 data[3]=data3;
93         }
94         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
95                 : type(type), flags(flags)
96         {
97                 memset(data, 0, sizeof(data));
98                 data[0]=data0;
99                 data[1]=data1;
100                 data[2]=data2;
101                 data[3]=data3;
102                 data[4]=data4;
103         }
104         eServiceReference(int type, int flags, const std::string &path)
105                 : type(type), flags(flags), path(path)
106         {
107                 memset(data, 0, sizeof(data));
108         }
109         eServiceReference(const std::string &string);
110         std::string toString() const;
111         bool operator==(const eServiceReference &c) const
112         {
113                 if (type != c.type)
114                         return 0;
115                 return (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
116         }
117         bool operator!=(const eServiceReference &c) const
118         {
119                 return !(*this == c);
120         }
121         bool operator<(const eServiceReference &c) const
122         {
123                 if (type < c.type)
124                         return 1;
125
126                 if (type > c.type)
127                         return 0;
128
129                 int r=memcmp(data, c.data, sizeof(int)*8);
130                 if (r)
131                         return r < 0;
132                 return path < c.path;
133         }
134         operator bool() const
135         {
136                 return valid();
137         }
138         
139         int valid() const
140         {
141                 return type != idInvalid;
142         }
143 };
144
145 SWIG_ALLOW_OUTPUT_SIMPLE(eServiceReference);
146
147 typedef long long pts_t;
148
149         /* the reason we have the servicereference as additional argument is
150            that we don't have to create one object for every entry in a possibly
151            large list, provided that no state information is nessesary to deliver
152            the required information. Anyway - ref *must* be the same as the argument
153            to the info() or getIServiceInformation call! */
154
155         /* About the usage of SWIG_VOID:
156            SWIG_VOID(real_returntype_t) hides a return value from swig. This is used for
157            the "superflouus" RESULT return values.
158            
159            Python code has to check the returned pointer against 0. This works,
160            as all functions returning instances in smartpointers AND having a 
161            RESULT have to BOTH return non-zero AND set the pointer to zero.
162            
163            Python code thus can't check for the reason, but the reason isn't
164            user-servicable anyway. If you want to return a real reason which
165            goes beyong "it just doesn't work", use extra variables for this,
166            not the RESULT.
167            
168            Hide the result only if there is another way to check for failure! */
169            
170 class iStaticServiceInformation: public iObject
171 {
172 public:
173         virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
174         
175                 // doesn't need to be implemented, should return -1 then.
176         virtual int getLength(const eServiceReference &ref);
177         virtual SWIG_VOID(RESULT) getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &SWIG_OUTPUT);
178                 // returns true when not implemented
179         virtual bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
180 };
181
182 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
183
184 class eServiceEvent;
185
186 TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
187
188 class iServiceInformation: public iObject
189 {
190 public:
191         virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
192         virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
193
194         enum { 
195                 sIsCrypted,  /* is encrypted (no indication if decrypt was possible) */
196                 sAspect,     /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */
197                 sIsMultichannel, /* multichannel *available* (probably not selected) */
198                 
199                         /* "user serviceable info" - they are not reliable. Don't use them for anything except the service menu!
200                            that's also the reason why they are so globally defined. 
201                            
202                            
203                            again - if somebody EVER tries to use this information for anything else than simply displaying it,
204                            i will change this to return a user-readable text like "zero x zero three three" (and change the
205                            exact spelling in every version) to stop that!
206                         */
207                 sVideoPID,
208                 sAudioPID,
209                 sPCRPID,
210                 sPMTPID,
211                 sTXTPID,
212                 
213                 sSID,
214                 sONID,
215                 sTSID,
216                 sNamespace,
217                 sProvider,
218         };
219         enum { resNA = -1, resIsString = -2 };
220
221         virtual int getInfo(int w);
222         virtual std::string getInfoString(int w);
223 };
224
225 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
226
227 class iFrontendStatusInformation: public iObject
228 {
229 public:
230         enum {
231                 bitErrorRate,
232                 signalPower,
233                 signalQuality
234         };
235         virtual int getFrontendInfo(int w)=0;
236 };
237
238 TEMPLATE_TYPEDEF(ePtr<iFrontendStatusInformation>, iFrontendStatusInformationPtr);
239
240 class iPauseableService: public iObject
241 {
242 public:
243         virtual RESULT pause()=0;
244         virtual RESULT unpause()=0;
245 };
246
247 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
248
249 class iSeekableService: public iObject
250 {
251 public:
252         virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
253         virtual RESULT seekTo(pts_t to)=0;
254         enum { dirForward = +1, dirBackward = -1 };
255         virtual RESULT seekRelative(int direction, pts_t to)=0;
256         virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
257 };
258
259 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
260
261 struct iAudioTrackInfo
262 {
263         std::string m_description;
264         std::string m_language; /* iso639 */
265         
266         std::string getDescription() { return m_description; }
267         std::string getLanguage() { return m_language; }
268 };
269
270 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
271
272 class iAudioTrackSelection: public iObject
273 {
274 public:
275         virtual int getNumberOfTracks()=0;
276         virtual RESULT selectTrack(unsigned int i)=0;
277         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
278 };
279
280 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
281
282 class iPlayableService: public iObject
283 {
284         friend class iServiceHandler;
285 public:
286         enum
287         {
288                 evStart,
289                 evEnd,
290                 
291                 evTuneFailed,
292                         // when iServiceInformation is implemented:
293                 evUpdatedEventInfo,
294                 evUpdatedInfo,
295         };
296         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
297         virtual RESULT start()=0;
298         virtual RESULT stop()=0;
299         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
300         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
301         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
302         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
303         virtual SWIG_VOID(RESULT) frontendStatusInfo(ePtr<iFrontendStatusInformation> &SWIG_OUTPUT)=0;
304 };
305
306 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
307
308 class iRecordableService: public iObject
309 {
310 public:
311         virtual RESULT prepare(const char *filename)=0;
312         virtual RESULT start()=0;
313         virtual RESULT stop()=0;
314 };
315
316 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
317
318 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
319
320 class iMutableServiceList: public iObject
321 {
322 public:
323                 /* flush changes */
324         virtual RESULT flushChanges()=0;
325                 /* adds a service to a list */
326         virtual RESULT addService(eServiceReference &ref)=0;
327                 /* removes a service from a list */
328         virtual RESULT removeService(eServiceReference &ref)=0;
329                 /* moves a service in a list, only if list suppports a specific sort method. */
330                 /* pos is the new, absolute position from 0..size-1 */
331         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
332 };
333
334 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
335
336 class iListableService: public iObject
337 {
338 public:
339                 /* legacy interface: get a list */
340         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
341         
342                 /* new, shiny interface: streaming. */
343         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
344         
345                 /* use this for sorting. output is not sorted because of either
346                  - performance reasons: the whole list must be buffered or
347                  - the interface would be restricted to a list. streaming
348                    (as well as a future "active" extension) won't be possible.
349                 */
350         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
351         
352         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
353 };
354
355 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
356
357         /* a helper class which can be used as argument to stl's sort(). */
358 class iListableServiceCompare
359 {
360         ePtr<iListableService> m_list;
361 public:
362         iListableServiceCompare(iListableService *list): m_list(list) { }
363         bool operator()(const eServiceReference &a, const eServiceReference &b)
364         {
365                 return m_list->compareLessEqual(a, b);
366         }
367 };
368
369 class iServiceOfflineOperations: public iObject
370 {
371 public:
372                 /* to delete a service, forever. */
373         virtual RESULT deleteFromDisk(int simulate=1)=0;
374         
375                 /* for transferring a service... */
376         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
377         
378                 // TODO: additional stuff, like a conversion interface?
379 };
380
381 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
382
383 class iServiceHandler: public iObject
384 {
385 public:
386         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
387         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
388         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
389         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
390         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
391 };
392
393 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
394
395 #endif