1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
#ifndef __dvb_idvb_h
#define __dvb_idvb_h
#if HAVE_DVB_API_VERSION < 3
#include <ost/frontend.h>
#define FRONTENDPARAMETERS FrontendParameters
#else
#include <linux/dvb/frontend.h>
#define FRONTENDPARAMETERS struct dvb_frontend_parameters
#endif
#include <lib/dvb/frontendparms.h>
#include <lib/base/object.h>
#include <lib/base/ebase.h>
#include <lib/base/elock.h>
#include <lib/service/service.h>
#include <libsig_comp.h>
#include <connection.h>
struct eBouquet
{
std::string m_bouquet_name;
std::string m_filename; // without path.. just name
typedef std::list<eServiceReference> list;
list m_services;
// the following five methods are implemented in db.cpp
RESULT flushChanges();
RESULT addService(const eServiceReference &);
RESULT removeService(const eServiceReference &);
RESULT moveService(const eServiceReference &, unsigned int);
RESULT setListName(const std::string &name);
};
/* these structures have by intention no operator int() defined.
the reason of these structures is to avoid mixing for example
a onid and a tsid (as there's no general order for them).
defining an operator int() would implicitely convert values
between them over the constructor with the int argument.
'explicit' doesn't here - eTransportStreamID(eOriginalNetworkID(n))
would still work. */
struct eTransportStreamID
{
private:
int v;
public:
int get() const { return v; }
eTransportStreamID(int i): v(i) { }
eTransportStreamID(): v(-1) { }
bool operator == (const eTransportStreamID &c) const { return v == c.v; }
bool operator != (const eTransportStreamID &c) const { return v != c.v; }
bool operator < (const eTransportStreamID &c) const { return v < c.v; }
bool operator > (const eTransportStreamID &c) const { return v > c.v; }
};
struct eServiceID
{
private:
int v;
public:
int get() const { return v; }
eServiceID(int i): v(i) { }
eServiceID(): v(-1) { }
bool operator == (const eServiceID &c) const { return v == c.v; }
bool operator != (const eServiceID &c) const { return v != c.v; }
bool operator < (const eServiceID &c) const { return v < c.v; }
bool operator > (const eServiceID &c) const { return v > c.v; }
};
struct eOriginalNetworkID
{
private:
int v;
public:
int get() const { return v; }
eOriginalNetworkID(int i): v(i) { }
eOriginalNetworkID(): v(-1) { }
bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
};
struct eDVBNamespace
{
private:
int v;
public:
int get() const { return v; }
eDVBNamespace(int i): v(i) { }
eDVBNamespace(): v(-1) { }
bool operator == (const eDVBNamespace &c) const { return v == c.v; }
bool operator != (const eDVBNamespace &c) const { return v != c.v; }
bool operator < (const eDVBNamespace &c) const { return v < c.v; }
bool operator > (const eDVBNamespace &c) const { return v > c.v; }
};
struct eDVBChannelID
{
eDVBNamespace dvbnamespace;
eTransportStreamID transport_stream_id;
eOriginalNetworkID original_network_id;
bool operator==(const eDVBChannelID &c) const
{
return dvbnamespace == c.dvbnamespace &&
transport_stream_id == c.transport_stream_id &&
original_network_id == c.original_network_id;
}
bool operator<(const eDVBChannelID &c) const
{
if (dvbnamespace < c.dvbnamespace)
return 1;
else if (dvbnamespace == c.dvbnamespace)
{
if (original_network_id < c.original_network_id)
return 1;
else if (original_network_id == c.original_network_id)
if (transport_stream_id < c.transport_stream_id)
return 1;
}
return 0;
}
eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid):
dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
{
}
eDVBChannelID():
dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
{
}
operator bool() const
{
return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
}
};
struct eServiceReferenceDVB: public eServiceReference
{
int getServiceType() const { return data[0]; }
void setServiceType(int service_type) { data[0]=service_type; }
eServiceID getServiceID() const { return eServiceID(data[1]); }
void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
eServiceID getParentServiceID() const { return eServiceID(data[5]); }
void setParentServiceID( eServiceID sid ) { data[5]=sid.get(); }
eTransportStreamID getParentTransportStreamID() const { return eTransportStreamID(data[6]); }
void setParentTransportStreamID( eTransportStreamID tsid ) { data[6]=tsid.get(); }
eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
:eServiceReference(eServiceReference::idDVB, 0)
{
setTransportStreamID(transport_stream_id);
setOriginalNetworkID(original_network_id);
setDVBNamespace(dvbnamespace);
setServiceID(service_id);
setServiceType(service_type);
}
void set(const eDVBChannelID &chid)
{
setDVBNamespace(chid.dvbnamespace);
setOriginalNetworkID(chid.original_network_id);
setTransportStreamID(chid.transport_stream_id);
}
void getChannelID(eDVBChannelID &chid) const
{
chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
}
eServiceReferenceDVB()
:eServiceReference(eServiceReference::idDVB, 0)
{
}
eServiceReferenceDVB(const std::string &string)
:eServiceReference(string)
{
}
};
////////////////// TODO: we need an interface here, but what exactly?
#include <set>
// btw, still implemented in db.cpp. FIX THIS, TOO.
class eDVBChannelQuery;
class eDVBService: public iStaticServiceInformation
{
DECLARE_REF(eDVBService);
public:
enum cacheID
{
cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cacheMax
};
int getCachePID(cacheID);
void setCachePID(cacheID, int);
bool cacheEmpty() { return m_cache.empty(); }
eDVBService();
/* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
std::string m_service_name, m_service_name_sort;
std::string m_provider_name;
void genSortName();
int m_flags;
std::set<int> m_ca;
std::map<int,int> m_cache;
virtual ~eDVBService();
eDVBService &operator=(const eDVBService &);
// iStaticServiceInformation
RESULT getName(const eServiceReference &ref, std::string &name);
RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
/* for filtering: */
int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
};
//////////////////
class iDVBChannel;
class iDVBDemux;
class iDVBFrontendParameters;
class iDVBChannelListQuery: public iObject
{
public:
virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)=0;
};
class eDVBChannelQuery: public iObject
{
DECLARE_REF(eDVBChannelQuery);
public:
enum
{
tName,
tProvider,
tType,
tBouquet,
tSatellitePosition,
tChannelID,
tAND,
tOR
};
int m_type;
int m_inverse;
std::string m_string;
int m_int;
eDVBChannelID m_channelid;
/* sort is only valid in root, and must be from the enum above. */
int m_sort;
std::string m_bouquet_name;
static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
ePtr<eDVBChannelQuery> m_p1, m_p2;
};
class iDVBChannelList: public iObject
{
public:
virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
virtual RESULT removeChannel(const eDVBChannelID &id)=0;
virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
virtual RESULT addService(const eServiceReferenceDVB &service, eDVBService *service)=0;
virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
virtual RESULT flush()=0;
virtual RESULT getBouquet(const eServiceReference &ref, eBouquet* &bouquet)=0;
virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query, const eServiceReference &source)=0;
};
class iDVBFrontendParameters: public iObject
{
public:
virtual RESULT getSystem(int &type) const = 0;
virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
virtual RESULT getHash(unsigned long &hash) const = 0;
};
#define MAX_DISEQC_LENGTH 16
class eDVBDiseqcCommand
{
public:
int len;
__u8 data[MAX_DISEQC_LENGTH];
#if HAVE_DVB_API_VERSION < 3
int tone;
int voltage;
#endif
};
class iDVBSatelliteEquipmentControl;
class eSecCommandList;
class iDVBFrontend: public iObject
{
public:
enum {
feSatellite, feCable, feTerrestrial
};
virtual RESULT getFrontendType(int &type)=0;
virtual RESULT tune(const iDVBFrontendParameters &where)=0;
virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
enum {
stateIdle = 0,
stateTuning = 1,
stateFailed = 2,
stateLock = 3,
stateLostLock = 4,
};
virtual RESULT getState(int &state)=0;
enum {
toneOff, toneOn
};
virtual RESULT setTone(int tone)=0;
enum {
voltageOff, voltage13, voltage18, voltage13_5, voltage18_5
};
virtual RESULT setVoltage(int voltage)=0;
virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
virtual RESULT sendToneburst(int burst)=0;
virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
virtual RESULT setSecSequence(const eSecCommandList &list)=0;
enum {
bitErrorRate, signalPower, signalQuality
};
virtual int readFrontendData(int type)=0;
virtual RESULT getData(int num, int &data)=0;
virtual RESULT setData(int num, int val)=0;
/* 0 means: not compatible. other values are a priority. */
virtual int isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)=0;
};
class iDVBSatelliteEquipmentControl: public iObject
{
public:
virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat, int frontend_id)=0;
virtual int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *fe, int frontend_id)=0;
virtual void setRotorMoving(bool)=0;
};
struct eDVBCIRouting
{
int enabled;
};
class iDVBChannel: public iObject
{
public:
enum
{
state_idle, /* not yet tuned */
state_tuning, /* currently tuning (first time) */
state_failed, /* tuning failed. */
state_unavailable, /* currently unavailable, will be back without further interaction */
state_ok, /* ok */
state_last_instance, /* just one reference to this channel is left */
state_release /* channel is being shut down. */
};
enum
{
evtEOF, evtSOF, evtFailed
};
virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
virtual RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection)=0;
virtual RESULT getState(int &state)=0;
/* demux capabilities */
enum
{
capDecode = 1,
/* capCI = 2 */
};
virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
virtual RESULT getDemux(ePtr<iDVBDemux> &demux, int cap=0)=0;
/* direct frontend access for raw channels and/or status inquiries. */
virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
/* use count handling */
virtual void AddUse() = 0;
virtual void ReleaseUse() = 0;
};
/* signed, so we can express deltas. */
typedef long long pts_t;
class iFilePushScatterGather;
class iTSMPEGDecoder;
/* note that a cue sheet describes the logical positions. thus
everything is specified in pts and not file positions */
/* implemented in dvb.cpp */
class eCueSheet: public iObject, public Object
{
DECLARE_REF(eCueSheet);
public:
eCueSheet();
/* frontend */
void seekTo(int relative, const pts_t &pts);
void clear();
void addSourceSpan(const pts_t &begin, const pts_t &end);
void setSkipmode(const pts_t &ratio); /* 90000 is 1:1 */
void setDecodingDemux(iDVBDemux *demux, iTSMPEGDecoder *decoder);
/* frontend and backend */
eSingleLock m_lock;
/* backend */
enum { evtSeek, evtSkipmode, evtSpanChanged };
RESULT connectEvent(const Slot1<void, int> &event, ePtr<eConnection> &connection);
std::list<std::pair<pts_t,pts_t> > m_spans; /* begin, end */
std::list<std::pair<int, pts_t> > m_seek_requests; /* relative, delta */
pts_t m_skipmode_ratio;
Signal1<void,int> m_event;
ePtr<iDVBDemux> m_decoding_demux;
ePtr<iTSMPEGDecoder> m_decoder;
};
class iDVBPVRChannel: public iDVBChannel
{
public:
enum
{
state_eof = state_release + 1 /* end-of-file reached. */
};
/* FIXME: there are some very ugly buffer-end and ... related problems */
/* so this is VERY UGLY.
ok, it's going to get better. but still...*/
virtual RESULT playFile(const char *file) = 0;
virtual void stopFile() = 0;
virtual void setCueSheet(eCueSheet *cuesheet) = 0;
virtual RESULT getLength(pts_t &pts) = 0;
/* we explicitely ask for the decoding demux here because a channel
can be shared between multiple decoders.
*/
virtual RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode) = 0;
/* skipping must be done with a cue sheet */
};
class iDVBSectionReader;
class iDVBTSRecorder;
class iTSMPEGDecoder;
class iDVBDemux: public iObject
{
public:
virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
virtual RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder)=0;
virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
virtual RESULT getSTC(pts_t &pts, int num=0)=0;
virtual RESULT getCADemuxID(uint8_t &id)=0;
virtual RESULT flush()=0;
};
class iTSMPEGDecoder: public iObject
{
public:
enum { pidDisabled = -1 };
/** Set Displayed Video PID */
virtual RESULT setVideoPID(int vpid)=0;
enum { af_MPEG, af_AC3, af_DTS };
/** Set Displayed Audio PID and type */
virtual RESULT setAudioPID(int apid, int type)=0;
/** Set Displayed Videotext PID */
virtual RESULT setTextPID(int vpid)=0;
/** Set Sync mode to PCR */
virtual RESULT setSyncPCR(int pcrpid)=0;
enum { sm_Audio, sm_Video };
/** Set Sync mode to either audio or video master */
virtual RESULT setSyncMaster(int who)=0;
/** Apply settings */
virtual RESULT start()=0;
/** Freeze frame. Either continue decoding (without display) or halt. */
virtual RESULT freeze(int cont)=0;
/** Continue after freeze. */
virtual RESULT unfreeze()=0;
/** fast forward by skipping frames. 0 is disabled, 2 is twice-the-speed, ... */
virtual RESULT setFastForward(int skip=0)=0;
// stop on .. Picture
enum { spm_I, spm_Ref, spm_Any };
/** Stop on specific decoded picture. For I-Frame display. */
virtual RESULT setSinglePictureMode(int when)=0;
enum { pkm_B, pkm_PB };
/** Fast forward by skipping either B or P/B pictures */
virtual RESULT setPictureSkipMode(int what)=0;
/** Slow Motion by repeating pictures */
virtual RESULT setSlowMotion(int repeat)=0;
enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
/** Set Zoom. mode *must* be fitting. */
virtual RESULT setZoom(int what)=0;
virtual RESULT setTrickmode(int what) = 0;
virtual RESULT getPTS(int what, pts_t &pts) = 0;
};
#endif
|