Added support for HTTP path and tweaked channel editing.

This commit is contained in:
Rolf Ahrenberg 2007-09-19 17:14:03 +00:00
parent a7bd285fc6
commit 30ced52a0c
4 changed files with 49 additions and 32 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: VDR 1.5.7\n" "Project-Id-Version: VDR 1.5.7\n"
"Report-Msgid-Bugs-To: Rolf Ahrenberg\n" "Report-Msgid-Bugs-To: Rolf Ahrenberg\n"
"POT-Creation-Date: 2007-09-18 21:37+0300\n" "POT-Creation-Date: 2007-09-19 19:49+0300\n"
"PO-Revision-Date: 2007-08-12 23:22+0300\n" "PO-Revision-Date: 2007-08-12 23:22+0300\n"
"Last-Translator: Rolf Ahrenberg\n" "Last-Translator: Rolf Ahrenberg\n"
"Language-Team: <vdr@linuxtv.org>\n" "Language-Team: <vdr@linuxtv.org>\n"
@ -43,26 +43,26 @@ msgstr "Osoite"
msgid "Port" msgid "Port"
msgstr "Portti" msgstr "Portti"
#: setup.c:280 #: setup.c:296
msgid "IPTV Channels" msgid "IPTV Channels"
msgstr "IPTV-kanavat" msgstr "IPTV-kanavat"
#: setup.c:416 #: setup.c:432
msgid "TS buffer size [MB]" msgid "TS buffer size [MB]"
msgstr "TS-puskurin koko [MB]" msgstr "TS-puskurin koko [MB]"
#: setup.c:417 #: setup.c:433
msgid "TS buffer prefill ratio [%]" msgid "TS buffer prefill ratio [%]"
msgstr "TS-puskurin esitäyttöaste [%]" msgstr "TS-puskurin esitäyttöaste [%]"
#: setup.c:418 #: setup.c:434
msgid "UDP buffer size [packets]" msgid "UDP buffer size [packets]"
msgstr "UDP-puskurin koko [pakettia]" msgstr "UDP-puskurin koko [pakettia]"
#: setup.c:419 #: setup.c:435
msgid "HTTP buffer size [packets]" msgid "HTTP buffer size [packets]"
msgstr "HTTP-puskurin koko [pakettia]" msgstr "HTTP-puskurin koko [pakettia]"
#: setup.c:420 #: setup.c:436
msgid "FILE buffer size [packets]" msgid "FILE buffer size [packets]"
msgstr "FILE-puskurin koko [pakettia]" msgstr "FILE-puskurin koko [pakettia]"

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolhttp.c,v 1.2 2007/09/16 13:38:20 rahrenbe Exp $ * $Id: protocolhttp.c,v 1.3 2007/09/19 17:14:03 rahrenbe Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -11,6 +11,7 @@
#include <netdb.h> #include <netdb.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <vdr/device.h> #include <vdr/device.h>
@ -27,6 +28,7 @@ cIptvProtocolHttp::cIptvProtocolHttp()
debug("cIptvProtocolHttp::cIptvProtocolHttp(): readBufferLen=%d (%d)\n", debug("cIptvProtocolHttp::cIptvProtocolHttp(): readBufferLen=%d (%d)\n",
readBufferLen, (readBufferLen / TS_SIZE)); readBufferLen, (readBufferLen / TS_SIZE));
streamAddr = strdup(""); streamAddr = strdup("");
streamPath = strdup("/");
// Allocate receive buffer // Allocate receive buffer
readBuffer = MALLOC(unsigned char, readBufferLen); readBuffer = MALLOC(unsigned char, readBufferLen);
if (!readBuffer) if (!readBuffer)
@ -39,6 +41,7 @@ cIptvProtocolHttp::~cIptvProtocolHttp()
// Close the socket // Close the socket
Close(); Close();
// Free allocated memory // Free allocated memory
free(streamPath);
free(streamAddr); free(streamAddr);
free(readBuffer); free(readBuffer);
} }
@ -106,11 +109,11 @@ bool cIptvProtocolHttp::Connect(void)
{ {
debug("cIptvProtocolHttp::Connect()\n"); debug("cIptvProtocolHttp::Connect()\n");
// Check that stream address is valid // Check that stream address is valid
if (!unicastActive && !isempty(streamAddr)) { if (!unicastActive && !isempty(streamAddr) && !isempty(streamPath)) {
// Ensure that socket is valid // Ensure that socket is valid
OpenSocket(streamPort); OpenSocket(streamPort);
// First try only the IP -address // First try only the IP address
sockAddr.sin_addr.s_addr = inet_addr(streamAddr); sockAddr.sin_addr.s_addr = inet_addr(streamAddr);
if (sockAddr.sin_addr.s_addr == INADDR_NONE) { if (sockAddr.sin_addr.s_addr == INADDR_NONE) {
@ -167,7 +170,7 @@ bool cIptvProtocolHttp::Connect(void)
return false; return false;
} }
// Formulate and send HTTP -request // Formulate and send HTTP request
char buffer[256]; char buffer[256];
memset(buffer, '\0', sizeof(buffer)); memset(buffer, '\0', sizeof(buffer));
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
@ -176,10 +179,9 @@ bool cIptvProtocolHttp::Connect(void)
"User-Agent: vdr-iptv\r\n" "User-Agent: vdr-iptv\r\n"
"Range: bytes=0-\r\n" "Range: bytes=0-\r\n"
"Connection: Close\r\n" "Connection: Close\r\n"
"\r\n", "/", streamAddr); // Hardcoding of file name must go! "\r\n", streamPath, streamAddr);
debug("Sending http -request: %s\n", buffer); //debug("Sending http request: %s\n", buffer);
err = send(socketDesc, buffer, strlen(buffer), 0); err = send(socketDesc, buffer, strlen(buffer), 0);
if (err < 0) { if (err < 0) {
char tmp[64]; char tmp[64];
@ -193,7 +195,6 @@ bool cIptvProtocolHttp::Connect(void)
// Also parsing the reply headers should happen here to see if the // Also parsing the reply headers should happen here to see if the
// connection should be re-located etc. // connection should be re-located etc.
// Update active flag // Update active flag
unicastActive = true; unicastActive = true;
} }
@ -204,16 +205,9 @@ bool cIptvProtocolHttp::Disconnect(void)
{ {
debug("cIptvProtocolHttp::Disconnect()\n"); debug("cIptvProtocolHttp::Disconnect()\n");
// Check that stream address is valid // Check that stream address is valid
if (unicastActive && !isempty(streamAddr)) { if (unicastActive) {
// Ensure that socket is valid // Close the socket
OpenSocket(streamPort); CloseSocket();
int err = close(socketDesc);
if (err < 0) {
char tmp[64];
error("ERROR: close(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return false;
}
// Update active flag // Update active flag
unicastActive = false; unicastActive = false;
} }
@ -262,8 +256,6 @@ bool cIptvProtocolHttp::Close(void)
debug("cIptvProtocolHttp::Close(): streamAddr=%s\n", streamAddr); debug("cIptvProtocolHttp::Close(): streamAddr=%s\n", streamAddr);
// Disconnect the current stream // Disconnect the current stream
Disconnect(); Disconnect();
// Close the socket
CloseSocket();
return true; return true;
} }
@ -273,9 +265,17 @@ bool cIptvProtocolHttp::Set(const char* Address, const int Port)
if (!isempty(Address)) { if (!isempty(Address)) {
// Disconnect the current socket // Disconnect the current socket
Disconnect(); Disconnect();
// Update stream address and port // Update stream address, path and port
streamAddr = strcpyrealloc(streamAddr, Address); streamAddr = strcpyrealloc(streamAddr, Address);
char *path = strstr(streamAddr, "/");
if (path) {
streamPath = strcpyrealloc(streamPath, path);
*path = 0;
}
else
streamPath = strcpyrealloc(streamPath, "/");
streamPort = Port; streamPort = Port;
debug("iptv://%s:%d%s\n", streamAddr, streamPort, streamPath);
// Re-connect the socket // Re-connect the socket
Connect(); Connect();
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolhttp.h,v 1.1 2007/09/16 09:38:01 ajhseppa Exp $ * $Id: protocolhttp.h,v 1.2 2007/09/19 17:14:03 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLHTTP_H #ifndef __IPTV_PROTOCOLHTTP_H
@ -15,6 +15,7 @@
class cIptvProtocolHttp : public cIptvProtocolIf { class cIptvProtocolHttp : public cIptvProtocolIf {
private: private:
char* streamAddr; char* streamAddr;
char* streamPath;
int streamPort; int streamPort;
int socketDesc; int socketDesc;
unsigned char* readBuffer; unsigned char* readBuffer;

22
setup.c
View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: setup.c,v 1.6 2007/09/18 18:48:11 rahrenbe Exp $ * $Id: setup.c,v 1.7 2007/09/19 17:14:03 rahrenbe Exp $
*/ */
#include <string.h> #include <string.h>
@ -132,7 +132,7 @@ void cIptvMenuEditChannel::GetChannelData(cChannel *Channel)
strn0cpy(data.name, "IPTV", sizeof(data.name)); strn0cpy(data.name, "IPTV", sizeof(data.name));
strn0cpy(data.location, "127.0.0.1", sizeof(data.location)); strn0cpy(data.location, "127.0.0.1", sizeof(data.location));
data.protocol = eProtocolUDP; data.protocol = eProtocolUDP;
data.port = 0; data.port = 1234;
} }
} }
@ -225,8 +225,24 @@ eOSState cIptvMenuEditChannel::ProcessKey(eKeys Key)
} }
} }
} }
if ((Key != kNone) && (data.protocol != oldProtocol)) if ((Key != kNone) && (data.protocol != oldProtocol)) {
switch (data.protocol) {
case eProtocolFILE:
strn0cpy(data.location, "/tmp/video.ts", sizeof(data.location));
data.port = 0;
break;
case eProtocolHTTP:
strn0cpy(data.location, "127.0.0.1/TS/1", sizeof(data.location));
data.port = 3000;
break;
default:
case eProtocolUDP:
strn0cpy(data.location, "127.0.0.1", sizeof(data.location));
data.port = 1234;
break;
}
Setup(); Setup();
}
return state; return state;
} }