Permalink
Browse files

Refactor TeletextDecoder and TeletextScreen and add a new TeletextReader

class.

This follows the approach used in the other subtitle and caption classes
whereby the screen object handles OSD representation of the data, the
reader object holds the state and data and the decoder object feeds new
data into the reader.

This simplifies setup and initialisation of the teletext objects and
removes the requirement to lock the OSD from the decoder, which was
causing endless problems.

The previous behaviour of always decoding teletext packets is also
reinstated which radically improves responsiveness. Actually decoding
and parsing the packets is trivial for a modern processor and hence
should have no impact on performance.

I will backport to release-0-24-fixes in a few days if there are no
reported problems.

Refs #9271


git-svn-id: http://svn.mythtv.org/svn/trunk@27381 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information...
1 parent 255cdf9 commit 9fc9ee1b0d328d840877f42d0d99152bf984e906 Mark Kendall committed Nov 30, 2010
@@ -28,6 +28,7 @@ using namespace std;
#include "dvbdescriptors.h"
#include "cc608decoder.h"
#include "cc708decoder.h"
+#include "teletextdecoder.h"
#include "subtitlereader.h"
#include "interactivetv.h"
#include "DVDRingBuffer.h"
@@ -277,7 +278,8 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
// Closed Caption & Teletext decoders
ccd608(new CC608Decoder(parent->GetCC608Reader())),
ccd708(new CC708Decoder(parent->GetCC708Reader())),
- ttd(new TeletextDecoder(parent)), subReader(parent->GetSubReader()),
+ ttd(new TeletextDecoder(parent->GetTeletextReader())),
+ subReader(parent->GetSubReader()),
// Interactive TV
itv(NULL),
// Audio
@@ -3511,11 +3513,6 @@ int AvFormatDecoder::GetTeletextDecoderType(void) const
return ttd->GetDecoderType();
}
-void AvFormatDecoder::SetTeletextDecoderViewer(TeletextViewer *view)
-{
- ttd->SetViewer(view);
-}
-
QString AvFormatDecoder::GetXDS(const QString &key) const
{
return ccd608->GetXDS(key);
@@ -158,7 +158,6 @@ class AvFormatDecoder : public DecoderBase
virtual int64_t NormalizeVideoTimecode(AVStream *st, int64_t timecode);
virtual int GetTeletextDecoderType(void) const;
- virtual void SetTeletextDecoderViewer(TeletextViewer*);
virtual QString GetXDS(const QString&) const;
@@ -188,7 +188,6 @@ class DecoderBase
inline int NextTrack(uint type);
virtual int GetTeletextDecoderType(void) const { return -1; }
- virtual void SetTeletextDecoderViewer(TeletextViewer*) {;}
virtual QString GetXDS(const QString&) const { return QString::null; }
@@ -197,8 +197,8 @@ HEADERS += datadirect.h
SOURCES += datadirect.cpp
# Teletext stuff
-HEADERS += teletextdecoder.h vbilut.h
-SOURCES += teletextdecoder.cpp vbilut.cpp
+HEADERS += teletextdecoder.h teletextreader.h vbilut.h
+SOURCES += teletextdecoder.cpp teletextreader.cpp vbilut.cpp
# MPEG parsing stuff
HEADERS += mpeg/tspacket.h mpeg/pespacket.h
@@ -210,7 +210,6 @@ MythPlayer::MythPlayer(bool muted)
ttPageNum(0x888),
// Support for captions, teletext, etc. decoded by libav
textDesired(false), enableCaptions(false), disableCaptions(false),
- initTeletext(false),
// CC608/708
db_prefer708(true), cc608(this), cc708(this),
// MHEG/MHI Interactive TV visible in OSD
@@ -617,7 +616,6 @@ void MythPlayer::ReinitOSD(void)
uint old = textDisplayMode;
ToggleCaptions(old);
osd->Reinit(visible, aspect);
- SetupTeletextViewer();
EnableCaptions(old, false);
}
}
@@ -1433,26 +1431,6 @@ bool MythPlayer::ToggleCaptions(uint type)
return textDisplayMode;
}
-void MythPlayer::SetupTeletextViewer(void)
-{
- if (QThread::currentThread() != playerThread)
- {
- initTeletext = true;
- return;
- }
-
- if (osd)
- {
- QMutexLocker locker(&osdLock);
- TeletextViewer* ttview = (TeletextViewer*)osd->InitTeletext();
- if (ttview && decoder)
- {
- initTeletext = false;
- decoder->SetTeletextDecoderViewer(ttview);
- }
- }
-}
-
void MythPlayer::SetCaptionsEnabled(bool enable, bool osd_msg)
{
QMutexLocker locker(&osdLock);
@@ -2050,7 +2028,6 @@ void MythPlayer::VideoStart(void)
videoOutput->GetOSDBounds(total, visible, aspect, scaling, 1.0f);
osd->Init(visible, aspect);
videoOutput->InitOSD(osd);
- SetupTeletextViewer();
osd->EnableSubtitles(kDisplayNone);
#ifdef USING_MHEG
@@ -2543,10 +2520,6 @@ void MythPlayer::EventLoop(void)
if (disableCaptions)
SetCaptionsEnabled(false, false);
- // (re)initialise the teletext viewer
- if (initTeletext)
- SetupTeletextViewer();
-
// refresh the position map for an in-progress recording while editing
if (hasFullPositionMap && watchingrecording && player_ctx->recorder &&
player_ctx->recorder->IsValidRecorder() && deleteMap.IsEditing())
@@ -15,7 +15,7 @@
#include "osd.h"
#include "jitterometer.h"
#include "videooutbase.h"
-#include "teletextdecoder.h"
+#include "teletextreader.h"
#include "subtitlereader.h"
#include "tv_play.h"
#include "yuv2rgb.h"
@@ -254,11 +254,11 @@ class MPUBLIC MythPlayer
virtual bool PrepareAudioSample(int64_t &timecode);
// Public Closed caption and teletext stuff
- void SetupTeletextViewer(void);
uint GetCaptionMode(void) const { return textDisplayMode; }
CC708Reader* GetCC708Reader(void) { return &cc708; }
CC608Reader* GetCC608Reader(void) { return &cc608; }
SubtitleReader* GetSubReader(void) { return &subReader; }
+ TeletextReader* GetTeletextReader(void) { return &ttxReader; }
// Public Audio/Subtitle/EIA-608/EIA-708 stream selection - thread safe
void TracksChanged(uint trackType);
@@ -634,12 +634,12 @@ class MPUBLIC MythPlayer
// Support for captions, teletext, etc. decoded by libav
SubtitleReader subReader;
+ TeletextReader ttxReader;
/// This allows us to enable captions/subtitles later if the streams
/// are not immediately available when the video starts playing.
bool textDesired;
bool enableCaptions;
bool disableCaptions;
- bool initTeletext;
// CC608/708
bool db_prefer708;
@@ -31,14 +31,10 @@ using namespace std;
#include "osd.h"
#include "teletextdecoder.h"
+#include "teletextreader.h"
#include "vbilut.h"
-#include "mythplayer.h"
#include "mythverbose.h"
-/******************************************************************/
-//Decoder section
-//
-
/** \fn TeletextDecoder::Decode(const unsigned char*, int)
* \brief Decodes teletext data
*
@@ -50,36 +46,8 @@ void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
int err = 0, latin1 = -1, zahl1, pagenum, subpagenum, lang, flags;
uint magazine, packet, header;
- if (!m_player)
- return;
-
- int mode = m_player->GetCaptionMode();
- if (!((mode == kDisplayNUVTeletextCaptions) ||
- (mode == kDisplayTeletextCaptions) ||
- (mode == kDisplayTeletextMenu)))
- {
- return;
- }
-
- if (!m_player->TryLockOSD())
- {
- VERBOSE(VB_PLAYBACK, "TeletextDecoder: Failed to get OSD lock.");
- return;
- }
-
- if (!m_teletextviewer && m_player)
- {
- m_player->UnlockOSD();
- m_player->SetupTeletextViewer();
- return;
- }
-
- if (!m_teletextviewer)
- {
- VERBOSE(VB_VBI, "TeletextDecoder: No Teletext Viewer defined!");
- m_player->UnlockOSD();
+ if (!m_teletext_reader)
return;
- }
m_decodertype = vbimode;
@@ -89,10 +57,7 @@ void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
header = hamm16(buf, &err);
if (err & 0xf000)
- {
- m_player->UnlockOSD();
return; // error in data header
- }
magazine = header & 7;
packet = (header >> 3) & 0x1f;
@@ -125,16 +90,12 @@ void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
packet += 16;
if (err == 1)
- {
- m_player->UnlockOSD();
return; // error in data header
- }
buf += 2;
break;
default:
- m_player->UnlockOSD();
return; // error in vbimode
}
@@ -150,10 +111,7 @@ void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
b3 = hamm16(buf+4, &err);// subpage number + flags
b4 = hamm16(buf+6, &err);// language code + more flags
if (err & 0xf000)
- {
- m_player->UnlockOSD();
return;
- }
break;
@@ -164,38 +122,29 @@ void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
b3 = hamm84(buf+5, &err)*16+hamm84(buf+4, &err);
b4 = hamm84(buf+7, &err)*16+hamm84(buf+6, &err);
if (err == 1)
- {
- m_player->UnlockOSD();
return;
- }
break;
default:
- m_player->UnlockOSD();
return; // error in vbimode
}
- //VERBOSE(VB_VBI, QString("Page Header found: "
- // "Magazine %1, Page Number %2")
- // .arg(magazine).arg(b1));
-
subpagenum= (b2 + b3 * 256) & 0x3f7f;
pagenum = (magazine?:8)*256 + b1;
lang = "\0\4\2\6\1\5\3\7"[b4 >> 5] + (latin1 ? 0 : 8);
flags = b4 & 0x1F;
flags |= b3 & 0xC0;
flags |= (b2 & 0x80) >> 2;
- m_teletextviewer->AddPageHeader(pagenum, subpagenum, buf,
- vbimode, lang, flags);
+ m_teletext_reader->AddPageHeader(pagenum, subpagenum, buf,
+ vbimode, lang, flags);
break;
default: // Page Data
- m_teletextviewer->AddTeletextData((magazine?:8), packet,
- buf, vbimode);
+ m_teletext_reader->AddTeletextData((magazine?:8), packet,
+ buf, vbimode);
break;
}
- m_player->UnlockOSD();
}
@@ -3,52 +3,20 @@
#include <stdint.h>
-class TeletextViewer
-{
- public:
- TeletextViewer() { }
- virtual ~TeletextViewer() { }
-
- virtual void KeyPress(uint key) { (void) key; }
- virtual void SetPage(int page, int subpage) { (void) page; (void) subpage; }
- virtual void SetDisplaying(bool displaying) { (void) displaying; }
-
- virtual void Reset(void) = 0;
- virtual void AddPageHeader(int page, int subpage,
- const uint8_t *buf, int vbimode,
- int lang, int flags) = 0;
- virtual void AddTeletextData(int magazine, int row,
- const uint8_t* buf, int vbimode) = 0;
-};
-
-class MythPlayer;
+class TeletextReader;
class TeletextDecoder
{
public:
- TeletextDecoder(MythPlayer *player)
- : m_player(player), m_teletextviewer(NULL), m_decodertype(-1) {}
+ TeletextDecoder(TeletextReader *reader)
+ : m_teletext_reader(reader), m_decodertype(-1) {}
virtual ~TeletextDecoder() {}
- /// Sets the TeletextViewer which will get the text from this decoder.
- void SetViewer(TeletextViewer *viewer)
- { m_teletextviewer = viewer; }
-
- /**
- * \brief Returns the actual decoder type (DVB,IVTV,DVB_SUBTITLE...)
- *
- * This is used for the decision in NuppelVideoPlayer
- * to this TeletextDecoder or the caption only decoder.
- */
- int GetDecoderType(void) const
- { return m_decodertype; }
-
+ int GetDecoderType(void) const { return m_decodertype; }
void Decode(const unsigned char *buf, int vbimode);
private:
-
- MythPlayer *m_player;
- TeletextViewer *m_teletextviewer;
+ TeletextReader *m_teletext_reader;
int m_decodertype;
};
Oops, something went wrong.

0 comments on commit 9fc9ee1

Please sign in to comment.