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
|
/*
* Copyright (C) 2000-2002 the xine project
*
* This file is part of xine, a free video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* $Id: tvmode.c,v 1.15 2003/05/16 11:39:50 hadess Exp $
*
* tvmode - TV output selection
*
* Currently uses nvtvd (Dirk Thierbach <dthierbach@gmx.de>)
* for setting TV mode
* xine support hacked in by Matthias Hopf <mat@mshopf.de>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "xine_internal.h"
#include "xineutils.h"
#ifdef XINE_HAVE_NVTV
#include "nvtv/back_client.h"
/*
* PRIVATE
*/
BackCardPtr back_card = 0;
BackAccessPtr back_access = 0;
static int current_type, current_width, current_height;
static double current_fps;
static TVRegs old_tvregs;
static TVSettings old_settings;
static int tvmode_enabled = 1;
static int was_enabled = 0;
static TVSystem opt_system = TV_SYSTEM_PAL;
static TVConnect opt_connect = CONNECT_NONE;
static TVMode *modes_pal = NULL;
static int size_modes_pal = 0;
static TVMode *modes_ntsc =NULL;
static int size_modes_ntsc = 0;
static double opt_aspect = 4.0 / 3.0;
/* Try to connect to nvtvd server */
static void tvmode_connect(xine_t *this) {
CardPtr main_card_list, main_card = NULL;
if (was_enabled) {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf ("tvmode: Already initialized!\n");
return;
}
if (back_client_avail ()) {
main_card_list = back_client_init ();
} else {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf ("tvmode: Nvtvd not detected, make sure nvtvd is running.\n");
/* Handle well in some way... */
return;
}
if (back_access) {
back_access->closeCard ();
}
if (!main_card_list) {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf ("tvmode: No supported video card found.\n");
/* Handle well in some way... */
return;
}
/* Just pick the first, here we might want to pick an alternative card... */
main_card = main_card_list;
if (!main_card) {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf ("tvmode: No supported video card found at specified address.\n");
/* Handle well in some way... */
return;
}
if (back_access) {
back_access->openCard (main_card);
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: Using card %s for tvout\n", main_card->name);
was_enabled = 1;
} else {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: cannot connect to nvtvd - no TV mode switching available\n");
}
}
/* Disconnect from server */
static void tvmode_disconnect (xine_t *this) {
back_access->closeCard ();
back_access = 0;
was_enabled = 0;
}
/* Save current CRT and TV register configuration */
static void tvmode_savestate (xine_t *this) {
back_card->getSettings(&old_settings);
back_card->getMode (&old_tvregs);
}
/* Restore CRT and TV register configuration */
static void tvmode_restorestate (xine_t *this) {
back_card->setModeSettings (&old_tvregs,&old_settings);
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: Old mode saved!");
current_type = 0;
}
/* Set CRT and TV registers to given TV-Out configuration */
static void tvmode_settvstate (xine_t *this, int width, int height, double fps) {
TVSettings settings;
TVMode mode;
TVMode *modes;
int size;
int found = 0;
int tmp_fps;
int i;
/* TODO: do that at initialization and save possible combinations */
/* Find supported TV mode */
if (opt_system == TV_SYSTEM_NTSC) {
modes = modes_ntsc;
size = size_modes_ntsc;
tmp_fps = 29.97;
} else {
modes = modes_pal;
tmp_fps = 25;
size = size_modes_pal;
}
for (i=0; i < size; i++) {
/*
printf ("Trying mode %dx%d %f %f\n", modes[i].spec.res_x, modes[i].spec.res_y, modes[i].spec.hoc, modes[i].spec.voc);
*/
if ((width <= modes[i].spec.res_x) && (height <= modes[i].spec.res_y) &&
(back_card->findByOverscan (opt_system, modes[i].spec.res_x, modes[i].spec.res_y, 10, 5, &mode))) {
current_width = mode.spec.res_x;
current_height = mode.spec.res_y;
current_fps = tmp_fps;
found++;
}
}
/* Switch to mode */
if (found) {
back_card->getSettings (&settings);
if (opt_connect > CONNECT_NONE) {
settings.connector = opt_connect;
} else {
settings.connector = CONNECT_BOTH;
}
mode.regs.devFlags = DEV_MONITOR | DEV_TELEVISION;
settings.flags |= TV_DESC_DUALVIEW;
back_card->setModeSettings (&mode.regs, &settings);
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: Trying to use mode %i x %i\n",current_width,current_height);
current_type = 1;
} else {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: cannot find any valid TV mode - TV output disabled\n");
xine_tvmode_exit (this);
}
}
/*
* PUBLIC
*/
/* Set to 'regular'(0) or 'tv'(1) state, that is if it is enabled */
int xine_tvmode_switch (xine_t *this, int type, int width, int height, double fps) {
if(tvmode_enabled) {
/*
* Wasn't initialized
*/
if(!was_enabled) {
xine_tvmode_init(this);
}
if (back_card) {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: switching to %s\n", type ? "TV" : "default");
switch (type) {
case 0:
tvmode_restorestate (this);
break;
case 1:
tvmode_settvstate (this, width, height, fps);
break;
default:
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: illegal type for switching\n");
tvmode_restorestate (this);
}
} else {
if (this->verbosity >= XINE_VERBOSITY_LOG)
printf("tvmode: not connected to nvtvd for switching\n");
}
}
return current_type;
}
/* Addapt (maximum) output size to visible area and set pixel aspect and fps */
void xine_tvmode_size (xine_t *this, int *width, int *height,
double *pixelratio, double *fps) {
if(tvmode_enabled) {
switch (current_type) {
case 1:
/*
if (width && *width > current_width)
*/
if (width)
*width = current_width;
/*
if (height && *height > current_height)
*/
if (height)
*height = current_height;
if (pixelratio)
*pixelratio = ((double) current_width / current_height) / opt_aspect;
if (fps)
*fps = current_fps;
break;
}
}
}
void init_modes() {
int i;
size_modes_pal = back_card->listModes(TV_SYSTEM_PAL, &modes_pal);
size_modes_ntsc = back_card->listModes(TV_SYSTEM_NTSC, &modes_ntsc);
/*
for (i=0; i < size_modes_pal; i++) {
printf ("Modes PAL %dx%d %f %f\n", modes_pal[i].spec.res_x, modes_pal[i].spec.res_y, modes_pal[i].spec.hoc, modes_pal[i].spec.voc);
}
for (i=0; i < size_modes_pal; i++) {
printf ("Modes NTSC %dx%d %f %f\n", modes_ntsc[i].spec.res_x, modes_ntsc[i].spec.res_y, modes_ntsc[i].spec.hoc, modes_ntsc[i].spec.voc);
}
*/
}
/* Connect to nvtvd server if possible and store settings */
int xine_tvmode_init(xine_t *self) {
tvmode_connect (self);
if (back_card) {
tvmode_savestate (self);
init_modes();
return 1;
}
return 0;
}
int xine_tvmode_use(xine_t *self, int use_tvmode) {
tvmode_enabled = 0;
if (use_tvmode) {
if (was_enabled || xine_tvmode_init(self)) {
tvmode_enabled = 1;
}
}
return (tvmode_enabled);
}
void xine_tvmode_set_tvsystem(xine_t *self, xine_tvsystem system) {
switch (system) {
case XINE_TVSYSTEM_PAL:
opt_system = TV_SYSTEM_PAL;
break;
case XINE_TVSYSTEM_NTSC:
opt_system = TV_SYSTEM_NTSC;
break;
default:
opt_system = TV_SYSTEM_PAL;
}
}
/* Restore old CRT and TV registers and close nvtvd connection */
void xine_tvmode_exit (xine_t *this) {
if(tvmode_enabled || was_enabled) {
if (back_card) {
tvmode_restorestate (this);
tvmode_disconnect (this);
}
if (modes_pal != NULL) {
free(modes_pal);
}
if (modes_ntsc != NULL) {
free(modes_ntsc);
}
}
}
#else
/* no nvtv support compiled in lib */
int xine_tvmode_switch (xine_t *this, int type, int width, int height, double fps) {
/* not supported: return regular mode */
return 0;
}
void xine_tvmode_size (xine_t *this, int *width, int *height,
double *pixelratio, double *fps) {
}
int xine_tvmode_init (xine_t *this) {
return 0;
}
void xine_tvmode_exit (xine_t *this) {
}
void xine_tvmode_set_tvsystem(xine_t *self, xine_tvsystem system) {
}
int xine_tvmode_use(xine_t *self, int use_tvmode) {
return 0;
}
#endif
|