8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/avcinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

AVCInfo::AVCInfo()
{
memset(m_unit_table, 0xff, sizeof(m_unit_table));
m_unit_table.fill(0xff);
}

AVCInfo::AVCInfo(const AVCInfo &o) :
Expand All @@ -18,7 +18,7 @@ AVCInfo::AVCInfo(const AVCInfo &o) :
m_firmware_revision(o.m_firmware_revision),
m_product_name(o.m_product_name)
{
memcpy(m_unit_table, o.m_unit_table, sizeof(m_unit_table));
m_unit_table = o.m_unit_table;
}

AVCInfo &AVCInfo::operator=(const AVCInfo &o)
Expand All @@ -34,14 +34,14 @@ AVCInfo &AVCInfo::operator=(const AVCInfo &o)
m_modelid = o.m_modelid;
m_firmware_revision = o.m_firmware_revision;
m_product_name = o.m_product_name;
memcpy(m_unit_table, o.m_unit_table, sizeof(m_unit_table));
m_unit_table = o.m_unit_table;

return *this;
}

bool AVCInfo::GetSubunitInfo(void)
{
memset(m_unit_table, 0xff, 32 * sizeof(uint8_t));
m_unit_table.fill(0xff);

for (uint i = 0; i < 8; i++)
{
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/recorders/avcinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define AVC_INFO_H

// C++ headers
#include <array>
#include <cstdint>
#include <vector>
using namespace std;
Expand Down Expand Up @@ -50,7 +51,7 @@ class AVCInfo
uint m_modelid {0};
uint m_firmware_revision {0};
QString m_product_name;
uint8_t m_unit_table[32] {};
std::array<uint8_t,32> m_unit_table {};
};

#endif // AVC_INFO_H
27 changes: 10 additions & 17 deletions mythtv/libs/libmythtv/recorders/dvbcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -324,7 +325,7 @@ void DVBCam::SetTimeOffset(double offset_in_seconds)
m_ciHandler->SetTimeOffset(offset_in_seconds);
}

static const char *cplm_info[] =
static std::array<const std::string,6> cplm_info
{
"CPLM_MORE",
"CPLM_FIRST",
Expand All @@ -334,7 +335,7 @@ static const char *cplm_info[] =
"CPLM_UPDATE"
};

cCiCaPmt CreateCAPMT(const ProgramMapTable& /*pmt*/, const unsigned short* /*casids*/, uint /*cplm*/);
cCiCaPmt CreateCAPMT(const ProgramMapTable& /*pmt*/, const dvbca_vector &/*casids*/, uint /*cplm*/);

