MythTV  master
firewiredevice.h
Go to the documentation of this file.
1 
7 #ifndef _FIREWIRE_DEVICE_H_
8 #define _FIREWIRE_DEVICE_H_
9 
10 // C++ headers
11 #include <vector>
12 using namespace std;
13 
14 // Qt headers
15 #include <QString>
16 #include <QMutex>
17 
18 // MythTV headers
19 #include "streamlisteners.h"
20 #include "avcinfo.h"
21 
22 class TSPacket;
23 
25 {
26  public:
27 
28  // Public enums
29  typedef enum
30  {
35  } PowerState;
36 
37  // AVC commands
38  typedef enum
39  {
40  kAVCControlCommand = 0x00,
41  kAVCStatusInquiryCommand = 0x01,
42  kAVCSpecificInquiryCommand = 0x02,
43  kAVCNotifyCommand = 0x03,
44  kAVCGeneralInquiryCommand = 0x04,
45 
46  kAVCNotImplementedStatus = 0x08,
47  kAVCAcceptedStatus = 0x09,
48  kAVCRejectedStatus = 0x0a,
49  kAVCInTransitionStatus = 0x0b,
50  kAVCImplementedStatus = 0x0c,
51  kAVCChangedStatus = 0x0d,
52 
53  kAVCInterimStatus = 0x0f,
54  kAVCResponseImplemented = 0x0c,
55  } IEEE1394Command;
56 
57  // AVC unit addresses
58  typedef enum
59  {
60  kAVCSubunitId0 = 0x00,
61  kAVCSubunitId1 = 0x01,
62  kAVCSubunitId2 = 0x02,
63  kAVCSubunitId3 = 0x03,
64  kAVCSubunitId4 = 0x04,
65  kAVCSubunitIdExtended = 0x05,
66  kAVCSubunitIdIgnore = 0x07,
67 
68  kAVCSubunitTypeVideoMonitor = (0x00 << 3),
69  kAVCSubunitTypeAudio = (0x01 << 3),
70  kAVCSubunitTypePrinter = (0x02 << 3),
71  kAVCSubunitTypeDiscRecorder = (0x03 << 3),
72  kAVCSubunitTypeTapeRecorder = (0x04 << 3),
73  kAVCSubunitTypeTuner = (0x05 << 3),
74  kAVCSubunitTypeCA = (0x06 << 3),
75  kAVCSubunitTypeVideoCamera = (0x07 << 3),
76  kAVCSubunitTypePanel = (0x09 << 3),
77  kAVCSubunitTypeBulletinBoard = (0x0a << 3),
78  kAVCSubunitTypeCameraStorage = (0x0b << 3),
79  kAVCSubunitTypeMusic = (0x0c << 3),
80  kAVCSubunitTypeVendorUnique = (0x1c << 3),
81  kAVCSubunitTypeExtended = (0x1e << 3),
82  kAVCSubunitTypeUnit = (0x1f << 3),
83  } IEEE1394UnitAddress;
84 
85  // AVC opcode
86  typedef enum
87  {
88  // Unit
89  kAVCUnitPlugInfoOpcode = 0x02,
90  kAVCUnitDigitalOutputOpcode = 0x10,
91  kAVCUnitDigitalInputOpcode = 0x11,
92  kAVCUnitChannelUsageOpcode = 0x12,
93  kAVCUnitOutputPlugSignalFormatOpcode = 0x18,
94  kAVCUnitInputPlugSignalFormatOpcode = 0x19,
95  kAVCUnitConnectAVOpcode = 0x20,
96  kAVCUnitDisconnectAVOpcode = 0x21,
97  kAVCUnitConnectionsOpcode = 0x22,
98  kAVCUnitConnectOpcode = 0x24,
99  kAVCUnitDisconnectOpcode = 0x25,
100  kAVCUnitUnitInfoOpcode = 0x30,
101  kAVCUnitSubunitInfoOpcode = 0x31,
102  kAVCUnitSignalSourceOpcode = 0x1a,
103  kAVCUnitPowerOpcode = 0xb2,
104 
105  // Common Unit + Subunit
106  kAVCCommonOpenDescriptorOpcode = 0x08,
107  kAVCCommonReadDescriptorOpcode = 0x09,
108  kAVCCommonWriteDescriptorOpcode = 0x0A,
109  kAVCCommonSearchDescriptorOpcode = 0x0B,
110  kAVCCommonObjectNumberSelectOpcode = 0x0D,
111  kAVCCommonPowerOpcode = 0xB2,
112  kAVCCommonReserveOpcode = 0x01,
113  kAVCCommonPlugInfoOpcode = 0x02,
114  kAVCCommonVendorDependentOpcode = 0x00,
115 
116  // Panel
117  kAVCPanelPassThrough = 0x7c,
118  } IEEE1394Opcode;
119 
120  // AVC param 0
121  typedef enum
122  {
123  kAVCPowerStateOn = 0x70,
124  kAVCPowerStateOff = 0x60,
125  kAVCPowerStateQuery = 0x7f,
126  } IEEE1394UnitPowerParam0;
127 
128  typedef enum
129  {
130  kAVCPanelKeySelect = 0x00,
131  kAVCPanelKeyUp = 0x01,
132  kAVCPanelKeyDown = 0x02,
133  kAVCPanelKeyLeft = 0x03,
134  kAVCPanelKeyRight = 0x04,
135  kAVCPanelKeyRightUp = 0x05,
136  kAVCPanelKeyRightDown = 0x06,
137  kAVCPanelKeyLeftUp = 0x07,
138  kAVCPanelKeyLeftDown = 0x08,
139  kAVCPanelKeyRootMenu = 0x09,
140  kAVCPanelKeySetupMenu = 0x0A,
141  kAVCPanelKeyContentsMenu = 0x0B,
142  kAVCPanelKeyFavoriteMenu = 0x0C,
143  kAVCPanelKeyExit = 0x0D,
144 
145  kAVCPanelKey0 = 0x20,
146  kAVCPanelKey1 = 0x21,
147  kAVCPanelKey2 = 0x22,
148  kAVCPanelKey3 = 0x23,
149  kAVCPanelKey4 = 0x24,
150  kAVCPanelKey5 = 0x25,
151  kAVCPanelKey6 = 0x26,
152  kAVCPanelKey7 = 0x27,
153  kAVCPanelKey8 = 0x28,
154  kAVCPanelKey9 = 0x29,
155  kAVCPanelKeyDot = 0x2A,
156  kAVCPanelKeyEnter = 0x2B,
157  kAVCPanelKeyClear = 0x2C,
158 
159  kAVCPanelKeyChannelUp = 0x30,
160  kAVCPanelKeyChannelDown = 0x31,
161  kAVCPanelKeyPreviousChannel = 0x32,
162  kAVCPanelKeySoundSelect = 0x33,
163  kAVCPanelKeyInputSelect = 0x34,
164  kAVCPanelKeyDisplayInfo = 0x35,
165  kAVCPanelKeyHelp = 0x36,
166  kAVCPanelKeyPageUp = 0x37,
167  kAVCPanelKeyPageDown = 0x38,
168 
169  kAVCPanelKeyPower = 0x40,
170  kAVCPanelKeyVolumeUp = 0x41,
171  kAVCPanelKeyVolumeDown = 0x42,
172  kAVCPanelKeyMute = 0x43,
173  kAVCPanelKeyPlay = 0x44,
174  kAVCPanelKeyStop = 0x45,
175  kAVCPanelKeyPause = 0x46,
176  kAVCPanelKeyRecord = 0x47,
177  kAVCPanelKeyRewind = 0x48,
178  kAVCPanelKeyFastForward = 0x49,
179  kAVCPanelKeyEject = 0x4a,
180  kAVCPanelKeyForward = 0x4b,
181  kAVCPanelKeyBackward = 0x4c,
182 
183  kAVCPanelKeyAngle = 0x50,
184  kAVCPanelKeySubPicture = 0x51,
185 
186  kAVCPanelKeyTuneFunction = 0x67,
187 
188  kAVCPanelKeyPress = 0x00,
189  kAVCPanelKeyRelease = 0x80,
190 
191  } IEEE1394PanelPassThroughParam0;
192 
193  virtual ~FirewireDevice() = default;
194 
195  // Commands
196  virtual bool OpenPort(void) = 0;
197  virtual bool ClosePort(void) = 0;
198  virtual bool ResetBus(void) { return false; }
199 
200  virtual void AddListener(TSDataListener*);
201  virtual void RemoveListener(TSDataListener*);
202 
203  // Sets
204  virtual bool SetPowerState(bool on);
205  virtual bool SetChannel(const QString &panel_model,
206  uint alt_method, uint channel);
207 
208  // Gets
209  virtual bool IsPortOpen(void) const = 0;
210  bool IsSTBBufferCleared(void) const { return m_buffer_cleared; }
211 
212  // non-const Gets
213  virtual PowerState GetPowerState(void);
214 
215  // Statics
216  static bool IsSTBSupported(const QString &model);
217  static QString GetModelName(uint vendor_id, uint model_id);
218  static vector<AVCInfo> GetSTBList(void);
219 
220  protected:
221  FirewireDevice(uint64_t guid, uint subunitid, uint speed);
222 
223  virtual bool SendAVCCommand(const vector<uint8_t> &cmd,
224  vector<uint8_t> &result,
225  int retry_cnt) = 0;
226  bool GetSubunitInfo(uint8_t table[32]);
227 
228  void SetLastChannel(uint channel);
229  void ProcessPATPacket(const TSPacket&);
230  virtual void BroadcastToListeners(
231  const unsigned char *data, uint dataSize);
232 
233  uint64_t m_guid;
236  uint m_last_channel {0};
237  uint m_last_crc {0};
238  bool m_buffer_cleared {true};
239 
240  uint m_open_port_cnt {0};
241  vector<TSDataListener*> m_listeners;
242  mutable QMutex m_lock;
243 
245  static QMap<uint64_t,QString> s_id_to_model;
246  static QMutex s_static_lock;
247 };
248 
249 #endif // _FIREWIRE_DEVICE_H_
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:166
static QMutex s_static_lock
unsigned int uint
Definition: compat.h:140
vector< TSDataListener * > m_listeners
static QMap< uint64_t, QString > s_id_to_model
Vendor ID + Model ID to FirewireDevice STB model string.
virtual bool ResetBus(void)
bool IsSTBBufferCleared(void) const