summaryrefslogtreecommitdiff
path: root/dxr3.c
blob: 9e7970e828211812804a9655d6495ef1a04867ce (plain)
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/*
* dxr3.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: dxr3.c,v 1.4 2005/03/22 20:55:42 scop Exp $
*/


#include "dxr3vdrincludes.h"
#include "dxr3device.h"
#include "dxr3syncbuffer.h"
#include "dxr3configdata.h"
#include "dxr3interface.h"
#include "dxr3i18n.h"
#include "dxr3cpu.h"
#include "dxr3dolbydigital.h"
#include "dxr3.h"

static const char *VERSION        = "0.3.0-cvs";
static const char *DESCRIPTION    = "Hardware MPEG decoder";
static const char *MAINMENUENTRY  = "DXR3";

// ==================================
// 'message-handler' for the main screen
eOSState cDxr3OsdItem::ProcessKey(eKeys Key) 
{
	if (Key == kOk) 
	{
		switch (m_item) 
		{
		case DXR3_RESET_HARDWARE:
			cDxr3Interface::Instance().ResetHardware();
			cDxr3Device::Instance().Reset();
			break;

		case DXR3_FORCE_LETTER_BOX:
			cDxr3ConfigData::Instance().SetForceLetterBox(!cDxr3ConfigData::Instance().GetForceLetterBox());
			break;

		case DXR3_ANALOG_OUT:
			cLog::Instance() << "Changing audio to analog\n";
			cDxr3ConfigData::Instance().SetUseDigitalOut(0);
			cDxr3ConfigData::Instance().SetAc3OutPut(0);
			cDxr3Device::Instance().Reset();            
			break;

		case DXR3_DIGITAL_OUT:
			cLog::Instance() << "Changing audio to digital\n";
			cDxr3ConfigData::Instance().SetUseDigitalOut(1);
			cDxr3ConfigData::Instance().SetAc3OutPut(0);
			cDxr3Device::Instance().Reset();                    
			break;

		case DXR3_AC3_OUT:
			cLog::Instance() << "Changing audio to ac3\n";
			cDxr3ConfigData::Instance().SetAc3OutPut(!cDxr3ConfigData::Instance().GetAc3OutPut());
			cDxr3Device::Instance().Reset();                    
			break;
		}
	}
	
	return Key == kOk ? osBack : cOsdItem::ProcessKey(Key);
}

// ==================================
// special osd item to change color settings
cDxr3OsdColorItem::cDxr3OsdColorItem(const char* Name, eDxr3ColorItem item)
:cMenuEditItem(Name), m_item(item)
{
	m_value = 0;
	m_min = 0;
	m_max = 32;

	// get vale from setup.conf
	switch (m_item)
	{
	case DXR3_BRIGHTNESS:
		m_value = cDxr3ConfigData::Instance().GetBrightness();
		break;

	case DXR3_CONTRAST:
		m_value = cDxr3ConfigData::Instance().GetContrast();
		break;

	case DXR3_SATURATION:
		m_value = cDxr3ConfigData::Instance().GetSaturation();
		break;
	};

	Set();
}

// ==================================
// react to keypresses
eOSState cDxr3OsdColorItem::ProcessKey(eKeys Key)
{
	eOSState state = cMenuEditItem::ProcessKey(Key);
	
	if (state == osUnknown) 
	{
		int newValue = m_value;
		Key = NORMALKEY(Key);
		switch (Key) 
		{
		case kNone: break;
		case k0 ... k9:
            if (fresh) 
			{
				m_value = 0;
				fresh = false;
			}
            newValue = m_value * 10 + (Key - k0);
            break;
		case kLeft: // TODO might want to increase the delta if repeated quickly?
            newValue = m_value - 1;
            fresh = true;
            break;
		case kRight:
            newValue = m_value + 1;
            fresh = true;
            break;
		default:
            if (m_value < m_min) { m_value = m_min; Set(); }
            if (m_value > m_max) { m_value = m_max; Set(); }
            return state;
		}
		if ((!fresh || m_min <= newValue) && newValue <= m_max) 
		{
			m_value = newValue;
			Set();
        }
		state = osContinue;
	}
	return state;
}

// ==================================
// set caption and call hardware ioctl's
void cDxr3OsdColorItem::Set()
{
	// real value with rounding
	int realValue = int(m_value * 31.25);
	
	char buf[16];
	snprintf(buf, sizeof(buf), "%s", "Hallo");
	SetValue(buf);
}