/*
* Send a CA_PMT object to the CAM (see EN50221, section 8.4.3.4)
Expand All @@ -345,17 +346,9 @@ void DVBCam::SendPMT(const ProgramMapTable &pmt, uint cplm)

for (uint s = 0; s < (uint)m_ciHandler->NumSlots(); s++)
{
const unsigned short *casids = m_ciHandler->GetCaSystemIds(s);
dvbca_vector casids = m_ciHandler->GetCaSystemIds(s);

if (!casids)
{
LOG(success ? VB_DVBCAM : VB_GENERAL, LOG_ERR,
LOC + "GetCaSystemIds returned NULL! " +
QString("(Slot #%1)").arg(s));
continue;
}

if (!casids[0])
if (casids.empty())
{
LOG(success ? VB_DVBCAM : VB_GENERAL, LOG_ERR,
LOC + "CAM supports no CA systems! " +
Expand All @@ -371,7 +364,7 @@ void DVBCam::SendPMT(const ProgramMapTable &pmt, uint cplm)

LOG(VB_DVBCAM, LOG_INFO, LOC +
QString("Sending CA_PMT with %1 to CI slot #%2")
.arg(cplm_info[cplm]).arg(s));
.arg(QString::fromStdString(cplm_info[cplm])).arg(s));

if (!m_ciHandler->SetCaPmt(capmt, s))
{
Expand All @@ -386,16 +379,16 @@ void DVBCam::SendPMT(const ProgramMapTable &pmt, uint cplm)
}

static void process_desc(cCiCaPmt &capmt,
const unsigned short *casids,
const dvbca_vector &casids,
const desc_list_t &desc)
{
desc_list_t::const_iterator it;
for (it = desc.begin(); it != desc.end(); ++it)
{
ConditionalAccessDescriptor cad(*it);
for (uint q = 0; casids[q]; q++)
for (auto id : casids)
{
if (!cad.IsValid() || cad.SystemID() != casids[q])
if (!cad.IsValid() || cad.SystemID() != id)
continue;

LOG(VB_DVBCAM, LOG_INFO, QString("DVBCam: Adding CA descriptor: "
Expand All @@ -410,7 +403,7 @@ static void process_desc(cCiCaPmt &capmt,
}

cCiCaPmt CreateCAPMT(const ProgramMapTable &pmt,
const unsigned short *casids,
const dvbca_vector &casids,
uint cplm)
{
cCiCaPmt capmt(pmt.ProgramNumber(), cplm);
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/recorders/dvbchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,13 +1206,13 @@ double DVBChannel::GetSNR(bool *ok) const
// documented in dvbchannel.h
double DVBChannel::GetBitErrorRateDVBv5(bool *ok) const
{
struct dtv_property prop[2] = {};
std::array<struct dtv_property,2> prop {};
struct dtv_properties cmd = {};

prop[0].cmd = DTV_STAT_POST_ERROR_BIT_COUNT;
prop[1].cmd = DTV_STAT_POST_TOTAL_BIT_COUNT;
cmd.num = 2;
cmd.props = prop;
cmd.num = prop.size();
cmd.props = prop.data();
int ret = ioctl(m_fdFrontend, FE_GET_PROPERTY, &cmd);
LOG(VB_RECORD, LOG_DEBUG, LOC +
QString("FE DTV bit error rate ret=%1 res=%2 len=%3 scale=%4 val=%5 res=%6 len=%7 scale=%8 val=%9")
Expand Down
203 changes: 114 additions & 89 deletions mythtv/libs/libmythtv/recorders/dvbdev/dvbci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ static uint8_t *SetLength(uint8_t *Data, int Length)
return p;
}

//! @copydoc SetLength(uint8_t *Data, int Length)
static void SetLength(std::vector<uint8_t> &Data, int Length)
{
if (Length < 128)
{
Data.push_back(Length);
return;
}

// This will be replaced with the number of bytes in the length
size_t len_offset = Data.size();
Data.push_back(0);

int n = sizeof(Length);
for (int i = n - 1; i >= 0; i--) {
int b = (Length >> (8 * i)) & 0xFF;
if ((len_offset != Data.size()) || b)
Data.push_back(b);
}
Data[len_offset] = (Data.size() - len_offset) | SIZE_INDICATOR;
}

static char *CopyString(int Length, const uint8_t *Data)
///< Copies the string at Data.
///< \param Length The number of bytes to copy from Data.
Expand Down Expand Up @@ -240,15 +262,15 @@ bool cMutexLock::Lock(cMutex *Mutex)
class cTPDU {
private:
int m_size {0};
uint8_t m_data[MAX_TPDU_SIZE] {0};
std::array<uint8_t,MAX_TPDU_SIZE> m_data {0};
const uint8_t *GetData(const uint8_t *Data, int &Length) const;
public:
cTPDU(void) = default;
cTPDU(uint8_t Slot, uint8_t Tcid, uint8_t Tag, int Length = 0, const uint8_t *Data = nullptr);
uint8_t Slot(void) { return m_data[0]; }
uint8_t Tcid(void) { return m_data[1]; }
uint8_t Tag(void) { return m_data[2]; }
const uint8_t *Data(int &Length) { return GetData(m_data + 3, Length); }
const uint8_t *Data(int &Length) { return GetData(m_data.data() + 3, Length); }
uint8_t Status(void);
int Write(int fd);
int Read(int fd);
Expand Down Expand Up @@ -285,12 +307,12 @@ cTPDU::cTPDU(uint8_t Slot, uint8_t Tcid, uint8_t Tag, int Length, const uint8_t
case T_DATA_LAST:
case T_DATA_MORE:
if (Length <= MAX_TPDU_DATA) {
uint8_t *p = m_data + 3;
uint8_t *p = m_data.data() + 3;
p = SetLength(p, Length + 1);
*p++ = Tcid;
if (Length)
memcpy(p, Data, Length);
m_size = Length + (p - m_data);
m_size = Length + (p - m_data.data());
}
else
esyslog("ERROR: illegal data length for TPDU tag 0x%02X: %d", Tag, Length);
Expand All @@ -304,14 +326,14 @@ int cTPDU::Write(int fd)
{
Dump(true);
if (m_size)
return write(fd, m_data, m_size) == m_size ? OK : ERROR;
return write(fd, m_data.data(), m_size) == m_size ? OK : ERROR;
esyslog("ERROR: attemp to write TPDU with zero size");
return ERROR;
}

int cTPDU::Read(int fd)
{
m_size = safe_read(fd, m_data, sizeof(m_data));
m_size = safe_read(fd, m_data.data(), m_data.size());
if (m_size < 0) {
esyslog("ERROR: %m");
m_size = 0;
Expand Down Expand Up @@ -391,6 +413,8 @@ class cCiTransportConnection {
~cCiTransportConnection();
int Slot(void) const { return m_slot; }
int SendData(int Length, const uint8_t *Data);
int SendData(std::vector<uint8_t> &Data)
{ return SendData(Data.size(), Data.data()); }
int RecvData(void);
const uint8_t *Data(int &Length);
//XXX Close()
Expand Down Expand Up @@ -429,13 +453,13 @@ int cCiTransportConnection::SendTPDU(uint8_t Tag, int Length, const uint8_t *Dat

int cCiTransportConnection::RecvTPDU(void)
{
struct pollfd pfd[1];
std::array<struct pollfd,1> pfd {};
pfd[0].fd = m_fd;
pfd[0].events = POLLIN;
m_lastResponse = ERROR;

for (;;) {
int ret = poll(pfd, 1, CAM_READ_TIMEOUT);
int ret = poll(pfd.data(), 1, CAM_READ_TIMEOUT);
if (ret == -1 && (errno == EAGAIN || errno == EINTR))
continue;
break;
Expand Down Expand Up @@ -574,7 +598,7 @@ class cCiTransportLayer {
private:
int m_fd;
int m_numSlots;
cCiTransportConnection m_tc[MAX_CI_CONNECT];
std::array<cCiTransportConnection,MAX_CI_CONNECT> m_tc;
public:
cCiTransportLayer(int Fd, int NumSlots);
cCiTransportConnection *NewConnection(int Slot);
Expand Down Expand Up @@ -752,6 +776,8 @@ class cCiSession {
static int GetTag(int &Length, const uint8_t **Data);
static const uint8_t *GetData(const uint8_t *Data, int &Length);
int SendData(int Tag, int Length = 0, const uint8_t *Data = nullptr);
int SendData(int Tag, std::vector<uint8_t> &Data)
{ return SendData(Tag, Data.size(), Data.data()); };
public:
cCiSession(int SessionId, int ResourceId, cCiTransportConnection *Tc);
virtual ~cCiSession() = default;
Expand Down Expand Up @@ -796,36 +822,39 @@ const uint8_t *cCiSession::GetData(const uint8_t *Data, int &Length)

int cCiSession::SendData(int Tag, int Length, const uint8_t *Data)
{
uint8_t buffer[2048];
uint8_t *p = buffer;
*p++ = ST_SESSION_NUMBER;
*p++ = 0x02;
*p++ = (m_sessionId >> 8) & 0xFF;
*p++ = m_sessionId & 0xFF;
*p++ = (Tag >> 16) & 0xFF;
*p++ = (Tag >> 8) & 0xFF;
*p++ = Tag & 0xFF;
if (Length >= 0)
if (Length < 0)
{
esyslog("ERROR: CAM: data length (%d) is negative", Length);
return ERROR;
}

if (!Data)
{
esyslog("ERROR: CAM: Data pointer null");
return ERROR;
}

std::vector<uint8_t> buffer {
ST_SESSION_NUMBER, 0x02,
static_cast<uint8_t>((m_sessionId >> 8) & 0xFF),
static_cast<uint8_t>((m_sessionId ) & 0xFF),
static_cast<uint8_t>((Tag >> 16) & 0xFF),
static_cast<uint8_t>((Tag >> 8) & 0xFF),
static_cast<uint8_t>((Tag ) & 0xFF)} ;
buffer.reserve(2048);

SetLength(buffer, Length);
if (buffer.size() + Length >= buffer.capacity())
{
p = SetLength(p, Length);
if (p - buffer + Length < int(sizeof(buffer)))
{
if (Length != 0)
{
if (!Data)
{
esyslog("ERROR: CAM: Data pointer null");
return ERROR;
}
memcpy(p, Data, Length);
p += Length;
}
return m_tc->SendData(p - buffer, buffer);
}
esyslog("ERROR: CAM: data length (%d) exceeds buffer size", Length);
return ERROR;
}
esyslog("ERROR: CAM: data length (%d) is negative", Length);
return ERROR;

if (Length != 0)
{
buffer.insert(buffer.end(), Data, Data + Length);
}
return m_tc->SendData(buffer);
}

bool cCiSession::Process(int Length, const uint8_t *Data)
Expand Down Expand Up @@ -859,7 +888,7 @@ bool cCiResourceManager::Process(int Length, const uint8_t *Data)
switch (Tag) {
case AOT_PROFILE_ENQ: {
dbgprotocol("%d: <== Profile Enquiry\n", SessionId());
uint32_t resources[] =
const std::array<const uint32_t,5> resources
{
htonl(RI_RESOURCE_MANAGER),
htonl(RI_APPLICATION_INFORMATION),
Expand All @@ -868,7 +897,8 @@ bool cCiResourceManager::Process(int Length, const uint8_t *Data)
htonl(RI_MMI)
};
dbgprotocol("%d: ==> Profile\n", SessionId());
SendData(AOT_PROFILE, sizeof(resources), (uint8_t*)resources);
SendData(AOT_PROFILE, resources.size() * sizeof(uint32_t),
reinterpret_cast<const uint8_t*>(resources.data()));
m_state = 3;
}
break;
Expand Down Expand Up @@ -988,13 +1018,12 @@ bool cCiApplicationInformation::EnterMenu(void)
class cCiConditionalAccessSupport : public cCiSession {
private:
int m_state {0};
int m_numCaSystemIds {0};
unsigned short m_caSystemIds[MAXCASYSTEMIDS + 1] {0}; // list is zero terminated!
dvbca_vector m_caSystemIds {};
bool m_needCaPmt {false};
public:
cCiConditionalAccessSupport(int SessionId, cCiTransportConnection *Tc);
bool Process(int Length = 0, const uint8_t *Data = nullptr) override; // cCiSession
const unsigned short *GetCaSystemIds(void) { return m_caSystemIds; }
dvbca_vector GetCaSystemIds(void) { return m_caSystemIds; }
bool SendPMT(cCiCaPmt &CaPmt);
bool NeedCaPmt(void) const { return m_needCaPmt; }
};
Expand All @@ -1020,22 +1049,16 @@ bool cCiConditionalAccessSupport::Process(int Length, const uint8_t *Data)
dbgprotocol(" %04X", id);
d += 2;
l -= 2;
if (m_numCaSystemIds < MAXCASYSTEMIDS) {
int i = 0;
// Make sure the id is not already present
for (; i < m_numCaSystemIds; i++)
if (m_caSystemIds[i] == id)
break;

if (i < m_numCaSystemIds)
continue;

m_caSystemIds[m_numCaSystemIds++] = id;
m_caSystemIds[m_numCaSystemIds] = 0;
}
else
esyslog("ERROR: too many CA system IDs!");
}

// Make sure the id is not already present
if (std::find(m_caSystemIds.cbegin(), m_caSystemIds.cend(), id)
!= m_caSystemIds.end())
continue;

// Insert before the last element.
m_caSystemIds.emplace_back(id);
}

dbgprotocol("\n");
}
m_state = 2;
Expand Down Expand Up @@ -1111,21 +1134,22 @@ bool cCiDateTime::SendDateTime(void)
int L = (M == 1 || M == 2) ? 1 : 0;
int MJD = 14956 + D + int((Y - L) * 365.25) + int((M + 1 + L * 12) * 30.6001);
#define DEC2BCD(d) (uint8_t((((d) / 10) << 4) + ((d) % 10)))
#define BYTE0(a) ((a) & 0xFF)
#define BYTE1(a) (((a) >> 8) & 0xFF)
uint8_t T[7];
#define BYTE0(a) static_cast<uint8_t>((a) & 0xFF)
#define BYTE1(a) static_cast<uint8_t>(((a) >> 8) & 0xFF)
uint16_t mjd = htons(MJD);
int16_t local_offset = htons(tm_loc.tm_gmtoff / 60);
T[0] = BYTE0(mjd);
T[1] = BYTE1(mjd);
T[2] = DEC2BCD(tm_gmt.tm_hour);
T[3] = DEC2BCD(tm_gmt.tm_min);
T[4] = DEC2BCD(tm_gmt.tm_sec);
T[5] = BYTE0(local_offset);
T[6] = BYTE1(local_offset);
std::vector<uint8_t> T {
BYTE0(mjd),
BYTE1(mjd),
DEC2BCD(tm_gmt.tm_hour),
DEC2BCD(tm_gmt.tm_min),
DEC2BCD(tm_gmt.tm_sec),
BYTE0(local_offset),
BYTE1(local_offset)
};

dbgprotocol("%d: ==> Date Time\n", SessionId());
SendData(AOT_DATE_TIME, 7, T);
SendData(AOT_DATE_TIME, T);
//XXX return value of all SendData() calls???
return true;
}
Expand Down Expand Up @@ -1368,10 +1392,14 @@ bool cCiMMI::SendMenuAnswer(uint8_t Selection)
return true;
}

// Define protocol structure
extern "C" {
struct tAnswer { uint8_t m_id; char m_text[256]; };
}

bool cCiMMI::SendAnswer(const char *Text)
{
dbgprotocol("%d: ==> Answ\n", SessionId());
struct tAnswer { uint8_t m_id; char m_text[256]; };//XXX
tAnswer answer {};
answer.m_id = Text ? AI_ANSWER : AI_CANCEL;
if (Text) {
Expand Down Expand Up @@ -1587,20 +1615,19 @@ int cLlCiHandler::ResourceIdToInt(const uint8_t *Data)

bool cLlCiHandler::Send(uint8_t Tag, int SessionId, int ResourceId, int Status)
{
uint8_t buffer[16];
uint8_t *p = buffer;
*p++ = Tag;
*p++ = 0x00; // will contain length
std::vector<uint8_t> buffer {Tag, 0x00} ; // 0x00 will be replaced with length
if (Status >= 0)
*p++ = Status;
buffer.push_back(Status);
if (ResourceId) {
*(int *)p = htonl(ResourceId);
p += 4;
buffer.push_back((ResourceId >> 24) & 0xFF);
buffer.push_back((ResourceId >> 16) & 0xFF);
buffer.push_back((ResourceId >> 8) & 0xFF);
buffer.push_back( ResourceId & 0xFF);
}
*(short *)p = htons(SessionId);
p += 2;
buffer[1] = p - buffer - 2; // length
return m_tc && m_tc->SendData(p - buffer, buffer) == OK;
buffer.push_back((SessionId >> 8) & 0xFF);
buffer.push_back( SessionId & 0xFF);
buffer[1] = buffer.size() - 2; // length
return m_tc && m_tc->SendData(buffer) == OK;
}

cCiSession *cLlCiHandler::GetSessionBySessionId(int SessionId)
Expand Down Expand Up @@ -1816,11 +1843,12 @@ cCiEnquiry *cLlCiHandler::GetEnquiry(void)
return nullptr;
}

const unsigned short *cLlCiHandler::GetCaSystemIds(int Slot)
dvbca_vector cLlCiHandler::GetCaSystemIds(int Slot)
{
static dvbca_vector empty {};
cMutexLock MutexLock(&m_mutex);
auto *cas = dynamic_cast<cCiConditionalAccessSupport *>(GetSessionByResourceId(RI_CONDITIONAL_ACCESS_SUPPORT, Slot));
return cas ? cas->GetCaSystemIds() : nullptr;
return cas ? cas->GetCaSystemIds() : empty;
}

bool cLlCiHandler::SetCaPmt(cCiCaPmt &CaPmt, int Slot)
Expand Down Expand Up @@ -1923,12 +1951,9 @@ bool cHlCiHandler::Process(void)
dbgprotocol(" %04X", id);
d += 2;
l -= 2;
if (m_numCaSystemIds < MAXCASYSTEMIDS) {
m_caSystemIds[m_numCaSystemIds++] = id;
m_caSystemIds[m_numCaSystemIds] = 0;
}
else
esyslog("ERROR: too many CA system IDs!");

// Insert before the last element.
m_caSystemIds.emplace_back(id);
}
dbgprotocol("\n");
}
Expand Down Expand Up @@ -1957,7 +1982,7 @@ cCiEnquiry *cHlCiHandler::GetEnquiry(void)
return nullptr;
}

const unsigned short *cHlCiHandler::GetCaSystemIds(int /*Slot*/)
dvbca_vector cHlCiHandler::GetCaSystemIds(int /*Slot*/)
{
return m_caSystemIds;
}
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/recorders/dvbdev/dvbci.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#endif

