summaryrefslogtreecommitdiff
path: root/reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'reader.c')
-rw-r--r--reader.c75
1 files changed, 64 insertions, 11 deletions
diff --git a/reader.c b/reader.c
index 4162453..e1a6d9c 100644
--- a/reader.c
+++ b/reader.c
@@ -37,7 +37,7 @@ const unsigned char kPAT[TS_SIZE] = {
0xff, 0xff, 0xff, 0xff
};
-const unsigned char kPMT[TS_SIZE] = {
+const unsigned char kPMTwithTeletext[TS_SIZE] = {
0x47, 0x40, 0x84, 0x10, 0x00, 0x02, 0xb0, 0x24,
0x00, 0x01, 0xc1, 0x00, 0x00, 0xe0, 0x65, 0xf0,
0x00, 0x02, 0xe1, 0x2d, 0xf0, 0x00, 0x04, 0xe1,
@@ -64,6 +64,33 @@ const unsigned char kPMT[TS_SIZE] = {
0xff, 0xff, 0xff, 0xff
};
+const unsigned char kPMTwithoutTeletext[TS_SIZE] = {
+ 0x47, 0x40, 0x84, 0x10, 0x00, 0x02, 0xb0, 0x1d,
+ 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe0, 0x65, 0xf0,
+ 0x00, 0x02, 0xe1, 0x2d, 0xf0, 0x00, 0x04, 0xe1,
+ 0x2c, 0xf0, 0x06, 0x0a, 0x04, 0x00, 0x00, 0x00,
+ 0x01, 0xcc, 0x32, 0xcc, 0x32, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff
+};
+
const unsigned char kPMTRadio[TS_SIZE] = {
0x47, 0x40, 0x84, 0x10, 0x00, 0x02, 0xb0, 0x18,
0x00, 0x01, 0xc1, 0x00, 0x00, 0xe0, 0x65, 0xf0,
@@ -126,6 +153,35 @@ const unsigned char kInvTab[256] = {
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
};
+static bool GetPMT(unsigned char *PMT, int Sid, bool WithTeletext, bool IncreaseVersion)
+{
+ uint8_t cont_counter = 0;
+ uint8_t next_version = 0;
+ if (IncreaseVersion) {
+ cont_counter = PMT[3] & 0x0f;
+ next_version = (PMT[10] + 2) | 0xc1;
+ }
+ int crc_offset = 0;
+ if (WithTeletext) {
+ memcpy( PMT, kPMTwithTeletext, TS_SIZE);
+ crc_offset = 40;
+ }
+ else {
+ memcpy( PMT, kPMTwithoutTeletext, TS_SIZE);
+ crc_offset = 33;
+ }
+ PMT[3] = (PMT[3] & 0xf0) | cont_counter;
+ PMT[8] = (Sid >> 8) & 0xFF;
+ PMT[9] = Sid & 0xFF;
+ PMT[10] = next_version;
+ int crc = SI::CRC32::crc32((const char *)(PMT + 5), crc_offset - 5, 0xFFFFFFFF);
+ PMT[crc_offset] = crc >> 24;
+ PMT[crc_offset + 1] = crc >> 16;
+ PMT[crc_offset + 2] = crc >> 8;
+ PMT[crc_offset + 3] = crc;
+ return WithTeletext;
+}
+
cPvrReadThread::cPvrReadThread(cRingBufferLinear *TsBuffer, cPvrDevice *_parent)
: tsBuffer(TsBuffer),
video_counter(0),
@@ -188,6 +244,11 @@ void cPvrReadThread::PesToTs(uint8_t *Data, uint32_t Length)
uint32_t Payload_Rest = Length % PayloadSize;
stream_id = Data[3];
+ if ((stream_id == 0xBD) && !pmt_has_teletext) {
+ pmt_has_teletext = GetPMT(pmt_buffer, parent->CurrentChannel.Sid(), true, true);
+ packet_counter = 0;
+ }
+
if (packet_counter <= 0) { // time to send PAT and PMT
// increase continuity counter
pat_buffer[ 3] = (pat_buffer[ 3] & 0xF0) | (((pat_buffer[ 3] & 0x0F) + 1) & 0x0F);
@@ -494,16 +555,8 @@ void cPvrReadThread::Action(void)
pmt_buffer[30] = crc >> 8;
pmt_buffer[31] = crc;
}
- else {
- memcpy(pmt_buffer, kPMT, TS_SIZE);
- pmt_buffer[8] = (sid >> 8) & 0xFF;
- pmt_buffer[9] = sid & 0xFF;
- crc = SI::CRC32::crc32((const char *)(pmt_buffer + 5), 35, 0xFFFFFFFF);
- pmt_buffer[40] = crc >> 24;
- pmt_buffer[41] = crc >> 16;
- pmt_buffer[42] = crc >> 8;
- pmt_buffer[43] = crc;
- }
+ else
+ pmt_has_teletext = GetPMT(pmt_buffer, sid, false, false);
}
retry:
while (Running() && parent->readThreadRunning) {