File indexing completed on 2024-05-12 04:52:13

0001 /*
0002  * dvbdevice_linux.h
0003  *
0004  * Copyright (C) 2007-2011 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef DVBDEVICE_LINUX_H
0022 #define DVBDEVICE_LINUX_H
0023 
0024 #include <QThread>
0025 #include "dvbbackenddevice.h"
0026 #include "dvbcam_linux.h"
0027 
0028 extern "C" {
0029   #include <libdvbv5/dvb-file.h>
0030   #include <libdvbv5/dvb-demux.h>
0031   #include <libdvbv5/dvb-v5-std.h>
0032   #include <libdvbv5/dvb-scan.h>
0033 }
0034 
0035 class DvbLinuxDevice : public QThread, public DvbBackendDevice
0036 {
0037 public:
0038     explicit DvbLinuxDevice(QObject *parent);
0039     ~DvbLinuxDevice();
0040 
0041     bool isReady() const;
0042     void startDevice(const QString &deviceId_);
0043     void startCa();
0044     void stopCa();
0045     void stopDevice();
0046     void enableDvbDump() override;
0047     QString getDeviceId() override;
0048     QString getFrontendName() override;
0049 
0050     QString caPath;
0051     QString caUdi;
0052     QString demuxPath;
0053     QString demuxUdi;
0054     QString dvrPath;
0055     QString dvrUdi;
0056     int adapter;
0057     int index;
0058     int numDemux;
0059     struct dvb_v5_fe_parms *dvbv5_parms;
0060     QString frontendPath;
0061     QString frontendUdi;
0062 
0063 protected:
0064     TransmissionTypes getTransmissionTypes() override;
0065     Capabilities getCapabilities() override;
0066     void setFrontendDevice(DvbFrontendDevice *frontend_) override;
0067     void setDeviceEnabled(bool enabled_) override;
0068     bool acquire() override;
0069     bool setHighVoltage(int higherVoltage) override;
0070     bool sendMessage(const char *message, int length) override;
0071     bool sendBurst(SecBurst burst) override;
0072     bool satSetup(QString lnbModel, int satNumber, int bpf) override;
0073     bool tune(const DvbTransponder &transponder) override; // discards obsolete data
0074     bool getProps(DvbTransponder &transponder) override;
0075     bool isTuned() override;
0076     float getFrqMHz() override;
0077     float getSignal(Scale &scale) override;
0078     float getSnr(DvbBackendDevice::Scale &scale) override;
0079     bool addPidFilter(int pid) override;
0080     void removePidFilter(int pid) override;
0081     void startDescrambling(const QByteArray &pmtSectionData) override;
0082     void stopDescrambling(int serviceId) override;
0083     void release() override;
0084 
0085 private:
0086     void startDvr();
0087     void stopDvr();
0088     void run() override;
0089 
0090     bool ready;
0091     QString deviceId;
0092     QString frontendName;
0093     TransmissionTypes transmissionTypes;
0094     Capabilities capabilities;
0095     DvbFrontendDevice *frontend;
0096     bool enabled;
0097     QMap<int, int> dmxFds;
0098 
0099     float freqMHz;
0100 
0101     int verbose;
0102     int dvrFd;
0103     int dvrPipe[2];
0104     DvbDataBuffer dvrBuffer;
0105 
0106     DvbLinuxCam cam;
0107 };
0108 
0109 class DvbDeviceMonitor;
0110 class DvbLinuxDeviceManager : public QObject
0111 {
0112     Q_OBJECT
0113 public:
0114     explicit DvbLinuxDeviceManager(QObject *parent);
0115     ~DvbLinuxDeviceManager();
0116 
0117     void componentAdded(QString node, int adapter, int index);
0118     void componentRemoved(QString node, int adapter, int index);
0119 public slots:
0120     void doColdPlug();
0121 
0122 signals:
0123     void requestBuiltinDeviceManager(QObject *&bultinDeviceManager);
0124     void deviceAdded(DvbBackendDevice *device);
0125     void deviceRemoved(DvbBackendDevice *device);
0126 
0127 private slots:
0128     void componentAdded(const QString &udi);
0129     void componentRemoved(const QString &udi);
0130 
0131 private:
0132     int readSysAttr(const QString &path);
0133 
0134     QMap<int, DvbLinuxDevice *> devices;
0135     QMap<QString, DvbLinuxDevice *> udis;
0136     class DvbDeviceMonitor *monitor;
0137 };
0138 
0139 #endif /* DVBDEVICE_LINUX_H */