#include <cstdio>
#include <vector>

#include <pthread.h>
#include <sys/types.h>
Expand All @@ -41,7 +42,7 @@
#include <sys/stat.h>
#include <sys/uio.h>

#define MAXCASYSTEMIDS 64
using dvbca_vector = std::vector<uint16_t>;

class cMutex {
friend class cCondVar;
Expand Down Expand Up @@ -151,7 +152,7 @@ class cCiHandler {
virtual bool EnterMenu(int Slot) = 0;
virtual cCiMenu *GetMenu(void) = 0;
virtual cCiEnquiry *GetEnquiry(void) = 0;
virtual const unsigned short *GetCaSystemIds(int Slot) = 0;
virtual dvbca_vector GetCaSystemIds(int Slot) = 0;
virtual bool SetCaPmt(cCiCaPmt &CaPmt, int Slot) = 0;
virtual void SetTimeOffset(double /*offset_in_seconds*/) { }
};
Expand Down Expand Up @@ -192,7 +193,7 @@ class cLlCiHandler : public cCiHandler {
cCiMenu *GetMenu(void) override; // cCiHandler
cCiEnquiry *GetEnquiry(void) override; // cCiHandler
bool SetCaPmt(cCiCaPmt &CaPmt);
const unsigned short *GetCaSystemIds(int Slot) override; // cCiHandler
dvbca_vector GetCaSystemIds(int Slot) override; // cCiHandler
bool SetCaPmt(cCiCaPmt &CaPmt, int Slot) override; // cCiHandler
void SetTimeOffset(double offset_in_seconds) override; // cCiHandler
bool Reset(int Slot);
Expand All @@ -207,7 +208,7 @@ class cHlCiHandler : public cCiHandler {
int m_numSlots;
int m_state {0};
int m_numCaSystemIds {0};
unsigned short m_caSystemIds[MAXCASYSTEMIDS + 1] {0}; // list is zero terminated!
dvbca_vector m_caSystemIds {};
cHlCiHandler(int Fd, int NumSlots);
int CommHL(unsigned tag, unsigned function, struct ca_msg *msg) const;
int GetData(unsigned tag, struct ca_msg *msg);
Expand All @@ -223,7 +224,7 @@ class cHlCiHandler : public cCiHandler {
cCiMenu *GetMenu(void) override; // cCiHandler
cCiEnquiry *GetEnquiry(void) override; // cCiHandler
bool SetCaPmt(cCiCaPmt &CaPmt);
const unsigned short *GetCaSystemIds(int Slot) override; // cCiHandler
dvbca_vector GetCaSystemIds(int Slot) override; // cCiHandler
bool SetCaPmt(cCiCaPmt &CaPmt, int Slot) override; // cCiHandler
bool Reset(int Slot) const;
bool connected() const;
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/recorders/firewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ bool FirewireDevice::SetChannel(const QString &panel_model,
return false;
}

int digit[3];
digit[0] = (channel % 1000) / 100;
digit[1] = (channel % 100) / 10;
digit[2] = (channel % 10);
std::array<uint,3> digit {
(channel % 1000) / 100,
(channel % 100) / 10,
(channel % 10)
};

if (m_subunitid >= kAVCSubunitIdExtended)
{
Expand Down Expand Up @@ -233,7 +234,7 @@ bool FirewireDevice::SetChannel(const QString &panel_model,

if (is_mot && !alt_method)
{
for (int d : digit)
for (uint d : digit)
{
cmd.clear();
cmd.push_back(kAVCControlCommand);
Expand Down
2 changes: 0 additions & 2 deletions mythtv/libs/libmythtv/recorders/firewiredevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class FirewireDevice
virtual bool SendAVCCommand(const vector<uint8_t> &cmd,
vector<uint8_t> &result,
int retry_cnt) = 0;
bool GetSubunitInfo(uint8_t table[32]);

void SetLastChannel(uint channel);
void ProcessPATPacket(const TSPacket &tspacket);
virtual void BroadcastToListeners(
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/recorders/iptvstreamhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class IPTVStreamHandler : public StreamHandler

protected:
IPTVTuningData m_tuning;
QUdpSocket *m_sockets[IPTV_SOCKET_COUNT] {};
IPTVStreamHandlerReadHelper *m_readHelpers[IPTV_SOCKET_COUNT] {};
QHostAddress m_sender[IPTV_SOCKET_COUNT];
std::array<QUdpSocket*,IPTV_SOCKET_COUNT> m_sockets {};
std::array<IPTVStreamHandlerReadHelper*,IPTV_SOCKET_COUNT> m_readHelpers {};
std::array<QHostAddress,IPTV_SOCKET_COUNT> m_sender;
IPTVStreamHandlerWriteHelper *m_writeHelper {nullptr};
PacketBuffer *m_buffer {nullptr};

Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/linuxavcinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ bool LinuxAVCInfo::Update(uint64_t _guid, raw1394handle_t handle,
m_firmware_revision = dir.unit_sw_version;
m_product_name = QString("%1").arg(dir.label);

if (avc1394_subunit_info(handle, m_node, (uint32_t*)m_unit_table) < 0)
memset(m_unit_table, 0xff, sizeof(m_unit_table));
if (avc1394_subunit_info(handle, m_node, (uint32_t*)m_unit_table.data()) < 0)
m_unit_table.fill(0xff);

return true;
}
Expand Down Expand Up @@ -82,14 +82,14 @@ bool LinuxAVCInfo::SendAVCCommand(
if (cmd.size() > 4096)
return false;

uint32_t cmdbuf[1024];
std::array<uint32_t,1024> cmdbuf {};
for (size_t i = 0; i < cmd.size(); i+=4)
cmdbuf[i>>2] = cmd[i]<<24 | cmd[i+1]<<16 | cmd[i+2]<<8 | cmd[i+3];

uint result_length = 0;

uint32_t *ret = avc1394_transaction_block2(
m_fwHandle, m_node, cmdbuf, cmd.size() >> 2,
m_fwHandle, m_node, cmdbuf.data(), cmd.size() >> 2,
&result_length, retry_cnt);

if (!ret)
Expand Down
10 changes: 6 additions & 4 deletions mythtv/libs/libmythtv/recorders/linuxfirewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,9 @@ bool LinuxFirewireDevice::UpdateDeviceList(void)
return false;
}

struct raw1394_portinfo port_info[16];
int numcards = raw1394_get_port_info(item.m_handle, port_info, 16);
std::array<raw1394_portinfo,16> port_info {};
int numcards = raw1394_get_port_info(item.m_handle, port_info.data(),
port_info.size());
if (numcards < 1)
{
raw1394_destroy_handle(item.m_handle);
Expand Down Expand Up @@ -896,7 +897,8 @@ bool LinuxFirewireDevice::UpdateDeviceList(void)
break;
}

numcards = raw1394_get_port_info(item.m_handle, port_info, 16);
numcards = raw1394_get_port_info(item.m_handle, port_info.data(),
port_info.size());
}

if (item.m_handle)
Expand Down Expand Up @@ -998,7 +1000,7 @@ static QString speed_to_string(uint speed)
if (speed > 3)
return QString("Invalid Speed (%1)").arg(speed);

static constexpr uint kSpeeds[] = { 100, 200, 400, 800 };
static constexpr std::array<const uint,4> kSpeeds { 100, 200, 400, 800 };
return QString("%1Mbps").arg(kSpeeds[speed]);
}

Expand Down
23 changes: 13 additions & 10 deletions mythtv/libs/libmythtv/recorders/vbitext/cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <array>
#include <cstdlib>
#include <cstdarg>
#include <unistd.h>
Expand Down Expand Up @@ -68,14 +69,15 @@ static bool decodebit(const unsigned char *data, int threshold, int scale1)

static int decode(unsigned char *vbiline, int scale0, int scale1)
{
int max[7];
int min[7];
int val[7];
std::array<int,7> max {};
std::array<int,7> min {};
std::array<int,7> val {};
int sample = 0;
int packedbits = 0;

for (int clk = 0; clk < 7; clk++)
max[clk] = min[clk] = val[clk] = -1;
max.fill(-1);
min.fill(-1);
val.fill(-1);
int clk = 0;
int tmp = 0;
int i = 30;
Expand Down Expand Up @@ -124,7 +126,6 @@ static int webtv_check(char *buf, int len)
unsigned long sum;
unsigned long nwords;
unsigned short csum = 0;
char temp[9];
int nbytes = 0;

while (buf[0] != '<' && len > 6) //search for the start
Expand Down Expand Up @@ -166,9 +167,11 @@ static int webtv_check(char *buf, int len)
sum = csum + (sum & 0xffff);
csum = (unsigned short) (sum >> 16);
}
sprintf(temp, "%04X\n", (int) ~sum & 0xffff);

std::array<char,9> temp {};
sprintf(temp.data(), "%04X\n", (int) ~sum & 0xffff);
buf++;
if (!strncmp(buf, temp, 4))
if (!strncmp(buf, temp.data(), 4))
{
buf[5] = 0;
printf("\33[35mWEBTV: %s\33[0m\n", buf - nbytes - 1);
Expand All @@ -187,14 +190,14 @@ struct cc *cc_open(const char *vbi_name)
if (!(cc = new struct cc))
{
printf("out of memory\n");
return 0;
return nullptr;
}

if ((cc->fd = open(vbi_name, O_RDONLY)) == -1)
{
printf("cannot open vbi device\n");
free(cc);
return 0;
return nullptr;
}

cc->code1 = -1;
Expand Down
30 changes: 16 additions & 14 deletions mythtv/libs/libmythtv/recorders/vbitext/lang.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <array>
#include <cstring>
#include "vt.h"
#include "lang.h"

int latin1 = -1;

static unsigned char lang_char[256];
static std::array<uint8_t,256> lang_char;

/* Yankable latin charset :-)
!"#$%&'()*+,-./0123456789:;<=>?
Expand All @@ -17,8 +18,9 @@ static unsigned char lang_char[256];



static struct mark { const char *m_g0, *m_latin1, *m_latin2; } marks[16] =
{
struct mark { const std::string m_g0, m_latin1, m_latin2; };
static const std::array<const mark,16> marks =
{{
/* none */ { "#",
"\xA4", /* ¤ */
"$" },
Expand Down Expand Up @@ -67,9 +69,9 @@ static struct mark { const char *m_g0, *m_latin1, *m_latin2; } marks[16] =
/* caron - v */ { "cdelnrstzCDELNRSTZ",
"cdelnrstzCDELNRSTZ",
"\xE8\xEF\xEC\xB5\xF2\xF8\xB9\xBB\xBE\xC8\xCF̥\xD2ة\xAB\xAE" /* èïìµòø¹»¾ÈÏÌ¥ÒØ©«® */ },
};
}};

static unsigned char g2map_latin1[] =
static const std::string g2map_latin1 =
/*0123456789abcdef*/
"\x20\xA1\xA2\xA3\x24\xA5\x23\xA7\xA4\x27\x22\xAB\x20\x20\x20\x20" /* ¡¢£$¥#§¤'\"« */
"\xB0\xB1\xB2\xB3\xD7\xB5\xB6\xB7\xF7\x27\x22\xBB\xBC\xBD\xBE\xBF" /* °±²³×µ¶·÷'\"»¼½¾¿ */
Expand All @@ -78,7 +80,7 @@ static unsigned char g2map_latin1[] =
"\x20\xC6\xD0\xAA\x48\x20\x49\x4C\x4C\xD8\x20\xBA\xDE\x54\x4E\x6E" /* ÆÐªH ILLØ ºÞTNn */
"\x4B\xE6\x64\xF0\x68\x69\x69\x6C\x6C\xF8\x20\xDF\xFE\x74\x6E\x7f"; /* Kædðhiillø ßþtn\x7f" */

static unsigned char g2map_latin2[] =
static const std::string g2map_latin2 =
/*0123456789abcdef*/
"\x20\x69\x63\x4C\x24\x59\x23\xA7\xA4\x27\x22\x3C\x20\x20\x20\x20" /* icL$Y#§¤'\"< */
"\xB0\x20\x20\x20\xD7\x75\x20\x20\xF7\x27\x22\x3E\x20\x20\x20\x20" /* ° ×u ÷'\"> */
Expand All @@ -94,7 +96,7 @@ lang_init(void)
{
int i = 0;

memset(lang_char, 0, sizeof(lang_char));
lang_char.fill(0);
for (i = 1; i <= 13; i++)
lang_char[(unsigned char)(lang_chars[0][i])] = i;
}
Expand Down Expand Up @@ -128,11 +130,11 @@ init_enhance(struct enhance *eh)
}

void
add_enhance(struct enhance *eh, int dcode, unsigned int *data)
add_enhance(struct enhance *eh, int dcode, std::array<unsigned int,13>& data)
{
if (dcode == eh->next_des)
{
memcpy(eh->trip + dcode * 13, data, 13 * sizeof(*data));
memcpy(eh->trip + dcode * 13, data.cbegin(), data.size() * sizeof(unsigned int));
eh->next_des++;
}
else
Expand Down Expand Up @@ -173,14 +175,14 @@ do_enhancements(struct enhance *eh, struct vt_page *vtp)
case 16 ... 31: // char from G0 set with diacritical mark
if (adr < VT_WIDTH && row < VT_HEIGHT)
{
struct mark *mark = marks + (mode - 16);
const char *x = std::strchr(mark->m_g0, data);
if (x != nullptr)
const struct mark *mark = &marks[mode - 16];
size_t index = mark->m_g0.find(data);
if (index != std::string::npos)
{
if (latin1)
data = mark->m_latin1[x - mark->m_g0];
data = mark->m_latin1[index];
else
data = mark->m_latin2[x - mark->m_g0];
data = mark->m_latin2[index];
}
vtp->data[row][adr] = data;
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/vbitext/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void lang_init(void);
void conv2latin(unsigned char *p, int n, int lang);

void init_enhance(struct enhance *eh);
void add_enhance(struct enhance *eh, int dcode, unsigned int *data);
void add_enhance(struct enhance *eh, int dcode, std::array<unsigned int,13>& data);
void do_enhancements(struct enhance *eh, struct vt_page *vtp);

#endif // LANG_H
Expand Down
32 changes: 16 additions & 16 deletions mythtv/libs/libmythtv/recorders/vbitext/vbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ out_of_sync(struct vbi *vbi)
static void
vbi_send(struct vbi *vbi, int type, int i1, int i2, int i3, void *p1)
{
struct vt_event ev[1];
struct vt_event ev {};
struct vbi_client *cl = nullptr;
struct vbi_client *cln = nullptr;

ev->resource = vbi;
ev->type = type;
ev->i1 = i1;
ev->i2 = i2;
ev->i3 = i3;
ev->p1 = p1;
ev.resource = vbi;
ev.type = type;
ev.i1 = i1;
ev.i2 = i2;
ev.i3 = i3;
ev.p1 = p1;

for (cl = static_cast<vbi_client *>((void*)vbi->clients[0].first);
(cln = static_cast<vbi_client *>((void*)cl->node->next)) != nullptr;
cl = cln)
cl->handler(cl->data, ev);
cl->handler(cl->data, &ev);
}

static void
Expand Down Expand Up @@ -265,14 +265,14 @@ vt_line(struct vbi *vbi, unsigned char *p)
if (err & 0xf000)
return 4;

int t[13];
std::array<unsigned int,13> t {};
for (int i = 0; i < 13; ++i)
t[i] = hamm24(p + 1 + 3*i, &err);
if (err & 0xf000)
return 4;

//printf("enhance on %x/%x\n", cvtp->pgno, cvtp->subno);
add_enhance(rvtp->enh, d, (unsigned int *)t);
add_enhance(rvtp->enh, d, t);
return 0;
}
case 27:
Expand Down Expand Up @@ -336,10 +336,10 @@ vt_line(struct vbi *vbi, unsigned char *p)
static int
vbi_line(struct vbi *vbi, const unsigned char *p)
{
unsigned char data[43];
int dt[256];
int hi[6];
int lo[6];
std::array<unsigned char,43> data {};
std::array<int,2566> dt {};
std::array<int,6> hi {};
std::array<int,6> lo {};
int i = 0;
int n = 0;
int bpb = vbi->bpb;
Expand Down Expand Up @@ -389,7 +389,7 @@ vbi_line(struct vbi *vbi, const unsigned char *p)
if (p[i/FAC] > thr && p[(i+bpb)/FAC] > thr) // two ones is enough...
{
/* got it... */
memset(data, 0, sizeof(data));
data.fill(0);

for (n = 0; n < 43*8; ++n, i += bpb)
if (p[i/FAC] > thr)
Expand All @@ -398,7 +398,7 @@ vbi_line(struct vbi *vbi, const unsigned char *p)
if (data[0] != 0x27) // really 11100100? (rev order!)
return -1;

if ((i = vt_line(vbi, data+1)))
if ((i = vt_line(vbi, data.data()+1)))
{
if (i < 0)
pll_add(vbi, 2, -i);
Expand Down