summaryrefslogtreecommitdiffstats
path: root/kaffeine/src/input/dvb/dvbstream.h
blob: fe85f047b7efb7c3618d2e7943b1a0c7cb88ee24 (plain)
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
/*
 * dvbstream.h
 *
 * Copyright (C) 2003-2007 Christophe Thommeret <hftom@free.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifndef DVBSTREAM_H
#define DVBSTREAM_H

#include <sys/poll.h>
#include <sys/stat.h>

#include <qthread.h>
#include <qptrlist.h>
#include <qfile.h>
#include <qobject.h>
#include <qtimer.h>
#include <qstringlist.h>

#include "channeldesc.h"
#include "dvbout.h"
#include "ts2rtp.h"
#include "dvbconfig.h"

#define MAX_CHANNELS 8

class DVBevents;
class DvbCam;
class KaffeineDvbPlugin;
class EventTable;



class DvbStream : public QObject, public QThread
{
	Q_OBJECT

public :

	enum { ErrDontSwitchAudio=-1, ErrCantTune=1, ErrCantSetPids=2, ErrIsRecording=3, ErrNoLive=4,
		ErrCantOpenFile=5, ErrIsBroadcasting=6, ErrCamUsed=7 };

	DvbStream( Device *d, const QString &charset, EventTable *et );
	~DvbStream();
	int getAdapter() { return dvbDevice->adapter; }
	int getTuner() { return dvbDevice->tuner; }
	fe_type_t getType() {return dvbDevice->type; }
	void setPlug( KaffeineDvbPlugin *p );
	QStringList getSources( bool all=false );
	bool canSource( ChannelDesc *chan );
	int getPriority();
	bool tuneDvb( ChannelDesc *chan, bool dvr=true );
	void stopFrontend();
	virtual void run();
	int goLive( ChannelDesc *chan, const QString &pipeName, int ringBufSize );
	void preStopLive();
	void stopLive( ChannelDesc *chan );
	void stop();
	void stopScan();
	void setScanning( bool b );
	bool hasVideo();
	bool doPause( const QString &name );
	bool timeShiftMode();
	bool running() const;
	ChannelDesc getLiveChannel();
	Transponder getCurrentTransponder();
	unsigned long getCurrentFreq();
	bool isTuned();
	bool startTimer( ChannelDesc *chan, QString path, int maxsize, RecTimer *t, QString filename );
	int canStartTimer( bool &live, ChannelDesc *chan );
	int canStartBroadcast( bool &live, ChannelDesc *chan );
	bool startBroadcast( QPtrList<ChannelDesc> *list, Ts2Rtp *rtp );
	void stopBroadcast();
	bool hasRec();
	bool hasBroadcast();
	bool hasLive();
	bool liveIsRecording();
	int getSNR();
	void probeCam();
	void showCamDialog();

	struct pollfd pfd;
	DVBevents *dvbEvents;

public slots:

	bool checkStatus();
	void receivePlayDvb();
	void recordEnded( DVBout *o, RecTimer *t, bool kill );
	void receiveShifting( bool b );
	void updateTimer( RecTimer *t, int ms );

protected:

	void timerEvent( QTimerEvent* ev );

private :

	int setDiseqc( int switchPos, ChannelDesc *chan, int hiband, int &rotor, bool dvr );
	void moveRotor( int switchPos, ChannelDesc *chan, int hiband, bool dvr );
	void rotorCommand( int cmd, int n1=0, int n2=0, int n3=0 );
	void gotoX( double azimuth );
	double getAzimuth( double angle );
	double getSourceAngle( QString source );
	int getSatPos( const QString &src );
	bool setPids( DVBout *o );
	void removePids( DVBout *o );
	void removeOut( DVBout *o );
	void recordingState();
	void startReading();
	bool openFe();
	bool closeFe();
	void connectStatus( bool con );

	QFile liveFile;
	bool timeShifting;
	QPtrList<DVBout> out;
	Device *dvbDevice;
	int waitPause;
	DVBout *delOut;
	Transponder currentTransponder;

	QString frontendName;
	QString dvrName;
	QString demuxName;
	int fdFrontend;
	int ndmx;
	int fdDvr, fdPipe;
	bool isRunning;
	QTimer statusTimer;
	QString timeShiftFileName;
	DvbCam *cam;
	bool camProbed;
	int diseqcTwice;
	KaffeineDvbPlugin *plug;

signals:

	void playDvb();
	void isRecording(bool);
	void isBroadcasting(bool);
	void timerEnded(RecTimer*);

	void errorMsg( QString );
	void snrStatus( int );
	void signalStatus( int );
	void lockStatus( bool );
	void shifting( bool );

};

#endif /* DVBSTREAM_H */