File xineliboutput-2.1.0...977ff0.diff of Package vdr-plugin-xineliboutput
diff --git a/config.c b/config.c
index 8851646..3cf1734 100644
--- a/config.c
+++ b/config.c
@@ -815,7 +815,7 @@ bool config_t::ProcessArgs(int argc, char *argv[])
case 'h': //ProcessArg("Fullscreen", "0");
ProcessArg("X11.WindowHeight", optarg);
break;
- case 'g': {
+ case 'g': if (optarg) {
int _width = width, _height = height, _xpos = 0, _ypos = 0;
sscanf (optarg, "%dx%d+%d+%d", &_width, &_height, &_xpos, &_ypos);
ProcessArg("X11.WindowWidth", *cString::sprintf("%d", _width));
@@ -832,7 +832,7 @@ bool config_t::ProcessArgs(int argc, char *argv[])
break;
//case 'm': ProcessArg("Modeline", optarg);
// break;
- case 'r': if(strcmp(optarg, "none")) {
+ case 'r': if (optarg && strcmp(optarg, "none")) {
if(strchr(optarg, ':')) {
char *tmp = strdup(optarg);
char *pt = strchr(tmp,':');
@@ -851,7 +851,7 @@ bool config_t::ProcessArgs(int argc, char *argv[])
break;
case 'V': ProcessArg("Video.Driver", optarg);
break;
- case 'A': if(strchr(optarg,':')) {
+ case 'A': if (optarg && strchr(optarg,':')) {
char *tmp = strdup(optarg);
char *pt = strchr(tmp,':');
*pt = 0;
@@ -865,7 +865,10 @@ bool config_t::ProcessArgs(int argc, char *argv[])
post_plugins = strcatrealloc(post_plugins, ";");
post_plugins = strcatrealloc(post_plugins, optarg);
break;
- case 'C': config_file = strdup(optarg);
+ case 'C': if (optarg) {
+ free(config_file);
+ config_file = strdup(optarg);
+ }
break;
case 'p': ProcessArg("ForcePrimaryDevice", "1");
break;
diff --git a/frontend_local.c b/frontend_local.c
index fd834ed..530d469 100644
--- a/frontend_local.c
+++ b/frontend_local.c
@@ -256,7 +256,6 @@ int cXinelibLocal::Xine_Control(const char *cmd)
frontend_t *cXinelibLocal::load_frontend(const char *fe_name)
{
Dl_info info;
- struct stat statbuffer;
char libname[4096]="";
void *lib = NULL;
fe_creator_f *fe_creator = NULL;
@@ -285,14 +284,15 @@ frontend_t *cXinelibLocal::load_frontend(const char *fe_name)
do {
strncat(libname, xc.s_frontend_files[fe_ind], 64);
LOGDBG("Probing %s", libname);
-
+#if 0
+ struct stat statbuffer;
if (stat(libname, &statbuffer)) {
LOGERR("load_frontend: can't stat %s", libname);
} else if((statbuffer.st_mode & S_IFMT) != S_IFREG) {
LOGMSG("load_frontend: %s not regular file ! trying to load anyway ...",
libname);
}
-
+#endif
if ( !(lib = dlopen (libname, RTLD_LAZY | RTLD_GLOBAL))) {
LOGERR("load_frontend: cannot dlopen file %s: %s", libname, dlerror());
diff --git a/frontend_svr.c b/frontend_svr.c
index 46f3619..d783586 100644
--- a/frontend_svr.c
+++ b/frontend_svr.c
@@ -65,9 +65,13 @@
#undef MIN
#define MIN(a,b) ( (a) < (b) ? (a) : (b))
-typedef struct {
+typedef struct grab_result {
int Size;
uchar *Data;
+ grab_result() {
+ Size = 0;
+ Data = NULL;
+ }
} grab_result_t;
class cStcFuture : public cFuture<int64_t> {};
@@ -823,9 +827,9 @@ int cXinelibServer::PlayFileCtrl(const char *Cmd, int TimeoutMs)
}
int result;
- bool bPlayfile = false;
- if((!strncmp(Cmd, "PLAYFILE", 8) && (bPlayfile=true)) ||
- (!strncmp(Cmd, "GET", 3) )) { // GETPOS, GETLENGTH, ...
+ bool bPlayfile = !strncmp(Cmd, "PLAYFILE", 8);
+ if (bPlayfile ||
+ !strncmp(Cmd, "GET", 3)) { // GETPOS, GETLENGTH, ...
if(TimeoutMs < 0)
TimeoutMs = bPlayfile ? PLAYFILE_TIMEOUT : PLAYFILE_CTRL_TIMEOUT;
@@ -870,18 +874,21 @@ bool cXinelibServer::Listen(int listen_port)
CLOSESOCKET(fd_listen);
int iReuse = 1;
- struct sockaddr_in name;
- memset(&name, 0, sizeof(name));
- name.sin_family = AF_INET;
- name.sin_addr.s_addr = htonl(INADDR_ANY);
- name.sin_port = htons(m_Port);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_addr.s_addr = htonl(INADDR_ANY);
+ addr.in.sin_port = htons(m_Port);
if(xc.remote_local_ip[0]) {
uint32_t ip = inet_addr(xc.remote_local_ip);
if(ip != INADDR_NONE) {
char txt[128];
- name.sin_addr.s_addr = ip;
- LOGDBG("Binding server to %s", cxSocket::ip2txt(name.sin_addr.s_addr, htons(m_Port), txt));
+ addr.in.sin_addr.s_addr = ip;
+ LOGDBG("Binding server to %s", cxSocket::ip2txt(addr.in.sin_addr.s_addr, htons(m_Port), txt));
} else {
LOGERR("Local interface address %s is invalid !", xc.remote_local_ip);
}
@@ -894,7 +901,7 @@ bool cXinelibServer::Listen(int listen_port)
LOGERR("cXinelibServer: error setting REUSE for listen socket");
}
- if (bind(fd_listen, (struct sockaddr *)&name, sizeof(name)) < 0) {
+ if (bind(fd_listen, &addr.sa, sizeof(addr)) < 0) {
LOGERR("cXinelibServer: bind error %s port %d: %s",
xc.remote_local_ip[0] ? xc.remote_local_ip : "",
m_Port, strerror(errno));
@@ -1544,15 +1551,18 @@ void cXinelibServer::Handle_Control_RTSP(int cli, const char *arg)
else if(!strcmp(m_State[cli]->Name(), "DESCRIBE")) {
cHeader *accept = m_State[cli]->Header("Accept");
if(accept && strstr(accept->Value(), "application/sdp")) {
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ socklen_t len = sizeof(addr);
char buf[64];
uint32_t payload_type = VDRVERSNUM > 10702 ? SDP_PAYLOAD_MPEG_TS : SDP_PAYLOAD_MPEG_PES;
- if (fd_control[cli].getsockname((struct sockaddr *)&sin, &len) < 0) {
+ if (fd_control[cli].getsockname(&addr.sa, &len) < 0) {
LOGERR("Error getting control socket address");
}
- cString sdp_descr = vdr_sdp_description(cxSocket::ip2txt(sin.sin_addr.s_addr,
- sin.sin_port, buf),
+ cString sdp_descr = vdr_sdp_description(cxSocket::ip2txt(addr.in.sin_addr.s_addr,
+ addr.in.sin_port, buf),
2001,
xc.listen_port,
xc.remote_rtp_addr,
@@ -1582,9 +1592,9 @@ void cXinelibServer::Handle_Control_RTSP(int cli, const char *arg)
cHeader *transport = m_State[cli]->Header("Transport");
int urtp=0, mrtp=0, tcp=0;
if(transport &&
- ( (strstr(transport->Value(), "RTP/AVP;multicast") && (mrtp=1)) ||
- (strstr(transport->Value(), "RTP/AVP;unicast") && (urtp=1)) ||
- (strstr(transport->Value(), "RTP/AVP;interleaved") && (tcp=1)))) {
+ ( (mrtp = !!strstr(transport->Value(), "RTP/AVP;multicast")) ||
+ (urtp = !!strstr(transport->Value(), "RTP/AVP;unicast")) ||
+ (tcp = !!strstr(transport->Value(), "RTP/AVP;interleaved")))) {
//if(!mrtp)
// sprintf(buf, "RTSP/1.0 461 Unsupported transport\r\n" RTSP_H_CSEQ RTSP_OK_FIN);
//else
@@ -1779,25 +1789,28 @@ void cXinelibServer::Read_Control(int cli)
void cXinelibServer::Handle_ClientConnected(int fd)
{
char buf[64];
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ socklen_t len = sizeof(addr);
int cli;
for(cli=0; cli<MAXCLIENTS; cli++)
if(!fd_control[cli].open())
break;
- if(getpeername(fd, (struct sockaddr *)&sin, &len)) {
+ if (getpeername(fd, &addr.sa, &len) < 0) {
LOGERR("getpeername() failed, dropping new incoming connection %d", cli);
CLOSESOCKET(fd);
return;
}
LOGMSG("Client %d connected: %s", cli,
- cxSocket::ip2txt(sin.sin_addr.s_addr, sin.sin_port, buf));
+ cxSocket::ip2txt(addr.in.sin_addr.s_addr, addr.in.sin_port, buf));
cAllowedHosts AllowedHosts(m_AllowedHostsFile);
- if (!AllowedHosts.Acceptable(sin.sin_addr.s_addr)) {
+ if (!AllowedHosts.Acceptable(addr.in.sin_addr.s_addr)) {
const char *msg = "Access denied.\r\n";
ssize_t len = strlen(msg);
LOGMSG("Address not allowed to connect (%s)", *m_AllowedHostsFile);
diff --git a/menu.c b/menu.c
index 1ec2144..e928a34 100644
--- a/menu.c
+++ b/menu.c
@@ -200,8 +200,8 @@ char *cMenuBrowseFiles::GetLastDir(void)
switch (m_Mode) {
case ShowMusic: return xc.browse_music_dir;
case ShowImages: return xc.browse_images_dir;
- default:
case ShowFiles: return xc.browse_files_dir;
+ default: break;
}
return xc.browse_files_dir;
}
diff --git a/tools/backgroundwriter.c b/tools/backgroundwriter.c
index 79f0610..cd7ef3e 100644
--- a/tools/backgroundwriter.c
+++ b/tools/backgroundwriter.c
@@ -353,6 +353,13 @@ void cRawWriter::Action(void)
LOGMSG("cBackgroundWriter @NextHeaderPos: Count < header size !");
int packlen = DATA_IS_TS(Data) ? TS_SIZE : pes_packet_len(Data, Count);
+ if (packlen < 1) {
+ LOGMSG("cBackgroundWriter: garbage in input ? clearing buffer");
+ Lock();
+ m_DiscardEnd = m_PutPos;
+ Unlock();
+ continue;
+ }
if (Count < packlen)
;//LOGMSG("Count = %d < %d", Count,
diff --git a/tools/cxsocket.c b/tools/cxsocket.c
index c3c0a62..43be3df 100644
--- a/tools/cxsocket.c
+++ b/tools/cxsocket.c
@@ -33,11 +33,16 @@ bool cxSocket::connect(struct sockaddr *addr, socklen_t len)
bool cxSocket::connect(const char *ip, int port)
{
- struct sockaddr_in sin;
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = inet_addr(ip);
- return connect((struct sockaddr *)&sin, sizeof(sin));
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = htons(port);
+ addr.in.sin_addr.s_addr = inet_addr(ip);
+
+ return connect(&addr.sa, sizeof(addr));
}
bool cxSocket::set_blocking(bool state)
@@ -347,11 +352,14 @@ uint32_t cxSocket::get_local_address(char *ip_address)
struct ifreq buf[3];
unsigned int n;
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ socklen_t len = sizeof(addr);
- if(!getsockname((struct sockaddr *)&sin, &len)) {
- local_addr = sin.sin_addr.s_addr;
+ if (!getsockname(&addr.sa, &len)) {
+ local_addr = addr.in.sin_addr.s_addr;
} else {
//LOGERR("getsockname failed");
diff --git a/tools/cxsocket.h b/tools/cxsocket.h
index de63904..f7f8acf 100644
--- a/tools/cxsocket.h
+++ b/tools/cxsocket.h
@@ -149,16 +149,19 @@ static inline void set_socket_buffers(int s, int txbuf, int rxbuf)
//
static inline int sock_connect(int fd_control, int port, int type)
{
- struct sockaddr_in sin;
- socklen_t len = sizeof(sin);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ socklen_t len = sizeof(addr);
int s, one = 1;
- if(getpeername(fd_control, (struct sockaddr *)&sin, &len)) {
+ if (getpeername(fd_control, &addr.sa, &len) < 0) {
LOGERR("sock_connect: getpeername failed");
return -1;
}
- uint32_t tmp = ntohl(sin.sin_addr.s_addr);
+ uint32_t tmp = ntohl(addr.in.sin_addr.s_addr);
LOGMSG("Client address: %d.%d.%d.%d",
((tmp>>24)&0xff), ((tmp>>16)&0xff),
((tmp>>8)&0xff), ((tmp)&0xff));
@@ -181,10 +184,10 @@ static inline int sock_connect(int fd_control, int port, int type)
if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int)) < 0)
LOGERR("sock_connect: setsockopt(SO_REUSEADDR) failed");
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = htons(port);
- if (connect(s, (struct sockaddr *)&sin, sizeof(sin))==-1 &&
+ if (connect(s, &addr.sa, sizeof(addr)) < 0 &&
errno != EINPROGRESS) {
LOGERR("connect() failed");
CLOSESOCKET(s);
diff --git a/tools/future.h b/tools/future.h
index e5c5414..43d998d 100644
--- a/tools/future.h
+++ b/tools/future.h
@@ -28,6 +28,7 @@ class cFuture {
cFuture()
{
m_Ready = false;
+ memset(&m_Value, 0, sizeof(m_Value));
}
void Reset(void)
diff --git a/tools/pes.h b/tools/pes.h
index 73229cc..00da267 100644
--- a/tools/pes.h
+++ b/tools/pes.h
@@ -99,14 +99,23 @@ static inline int pes_is_mpeg1(const uint8_t *header)
static inline int pes_packet_len(const uint8_t *data, const int len)
{
if (IS_VIDEO_PACKET(data) || IS_AUDIO_PACKET(data)) {
+ if (len < 6)
+ return 0;
return 6 + (data[4] << 8 | data[5]);
} else if (data[3] == PADDING_STREAM) {
+ if (len < 6)
+ return 0;
return 6 + (data[4] << 8 | data[5]);
} else if (data[3] == 0xBA) {
+ if (len < 5)
+ return 0;
if ((data[4] & 0x40) == 0) /* mpeg1 */
return 12;
- else /* mpeg 2 */
+ else { /* mpeg 2 */
+ if (len < 14)
+ return 0;
return 14 + (data[0xD] & 0x07);
+ }
} else if (data[3] <= 0xB9) {
return -3;
}
diff --git a/tools/rle.c b/tools/rle.c
index bddd6ac..2c944c7 100644
--- a/tools/rle.c
+++ b/tools/rle.c
@@ -262,8 +262,11 @@ size_t rle_compress_argbrle(uint8_t **rle_data, const uint32_t *data,
*rle_data = NULL;
*num_rle = 0;
- assert(h > 0);
- assert(w <= 0x3fff);
+ assert(w > 0); /* avoid overreading data */
+ assert(w <= 0x3fff); /* larger value does not fit in codeword */
+
+ if (w < 1 || h < 1)
+ return 0;
for (y = 0; y < h; y++) {
@@ -442,11 +445,15 @@ size_t rle_compress_hdmv(uint8_t **rle_data, const uint8_t *data, unsigned w, un
size_t rle_size = 0;
uint8_t *rle = NULL;
- assert(w <= 0x3fff);
+ assert(w > 0); /* avoid overreading data */
+ assert(w <= 0x3fff); /* larger value does not fit in codeword */
*rle_data = NULL;
*num_rle = 0;
+ if (w < 1 || h < 1)
+ return 0;
+
for (y = 0; y < h; y++) {
/* grow buffer ? */
diff --git a/tools/sap.h b/tools/sap.h
index 212b8d4..43379e5 100644
--- a/tools/sap.h
+++ b/tools/sap.h
@@ -146,13 +146,16 @@ static inline int sap_send_pdu(int *pfd, sap_pdu_t *pdu, uint32_t dst_ip)
}
// Connect to multicast address
- struct sockaddr_in sin;
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(SAP_UDP_PORT);
- sin.sin_addr.s_addr = dst_ip ? dst_ip : inet_addr(SAP_IP_ADDRESS_GLOBAL);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = htons(SAP_UDP_PORT);
+ addr.in.sin_addr.s_addr = dst_ip ? dst_ip : inet_addr(SAP_IP_ADDRESS_GLOBAL);
- if(connect(fd, (struct sockaddr *)&sin, sizeof(sin))==-1)
+ if (connect(fd, &addr.sa, sizeof(addr)) == -1)
LOGERR("UDP/SAP multicast connect() failed.");
// Set to non-blocking mode
diff --git a/tools/ts.c b/tools/ts.c
index e769ae1..67e013e 100644
--- a/tools/ts.c
+++ b/tools/ts.c
@@ -634,7 +634,7 @@ ts_state_t *ts_state_init(size_t buffer_size)
if (buffer_size < 8 * TS_SIZE)
buffer_size = 8 * TS_SIZE;
if (buffer_size > 4*1024*1024) {
- LOGMSG("ERROR: ts_state_init(%zd)", buffer_size);
+ LOGMSG("ERROR: ts_state_init(%zu)", buffer_size);
buffer_size = 4*1024*1024;
}
@@ -677,6 +677,11 @@ static size_t ts_add_payload(ts_state_t *ts, const uint8_t *data)
ts->buf_len = 0;
}
+ if (ts->buf_size < 2*TS_SIZE) {
+ LOGMSG("ts_add_payload(): assertion failed: buf_size < 2*TS_SIZE");
+ return 0;
+ }
+
if (ts->buf_len >= ts->buf_size - TS_SIZE) {
LOGDBG("ts_add_payload: buffer full");
ts->buf_len -= TS_SIZE;
diff --git a/tools/udp_pes_scheduler.c b/tools/udp_pes_scheduler.c
index 1ea970c..5a6dec9 100644
--- a/tools/udp_pes_scheduler.c
+++ b/tools/udp_pes_scheduler.c
@@ -184,14 +184,17 @@ bool cUdpScheduler::AddRtp(void)
}
if(xc.remote_local_ip[0]) {
- struct sockaddr_in name;
- memset(&name, 0, sizeof(name));
- name.sin_family = AF_INET;
- name.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
- if(name.sin_addr.s_addr == INADDR_NONE)
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
+ if(addr.in.sin_addr.s_addr == INADDR_NONE)
LOGERR("Local address %s is invalid", xc.remote_local_ip);
- name.sin_port = htons(xc.remote_rtp_port);
- if (bind(m_fd_rtp.handle(), (struct sockaddr *)&name, sizeof(name)) < 0)
+ addr.in.sin_port = htons(xc.remote_rtp_port);
+ if (bind(m_fd_rtp.handle(), &addr.sa, sizeof(addr)) < 0)
LOGERR("bind(%s:%d) failed for udp/rtp multicast", xc.remote_local_ip, xc.remote_rtp_port);
#if 0
struct ip_mreqn mreqn;
@@ -226,12 +229,15 @@ bool cUdpScheduler::AddRtp(void)
m_fd_rtcp.close();
if(xc.remote_local_ip[0]) {
- struct sockaddr_in name;
- memset(&name, 0, sizeof(name));
- name.sin_family = AF_INET;
- name.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
- name.sin_port = htons(xc.remote_rtp_port+1);
- if (bind(m_fd_rtcp.handle(), (struct sockaddr *)&name, sizeof(name)) < 0)
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_addr.s_addr = inet_addr(xc.remote_local_ip);
+ addr.in.sin_port = htons(xc.remote_rtp_port+1);
+ if (bind(m_fd_rtcp.handle(), &addr.sa, sizeof(addr)) < 0)
LOGERR("bind(%s:%d) failed for udp/rtp multicast", xc.remote_local_ip, xc.remote_rtp_port);
#if 0
struct ip_mreqn mreqn;
@@ -585,7 +591,7 @@ void cUdpScheduler::Send_RTCP(void)
msg->hdr.length = htons(1 + 1 + ((it->length - 2) + 3) / 4);
content += sizeof(rtcp_common_t) + 4*ntohs(msg->hdr.length);
- msg = (rtcp_packet_t *)content;
+ //msg = (rtcp_packet_t *)content;
// Send
#ifndef LOG_RTCP
@@ -887,7 +893,9 @@ void cUdpScheduler::ReSend(int fd, uint64_t Pos, int Seq1, int Seq2)
snprintf(udp_ctrl.payload, sizeof(udp_ctrl.payload),
"UDP MISSING %d-%d %" PRIu64,
Seq1, (Seq2 & UDP_BUFFER_MASK), Pos);
- send(fd, &udp_ctrl, sizeof(udp_ctrl), 0);
+ if (send(fd, &udp_ctrl, sizeof(udp_ctrl), 0) != sizeof(udp_ctrl)) {
+ LOGERR("cUdpScheduler: UDP/RTP re-send() failed !");
+ }
return;
}
@@ -906,12 +914,13 @@ void cUdpScheduler::ReSend(int fd, uint64_t Pos, int Seq1, int Seq2)
if(frame) {
if(priv_ntohull(frame->hdr_ext.pos) - Pos < 100000) {
- send(fd,
- RTP_UDP_PAYLOAD(frame),
- m_BackLog->PayloadSize(Seq1) + sizeof(stream_udp_header_t),
- 0);
- LOGRESEND("cUdpScheduler::ReSend: %d (%d bytes) @%lld sent",
- Seq1, m_BackLog->PayloadSize(Seq1), Pos);
+ ssize_t pac_len = m_BackLog->PayloadSize(Seq1) + sizeof(stream_udp_header_t);
+ if (send(fd, RTP_UDP_PAYLOAD(frame), pac_len, 0) != pac_len) {
+ LOGERR("cUdpScheduler: UDP/RTP re-send() failed !");
+ } else {
+ LOGRESEND("cUdpScheduler::ReSend: %d (%d bytes) @%lld sent",
+ Seq1, m_BackLog->PayloadSize(Seq1), Pos);
+ }
Pos = priv_ntohull(frame->hdr_ext.pos) + m_BackLog->PayloadSize(Seq1);
continue;
} else {
@@ -939,6 +948,8 @@ void cUdpScheduler::ReSend(int fd, uint64_t Pos, int Seq1, int Seq2)
"UDP MISSING %d-%d %" PRIu64,
Seq0, (Seq1 & UDP_BUFFER_MASK), Pos);
- send(fd, &udp_ctrl, sizeof(udp_ctrl), 0);
+ if (send(fd, &udp_ctrl, sizeof(udp_ctrl), 0) != sizeof(udp_ctrl)) {
+ LOGERR("cUdpScheduler: UDP/RTP control send() failed !");
+ }
}
}
diff --git a/tools/vdrdiscovery.c b/tools/vdrdiscovery.c
index a4d67a1..80eb3d9 100644
--- a/tools/vdrdiscovery.c
+++ b/tools/vdrdiscovery.c
@@ -60,7 +60,10 @@ static inline int discovery_init(int port)
{
int fd_discovery = -1;
int iBroadcast = 1, iReuse = 1;
- struct sockaddr_in sin;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
if ((fd_discovery = socket(PF_INET, SOCK_DGRAM, 0/*IPPROTO_TCP*/)) < 0) {
LOGERR("discovery_init: socket() failed");
@@ -73,11 +76,11 @@ static inline int discovery_init(int port)
if (setsockopt(fd_discovery, SOL_SOCKET, SO_REUSEADDR, &iReuse, sizeof(int)) < 0)
LOGERR("discovery_init: setsockopt(SO_REUSEADDR) failed");
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = htonl(INADDR_BROADCAST);
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = htons(port);
+ addr.in.sin_addr.s_addr = htonl(INADDR_BROADCAST);
- if (bind(fd_discovery, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ if (bind(fd_discovery, &addr.sa, sizeof(addr)) < 0) {
LOGERR("discovery_init: bind() failed");
close(fd_discovery);
return -1;
@@ -93,15 +96,17 @@ int udp_discovery_init(void)
static inline int udp_discovery_send(int fd_discovery, int port, char *msg)
{
- struct sockaddr_in sin;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
int len = strlen(msg);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = INADDR_BROADCAST;
+ addr.in.sin_family = AF_INET;
+ addr.in.sin_port = htons(port);
+ addr.in.sin_addr.s_addr = INADDR_BROADCAST;
- if(len != sendto(fd_discovery, msg, len, 0,
- (struct sockaddr *)&sin, sizeof(sin))) {
+ if (len != sendto(fd_discovery, msg, len, 0, &addr.sa, sizeof(addr))) {
LOGERR("UDP broadcast send failed (discovery)");
return -1;
}
diff --git a/xine/demux_xvdr.c b/xine/demux_xvdr.c
index 40001c3..533b3b2 100644
--- a/xine/demux_xvdr.c
+++ b/xine/demux_xvdr.c
@@ -654,7 +654,7 @@ static int32_t parse_pes_for_pts(demux_xvdr_t *this, uint8_t *p, buf_element_t *
this->pts |= (p[ 2] & 0xFE) << 14 ;
this->pts |= p[ 3] << 7 ;
this->pts |= (p[ 4] & 0xFE) >> 1 ;
- p += 5;
+ //p += 5;
header_len+= 5;
this->packet_len -=5;
return header_len;
@@ -671,12 +671,12 @@ static int32_t parse_pes_for_pts(demux_xvdr_t *this, uint8_t *p, buf_element_t *
this->dts |= p[ 8] << 7 ;
this->dts |= (p[ 9] & 0xFE) >> 1 ;
- p += 10;
+ //p += 10;
header_len += 10;
this->packet_len -= 10;
return header_len;
} else {
- p++;
+ //p++;
header_len++;
this->packet_len--;
return header_len;
diff --git a/xine/post.c b/xine/post.c
index 70004ef..921223d 100644
--- a/xine/post.c
+++ b/xine/post.c
@@ -308,6 +308,21 @@ static post_element_t **pplugin_parse_and_load(fe_t *fe,
return post_elements;
}
+static void strcat_n(size_t sz, char *dst, const char *src)
+{
+ size_t len = strlen(dst) + strlen(src);
+ if (sz < 1)
+ return;
+ if (len + 6 > sz) {
+ while (len + 1 < sz) {
+ dst[len++] = '.';
+ }
+ dst[sz-1] = 0;
+ return;
+ }
+ strcat(dst, src);
+}
+
static
void pplugin_parse_and_store_post(fe_t *fe, int plugin_type,
const char *post_chain)
@@ -364,12 +379,12 @@ void pplugin_parse_and_store_post(fe_t *fe, int plugin_type,
if((*_post_elements)[i])
if(((*_post_elements)[i])->post) {
if(((*_post_elements)[i])->enable)
- strcat(s, "*");
+ strcat_n(sizeof(s), s, "*");
if(((*_post_elements)[i])->name)
- strcat(s, ((*_post_elements)[i])->name);
+ strcat_n(sizeof(s), s, ((*_post_elements)[i])->name);
else
- strcat(s, "<no name!>");
- strcat(s, " ");
+ strcat_n(sizeof(s), s, "<no name!>");
+ strcat_n(sizeof(s), s, " ");
}
LOGDBG(" loaded plugins (type %d.%d): %s",
(plugin_type>>16), (plugin_type&0xffff), s);
diff --git a/xine_fbfe_frontend.c b/xine_fbfe_frontend.c
index 254087e..c5977b1 100644
--- a/xine_fbfe_frontend.c
+++ b/xine_fbfe_frontend.c
@@ -76,7 +76,7 @@ static void update_DFBARGS(const char *fb_dev)
const char *env_old = getenv("DFBARGS");
char *env_new = NULL;
- if (env_old) {
+ if (env_old && env_old[0]) {
char *env_tmp = strdup(env_old);
char *head = strstr(env_tmp, "fbdev=");
@@ -92,7 +92,7 @@ static void update_DFBARGS(const char *fb_dev)
return;
}
} else {
- if(asprintf(&env_new, "fbdev=%s%s%s", fb_dev, env_tmp ? "," : "", env_tmp ?: "") < 0) {
+ if (asprintf(&env_new, "fbdev=%s,%s", fb_dev, env_tmp) < 0) {
free(env_tmp);
return;
}
diff --git a/xine_frontend.c b/xine_frontend.c
index 6902f3f..0bf30bf 100644
--- a/xine_frontend.c
+++ b/xine_frontend.c
@@ -686,6 +686,14 @@ static int fe_xine_init(frontend_t *this_gen, const char *audio_driver,
"also increased latency and memory "
"consumption."),
20, NULL, NULL);
+ x_reg_num ("engine.buffers.audio_num_buffers",
+ 500,
+ _("number of audio buffers"),
+ _("The number of audio buffers (each is 8k in size) "
+ "xine uses in its internal queue. Higher values "
+ "mean smoother playback for unreliable inputs, but "
+ "also increased latency and memory consumption."),
+ 20, NULL, NULL);
x_reg_bool("gui.osd_use_unscaled",
0,
_("Use unscaled OSD"),
diff --git a/xine_frontend_lirc.c b/xine_frontend_lirc.c
index e227c51..67038b5 100644
--- a/xine_frontend_lirc.c
+++ b/xine_frontend_lirc.c
@@ -64,7 +64,10 @@ extern int gui_hotkeys;
static void lircd_connect(void)
{
- struct sockaddr_un addr;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_un un;
+ } addr;
if (fd_lirc >= 0) {
close(fd_lirc);
@@ -76,16 +79,16 @@ static void lircd_connect(void)
return;
}
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, (char*)lirc_device_name, sizeof(addr.sun_path));
- addr.sun_path[sizeof(addr.sun_path)-1] = 0;
+ addr.un.sun_family = AF_UNIX;
+ strncpy(addr.un.sun_path, (char*)lirc_device_name, sizeof(addr.un.sun_path));
+ addr.un.sun_path[sizeof(addr.un.sun_path)-1] = 0;
if ((fd_lirc = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
LOGERR("lirc error: socket() < 0");
return;
}
- if (connect(fd_lirc, (struct sockaddr *)&addr, sizeof(addr))) {
+ if (connect(fd_lirc, &addr.sa, sizeof(addr))) {
LOGERR("lirc error: connect(%s) < 0", lirc_device_name);
close(fd_lirc);
fd_lirc = -1;
diff --git a/xine_frontend_main.c b/xine_frontend_main.c
index 42a6c39..c3d8355 100644
--- a/xine_frontend_main.c
+++ b/xine_frontend_main.c
@@ -399,9 +399,11 @@ int main(int argc, char *argv[])
PRINTF("Buffers: %d\n", pes_buffers);
break;
case 'T': tty = optarg;
+#if 0
if (access(tty, R_OK | W_OK) < 0) {
EXIT("Can't access terminal: %s\n", tty);
}
+#endif
PRINTF("Terminal: %s\n", tty);
break;
case 'n': scale_video = 0;
@@ -503,7 +505,14 @@ int main(int argc, char *argv[])
/* claim new controlling terminal */
stdin = freopen(tty, "r", stdin);
stdout = freopen(tty, "w", stdout);
+ if (!stdin || !stdout) {
+ EXIT("Can't access terminal: %s\n", tty);
+ }
stderr = freopen(tty, "w", stderr);
+ if (!stderr) {
+ printf("Error reopening stderr\n");
+ exit(-1);
+ }
}
#if 1
@@ -530,8 +539,10 @@ int main(int argc, char *argv[])
if (mrl) {
char *tmp = mrl;
mrl = NULL;
- if (asprintf(&mrl, "%s//%s:%d", tmp, address, port) < 0)
+ if (asprintf(&mrl, "%s//%s:%d", tmp, address, port) < 0) {
+ free(tmp);
return -1;
+ }
free(tmp);
} else
if (asprintf(&mrl, MRL_ID "://%s:%d", address, port) < 0)
@@ -545,13 +556,14 @@ int main(int argc, char *argv[])
}
}
- if (mrl &&
- strncmp(mrl, MRL_ID ":", MRL_ID_LEN+1) &&
+ if (strncmp(mrl, MRL_ID ":", MRL_ID_LEN+1) &&
strncmp(mrl, MRL_ID "+", MRL_ID_LEN+1)) {
char *mrl2 = mrl;
PRINTF("WARNING: MRL does not start with \'" MRL_ID ":\' (%s)\n", mrl);
- if (asprintf(&mrl, MRL_ID "://%s", mrl) < 0)
+ if (asprintf(&mrl, MRL_ID "://%s", mrl) < 0) {
+ free(mrl2);
return -1;
+ }
free(mrl2);
}
@@ -582,6 +594,7 @@ int main(int argc, char *argv[])
fe = (*fe_creator)();
if (!fe) {
fprintf(stderr, "Error initializing frontend\n");
+ free(mrl);
return -3;
}
@@ -592,6 +605,7 @@ int main(int argc, char *argv[])
aspect_controller, window_id)) {
fprintf(stderr, "Error opening display\n");
fe->fe_free(fe);
+ free(mrl);
return -4;
}
@@ -601,6 +615,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error initializing xine\n");
list_xine_plugins(fe, SysLogLevel>2);
fe->fe_free(fe);
+ free(mrl);
return -5;
}
if (power_off_cmd) {
diff --git a/xine_input_vdr.c b/xine_input_vdr.c
index 31a5bf6..3ebc6e6 100644
--- a/xine_input_vdr.c
+++ b/xine_input_vdr.c
@@ -883,6 +883,22 @@ static void create_timeout_time(struct timespec *abstime, int timeout_ms)
/**************************** socket I/O *********************************/
+int io_set_nonblock(int fd)
+{
+ int flags, result;
+
+ flags = fcntl (fd, F_GETFL);
+ if (flags < 0) {
+ LOGERR("fcntl(F_GETFL) failed");
+ return flags;
+ }
+ result = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+ if (result < 0) {
+ LOGERR("Failed setting fd to non-blocking mode");
+ }
+ return result;
+}
+
/*
* io_select_rd()
*
@@ -935,7 +951,7 @@ static int io_select_rd (int fd)
*/
static ssize_t write_control_data(vdr_input_plugin_t *this, const void *str, size_t len)
{
- size_t ret, result = len;
+ size_t result = len;
while (len > 0) {
@@ -968,7 +984,7 @@ static ssize_t write_control_data(vdr_input_plugin_t *this, const void *str, siz
}
errno = 0;
- ret = send (this->fd_control, str, len, 0);
+ ssize_t ret = send (this->fd_control, str, len, 0);
if (ret <= 0) {
if (ret == 0) {
@@ -2319,15 +2335,17 @@ static void dvd_set_speed(const char *device, int speed)
if (!device) return;
if (!speed) return;
- if (stat(device, &st) == -1) return;
-
- if (!S_ISBLK(st.st_mode)) return; /* not a block device */
-
if ((fd = open(device, O_RDWR | O_NONBLOCK)) == -1) {
LOGMSG("set_dvd_speed: error opening DVD device %s for read/write", device);
return;
}
+ if (fstat(fd, &st) < 0 ||
+ !S_ISBLK(st.st_mode)) {
+ close(fd);
+ return; /* not a block device */
+ }
+
memset(&sghdr, 0, sizeof(sghdr));
memset(buffer, 0, sizeof(buffer));
memset(sense, 0, sizeof(sense));
@@ -2528,10 +2546,9 @@ static int handle_control_playfile(vdr_input_plugin_t *this, const char *cmd)
if(sub) *sub = 0;
sprintf(mrl, "%s%s", mrlbase, filename + is_file_mrl);
if(sub) {
+ size_t len = strlen(mrl);
sub += 10; /*strlen("#subtitle:");*/
- strcat(mrl, "#subtitle:");
- strcat(mrl, mrlbase);
- strcat(mrl, sub);
+ snprintf(mrl + len, sizeof(mrl) - len, "#subtitle:%s%s", mrlbase, sub);
}
LOGMSG(" -> trying to stream from server (%s) ...", mrl);
strn0cpy(filename, mrl, sizeof(filename));
@@ -2711,6 +2728,16 @@ static int handle_control_playfile(vdr_input_plugin_t *this, const char *cmd)
* grab
*/
+static void _send_grab_data(vdr_input_plugin_t *this, const grab_data_t *data)
+{
+ char s[128];
+ sprintf(s, "GRAB %d %lu\r\n", this->token, (unsigned long)data->size);
+ mutex_lock_cancellable (&this->fd_control_lock);
+ write_control_data(this, s, strlen(s));
+ write_control_data(this, data->data, data->size);
+ mutex_unlock_cancellable (&this->fd_control_lock);
+}
+
static int handle_control_grab(vdr_input_plugin_t *this, const char *cmd)
{
int quality, width, height, jpeg;
@@ -2732,12 +2759,7 @@ static int handle_control_grab(vdr_input_plugin_t *this, const char *cmd)
data = (grab_data_t*)(this->funcs.fe_control(this->funcs.fe_handle, cmd));
if(data && data->size>0 && data->data) {
- char s[128];
- sprintf(s, "GRAB %d %lu\r\n", this->token, (unsigned long)data->size);
- mutex_lock_cancellable (&this->fd_control_lock);
- write_control_data(this, s, strlen(s));
- write_control_data(this, data->data, data->size);
- mutex_unlock_cancellable (&this->fd_control_lock);
+ _send_grab_data(this, data);
} else {
/* failed */
printf_control(this, "GRAB %d 0\r\n", this->token);
@@ -2814,6 +2836,10 @@ static int handle_osdcmd(vdr_input_plugin_t *this, int fd)
LOGMSG("error reading OSDCMD data length");
return CONTROL_DISCONNECTED;
}
+ if (osdcmd.size < 2) { /* avoid integer overflow when calculating todo */
+ LOGMSG("invalid OSDCMD data length");
+ return CONTROL_DISCONNECTED;
+ }
pt += sizeof(osdcmd.size);
expect -= sizeof(osdcmd.size);
todo = osdcmd.size - sizeof(osdcmd.size);
@@ -4281,13 +4307,15 @@ static buf_element_t *read_socket_udp(vdr_input_plugin_t *this)
/*
* Receive frame from socket and check for errors
*/
-
- struct sockaddr_in server_address;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } server_address;
socklen_t address_len = sizeof(server_address);
ssize_t n = recvfrom(this->fd_data, read_buffer->mem,
read_buffer->max_size, MSG_TRUNC,
- &server_address, &address_len);
+ &server_address.sa, &address_len);
if (n <= 0) {
if (!n || (errno != EINTR && errno != EAGAIN)) {
LOGERR("read_socket_udp(): recvfrom() failed");
@@ -4302,11 +4330,11 @@ static buf_element_t *read_socket_udp(vdr_input_plugin_t *this)
* check source address
*/
- if ((server_address.sin_addr.s_addr !=
+ if ((server_address.in.sin_addr.s_addr !=
udp->server_address.sin_addr.s_addr) ||
- server_address.sin_port != udp->server_address.sin_port) {
+ server_address.in.sin_port != udp->server_address.sin_port) {
#ifdef LOG_UDP
- uint32_t tmp_ip = ntohl(server_address.sin_addr.s_addr);
+ uint32_t tmp_ip = ntohl(server_address.in.sin_addr.s_addr);
LOGUDP("Received data from unknown sender: %d.%d.%d.%d:%d",
((tmp_ip>>24)&0xff), ((tmp_ip>>16)&0xff),
((tmp_ip>>8)&0xff), ((tmp_ip)&0xff),
@@ -5167,14 +5195,18 @@ static void vdr_plugin_dispose (input_plugin_t *this_gen)
if(fc >= 0) {
LOGDBG("Shutdown control");
- setsockopt(fc, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger));
- shutdown(fc, SHUT_RDWR);
+ if (setsockopt(fc, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger)) < 0)
+ LOGDBG("setsockopt(control, SO_LINGER) failed");
+ if (shutdown(fc, SHUT_RDWR) < 0)
+ LOGDBG("shutdown(control) failed");
}
if(fd >= 0 && this->tcp) {
LOGDBG("Shutdown data");
- setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger));
- shutdown(fd, SHUT_RDWR);
+ if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger)) < 0)
+ LOGDBG("setsockopt(data, SO_LINGER) failed");
+ if (shutdown(fd, SHUT_RDWR) < 0)
+ LOGDBG("shutdown(data) failed");
}
}
@@ -5378,17 +5410,21 @@ static void set_recv_buffer_size(int fd, unsigned max_buf)
/*}*/
max_buf = 256;
/* not going to send anything, so shrink send buffer ... */
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(int));
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(int)) < 0)
+ LOGDBG("Shrinking data socket buffer failed");
}
static int alloc_udp_data_socket(int firstport, int trycount, int *port)
{
int fd, one = 1;
- struct sockaddr_in name;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } name;
- name.sin_family = AF_INET;
- name.sin_port = htons(firstport);
- name.sin_addr.s_addr = htonl(INADDR_ANY);
+ name.in.sin_family = AF_INET;
+ name.in.sin_port = htons(firstport);
+ name.in.sin_addr.s_addr = htonl(INADDR_ANY);
fd = socket(PF_INET, SOCK_DGRAM, 0/*IPPROTO_UDP*/);
if (fd < 0) {
@@ -5400,18 +5436,18 @@ static int alloc_udp_data_socket(int firstport, int trycount, int *port)
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int)) < 0)
LOGERR("UDP data stream: setsockopt(SO_REUSEADDR) failed");
- while(bind(fd, (struct sockaddr *)&name, sizeof(name)) < 0) {
+ while (bind(fd, &name.sa, sizeof(name)) < 0) {
if(!--trycount) {
LOGMSG("UDP Data stream: bind error, no free port found");
close(fd);
return -1;
}
LOGERR("UDP Data stream: bind error, port %d: %s",
- name.sin_port, strerror(errno));
- name.sin_port = htons(++firstport);
+ name.in.sin_port, strerror(errno));
+ name.in.sin_port = htons(++firstport);
}
- *port = ntohs(name.sin_port);
+ *port = ntohs(name.in.sin_port);
return fd;
}
@@ -5484,11 +5520,12 @@ static int connect_control_stream(vdr_input_plugin_t *this, const char *host,
}
/* set socket to non-blocking mode */
- fcntl (fd_control, F_SETFL, fcntl (fd_control, F_GETFL) | O_NONBLOCK);
+ io_set_nonblock(fd_control);
/* set control socket to deliver data immediately
instead of waiting for full TCP segments */
- setsockopt(fd_control, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(int));
+ if (setsockopt(fd_control, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(int)) < 0)
+ LOGERR("Failed setting control socket TCP_NODELAY");
this->fd_control = saved_fd;
return fd_control;
@@ -5500,14 +5537,16 @@ static int connect_rtp_data_stream(vdr_input_plugin_t *this)
char cmd[256];
unsigned int ip0, ip1, ip2, ip3, port;
int fd=-1, one = 1, retries = 0;
- struct sockaddr_in multicastAddress;
struct ip_mreq mreq;
- struct sockaddr_in server_address, sin;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } multicastAddress, server_address, sin;
socklen_t len = sizeof(sin);
stream_rtp_header_impl_t tmp_rtp;
/* get server IP address */
- if(getpeername(this->fd_control, (struct sockaddr *)&server_address, &len)) {
+ if (getpeername(this->fd_control, &server_address.sa, &len)) {
LOGERR("getpeername(fd_control) failed");
/* close(fd); */
return -1;
@@ -5537,9 +5576,9 @@ static int connect_rtp_data_stream(vdr_input_plugin_t *this)
LOGMSG("Connecting (data) to rtp://@%u.%u.%u.%u:%u ...",
ip0, ip1, ip2, ip3, port);
- multicastAddress.sin_family = AF_INET;
- multicastAddress.sin_port = htons(port);
- multicastAddress.sin_addr.s_addr = htonl((ip0<<24)|(ip1<<16)|(ip2<<8)|ip3);
+ multicastAddress.in.sin_family = AF_INET;
+ multicastAddress.in.sin_port = htons(port);
+ multicastAddress.in.sin_addr.s_addr = htonl((ip0<<24)|(ip1<<16)|(ip2<<8)|ip3);
if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
LOGERR("socket() failed");
@@ -5553,8 +5592,7 @@ static int connect_rtp_data_stream(vdr_input_plugin_t *this)
return -1;
}
- if(bind(fd, (struct sockaddr *)&multicastAddress,
- sizeof(multicastAddress)) < 0) {
+ if (bind(fd, &multicastAddress.sa, sizeof(multicastAddress)) < 0) {
LOGERR("bind() to multicast address failed");
close(fd);
return -1;
@@ -5563,7 +5601,7 @@ static int connect_rtp_data_stream(vdr_input_plugin_t *this)
/* Join to multicast group */
memset(&mreq, 0, sizeof(mreq));
- mreq.imr_multiaddr.s_addr = multicastAddress.sin_addr.s_addr;
+ mreq.imr_multiaddr.s_addr = multicastAddress.in.sin_addr.s_addr;
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
/*mreq.imr_ifindex = 0;*/
if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) {
@@ -5596,16 +5634,16 @@ retry_recvfrom:
/* check sender address */
- if (recvfrom(fd, &tmp_rtp, sizeof(tmp_rtp), 0, &sin, &len) < 0) {
+ if (recvfrom(fd, &tmp_rtp, sizeof(tmp_rtp), 0, &sin.sa, &len) < 0) {
LOGERR("RTP recvrom() failed");
return -1;
}
- if(sin.sin_addr.s_addr != server_address.sin_addr.s_addr) {
- uint32_t tmp_ip = ntohl(sin.sin_addr.s_addr);
+ if (sin.in.sin_addr.s_addr != server_address.in.sin_addr.s_addr) {
+ uint32_t tmp_ip = ntohl(sin.in.sin_addr.s_addr);
LOGMSG("Received UDP/RTP multicast from unknown sender: %d.%d.%d.%d:%d",
((tmp_ip>>24)&0xff), ((tmp_ip>>16)&0xff),
((tmp_ip>>8)&0xff), ((tmp_ip)&0xff),
- sin.sin_port);
+ sin.in.sin_port);
if(XIO_READY == _x_io_select(this->stream, fd, XIO_READ_READY, 0))
goto retry_recvfrom;
@@ -5630,19 +5668,22 @@ retry_recvfrom:
static int connect_udp_data_stream(vdr_input_plugin_t *this)
{
char cmd[256];
- struct sockaddr_in server_address, sin;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } server_address, sin;
socklen_t len = sizeof(sin);
uint32_t tmp_ip;
stream_udp_header_t tmp_udp;
int retries = 0, port = -1, fd = -1;
/* get server IP address */
- if(getpeername(this->fd_control, (struct sockaddr *)&server_address, &len)) {
+ if (getpeername(this->fd_control, &server_address.sa, &len)) {
LOGERR("getpeername(fd_control) failed");
/* close(fd); */
return -1;
}
- tmp_ip = ntohl(server_address.sin_addr.s_addr);
+ tmp_ip = ntohl(server_address.in.sin_addr.s_addr);
LOGDBG("VDR server address: %d.%d.%d.%d",
((tmp_ip>>24)&0xff), ((tmp_ip>>16)&0xff),
@@ -5690,16 +5731,16 @@ retry_recvfrom:
/* check sender address */
- if (recvfrom(fd, &tmp_udp, sizeof(tmp_udp), 0, &sin, &len) < 0) {
+ if (recvfrom(fd, &tmp_udp, sizeof(tmp_udp), 0, &sin.sa, &len) < 0) {
LOGERR("UDP recvrom() failed");
return -1;
}
- if(sin.sin_addr.s_addr != server_address.sin_addr.s_addr) {
- tmp_ip = ntohl(sin.sin_addr.s_addr);
+ if (sin.in.sin_addr.s_addr != server_address.in.sin_addr.s_addr) {
+ tmp_ip = ntohl(sin.in.sin_addr.s_addr);
LOGMSG("Received UDP packet from unknown sender: %d.%d.%d.%d:%d",
((tmp_ip>>24)&0xff), ((tmp_ip>>16)&0xff),
((tmp_ip>>8)&0xff), ((tmp_ip)&0xff),
- sin.sin_port);
+ sin.in.sin_port);
if(XIO_READY == _x_io_select(this->stream, fd, XIO_READ_READY, 0))
goto retry_recvfrom;
@@ -5719,12 +5760,15 @@ retry_recvfrom:
return fd;
}
-static int connect_tcp_data_stream(vdr_input_plugin_t *this, const char *host,
- int port)
+static int connect_tcp_data_stream(vdr_input_plugin_t *this, const char *host,
+ int port)
{
static const char ackmsg[] = {'D','A','T','A','\r','\n'};
- struct sockaddr_in sinc;
- socklen_t len = sizeof(sinc);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr;
+ socklen_t len = sizeof(addr);
uint32_t ipc;
char tmpbuf[256];
int fd_data;
@@ -5744,13 +5788,17 @@ static int connect_tcp_data_stream(vdr_input_plugin_t *this, const char *host,
/* request data connection */
- getsockname(this->fd_control, (struct sockaddr *)&sinc, &len);
- ipc = ntohl(sinc.sin_addr.s_addr);
+ if (getsockname(this->fd_control, &addr.sa, &len) < 0) {
+ LOGERR("getsockname(fd_control) failed");
+ close(fd_data);
+ return -1;
+ }
+ ipc = ntohl(addr.in.sin_addr.s_addr);
sprintf(tmpbuf,
"DATA %d 0x%x:%u %d.%d.%d.%d\r\n",
this->client_id,
(unsigned int)ipc,
- (unsigned int)ntohs(sinc.sin_port),
+ (unsigned int)ntohs(addr.in.sin_port),
((ipc>>24)&0xff), ((ipc>>16)&0xff), ((ipc>>8)&0xff), ((ipc)&0xff)
);
if(_x_io_tcp_write(this->stream, fd_data, tmpbuf, strlen(tmpbuf)) < 0) {
@@ -5765,7 +5813,7 @@ static int connect_tcp_data_stream(vdr_input_plugin_t *this, const char *host,
} else {
/* succeed */
/* set socket to non-blocking mode */
- fcntl (fd_data, F_SETFL, fcntl (fd_data, F_GETFL) | O_NONBLOCK);
+ io_set_nonblock(fd_data);
return fd_data;
}
@@ -5779,14 +5827,19 @@ static int connect_pipe_data_stream(vdr_input_plugin_t *this)
/* check if IP address matches */
if(!strstr(this->mrl, "127.0.0.1")) {
- struct sockaddr_in sinc;
- struct sockaddr_in sins;
- socklen_t len = sizeof(sinc);
- getsockname(this->fd_control, &sinc, &len);
- getpeername(this->fd_control, &sins, &len);
- if(sinc.sin_addr.s_addr != sins.sin_addr.s_addr) {
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } addr_cli, addr_svr;
+ socklen_t lenc = sizeof(addr_cli);
+ socklen_t lens = sizeof(addr_svr);
+ if (getsockname(this->fd_control, &addr_cli.sa, &lenc) < 0)
+ LOGERR("getsockname(fd_control) failed");
+ else if (getpeername(this->fd_control, &addr_svr.sa, &lens) < 0)
+ LOGERR("getpeername(fd_control) failed");
+ else if (addr_cli.in.sin_addr.s_addr != addr_svr.in.sin_addr.s_addr) {
LOGMSG("connect_pipe_data_stream: client ip=0x%x != server ip=0x%x !",
- (unsigned int)sinc.sin_addr.s_addr, (unsigned int)sins.sin_addr.s_addr);
+ (unsigned int)addr_cli.in.sin_addr.s_addr, (unsigned int)addr_svr.in.sin_addr.s_addr);
#if 0
return -1;
#endif
@@ -5812,7 +5865,7 @@ static int connect_pipe_data_stream(vdr_input_plugin_t *this)
if (_x_io_tcp_write(this->stream, this->fd_control, "PIPE OPEN\r\n", 11) == 11 &&
readline_control(this, tmpbuf, sizeof(tmpbuf)-1, 4) >6 &&
!strncmp(tmpbuf, "PIPE OK", 7)) {
- fcntl (fd_data, F_SETFL, fcntl (fd_data, F_GETFL) | O_NONBLOCK);
+ io_set_nonblock(fd_data);
return fd_data;
}
LOGMSG("Data stream connection failed (PIPE)");
@@ -5834,9 +5887,9 @@ static int vdr_plugin_open_net (input_plugin_t *this_gen)
if(strchr(this->mrl, '#'))
*strchr(this->mrl, '#') = 0;
- if((!strncasecmp(this->mrl, MRL_ID "+tcp://", MRL_ID_LEN+7) && (this->tcp=1)) ||
- (!strncasecmp(this->mrl, MRL_ID "+udp://", MRL_ID_LEN+7) && (this->udp=1)) ||
- (!strncasecmp(this->mrl, MRL_ID "+rtp://", MRL_ID_LEN+7) && (this->rtp=1)) ||
+ if((this->tcp = !strncasecmp(this->mrl, MRL_ID "+tcp://", MRL_ID_LEN+7)) ||
+ (this->udp = !strncasecmp(this->mrl, MRL_ID "+udp://", MRL_ID_LEN+7)) ||
+ (this->rtp = !strncasecmp(this->mrl, MRL_ID "+rtp://", MRL_ID_LEN+7)) ||
(!strncasecmp(this->mrl, MRL_ID "+pipe://", MRL_ID_LEN+8)) ||
(!strncasecmp(this->mrl, MRL_ID "://", MRL_ID_LEN+3))) {
@@ -5861,7 +5914,8 @@ static int vdr_plugin_open_net (input_plugin_t *this_gen)
LOGERR("Can't connect to tcp://%s:%d", host, iport);
return 0;
}
- setsockopt(this->fd_control, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(int));
+ if (setsockopt(this->fd_control, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(int)) < 0)
+ LOGERR("Failed setting TCP_NODELAY for control socket");
LOGMSG("Connected (control) to tcp://%s:%d", host, iport);
diff --git a/xine_post_swscale.c b/xine_post_swscale.c
index de6ecfe..ccc5f8f 100644
--- a/xine_post_swscale.c
+++ b/xine_post_swscale.c
@@ -376,8 +376,8 @@ static void init_tables_yuy2(int newwidth, int newheight, int oldwidth, int oldh
k = j>>8;
wY2 = j - (k << 8); /* luma weight of right pixel */
wY1 = 256 - wY2; /* luma weight of left pixel */
- wUV2 = (k%2) ? 128 + (wY2 >> 1) : wY2 >> 1;
- wUV1 = 256 - wUV2;
+ //wUV2 = (k%2) ? 128 + (wY2 >> 1) : wY2 >> 1;
+ //wUV1 = 256 - wUV2;
if (k > oldwidth - 2) {
hControl[i*3+5] = oldwidth - 1; /* point to last byte */
diff --git a/xine_sxfe_frontend.c b/xine_sxfe_frontend.c
index 8a2f870..db8cb6b 100644
--- a/xine_sxfe_frontend.c
+++ b/xine_sxfe_frontend.c
@@ -884,7 +884,7 @@ static void hud_osd_draw(sxfe_t *this, const struct osd_command_s *cmd)
XDouble scale_x = (XDouble)this->x.width / (XDouble)this->osd_width;
XDouble scale_y = (XDouble)this->x.height / (XDouble)this->osd_height;
- int mask_changed;
+ int mask_changed = 0;
#ifdef HAVE_XSHAPE
Xrender_Surf *dst_surf = this->surf_back_img ? this->surf_back_img : this->surf_win;
@@ -2214,6 +2214,29 @@ static void *opengl_draw_frame_thread(void *arg)
return NULL;
}
+static void _opengl_cleanup(sxfe_t *this)
+{
+ free(this->opengl_osd_texture_img);
+ pthread_cond_destroy(&this->opengl_redraw_cv);
+ pthread_cond_destroy(&this->opengl_redraw_finished_cv);
+ pthread_mutex_destroy(&this->opengl_redraw_mutex);
+ pthread_mutex_destroy(&this->opengl_osd_texture_img_mutex);
+}
+
+static void opengl_stop(sxfe_t *this)
+{
+ if (this->opengl_always || this->opengl_hud) {
+ void *status;
+ this->opengl_deinit = 1;
+ opengl_trigger_drawing_thread(this);
+ if (pthread_join(this->opengl_drawing_thread, &status)) {
+ LOGERR("sxfe_display_close: can not join opengl drawing thread!");
+ }
+
+ _opengl_cleanup(this);
+ }
+}
+
static int opengl_start(sxfe_t *this)
{
LOGDBG("sxfe_display_open: starting opengl drawing thread");
@@ -2250,6 +2273,7 @@ static int opengl_start(sxfe_t *this)
pthread_attr_destroy(&attr);
LOGERR("sxfe_display_open: can not start OpenGL drawing thread");
this->opengl_always = this->opengl_hud = 0; /* avoid pthread_join segfault */
+ _opengl_cleanup(this);
return 0;
}
pthread_attr_destroy(&attr);
@@ -3125,15 +3149,7 @@ static void sxfe_display_close(frontend_t *this_gen)
if(this->display) {
#ifdef HAVE_OPENGL
- if (this->opengl_always || this->opengl_hud) {
- void *status;
- this->opengl_deinit = 1;
- opengl_trigger_drawing_thread(this);
- if (pthread_join(this->opengl_drawing_thread, &status)) {
- LOGERR("sxfe_display_close: can not join opengl drawing thread!");
- }
- free(this->opengl_osd_texture_img);
- }
+ opengl_stop(this);
#endif
#ifdef HAVE_XRENDER