Skip to content

Commit

Permalink
Add on-line CC & Subtitle extraction.
Browse files Browse the repository at this point in the history
Instead of waiting for a recording to finish before outputting the extracted
closed captions or teletext, this writes them out as we go.
  • Loading branch information
daniel-kristjansson committed Nov 18, 2011
1 parent f5a2dc9 commit ff6487b
Show file tree
Hide file tree
Showing 10 changed files with 729 additions and 735 deletions.
77 changes: 43 additions & 34 deletions mythtv/libs/libmythtv/cc608decoder.cpp
Expand Up @@ -656,6 +656,43 @@ void CC608Decoder::ResetCC(int mode)
ccbuf[mode] = "";
}

QString CC608Decoder::ToASCII(const QString &cc608str, bool suppress_unknown)
{
QString ret = "";
int i = 0;

for (int i = 0; i < cc608str.length(); i++)
{
QChar cp = cc608str[i];
int cpu = cp.unicode();
switch (cpu)
{
case 0x2120 : ret += "(SM)"; break;
case 0x2122 : ret += "(TM)"; break;
case 0x2014 : ret += "(--)"; break;
case 0x201C : ret += "``"; break;
case 0x201D : ret += "''"; break;
case 0x250C : ret += "|-"; break;
case 0x2510 : ret += "-|"; break;
case 0x2514 : ret += "|_"; break;
case 0x2518 : ret += "_|"; break;
case 0x2588 : ret += "[]"; break;
case 0x266A : ret += "o/~"; break;
case '\b' : ret += "\\b"; break;
default :
if (cpu >= 0x7000 && cpu < 0x7000 + 0x30)
{
if (!suppress_unknown)
ret += QString("[%1]").arg(cpu - 0x7000, 2, 16);
}
else
ret += QString(cp.toLatin1());
}
}

return ret;
}

void CC608Decoder::BufferCC(int mode, int len, int clr)
{
QByteArray tmpbuf;
Expand Down Expand Up @@ -689,42 +726,14 @@ void CC608Decoder::BufferCC(int mode, int len, int clr)
else
len = sizeof(ccsubtitle);

LOG(VB_VBI, LOG_INFO, QString("### %1 %2 %3 %4 %5 %6 %7 -")
.arg(timecode[mode], 10)
.arg(row[mode], 2).arg(rowcount[mode])
.arg(style[mode]).arg(f, 2, 16)
.arg(clr).arg(len, 3));
if (len && VERBOSE_LEVEL_CHECK(VB_VBI, LOG_INFO))
{
QString dispbuf = QString::fromUtf8(tmpbuf.constData(), len);
LOG(VB_VBI, LOG_INFO, QString("%1 '").arg(timecode[mode], 10));
QString vbuf = "";
int i = 0;
while (i < dispbuf.length()) {
QChar cp = dispbuf.at(i);
int cpu = cp.unicode();
switch (cpu)
{
case 0x2120 : vbuf += "(SM)"; break;
case 0x2122 : vbuf += "(TM)"; break;
case 0x2014 : vbuf += "(--)"; break;
case 0x201C : vbuf += "``"; break;
case 0x201D : vbuf += "''"; break;
case 0x250C : vbuf += "|-"; break;
case 0x2510 : vbuf += "-|"; break;
case 0x2514 : vbuf += "|_"; break;
case 0x2518 : vbuf += "_|"; break;
case 0x2588 : vbuf += "[]"; break;
case 0x266A : vbuf += "o/~"; break;
case '\b' : vbuf += "\\b"; break;
default :
if (cpu >= 0x7000 && cpu < 0x7000 + 0x30)
vbuf += QString("[%1]").arg(cpu - 0x7000, 2, 16);
else vbuf += QString(cp.toLatin1());
}
i++;
}
LOG(VB_VBI, LOG_INFO, vbuf);
LOG(VB_VBI, LOG_INFO, QString("### %1 %2 %3 %4 %5 %6 %7 - '%8'")
.arg(timecode[mode], 10)
.arg(row[mode], 2).arg(rowcount[mode])
.arg(style[mode]).arg(f, 2, 16)
.arg(clr).arg(len, 3)
.arg(ToASCII(QString::fromUtf8(tmpbuf.constData(), len), false)));
}

reader->AddTextData(rbuf, len, timecode[mode], 'C');
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/cc608decoder.h
Expand Up @@ -63,6 +63,8 @@ class CC608Decoder
/// \return Services seen in last few seconds as specified.
void GetServices(uint seconds, bool[4]) const;

static QString ToASCII(const QString &cc608, bool suppress_unknown);

private:
QChar CharCC(int code) const { return stdchar[code]; }
void ResetCC(int mode);
Expand Down
23 changes: 22 additions & 1 deletion mythtv/libs/libmythtv/cc608reader.cpp
Expand Up @@ -60,9 +60,30 @@ CC608Buffer *CC608Reader::GetOutputText(bool &changed, int &streamIdx)
{
streamIdx = -1;

if (!m_enabled || !m_parent)
if (!m_enabled)
return NULL;

if (!m_parent)
{
if (NumInputBuffers())
{
streamIdx = Update(m_inputBuffers[m_writePosition].buffer);
changed = true;

QMutexLocker locker(&m_inputBufLock);
if (m_writePosition != m_readPosition)
m_writePosition = (m_writePosition + 1) % MAXTBUFFER;
}

if (streamIdx >= 0)
{
m_state[streamIdx].m_changed = false;
return &m_state[streamIdx].m_output;
}
else
return &m_state[MAXOUTBUFFERS - 1].m_output;
}

VideoFrame *last = NULL;
if (m_parent->GetVideoOutput())
last = m_parent->GetVideoOutput()->GetLastShownFrame();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/cc708reader.cpp
Expand Up @@ -60,7 +60,7 @@ void CC708Reader::DefineWindow(
int row_lock, int column_lock,
int pen_style, int window_style)
{
if (parent->GetDecoder())
if (parent && parent->GetDecoder())
{
StreamInfo si(-1, 0, 0, service_num, false, false);
parent->GetDecoder()->InsertTrack(kTrackTypeCC708, si);
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythtv/libmythtv.pro
Expand Up @@ -253,6 +253,10 @@ SOURCES += dtvconfparser.cpp dtvconfparserhelpers.cpp
HEADERS += channelscan/scaninfo.h channelscan/channelimporter.h
SOURCES += channelscan/scaninfo.cpp channelscan/channelimporter.cpp

# subtitles: srt
HEADERS += srtwriter.h
SOURCES += srtwriter.cpp

inc.path = $${PREFIX}/include/mythtv/
inc.files = playgroup.h
inc.files += mythtvexp.h metadataimagehelper.h
Expand Down

0 comments on commit ff6487b

Please sign in to comment.