MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
linuxavcinfo.cpp
Go to the documentation of this file.
1 #include "linuxavcinfo.h"
2 
3 // MythTV headers
4 #include "mythcontext.h"
5 
6 #define LOC QString("LAVCInfo(): ")
7 
8 bool LinuxAVCInfo::Update(uint64_t _guid, raw1394handle_t handle,
9  uint _port, uint _node)
10 {
11  port = _port;
12  node = _node;
13 
14  if (guid == _guid)
15  return true; // we're done
16 
18  // get basic info
19 
20  rom1394_directory dir;
21  if (rom1394_get_directory(handle, _node, &dir) < 0)
22  return false;
23 
24  guid = _guid;
25  vendorid = dir.vendor_id;
26  modelid = dir.model_id;
27  specid = dir.unit_spec_id;
28  firmware_revision = dir.unit_sw_version;
29  product_name = QString("%1").arg(dir.label);
30 
31  if (avc1394_subunit_info(handle, node, (uint32_t*)unit_table) < 0)
32  memset(unit_table, 0xff, sizeof(unit_table));
33 
34  return true;
35 }
36 
38 {
39  LOG(VB_RECORD, LOG_INFO,
40  LOC + QString("Getting raw1394 handle for port %1").arg(port));
41  fw_handle = raw1394_new_handle_on_port(port);
42 
43  if (!fw_handle)
44  {
45  LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to get handle for " +
46  QString("port: %1").arg(port) + ENO);
47 
48  return false;
49  }
50 
51  return true;
52 }
53 
55 {
56  if (fw_handle)
57  {
58  LOG(VB_RECORD, LOG_INFO, LOC + "Releasing raw1394 handle");
59  raw1394_destroy_handle(fw_handle);
60  fw_handle = NULL;
61  }
62 
63  return true;
64 }
65 
67  const vector<uint8_t> &_cmd,
68  vector<uint8_t> &result,
69  int retry_cnt)
70 {
71  retry_cnt = (retry_cnt < 0) ? 2 : retry_cnt;
72 
73  result.clear();
74 
75  if (!fw_handle || (node < 0))
76  return false;
77 
78  vector<uint8_t> cmd = _cmd;
79  while (cmd.size() & 0x3)
80  cmd.push_back(0x00);
81 
82  if (cmd.size() > 4096)
83  return false;
84 
85  uint32_t cmdbuf[1024];
86  for (uint i = 0; i < cmd.size(); i+=4)
87  cmdbuf[i>>2] = cmd[i]<<24 | cmd[i+1]<<16 | cmd[i+2]<<8 | cmd[i+3];
88 
89  uint result_length = 0;
90 
91  uint32_t *ret = avc1394_transaction_block2(
92  fw_handle, node, cmdbuf, cmd.size() >> 2,
93  &result_length, retry_cnt);
94 
95  if (!ret)
96  return false;
97 
98  for (uint i = 0; i < result_length; i++)
99  {
100  result.push_back((ret[i]>>24) & 0xff);
101  result.push_back((ret[i]>>16) & 0xff);
102  result.push_back((ret[i]>>8) & 0xff);
103  result.push_back((ret[i]) & 0xff);
104  }
105 
106  avc1394_transaction_block_close(fw_handle);
107 
108  return true;
109 }