2007-10-05 22:01:24 +02:00
|
|
|
/*
|
|
|
|
* common.c: IPTV plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
#include <ctype.h>
|
2007-10-05 22:01:24 +02:00
|
|
|
#include <vdr/tools.h>
|
2007-10-06 02:02:50 +02:00
|
|
|
#include "common.h"
|
2007-10-05 22:01:24 +02:00
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
uint16_t ts_pid(const uint8_t *bufP)
|
2007-10-05 22:01:24 +02:00
|
|
|
{
|
2013-02-28 21:07:14 +01:00
|
|
|
return (uint16_t)(((bufP[1] & 0x1f) << 8) + bufP[2]);
|
2007-10-05 22:01:24 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
uint8_t payload(const uint8_t *bufP)
|
2007-10-05 22:01:24 +02:00
|
|
|
{
|
2013-02-28 21:07:14 +01:00
|
|
|
if (!(bufP[3] & 0x10)) // no payload?
|
2007-10-05 22:01:24 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
if (bufP[3] & 0x20) { // adaptation field?
|
|
|
|
if (bufP[4] > 183) // corrupted data?
|
2007-10-05 22:01:24 +02:00
|
|
|
return 0;
|
|
|
|
else
|
2013-02-28 21:07:14 +01:00
|
|
|
return (uint8_t)((184 - 1) - bufP[4]);
|
2007-10-05 22:01:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 184;
|
|
|
|
}
|
2007-10-06 02:02:50 +02:00
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
const char *id_pid(const u_short pidP)
|
2007-10-10 21:41:10 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
|
2013-02-28 21:07:14 +01:00
|
|
|
if (pidP == section_filter_table[i].pid)
|
2007-10-10 21:41:10 +02:00
|
|
|
return section_filter_table[i].tag;
|
|
|
|
}
|
|
|
|
return "---";
|
|
|
|
}
|
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
int select_single_desc(int descriptorP, const int usecsP, const bool selectWriteP)
|
2007-10-20 22:27:58 +02:00
|
|
|
{
|
|
|
|
// Wait for data
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 0;
|
2013-02-28 21:07:14 +01:00
|
|
|
tv.tv_usec = usecsP;
|
2007-10-20 22:27:58 +02:00
|
|
|
// Use select
|
2013-02-23 01:03:27 +01:00
|
|
|
fd_set infd;
|
|
|
|
fd_set outfd;
|
|
|
|
fd_set errfd;
|
|
|
|
FD_ZERO(&infd);
|
|
|
|
FD_ZERO(&outfd);
|
|
|
|
FD_ZERO(&errfd);
|
2013-02-28 21:07:14 +01:00
|
|
|
FD_SET(descriptorP, &errfd);
|
|
|
|
if (selectWriteP)
|
|
|
|
FD_SET(descriptorP, &outfd);
|
2007-10-20 22:27:58 +02:00
|
|
|
else
|
2013-02-28 21:07:14 +01:00
|
|
|
FD_SET(descriptorP, &infd);
|
|
|
|
int retval = select(descriptorP + 1, &infd, &outfd, &errfd, &tv);
|
2007-10-20 22:27:58 +02:00
|
|
|
// Check if error
|
2007-10-21 01:25:14 +02:00
|
|
|
ERROR_IF_RET(retval < 0, "select()", return retval);
|
2007-10-20 22:27:58 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-02-28 21:07:14 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:02:50 +02:00
|
|
|
const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE] =
|
|
|
|
{
|
2014-04-05 17:29:45 +02:00
|
|
|
/* description tag pid tid mask */
|
|
|
|
{trNOOP("PAT (0x00)"), "PAT", 0x00, 0x00, 0xFF},
|
|
|
|
{trNOOP("NIT (0x40)"), "NIT", 0x10, 0x40, 0xFF},
|
|
|
|
{trNOOP("SDT (0x42)"), "SDT", 0x11, 0x42, 0xFF},
|
|
|
|
{trNOOP("EIT (0x4E/0x4F/0x5X/0x6X)"), "EIT", 0x12, 0x40, 0xC0},
|
|
|
|
{trNOOP("TDT (0x70)"), "TDT", 0x14, 0x70, 0xFF},
|
2007-10-06 02:02:50 +02:00
|
|
|
};
|