Skip to content

Commit

Permalink
WIP: add VTXv4 file format support
Browse files Browse the repository at this point in the history
VTXv4 is used by the dvbtext tool, which fetches pages from live DVB-{T,S,C} teletext
  • Loading branch information
girst committed Feb 4, 2019
1 parent 5ae6935 commit 40fe1dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ void FileMonitor::run()
// Load the filenames into a list
while ((dirp = readdir(dp)) != NULL)
{
// Select only pages that might be teletext. tti or ttix at the moment.
// Select only pages that might be teletext. .tti, .ttix or .vtx at the moment.
// strcasestr doesn't seem to be in my Windows compiler.
#ifdef _WIN32
char* p=strstr(dirp->d_name,".tti");
if (!p)
p=strstr(dirp->d_name,".vtx");
#else
char* p=strcasestr(dirp->d_name,".tti");
if (!p)
p=strcasestr(dirp->d_name,".vtx");
#endif
// std::cerr << path << "/" << dirp->d_name << std::endl;
if (p)
Expand Down
49 changes: 49 additions & 0 deletions ttxpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ TTXPage::TTXPage(std::string filename) :
m_Init(); // Careful! We should move inits to the initialisation list and call the default constructor
// Try all the possible formats.

m_Loaded |= m_LoadVTXv4(filename);

if (!m_Loaded)
if (m_LoadTTI(filename))
{
Expand Down Expand Up @@ -243,6 +245,53 @@ bool TTXPage::m_LoadVTX(std::string filename)
return true;
}

bool TTXPage::m_LoadVTXv4(std::string filename)
{
// vtxv4 files as produced by dvbtext; see also: https://github.com/girst/ttxd -> src/dvbtext-src/
// NOTE: dvbtext does not encode subpage-numbers. we can only infer them from the filename, which is "PPP_SS.vtx".
char buf[100];
int pageno, subpageno = 0;
TTXPage* p = this;
std::ifstream filein(filename.c_str(), std::ios::binary | std::ios::in);
sscanf(basename(filename.c_str()), "%d_%d.", &pageno, &subpageno);
p->Setm_SubPage(nullptr); //TODO: how does this work?

// read .vtx-header, must start with "VTXV4" (12 bytes)
filein.read(buf,12);
if (buf[0]!='V' || buf[1]!='T' || buf[2]!='X' || buf[3]!='V' || buf[4]!='4')
{
filein.close();
return false;
}
pageno = buf[6]*256 + buf[7];
p->SetPageNumber(pageno*0x100+subpageno);

// read teletext header (8 bytes)
filein.read(buf,8);

// read status bar (32 bytes)
filein.read(buf,32);
for (int i = 0; i < 40; i++) buf[i] = ' ';//TODO: format statusbar correctly (pad where?)
buf[40] = 0;
std::string s(buf);
p->SetRow(0, buf);

// read page content (23*40 bytes)
for (int i=1;i<24;i++)
{
filein.read(buf,40);
for (int i=0; i<40; i++)
buf[i] &= 0x7f; //remove parity bit
buf[40]=0;
std::string s(buf);
p->SetRow(i,s);
}

filein.close();
TTXPage::pageChanged = false;
return true;
}

bool TTXPage::m_LoadEP1(std::string filename)
{
char buf[100];
Expand Down
7 changes: 7 additions & 0 deletions ttxpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ class TTXPage
std::string m_FormatPageNumber(TTXPage* p); /// \return the page number ready to write to file
int findPageNumber(char* buf);
bool m_Loaded;

/** Load a VTXv$ page
* \param filename : The source file
* \return true if the page was loaded
*/
bool m_LoadVTXv4(std::string filename);

/** Load an EP1 page
* \param filename : The source file
* \return true if the page was loaded
Expand Down

0 comments on commit 40fe1dd

Please sign in to comment.