| 1 |
|
| 2 |
#include "v4lwindow.h" |
| 3 |
#include "v4lwindow.moc" |
| 4 |
|
| 5 |
#include "avicapwnd.h" |
| 6 |
#include "ccap.h" |
| 7 |
#include "epgwindow.h" |
| 8 |
#include "frequencies.h" |
| 9 |
#include "picprop.h" |
| 10 |
#include "timertable.h" |
| 11 |
#include "vidconf.h" |
| 12 |
|
| 13 |
#include <aviplay.h> |
| 14 |
#include "v4lxif.h" |
| 15 |
|
| 16 |
#include <avifile.h> |
| 17 |
#include <avm_creators.h> |
| 18 |
#include <avm_output.h> |
| 19 |
#include <avm_cpuinfo.h> |
| 20 |
#include <avm_except.h> |
| 21 |
#include <avm_fourcc.h> |
| 22 |
#include <videodecoder.h> |
| 23 |
#include <utils.h> |
| 24 |
#define DECLARE_REGISTRY_SHORTCUT |
| 25 |
#include <configfile.h> |
| 26 |
#undef DECLARE_REGISTRY_SHORTCUT |
| 27 |
|
| 28 |
//#ifdef QT_VERSION |
| 29 |
#include "fullscreen_renderer.h" |
| 30 |
|
| 31 |
#include <renderer.h> |
| 32 |
|
| 33 |
//#include <qglobal.h> |
| 34 |
#include <qpopupmenu.h> |
| 35 |
#include <qmessagebox.h> |
| 36 |
#include <qpoint.h> |
| 37 |
#include <qfiledialog.h> |
| 38 |
#include <qlabel.h> |
| 39 |
#include <qpainter.h> |
| 40 |
#include <qcursor.h> |
| 41 |
#include <qwindowdefs.h> |
| 42 |
#include <qimage.h> |
| 43 |
#include <qdom.h> |
| 44 |
//#endif |
| 45 |
|
| 46 |
#include "qtrenderer.h" |
| 47 |
|
| 48 |
#ifndef WIN32 |
| 49 |
#include <pwd.h> |
| 50 |
#endif |
| 51 |
#include <unistd.h> |
| 52 |
#include <assert.h> |
| 53 |
#include <stdlib.h> |
| 54 |
#include <ctype.h> |
| 55 |
|
| 56 |
#include <memory> // auto_ptr |
| 57 |
|
| 58 |
static int rgb_method=0; |
| 59 |
|
| 60 |
static inline void default_dimensions(int& w, int& h) |
| 61 |
{ |
| 62 |
if (RI("ColorMode", 0) == 1) |
| 63 |
{ |
| 64 |
w = 320; |
| 65 |
h = 240; |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
w = 384; |
| 70 |
h = 288; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
V4LWindow::V4LWindow(v4lxif* pDev, QWidget* pParent) |
| 75 |
: QWidget(pParent, 0, 0), avm::AvmOutputLog("V4LWindow"), |
| 76 |
m_pDev(pDev), m_pRenderer(0), visibility(VisibilityFullyObscured), |
| 77 |
oc_count(0), m_eMode(Overlay), m_iPainter(0), |
| 78 |
m_pPicConfig(0), m_pTimerTable(0),m_pEpgWindow(0), |
| 79 |
m_pCapDialog(0), m_pCC(0), m_pPopup(0), m_pLabel(0), |
| 80 |
m_bForce4x3(true), m_bSubtitles(false), |
| 81 |
known_pos(false), m_bAutoRecord(false), m_bMoved(false), |
| 82 |
mc_switch(10), mc_tiles(3) |
| 83 |
{ |
| 84 |
AVMOUT(AVML_DEBUG, "opened"); |
| 85 |
|
| 86 |
assert(m_pDev); |
| 87 |
m_pDev->setCapture(0); |
| 88 |
AVMOUT(AVML_DEBUG, "after setcapture"); |
| 89 |
fs_renderer=NULL; |
| 90 |
|
| 91 |
m_eMode = (Modes)RI("DisplayMode", 0); |
| 92 |
setMode(m_eMode); |
| 93 |
int norm = RI("ColorMode", 0); |
| 94 |
if (((norm==1) || (norm==3)) && m_pDev->hasvbi())//NTSC or AUTO |
| 95 |
m_bSubtitles = RI("Subtitles", 0); |
| 96 |
else |
| 97 |
m_bSubtitles = false; |
| 98 |
setupSubtitles(); |
| 99 |
AVMOUT(AVML_DEBUG, "after setupSubtitles"); |
| 100 |
|
| 101 |
int w, h; |
| 102 |
default_dimensions(w, h); |
| 103 |
connect(&m_timer, SIGNAL(timeout()), this, SLOT(timerStop())); |
| 104 |
connect(&m_cctimer, SIGNAL(timeout()), this, SLOT(updatesub())); |
| 105 |
//connect(&m_RatioTimer, SIGNAL(timeout()), this, SLOT(ratioTimerStop())); |
| 106 |
m_RatioTimer.start(200, FALSE); |
| 107 |
setBackgroundColor(QColor(0,0,0)); |
| 108 |
AVMOUT(AVML_DEBUG, "before setupDevice()"); |
| 109 |
setupDevice(); |
| 110 |
AVMOUT(AVML_DEBUG, "after setupDevice()"); |
| 111 |
scanXawtv(); |
| 112 |
resize(w, h); |
| 113 |
|
| 114 |
last_station=-1; |
| 115 |
QString capstr=tr("Avicap - unknown channel"); |
| 116 |
setCaption(capstr); |
| 117 |
if (fs_renderer) |
| 118 |
fs_renderer->setCaption(capstr.latin1()); |
| 119 |
|
| 120 |
int plock=RI("Password-Locked",0); |
| 121 |
lock(plock); |
| 122 |
AVMOUT(AVML_DEBUG, "end of constructor"); |
| 123 |
} |
| 124 |
|
| 125 |
V4LWindow::~V4LWindow() |
| 126 |
{ |
| 127 |
AVMOUT(AVML_DEBUG, "Exiting"); |
| 128 |
refresh_timer(); |
| 129 |
if (m_eMode==AvicapRend || m_eMode==MultiChannel) |
| 130 |
m_eMode=Overlay; |
| 131 |
|
| 132 |
avicap_renderer_stop(); |
| 133 |
multichannel_stop(); |
| 134 |
|
| 135 |
WI("DisplayMode", m_eMode); |
| 136 |
WI("Subtitles", m_bSubtitles); |
| 137 |
delete m_pEpgWindow; |
| 138 |
delete m_pTimerTable; |
| 139 |
delete m_pDev; |
| 140 |
delete m_pPicConfig; |
| 141 |
#if 0 |
| 142 |
UserLog("exiting V4lwindow\n"); |
| 143 |
if(user_logfh){ |
| 144 |
fclose(user_logfh); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
void V4LWindow::UserLog(QString str){ |
| 149 |
if(!RI("LogToFile",0)){ |
| 150 |
return; |
| 151 |
} |
| 152 |
if(!user_logfh){ |
| 153 |
struct passwd* pwent = getpwuid(getuid()); |
| 154 |
QString homedir = pwent->pw_dir; |
| 155 |
QString filename=homedir+"/.avm/avicap-userlog.log"; |
| 156 |
|
| 157 |
user_logfh=fopen(filename.latin1(),"a+"); |
| 158 |
fputs("\n=============Logging started==============\n",user_logfh); |
| 159 |
} |
| 160 |
#if QT_VERSION>=300 |
| 161 |
fputs(QDateTime::currentDateTime().toString("yy/MM/dd hh:mm:ss ").latin1(),user_logfh); |
| 162 |
#else |
| 163 |
fputs(QDateTime::currentDateTime().toString().latin1(),user_logfh); |
| 164 |
#endif |
| 165 |
fputs(str.latin1(),user_logfh); |
| 166 |
fflush(user_logfh); |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
void V4LWindow::pLog(avm::string str){ |
| 171 |
#ifdef AVICAP_PARANOIA |
| 172 |
ParanoiaLog(str); |
| 173 |
#endif |
| 174 |
|
| 175 |
#endif |
| 176 |
|
| 177 |
AVMOUT(AVML_DEBUG, "Exiting"); |
| 178 |
} |
| 179 |
|
| 180 |
void V4LWindow::postResizeEvent(int w, int h) |
| 181 |
{ |
| 182 |
QEvent* e = new QResizeEvent(QSize(w, h), size()); |
| 183 |
qApp->postEvent(this, e); |
| 184 |
} |
| 185 |
|
| 186 |
// Xawtv DGA refresh trick |
| 187 |
// makes complete screen refresh by mapping unmapping fullscreen window |
| 188 |
void V4LWindow::refresh_timer() |
| 189 |
{ |
| 190 |
#if 0 |
| 191 |
static long refresh_counter=0; |
| 192 |
if (refresh_counter%(25*60)==0) |
| 193 |
avml(AVML_DEBUG1, "V4lwindow: refresh timer\n"); |
| 194 |
refresh_counter++; |
| 195 |
#endif |
| 196 |
|
| 197 |
Display* dpy = x11Display(); |
| 198 |
Window win = DefaultRootWindow(dpy); |
| 199 |
Screen* scr = DefaultScreenOfDisplay(dpy); |
| 200 |
int swidth = scr->width; |
| 201 |
int sheight = scr->height; |
| 202 |
XSetWindowAttributes xswa; |
| 203 |
unsigned long mask; |
| 204 |
Window tmp; |
| 205 |
|
| 206 |
xswa.override_redirect = True; |
| 207 |
xswa.backing_store = NotUseful; |
| 208 |
xswa.save_under = False; |
| 209 |
mask = (CWSaveUnder | CWBackingStore| CWOverrideRedirect ); |
| 210 |
tmp = XCreateWindow(dpy, win, 0,0, swidth, sheight, 0, |
| 211 |
CopyFromParent, InputOutput, CopyFromParent, |
| 212 |
mask, &xswa); |
| 213 |
XMapWindow(dpy, tmp); |
| 214 |
XUnmapWindow(dpy, tmp); |
| 215 |
XDestroyWindow(dpy, tmp); |
| 216 |
} |
| 217 |
|
| 218 |
void V4LWindow::hidePopup() |
| 219 |
{ |
| 220 |
if (m_pPopup) |
| 221 |
m_pPopup->hide(); |
| 222 |
// m_pDev->setCapture(1); |
| 223 |
get_clips(); |
| 224 |
} |
| 225 |
|
| 226 |
void V4LWindow::timerStop() |
| 227 |
{ |
| 228 |
if(m_eMode==Overlay) |
| 229 |
{ |
| 230 |
//printf("SETCAPTURE\n"); |
| 231 |
if (m_bMoved) |
| 232 |
{ |
| 233 |
m_bMoved = false; |
| 234 |
refresh_timer(); |
| 235 |
get_clips(); |
| 236 |
} |
| 237 |
m_pDev->setCapture(1); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
void V4LWindow::setMode(Modes m) |
| 242 |
{ |
| 243 |
AVMOUT(AVML_DEBUG, "Changed display mode to %d", m); |
| 244 |
|
| 245 |
if ((m == DeinterlacedPreview) && !freq.HaveMMXEXT()) |
| 246 |
m = Preview; |
| 247 |
switch(m) { |
| 248 |
case Overlay: |
| 249 |
overlay(); |
| 250 |
break; |
| 251 |
case Preview: |
| 252 |
preview(); |
| 253 |
break; |
| 254 |
case DeinterlacedPreview: |
| 255 |
deinterlaced_preview(); |
| 256 |
break; |
| 257 |
case AvicapRend: |
| 258 |
avicap_renderer(); |
| 259 |
break; |
| 260 |
case MultiChannel: |
| 261 |
multichannel(); |
| 262 |
break; |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
void V4LWindow::moveEvent( QMoveEvent * e) |
| 267 |
{ |
| 268 |
if (m_eMode != Overlay || !isVisible()) |
| 269 |
return; |
| 270 |
|
| 271 |
m_pDev->setCapture(0); |
| 272 |
int norm = RI("ColorMode", 0); |
| 273 |
// QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 274 |
// int field_width, field_height; |
| 275 |
// default_dimensions(field_width, field_height); |
| 276 |
// m_pDev->setCapAClip(pnt.x()+(384-field_width)/2, pnt.y()+(288-field_height)/2, |
| 277 |
// field_width, field_height); |
| 278 |
// m_pDev->setCapAClip(pnt.x(), pnt.y(), width(), height()); |
| 279 |
setupPicDimensions(); |
| 280 |
m_pDev->applyCapAClip(0); |
| 281 |
m_bMoved = true; |
| 282 |
if(m_timer.isActive()) |
| 283 |
m_timer.stop(); |
| 284 |
m_timer.start(200, TRUE); |
| 285 |
|
| 286 |
// if(!known_pos) |
| 287 |
// m_pDev->setCapture(1); |
| 288 |
known_pos=true; |
| 289 |
if(m_bAutoRecord) |
| 290 |
{ |
| 291 |
captureAVI(); |
| 292 |
m_bAutoRecord=false; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
void V4LWindow::setXawtv(int st) |
| 297 |
{ |
| 298 |
AVMOUT(AVML_DEBUG, "setXawtv %d:%s", |
| 299 |
st, xawtvstations[st].input.c_str()); |
| 300 |
|
| 301 |
if (st < 0 || st >= getStations()) |
| 302 |
return; |
| 303 |
#if 0 |
| 304 |
if (m_pCapDialog) |
| 305 |
{ |
| 306 |
m_pCapDialog->stop(); |
| 307 |
delete m_pCapDialog; |
| 308 |
m_pCapDialog = 0; |
| 309 |
} |
| 310 |
#endif |
| 311 |
|
| 312 |
if (m_eMode == AvicapRend) |
| 313 |
m_CaptureTimer.stop(); |
| 314 |
// delete fs_renderer; |
| 315 |
//fs_renderer=NULL; |
| 316 |
|
| 317 |
#if 0 |
| 318 |
// old style channel-change |
| 319 |
delete m_pDev; |
| 320 |
delete m_pPicConfig; |
| 321 |
m_pPicConfig = 0; |
| 322 |
|
| 323 |
avm::string s = avm::string("v4lctl setstation \""); |
| 324 |
s += xawtvstations[st].sname.c_str(); |
| 325 |
s += "\""; |
| 326 |
system(s.c_str()); |
| 327 |
#else |
| 328 |
//new channel change |
| 329 |
|
| 330 |
avm::string channelstr=xawtvstations[st].channel; |
| 331 |
|
| 332 |
int cl=0; |
| 333 |
while(!( chanlists[cl].name==NULL || chanlists[cl].name==freqtable )){ |
| 334 |
cl++; |
| 335 |
} |
| 336 |
if(chanlists[cl].name==NULL){ |
| 337 |
printf("not found\n"); |
| 338 |
} |
| 339 |
else{ |
| 340 |
//printf("found channellist %d\n",cl); |
| 341 |
|
| 342 |
const struct CHANLIST *myclist=chanlists[cl].list; |
| 343 |
int myccount=chanlists[cl].count; |
| 344 |
|
| 345 |
int scount=0; |
| 346 |
while(!(scount>=myccount || myclist[scount].name==channelstr )){ |
| 347 |
scount++; |
| 348 |
} |
| 349 |
|
| 350 |
if(scount>=myccount){ |
| 351 |
printf("channel %s not found\n",channelstr.c_str()); |
| 352 |
} |
| 353 |
else{ |
| 354 |
m_pDev->setAudioMute(true); |
| 355 |
//m_pDev->setAudioVolume(0); |
| 356 |
|
| 357 |
int freq=myclist[scount].freq; |
| 358 |
//printf("channel %s freq %d\n",channelstr.c_str(),freq); |
| 359 |
|
| 360 |
//m_pDev->setCapture(0); |
| 361 |
//sleep(1); |
| 362 |
unsigned long lfreq=(unsigned long) freq*16/1000; |
| 363 |
lfreq+=xawtvstations[st].finetune; |
| 364 |
m_pDev->setFreq(lfreq); |
| 365 |
//sleep(1); |
| 366 |
//m_pDev->setCapture(1); |
| 367 |
} |
| 368 |
} |
| 369 |
#endif |
| 370 |
|
| 371 |
try |
| 372 |
{ |
| 373 |
//m_pDev = new v4l1if(0, RS("CapDev", "/dev/video")); |
| 374 |
m_pDev->setChannelName(xawtvstations[st].input.c_str()); |
| 375 |
get_clips(); |
| 376 |
if(m_eMode!=MultiChannel){ |
| 377 |
//m_pDev->setAudioVolume(st*5); |
| 378 |
m_pDev->setAudioMute(false); |
| 379 |
} |
| 380 |
last_station=st; |
| 381 |
QString locked; |
| 382 |
if (RI("Password-Locked",0)) |
| 383 |
locked=tr(" locked"); |
| 384 |
|
| 385 |
QString capstr = tr( "Avicap: " ) + QString::number(st+1)+" - "+QString(xawtvstations[st].sname.c_str()) + locked; |
| 386 |
setCaption( capstr ); |
| 387 |
if (fs_renderer) |
| 388 |
fs_renderer->setCaption( capstr.latin1() ); |
| 389 |
AVMOUT(AVML_DEBUG, "Channel change -> %d", st); |
| 390 |
|
| 391 |
} |
| 392 |
catch (FatalError& e) |
| 393 |
{ |
| 394 |
e.PrintAll(); |
| 395 |
m_pDev = 0; |
| 396 |
} |
| 397 |
if (m_eMode == AvicapRend){ |
| 398 |
// avicap_renderer(); |
| 399 |
m_CaptureTimer.start(40); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
static avm::string get_keyword(const char* s) |
| 404 |
{ |
| 405 |
const char* e = strchr(s, '='); |
| 406 |
if (e) |
| 407 |
{ |
| 408 |
e++; |
| 409 |
while (*e && isspace(*e)) e++; |
| 410 |
s = e; |
| 411 |
while (*e && !isspace(*e)) e++; |
| 412 |
} |
| 413 |
else |
| 414 |
e = s; |
| 415 |
return avm::string(s, e - s); |
| 416 |
} |
| 417 |
|
| 418 |
/* |
| 419 |
* |
| 420 |
* |
| 421 |
* Simple parser of Xawtv configure file |
| 422 |
* |
| 423 |
*/ |
| 424 |
void V4LWindow::scanXawtv() |
| 425 |
{ |
| 426 |
AVMOUT(AVML_DEBUG, "reading Xawtv file\n"); |
| 427 |
|
| 428 |
struct passwd* pwent = getpwuid(getuid()); |
| 429 |
avm::string xawtvcnf = pwent->pw_dir; |
| 430 |
xawtvcnf += "/.xawtv"; |
| 431 |
FILE* fl = fopen(xawtvcnf.c_str(), "rb"); |
| 432 |
int x = 0; |
| 433 |
xawtvstations.clear(); |
| 434 |
|
| 435 |
if (fl != NULL) |
| 436 |
{ |
| 437 |
xawtvstation xawdefaults; |
| 438 |
xawtvstation xs; |
| 439 |
|
| 440 |
while (!feof(fl)) |
| 441 |
{ |
| 442 |
char b[500]; |
| 443 |
fgets(b, sizeof(b) - 1, fl); |
| 444 |
b[sizeof(b) - 1] = 0; |
| 445 |
char* s = strchr(b, '#'); |
| 446 |
if (s) |
| 447 |
*s = 0; |
| 448 |
if ((s = strchr(b, '['))) |
| 449 |
{ |
| 450 |
s++; |
| 451 |
char* e = strchr(s, ']'); |
| 452 |
avm::string sname = avm::string(s, e - s); |
| 453 |
if (strcasecmp(sname.c_str(), "global") == 0 |
| 454 |
|| strcasecmp(sname.c_str(), "launch") == 0) |
| 455 |
continue; |
| 456 |
//printf("stname %s\n", sname.c_str()); |
| 457 |
|
| 458 |
xs.sname = sname; |
| 459 |
|
| 460 |
if (strcasecmp(sname.c_str(), "defaults") == 0) |
| 461 |
{ |
| 462 |
xawdefaults = xs; |
| 463 |
continue; |
| 464 |
} |
| 465 |
|
| 466 |
if (!getStations()) |
| 467 |
// assumption - default comes in the begining |
| 468 |
xawdefaults = xs; |
| 469 |
xawtvstations.push_back(xs); |
| 470 |
xs = xawdefaults; |
| 471 |
} |
| 472 |
else if ((s = strstr(b, "key"))) |
| 473 |
{ |
| 474 |
avm::string k = get_keyword(s); |
| 475 |
if (k.size()) |
| 476 |
{ |
| 477 |
xs.key = toupper(k[0]); |
| 478 |
if (getStations()) |
| 479 |
xawtvstations.back().key = xs.key; |
| 480 |
} |
| 481 |
} |
| 482 |
else if ((s = strstr(b, "input"))) |
| 483 |
{ |
| 484 |
xs.input = get_keyword(s); |
| 485 |
if (xs.input.size()) |
| 486 |
{ |
| 487 |
if (getStations()) |
| 488 |
xawtvstations.back().input = xs.input; |
| 489 |
} |
| 490 |
} |
| 491 |
else if ((s = strstr(b, "freqtab"))) |
| 492 |
{ |
| 493 |
freqtable = get_keyword(s); |
| 494 |
printf("freqtab is %s\n", freqtable.c_str()); |
| 495 |
} |
| 496 |
else if ((s = strstr(b, "channel"))) |
| 497 |
{ |
| 498 |
avm::string channelstr = get_keyword(s); |
| 499 |
if (channelstr.size()) { |
| 500 |
int ss = getStations(); |
| 501 |
xawtvstations[ss-1].channel = channelstr; |
| 502 |
//printf("channel %s for %s\n", channelstr.c_str(), xawtvstations[ss-1].sname.c_str()); |
| 503 |
} |
| 504 |
} |
| 505 |
else if ((s = strstr(b, "fine"))) |
| 506 |
{ |
| 507 |
avm::string finestr = get_keyword(s); |
| 508 |
if (finestr.size()) { |
| 509 |
int ss = getStations(); |
| 510 |
xawtvstations[ss-1].finetune = atoi(finestr.c_str());; |
| 511 |
printf("finetune %d for %s\n", |
| 512 |
xawtvstations[ss-1].finetune, xawtvstations[ss-1].sname.c_str()); |
| 513 |
} |
| 514 |
} |
| 515 |
} |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
bool V4LWindow::event(QEvent* e) |
| 520 |
{ |
| 521 |
// printf("EVENT %d\n", e->type()); |
| 522 |
switch (e->type()) |
| 523 |
{ |
| 524 |
case Q_MyCloseEvent: |
| 525 |
emit overlay(); |
| 526 |
break; |
| 527 |
default: |
| 528 |
return QWidget::event(e); // parent call |
| 529 |
} |
| 530 |
return true; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
void V4LWindow::sendQt(QEvent* e) |
| 535 |
{ |
| 536 |
qApp->postEvent(this, e); |
| 537 |
// event deleted by Qt |
| 538 |
#if QT_VERSION > 220 |
| 539 |
// qApp->wakeUpGuiThread(); |
| 540 |
#endif |
| 541 |
} |
| 542 |
|
| 543 |
void V4LWindow::makePopup() |
| 544 |
{ |
| 545 |
// avm::Locker lock(m_Mutex); |
| 546 |
|
| 547 |
if (m_pPopup && m_pPopup->isVisible()) |
| 548 |
{ |
| 549 |
m_pPopup->hide(); |
| 550 |
return; |
| 551 |
} |
| 552 |
delete m_pPopup; |
| 553 |
m_pPopup = new QPopupMenu; |
| 554 |
int norm = RI("ColorMode", 0); |
| 555 |
m_pPopup->insertItem(tr("Configure"), this, SLOT(config())); |
| 556 |
|
| 557 |
if (getStations()) |
| 558 |
{ |
| 559 |
QPopupMenu* p = new QPopupMenu(); |
| 560 |
connect(p, SIGNAL(activated(int)), this, SLOT(changeChannel(int))); |
| 561 |
|
| 562 |
char cbuf[100]; |
| 563 |
for (unsigned i = 0; i < xawtvstations.size(); i++){ |
| 564 |
sprintf(cbuf,"%-2d %s",i+1,xawtvstations[i].sname.c_str()); |
| 565 |
p->insertItem(cbuf, i); |
| 566 |
} |
| 567 |
m_pPopup->insertItem(tr("Xawtv stations"), p); |
| 568 |
} |
| 569 |
|
| 570 |
m_pPopup->insertItem(tr("Picture properties"), this, SLOT(picprop())); |
| 571 |
m_pPopup->insertItem(tr("Timertable"), this, SLOT(timertable())); |
| 572 |
m_pPopup->insertItem(tr("Electronic Program Guide"), this, SLOT(epgwindow())); |
| 573 |
m_pPopup->insertItem(tr("Capture AVI"), this, SLOT(captureAVI())); |
| 574 |
m_pPopup->insertItem(tr("Capture BMP"), this, SLOT(captureBMP())); |
| 575 |
// m_pPopup->insertItem("Capture JPG", this, SLOT(captureJPG())); |
| 576 |
m_pPopup->insertSeparator(); |
| 577 |
int iItem=m_pPopup->insertItem(tr("Force 4x3 ratio"), this, SLOT(force4x3())); |
| 578 |
m_pPopup->setCheckable(true); |
| 579 |
m_pPopup->setItemChecked(iItem, m_bForce4x3); |
| 580 |
if(((norm==1) || (norm==3)) && m_pDev->hasvbi())//NTSC or AUTO |
| 581 |
{ |
| 582 |
iItem=m_pPopup->insertItem(tr("Show subtitles"), this, SLOT(showsub())); |
| 583 |
m_pPopup->setCheckable(true); |
| 584 |
m_pPopup->setItemChecked(iItem, m_bSubtitles); |
| 585 |
} |
| 586 |
else |
| 587 |
m_bSubtitles=false; |
| 588 |
// m_pPopup->setChecked(m_bForce4x3); |
| 589 |
m_pPopup->insertSeparator(); |
| 590 |
int iModeItems[5]; |
| 591 |
iModeItems[0]=m_pPopup->insertItem(tr("&Overlay"), this, SLOT(overlay())); |
| 592 |
m_pPopup->setCheckable(true); |
| 593 |
m_pPopup->setItemChecked(iModeItems[0], false); |
| 594 |
iModeItems[1]=m_pPopup->insertItem(tr("&Preview"), this, SLOT(preview())); |
| 595 |
m_pPopup->setCheckable(true); |
| 596 |
m_pPopup->setItemChecked(iModeItems[1], false); |
| 597 |
if(freq.HaveMMXEXT()) |
| 598 |
{ |
| 599 |
iModeItems[2]=m_pPopup->insertItem(tr("Deinterlace"), this, SLOT(deinterlaced_preview())); |
| 600 |
m_pPopup->setCheckable(true); |
| 601 |
m_pPopup->setItemChecked(iModeItems[2], false); |
| 602 |
} |
| 603 |
else |
| 604 |
iModeItems[2]=-1; |
| 605 |
|
| 606 |
iModeItems[3]=m_pPopup->insertItem(tr("exp. SDL/FS renderer"), this, SLOT(avicap_renderer())); |
| 607 |
m_pPopup->setCheckable(true); |
| 608 |
m_pPopup->setItemChecked(iModeItems[3], false); |
| 609 |
|
| 610 |
iModeItems[4]=m_pPopup->insertItem(tr("MultiChannel"), this, SLOT(multichannel())); |
| 611 |
m_pPopup->setCheckable(true); |
| 612 |
m_pPopup->setItemChecked(iModeItems[3], false); |
| 613 |
|
| 614 |
|
| 615 |
switch(getMode()) |
| 616 |
{ |
| 617 |
case Overlay: |
| 618 |
m_pPopup->setItemChecked(iModeItems[0], true); |
| 619 |
break; |
| 620 |
case Preview: |
| 621 |
m_pPopup->setItemChecked(iModeItems[1], true); |
| 622 |
break; |
| 623 |
case DeinterlacedPreview: |
| 624 |
// if(iModeItems[2]>=0) |
| 625 |
m_pPopup->setItemChecked(iModeItems[2], true); |
| 626 |
break; |
| 627 |
case AvicapRend: |
| 628 |
m_pPopup->setItemChecked(iModeItems[3], true); |
| 629 |
break; |
| 630 |
case MultiChannel: |
| 631 |
m_pPopup->setItemChecked(iModeItems[4], true); |
| 632 |
break; |
| 633 |
} |
| 634 |
#if 0 |
| 635 |
m_pPopup->insertSeparator(); |
| 636 |
m_pPopup->insertItem(tr("Fullscreen"), this, SLOT(fullscreen())); |
| 637 |
//#ifdef HAVE_LIBXXF86VM |
| 638 |
m_pPopup->insertItem("Maximize", this, SLOT(maximize())); |
| 639 |
//#endif |
| 640 |
//#endif |
| 641 |
#endif |
| 642 |
|
| 643 |
m_pPopup->insertSeparator(); |
| 644 |
m_pPopup->insertItem(tr("&Quit"), this, SLOT(close())); |
| 645 |
|
| 646 |
#if 0 |
| 647 |
Window root_return, child_return; |
| 648 |
int root_x_return, root_y_return; |
| 649 |
int win_x_return, win_y_return; |
| 650 |
unsigned int mask_return; |
| 651 |
|
| 652 |
XQueryPointer(x11Display(), handle(), &root_return, &child_return, |
| 653 |
&root_x_return, &root_y_return, |
| 654 |
&win_x_return, &win_y_return, &mask_return); |
| 655 |
#endif |
| 656 |
QPoint cpos=QCursor::pos(); |
| 657 |
//popup(QPoint(root_x_return, root_y_return)); |
| 658 |
m_pPopup->exec(cpos); |
| 659 |
} |
| 660 |
|
| 661 |
void V4LWindow::avicap_renderer_stop() |
| 662 |
{ |
| 663 |
m_avicapTimer.stop(); |
| 664 |
delete fs_renderer; |
| 665 |
fs_renderer=NULL; |
| 666 |
|
| 667 |
} |
| 668 |
void V4LWindow::avicap_renderer_close() |
| 669 |
{ |
| 670 |
QEvent *me=new QEvent(Q_MyCloseEvent); |
| 671 |
|
| 672 |
sendQt(me); |
| 673 |
|
| 674 |
} |
| 675 |
|
| 676 |
void V4LWindow::avicap_renderer_popup() |
| 677 |
{ |
| 678 |
|
| 679 |
QMouseEvent *me=new QMouseEvent(QEvent::MouseButtonRelease,QCursor::pos(),Qt::RightButton,Qt::RightButton); |
| 680 |
|
| 681 |
sendQt(me); |
| 682 |
// makePopup(); |
| 683 |
|
| 684 |
|
| 685 |
} |
| 686 |
|
| 687 |
void V4LWindow::mouseReleaseEvent( QMouseEvent * e) |
| 688 |
{ |
| 689 |
if (!(e->button() & Qt::RightButton)) |
| 690 |
return; |
| 691 |
|
| 692 |
makePopup(); |
| 693 |
} |
| 694 |
|
| 695 |
void V4LWindow::config() |
| 696 |
{ |
| 697 |
AVMOUT(AVML_DEBUG, "configure"); |
| 698 |
//m_pPopup=0; |
| 699 |
m_pDev->setCapture(0); |
| 700 |
if (m_timer.isActive()) |
| 701 |
m_timer.stop(); |
| 702 |
m_timer.start(100, TRUE); |
| 703 |
|
| 704 |
VidConfig conf(this, m_pDev, this); |
| 705 |
//QPoint pnt = mapToGlobal(QPoint(0,0)); |
| 706 |
//conf.move(pnt.x() + width() / 2, pnt.y() + height() / 4); |
| 707 |
conf.move(QCursor::pos()); |
| 708 |
conf.exec(); |
| 709 |
setupPicDimensions(); |
| 710 |
setupDevice(); |
| 711 |
} |
| 712 |
|
| 713 |
void V4LWindow::lock(bool lock){ |
| 714 |
//locked or not? |
| 715 |
if (lock) { |
| 716 |
AVMOUT(AVML_DEBUG, "locking system"); |
| 717 |
//we have to lock system |
| 718 |
|
| 719 |
//make shure the epg info is available |
| 720 |
epgwindow(); |
| 721 |
m_pEpgWindow->lock(true); |
| 722 |
changeChannel(last_station); |
| 723 |
} else { |
| 724 |
//unlock |
| 725 |
AVMOUT(AVML_DEBUG, "unlock system"); |
| 726 |
if (m_pEpgWindow) |
| 727 |
m_pEpgWindow->lock(false); |
| 728 |
//changeChannel(last_station); |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
void V4LWindow::force4x3() |
| 733 |
{ |
| 734 |
hidePopup(); |
| 735 |
m_bForce4x3 = !m_bForce4x3; |
| 736 |
if (m_bForce4x3) |
| 737 |
postResizeEvent(width(), height()); |
| 738 |
} |
| 739 |
|
| 740 |
void V4LWindow::getOverlaySizeAndOffset(int *pw, int *ph, int* pdx, int* pdy) |
| 741 |
{ |
| 742 |
int dxpos, dypos; |
| 743 |
int max_w, max_h; |
| 744 |
*pw=width(); |
| 745 |
*ph=height(); |
| 746 |
if(m_bSubtitles) |
| 747 |
*ph-=80; |
| 748 |
if(*ph<=0) |
| 749 |
{ |
| 750 |
printf("Oops: ph<0\n"); |
| 751 |
return; |
| 752 |
} |
| 753 |
default_dimensions(max_w, max_h); |
| 754 |
max_w*=2; |
| 755 |
max_h*=2; |
| 756 |
dxpos=dypos=0; |
| 757 |
if(*pw>max_w) |
| 758 |
{ |
| 759 |
dxpos=(*pw-max_w)/2; |
| 760 |
*pw=max_w; |
| 761 |
} |
| 762 |
if(*ph>max_h) |
| 763 |
{ |
| 764 |
dypos=(*ph-max_h)/2; |
| 765 |
*ph=max_h; |
| 766 |
} |
| 767 |
if(pdx)*pdx=dxpos; |
| 768 |
if(pdy)*pdy=dypos; |
| 769 |
} |
| 770 |
|
| 771 |
static int get_palette(Display * dpy) |
| 772 |
{ |
| 773 |
int r; |
| 774 |
switch (avm::GetPhysicalDepth(dpy)) |
| 775 |
{ |
| 776 |
case 15: |
| 777 |
r = VIDEO_PALETTE_RGB555; |
| 778 |
break; |
| 779 |
case 16: |
| 780 |
r = VIDEO_PALETTE_RGB565; |
| 781 |
break; |
| 782 |
case 24: |
| 783 |
r = VIDEO_PALETTE_RGB24; |
| 784 |
break; |
| 785 |
case 32: |
| 786 |
default: |
| 787 |
r = VIDEO_PALETTE_RGB32; |
| 788 |
break; |
| 789 |
} |
| 790 |
return r; |
| 791 |
} |
| 792 |
|
| 793 |
void V4LWindow::setupPicDimensions(int* pdx, int* pdy) |
| 794 |
{ |
| 795 |
AVMOUT(AVML_DEBUG, "setting pic dimensions"); |
| 796 |
|
| 797 |
avm::Locker lock(m_Mutex); |
| 798 |
int dxpos, dypos, pw, ph; |
| 799 |
QPoint pnt = mapToGlobal(QPoint(0,0)); |
| 800 |
getOverlaySizeAndOffset(&pw, &ph, &dxpos, &dypos); |
| 801 |
if(m_eMode == Overlay) |
| 802 |
m_pDev->setCapAClip(pnt.x()+dxpos, pnt.y()+dypos, pw, ph); |
| 803 |
else if(m_eMode==AvicapRend){ |
| 804 |
|
| 805 |
} |
| 806 |
else |
| 807 |
{ |
| 808 |
if (m_pRenderer |
| 809 |
&& (pw != m_pRenderer->getWidth() |
| 810 |
|| (ph!=m_pRenderer->getHeight()))) |
| 811 |
{ |
| 812 |
delete m_pRenderer; |
| 813 |
m_pRenderer=0; |
| 814 |
} |
| 815 |
|
| 816 |
if (!m_pRenderer) |
| 817 |
{ |
| 818 |
m_pRenderer = new ShmRenderer(this, pw, ph, dxpos, dypos); |
| 819 |
|
| 820 |
} else |
| 821 |
m_pRenderer->move(dxpos, dypos); |
| 822 |
m_pDev->grabSetParams(pw, ph, get_palette(x11Display())); |
| 823 |
} |
| 824 |
if(pdx)*pdx=dxpos; |
| 825 |
if(pdy)*pdy=dypos; |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
void V4LWindow::resizeEvent( QResizeEvent * e) |
| 830 |
{ |
| 831 |
QWidget::resizeEvent(e); |
| 832 |
int w=e->size().width(); |
| 833 |
int h=e->size().height(); |
| 834 |
|
| 835 |
if(m_eMode==MultiChannel){ |
| 836 |
mc_curw=w; |
| 837 |
mc_curh=h; |
| 838 |
multichannel(); |
| 839 |
return; |
| 840 |
} |
| 841 |
// printf("received resize event to %d,%d\n", w, h); |
| 842 |
// printf("resizeEvent: %d,%d -> %d,%d ( %d,%d )\n", |
| 843 |
// e->oldSize().width(), e->oldSize().height(), |
| 844 |
// e->size().width(), e->size().height(), |
| 845 |
// width(), height()); |
| 846 |
// if(!isVisible()) |
| 847 |
// { |
| 848 |
// printf("!visible\n"); |
| 849 |
// return; |
| 850 |
// } |
| 851 |
// if(!known_pos) |
| 852 |
// { |
| 853 |
// printf("!known\n"); |
| 854 |
// return; |
| 855 |
// } |
| 856 |
// if(m_bForce4x3 && w!=4*(h-(m_bSubtitles?80:0))/3) |
| 857 |
// { |
| 858 |
// printf("Recalc %d,%d\n", 4*(h-(m_bSubtitles?80:0))/3, h); |
| 859 |
// postResizeEvent(4*(h-(m_bSubtitles?80:0))/3, h); |
| 860 |
// resize(4*(h-(m_bSubtitles?80:0))/3, h); |
| 861 |
// return; |
| 862 |
// } |
| 863 |
if (m_pLabel) |
| 864 |
{ |
| 865 |
m_pLabel->move(0, h-80); |
| 866 |
m_pLabel->resize(w, 80); |
| 867 |
} |
| 868 |
m_pDev->setCapture(0); |
| 869 |
setupPicDimensions(); |
| 870 |
m_pDev->applyCapAClip(0); |
| 871 |
// m_pDev->setCapture(1); |
| 872 |
if (m_timer.isActive()) |
| 873 |
m_timer.stop(); |
| 874 |
if(m_eMode==AvicapRend){ |
| 875 |
avicap_renderer_resize_input(w,h); |
| 876 |
} |
| 877 |
|
| 878 |
m_timer.start(100, TRUE); |
| 879 |
} |
| 880 |
|
| 881 |
void V4LWindow::showEvent( QShowEvent * ) |
| 882 |
{ |
| 883 |
if(m_eMode!=Overlay) |
| 884 |
return; |
| 885 |
if(!known_pos) |
| 886 |
return; |
| 887 |
// avm_usleep(100000); |
| 888 |
// QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 889 |
// m_pDev->setCapAClip(pnt.x(), pnt.y(), width(), height()); |
| 890 |
setupPicDimensions(); |
| 891 |
m_pDev->applyCapAClip(0); |
| 892 |
m_pDev->setCapture(1); |
| 893 |
get_clips(); |
| 894 |
//printf("showEvent()\n"); |
| 895 |
} |
| 896 |
|
| 897 |
void V4LWindow::hideEvent( QHideEvent * qhe ) |
| 898 |
{ |
| 899 |
//printf("hideEvent()\n"); |
| 900 |
m_pDev->setCapture(0); |
| 901 |
} |
| 902 |
|
| 903 |
void V4LWindow::focusInEvent( QFocusEvent * ) |
| 904 |
{ |
| 905 |
//if(!known_pos)return; |
| 906 |
//printf("focusInEvent()\n"); |
| 907 |
get_clips(); |
| 908 |
} |
| 909 |
|
| 910 |
void V4LWindow::focusOutEvent( QFocusEvent * ) |
| 911 |
{ |
| 912 |
//printf("focusOutEvent()\n"); |
| 913 |
get_clips(); |
| 914 |
} |
| 915 |
|
| 916 |
void V4LWindow::paintEvent( QPaintEvent * qpe ) |
| 917 |
{ |
| 918 |
//printf("paintEvent() %d %p %d\n", m_bMoved, m_pRenderer, m_iPainter); |
| 919 |
if (--m_iPainter < 0) |
| 920 |
{ |
| 921 |
m_bMoved = true; |
| 922 |
m_pDev->setCapture(0); |
| 923 |
if (m_timer.isActive()) |
| 924 |
m_timer.stop(); |
| 925 |
m_timer.start(100, TRUE); |
| 926 |
m_iPainter = 1; |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
void V4LWindow::captureAVI() |
| 931 |
{ |
| 932 |
AVMOUT(AVML_INFO, "captureAVI (manual)"); |
| 933 |
captureAVI(NULL); |
| 934 |
} |
| 935 |
|
| 936 |
void V4LWindow::captureAVI(CaptureConfig *capconf) |
| 937 |
{ |
| 938 |
AVMOUT(AVML_INFO, "captureAVI (timertable)"); |
| 939 |
if (m_pCapDialog) |
| 940 |
return; |
| 941 |
m_pCapDialog = new AviCapDialog(this,capconf); |
| 942 |
// QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 943 |
// m_pCapDialog->move(pnt.x(), pnt.y()+height()+40); |
| 944 |
m_pDev->setCapture(0); |
| 945 |
if(m_timer.isActive()) |
| 946 |
m_timer.stop(); |
| 947 |
m_timer.start(100, TRUE); |
| 948 |
m_pCapDialog->show(); |
| 949 |
if(m_bAutoRecord) |
| 950 |
m_pCapDialog->start(); |
| 951 |
// m_pDev->setCapture(0); |
| 952 |
// QMessageBox::information(this, "Sorry", "Not implemented yet!"); |
| 953 |
// m_pDev->setCapture(1); |
| 954 |
} |
| 955 |
|
| 956 |
void V4LWindow::captureBMP() |
| 957 |
{ |
| 958 |
// int w=width(); |
| 959 |
// int h=height(); |
| 960 |
Modes eMode = m_eMode; |
| 961 |
overlay(); |
| 962 |
unsigned int w, h; |
| 963 |
int x, y; |
| 964 |
m_pDev->getCapAClip(&x, &y, &w, &h); |
| 965 |
w &= ~3; |
| 966 |
m_pDev->grabSetParams(w, h, VIDEO_PALETTE_RGB24); |
| 967 |
unsigned char* cp = (unsigned char*)m_pDev->grabCapture(true); |
| 968 |
std::auto_ptr<avm::CImage> im(new avm::CImage(cp, w, -h)); |
| 969 |
|
| 970 |
m_pDev->setCapture(0); |
| 971 |
if (m_timer.isActive()) |
| 972 |
m_timer.stop(); |
| 973 |
m_timer.start(100, TRUE); |
| 974 |
QString qs=QFileDialog::getSaveFileName(QString::null, "*.bmp", this, "Save as BMP file"); |
| 975 |
if (!qs.isNull()) |
| 976 |
im->Dump(qs); |
| 977 |
setMode(eMode); |
| 978 |
} |
| 979 |
|
| 980 |
void V4LWindow::captureJPG() |
| 981 |
{ |
| 982 |
// m_pDev->setCapture(0); |
| 983 |
QMessageBox::information(0, tr( "Sorry" ), tr( "Not implemented yet!" )); |
| 984 |
// m_pDev->setCapture(1); |
| 985 |
} |
| 986 |
|
| 987 |
void V4LWindow::changeChannel(int ch) |
| 988 |
{ |
| 989 |
if (ch == -1) |
| 990 |
ch = 0; |
| 991 |
|
| 992 |
if (m_pEpgWindow==NULL || !m_pEpgWindow->isBlocked(ch+1)) |
| 993 |
setXawtv(ch); |
| 994 |
else |
| 995 |
AVMOUT(AVML_DEBUG, "Channel %d blocked", ch); |
| 996 |
} |
| 997 |
|
| 998 |
void V4LWindow::avicap_renderer_keypress(int sym,int mod) |
| 999 |
{ |
| 1000 |
//printf("sym=%d mod=%d\n",sym,mod); |
| 1001 |
int key=0; |
| 1002 |
if(sym==273){ |
| 1003 |
key=Qt::Key_Up; |
| 1004 |
} |
| 1005 |
else if(sym==274){ |
| 1006 |
key=Qt::Key_Down; |
| 1007 |
} |
| 1008 |
|
| 1009 |
//printf("a1\n"); |
| 1010 |
keyPress(sym,key); |
| 1011 |
//printf("a2\n"); |
| 1012 |
} |
| 1013 |
|
| 1014 |
void V4LWindow::keyPress(int k,int key) |
| 1015 |
{ |
| 1016 |
//avm::Locker lock(m_Mutex); |
| 1017 |
|
| 1018 |
switch(k) |
| 1019 |
{ |
| 1020 |
case 'B': |
| 1021 |
captureBMP(); |
| 1022 |
break; |
| 1023 |
case 'C': |
| 1024 |
config(); |
| 1025 |
break; |
| 1026 |
case 'Q': |
| 1027 |
close(); |
| 1028 |
break; |
| 1029 |
case ']': |
| 1030 |
multichannel_increase_tiles(true); |
| 1031 |
break; |
| 1032 |
case '[': |
| 1033 |
multichannel_increase_tiles(false); |
| 1034 |
break; |
| 1035 |
case '+': |
| 1036 |
multichannel_increase_speed(true); |
| 1037 |
break; |
| 1038 |
case '-': |
| 1039 |
multichannel_increase_speed(false); |
| 1040 |
break; |
| 1041 |
} |
| 1042 |
|
| 1043 |
bool xawtv_key=false; |
| 1044 |
|
| 1045 |
for (unsigned i = 0; i < xawtvstations.size(); i++) |
| 1046 |
{ |
| 1047 |
//printf("key %d %d\n", xawtvstations[i].key, k); |
| 1048 |
if (xawtvstations[i].key == k){ |
| 1049 |
if(m_pEpgWindow==NULL || !m_pEpgWindow->isBlocked(i+1)){ |
| 1050 |
setXawtv(i); |
| 1051 |
} |
| 1052 |
xawtv_key=true; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
//alternate keybindings |
| 1057 |
if(!xawtv_key){ |
| 1058 |
if(k>='1' && k<='9'){ |
| 1059 |
int chnr=k-48; |
| 1060 |
if(m_pEpgWindow==NULL || !m_pEpgWindow->isBlocked(chnr)){ |
| 1061 |
setXawtv(chnr-1); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
if(key==Qt::Key_Down){ |
| 1067 |
int station=last_station; |
| 1068 |
do{ |
| 1069 |
station--; |
| 1070 |
if(station<0){ |
| 1071 |
station=xawtvstations.size()-1; |
| 1072 |
} |
| 1073 |
}while(station!=last_station && (m_pEpgWindow && m_pEpgWindow->isBlocked(station+1))); |
| 1074 |
|
| 1075 |
setXawtv(station); |
| 1076 |
} |
| 1077 |
else if(key==Qt::Key_Up){ |
| 1078 |
int station=last_station; |
| 1079 |
do{ |
| 1080 |
station++; |
| 1081 |
if(station>(int)xawtvstations.size()-1){ |
| 1082 |
station=0; |
| 1083 |
} |
| 1084 |
}while(station!=last_station && (m_pEpgWindow && m_pEpgWindow->isBlocked(station+1))); |
| 1085 |
|
| 1086 |
setXawtv(station); |
| 1087 |
} |
| 1088 |
|
| 1089 |
|
| 1090 |
} |
| 1091 |
|
| 1092 |
void V4LWindow::keyPressEvent( QKeyEvent * e ) |
| 1093 |
{ |
| 1094 |
int k = toupper(e->ascii()); |
| 1095 |
int key=e->key(); |
| 1096 |
|
| 1097 |
keyPress(k,key); |
| 1098 |
|
| 1099 |
} |
| 1100 |
|
| 1101 |
void V4LWindow::setupDevice() |
| 1102 |
{ |
| 1103 |
// int field_width, field_height; |
| 1104 |
// default_dimensions(field_width, field_height); |
| 1105 |
// v4l->setCapAClip(102,110,field_width,field_height); |
| 1106 |
// v4l->addCapAClip(0,248,384,288); |
| 1107 |
// v4l->applyCapAClip(0); |
| 1108 |
AVMOUT(AVML_DEBUG, "setupDevice()"); |
| 1109 |
|
| 1110 |
// I'm not sure why - but apply has to call this |
| 1111 |
// method twice to get apllied Norm & Channel change |
| 1112 |
// at the same time - if anyone knows how to fix this |
| 1113 |
// let us know - [email protected] FIXME |
| 1114 |
int i = 2; |
| 1115 |
while (i--) |
| 1116 |
{ |
| 1117 |
m_pDev->setChannelNorm(RI("ColorMode", 0)); |
| 1118 |
m_pDev->setChannel(RI("Channel", 1)); |
| 1119 |
} |
| 1120 |
AVMOUT(AVML_DEBUG, "setupDevice() - channel is set"); |
| 1121 |
|
| 1122 |
m_pDev->setAudioMute(0); |
| 1123 |
m_pDev->setAudioVolume(65535);//? |
| 1124 |
m_pDev->setAudioBalance(100); |
| 1125 |
|
| 1126 |
int amode; |
| 1127 |
switch (RI("SndChannels", 0)) |
| 1128 |
{ |
| 1129 |
default: |
| 1130 |
case 0: |
| 1131 |
amode = VIDEO_SOUND_MONO; |
| 1132 |
break; |
| 1133 |
case 1: |
| 1134 |
amode = VIDEO_SOUND_STEREO; |
| 1135 |
break; |
| 1136 |
case 2: |
| 1137 |
amode = VIDEO_SOUND_LANG1; |
| 1138 |
break; |
| 1139 |
case 3: |
| 1140 |
amode = VIDEO_SOUND_LANG2; |
| 1141 |
break; |
| 1142 |
} |
| 1143 |
m_pDev->setAudioMode(amode); |
| 1144 |
|
| 1145 |
m_pDev->setPicBrightness(RI("Image\\Brightness", 0)); |
| 1146 |
m_pDev->setPicConstrast(RI("Image\\Contrast", 255)); |
| 1147 |
m_pDev->setPicColor(RI("Image\\Color", 255)); |
| 1148 |
m_pDev->setPicHue(RI("Image\\Hue", 0)); |
| 1149 |
|
| 1150 |
int r = RI("Resolution", 0); |
| 1151 |
|
| 1152 |
AVMOUT(AVML_DEBUG, "setupDevice() starting capture"); |
| 1153 |
if (m_eMode == Overlay) |
| 1154 |
m_pDev->setCapture(1); |
| 1155 |
|
| 1156 |
get_clips(); |
| 1157 |
AVMOUT(AVML_DEBUG, "setupDevice() done"); |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
void V4LWindow::showsub() |
| 1162 |
{ |
| 1163 |
hidePopup(); |
| 1164 |
m_bSubtitles=!m_bSubtitles; |
| 1165 |
AVMOUT(AVML_DEBUG, "showsub() size %dx%d, set m_bSubtitles to %d", |
| 1166 |
width(), height(), (int)m_bSubtitles); |
| 1167 |
setupSubtitles(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
void V4LWindow::setupSubtitles() |
| 1171 |
{ |
| 1172 |
if(m_bSubtitles) |
| 1173 |
{ |
| 1174 |
m_pCC=new ClosedCaption(m_pDev); |
| 1175 |
m_pLabel=new QLabel(this); |
| 1176 |
int w=width(); |
| 1177 |
int h=height(); |
| 1178 |
// if(!m_bForce4x3) |
| 1179 |
resize(w, h+80); |
| 1180 |
m_pLabel->move(0, h); |
| 1181 |
m_pLabel->resize(w, 80); |
| 1182 |
m_pLabel->setAlignment(Qt::AlignCenter); |
| 1183 |
m_pLabel->show(); |
| 1184 |
m_cctimer.start(500); |
| 1185 |
} |
| 1186 |
else |
| 1187 |
{ |
| 1188 |
m_cctimer.stop(); |
| 1189 |
delete m_pCC; |
| 1190 |
delete m_pLabel; |
| 1191 |
m_pCC=0; |
| 1192 |
m_pLabel=0; |
| 1193 |
resize(width(), height() - 80); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
|
| 1197 |
void V4LWindow::startTimer() |
| 1198 |
{ |
| 1199 |
timertable(); |
| 1200 |
m_pTimerTable->startTimer(true); |
| 1201 |
} |
| 1202 |
|
| 1203 |
void V4LWindow::timertable() |
| 1204 |
{ |
| 1205 |
if (!m_pTimerTable) |
| 1206 |
{ |
| 1207 |
AVMOUT(AVML_DEBUG, "Timertable started"); |
| 1208 |
m_pTimerTable=new TimerTable(this,m_pDev,this); |
| 1209 |
QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 1210 |
m_pTimerTable->move(pnt.x(), pnt.y()+height()+20); |
| 1211 |
} |
| 1212 |
|
| 1213 |
if (m_pTimerTable->isVisible()) |
| 1214 |
m_pTimerTable->hide(); |
| 1215 |
else |
| 1216 |
m_pTimerTable->show(); |
| 1217 |
} |
| 1218 |
|
| 1219 |
void V4LWindow::epgwindow() |
| 1220 |
{ |
| 1221 |
if (!m_pEpgWindow) |
| 1222 |
{ |
| 1223 |
AVMOUT(AVML_DEBUG, "EPGWindow started"); |
| 1224 |
timertable(); |
| 1225 |
m_pEpgWindow=new EpgWindow(this,m_pTimerTable); |
| 1226 |
QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 1227 |
m_pEpgWindow->move(pnt.x(), pnt.y()+height()+20); |
| 1228 |
m_pTimerTable->setEpgWindow(m_pEpgWindow); |
| 1229 |
} |
| 1230 |
|
| 1231 |
if (m_pEpgWindow->isVisible()) |
| 1232 |
m_pEpgWindow->hide(); |
| 1233 |
else |
| 1234 |
m_pEpgWindow->show(); |
| 1235 |
} |
| 1236 |
|
| 1237 |
|
| 1238 |
void V4LWindow::picprop() |
| 1239 |
{ |
| 1240 |
AVMOUT(AVML_DEBUG, "picprop()"); |
| 1241 |
|
| 1242 |
if (!m_pPicConfig) |
| 1243 |
{ |
| 1244 |
m_pPicConfig = new PicturePropDialog(m_pDev); |
| 1245 |
QPoint pnt = mapToGlobal(QPoint(0,0)); |
| 1246 |
m_pPicConfig->move(pnt.x(), pnt.y()+height()+20); |
| 1247 |
} |
| 1248 |
|
| 1249 |
if (m_pPicConfig->isVisible()) |
| 1250 |
m_pPicConfig->hide(); |
| 1251 |
else |
| 1252 |
m_pPicConfig->show(); |
| 1253 |
} |
| 1254 |
|
| 1255 |
static int x11_error = 0; |
| 1256 |
typedef int (*handlerproc) (Display*, XErrorEvent*); |
| 1257 |
static int x11_error_dev_null(Display * dpy, XErrorEvent * event) |
| 1258 |
{ |
| 1259 |
x11_error++; |
| 1260 |
// if (debug > 1) |
| 1261 |
// fprintf(stderr," x11-error\n"); |
| 1262 |
return 0; |
| 1263 |
} |
| 1264 |
|
| 1265 |
void V4LWindow::add_clip(int x1, int y1, int x2, int y2) |
| 1266 |
{ |
| 1267 |
if (oc_count >= (int) (sizeof(oc)/sizeof(oc[0]))) |
| 1268 |
return; |
| 1269 |
if (oc[oc_count].x1 != x1 || oc[oc_count].y1 != y1 || |
| 1270 |
oc[oc_count].x2 != x2 || oc[oc_count].y2 != y2) { |
| 1271 |
conf = 1; |
| 1272 |
} |
| 1273 |
oc[oc_count].x1 = x1; |
| 1274 |
oc[oc_count].y1 = y1; |
| 1275 |
oc[oc_count].x2 = x2; |
| 1276 |
oc[oc_count].y2 = y2; |
| 1277 |
oc_count++; |
| 1278 |
} |
| 1279 |
|
| 1280 |
bool V4LWindow::x11Event( XEvent * e) |
| 1281 |
{ |
| 1282 |
#if 0 |
| 1283 |
switch(e->type) |
| 1284 |
{ |
| 1285 |
case VisibilityNotify: |
| 1286 |
printf("VisibilityNotify\n"); |
| 1287 |
if (e->xvisibility.window == handle()) |
| 1288 |
{ |
| 1289 |
visibility = e->xvisibility.state; |
| 1290 |
// get_clips(); |
| 1291 |
} |
| 1292 |
break; |
| 1293 |
case MapNotify: |
| 1294 |
printf("MapNotify\n"); |
| 1295 |
wmap=1; |
| 1296 |
break; |
| 1297 |
case UnmapNotify: |
| 1298 |
printf("UnmapNotify\n"); |
| 1299 |
wmap=0; |
| 1300 |
break; |
| 1301 |
case KeyPress: |
| 1302 |
case KeyRelease: |
| 1303 |
case ButtonPress: |
| 1304 |
case ButtonRelease: |
| 1305 |
case MotionNotify: |
| 1306 |
case EnterNotify: |
| 1307 |
case LeaveNotify: |
| 1308 |
case FocusIn: |
| 1309 |
case FocusOut: |
| 1310 |
case KeymapNotify: |
| 1311 |
case Expose: |
| 1312 |
case GraphicsExpose: |
| 1313 |
case NoExpose: |
| 1314 |
case CreateNotify: |
| 1315 |
case DestroyNotify: |
| 1316 |
case MapRequest: |
| 1317 |
case ReparentNotify: |
| 1318 |
case ConfigureNotify: |
| 1319 |
case ConfigureRequest: |
| 1320 |
case GravityNotify: |
| 1321 |
case ResizeRequest: |
| 1322 |
case CirculateNotify: |
| 1323 |
case CirculateRequest: |
| 1324 |
case PropertyNotify: |
| 1325 |
case SelectionClear: |
| 1326 |
case SelectionRequest: |
| 1327 |
case SelectionNotify: |
| 1328 |
case ColormapNotify: |
| 1329 |
case ClientMessage: |
| 1330 |
case MappingNotify: |
| 1331 |
// printf("Event %d\n", e->type); |
| 1332 |
break; |
| 1333 |
} |
| 1334 |
get_clips(); |
| 1335 |
|
| 1336 |
#endif |
| 1337 |
return QWidget::x11Event(e); |
| 1338 |
} |
| 1339 |
|
| 1340 |
void V4LWindow::get_clips() |
| 1341 |
{ |
| 1342 |
if (m_eMode != Overlay || !isVisible()) |
| 1343 |
return; |
| 1344 |
//printf("GETCLIPS\n"); |
| 1345 |
|
| 1346 |
int x1,y1,x2,y2,lastcount; |
| 1347 |
XWindowAttributes wts; |
| 1348 |
Window root, me, rroot, parent, *children; |
| 1349 |
uint nchildren, i; |
| 1350 |
int wx, wy; |
| 1351 |
conf=0; |
| 1352 |
QPoint pnt=mapToGlobal(QPoint(0,0)); |
| 1353 |
wx=pnt.x(); |
| 1354 |
wy=pnt.y(); |
| 1355 |
Display * dpy=x11Display(); |
| 1356 |
root=DefaultRootWindow(dpy); |
| 1357 |
me = (Window)handle(); |
| 1358 |
m_pDev->setCapture(0); |
| 1359 |
XSelectInput(dpy, me, ~0); |
| 1360 |
XSelectInput(dpy, root, VisibilityChangeMask | ExposureMask); |
| 1361 |
/* |
| 1362 |
XGetWindowAttributes(dpy, me, &wts); |
| 1363 |
wts.your_event_mask=~0; |
| 1364 |
*/ |
| 1365 |
// XSetWindowAttributes xsw; |
| 1366 |
// xsw.event_mask=~0; |
| 1367 |
// XChangeWindowAttributes(dpy, me, CWEventMask, &xsw); |
| 1368 |
// GC gc=qt_xget_readonly_gc(false); |
| 1369 |
// XSetGraphicsExposures( dpy, gc, TRUE ); |
| 1370 |
// XGCValues xcg; |
| 1371 |
// xcg.graphics_exposures=true; |
| 1372 |
// gc=XDefaultGC(dpy, me, GCGraphicsExposures, &xcg); |
| 1373 |
|
| 1374 |
/* |
| 1375 |
if (wmap |
| 1376 |
&& visibility != VisibilityFullyObscured |
| 1377 |
&& visibility != VisibilityPartiallyObscured) |
| 1378 |
{ |
| 1379 |
oc_count = 0; |
| 1380 |
return; |
| 1381 |
} |
| 1382 |
*/ |
| 1383 |
handlerproc old_handler = XSetErrorHandler(x11_error_dev_null); |
| 1384 |
|
| 1385 |
// if (debug > 1) |
| 1386 |
// fprintf(stderr," getclips"); |
| 1387 |
lastcount = oc_count; |
| 1388 |
oc_count = 0; |
| 1389 |
|
| 1390 |
if (wx<0) |
| 1391 |
add_clip(0, 0, (uint)(-wx), height()); |
| 1392 |
if (wy<0) |
| 1393 |
add_clip(0, 0, width(), (uint)(-wy)); |
| 1394 |
// if ((wx+width()) > swidth) |
| 1395 |
// add_clip(swidth-wx, 0, width(), height()); |
| 1396 |
// if ((wy+height()) > sheight) |
| 1397 |
// add_clip(0, sheight-wy, width(), height()); |
| 1398 |
|
| 1399 |
// find parent |
| 1400 |
for (;;) { |
| 1401 |
XQueryTree(dpy, me, &rroot, &parent, &children, &nchildren); |
| 1402 |
if (children) |
| 1403 |
XFree((char *) children); |
| 1404 |
/* fprintf(stderr,"me=0x%x, parent=0x%x\n",me,parent); */ |
| 1405 |
if (root == parent || me == parent) |
| 1406 |
break; |
| 1407 |
me = parent; |
| 1408 |
} |
| 1409 |
|
| 1410 |
// now find all clippping parts |
| 1411 |
XQueryTree(dpy, root, &rroot, &parent, &children, &nchildren); |
| 1412 |
// printf("%d children to check\n", nchildren); |
| 1413 |
for (i = 0; i < nchildren && children[i] != me; i++) |
| 1414 |
;/* empty */ |
| 1415 |
for (i++; i<nchildren; i++) { |
| 1416 |
XGetWindowAttributes(dpy, children[i], &wts); |
| 1417 |
if (!(wts.map_state & IsViewable)) |
| 1418 |
{ |
| 1419 |
// printf("child %d, (%d,%d)x(%d,%d): skipping\n", |
| 1420 |
// i, wts.x, wts.y, wts.width, wts.height); |
| 1421 |
continue; |
| 1422 |
} |
| 1423 |
x1=wts.x-wx; |
| 1424 |
y1=wts.y-wy; |
| 1425 |
x2=x1+wts.width+2*wts.border_width; |
| 1426 |
y2=y1+wts.height+2*wts.border_width; |
| 1427 |
if ((x2 < 0) || (x1 > (int)width()) || |
| 1428 |
(y2 < 0) || (y1 > (int)height())) |
| 1429 |
{ |
| 1430 |
// printf("child %d, (%d,%d)x(%d,%d): not overlapping\n", |
| 1431 |
// i, wts.x, wts.y, wts.width, wts.height); |
| 1432 |
continue; |
| 1433 |
} |
| 1434 |
if (x1<0) x1=0; |
| 1435 |
if (y1<0) y1=0; |
| 1436 |
if (x2>(int)width()) x2=width(); |
| 1437 |
if (y2>(int)height()) y2=height(); |
| 1438 |
add_clip(x1, y1, x2, y2); |
| 1439 |
} |
| 1440 |
XFree((char *) children); |
| 1441 |
|
| 1442 |
if (lastcount != oc_count) |
| 1443 |
conf=1; |
| 1444 |
|
| 1445 |
if(conf) |
| 1446 |
{ |
| 1447 |
m_pDev->resetCapAClip(); |
| 1448 |
int dx, dy; |
| 1449 |
setupPicDimensions(&dx, &dy); |
| 1450 |
for(int i=0; i<oc_count; i++) |
| 1451 |
{ |
| 1452 |
// printf("Adding clip (%d,%d)x(%d,%d)\n", |
| 1453 |
// oc[i].x1, oc[i].y1, oc[i].x2, oc[i].y2); |
| 1454 |
m_pDev->addCapAClip(-dx+oc[i].x1, -dy+oc[i].y1, -dx+oc[i].x2, -dy+oc[i].y2); |
| 1455 |
} |
| 1456 |
// printf("Applying %d clips\n", oc_count); |
| 1457 |
m_pDev->applyCapAClip(oc_count); |
| 1458 |
m_pDev->setCapture(1); |
| 1459 |
|
| 1460 |
// if(m_timer.isActive()) |
| 1461 |
// m_timer.stop(); |
| 1462 |
// m_timer.start(100, TRUE); |
| 1463 |
} |
| 1464 |
else |
| 1465 |
m_pDev->setCapture(1); |
| 1466 |
|
| 1467 |
XSetErrorHandler(old_handler); |
| 1468 |
} |
| 1469 |
|
| 1470 |
void V4LWindow::updatesub() |
| 1471 |
{ |
| 1472 |
// printf("updatesub()\n"); |
| 1473 |
if(!m_pCC) |
| 1474 |
return; |
| 1475 |
m_pCC->lock(); |
| 1476 |
char buf[256]; |
| 1477 |
strncpy(buf, m_pCC->getBuffer(), sizeof(buf) - 1); |
| 1478 |
m_pCC->unlock(); |
| 1479 |
// printf("%s\n", buf); |
| 1480 |
assert(m_pLabel); |
| 1481 |
assert(m_bSubtitles); |
| 1482 |
m_pLabel->setText(buf); |
| 1483 |
} |
| 1484 |
|
| 1485 |
void V4LWindow::overlay() |
| 1486 |
{ |
| 1487 |
show(); |
| 1488 |
avm::Locker lock(m_Mutex); |
| 1489 |
printf("overlay()\n"); |
| 1490 |
m_eMode=Overlay; |
| 1491 |
m_pDev->setCapture(1); |
| 1492 |
|
| 1493 |
//stop shm renderer |
| 1494 |
m_CaptureTimer.stop(); |
| 1495 |
delete m_pRenderer; |
| 1496 |
m_pRenderer=0; |
| 1497 |
|
| 1498 |
avicap_renderer_stop(); |
| 1499 |
multichannel_stop(); |
| 1500 |
} |
| 1501 |
|
| 1502 |
void V4LWindow::preview() |
| 1503 |
{ |
| 1504 |
int pw, ph, dx, dy; |
| 1505 |
show(); |
| 1506 |
avm::Locker lock(m_Mutex); |
| 1507 |
printf("preview()\n"); |
| 1508 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1509 |
m_eMode=Preview; |
| 1510 |
|
| 1511 |
avicap_renderer_stop(); |
| 1512 |
multichannel_stop(); |
| 1513 |
|
| 1514 |
m_pDev->setCapture(0); |
| 1515 |
m_pDev->grabSetParams(pw, ph, get_palette(x11Display())); |
| 1516 |
connect(&m_CaptureTimer, SIGNAL(timeout()), this, SLOT(preview_display())); |
| 1517 |
m_CaptureTimer.start(30); |
| 1518 |
m_eMode=Preview; |
| 1519 |
m_pDev->setCapture(0); |
| 1520 |
delete m_pRenderer; |
| 1521 |
|
| 1522 |
printf("new shm renderer %d %d\n",pw,ph); |
| 1523 |
|
| 1524 |
m_pRenderer=new ShmRenderer(this, pw, ph, dx, dy); |
| 1525 |
|
| 1526 |
connect(&m_CaptureTimer, SIGNAL(timeout()), this, SLOT(preview_display())); |
| 1527 |
m_CaptureTimer.start(40); |
| 1528 |
} |
| 1529 |
|
| 1530 |
void V4LWindow::deinterlaced_preview() |
| 1531 |
{ |
| 1532 |
if(!freq.HaveMMXEXT()) |
| 1533 |
return preview(); |
| 1534 |
printf("deint_preview()\n"); |
| 1535 |
show(); |
| 1536 |
avm::Locker lock(m_Mutex); |
| 1537 |
int pw, ph, dx, dy; |
| 1538 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1539 |
|
| 1540 |
avicap_renderer_stop(); |
| 1541 |
multichannel_stop(); |
| 1542 |
|
| 1543 |
m_eMode=DeinterlacedPreview; |
| 1544 |
m_pDev->setCapture(0); |
| 1545 |
m_pDev->grabSetParams(pw, ph, get_palette(x11Display())); |
| 1546 |
delete m_pRenderer; |
| 1547 |
m_pRenderer = new ShmRenderer(this, pw, ph, dx, dy); |
| 1548 |
connect(&m_CaptureTimer, SIGNAL(timeout()), this, SLOT(preview_display())); |
| 1549 |
m_CaptureTimer.start(30); |
| 1550 |
} |
| 1551 |
|
| 1552 |
void V4LWindow::avicap_renderer() |
| 1553 |
{ |
| 1554 |
int pw, ph, dx, dy; |
| 1555 |
avm::Locker lock(m_Mutex); |
| 1556 |
printf("avicap-renderer()\n"); |
| 1557 |
|
| 1558 |
m_eMode=AvicapRend; |
| 1559 |
|
| 1560 |
//stop shm renderer |
| 1561 |
m_CaptureTimer.stop(); |
| 1562 |
delete m_pRenderer; |
| 1563 |
m_pRenderer=0; |
| 1564 |
|
| 1565 |
multichannel_stop(); |
| 1566 |
|
| 1567 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1568 |
|
| 1569 |
fsr_width=pw; |
| 1570 |
fsr_height=ph; |
| 1571 |
|
| 1572 |
printf("New avicap- renderer %d %d\n",pw,ph); |
| 1573 |
|
| 1574 |
delete fs_renderer; |
| 1575 |
fs_renderer = 0; |
| 1576 |
|
| 1577 |
void *dpy = XOpenDisplay(0); |
| 1578 |
fs_renderer = new avm::AvicapRenderer(dpy); |
| 1579 |
fs_renderer->setV4LWindow(this); |
| 1580 |
fs_renderer->setSize(pw,ph); |
| 1581 |
fs_renderer->setYUVrendering(true); |
| 1582 |
|
| 1583 |
m_pDev->setCapture(0); |
| 1584 |
//m_pDev->grabSetParams(pw, ph, get_palette(x11Display())); |
| 1585 |
|
| 1586 |
Colorspaces colorspace=(enum Colorspaces)RI("Colorspace", 0); |
| 1587 |
|
| 1588 |
colorspace=cspYUY2; |
| 1589 |
Colorspaces recording_colorspace=colorspace; |
| 1590 |
|
| 1591 |
if (colorspace==cspRGB24 && rgb_method==0){ |
| 1592 |
printf("rgb24 renderer - rgb24 to rgb24\n"); |
| 1593 |
m_pDev->grabSetParams(pw, ph, VIDEO_PALETTE_RGB24); |
| 1594 |
fs_renderer->setYUVrendering(false); |
| 1595 |
} |
| 1596 |
else if(colorspace==cspRGB24 && rgb_method==1){ |
| 1597 |
printf("rgb24 renderer - grab rgb24 to yuv overlay,automatic conv.\n"); |
| 1598 |
m_pDev->grabSetParams(pw, ph, VIDEO_PALETTE_RGB24); |
| 1599 |
// recording_colorspace=cspYUY2; |
| 1600 |
} |
| 1601 |
else if(colorspace==cspRGB24 && rgb_method==2){ |
| 1602 |
printf("rgb24 renderer - grab rgb24 to yuv overlay, I do conv.\n"); |
| 1603 |
m_pDev->grabSetParams(pw, ph, VIDEO_PALETTE_RGB24); |
| 1604 |
recording_colorspace=cspYUY2; |
| 1605 |
} |
| 1606 |
else if(colorspace==cspYV12){ |
| 1607 |
printf("yv12 renderer\n"); |
| 1608 |
m_pDev->grabSetParams(pw, ph, VIDEO_PALETTE_YUV420P); |
| 1609 |
} |
| 1610 |
else if(colorspace==cspYUY2){ |
| 1611 |
printf("yuy2 renderer\n"); |
| 1612 |
m_pDev->grabSetParams(pw, ph, VIDEO_PALETTE_YUV422); |
| 1613 |
} |
| 1614 |
else{ |
| 1615 |
printf("error - not this mode\n"); |
| 1616 |
return; |
| 1617 |
} |
| 1618 |
|
| 1619 |
//connect(&m_CaptureTimer, SIGNAL(timeout()), this, SLOT(avicap_renderer_display())); |
| 1620 |
//m_CaptureTimer.start(30); |
| 1621 |
|
| 1622 |
m_eMode=AvicapRend; |
| 1623 |
// m_pDev->setCapture(0); |
| 1624 |
|
| 1625 |
fs_renderer->setRecordingColorSpace(recording_colorspace); |
| 1626 |
|
| 1627 |
fs_renderer->createVideoRenderer(); |
| 1628 |
printf("after fsrend\n"); |
| 1629 |
|
| 1630 |
connect(&m_avicapTimer, SIGNAL(timeout()), this, SLOT(avicap_renderer_display())); |
| 1631 |
m_avicapTimer.start(40); |
| 1632 |
|
| 1633 |
hide(); |
| 1634 |
|
| 1635 |
} |
| 1636 |
|
| 1637 |
void V4LWindow::multichannel_increase_speed(bool inc) |
| 1638 |
{ |
| 1639 |
if(inc) |
| 1640 |
mc_switch/=2; |
| 1641 |
else |
| 1642 |
mc_switch*=2; |
| 1643 |
|
| 1644 |
if(mc_switch<1) |
| 1645 |
mc_switch=1; |
| 1646 |
|
| 1647 |
multichannel(); |
| 1648 |
} |
| 1649 |
|
| 1650 |
void V4LWindow::multichannel_increase_tiles(bool inc) |
| 1651 |
{ |
| 1652 |
if(inc) |
| 1653 |
mc_tiles++; |
| 1654 |
else |
| 1655 |
mc_tiles--; |
| 1656 |
|
| 1657 |
if(mc_tiles<1) |
| 1658 |
mc_tiles=1; |
| 1659 |
|
| 1660 |
multichannel(); |
| 1661 |
} |
| 1662 |
|
| 1663 |
void V4LWindow::multichannel_stop() |
| 1664 |
{ |
| 1665 |
m_multichannelTimer.stop(); |
| 1666 |
} |
| 1667 |
|
| 1668 |
void V4LWindow::multichannel() |
| 1669 |
{ |
| 1670 |
int pw, ph, dx, dy; |
| 1671 |
avm::Locker lock(m_Mutex); |
| 1672 |
printf("multichannel()\n"); |
| 1673 |
|
| 1674 |
if(m_eMode!=MultiChannel){ |
| 1675 |
m_eMode=MultiChannel; |
| 1676 |
|
| 1677 |
//stop shm renderer |
| 1678 |
m_CaptureTimer.stop(); |
| 1679 |
delete m_pRenderer; |
| 1680 |
m_pRenderer=0; |
| 1681 |
|
| 1682 |
avicap_renderer_stop(); |
| 1683 |
|
| 1684 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1685 |
|
| 1686 |
mc_oldw=pw; |
| 1687 |
mc_oldh=ph; |
| 1688 |
mc_curw=pw; |
| 1689 |
mc_curh=ph; |
| 1690 |
|
| 1691 |
if(last_station<0){ |
| 1692 |
changeChannel(0); |
| 1693 |
} |
| 1694 |
mc_startchannel=last_station; |
| 1695 |
mc_curchannel=0; |
| 1696 |
mc_count=0; |
| 1697 |
} |
| 1698 |
|
| 1699 |
mc_grabw=mc_curw/mc_tiles; |
| 1700 |
mc_grabh=mc_curh/mc_tiles; |
| 1701 |
|
| 1702 |
printf("tiles=%d speed=%d\n",mc_tiles,mc_switch); |
| 1703 |
m_pDev->setCapture(0); |
| 1704 |
m_pDev->grabSetParams(mc_grabw, mc_grabh, get_palette(x11Display())); |
| 1705 |
|
| 1706 |
m_eMode=MultiChannel; |
| 1707 |
|
| 1708 |
connect(&m_multichannelTimer, SIGNAL(timeout()), this, SLOT(multichannel_display())); |
| 1709 |
m_multichannelTimer.start(40); |
| 1710 |
|
| 1711 |
} |
| 1712 |
|
| 1713 |
void V4LWindow::maximize() |
| 1714 |
{ |
| 1715 |
} |
| 1716 |
|
| 1717 |
void V4LWindow::fullscreen() |
| 1718 |
{ |
| 1719 |
} |
| 1720 |
|
| 1721 |
void V4LWindow::avicap_renderer_resize_input(int w,int h) |
| 1722 |
{ |
| 1723 |
int pw, ph, dx, dy; |
| 1724 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1725 |
printf("avicap-renderer resize input w=%d h=%d pw=%d ph=%d()\n",w,h,pw,ph); |
| 1726 |
|
| 1727 |
avicap_renderer(); |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
void V4LWindow::avicap_renderer_display() |
| 1733 |
{ |
| 1734 |
avm::Locker lock(m_Mutex); |
| 1735 |
// printf("avicap_renderer_display()\n"); |
| 1736 |
const char* z=m_pDev->grabCapture(false); |
| 1737 |
int pw, ph, dx, dy; |
| 1738 |
//getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1739 |
pw=fsr_width; |
| 1740 |
ph=fsr_height; |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
// printf("pw=%d ph=%d\n",pw,ph); |
| 1745 |
|
| 1746 |
avm::CImage *im; |
| 1747 |
//Colorspaces colorspace=(enum Colorspaces)RI("Colorspace", 0); |
| 1748 |
Colorspaces colorspace=cspYUY2; |
| 1749 |
BitmapInfo bi; |
| 1750 |
if(colorspace==cspRGB24 && rgb_method==0){ |
| 1751 |
im=new avm::CImage((const uint8_t *)z,pw,ph); |
| 1752 |
} |
| 1753 |
else if(colorspace==cspRGB24 && rgb_method==1){ |
| 1754 |
//convert rgb24 to yuv automatic |
| 1755 |
im=new avm::CImage((const uint8_t *)z,pw,ph); |
| 1756 |
} |
| 1757 |
else if(colorspace==cspRGB24 && rgb_method==2){ |
| 1758 |
//convert rgb24 to yuv, do-it-yourself |
| 1759 |
const avm::CImage *im0=new avm::CImage((const uint8_t *)z,pw,ph); |
| 1760 |
bi=BitmapInfo(pw,ph,fccYUY2); |
| 1761 |
im=new avm::CImage(im0,&bi); |
| 1762 |
} |
| 1763 |
else if(colorspace==cspYV12){ |
| 1764 |
// printf("yuv renderer\n"); |
| 1765 |
bi=BitmapInfo(pw,ph,fccYV12); |
| 1766 |
|
| 1767 |
im=new avm::CImage(&bi,(const uint8_t *)z,false); |
| 1768 |
} |
| 1769 |
else if(colorspace==cspYUY2){ |
| 1770 |
// printf("yuv renderer\n"); |
| 1771 |
bi=BitmapInfo(pw,ph,fccYUY2); |
| 1772 |
im=new avm::CImage(&bi,(const uint8_t *)z,false); |
| 1773 |
} |
| 1774 |
else{ |
| 1775 |
printf("error - not this mode\n"); |
| 1776 |
return; |
| 1777 |
} |
| 1778 |
|
| 1779 |
fs_renderer->drawFrame(im); |
| 1780 |
} |
| 1781 |
|
| 1782 |
void V4LWindow::preview_display() |
| 1783 |
{ |
| 1784 |
avm::Locker lock(m_Mutex); |
| 1785 |
// printf("preview_display()\n"); |
| 1786 |
const char* z=m_pDev->grabCapture(false); |
| 1787 |
QPainter qp(this); |
| 1788 |
m_pRenderer->draw(&qp, z, (m_eMode==DeinterlacedPreview)); |
| 1789 |
|
| 1790 |
#if 0 |
| 1791 |
//little bit of osd |
| 1792 |
if(last_station>=0 && last_station<xawtvstations.size()){ |
| 1793 |
qp.setPen(QColor(0,255,0)); |
| 1794 |
qp.drawText(30,30,xawtvstations[last_station].sname.c_str()); |
| 1795 |
} |
| 1796 |
#endif |
| 1797 |
|
| 1798 |
m_pRenderer->sync(); |
| 1799 |
|
| 1800 |
|
| 1801 |
/* |
| 1802 |
int pw, ph, dx, dy; |
| 1803 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1804 |
|
| 1805 |
int bpl=pw*4; |
| 1806 |
QImage* i=new QImage(pw, ph, 32); |
| 1807 |
for(int y=0; y<ph; y++) |
| 1808 |
{ |
| 1809 |
QRgb *line = (QRgb *)i->scanLine(y); |
| 1810 |
memcpy(line, z+bpl*y, bpl); |
| 1811 |
} |
| 1812 |
QPainter p(this); |
| 1813 |
p.drawImage(dx, dy, *i); |
| 1814 |
delete i; |
| 1815 |
*/ |
| 1816 |
} |
| 1817 |
|
| 1818 |
void V4LWindow::multichannel_display() |
| 1819 |
{ |
| 1820 |
avm::Locker lock(m_Mutex); |
| 1821 |
// printf("preview_display()\n"); |
| 1822 |
char* z=m_pDev->grabCapture(false); |
| 1823 |
QPainter qp(this); |
| 1824 |
|
| 1825 |
int pw, ph, dx, dy; |
| 1826 |
getOverlaySizeAndOffset(&pw, &ph, &dx, &dy); |
| 1827 |
|
| 1828 |
Display *dpy = x11Display(); |
| 1829 |
//Visual *vis = (Visual*)dev->x11Visual(); |
| 1830 |
|
| 1831 |
int bit_depth = avm::GetPhysicalDepth(dpy); |
| 1832 |
|
| 1833 |
const QImage pix=QImage((uchar *)z,mc_grabw,mc_grabh,bit_depth,NULL,0,QImage::IgnoreEndian); |
| 1834 |
|
| 1835 |
int max_channels=mc_tiles*mc_tiles; |
| 1836 |
|
| 1837 |
int ys=mc_curchannel/mc_tiles; |
| 1838 |
int xs=mc_curchannel%mc_tiles; |
| 1839 |
int xo=xs*mc_grabw; |
| 1840 |
int yo=ys*mc_grabh; |
| 1841 |
|
| 1842 |
qp.drawImage(xo,yo,pix); |
| 1843 |
|
| 1844 |
mc_count++; |
| 1845 |
|
| 1846 |
if(mc_count>mc_switch){ |
| 1847 |
mc_count=0; |
| 1848 |
mc_curchannel++; |
| 1849 |
if(mc_curchannel>=max_channels){ |
| 1850 |
mc_curchannel=0; |
| 1851 |
} |
| 1852 |
// printf("multichannel: %d\n",mc_startchannel+mc_curchannel); |
| 1853 |
changeChannel(mc_startchannel+mc_curchannel); |
| 1854 |
m_pDev->setAudioMute(true); |
| 1855 |
//m_pDev->setAudioVolume(0); |
| 1856 |
|
| 1857 |
} |
| 1858 |
|
| 1859 |
} |
| 1860 |
|
| 1861 |
void V4LWindow::ratioTimerStop() |
| 1862 |
{ |
| 1863 |
if(!m_bForce4x3) |
| 1864 |
return; |
| 1865 |
int w = width(); |
| 1866 |
int h = height()-(m_bSubtitles ? 80 : 0); |
| 1867 |
if(w != 4*h/3) |
| 1868 |
{ |
| 1869 |
printf("ratio time: subtitles %d, resizing %d,%d -> %d,%d\n", |
| 1870 |
(int)m_bSubtitles, |
| 1871 |
w, h, 4*h/3, h); |
| 1872 |
resize(4*h/3, h + (m_bSubtitles ? 80 : 0)); |
| 1873 |
} |
| 1874 |
// if(m_bForce4x3 && w!=4*(h-(m_bSubtitles?80:0))/3) |
| 1875 |
// { |
| 1876 |
// printf("Recalc %d,%d\n", 4*(h-(m_bSubtitles?80:0))/3, h); |
| 1877 |
// postResizeEvent(4*(h-(m_bSubtitles?80:0))/3, h); |
| 1878 |
// resize(4*(h-(m_bSubtitles?80:0))/3, h); |
| 1879 |
// return; |
| 1880 |
// } |
| 1881 |
} |