1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/*
* ttxtsubs.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: ttxtsubs.c,v 1.20 2003/07/19 02:03:15 ragge Exp ragge $
*/
#include <vdr/plugin.h>
#include <vdr/status.h>
#include <vdr/vdrttxtsubshooks.h>
#include <vdr/menuitems.h>
#include <vdr/config.h>
#include "ttxtsubsdisplayer.h"
#include "ttxtsubsrecorder.h"
#include "utils.h"
#include "siinfo.h"
#include "ttxtsubs.h"
static const char *VERSION = "0.0.4b";
static const char *DESCRIPTION = "Teletext subtitles";
//static const char *MAINMENUENTRY = "Ttxtsubs";
// ISO 639-2 language codes in VDR order
// XXX should be replaced by something that allows for other languages and for real language names!
// <http://www.loc.gov/standards/iso639-2/englangn_ascii.html>
char *gLanguages[] =
{ "eng", //English
"deu", //Deutsch
"slv", //Slovenian
"ita", //Italian
"dut", //"nld"? Dutch
"por", //Portuguese
"fre", //"fra"? French
"nor", //Norwegian
"fin", //Finnish
"pol", //Polish
"spa", //Spanish
"gre", //Greek
"swe", //"sve? Swedish
"rom", //Romanian
"hun", //Hungarian
"cat", //Catalanian
// Not in translations!
"dan" //Danish
};
int gNumLanguages = sizeof(gLanguages) / sizeof(gLanguages[0]);
class cPluginTtxtsubs : public cPlugin, public cStatus, public cVDRTtxtsubsHookListener {
public:
cPluginTtxtsubs(void);
virtual ~cPluginTtxtsubs();
// -- cPlugin
virtual const char *Version(void) { return VERSION; }
virtual const char *Description(void) { return DESCRIPTION; }
virtual const char *CommandLineHelp(void);
virtual bool ProcessArgs(int argc, char *argv[]);
virtual bool Start(void);
virtual void Housekeeping(void);
//virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *Name, const char *Value);
// -- Setup stuff
virtual char *Language(void) { return mLanguage; };
virtual int HearingImpaired(void) { return mHearingImpaired; };
virtual int Record(void) { return mRecord; };
virtual void SetLanguage(char *lang) { strncpy(mLanguage, lang, 4); mLanguage[3] = '\0'; };
virtual void SetHearingImpaired(int hi) { mHearingImpaired = hi; };
virtual void SetRecord(int record) { mRecord = record; };
// -- cStatus
protected:
virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber);
virtual void Replaying(const cControl *Control, const char *Name);
// The given player control has started replaying Name. Name is the name of the
// recording, without any directory path. In case of a player that can't provide
// a name, Name can be a string that identifies the player type (like, e.g., "DVD").
// If Name is NULL, the replay has ended.
// virtual void OsdClear(void) { ShowTtxt(); }
// virtual void OsdTitle(const char *Title) { HideTtxt(); }
// virtual void OsdStatusMessage(const char *Message) { HideTtxt(); }
// virtual void OsdHelpKeys(const char *Red, const char *Green, const char *Yellow, const char *Blue) { HideTtxt(); }
// virtual void OsdCurrentItem(const char *Text) { HideTtxt(); }
// virtual void OsdTextItem(const char *Text, bool Scroll) { HideTtxt(); }
// virtual void OsdChannel(const char *Text) { HideTtxt(); }
// virtual void OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle) { HideTtxt(); }
// -- cVDRTtxtsubsHookListener
virtual void HideOSD(void) { HideTtxt(); }
virtual void ShowOSD(void) { ShowTtxt(); }
virtual void PlayerTeletextData(uint8_t *p, int length);
virtual cTtxtSubsRecorderBase *NewTtxtSubsRecorder(cDevice *dev, const cChannel *ch);
// -- internal
private:
void StartTtxtLive(const cDevice *Device, int pid, int page);
void StartTtxtPlay(int page);
void StopTtxt(void);
void ShowTtxt(void);
void HideTtxt(void);
private:
// Add any member variables or functions you may need here.
cTtxtSubsDisplayer *mRec;
// Setup items
char mLanguage[4];
int mHearingImpaired;
int mRecord;
// ugly hack for now
int mPage;
};
class cMenuSetupTtxtsubs : public cMenuSetupPage {
public:
cMenuSetupTtxtsubs(cPluginTtxtsubs *ttxtsubs);
protected:
virtual void Store(void);
private:
cPluginTtxtsubs *mTtxtsubs;
char mLanguage[4];
int mLanguageNo;
int mHearingImpaired;
int mRecord;
};
cPluginTtxtsubs::cPluginTtxtsubs(void)
:
mRec(NULL),
mHearingImpaired(0),
mRecord(1),
mPage(0x199)
{
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
strncpy(mLanguage, "unk", 4);
}
cPluginTtxtsubs::~cPluginTtxtsubs()
{
// Clean up after yourself!
}
const char *cPluginTtxtsubs::CommandLineHelp(void)
{
// Return a string that describes all known command line options.
return NULL;
}
bool cPluginTtxtsubs::ProcessArgs(int argc, char *argv[])
{
// Implement command line argument processing here if applicable.
return true;
}
bool cPluginTtxtsubs::Start(void)
{
// Start any background activities the plugin shall perform.
if(!memcmp(mLanguage, "unk", 3)) {
int n = Setup.OSDLanguage;
if(n > gNumLanguages) {
strncpy(mLanguage, "eng", 4);
} else {
strncpy(mLanguage, gLanguages[n], 4);
mLanguage[3] = '\0';
}
}
//dprint("cPluginTtxtsubs::Start\n");
HookAttach();
return true;
}
void cPluginTtxtsubs::Housekeeping(void)
{
// Perform any cleanup or other regular tasks.
}
cOsdObject *cPluginTtxtsubs::MainMenuAction(void)
{
// Perform the action when selected from the main VDR menu.
return NULL;
}
cMenuSetupPage *cPluginTtxtsubs::SetupMenu(void)
{
return new cMenuSetupTtxtsubs(this);
}
bool cPluginTtxtsubs::SetupParse(const char *Name, const char *Value)
{
if(!strcasecmp(Name, "Language")) { strncpy(mLanguage, Value, 4); mLanguage[3] = '\0'; }
else if(!strcasecmp(Name, "HearingImpaired")) mHearingImpaired = atoi(Value);
else if(!strcasecmp(Name, "Record")) mRecord = atoi(Value);
else
return false;
return true;
}
void cPluginTtxtsubs::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
if(Device->IsPrimaryDevice()) {
if(ChannelNumber) {
cChannel *c = Channels.GetByNumber(ChannelNumber);
if(c) {
struct ttxtinfo info;
int pid, page;
if(GetTtxtInfo(Device->ActualDevice()->CardIndex(), ChannelNumber, c->Sid(), c->Vpid(), &info)) {
fprintf(stderr, "ttxtsubs: Error: GetTtxtInfo failed!\n");
} else {
if(FindSubs(&info, mLanguage, mHearingImpaired, &pid, &page)) {
//fprintf(stderr, "CHANNELSWITCH, pid: %d page: %x\n", pid, page);
mPage = page; // XXX remember this for playback (temporary hack)!
StartTtxtLive(Device, pid, page);
}
FreeTtxtInfoData(&info);
}
}
} else
StopTtxt();
}
}
void cPluginTtxtsubs::Replaying(const cControl *Control, const char *Name)
{
StopTtxt();
StartTtxtPlay(mPage);
// XXX this page number is just a fallback for old recordings which
// don't have a index page
}
void cPluginTtxtsubs::PlayerTeletextData(uint8_t *p, int length)
{
cTtxtSubsPlayer *r = dynamic_cast<cTtxtSubsPlayer *>(mRec);
if(!r) {
fprintf(stderr, "ttxtsubs: ERROR: not a cTtxtSubsPlayer!\n");
return;
}
r->PES_data(p, length);
}
cTtxtSubsRecorderBase *cPluginTtxtsubs::NewTtxtSubsRecorder(cDevice *dev, const cChannel *ch)
{
if(mRecord)
return new cTtxtSubsRecorder(dev, ch, mLanguage, mHearingImpaired);
else
return NULL;
}
// -- internal
void cPluginTtxtsubs::StartTtxtLive(const cDevice *Device, int pid, int page)
{
//dprint("cPluginTtxtsubs::StartTtxtLive\n");
#if 0
return; // XXX TEST - No live subs
#endif
if(!mRec) {
cTtxtSubsLiveReceiver *r;
//dprint("teletext subtitles started on pid %d\n", pid);
mRec = r = new cTtxtSubsLiveReceiver(pid, page);
if(!cDevice::PrimaryDevice()->ActualDevice()->AttachReceiver(r))
fprintf(stderr, "ttxtsubs: Error: AttachReceiver failed!\n"); //
} else
fprintf(stderr, "ttxtsubs: Error: StartTtxtLive called when already started!\n");
}
void cPluginTtxtsubs::StartTtxtPlay(int backup_page)
{
dprint("cPluginTtxtsubs::StartTtxtPlay\n");
if(!mRec) {
dprint("ttxtsubs: teletext subtitles replayer started with initial page %03x\n", backup_page);
mRec = new cTtxtSubsPlayer(mLanguage, mHearingImpaired, backup_page);
} else
fprintf(stderr, "ttxtsubs: Error: StartTtxtPlay called when already started!\n");
}
void cPluginTtxtsubs::StopTtxt(void)
{
dprint("cPluginTtxtsubs::StopTtxt\n");
if(mRec) {
HideTtxt();
delete mRec;
mRec = NULL;
}
}
void cPluginTtxtsubs::ShowTtxt(void)
{
if(mRec)
mRec->ShowDisplay();
}
void cPluginTtxtsubs::HideTtxt(void)
{
if(mRec)
mRec->HideDisplay();
}
// ----- cMenuSetupTtxtsubs -----
cMenuSetupTtxtsubs::cMenuSetupTtxtsubs(cPluginTtxtsubs *ttxtsubs)
:
mTtxtsubs(ttxtsubs),
mLanguageNo(-1),
mHearingImpaired(mTtxtsubs->HearingImpaired()),
mRecord(mTtxtsubs->Record())
{
memcpy(mLanguage, ttxtsubs->Language(), 3);
mLanguage[3] = '\0';
for(int i = 0; i < gNumLanguages; i++) {
if(!memcmp(mLanguage, gLanguages[i], 3)) {
mLanguageNo = i;
break;
}
}
if(mLanguageNo >= 0)
Add(new cMenuEditStraItem(tr("Language"), &mLanguageNo, gNumLanguages, gLanguages));
else
Add(new cMenuEditStrItem(tr("Language"), mLanguage, 4, "abcdefghijklmnopqrstuvwxyz"));
Add(new cMenuEditBoolItem(tr("Hearing Impaired"), &mHearingImpaired, tr("no"), tr("yes")));
Add(new cMenuEditBoolItem(tr("Record Subtitles"), &mRecord, tr("no"), tr("yes")));
}
void cMenuSetupTtxtsubs::Store(void)
{
if(mLanguageNo >= 0) {
SetupStore("Language", gLanguages[mLanguageNo]);
mTtxtsubs->SetLanguage(gLanguages[mLanguageNo]);
} else {
SetupStore("Language", mLanguage);
mTtxtsubs->SetLanguage(mLanguage);
}
SetupStore("HearingImpaired", mHearingImpaired);
mTtxtsubs->SetHearingImpaired(mHearingImpaired);
SetupStore("Record", mRecord);
mTtxtsubs->SetRecord(mRecord);
}
VDRPLUGINCREATOR(cPluginTtxtsubs); // Don't touch this!
|