1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Added case-insensitive comparisions and fixed data types of a few CURL options.

This commit is contained in:
Rolf Ahrenberg 2013-02-28 22:07:14 +02:00
parent 980aafb206
commit f632650547
4 changed files with 50 additions and 35 deletions

View File

@ -5,44 +5,45 @@
*
*/
#include <ctype.h>
#include <vdr/tools.h>
#include "common.h"
uint16_t ts_pid(const uint8_t *buf)
uint16_t ts_pid(const uint8_t *bufP)
{
return (uint16_t)(((buf[1] & 0x1f) << 8) + buf[2]);
return (uint16_t)(((bufP[1] & 0x1f) << 8) + bufP[2]);
}
uint8_t payload(const uint8_t *tsp)
uint8_t payload(const uint8_t *bufP)
{
if (!(tsp[3] & 0x10)) // no payload?
if (!(bufP[3] & 0x10)) // no payload?
return 0;
if (tsp[3] & 0x20) { // adaptation field?
if (tsp[4] > 183) // corrupted data?
if (bufP[3] & 0x20) { // adaptation field?
if (bufP[4] > 183) // corrupted data?
return 0;
else
return (uint8_t)((184 - 1) - tsp[4]);
return (uint8_t)((184 - 1) - bufP[4]);
}
return 184;
}
const char *id_pid(const u_short Pid)
const char *id_pid(const u_short pidP)
{
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
if (Pid == section_filter_table[i].pid)
if (pidP == section_filter_table[i].pid)
return section_filter_table[i].tag;
}
return "---";
}
int select_single_desc(int descriptor, const int usecs, const bool selectWrite)
int select_single_desc(int descriptorP, const int usecsP, const bool selectWriteP)
{
// Wait for data
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = usecs;
tv.tv_usec = usecsP;
// Use select
fd_set infd;
fd_set outfd;
@ -50,17 +51,28 @@ int select_single_desc(int descriptor, const int usecs, const bool selectWrite)
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(descriptor, &errfd);
if (selectWrite)
FD_SET(descriptor, &outfd);
FD_SET(descriptorP, &errfd);
if (selectWriteP)
FD_SET(descriptorP, &outfd);
else
FD_SET(descriptor, &infd);
int retval = select(descriptor + 1, &infd, &outfd, &errfd, &tv);
FD_SET(descriptorP, &infd);
int retval = select(descriptorP + 1, &infd, &outfd, &errfd, &tv);
// Check if error
ERROR_IF_RET(retval < 0, "select()", return retval);
return retval;
}
cString ChangeCase(const cString &strP, bool upperP)
{
cString res(strP);
char *p = (char *)*res;
while (p && *p) {
*p = upperP ? toupper(*p) : tolower(*p);
++p;
}
return res;
}
const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE] =
{
/* description tag pid tid mask */
@ -72,4 +84,3 @@ const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE]
{trNOOP("EIT (0x6X)"), "EIT", 0x12, 0x60, 0xF0},
{trNOOP("TDT (0x70)"), "TDT", 0x14, 0x70, 0xFF},
};

View File

@ -66,10 +66,11 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
uint16_t ts_pid(const uint8_t *buf);
uint8_t payload(const uint8_t *tsp);
const char *id_pid(const u_short Pid);
int select_single_desc(int descriptor, const int usecs, const bool selectWrite);
uint16_t ts_pid(const uint8_t *bufP);
uint8_t payload(const uint8_t *bufP);
const char *id_pid(const u_short pidP);
int select_single_desc(int descriptorP, const int usecsP, const bool selectWriteP);
cString ChangeCase(const cString &strP, bool upperP);
struct section_filter_table_type {
const char *description;

View File

@ -279,7 +279,7 @@ bool cIptvProtocolCurl::Connect()
// Request server options
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_perform(handleM);
// Request session description - SDP is delivered in message body and not in the header!
@ -287,7 +287,7 @@ bool cIptvProtocolCurl::Connect()
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, this);
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_DESCRIBE);
iptv_curl_easy_perform(handleM);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, NULL);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, NULL);
@ -297,7 +297,7 @@ bool cIptvProtocolCurl::Connect()
transport = "RTP/AVP/TCP;unicast;interleaved=0-1";
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_TRANSPORT, *transport);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP);
iptv_curl_easy_perform(handleM);
// Start playing
@ -305,13 +305,13 @@ bool cIptvProtocolCurl::Connect()
range = "0.000-";
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RANGE, *range);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
iptv_curl_easy_perform(handleM);
// Start receiving
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEFUNCTION, cIptvProtocolCurl::WriteRtspCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
}
break;
@ -420,12 +420,13 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
int len = 0;
if (ringBufferM) {
// Fill up the buffer
mutexM.Lock();
if (handleM && multiM) {
switch (modeM) {
case eModeRtsp:
{
CURLcode res = CURLE_OK;
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
// @todo - How to detect eof?
}
@ -443,14 +444,12 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
} while (res == CURLM_CALL_MULTI_PERFORM);
// Shall we continue filling up the buffer?
mutexM.Lock();
if (pausedM && (ringBufferM->Free() > ringBufferM->Available())) {
debug("cIptvProtocolCurl::%s(continue): free=%d available=%d", __FUNCTION__,
ringBufferM->Free(), ringBufferM->Available());
pausedM = false;
curl_easy_pause(handleM, CURLPAUSE_CONT);
}
mutexM.Unlock();
// Check if end of file
if (running_handles == 0) {
@ -471,6 +470,7 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
break;
}
}
mutexM.Unlock();
// ... and try to empty it
unsigned char *p = GetData(&bufferLenP);
@ -493,16 +493,18 @@ bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const i
Disconnect();
// Update stream URL
streamUrlM = locationP;
if (startswith(*streamUrlM, "rtsp") || startswith(*streamUrlM, "RTSP"))
cString protocol = ChangeCase(streamUrlM, false).Truncate(5);
if (startswith(*protocol, "rtsp"))
modeM = eModeRtsp;
else if (startswith(*streamUrlM, "https") || startswith(*streamUrlM, "HTTPS"))
modeM = eModeHttp;
else if (startswith(*streamUrlM, "http") || startswith(*streamUrlM, "HTTP"))
else if (startswith(*protocol, "https"))
modeM = eModeHttps;
else if (startswith(*streamUrlM, "file") || startswith(*streamUrlM, "FILE"))
else if (startswith(*protocol, "http"))
modeM = eModeHttp;
else if (startswith(*protocol, "file"))
modeM = eModeFile;
else
modeM = eModeUnknown;
debug("cIptvProtocolCurl::%s(): %s (%d)", __FUNCTION__, *protocol, modeM);
// Update stream parameter
streamParamM = parameterP;
// Reconnect

View File

@ -5,6 +5,7 @@
*
*/
#include <ctype.h>
#include "common.h"
#include "source.h"
@ -70,7 +71,7 @@ bool cIptvTransponderParameters::Parse(const char *strP)
++data;
if (data && (*data == '=')) {
++data;
switch (*token) {
switch (toupper(*token)) {
case 'S':
sidScanM = (int)strtol(data, (char **)NULL, 10);
found_s = true;