/*
// ==================================
// special osd item to change color settings
cDxr3OsdColorItem::cDxr3OsdColorItem(const char* Name, eDxr3ColorItem item)
:cOsdItem(Name), m_item(item)
{
	// get vale from setup.conf
	switch (m_item)
	{
	case DXR3_BRIGHTNESS:
		m_value = cDxr3ConfigData::Instance().GetBrightness();
		break;

	case DXR3_CONTRAST:
		m_value = cDxr3ConfigData::Instance().GetContrast();
		break;

	case DXR3_SATURATION:
		m_value = cDxr3ConfigData::Instance().GetSaturation();
		break;
	};

	// allowed values: 0 - 32
	m_min = 0;
	m_max = 32;

	m_name = strdup(Name);
	m_caption = NULL;

	Set();
}

// ==================================
// set caption and call hardware ioctl's
void cDxr3OsdColorItem::Set()
{
/*
	SetValue(SettingBar[m_value]);

	// real value with rounding
	int realValue = int(m_value * 31.25);

	switch (m_item)
	{
	case DXR3_BRIGHTNESS:
		cDxr3Interface::Instance().SetBrightness(realValue);
		cDxr3ConfigData::Instance().SetBrightness(m_value);
		break;

	case DXR3_CONTRAST:
		cDxr3Interface::Instance().SetContrast(realValue);
		cDxr3ConfigData::Instance().SetContrast(m_value);
		break;

	case DXR3_SATURATION:
		cDxr3Interface::Instance().SetSaturation(realValue);
		cDxr3ConfigData::Instance().SetSaturation(m_value);
		break;
	};
*//*
}

// ==================================
void cDxr3OsdColorItem::SetValue(const char *Value)
{
/*
	free(m_caption);
	m_caption = strdup(Value);
	char *buffer = NULL;
	asprintf(&buffer, "%s:\t%s", m_name, m_caption);
	SetText(buffer, false);
	cStatus::MsgOsdCurrentItem(buffer);
*//*
}

// ==================================
// react to keypresses
eOSState cDxr3OsdColorItem::ProcessKey(eKeys Key)
{
/*
	eOSState state = osUnknown;
	
	if (state == osUnknown) 
	{
		int newValue = m_value;
		Key = NORMALKEY(Key);
		
		switch (Key) 
		{
		case kNone: 
			break;
			
		case k0 ... k9:
            if (fresh) 
			{
				m_value = 0;
				fresh = false;
            }
            newValue = m_value * 10 + (Key - k0);
            break;
			
		case kLeft: // TODO might want to increase the delta if repeated quickly?
            newValue = m_value - 1;
            fresh = true;
            break;
			
		case kRight:
            newValue = m_value + 1;
            fresh = true;
            break;
			
		default:
            if (m_value < m_min) { m_value = m_min; Set(); }
            if (m_value > m_max) { m_value = m_max; Set(); }
            return state;
		}
		
		if ((!fresh || m_min <= newValue) && newValue <= m_max) 
		{
			m_value = newValue;
			Set();
        }
		state = osContinue;
	}
	return state;
*/
//}


// ==================================
// the main menu of the plugin
cDxr3OsdMenu::cDxr3OsdMenu() : cOsdMenu(tr("DXR3 Adjustment"))
{
	b = 0;
	c = 10;
	s = 0;

	Clear();
	SetHasHotkeys();
	Add(new cDxr3OsdItem(tr("Reset DXR3 hardware"), DXR3_RESET_HARDWARE));        
	Add(new cDxr3OsdItem(tr("Toggle force letterbox"), DXR3_FORCE_LETTER_BOX));

	// switch between differen output modes
	if (cDxr3ConfigData::Instance().GetUseDigitalOut())
	{
		Add(new cDxr3OsdItem(tr("Switch to analog audio output"), DXR3_ANALOG_OUT));
	}
	else
	{
		Add(new cDxr3OsdItem(tr("Switch to digital audio output"), DXR3_DIGITAL_OUT));
	}

	//SettingBar
	Add(new cDxr3OsdColorItem(tr("Brightness"), DXR3_BRIGHTNESS));
//	Add(new cMenuEditStraItem(tr("Brightness"),	&b, 33, SettingBar));
//	Add(new cMenuEditStraItem(tr("Contrast"),	&c, 33, SettingBar));
//	Add(new cMenuEditStraItem(tr("Saturation"),	&s, 33, SettingBar));
}


// ==================================
// setup menu
cMenuSetupDxr3::cMenuSetupDxr3(void)
{
	newUseDigitalOut = cDxr3ConfigData::Instance().GetUseDigitalOut();
	Add(new cMenuEditBoolItem(tr("Digital audio output"), &newUseDigitalOut));
	newDxr3Card = cDxr3ConfigData::Instance().GetDxr3Card();
	Add(new cMenuEditIntItem(tr("Card number"), &newDxr3Card));
	newVideoMode = (int) cDxr3ConfigData::Instance().GetVideoMode();
	menuVideoModes[0] = tr("PAL");
	menuVideoModes[1] = tr("PAL60");
	menuVideoModes[2] = tr("NTSC");
	Add(new cMenuEditStraItem(tr("Video mode"), &newVideoMode, 3, menuVideoModes));
	newDebug = (int) cDxr3ConfigData::Instance().GetDebug();
	Add(new cMenuEditBoolItem(tr("Debug mode"), &newDebug));
	newDebugLevel = (int) cDxr3ConfigData::Instance().GetDebugLevel();
	menuDebugModes[0] = tr("low");
	menuDebugModes[1] = tr("everything");
	Add(new cMenuEditStraItem(tr("Debug level"), &newDebugLevel, 2, menuDebugModes));
}

