Browse files

Merge pull request #45 from FernetMenta/vnsi

Vnsi fixes
  • Loading branch information...
2 parents 6da5d3e + b8760d0 commit e10dedbe69da759fe6884bb73a2ecfd8d9750b69 @FernetMenta FernetMenta committed Sep 28, 2012
View
46 addons/pvr.vdr.vnsi/src/VNSISession.cpp
@@ -158,14 +158,8 @@ bool cVNSISession::Login()
cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int iDatapacketTimeout /*= 10000*/)
{
uint32_t channelID = 0;
- uint32_t requestID;
uint32_t userDataLength = 0;
uint8_t* userData = NULL;
- uint32_t streamID;
- uint32_t duration;
- uint32_t opCodeID;
- int64_t dts = 0;
- int64_t pts = 0;
cResponsePacket* vresp = NULL;
@@ -179,16 +173,17 @@ cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int
channelID = ntohl(channelID);
if (channelID == VNSI_CHANNEL_STREAM)
{
- if (!readData((uint8_t*)&m_streamPacketHeader, sizeof(m_streamPacketHeader), iDatapacketTimeout)) return NULL;
+ vresp = new cResponsePacket();
- opCodeID = ntohl(m_streamPacketHeader.opCodeID);
- streamID = ntohl(m_streamPacketHeader.streamID);
- duration = ntohl(m_streamPacketHeader.duration);
- pts = ntohll(*(int64_t*)m_streamPacketHeader.pts);
- dts = ntohll(*(int64_t*)m_streamPacketHeader.dts);
- userDataLength = ntohl(m_streamPacketHeader.userDataLength);
+ if (!readData(vresp->getHeader(), vresp->getStreamHeaderLength(), iDatapacketTimeout))
+ {
+ delete vresp;
+ return NULL;
+ }
+ vresp->extractStreamHeader();
+ userDataLength = vresp->getUserDataLength();
- if(opCodeID == VNSI_STREAM_MUXPKT)
+ if(vresp->getOpCodeID() == VNSI_STREAM_MUXPKT)
{
DemuxPacket* p = PVR->AllocateDemuxPacket(userDataLength);
userData = (uint8_t*)p;
@@ -198,6 +193,7 @@ cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int
if (!readData(p->pData, userDataLength, iDatapacketTimeout))
{
PVR->FreeDemuxPacket(p);
+ delete vresp;
return NULL;
}
}
@@ -209,19 +205,23 @@ cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int
if (!readData(userData, userDataLength, iDatapacketTimeout))
{
free(userData);
+ delete vresp;
return NULL;
}
}
-
- vresp = new cResponsePacket();
- vresp->setStream(opCodeID, streamID, duration, dts, pts, userData, userDataLength);
+ vresp->setStream(userData, userDataLength);
}
else
{
- if (!readData((uint8_t*)&m_responsePacketHeader, sizeof(m_responsePacketHeader), iDatapacketTimeout)) return NULL;
+ vresp = new cResponsePacket();
- requestID = ntohl(m_responsePacketHeader.requestID);
- userDataLength = ntohl(m_responsePacketHeader.userDataLength);
+ if (!readData(vresp->getHeader(), vresp->getHeaderLength(), iDatapacketTimeout))
+ {
+ delete vresp;
+ return NULL;
+ }
+ vresp->extractHeader();
+ userDataLength = vresp->getUserDataLength();
if (userDataLength > 5000000) return NULL; // how big can these packets get?
userData = NULL;
@@ -232,15 +232,15 @@ cResponsePacket* cVNSISession::ReadMessage(int iInitialTimeout /*= 10000*/, int
if (!readData(userData, userDataLength, iDatapacketTimeout))
{
free(userData);
+ delete vresp;
return NULL;
}
}
- vresp = new cResponsePacket();
if (channelID == VNSI_CHANNEL_STATUS)
- vresp->setStatus(requestID, userData, userDataLength);
+ vresp->setStatus(userData, userDataLength);
else
- vresp->setResponse(requestID, userData, userDataLength);
+ vresp->setResponse(userData, userDataLength);
}
return vresp;
View
15 addons/pvr.vdr.vnsi/src/VNSISession.h
@@ -81,19 +81,4 @@ class cVNSISession
std::string m_server;
std::string m_version;
bool m_connectionLost;
-
- struct {
- uint32_t opCodeID;
- uint32_t streamID;
- uint32_t duration;
- uint8_t pts[sizeof(int64_t)];
- uint8_t dts[sizeof(int64_t)];
- uint32_t userDataLength;
- } m_streamPacketHeader;
-
- struct {
- uint32_t requestID;
- uint32_t userDataLength;
- } m_responsePacketHeader;
-
};
View
52 addons/pvr.vdr.vnsi/src/requestpacket.cpp
@@ -70,10 +70,15 @@ bool cRequestPacket::init(uint32_t topcode, bool stream, bool setUserDataLength,
serialNumber = serialNumberCounter++;
opcode = topcode;
- *(uint32_t*)&buffer[0] = htonl(channel);
- *(uint32_t*)&buffer[4] = htonl(serialNumber);
- *(uint32_t*)&buffer[8] = htonl(opcode);
- *(uint32_t*)&buffer[userDataLenPos] = htonl(userDataLength);
+ uint32_t ul;
+ ul = htonl(channel);
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(serialNumber);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = htonl(opcode);
+ memcpy(&buffer[8], &ul, sizeof(uint32_t));
+ ul = htonl(userDataLength);
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
bufUsed = headerLength;
return true;
@@ -85,7 +90,11 @@ bool cRequestPacket::add_String(const char* string)
if (!checkExtend(len)) return false;
memcpy(buffer + bufUsed, string, len);
bufUsed += len;
- if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ if (!lengthSet)
+ {
+ uint32_t tmp = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t));
+ }
return true;
}
@@ -94,34 +103,53 @@ bool cRequestPacket::add_U8(uint8_t c)
if (!checkExtend(sizeof(uint8_t))) return false;
buffer[bufUsed] = c;
bufUsed += sizeof(uint8_t);
- if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ if (!lengthSet)
+ {
+ uint32_t tmp = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t));
+ }
return true;
}
bool cRequestPacket::add_S32(int32_t l)
{
if (!checkExtend(sizeof(int32_t))) return false;
- *(int32_t*)&buffer[bufUsed] = htonl(l);
+ int32_t tmp = htonl(l);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(int32_t));
bufUsed += sizeof(int32_t);
- if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ if (!lengthSet)
+ {
+ uint32_t tmp = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t));
+ }
return true;
}
bool cRequestPacket::add_U32(uint32_t ul)
{
if (!checkExtend(sizeof(uint32_t))) return false;
- *(uint32_t*)&buffer[bufUsed] = htonl(ul);
+ uint32_t tmp = htonl(ul);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint32_t));
bufUsed += sizeof(uint32_t);
- if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ if (!lengthSet)
+ {
+ uint32_t tmp = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t));
+ }
return true;
}
bool cRequestPacket::add_U64(uint64_t ull)
{
if (!checkExtend(sizeof(uint64_t))) return false;
- *(uint64_t*)&buffer[bufUsed] = htonll(ull);
+ uint64_t tmp = htonll(ull);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint64_t));
bufUsed += sizeof(uint64_t);
- if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ if (!lengthSet)
+ {
+ uint32_t tmp = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &tmp, sizeof(uint32_t));
+ }
return true;
}
View
65 addons/pvr.vdr.vnsi/src/responsepacket.cpp
@@ -53,32 +53,57 @@ cResponsePacket::~cResponsePacket()
}
}
-void cResponsePacket::setResponse(uint32_t trequestID, uint8_t* tuserData, uint32_t tuserDataLength)
+void cResponsePacket::setResponse(uint8_t* tuserData, uint32_t tuserDataLength)
{
channelID = VNSI_CHANNEL_REQUEST_RESPONSE;
- requestID = trequestID;
userData = tuserData;
userDataLength = tuserDataLength;
+ packetPos = 0;
}
-void cResponsePacket::setStatus(uint32_t trequestID, uint8_t* tuserData, uint32_t tuserDataLength)
+void cResponsePacket::setStatus(uint8_t* tuserData, uint32_t tuserDataLength)
{
channelID = VNSI_CHANNEL_STATUS;
- requestID = trequestID;
userData = tuserData;
userDataLength = tuserDataLength;
+ packetPos = 0;
}
-void cResponsePacket::setStream(uint32_t topcodeID, uint32_t tstreamID, uint32_t tduration, int64_t tdts, int64_t tpts, uint8_t* tuserData, uint32_t tuserDataLength)
+void cResponsePacket::setStream(uint8_t* tuserData, uint32_t tuserDataLength)
{
channelID = VNSI_CHANNEL_STREAM;
- opcodeID = topcodeID;
- streamID = tstreamID;
- duration = tduration;
- dts = tdts;
- pts = tpts;
+ // set pointer to user data
userData = tuserData;
userDataLength = tuserDataLength;
+ packetPos = 0;
+}
+
+void cResponsePacket::extractHeader()
+{
+ // set data pointers to header first
+ userData = header;
+ userDataLength = sizeof(header);
+ packetPos = 0;
+
+ requestID = extract_U32();
+ userDataLength = extract_U32();
+}
+
+void cResponsePacket::extractStreamHeader()
+{
+ channelID = VNSI_CHANNEL_STREAM;
+
+ // set data pointers to header first
+ userData = header;
+ userDataLength = sizeof(header);
+ packetPos = 0;
+
+ opcodeID = extract_U32();
+ streamID = extract_U32();
+ duration = extract_U32();
+ pts = extract_U64();
+ dts = extract_U64();
+ userDataLength = extract_U32();
}
bool cResponsePacket::end()
@@ -115,23 +140,29 @@ uint8_t cResponsePacket::extract_U8()
uint32_t cResponsePacket::extract_U32()
{
if ((packetPos + sizeof(uint32_t)) > userDataLength) return 0;
- uint32_t ul = ntohl(*(uint32_t*)&userData[packetPos]);
+ uint32_t ul;
+ memcpy(&ul, &userData[packetPos], sizeof(uint32_t));
+ ul = ntohl(ul);
packetPos += sizeof(uint32_t);
return ul;
}
uint64_t cResponsePacket::extract_U64()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = ntohll(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = ntohll(ull);
packetPos += sizeof(uint64_t);
return ull;
}
double cResponsePacket::extract_Double()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = ntohll(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = ntohll(ull);
double d;
memcpy(&d,&ull,sizeof(double));
packetPos += sizeof(uint64_t);
@@ -141,15 +172,19 @@ double cResponsePacket::extract_Double()
int32_t cResponsePacket::extract_S32()
{
if ((packetPos + sizeof(int32_t)) > userDataLength) return 0;
- int32_t l = ntohl(*(int32_t*)&userData[packetPos]);
+ int32_t l;
+ memcpy(&l, &userData[packetPos], sizeof(int32_t));
+ l = ntohl(l);
packetPos += sizeof(int32_t);
return l;
}
int64_t cResponsePacket::extract_S64()
{
if ((packetPos + sizeof(int64_t)) > userDataLength) return 0;
- int64_t ll = ntohll(*(int64_t*)&userData[packetPos]);
+ int64_t ll;
+ memcpy(&ll, &userData[packetPos], sizeof(int64_t));
+ ll = ntohll(ll);
packetPos += sizeof(int64_t);
return ll;
}
View
13 addons/pvr.vdr.vnsi/src/responsepacket.h
@@ -29,10 +29,12 @@ class cResponsePacket
cResponsePacket();
~cResponsePacket();
- void setResponse(uint32_t requestID, uint8_t* packet, uint32_t packetLength);
- void setStatus(uint32_t requestID, uint8_t* packet, uint32_t packetLength);
+ void setResponse(uint8_t* packet, uint32_t packetLength);
+ void setStatus(uint8_t* packet, uint32_t packetLength);
+ void setStream(uint8_t* packet, uint32_t packetLength);
- void setStream(uint32_t opcodeID, uint32_t streamID, uint32_t duration, int64_t dts, int64_t pts, uint8_t* packet, uint32_t packetLength);
+ void extractHeader();
+ void extractStreamHeader();
bool noResponse() { return (userData == NULL); };
int serverError();
@@ -61,7 +63,12 @@ class cResponsePacket
// If you call this, the memory becomes yours. Free with free()
uint8_t* getUserData();
+ uint8_t* getHeader() { return header; };
+ unsigned int getStreamHeaderLength() { return 32; };
+ unsigned int getHeaderLength() { return 8; };
+
private:
+ uint8_t header[36];
uint8_t* userData;
uint32_t userDataLength;
uint32_t packetPos;
View
26 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/Makefile
@@ -15,20 +15,22 @@ VERSION = $(shell grep 'static const char \*VERSION *=' vnsi.h | awk '{ print $$
### The C++ compiler and options:
-OPTLEVEL ?= 2
-CXXFLAGS = -O$(OPTLEVEL) -g -Wall -Woverloaded-virtual -fPIC -DPIC
+CXX ?= g++
+CXXFLAGS ?= -g -O3 -fPIC -Wall -Werror=overloaded-virtual -Wno-parentheses
### The directory environment:
-DVBDIR = ../../../../DVB
-VDRDIR = ../../..
-LIBDIR = ../../lib
+VDRDIR ?= ../../..
+LIBDIR = $(VDRDIR)/PLUGINS/lib
TMPDIR = /tmp
+### Make sure that necessary options are included:
+
+-include $(VDRDIR)/Make.global
+
### Allow user defined options to overwrite defaults:
-include $(VDRDIR)/Make.config
--include $(VDRDIR)/Make.global
### The version number of VDR (taken from VDR's "config.h"):
@@ -41,15 +43,9 @@ PACKAGE = vdr-$(ARCHIVE)
### Includes and Defines (add further entries here):
-INCLUDES += -I$(VDRDIR)/include -I$(DVBDIR)/include -I$(VDRDIR)
+INCLUDES += -I$(VDRDIR)/include -I$(VDRDIR)
-DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DVNSI_SERVER_VERSION='"$(VERSION)"'
-ifeq ($(DEBUG),1)
- DEFINES += -DDEBUG
-endif
-ifeq ($(CONSOLEDEBUG),1)
- DEFINES += -DCONSOLEDEBUG
-endif
+DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DVNSI_SERVER_VERSION='"$(VERSION)"'
### The object files (add further files here):
@@ -67,7 +63,7 @@ all-redirect: all
# Dependencies:
-MAKEDEP = g++ -MM -MG
+MAKEDEP = $(CXX) -MM -MG
DEPFILE = .dependencies
$(DEPFILE): Makefile
@$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@
View
26 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/receiver.c
@@ -508,6 +508,11 @@ void cLivePatFilter::Process(u_short Pid, u_char Tid, const u_char *Data, int Le
INFOLOG("Currently unknown new streams found, receiver and demuxers reinited\n");
m_Streamer->RequestStreamChange();
}
+ else if (!m_Streamer->m_Receiver)
+ {
+ m_Streamer->m_Receiver = new cLiveReceiver(m_Streamer, m_Channel, m_Streamer->m_Priority, m_Streamer->m_Pids);
+ m_Streamer->m_Device->AttachReceiver(m_Streamer->m_Receiver);
+ }
}
}
@@ -818,9 +823,7 @@ bool cLiveStreamer::StreamChannel(const cChannel *channel, int priority, cxSocke
if (m_NumStreams > 0 && m_Socket)
{
dsyslog("VNSI: Creating new live Receiver");
- m_Receiver = new cLiveReceiver(this, m_Channel, m_Priority, m_Pids);
m_PatFilter = new cLivePatFilter(this, m_Channel);
- m_Device->AttachReceiver(m_Receiver);
m_Device->AttachFilter(m_PatFilter);
}
@@ -910,18 +913,15 @@ void cLiveStreamer::sendStreamPacket(sStreamPacket *pkt)
m_IFrameSeen = true;
- m_streamHeader.channel = htonl(VNSI_CHANNEL_STREAM); // stream channel
- m_streamHeader.opcode = htonl(VNSI_STREAM_MUXPKT); // Stream packet operation code
-
- m_streamHeader.id = htonl(pkt->id); // Stream ID
- m_streamHeader.duration = htonl(pkt->duration); // Duration
-
- *(int64_t*)&m_streamHeader.dts = __cpu_to_be64(pkt->dts); // DTS
- *(int64_t*)&m_streamHeader.pts = __cpu_to_be64(pkt->pts); // PTS
-
- m_streamHeader.length = htonl(pkt->size); // Data length
- m_Socket->write(&m_streamHeader, sizeof(m_streamHeader), -1, true);
+ if (!m_streamHeader.initStream(VNSI_STREAM_MUXPKT, pkt->id, pkt->duration, pkt->pts, pkt->dts))
+ {
+ ERRORLOG("stream response packet init fail");
+ return;
+ }
+ m_streamHeader.setLen(m_streamHeader.getStreamHeaderLength() + pkt->size);
+ m_streamHeader.finaliseStream();
+ m_Socket->write(m_streamHeader.getPtr(), m_streamHeader.getStreamHeaderLength(), -1, true);
m_Socket->write(pkt->data, pkt->size);
m_last_tick.Set(0);
View
12 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/receiver.h
@@ -35,6 +35,7 @@
#include <vdr/ringbuffer.h>
#include "demuxer.h"
+#include "responsepacket.h"
class cxSocket;
class cChannel;
@@ -83,16 +84,7 @@ class cLiveStreamer : public cThread
cTimeMs m_last_tick;
bool m_SignalLost;
bool m_IFrameSeen;
-
- struct {
- uint32_t channel;
- uint32_t opcode;
- uint32_t id;
- uint32_t duration;
- uint8_t pts[sizeof(int64_t)];
- uint8_t dts[sizeof(int64_t)];
- uint32_t length;
- } m_streamHeader;
+ cResponsePacket m_streamHeader;
protected:
virtual void Action(void);
View
6 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/recplayer.c
@@ -87,7 +87,7 @@ void cRecPlayer::scan()
m_segments.Append(segment);
m_totalLength += s.st_size;
- INFOLOG("File %i found, size: %llu, totalLength now %llu", i, s.st_size, m_totalLength);
+ INFOLOG("File %i found, size: %lu, totalLength now %lu", i, s.st_size, m_totalLength);
}
m_totalFrames = m_indexFile->Last();
@@ -188,13 +188,13 @@ int cRecPlayer::getBlock(unsigned char* buffer, uint64_t position, int amount)
// seek to position
if(lseek(m_file, filePosition, SEEK_SET) == -1) {
- ERRORLOG("unable to seek to position: %llu", filePosition);
+ ERRORLOG("unable to seek to position: %lu", filePosition);
return 0;
}
// try to read the block
int bytes_read = read(m_file, buffer, amount);
- INFOLOG("read %i bytes from file %i at position %llu", bytes_read, segmentNumber, filePosition);
+ INFOLOG("read %i bytes from file %i at position %lu", bytes_read, segmentNumber, filePosition);
if(bytes_read <= 0) {
return 0;
View
18 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/requestpacket.c
@@ -85,33 +85,41 @@ uint8_t cRequestPacket::extract_U8()
uint32_t cRequestPacket::extract_U32()
{
if ((packetPos + sizeof(uint32_t)) > userDataLength) return 0;
- uint32_t ul = ntohl(*(uint32_t*)&userData[packetPos]);
+ uint32_t ul;
+ memcpy(&ul, &userData[packetPos], sizeof(uint32_t));
+ ul = ntohl(ul);
packetPos += sizeof(uint32_t);
return ul;
}
uint64_t cRequestPacket::extract_U64()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = __be64_to_cpu(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = __be64_to_cpu(ull);
packetPos += sizeof(uint64_t);
return ull;
}
double cRequestPacket::extract_Double()
{
if ((packetPos + sizeof(uint64_t)) > userDataLength) return 0;
- uint64_t ull = __be64_to_cpu(*(uint64_t*)&userData[packetPos]);
+ uint64_t ull;
+ memcpy(&ull, &userData[packetPos], sizeof(uint64_t));
+ ull = __be64_to_cpu(ull);
double d;
- memcpy(&d,&ull,sizeof(double));
+ memcpy(&d, &ull, sizeof(double));
packetPos += sizeof(uint64_t);
return d;
}
int32_t cRequestPacket::extract_S32()
{
if ((packetPos + sizeof(int32_t)) > userDataLength) return 0;
- int32_t l = ntohl(*(int32_t*)&userData[packetPos]);
+ int32_t l;
+ memcpy(&l, &userData[packetPos], sizeof(int32_t));
+ l = ntohl(l);
packetPos += sizeof(int32_t);
return l;
}
View
83 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/responsepacket.c
@@ -70,9 +70,15 @@ bool cResponsePacket::init(uint32_t requestID)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_REQUEST_RESPONSE); // RR channel
- *(uint32_t*)&buffer[4] = htonl(requestID);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_REQUEST_RESPONSE); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(requestID);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
@@ -82,9 +88,15 @@ bool cResponsePacket::initScan(uint32_t opCode)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_SCAN); // RR channel
- *(uint32_t*)&buffer[4] = htonl(opCode);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_SCAN); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
@@ -94,38 +106,57 @@ bool cResponsePacket::initStatus(uint32_t opCode)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_STATUS); // RR channel
- *(uint32_t*)&buffer[4] = htonl(opCode);
- *(uint32_t*)&buffer[userDataLenPos] = 0;
+ uint32_t ul;
+
+ ul = htonl(VNSI_CHANNEL_STATUS); // RR channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
+
bufUsed = headerLength;
return true;
}
-bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t dts, int64_t pts)
+bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t pts, int64_t dts)
{
initBuffers();
- *(uint32_t*)&buffer[0] = htonl(VNSI_CHANNEL_STREAM); // stream channel
- *(uint32_t*)&buffer[4] = htonl(opCode); // Stream packet operation code
- *(uint32_t*)&buffer[8] = htonl(streamID); // Stream ID
- *(uint32_t*)&buffer[12] = htonl(duration); // Duration
- *(int64_t*) &buffer[16] = __cpu_to_be64(dts); // DTS
- *(int64_t*) &buffer[24] = __cpu_to_be64(pts); // PTS
- *(uint32_t*)&buffer[userDataLenPosStream] = 0;
+ uint32_t ul;
+ uint64_t ull;
+
+ ul = htonl(VNSI_CHANNEL_STREAM); // stream channel
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(opCode); // Stream packet operation code
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
+ ul = htonl(streamID); // Stream ID
+ memcpy(&buffer[8], &ul, sizeof(uint32_t));
+ ul = htonl(duration); // Duration
+ memcpy(&buffer[12], &ul, sizeof(uint32_t));
+ ull = __cpu_to_be64(pts); // PTS
+ memcpy(&buffer[16], &ull, sizeof(uint64_t));
+ ull = __cpu_to_be64(dts); // DTS
+ memcpy(&buffer[24], &ull, sizeof(uint64_t));
+ ul = 0;
+ memcpy(&buffer[userDataLenPosStream], &ul, sizeof(uint32_t));
+
bufUsed = headerLengthStream;
return true;
}
void cResponsePacket::finalise()
{
- *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
+ uint32_t ul = htonl(bufUsed - headerLength);
+ memcpy(&buffer[userDataLenPos], &ul, sizeof(uint32_t));
}
void cResponsePacket::finaliseStream()
{
- *(uint32_t*)&buffer[userDataLenPosStream] = htonl(bufUsed - headerLengthStream);
+ uint32_t ul = htonl(bufUsed - headerLengthStream);
+ memcpy(&buffer[userDataLenPosStream], &ul, sizeof(uint32_t));
}
@@ -162,7 +193,8 @@ bool cResponsePacket::add_String(const char* string)
bool cResponsePacket::add_U32(uint32_t ul)
{
if (!checkExtend(sizeof(uint32_t))) return false;
- *(uint32_t*)&buffer[bufUsed] = htonl(ul);
+ uint32_t tmp = htonl(ul);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint32_t));
bufUsed += sizeof(uint32_t);
return true;
}
@@ -178,15 +210,17 @@ bool cResponsePacket::add_U8(uint8_t c)
bool cResponsePacket::add_S32(int32_t l)
{
if (!checkExtend(sizeof(int32_t))) return false;
- *(int32_t*)&buffer[bufUsed] = htonl(l);
+ int32_t tmp = htonl(l);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(int32_t));
bufUsed += sizeof(int32_t);
return true;
}
bool cResponsePacket::add_U64(uint64_t ull)
{
if (!checkExtend(sizeof(uint64_t))) return false;
- *(uint64_t*)&buffer[bufUsed] = __cpu_to_be64(ull);
+ uint64_t tmp = __cpu_to_be64(ull);
+ memcpy(&buffer[bufUsed], &tmp, sizeof(uint64_t));
bufUsed += sizeof(uint64_t);
return true;
}
@@ -195,8 +229,9 @@ bool cResponsePacket::add_double(double d)
{
if (!checkExtend(sizeof(double))) return false;
uint64_t ull;
- memcpy(&ull,&d,sizeof(double));
- *(uint64_t*)&buffer[bufUsed] = __cpu_to_be64(ull);
+ memcpy(&ull, &d, sizeof(double));
+ ull = __cpu_to_be64(ull);
+ memcpy(&buffer[bufUsed], &ull, sizeof(uint64_t));
bufUsed += sizeof(uint64_t);
return true;
}
View
4 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/responsepacket.h
@@ -40,7 +40,7 @@ class cResponsePacket
bool init(uint32_t requestID);
bool initScan(uint32_t opCode);
bool initStatus(uint32_t opCode);
- bool initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t dts, int64_t pts);
+ bool initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t pts, int64_t dts);
void finalise();
void finaliseStream();
bool copyin(const uint8_t* src, uint32_t len);
@@ -56,6 +56,8 @@ class cResponsePacket
uint8_t* getPtr() { return buffer; }
uint32_t getLen() { return bufUsed; }
+ uint32_t getStreamHeaderLength() { return headerLengthStream; } ;
+ void setLen(uint32_t len) { bufUsed = len; }
private:
uint8_t* buffer;
View
9 addons/pvr.vdr.vnsi/vdr-plugin-vnsiserver/vnsiclient.c
@@ -162,8 +162,11 @@ void cVNSIClient::Action(void)
kaTimeStamp = ntohl(kaTimeStamp);
uint8_t buffer[8];
- *(uint32_t*)&buffer[0] = htonl(3); // KA CHANNEL
- *(uint32_t*)&buffer[4] = htonl(kaTimeStamp);
+ uint32_t ul;
+ ul = htonl(3); // KA CHANNEL
+ memcpy(&buffer[0], &ul, sizeof(uint32_t));
+ ul = htonl(kaTimeStamp);
+ memcpy(&buffer[4], &ul, sizeof(uint32_t));
if (!m_socket.write(buffer, 8))
{
ERRORLOG("Could not send back KA reply");
@@ -792,7 +795,7 @@ bool cVNSIClient::processRecStream_GetIFrame() /* OPCODE 45 */
m_resp->finalise();
m_socket.write(m_resp->getPtr(), m_resp->getLen());
- DEBUGLOG("Wrote GNIF reply to client %llu %u %u", rfilePosition, rframeNumber, rframeLength);
+ DEBUGLOG("Wrote GNIF reply to client %lu %u %u", rfilePosition, rframeNumber, rframeLength);
return true;
}

0 comments on commit e10dedb

Please sign in to comment.