1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

qrtplib: fixed urandom calls

This commit is contained in:
f4exb 2018-03-29 19:55:03 +02:00
parent 75201ad303
commit b244222667
7 changed files with 128 additions and 50 deletions

View File

@ -70,7 +70,7 @@ RTPPacket::RTPPacket(RTPRawPacket &rawpack) :
RTPPacket::RTPPacket( RTPPacket::RTPPacket(
uint8_t payloadtype, uint8_t payloadtype,
const void *payloaddata, const void *payloaddata,
std::size_t payloadlen, unsigned int payloadlen,
uint16_t seqnr, uint16_t seqnr,
uint32_t timestamp, uint32_t timestamp,
uint32_t ssrc, uint32_t ssrc,
@ -81,7 +81,7 @@ RTPPacket::RTPPacket(
uint16_t extensionid, uint16_t extensionid,
uint16_t extensionlen_numwords, uint16_t extensionlen_numwords,
const void *extensiondata, const void *extensiondata,
std::size_t maxpacksize) : unsigned int maxpacksize) :
receivetime(0, 0) receivetime(0, 0)
{ {
Clear(); Clear();
@ -106,7 +106,7 @@ RTPPacket::RTPPacket(
RTPPacket::RTPPacket( RTPPacket::RTPPacket(
uint8_t payloadtype, uint8_t payloadtype,
const void *payloaddata, const void *payloaddata,
std::size_t payloadlen, unsigned int payloadlen,
uint16_t seqnr, uint16_t seqnr,
uint32_t timestamp, uint32_t timestamp,
uint32_t ssrc, uint32_t ssrc,
@ -118,7 +118,7 @@ RTPPacket::RTPPacket(
uint16_t extensionlen_numwords, uint16_t extensionlen_numwords,
const void *extensiondata, const void *extensiondata,
void *buffer, void *buffer,
std::size_t buffersize) : unsigned int buffersize) :
receivetime(0, 0) receivetime(0, 0)
{ {
Clear(); Clear();
@ -148,7 +148,7 @@ RTPPacket::RTPPacket(
int RTPPacket::ParseRawPacket(RTPRawPacket &rawpack) int RTPPacket::ParseRawPacket(RTPRawPacket &rawpack)
{ {
uint8_t *packetbytes; uint8_t *packetbytes;
std::size_t packetlen; unsigned int packetlen;
uint8_t payloadtype; uint8_t payloadtype;
RTPHeader *rtpheader; RTPHeader *rtpheader;
bool marker; bool marker;
@ -264,7 +264,7 @@ uint32_t RTPPacket::GetCSRC(int num) const
int RTPPacket::BuildPacket( int RTPPacket::BuildPacket(
uint8_t payloadtype, uint8_t payloadtype,
const void *payloaddata, const void *payloaddata,
std::size_t payloadlen, unsigned int payloadlen,
uint16_t seqnr, uint16_t seqnr,
uint32_t timestamp, uint32_t timestamp,
uint32_t ssrc, uint32_t ssrc,
@ -276,7 +276,7 @@ int RTPPacket::BuildPacket(
uint16_t extensionlen_numwords, uint16_t extensionlen_numwords,
const void *extensiondata, const void *extensiondata,
void *buffer, void *buffer,
std::size_t maxsize) unsigned int maxsize)
{ {
if (numcsrcs > RTP_MAXCSRCS) if (numcsrcs > RTP_MAXCSRCS)
return ERR_RTP_PACKET_TOOMANYCSRCS; return ERR_RTP_PACKET_TOOMANYCSRCS;
@ -287,11 +287,11 @@ int RTPPacket::BuildPacket(
return ERR_RTP_PACKET_BADPAYLOADTYPE; return ERR_RTP_PACKET_BADPAYLOADTYPE;
packetlength = sizeof(RTPHeader); packetlength = sizeof(RTPHeader);
packetlength += sizeof(uint32_t) * ((std::size_t) numcsrcs); packetlength += sizeof(uint32_t) * ((unsigned int) numcsrcs);
if (gotextension) if (gotextension)
{ {
packetlength += sizeof(RTPExtensionHeader); packetlength += sizeof(RTPExtensionHeader);
packetlength += sizeof(uint32_t) * ((std::size_t) extensionlen_numwords); packetlength += sizeof(uint32_t) * ((unsigned int) extensionlen_numwords);
} }
packetlength += payloadlen; packetlength += payloadlen;
@ -330,7 +330,7 @@ int RTPPacket::BuildPacket(
RTPPacket::ssrc = ssrc; RTPPacket::ssrc = ssrc;
RTPPacket::payloadlength = payloadlen; RTPPacket::payloadlength = payloadlen;
RTPPacket::extid = extensionid; RTPPacket::extid = extensionid;
RTPPacket::extensionlength = ((std::size_t) extensionlen_numwords) * sizeof(uint32_t); RTPPacket::extensionlength = ((unsigned int) extensionlen_numwords) * sizeof(uint32_t);
rtphdr = (RTPHeader *) packet; rtphdr = (RTPHeader *) packet;
rtphdr->version = RTP_VERSION; rtphdr->version = RTP_VERSION;
@ -356,7 +356,7 @@ int RTPPacket::BuildPacket(
for (i = 0; i < numcsrcs; i++, curcsrc++) for (i = 0; i < numcsrcs; i++, curcsrc++)
*curcsrc = qToBigEndian(csrcs[i]); *curcsrc = qToBigEndian(csrcs[i]);
payload = packet + sizeof(RTPHeader) + ((std::size_t) numcsrcs) * sizeof(uint32_t); payload = packet + sizeof(RTPHeader) + ((unsigned int) numcsrcs) * sizeof(uint32_t);
if (gotextension) if (gotextension)
{ {
RTPExtensionHeader *rtpexthdr = (RTPExtensionHeader *) payload; RTPExtensionHeader *rtpexthdr = (RTPExtensionHeader *) payload;

View File

@ -68,13 +68,38 @@ public:
* \c maxpacksize. The arguments of the constructor are self-explanatory. Note that the size of a header * \c maxpacksize. The arguments of the constructor are self-explanatory. Note that the size of a header
* extension is specified in a number of 32-bit words. A memory manager can be installed. * extension is specified in a number of 32-bit words. A memory manager can be installed.
*/ */
RTPPacket(uint8_t payloadtype, const void *payloaddata, std::size_t payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, RTPPacket(uint8_t payloadtype,
const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, std::size_t maxpacksize); const void *payloaddata,
unsigned int payloadlen,
uint16_t seqnr,
uint32_t timestamp,
uint32_t ssrc,
bool gotmarker,
uint8_t numcsrcs,
const uint32_t *csrcs,
bool gotextension,
uint16_t extensionid,
uint16_t extensionlen_numwords,
const void *extensiondata,
unsigned int maxpacksize);
/** This constructor is similar to the other constructor, but here data is stored in an external buffer /** This constructor is similar to the other constructor, but here data is stored in an external buffer
* \c buffer with size \c buffersize. */ * \c buffer with size \c buffersize. */
RTPPacket(uint8_t payloadtype, const void *payloaddata, std::size_t payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, RTPPacket(uint8_t payloadtype,
const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, std::size_t buffersize); const void *payloaddata,
unsigned int payloadlen,
uint16_t seqnr,
uint32_t timestamp,
uint32_t ssrc,
bool gotmarker,
uint8_t numcsrcs,
const uint32_t *csrcs,
bool gotextension,
uint16_t extensionid,
uint16_t extensionlen_numwords,
const void *extensiondata,
void *buffer,
unsigned int buffersize);
virtual ~RTPPacket() virtual ~RTPPacket()
{ {
@ -163,13 +188,13 @@ public:
} }
/** Returns the length of the entire packet. */ /** Returns the length of the entire packet. */
std::size_t GetPacketLength() const unsigned int GetPacketLength() const
{ {
return packetlength; return packetlength;
} }
/** Returns the payload length. */ /** Returns the payload length. */
std::size_t GetPayloadLength() const unsigned int GetPayloadLength() const
{ {
return payloadlength; return payloadlength;
} }
@ -187,7 +212,7 @@ public:
} }
/** Returns the length of the header extension data. */ /** Returns the length of the header extension data. */
std::size_t GetExtensionLength() const unsigned int GetExtensionLength() const
{ {
return extensionlength; return extensionlength;
} }
@ -204,8 +229,8 @@ public:
private: private:
void Clear(); void Clear();
int ParseRawPacket(RTPRawPacket &rawpack); int ParseRawPacket(RTPRawPacket &rawpack);
int BuildPacket(uint8_t payloadtype, const void *payloaddata, std::size_t payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs, int BuildPacket(uint8_t payloadtype, const void *payloaddata, unsigned int payloadlen, uint16_t seqnr, uint32_t timestamp, uint32_t ssrc, bool gotmarker, uint8_t numcsrcs,
const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, std::size_t maxsize); const uint32_t *csrcs, bool gotextension, uint16_t extensionid, uint16_t extensionlen_numwords, const void *extensiondata, void *buffer, unsigned int maxsize);
RTPEndian m_endian; RTPEndian m_endian;
int error; int error;
@ -216,11 +241,11 @@ private:
uint8_t payloadtype; uint8_t payloadtype;
uint32_t extseqnr, timestamp, ssrc; uint32_t extseqnr, timestamp, ssrc;
uint8_t *packet, *payload; uint8_t *packet, *payload;
std::size_t packetlength, payloadlength; unsigned int packetlength, payloadlength;
uint16_t extid; uint16_t extid;
uint8_t *extension; uint8_t *extension;
std::size_t extensionlength; unsigned int extensionlength;
bool externalbuffer; bool externalbuffer;

View File

@ -41,9 +41,27 @@ namespace qrtplib
{ {
RTPPacketBuilder::RTPPacketBuilder(RTPRandom &r) : RTPPacketBuilder::RTPPacketBuilder(RTPRandom &r) :
rtprnd(r), lastwallclocktime(0, 0) rtprnd(r),
maxpacksize(0),
buffer(0),
packetlength(0),
lastwallclocktime(0, 0)
{ {
init = false; init = false;
deftsset = false;
defptset = false;
defmarkset = false;
defaultmark = false;
defaulttimestampinc = 0;
ssrc = 0;
timestamp = 0;
seqnr = 0;
prevrtptimestamp = 0;
lastrtptimestamp = 0;
defaultpayloadtype = 0;
numcsrcs = 0;
numpayloadbytes = 0;
numpackets = 0;
timeinit.Dummy(); timeinit.Dummy();
//std::cout << (void *)(&rtprnd) << std::endl; //std::cout << (void *)(&rtprnd) << std::endl;
@ -54,7 +72,7 @@ RTPPacketBuilder::~RTPPacketBuilder()
Destroy(); Destroy();
} }
int RTPPacketBuilder::Init(std::size_t max) int RTPPacketBuilder::Init(unsigned int max)
{ {
if (init) if (init)
return ERR_RTP_PACKBUILD_ALREADYINIT; return ERR_RTP_PACKBUILD_ALREADYINIT;
@ -66,6 +84,7 @@ int RTPPacketBuilder::Init(std::size_t max)
if (buffer == 0) if (buffer == 0)
return ERR_RTP_OUTOFMEM; return ERR_RTP_OUTOFMEM;
packetlength = 0; packetlength = 0;
numpackets = 0;
CreateNewSSRC(); CreateNewSSRC();
@ -87,7 +106,7 @@ void RTPPacketBuilder::Destroy()
init = false; init = false;
} }
int RTPPacketBuilder::SetMaximumPacketSize(std::size_t max) int RTPPacketBuilder::SetMaximumPacketSize(unsigned int max)
{ {
uint8_t *newbuf; uint8_t *newbuf;
@ -161,6 +180,8 @@ uint32_t RTPPacketBuilder::CreateNewSSRC()
timestamp = rtprnd.GetRandom32(); timestamp = rtprnd.GetRandom32();
seqnr = rtprnd.GetRandom16(); seqnr = rtprnd.GetRandom16();
qDebug("RTPPacketBuilder::CreateNewSSRC: timestamp: %u", timestamp);
// p 38: the count SHOULD be reset if the sender changes its SSRC identifier // p 38: the count SHOULD be reset if the sender changes its SSRC identifier
numpayloadbytes = 0; numpayloadbytes = 0;
numpackets = 0; numpackets = 0;
@ -186,7 +207,7 @@ uint32_t RTPPacketBuilder::CreateNewSSRC(RTPSources &sources)
return ssrc; return ssrc;
} }
int RTPPacketBuilder::BuildPacket(const void *data, std::size_t len) int RTPPacketBuilder::BuildPacket(const void *data, unsigned int len)
{ {
if (!init) if (!init)
return ERR_RTP_PACKBUILD_NOTINIT; return ERR_RTP_PACKBUILD_NOTINIT;
@ -199,14 +220,14 @@ int RTPPacketBuilder::BuildPacket(const void *data, std::size_t len)
return PrivateBuildPacket(data, len, defaultpayloadtype, defaultmark, defaulttimestampinc, false); return PrivateBuildPacket(data, len, defaultpayloadtype, defaultmark, defaulttimestampinc, false);
} }
int RTPPacketBuilder::BuildPacket(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc) int RTPPacketBuilder::BuildPacket(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc)
{ {
if (!init) if (!init)
return ERR_RTP_PACKBUILD_NOTINIT; return ERR_RTP_PACKBUILD_NOTINIT;
return PrivateBuildPacket(data, len, pt, mark, timestampinc, false); return PrivateBuildPacket(data, len, pt, mark, timestampinc, false);
} }
int RTPPacketBuilder::BuildPacketEx(const void *data, std::size_t len, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords) int RTPPacketBuilder::BuildPacketEx(const void *data, unsigned int len, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords)
{ {
if (!init) if (!init)
return ERR_RTP_PACKBUILD_NOTINIT; return ERR_RTP_PACKBUILD_NOTINIT;
@ -219,7 +240,7 @@ int RTPPacketBuilder::BuildPacketEx(const void *data, std::size_t len, uint16_t
return PrivateBuildPacket(data, len, defaultpayloadtype, defaultmark, defaulttimestampinc, true, hdrextID, hdrextdata, numhdrextwords); return PrivateBuildPacket(data, len, defaultpayloadtype, defaultmark, defaulttimestampinc, true, hdrextID, hdrextdata, numhdrextwords);
} }
int RTPPacketBuilder::BuildPacketEx(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords) int RTPPacketBuilder::BuildPacketEx(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords)
{ {
if (!init) if (!init)
return ERR_RTP_PACKBUILD_NOTINIT; return ERR_RTP_PACKBUILD_NOTINIT;
@ -227,8 +248,8 @@ int RTPPacketBuilder::BuildPacketEx(const void *data, std::size_t len, uint8_t p
} }
int RTPPacketBuilder::PrivateBuildPacket(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc, bool gotextension, uint16_t hdrextID, const void *hdrextdata, int RTPPacketBuilder::PrivateBuildPacket(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc, bool gotextension, uint16_t hdrextID, const void *hdrextdata,
std::size_t numhdrextwords) unsigned int numhdrextwords)
{ {
RTPPacket p(pt, data, len, seqnr, timestamp, ssrc, mark, numcsrcs, csrcs, gotextension, hdrextID, (uint16_t) numhdrextwords, hdrextdata, buffer, maxpacksize); RTPPacket p(pt, data, len, seqnr, timestamp, ssrc, mark, numcsrcs, csrcs, gotextension, hdrextID, (uint16_t) numhdrextwords, hdrextdata, buffer, maxpacksize);
int status = p.GetCreationError(); int status = p.GetCreationError();
@ -255,6 +276,8 @@ int RTPPacketBuilder::PrivateBuildPacket(const void *data, std::size_t len, uint
timestamp += timestampinc; timestamp += timestampinc;
seqnr++; seqnr++;
//qDebug("RTPPacketBuilder::PrivateBuildPacket: numpackets: %u timestamp: %u timestampinc: %u seqnr: %u", numpackets, timestamp, timestampinc, seqnr);
return 0; return 0;
} }

View File

@ -65,7 +65,7 @@ public:
~RTPPacketBuilder(); ~RTPPacketBuilder();
/** Initializes the builder to only allow packets with a size below \c maxpacksize. */ /** Initializes the builder to only allow packets with a size below \c maxpacksize. */
int Init(std::size_t maxpacksize); int Init(unsigned int maxpacksize);
/** Cleans up the builder. */ /** Cleans up the builder. */
void Destroy(); void Destroy();
@ -87,7 +87,7 @@ public:
} }
/** Sets the maximum allowed packet size to \c maxpacksize. */ /** Sets the maximum allowed packet size to \c maxpacksize. */
int SetMaximumPacketSize(std::size_t maxpacksize); int SetMaximumPacketSize(unsigned int maxpacksize);
/** Adds a CSRC to the CSRC list which will be stored in the RTP packets. */ /** Adds a CSRC to the CSRC list which will be stored in the RTP packets. */
int AddCSRC(uint32_t csrc); int AddCSRC(uint32_t csrc);
@ -103,14 +103,14 @@ public:
* and timestamp increment used will be those that have been set using the \c SetDefault * and timestamp increment used will be those that have been set using the \c SetDefault
* functions below. * functions below.
*/ */
int BuildPacket(const void *data, std::size_t len); int BuildPacket(const void *data, unsigned int len);
/** Builds a packet with payload \c data and payload length \c len. /** Builds a packet with payload \c data and payload length \c len.
* Builds a packet with payload \c data and payload length \c len. The payload type will be * Builds a packet with payload \c data and payload length \c len. The payload type will be
* set to \c pt, the marker bit to \c mark and after building this packet, the timestamp will * set to \c pt, the marker bit to \c mark and after building this packet, the timestamp will
* be incremented with \c timestamp. * be incremented with \c timestamp.
*/ */
int BuildPacket(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc); int BuildPacket(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc);
/** Builds a packet with payload \c data and payload length \c len. /** Builds a packet with payload \c data and payload length \c len.
* Builds a packet with payload \c data and payload length \c len. The payload type, marker * Builds a packet with payload \c data and payload length \c len. The payload type, marker
@ -119,7 +119,7 @@ public:
* \c hdrextID and data \c hdrextdata. The length of the header extension data is given by * \c hdrextID and data \c hdrextdata. The length of the header extension data is given by
* \c numhdrextwords which expresses the length in a number of 32-bit words. * \c numhdrextwords which expresses the length in a number of 32-bit words.
*/ */
int BuildPacketEx(const void *data, std::size_t len, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords); int BuildPacketEx(const void *data, unsigned int len, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords);
/** Builds a packet with payload \c data and payload length \c len. /** Builds a packet with payload \c data and payload length \c len.
* Builds a packet with payload \c data and payload length \c len. The payload type will be set * Builds a packet with payload \c data and payload length \c len. The payload type will be set
@ -128,7 +128,7 @@ public:
* with identifier \c hdrextID and data \c hdrextdata. The length of the header extension * with identifier \c hdrextID and data \c hdrextdata. The length of the header extension
* data is given by \c numhdrextwords which expresses the length in a number of 32-bit words. * data is given by \c numhdrextwords which expresses the length in a number of 32-bit words.
*/ */
int BuildPacketEx(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, std::size_t numhdrextwords); int BuildPacketEx(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords);
/** Returns a pointer to the last built RTP packet data. */ /** Returns a pointer to the last built RTP packet data. */
uint8_t *GetPacket() uint8_t *GetPacket()
@ -139,7 +139,7 @@ public:
} }
/** Returns the size of the last built RTP packet. */ /** Returns the size of the last built RTP packet. */
std::size_t GetPacketLength() unsigned int GetPacketLength()
{ {
if (!init) if (!init)
return 0; return 0;
@ -237,13 +237,19 @@ public:
ssrc = s; ssrc = s;
} }
private: private:
int PrivateBuildPacket(const void *data, std::size_t len, uint8_t pt, bool mark, uint32_t timestampinc, bool gotextension, uint16_t hdrextID = 0, const void *hdrextdata = 0, int PrivateBuildPacket(
std::size_t numhdrextwords = 0); const void *data,
unsigned int len, uint8_t pt,
bool mark,
uint32_t timestampinc,
bool gotextension, uint16_t hdrextID = 0,
const void *hdrextdata = 0,
unsigned int numhdrextwords = 0);
RTPRandom &rtprnd; RTPRandom &rtprnd;
std::size_t maxpacksize; unsigned int maxpacksize;
uint8_t *buffer; uint8_t *buffer;
std::size_t packetlength; unsigned int packetlength;
uint32_t numpayloadbytes; uint32_t numpayloadbytes;
uint32_t numpackets; uint32_t numpackets;

View File

@ -44,7 +44,7 @@
#include "export.h" #include "export.h"
#define RTPRANDOM_2POWMIN63 1.08420217248550443400745280086994171142578125e-19 #define RTPRANDOM_2POWMIN63 1.08420217248550443400745280086994171142578125e-19
namespace qrtplib namespace qrtplib
{ {

View File

@ -31,6 +31,7 @@
*/ */
#include "rtprandomrand48.h" #include "rtprandomrand48.h"
#include <Qt>
namespace qrtplib namespace qrtplib
{ {
@ -72,6 +73,7 @@ uint32_t RTPRandomRand48::GetRandom32()
{ {
state = ((0x5DEECE66DULL * state) + 0xBULL) & 0x0000ffffffffffffULL; state = ((0x5DEECE66DULL * state) + 0xBULL) & 0x0000ffffffffffffULL;
uint32_t x = (uint32_t) ((state >> 16) & 0xffffffffULL); uint32_t x = (uint32_t) ((state >> 16) & 0xffffffffULL);
qDebug("RTPRandomRand48::GetRandom32: %u", x);
return x; return x;
} }

View File

@ -32,6 +32,8 @@
#include "rtprandomurandom.h" #include "rtprandomurandom.h"
#include "rtperrors.h" #include "rtperrors.h"
#include <Qt>
#include <cstdio>
namespace qrtplib namespace qrtplib
{ {
@ -43,18 +45,22 @@ RTPRandomURandom::RTPRandomURandom()
RTPRandomURandom::~RTPRandomURandom() RTPRandomURandom::~RTPRandomURandom()
{ {
if (device) if (device) {
fclose(device); fclose(device);
}
} }
int RTPRandomURandom::Init() int RTPRandomURandom::Init()
{ {
if (device) if (device) {
return ERR_RTP_RTPRANDOMURANDOM_ALREADYOPEN; return ERR_RTP_RTPRANDOMURANDOM_ALREADYOPEN;
}
device = fopen("/dev/urandom", "rb"); device = fopen("/dev/urandom", "rb");
if (device == 0)
if (device == 0) {
return ERR_RTP_RTPRANDOMURANDOM_CANTOPEN; return ERR_RTP_RTPRANDOMURANDOM_CANTOPEN;
}
return 0; return 0;
} }
@ -62,12 +68,16 @@ int RTPRandomURandom::Init()
uint8_t RTPRandomURandom::GetRandom8() uint8_t RTPRandomURandom::GetRandom8()
{ {
if (!device) if (!device)
{
qWarning("RTPRandomURandom::GetRandom8: no device");
return 0; return 0;
}
uint8_t value; uint8_t value;
if (fread(&value, sizeof(uint8_t), 1, device) != sizeof(uint8_t)) if (fread(&value, 1, sizeof(uint8_t), device) != sizeof(uint8_t))
{ {
qWarning("RTPRandomURandom::GetRandom8: cannot read unsigned 8 bit value from device");
return 0; return 0;
} }
@ -77,12 +87,16 @@ uint8_t RTPRandomURandom::GetRandom8()
uint16_t RTPRandomURandom::GetRandom16() uint16_t RTPRandomURandom::GetRandom16()
{ {
if (!device) if (!device)
{
qWarning("RTPRandomURandom::GetRandom16: no device");
return 0; return 0;
}
uint16_t value; uint16_t value;
if (fread(&value, sizeof(uint16_t), 1, device) != sizeof(uint16_t)) if (fread(&value, 1, sizeof(uint16_t), device) != sizeof(uint16_t))
{ {
qWarning("RTPRandomURandom::GetRandom16: cannot read unsigned 16 bit value from device");
return 0; return 0;
} }
@ -92,12 +106,16 @@ uint16_t RTPRandomURandom::GetRandom16()
uint32_t RTPRandomURandom::GetRandom32() uint32_t RTPRandomURandom::GetRandom32()
{ {
if (!device) if (!device)
{
qWarning("RTPRandomURandom::GetRandom32: no device");
return 0; return 0;
}
uint32_t value; uint32_t value;
if (fread(&value, sizeof(uint32_t), 1, device) != sizeof(uint32_t)) if (fread(&value, 1, sizeof(uint32_t), device) != sizeof(uint32_t))
{ {
qWarning("RTPRandomURandom::GetRandom32: cannot read unsigned 32 bit value from device");
return 0; return 0;
} }
@ -107,12 +125,16 @@ uint32_t RTPRandomURandom::GetRandom32()
double RTPRandomURandom::GetRandomDouble() double RTPRandomURandom::GetRandomDouble()
{ {
if (!device) if (!device)
{
qWarning("RTPRandomURandom::GetRandomDouble: no device");
return 0; return 0;
}
uint64_t value; uint64_t value;
if (fread(&value, sizeof(uint64_t), 1, device) != sizeof(uint64_t)) if (fread(&value, 1, sizeof(uint64_t), device) != sizeof(uint64_t))
{ {
qWarning("RTPRandomURandom::GetRandomDouble: cannot read unsigned 64 bit value from device");
return 0; return 0;
} }