From bb1ac54c87ea689e6275838c606fa7224adf4169 Mon Sep 17 00:00:00 2001 From: schmirl Date: Wed, 9 May 2007 09:12:42 +0000 Subject: [PATCH] Set DSCP 41 on stream data packets. WMM capable WLAN accesspoints should understand this and give precedence. For Internet streaming it could be used by traffic shapers. Suggested by ollo@vdrportal (#237). Modified Files: server/connectionHTTP.c server/connectionVTP.c tools/socket.c tools/socket.h --- server/connectionHTTP.c | 4 +++- server/connectionVTP.c | 4 +++- tools/socket.c | 14 ++++++++++++++ tools/socket.h | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/server/connectionHTTP.c b/server/connectionHTTP.c index 5f0beef..8bde3aa 100644 --- a/server/connectionHTTP.c +++ b/server/connectionHTTP.c @@ -1,5 +1,5 @@ /* - * $Id: connectionHTTP.c,v 1.11 2007/04/16 11:01:02 schmirl Exp $ + * $Id: connectionHTTP.c,v 1.12 2007/05/09 09:12:42 schmirl Exp $ */ #include @@ -71,6 +71,8 @@ bool cConnectionHTTP::ProcessRequest(void) device->SwitchChannel(m_Channel, false); if (m_LiveStreamer->SetChannel(m_Channel, m_StreamType, m_Apid)) { m_LiveStreamer->SetDevice(device); + if (!SetDSCP()) + LOG_ERROR_STR("unable to set DSCP sockopt"); if (m_StreamType == stES && (m_Apid != 0 || ISRADIO(m_Channel))) { return Respond("HTTP/1.0 200 OK") && Respond("Content-Type: audio/mpeg") diff --git a/server/connectionVTP.c b/server/connectionVTP.c index 1d8a2d8..c847bf3 100644 --- a/server/connectionVTP.c +++ b/server/connectionVTP.c @@ -1,5 +1,5 @@ /* - * $Id: connectionVTP.c,v 1.13 2007/04/26 06:25:13 schmirl Exp $ + * $Id: connectionVTP.c,v 1.14 2007/05/09 09:12:42 schmirl Exp $ */ #include "server/connectionVTP.h" @@ -691,6 +691,8 @@ bool cConnectionVTP::CmdPORT(char *Opts) return Respond(551, "Couldn't open data connection"); } + if (!m_LiveSocket->SetDSCP()) + LOG_ERROR_STR("unable to set DSCP sockopt"); if (m_LiveStreamer) m_LiveStreamer->Start(m_LiveSocket); diff --git a/tools/socket.c b/tools/socket.c index 4b5167d..e9266c5 100644 --- a/tools/socket.c +++ b/tools/socket.c @@ -6,6 +6,15 @@ #include #include +// default class: best effort +#define DSCP_BE 0 +// gold class (video): assured forwarding 4 with lowest drop precedence +#define DSCP_AF41 34 << 2 +// premium class (voip): expedited forwarding +#define DSCP_EF 46 << 2 +// actual DSCP value used +#define STREAMDEV_DSCP DSCP_AF41 + cTBSocket::cTBSocket(int Type) { memset(&m_LocalAddr, 0, sizeof(m_LocalAddr)); memset(&m_RemoteAddr, 0, sizeof(m_RemoteAddr)); @@ -141,3 +150,8 @@ bool cTBSocket::Shutdown(int how) { return ::shutdown(*this, how) != -1; } + +bool cTBSocket::SetDSCP(void) { + int dscp = STREAMDEV_DSCP; + return ::setsockopt(*this, SOL_IP, IP_TOS, &dscp, sizeof(dscp)) != -1; +} diff --git a/tools/socket.h b/tools/socket.h index d1a7d62..23272ec 100644 --- a/tools/socket.h +++ b/tools/socket.h @@ -68,6 +68,9 @@ public: an appropriate value. */ virtual bool Accept(const cTBSocket &Listener); + /* Sets DSCP sockopt */ + bool SetDSCP(void); + /* LocalPort() returns the port number this socket is connected to locally. The result is undefined for a non-open socket. */ int LocalPort(void) const { return ntohs(m_LocalAddr.sin_port); }