File indexing completed on 2024-05-12 04:52:08
0001 /* 0002 * dvbcam_linux.h 0003 * 0004 * Copyright (C) 2010-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 DVBCAM_LINUX_H 0022 #define DVBCAM_LINUX_H 0023 0024 #include <QMap> 0025 #include <QTimer> 0026 0027 class QSocketNotifier; 0028 class DvbLinuxCamService; 0029 class DvbPmtSection; 0030 0031 class DvbLinuxCam : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit DvbLinuxCam(QObject *parent); 0036 ~DvbLinuxCam(); 0037 0038 void startCa(const QString &path); 0039 void startDescrambling(const QByteArray &pmtSection); 0040 void stopDescrambling(int serviceId); 0041 void stopCa(); 0042 0043 private slots: 0044 void pollModule(); 0045 void readyRead(); 0046 0047 public: 0048 enum PendingCommand { 0049 Nothing = 0, 0050 ExpectingReply = (1 << 0), 0051 ResetCa = (1 << 1), 0052 SendCreateTransportConnection = (1 << 2), 0053 SendReceiveData = (1 << 3), 0054 SendPoll = (1 << 4), 0055 SendProfileEnquiry = (1 << 5), 0056 SendProfileChange = (1 << 6), 0057 SendApplicationInfoEnquiry = (1 << 7), 0058 SendCaInfoEnquiry = (1 << 8) 0059 }; 0060 0061 Q_DECLARE_FLAGS(PendingCommands, PendingCommand) 0062 0063 private: 0064 Q_DISABLE_COPY(DvbLinuxCam) 0065 0066 enum TransportLayerTag { 0067 StatusByte = 0x80, 0068 ReceiveData = 0x81, 0069 CreateTransportConnection = 0x82, 0070 CreateTransportConnectionReply = 0x83, 0071 DataLast = 0xa0 0072 }; 0073 0074 enum { 0075 ConnectionId = 0x01, 0076 HeaderSize = 17 0077 }; 0078 0079 enum SessionLayerTag { 0080 OpenSessionRequest = 0x91, 0081 OpenSessionResponse = 0x92, 0082 SessionNumber = 0x90 0083 }; 0084 0085 enum Resources { 0086 ResourceManager = 0x00010041, 0087 ApplicationInformation = 0x00020041, 0088 ConditionalAccess = 0x00030041 0089 }; 0090 0091 enum SessionNumbers { 0092 ResourceManagerSession = 1, 0093 ApplicationInformationSession = 2, 0094 ConditionalAccessSession = 3 0095 }; 0096 0097 enum ApplicationLayerTag { 0098 ProfileEnquiry = 0x9f8010, 0099 ProfileReply = 0x9f8011, 0100 ProfileChange = 0x9f8012, 0101 ApplicationInfoEnquiry = 0x9f8020, 0102 ApplicationInfo = 0x9f8021, 0103 CaInfoEnquiry = 0x9f8030, 0104 CaInfo = 0x9f8031, 0105 CaPmt = 0x9f8032 0106 }; 0107 0108 enum CaPmtListManagement { 0109 Only = 0x03, 0110 Add = 0x04, 0111 Update = 0x05 0112 }; 0113 0114 enum CaPmtCommand { 0115 Descramble = 0x01, 0116 StopDescrambling = 0x04 0117 }; 0118 0119 bool detectSlot(); 0120 int decodeLength(const unsigned char *&data, int &size); 0121 void resize(int messageSize); 0122 void handleTransportLayer(const unsigned char *data, int size); 0123 void handleSessionLayer(const unsigned char *data, int size); 0124 void handleApplicationLayer(const unsigned char *data, int size); 0125 void handlePendingCommands(); 0126 void customEvent(QEvent *event) override; 0127 void sendCaPmt(const DvbPmtSection &pmtSection, CaPmtListManagement listManagement, 0128 CaPmtCommand command); 0129 void sendApplicationLayerMessage(ApplicationLayerTag tag, char *data, char *end); 0130 void sendSessionLayerMessage(SessionLayerTag tag, char *data, char *end); 0131 void sendTransportLayerMessage(TransportLayerTag tag, char *data, char *end); 0132 0133 int caFd; 0134 int slot; 0135 QTimer pollTimer; 0136 QSocketNotifier *socketNotifier; 0137 PendingCommands pendingCommands; 0138 QByteArray message; 0139 char *messageData; 0140 bool ready; 0141 bool eventPosted; 0142 QMap<int, DvbLinuxCamService> services; 0143 }; 0144 0145 Q_DECLARE_OPERATORS_FOR_FLAGS(DvbLinuxCam::PendingCommands) 0146 0147 #endif /* DVBCAM_LINUX_H */