((h24 & 0x7f0000) >> 5);
}
+static int extractPTS(pts_t &pts, unsigned char *pkt)
+{
+ pkt += 7;
+ int flags = *pkt++;
+
+ pkt++; // header length
+
+ if (flags & 0x80) /* PTS present? */
+ {
+ /* damn gcc bug */
+ pts = ((unsigned long long)(((pkt[0] >> 1) & 7))) << 30;
+ pts |= pkt[1] << 22;
+ pts |= (pkt[2]>>1) << 15;
+ pts |= pkt[3] << 7;
+ pts |= (pkt[5]>>1);
+
+ return 0;
+ } else
+ return -1;
+}
+
eDVBTeletextParser::eDVBTeletextParser(iDVBDemux *demux)
{
setStreamID(0xBD); /* as per en 300 472 */
- setPage(0x150);
+ setPage(-1);
if (demux->createPESReader(eApp, m_pes_reader))
eDebug("failed to create PES reader!");
{
unsigned char *p = pkt;
+ pts_t pts;
+ int have_pts = extractPTS(pts, pkt);
+
p += 4; len -= 4; /* start code, already be verified by pes parser */
p += 2; len -= 2; /* length, better use the argument */
if (data_unit_length != 44)
{
- eDebug("illegal data unit length %d", data_unit_length);
+ /* eDebug("illegal data unit length %d", data_unit_length); */
break;
}
m_M = magazine_and_packet_address & 7;
m_Y = magazine_and_packet_address >> 3;
-// eDebug("line %d, framing code: %02x, M=%02x, Y=%02x", line_offset, framing_code, M, Y);
+
+// eDebug("line %d, framing code: %02x, M=%02x, Y=%02x", line_offset, framing_code, m_M, m_Y);
if (m_Y == 0) /* page header */
{
m_C |= decode_hamming_84(data + 6) << 7;
m_C |= decode_hamming_84(data + 7) << 11;
+ int serial_mode = m_C & (1<<11);
+
/* page on the same magazine? end current page. */
- if ((m_M == m_page_M) && (m_page_open))
+ if ((serial_mode || (m_M == m_page_M)) && (m_page_open))
{
- handlePageEnd();
+ handlePageEnd(have_pts, pts);
m_page_open = 0;
}
m_X = decode_hamming_84(data+1) * 0x10 + decode_hamming_84(data);
+ if ((m_C & (1<<6)) && (m_X != 0xFF)) /* scan for pages with subtitle bit set */
+ m_found_subtitle_pages.insert((m_M << 8) | m_X);
+
/* correct page on correct magazine? open page. */
if ((m_M == m_page_M) && (m_X == m_page_X))
{
void eDVBTeletextParser::handleLine(unsigned char *data, int len)
{
+/* // hexdump
+ for (int i=0; i<len; ++i)
+ eDebugNoNewLine("%02x ", decode_odd_parity(data + i));
+ eDebug(""); */
if (!m_Y) /* first line is page header, we don't need that. */
+ {
+ m_double_height = -1;
return;
+ }
+
+ if (m_double_height == m_Y)
+ {
+ m_double_height = -1;
+ return;
+ }
- int last_was_white = 1, color = -1;
+ int last_was_white = 1, color = 7; /* start with whitespace. start with color=white. (that's unrelated.) */
std::string text;
+// eDebug("handle subtitle line: %d len", len);
for (int i=0; i<len; ++i)
{
unsigned char b = decode_odd_parity(data + i);
{
if (b != color) /* new color is split into a new string */
{
- if (color != -1)
- addSubtitleString(color, text);
+ addSubtitleString(color, text);
text = "";
color = b;
}
- }
+ } else if (b == 0xd)
+ {
+ m_double_height = m_Y + 1;
+ } else if (b != 0xa && b != 0xb) /* box */
+ eDebug("[ignore %x]", b);
/* ignore other attributes */
} else
{
+ eDebugNoNewLine("%c", b);
/* no more than one whitespace, only printable chars */
if (((!last_was_white) || (b != ' ')) && (b >= 0x20))
{
}
}
}
+ eDebug("");
addSubtitleString(color, text);
}
-void eDVBTeletextParser::handlePageEnd()
+void eDVBTeletextParser::handlePageEnd(int have_pts, const pts_t &pts)
{
- addSubtitleString(-1, ""); /* end last line */
+// eDebug("handle page end");
+ addSubtitleString(-2, ""); /* end last line */
+
+ m_subtitle_page.m_have_pts = have_pts;
+ m_subtitle_page.m_pts = pts;
+ m_subtitle_page.m_timeout = 90000 * 20; /* 20s */
sendSubtitlePage(); /* send assembled subtitle page to display */
}
connection = new eConnection(this, m_new_subtitle_page.connect(slot));
}
-void eDVBTeletextParser::addSubtitleString(int color, const std::string &string)
+void eDVBTeletextParser::addSubtitleString(int color, std::string string)
{
+// eDebug("add subtitle string: %s, col %d", string.c_str(), color);
+
+ int force_cell = 0;
+
+ if (string.substr(0, 2) == "- ")
+ {
+ string = string.substr(2);
+ force_cell = 1;
+ }
+
+// eDebug("color %d, m_subtitle_color %d", color, m_subtitle_color);
gRGB rgbcol((color & 1) ? 255 : 128, (color & 2) ? 255 : 128, (color & 4) ? 255 : 128);
- if ((color != m_subtitle_color) && !m_subtitle_text.empty())
+ if ((color != m_subtitle_color || force_cell) && !m_subtitle_text.empty() && ((color == -2) || !string.empty()))
{
+// eDebug("add text |%s|: %d != %d || %d", m_subtitle_text.c_str(), color, m_subtitle_color, force_cell);
m_subtitle_page.m_elements.push_back(eDVBTeletextSubtitlePageElement(rgbcol, m_subtitle_text));
m_subtitle_text = "";
} else if (!m_subtitle_text.empty() && m_subtitle_text[m_subtitle_text.size()-1] != ' ')
m_subtitle_text += " ";
- m_subtitle_color = color;
- m_subtitle_text += string;
+ if (!string.empty())
+ {
+// eDebug("set %d as new color", color);
+ m_subtitle_color = color;
+ m_subtitle_text += string;
+ }
}
void eDVBTeletextParser::sendSubtitlePage()
{
- eDebug("subtitle page:");
+// eDebug("subtitle page:");
for (unsigned int i = 0; i < m_subtitle_page.m_elements.size(); ++i)
eDebug("%s", m_subtitle_page.m_elements[i].m_text.c_str());
m_new_subtitle_page(m_subtitle_page);