// ==================================
// save menu values
void cMenuSetupDxr3::Store(void)
{  
	SetupStore("UseDigitalOut",		cDxr3ConfigData::Instance().SetUseDigitalOut(newUseDigitalOut));
	SetupStore("Dxr3Card",			cDxr3ConfigData::Instance().SetDxr3Card(newDxr3Card));
	SetupStore("Dxr3VideoMode",		cDxr3ConfigData::Instance().SetVideoMode((eVideoMode) newVideoMode));
	SetupStore("Dxr3Debug",			cDxr3ConfigData::Instance().SetDebug(newDebug));
	SetupStore("Dxr3DebugLevel",	cDxr3ConfigData::Instance().SetDebugLevel(newDebugLevel));
}

// ==================================
class cPluginDxr3 : public cPlugin 
{
private:
	// Add any member variables or functions you may need here.
public:
	cPluginDxr3();    
	~cPluginDxr3();
	const char *Version()			{ return VERSION; }
	const char *Description()		{ return tr(DESCRIPTION); }
	const char *CommandLineHelp();
	bool ProcessArgs(int argc, char *argv[]);
	bool Initialize();
	bool Start();
	void Housekeeping();
	cMenuSetupPage *SetupMenu();
	bool SetupParse(const char *Name, const char *Value);
	const char* MainMenuEntry();
	cOsdObject* MainMenuAction();
};

// ==================================
cPluginDxr3::cPluginDxr3() 
{
	// Initialize any member varaiables here.
	// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
	// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
	cDxr3ConfigData::Instance();
}

// ==================================
cPluginDxr3::~cPluginDxr3() 
{
}

// ==================================
const char *cPluginDxr3::CommandLineHelp() 
{
	return NULL;
}

// ==================================
bool cPluginDxr3::ProcessArgs(int argc, char *argv[]) 
{
	return true;
}

// ==================================
bool cPluginDxr3::Start() 
{
	new cDxr3DolbyDigital();
    return true;
}

// ==================================
bool cPluginDxr3::Initialize() 
{
	RegisterI18n(Phrases);

	new cDxr3CPU();
	cDxr3Device::Instance();

    return true;
}    

// ==================================  
void cPluginDxr3::Housekeeping() 
{
}

// ==================================
cMenuSetupPage* cPluginDxr3::SetupMenu() 
{
	return new cMenuSetupDxr3();
}

// ==================================
bool cPluginDxr3::SetupParse(const char *Name, const char *Value) 
{
	// Parse your own setup parameters and store their values.
	if (!strcasecmp(Name, "UseDigitalOut"))		{ cDxr3ConfigData::Instance().SetUseDigitalOut(atoi(Value)); return true; }
	if (!strcasecmp(Name, "Dxr3Card"))			{ cDxr3ConfigData::Instance().SetDxr3Card(atoi(Value));      return true; }
	if (!strcasecmp(Name, "Dxr3Debug"))			{ cDxr3ConfigData::Instance().SetDebug(atoi(Value));      return true; }
	if (!strcasecmp(Name, "Dxr3VideoMode"))		{ cDxr3ConfigData::Instance().SetVideoMode((eVideoMode) atoi(Value)); return true;}
	if (!strcasecmp(Name, "Dxr3DebugLevel"))	{ cDxr3ConfigData::Instance().SetDebugLevel(atoi(Value)); return true;}
	if (!strcasecmp(Name, "Dxr3Contrast"))		{ cDxr3ConfigData::Instance().SetContrast(atoi(Value)); return true;}
	if (!strcasecmp(Name, "Dxr3Brightness"))	{ cDxr3ConfigData::Instance().SetBrightness(atoi(Value)); return true;}
	if (!strcasecmp(Name, "Dxr3Saturation"))	{ cDxr3ConfigData::Instance().SetSaturation(atoi(Value)); return true;}
	
	return false;
}

// ==================================
const char* cPluginDxr3::MainMenuEntry() 
{
	return tr(MAINMENUENTRY);
}

// ==================================
cOsdObject* cPluginDxr3::MainMenuAction() 
{
	return new cDxr3OsdMenu;
}

VDRPLUGINCREATOR(cPluginDxr3); // Don't touch this!