| 1 | /******************************************************** |
| 2 | |
| 3 | Main AVI player widget |
| 4 | Copyright 2000-2002 Zdenek Kabelac ([email protected]) |
| 5 | original author: Eugene Kuznetsov ([email protected]) |
| 6 | |
| 7 | *********************************************************/ |
| 8 | |
| 9 | #include "playercontrol.h" |
| 10 | #include "playercontrol.moc" |
| 11 | |
| 12 | #include "decoder_config.h" |
| 13 | #include "configdialog_impl.h" |
| 14 | |
| 15 | #define DECLARE_REGISTRY_SHORTCUT |
| 16 | #include "configfile.h" |
| 17 | #undef DECLARE_REGISTRY_SHORTCUT |
| 18 | |
| 19 | #include "avm_output.h" |
| 20 | #include "avm_creators.h" |
| 21 | #include "avm_except.h" |
| 22 | #include "renderer.h" |
| 23 | #include "utils.h" |
| 24 | #include "version.h" |
| 25 | #include "videodecoder.h" |
| 26 | |
| 27 | #include "pixmapbutton.h" |
| 28 | |
| 29 | #include <qcursor.h> |
| 30 | #include <qfiledialog.h> |
| 31 | #include <qgroupbox.h> |
| 32 | #include <qlabel.h> |
| 33 | #include <qlayout.h> |
| 34 | #include <qmessagebox.h> |
| 35 | #include <qpainter.h> |
| 36 | #include <qprogressbar.h> |
| 37 | #include <qpushbutton.h> |
| 38 | #include <qslider.h> |
| 39 | #include <qtimer.h> |
| 40 | |
| 41 | #ifndef Qt4 |
| 42 | #include <qhbox.h> |
| 43 | #include <qpopupmenu.h> |
| 44 | #include <qdragobject.h> |
| 45 | #else |
| 46 | #include <qboxlayout.h> |
| 47 | #include <q3popupmenu.h> |
| 48 | #include <q3dragobject.h> |
| 49 | #endif |
| 50 | |
| 51 | #ifdef HAVE_LIBSDL |
| 52 | #include <SDL.h> // hmm SDL-1.3 will be funny |
| 53 | #include <SDL_keysym.h> |
| 54 | #endif |
| 55 | |
| 56 | #include <sys/time.h> |
| 57 | #include <unistd.h> |
| 58 | #include <ctype.h> |
| 59 | #include <math.h> |
| 60 | #include <stdio.h> |
| 61 | #include <stdlib.h> |
| 62 | |
| 63 | |
| 64 | const char* g_pcProgramName = "aviplay"; |
| 65 | static const int MAX_VBAR = 100; |
| 66 | static const int MAX_MBAR = 1000; |
| 67 | |
| 68 | //using namespace Qt; |
| 69 | |
| 70 | QPlayerWidget::QPlayerWidget(PlayerControl* c) |
| 71 | : QWidget( 0, 0, Qt::WDestructiveClose ), m_pControl(c) |
| 72 | { |
| 73 | QPixmap pm; |
| 74 | pm.load( PIXMAP_PATH "/test.png" ); |
| 75 | setIcon( pm ); |
| 76 | |
| 77 | //QVBoxLayout* top_vbl = new QVBoxLayout( this, 0 ); |
| 78 | QVBoxLayout* top_vbl = new QVBoxLayout( this ); |
| 79 | top_vbl->setMargin( 2 ); |
| 80 | top_vbl->setSpacing( 2 ); |
| 81 | |
| 82 | QBoxLayout* line1_hbl = new QHBoxLayout( top_vbl, 1 ); |
| 83 | //QBoxLayout* line1_hbl = new QHBoxLayout( this );//top_vbl ); |
| 84 | |
| 85 | b_open = new QavmPixmapButton( "open", this ); |
| 86 | line1_hbl->addWidget( b_open ); |
| 87 | |
| 88 | b_pause = new QavmPixmapButton( "pause", this ); |
| 89 | line1_hbl->addWidget( b_pause ); |
| 90 | |
| 91 | b_play = new QavmPixmapButton( "play", this ); |
| 92 | line1_hbl->addWidget( b_play ); |
| 93 | |
| 94 | b_stop = new QavmPixmapButton( "stop", this ); |
| 95 | line1_hbl->addWidget( b_stop ); |
| 96 | |
| 97 | line1_hbl->addSpacing( 4 ); |
| 98 | |
| 99 | m_pScroller = new QSlider( 0, MAX_MBAR, MAX_MBAR / 10, 0, |
| 100 | QSlider::Horizontal, this ); |
| 101 | m_pScroller->setTickmarks( QSlider::Both ); |
| 102 | m_pScroller->setTickInterval( MAX_MBAR / 10 ); |
| 103 | m_pScroller->setMaximumHeight( 18 ); |
| 104 | m_pScroller->setSteps( 5, MAX_MBAR/10 ); |
| 105 | line1_hbl->addWidget( m_pScroller ); |
| 106 | |
| 107 | line1_hbl->addSpacing( 4 ); |
| 108 | |
| 109 | b_about = new QavmPixmapButton( "about", this ); |
| 110 | line1_hbl->addWidget( b_about ); |
| 111 | |
| 112 | QBoxLayout* line2_hbl = new QHBoxLayout( top_vbl, 1 ); |
| 113 | b_mute = new QavmPixmapButton( "mute", this ); |
| 114 | line2_hbl->addWidget( b_mute ); |
| 115 | |
| 116 | line2_hbl->addSpacing( 4 ); |
| 117 | |
| 118 | vbar = new QSlider( 0, MAX_VBAR, 5, MAX_VBAR, QSlider::Horizontal, this ); |
| 119 | vbar->setMaximumHeight( 18 ); |
| 120 | vbar->setMaximumWidth( 80 ); |
| 121 | //vbar->setTickmarks(QSlider::Above); |
| 122 | line2_hbl->addWidget( vbar, 20 ); |
| 123 | |
| 124 | line2_hbl->addSpacing( 2 ); |
| 125 | |
| 126 | pbar = new QProgressBar( this ); |
| 127 | pbar->setTotalSteps( 100 ); |
| 128 | pbar->setMaximumHeight( 18 ); |
| 129 | pbar->setMaximumWidth( 80 ); |
| 130 | pbar->setProgress( 0 ); |
| 131 | pbar->hide(); |
| 132 | //pbar->setIndicatorFollowsStyle( FALSE ); |
| 133 | line2_hbl->addWidget( pbar, 1 ); |
| 134 | |
| 135 | line2_hbl->addSpacing( 2 ); |
| 136 | |
| 137 | m_pLStatus = new QLabel( this ); |
| 138 | line2_hbl->addWidget( m_pLStatus ); |
| 139 | line2_hbl->addStretch( 10 ); |
| 140 | |
| 141 | m_pLTime = new QLabel( this ); |
| 142 | line2_hbl->addWidget( m_pLTime ); |
| 143 | //line2_hbl->setStretchFactor( m_pLTime ); |
| 144 | } |
| 145 | |
| 146 | bool QPlayerWidget::event(QEvent* e) |
| 147 | { |
| 148 | //printf("EVENT %d\n", e->type()); |
| 149 | switch (e->type()) |
| 150 | { |
| 151 | case Q_MenuEvent: |
| 152 | m_pControl->menuSlot(); |
| 153 | break; |
| 154 | case Q_MyPosEvent: |
| 155 | m_pControl->updatePos(); |
| 156 | break; |
| 157 | case Q_MyCloseEvent: |
| 158 | if (!m_pControl->m_Dialog.TryLock()) { |
| 159 | m_pControl->m_Dialog.Unlock(); |
| 160 | close(); |
| 161 | } |
| 162 | break; |
| 163 | case Q_MyRefreshEvent: |
| 164 | m_pControl->refresh(); |
| 165 | break; |
| 166 | case Q_MyOpenEvent: |
| 167 | m_pControl->openSlot(); |
| 168 | break; |
| 169 | case Q_MyAboutEvent: |
| 170 | m_pControl->aboutMovie(); |
| 171 | break; |
| 172 | case Q_MyConfigEvent: |
| 173 | m_pControl->showconfSlot(); |
| 174 | break; |
| 175 | case Q_MyResizeEvent: |
| 176 | m_pControl->resizePlayer(((QMyResizeEvent*) e)->m_x, |
| 177 | ((QMyResizeEvent*) e)->m_y); |
| 178 | break; |
| 179 | #if QT_VERSION < 220 |
| 180 | case QEvent::Accel: |
| 181 | #endif |
| 182 | case QEvent::KeyPress: |
| 183 | m_pControl->keyPressEvent((QKeyEvent*)e); |
| 184 | break; |
| 185 | case QEvent::Show: |
| 186 | m_pControl->showSlot(); |
| 187 | break; |
| 188 | case QEvent::Hide: |
| 189 | m_pControl->hideSlot(); |
| 190 | break; |
| 191 | case QEvent::Quit: |
| 192 | case QEvent::Close: // Have to be checked here - for safe destruction |
| 193 | m_pControl->endPlayer(); |
| 194 | default: |
| 195 | return QWidget::event(e); // parent call |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Player Control |
| 202 | */ |
| 203 | PlayerControl::PlayerControl() |
| 204 | : QObject( 0, 0 ) |
| 205 | { |
| 206 | m_pMW = 0; |
| 207 | player = 0; |
| 208 | popup = 0; |
| 209 | m_pAboutPopup = 0; |
| 210 | m_pOpenPopup = 0; |
| 211 | m_iResizeCount = 1; |
| 212 | m_iLastVolume = -1; |
| 213 | m_bIsTracking = false; |
| 214 | m_bInReseek = false; |
| 215 | m_bKeyProcessed = false; |
| 216 | m_bUnpause = false; |
| 217 | m_dStartTime = 0.0; |
| 218 | // Here we can set an icon for the application. |
| 219 | // Does anyone know how to draw an AVI player? :) No? Well, |
| 220 | // then let's leave this for a while. |
| 221 | |
| 222 | m_TimerStarter = new QTimer(this); |
| 223 | QObject::connect( m_TimerStarter, SIGNAL(timeout()), this, SLOT(starterSlot())); |
| 224 | |
| 225 | //return; |
| 226 | |
| 227 | #if QT_VERSION >= 300 |
| 228 | //QStyle& origth = qApp->style(); |
| 229 | QString usedefth = RS("theme", "default"); |
| 230 | if (usedefth != "default") |
| 231 | qApp->setStyle( usedefth.ascii() ); |
| 232 | // FIXME me - rememeber original style somehow |
| 233 | #endif |
| 234 | m_pTimer = new QTimer(this); |
| 235 | QObject::connect(m_pTimer, SIGNAL(timeout()), this, SLOT(updatePos())); |
| 236 | |
| 237 | m_pMW = new QPlayerWidget( this ); |
| 238 | |
| 239 | connect(m_pMW->m_pScroller, SIGNAL(sliderReleased()), this, SLOT(reseekSlot())); |
| 240 | connect(m_pMW->m_pScroller, SIGNAL(sliderPressed()), this, SLOT(sliderSlot())); |
| 241 | connect(m_pMW->m_pScroller, SIGNAL(sliderMoved(int)), this, SLOT(movedSlot(int))); |
| 242 | connect(m_pMW->m_pScroller, SIGNAL(valueChanged(int)), this, SLOT(changedSlot(int))); |
| 243 | |
| 244 | //connect(m_pScroller, SIGNAL(sliderPressed()), this, SLOT(sliderSlot())); |
| 245 | //connect(scroller, SIGNAL(sliderMoved(int)), this, SLOT(movedSlot(int))); |
| 246 | connect(m_pMW->vbar, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int))); |
| 247 | |
| 248 | connect(m_pMW->b_pause, SIGNAL(clicked()), this, SLOT(pauseSlot())); |
| 249 | connect(m_pMW->b_stop, SIGNAL(clicked()), this, SLOT(stopSlot())); |
| 250 | connect(m_pMW->b_play, SIGNAL(clicked()), this, SLOT(playSlot())); |
| 251 | connect(m_pMW->b_about, SIGNAL(clicked()), this, SLOT(aboutSlot())); |
| 252 | connect(m_pMW->b_mute, SIGNAL(clicked()), this, SLOT(muteChanged())); |
| 253 | connect(m_pMW->b_open, SIGNAL(clicked()), this, SLOT(openpopupSlot())); |
| 254 | |
| 255 | m_pMW->setAcceptDrops(TRUE); |
| 256 | m_pMW->resize(400, 30); |
| 257 | m_pMW->show(); |
| 258 | } |
| 259 | |
| 260 | PlayerControl::~PlayerControl() |
| 261 | { |
| 262 | delete m_pTimer; |
| 263 | delete m_TimerStarter; |
| 264 | } |
| 265 | |
| 266 | void PlayerControl::sendQt(QEvent* e) |
| 267 | { |
| 268 | if (m_pMW) |
| 269 | { |
| 270 | qApp->postEvent(m_pMW, e); |
| 271 | // event deleted by Qt |
| 272 | #if QT_VERSION > 220 |
| 273 | qApp->wakeUpGuiThread(); |
| 274 | #endif |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void PlayerControl::sendKeyEvent(int qtkey, int qtascii, int qtstate) |
| 279 | { |
| 280 | m_bKeyProcessed = true; |
| 281 | sendQt(new QKeyEvent(QEvent::KeyPress, qtkey, qtascii, qtstate)); |
| 282 | } |
| 283 | |
| 284 | void PlayerControl::keySlot(int sym, int mod) |
| 285 | { |
| 286 | #ifdef HAVE_LIBSDL |
| 287 | //printf("Key %d mod %d process: %d\n", sym, mod, m_bKeyProcessed); |
| 288 | //if (m_bKeyProcessed) return; |
| 289 | // queue new key only if the previous one has been processed |
| 290 | #define SDL_UNSAFE 0x40000000 |
| 291 | // SDL -> QT key translation |
| 292 | static const struct keytr { |
| 293 | int sdlkey; |
| 294 | int qtkey; |
| 295 | int qtascii; |
| 296 | int qtstate; |
| 297 | } sdlqttable[] = |
| 298 | { |
| 299 | { SDLK_RETURN, Qt::Key_Return }, |
| 300 | { SDLK_BACKSPACE, Qt::Key_Backspace }, |
| 301 | { SDLK_LEFT, Qt::Key_Left }, |
| 302 | { SDLK_PAGEDOWN, Qt::Key_PageDown }, |
| 303 | { SDLK_RIGHT, Qt::Key_Right }, |
| 304 | { SDLK_PAGEUP, Qt::Key_PageUp }, |
| 305 | { SDLK_UP, Qt::Key_Up }, |
| 306 | { SDLK_DOWN, Qt::Key_Down }, |
| 307 | { SDLK_HOME, Qt::Key_Home }, |
| 308 | { SDLK_END, Qt::Key_End }, |
| 309 | { SDLK_INSERT | SDL_UNSAFE, Qt::Key_Insert }, |
| 310 | { SDLK_DELETE | SDL_UNSAFE, Qt::Key_Delete }, |
| 311 | #if QT_VERSION > 220 |
| 312 | { SDLK_KP_PLUS, Qt::Key_Plus, 0, Qt::Keypad }, |
| 313 | { SDLK_KP_MINUS, Qt::Key_Minus, 0, Qt::Keypad }, |
| 314 | #endif |
| 315 | { SDLK_1 | SDL_UNSAFE, Qt::Key_1, '1' }, |
| 316 | { SDLK_2 | SDL_UNSAFE, Qt::Key_2, '2' }, |
| 317 | { SDLK_3 | SDL_UNSAFE, Qt::Key_3, '3' }, |
| 318 | { SDLK_4 | SDL_UNSAFE, Qt::Key_4, '4' }, |
| 319 | { SDLK_5 | SDL_UNSAFE, Qt::Key_5, '5' }, |
| 320 | { SDLK_6 | SDL_UNSAFE, Qt::Key_6, '6' }, |
| 321 | { SDLK_7 | SDL_UNSAFE, Qt::Key_7, '7' }, |
| 322 | { SDLK_8 | SDL_UNSAFE, Qt::Key_8, '8' }, |
| 323 | { SDLK_9 | SDL_UNSAFE, Qt::Key_9, '9' }, |
| 324 | { SDLK_0 | SDL_UNSAFE, Qt::Key_0, '0' }, |
| 325 | { SDLK_a | SDL_UNSAFE, Qt::Key_A, 'A' }, |
| 326 | { SDLK_z | SDL_UNSAFE, Qt::Key_Z, 'Z' }, |
| 327 | { SDLK_f | SDL_UNSAFE, Qt::Key_F, 'F' }, |
| 328 | { SDLK_m | SDL_UNSAFE, Qt::Key_M, 'M' }, |
| 329 | { SDLK_n | SDL_UNSAFE, Qt::Key_N, 'N' }, |
| 330 | { SDLK_o, Qt::Key_O, 'O' }, |
| 331 | { SDLK_l, Qt::Key_L, 'L' }, |
| 332 | { SDLK_i, Qt::Key_I, 'I' }, |
| 333 | { SDLK_LEFTBRACKET, Qt::Key_BraceLeft, '[' }, |
| 334 | { SDLK_RIGHTBRACKET, Qt::Key_BraceRight, ']' }, |
| 335 | { SDLK_F1, Qt::Key_F1 }, |
| 336 | { SDLK_F2, Qt::Key_F2 }, |
| 337 | { SDLK_F3, Qt::Key_F3 }, |
| 338 | { SDLK_F4, Qt::Key_F4 }, |
| 339 | { SDLK_F5, Qt::Key_F5 }, |
| 340 | { SDLK_F6, Qt::Key_F6 }, |
| 341 | { SDLK_F7, Qt::Key_F7 }, |
| 342 | { SDLK_F8, Qt::Key_F8 }, |
| 343 | { SDLK_F9, Qt::Key_F9 }, |
| 344 | { SDLK_F10, Qt::Key_F10 }, |
| 345 | { 0 } |
| 346 | }; |
| 347 | |
| 348 | int i = 0; |
| 349 | while (sdlqttable[i].sdlkey |
| 350 | && (sdlqttable[i].sdlkey & ~(SDL_UNSAFE)) != sym) |
| 351 | i++; |
| 352 | |
| 353 | if (sdlqttable[i].sdlkey) |
| 354 | { |
| 355 | if (sdlqttable[i].sdlkey & SDL_UNSAFE) |
| 356 | { |
| 357 | sendKeyEvent(sdlqttable[i].qtkey, |
| 358 | sdlqttable[i].qtascii, |
| 359 | sdlqttable[i].qtstate); |
| 360 | } |
| 361 | else |
| 362 | { |
| 363 | // testing thread stability & safety |
| 364 | // code path for actions which may be |
| 365 | // implemented directly without Qt passthrough |
| 366 | QKeyEvent e(QEvent::KeyPress, |
| 367 | sdlqttable[i].qtkey, |
| 368 | sdlqttable[i].qtascii, |
| 369 | sdlqttable[i].qtstate); |
| 370 | keyPressEvent(&e); |
| 371 | } |
| 372 | } |
| 373 | #undef SDL_UNSAFE |
| 374 | #endif |
| 375 | } |
| 376 | |
| 377 | void PlayerControl::menuSlot() |
| 378 | { |
| 379 | if (!popup) |
| 380 | { |
| 381 | popup = new QPopupMenu(); |
| 382 | #if 1 |
| 383 | //popup->insertTearOffHandle(); |
| 384 | QPopupMenu* p = new QPopupMenu(); |
| 385 | //connect( p, SIGNAL( activated( int ) ), this, SLOT( zoom_mode( int ) ) ); |
| 386 | if (p) |
| 387 | { |
| 388 | p->insertItem( tr( "Size 2x &3" ), this, SLOT( zoom_2x() ) ); |
| 389 | p->insertItem( tr( "Size 1x &2" ), this, SLOT( zoom_1x() ) ); |
| 390 | p->insertItem( tr( "Size 0.5x &1" ), this, SLOT( zoom_0_5x() ) ); |
| 391 | p->insertItem( tr( "Size +10% &A" ), this, SLOT( zoom_plus() ) ); |
| 392 | p->insertItem( tr( "Size -10% &Z" ), this, SLOT( zoom_minus() ) ); |
| 393 | p->insertItem( tr( "Crop Top " ), this, SLOT( crop_top() ) ); |
| 394 | p->insertItem( tr( "Crop Bottom " ), this, SLOT( crop_bottom() ) ); |
| 395 | p->insertItem( tr( "Crop Left " ), this, SLOT( crop_left() ) ); |
| 396 | p->insertItem( tr( "Crop Right " ), this, SLOT( crop_right() ) ); |
| 397 | p->insertItem( tr( "Crop 16:9 &6" ), this, SLOT( crop_16_9() ) ); |
| 398 | p->insertItem( tr( "Crop 16:10 &7" ), this, SLOT( crop_16_10() ) ); |
| 399 | p->insertItem( tr( "Crop 4:3 &4" ), this, SLOT( crop_4_3() ) ); |
| 400 | popup->insertItem( tr( "Zoom" ), p); |
| 401 | } |
| 402 | |
| 403 | p = new QPopupMenu(); |
| 404 | //connect( p, SIGNAL( activated( int ) ), this, SLOT( zoom_mode( int ) ) ); |
| 405 | if (p) |
| 406 | { |
| 407 | p->insertItem( tr( "Original" ), this, SLOT( ratio_orig() ) ); |
| 408 | p->insertItem( tr( "16:9" ) , this, SLOT( ratio_16_9() ) ); |
| 409 | p->insertItem( tr( "4:3" ) , this, SLOT( ratio_4_3() ) ); |
| 410 | popup->insertItem( tr( "Aspect Ratio" ), p); |
| 411 | } |
| 412 | popup->insertSeparator(); |
| 413 | popup->insertItem( tr( "&Fullscreen" ), this, SLOT( fullscreen() ), CTRL+Key_F ); |
| 414 | popup->insertItem( tr( "&Maximize" ), this, SLOT( maximize() ) ); |
| 415 | |
| 416 | const avm::vector<avm::IVideoRenderer*>& vvr = player->GetVideoRenderers(); |
| 417 | if (vvr.size() > 0) |
| 418 | { |
| 419 | modes = new QPopupMenu(); |
| 420 | |
| 421 | connect(modes, SIGNAL(activated(int)), |
| 422 | this, SLOT(maximizeMode(int))); |
| 423 | |
| 424 | unsigned i = 0; |
| 425 | while (i < vvr.size()) |
| 426 | { |
| 427 | const avm::vector<avm::VideoMode>& vvm = vvr[i]->GetVideoModes(); |
| 428 | unsigned j = 0; |
| 429 | while (j < vvm.size()) |
| 430 | { |
| 431 | modes->insertItem(vvm[j].name.c_str(), (i << 8) + j); |
| 432 | j++; |
| 433 | } |
| 434 | i++; |
| 435 | } |
| 436 | popup->insertItem( tr( "Maximize Modes" ), modes); |
| 437 | } |
| 438 | #endif |
| 439 | popup->insertSeparator(); |
| 440 | popup->insertItem( tr( "&Properties" ), this, SLOT(aboutMovie())); |
| 441 | |
| 442 | bool is = false; |
| 443 | if (player->GetRtConfig(player->AUDIO_CODECS) |
| 444 | || player->GetCodecInfo().decoder_info.size()) |
| 445 | { |
| 446 | is = true; |
| 447 | popup->insertSeparator(); |
| 448 | popup->insertItem( tr("&Audio Decoder config"), this, SLOT( audioDecoderConfig() ) ); |
| 449 | } |
| 450 | if (player->GetRtConfig(player->VIDEO_CODECS) |
| 451 | || player->GetCodecInfo().decoder_info.size()) |
| 452 | { |
| 453 | if (!is) |
| 454 | popup->insertSeparator(); |
| 455 | is = true; |
| 456 | popup->insertItem( tr("&Video Decoder config"), this, SLOT( videoDecoderConfig() ) ); |
| 457 | } |
| 458 | if (player->GetRtConfig(player->VIDEO_RENDERER)) |
| 459 | { |
| 460 | if (!is) |
| 461 | popup->insertSeparator(); |
| 462 | popup->insertItem( tr("Video &Renderer config"), this, SLOT( rendererConfig() ) ); |
| 463 | } |
| 464 | |
| 465 | popup->insertItem( tr("P&layer config"), this, SLOT( sendConfig() ) ); |
| 466 | |
| 467 | popup->hide(); |
| 468 | } |
| 469 | |
| 470 | if (popup->isVisible()) |
| 471 | { |
| 472 | //printf("VISIBLE\n"); |
| 473 | popup->hide(); |
| 474 | } |
| 475 | else |
| 476 | { |
| 477 | //printf("INVISIBLE\n"); |
| 478 | //popup->move( QCursor::pos() ); |
| 479 | //popup->show(); |
| 480 | popup->exec( QCursor::pos() ); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | void PlayerControl::zoom(float scale) |
| 485 | { |
| 486 | if (player) |
| 487 | { |
| 488 | player->Zoom(0, 0, 0, 0); // disable any zoom |
| 489 | if (scale == 2.f) |
| 490 | m_iResizeCount = 2; |
| 491 | else if (scale == 1.f) |
| 492 | m_iResizeCount = 1; |
| 493 | else |
| 494 | m_iResizeCount = 0; |
| 495 | |
| 496 | float h = scale * (float)player->GetHeight(); |
| 497 | float w = (float)player->GetWidth(); |
| 498 | avm::StreamInfo* si = player->GetVideoStreamInfo(); |
| 499 | if (si) |
| 500 | { |
| 501 | float a = si->GetAspectRatio(); |
| 502 | w = (a > 0) ? h * a : scale * w; |
| 503 | delete si; |
| 504 | int ww = (int)(w + 0.5f); |
| 505 | int hh = (int)(h + 0.5f); |
| 506 | player->Resize(ww, hh); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | void PlayerControl::zoom_mode(int mode) |
| 512 | { |
| 513 | int x = 0; |
| 514 | int y = 0; |
| 515 | int w = player->GetWidth(); |
| 516 | int h = player->GetHeight(); |
| 517 | int wo = w, ho = h; |
| 518 | int vw, vh; |
| 519 | if (!w || !h) |
| 520 | return; // no picture |
| 521 | |
| 522 | player->Get(player->QUERY_VIDEO_WIDTH, &vw, |
| 523 | player->QUERY_VIDEO_HEIGHT, &vh, 0); |
| 524 | |
| 525 | float r = (float)vw / (float)vh; |
| 526 | float s = (float)vw / (float)w; |
| 527 | //printf("W %d H %d %d x %d %f\n", vw, vh, w, h, r); |
| 528 | switch (mode) |
| 529 | { |
| 530 | case ZOOM_PLUS: |
| 531 | w = ((vw * 11) / 10 + 15) & ~15; |
| 532 | h = (int) ((float)w / r + 0.5f); |
| 533 | break; |
| 534 | case ZOOM_MINUS: |
| 535 | w = ((vw * 9) / 10 + 15) & ~15; |
| 536 | h = (int) ((float)w / r + 0.5f); |
| 537 | break; |
| 538 | case CROP_4_3: |
| 539 | setRatio(x, y, w, h, 4, 3); |
| 540 | break; |
| 541 | case CROP_16_9: |
| 542 | setRatio(x, y, w, h, 16, 9); |
| 543 | break; |
| 544 | case CROP_16_10: |
| 545 | setRatio(x, y, w, h, 16, 10); |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | ho = h * vw / wo; |
| 550 | wo = w * vw / wo; |
| 551 | switch (mode) |
| 552 | { |
| 553 | case ZOOM_PLUS: |
| 554 | case ZOOM_MINUS: |
| 555 | printf("zoom %d x %d\n", w, h); |
| 556 | player->Resize(w, h); |
| 557 | break; |
| 558 | case CROP_16_10: |
| 559 | case CROP_16_9: |
| 560 | case CROP_4_3: |
| 561 | printf("crop %d %d %d x %d\n", x, y, w, h); |
| 562 | player->Zoom(x, y, w, h); |
| 563 | player->Resize(wo, ho); |
| 564 | break; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | void PlayerControl::ratio(int r) |
| 569 | { |
| 570 | int w = player->GetWidth(); |
| 571 | int h = player->GetHeight(); |
| 572 | |
| 573 | switch (r) |
| 574 | { |
| 575 | case RATIO_ORIG: |
| 576 | break; |
| 577 | case RATIO_16_9: |
| 578 | w = 16 * h / 9; |
| 579 | break; |
| 580 | case RATIO_4_3: |
| 581 | w = 4 * h / 3; |
| 582 | break; |
| 583 | } |
| 584 | player->Resize(w, h); |
| 585 | } |
| 586 | |
| 587 | void PlayerControl::zoomWH(int new_w, int new_h, int ori_w, int ori_h) |
| 588 | { |
| 589 | //printf("zoomWH %dx%d\n", new_w, new_h); |
| 590 | if (ori_w > ori_h) |
| 591 | new_h = (int) (new_w * ori_h / (double) ori_w + 0.5); |
| 592 | else |
| 593 | new_w = (int) (new_h * ori_w / (double) ori_h + 0.5); |
| 594 | player->Resize(new_w, new_h); |
| 595 | fullscreen(); |
| 596 | } |
| 597 | |
| 598 | void PlayerControl::fullscreen() |
| 599 | { |
| 600 | if (player) |
| 601 | { |
| 602 | apip.fullscreen = !apip.fullscreen; |
| 603 | player->ToggleFullscreen(false); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | void PlayerControl::maximize() |
| 608 | { |
| 609 | if (player) |
| 610 | { |
| 611 | apip.maximize = !apip.maximize; |
| 612 | player->ToggleFullscreen(true); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | void PlayerControl::maximizeMode(int renderer_mode) |
| 617 | { |
| 618 | if (renderer_mode < 0) |
| 619 | return; |
| 620 | |
| 621 | const avm::vector<avm::IVideoRenderer*>& vvr = player->GetVideoRenderers(); |
| 622 | unsigned renderer = (renderer_mode >> 8); |
| 623 | if (renderer < vvr.size()) |
| 624 | { |
| 625 | unsigned mode = renderer_mode & 0xff; |
| 626 | const avm::vector<avm::VideoMode>& vvm = vvr[renderer]->GetVideoModes(); |
| 627 | if (mode < vvm.size()) |
| 628 | { |
| 629 | int ori_w, ori_h; |
| 630 | int new_w = vvm[mode].width; |
| 631 | int new_h = vvm[mode].height; |
| 632 | |
| 633 | if (vvr[renderer]->GetSize(ori_w, ori_h) < 0) |
| 634 | { |
| 635 | ori_w = player->GetWidth(); |
| 636 | ori_h = player->GetHeight(); |
| 637 | } |
| 638 | zoomWH(new_w, new_h, ori_w, ori_h); |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void PlayerControl::showconfSlot() |
| 644 | { |
| 645 | if (m_Dialog.TryLock()) |
| 646 | return; |
| 647 | if (!player) |
| 648 | initPlayer(apip); |
| 649 | // Qt is buggy - will crash if |
| 650 | // player quits and this window is opened |
| 651 | ConfigDialog_impl dilg(this); |
| 652 | delete popup; |
| 653 | popup = 0; |
| 654 | dilg.exec(); |
| 655 | readConfig(); |
| 656 | m_Dialog.Unlock(); |
| 657 | } |
| 658 | |
| 659 | void PlayerControl::decoderConfig(int type) |
| 660 | { |
| 661 | if (!player || !player->IsValid() || m_Dialog.TryLock()) |
| 662 | return; |
| 663 | |
| 664 | avm::IRtConfig* rt = player->GetRtConfig(type); |
| 665 | QCodecConf qdlg(player->GetCodecInfo(type), rt); |
| 666 | if (qdlg.exec() == QDialog::Accepted) |
| 667 | { |
| 668 | m_bInReseek = true; |
| 669 | if (!rt) |
| 670 | { |
| 671 | qdlg.valueChanged(0); |
| 672 | player->Restart(); |
| 673 | } |
| 674 | //this call blocks until main processing thread |
| 675 | //is stopped, so it can safely restart decoder. |
| 676 | //Operations with _in_reseek and mutex guarantee that |
| 677 | //we won't receive a deadlock. |
| 678 | m_bInReseek = false; |
| 679 | } |
| 680 | m_Dialog.Unlock(); |
| 681 | } |
| 682 | |
| 683 | void PlayerControl::rendererConfig() |
| 684 | { |
| 685 | if (!player || !player->IsValid() || m_Dialog.TryLock()) |
| 686 | return; |
| 687 | |
| 688 | avm::IRtConfig* rt = player->GetRtConfig(player->VIDEO_RENDERER); |
| 689 | if (rt) |
| 690 | { |
| 691 | const avm::vector<avm::AttributeInfo>& ai = rt->GetAttrs(); |
| 692 | //printf("RtSize %d\n", ai.size()); |
| 693 | //for(unsigned i = 0; i < ai.size(); i++) |
| 694 | // printf("%s %s\n", ai[i].GetName(), ai[i].GetAbout()); |
| 695 | |
| 696 | QRendererConf qdlg( ai, rt ); |
| 697 | qdlg.exec(); |
| 698 | } |
| 699 | m_Dialog.Unlock(); |
| 700 | } |
| 701 | |
| 702 | |
| 703 | // this method should be used for all volume changes |
| 704 | // for common interpretation |
| 705 | void PlayerControl::volumeChanged(int vpos) |
| 706 | { |
| 707 | if (player) |
| 708 | player->Set(player->AUDIO_VOLUME, vpos * 1000 / MAX_VBAR, 0); |
| 709 | } |
| 710 | |
| 711 | void PlayerControl::muteChanged() |
| 712 | { |
| 713 | if (m_pMW) |
| 714 | { |
| 715 | int p = m_pMW->vbar->value(); |
| 716 | int n = m_iLastVolume; |
| 717 | if (p != 0) { |
| 718 | m_iLastVolume = p; |
| 719 | n = 0; |
| 720 | } |
| 721 | m_pMW->vbar->setValue(n); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | void PlayerControl::pauseSlot() |
| 726 | { |
| 727 | m_bUnpause = false; |
| 728 | if (player) |
| 729 | player->Pause(!player->IsPaused()); |
| 730 | } |
| 731 | |
| 732 | void PlayerControl::stopSlot() |
| 733 | { |
| 734 | if (player) |
| 735 | player->Stop(); |
| 736 | hideSlot(); |
| 737 | } |
| 738 | |
| 739 | void PlayerControl::changedSlot(int cpos) |
| 740 | { |
| 741 | if (player && m_pMW) |
| 742 | { |
| 743 | bool wrapAround = cpos < (m_pMW->m_pScroller->minValue() + 1) |
| 744 | && last_slider > (m_pMW->m_pScroller->maxValue() - 1); |
| 745 | //printf("WRAP %d %d\n", wrapAround, last_slider); |
| 746 | // when paused or when mouse wheel movement... |
| 747 | int minchange = (player->IsPaused()) ? 0 : 2; |
| 748 | if (!m_bSettingScroller |
| 749 | && (!m_bIsTracking || player->IsPaused()) |
| 750 | && !wrapAround && abs(last_slider - cpos) > minchange) |
| 751 | { |
| 752 | double t = cpos * m_dLengthTime / MAX_MBAR; |
| 753 | player->ReseekExact(t + m_dStartTime); |
| 754 | //printf("reseek %f %f %d\n", t+m_dStartTime, m_dLengthTime, cpos); |
| 755 | updatePos(); |
| 756 | } |
| 757 | last_slider = cpos; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void PlayerControl::nextPage() |
| 762 | { |
| 763 | if (player && player->NextKeyFrame() == 0) |
| 764 | updatePos(); |
| 765 | } |
| 766 | |
| 767 | void PlayerControl::prevPage() |
| 768 | { |
| 769 | if (player && player->PrevKeyFrame() == 0) |
| 770 | updatePos(); |
| 771 | } |
| 772 | |
| 773 | void PlayerControl::playSlot() |
| 774 | { |
| 775 | if (player) |
| 776 | { |
| 777 | if (!player->IsPlaying() && !player->IsPaused()) |
| 778 | { |
| 779 | player->Start(); |
| 780 | m_dStartTime = player->GetTime(); |
| 781 | } |
| 782 | else |
| 783 | player->Play(); |
| 784 | |
| 785 | showSlot(); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | void PlayerControl::openSlot() |
| 790 | { |
| 791 | if (m_Dialog.TryLock()) |
| 792 | return; |
| 793 | |
| 794 | QString path = RS("url", "."); |
| 795 | int pos = path.findRev('/'); |
| 796 | if (pos < 0) |
| 797 | path = "./"; |
| 798 | #if QT_VERSION <= 220 |
| 799 | else |
| 800 | path.remove(pos, path.length()); |
| 801 | #endif |
| 802 | //QFileDialog *fld = new QFileDialog(); |
| 803 | //open_qs = fld->getOpenFileName(tr(path.c_str()), tr("AVI files (*.avi *.AVI);;ASF files (*.asf *.ASF);;All files(*)")); |
| 804 | //mb->setTextFormat(Qt::RichText); |
| 805 | QStringList o = QFileDialog::getOpenFileNames( |
| 806 | #if QT_VERSION > 220 |
| 807 | tr("All files (*);;" |
| 808 | "AVI files (*.avi *.AVI);;" |
| 809 | "ASF files (*.asf *.ASF *.wma *.WMA *.wmv *.WMV);;" |
| 810 | "MPEG files (*.mpg *.MPG *.mpeg *.MPEG *.mp3 *.MP3 *.m2v *.M2V *.mp2 *.MP2 *.mpv2 *.MPV2 *.ts *.TS *.vob *.VOB);;" |
| 811 | "QuickTime files (*.mov *.MOV *.qt *.QT);;" |
| 812 | ) |
| 813 | #else |
| 814 | "" |
| 815 | #endif |
| 816 | , path.ascii(), |
| 817 | 0, 0 |
| 818 | #if QT_VERSION > 220 |
| 819 | , tr( "Open video file(s)" ) |
| 820 | #endif |
| 821 | ); |
| 822 | m_Dialog.Unlock(); |
| 823 | if (o.isEmpty()) |
| 824 | return; |
| 825 | |
| 826 | apip.urls.clear(); |
| 827 | apip.idx = 0; |
| 828 | for (size_t i = 0; i < o.count(); ++i) |
| 829 | apip.urls.push_back((const char*)o[i].local8Bit()); |
| 830 | initPlayer(apip); |
| 831 | } |
| 832 | |
| 833 | void PlayerControl::opensubSlot() |
| 834 | { |
| 835 | if (!player || m_Dialog.TryLock()) |
| 836 | return; |
| 837 | |
| 838 | QString path = RS("subtitle-url", "."); |
| 839 | QString o = QFileDialog::getOpenFileName( path.ascii(), |
| 840 | #if QT_VERSION > 220 |
| 841 | tr( |
| 842 | "SUB files (*.sub *.SUB *.txt *.TXT);;" |
| 843 | "SRT files (*.srt *.SRT);;" |
| 844 | "SAMI files (*.smi *.SMI);;" |
| 845 | "All files (*)" |
| 846 | ), |
| 847 | #else |
| 848 | "", |
| 849 | #endif |
| 850 | 0, 0 |
| 851 | #if QT_VERSION > 220 |
| 852 | , tr( "Open subtitle file" ) |
| 853 | #endif |
| 854 | ); |
| 855 | if (!o.isNull()) { |
| 856 | player->InitSubtitles(o.local8Bit()); |
| 857 | WS("subtitle-url", (const char *)o.local8Bit()); |
| 858 | } |
| 859 | |
| 860 | m_Dialog.Unlock(); |
| 861 | } |
| 862 | |
| 863 | void PlayerControl::openaudSlot() |
| 864 | { |
| 865 | if (!player || m_Dialog.TryLock()) |
| 866 | return; |
| 867 | |
| 868 | char* astr = 0; |
| 869 | player->Get(player->AUDIO_URL, &astr, 0); |
| 870 | QString o = QFileDialog::getOpenFileName( astr, |
| 871 | #if QT_VERSION > 220 |
| 872 | tr( "All files (*)" ), |
| 873 | #else |
| 874 | "", |
| 875 | #endif |
| 876 | 0, 0 |
| 877 | #if QT_VERSION > 220 |
| 878 | , tr( "Open audio file" ) |
| 879 | #endif |
| 880 | ); |
| 881 | if (astr) |
| 882 | free(astr); |
| 883 | |
| 884 | if (!o.isNull()) |
| 885 | player->Set(player->AUDIO_URL, (const char*)o.local8Bit(), 0); |
| 886 | |
| 887 | m_Dialog.Unlock(); |
| 888 | } |
| 889 | |
| 890 | void PlayerControl::keyPressEvent(QKeyEvent * kevent) |
| 891 | { |
| 892 | avm::Locker locker(m_Mutex); |
| 893 | // for SDL events are also mirrored in EventFilter ( see renderer.cpp ) |
| 894 | //printf("KEYPRESS %d ascii: %c\n", kevent->key(), kevent->ascii()); |
| 895 | |
| 896 | m_bKeyProcessed = false; |
| 897 | switch(kevent->key()) |
| 898 | { |
| 899 | case Qt::Key_Q: sendEvent(Q_MyCloseEvent); return; |
| 900 | case Qt::Key_X: stopSlot(); return; |
| 901 | case Qt::Key_C: |
| 902 | case Qt::Key_P: |
| 903 | case Qt::Key_Space: |
| 904 | // try to support most natural keystrokes |
| 905 | pauseSlot(); |
| 906 | return; |
| 907 | case Qt::Key_BracketLeft: |
| 908 | if (player) |
| 909 | { |
| 910 | int t; |
| 911 | player->Get(avm::IAviPlayer::ASYNC_TIME_MS, &t, 0); |
| 912 | player->Set(avm::IAviPlayer::ASYNC_TIME_MS, ((t - 100) * 100) / 100, 0); |
| 913 | printf("Set async %dms\n", t); |
| 914 | } |
| 915 | return; |
| 916 | case Qt::Key_BracketRight: |
| 917 | if (player) |
| 918 | { |
| 919 | int t; |
| 920 | player->Get(avm::IAviPlayer::ASYNC_TIME_MS, &t, 0); |
| 921 | player->Set(avm::IAviPlayer::ASYNC_TIME_MS, ((t + 100) * 100) / 100, 0); |
| 922 | printf("Set async %dms\n", t); |
| 923 | } |
| 924 | return; |
| 925 | case Qt::Key_V: playSlot(); return; |
| 926 | case Qt::Key_F: fullscreen(); return; |
| 927 | case Qt::Key_M: maximize(); return; |
| 928 | case Qt::Key_1: zoom(0.5); return; |
| 929 | case Qt::Key_2: zoom(1.0); return; |
| 930 | case Qt::Key_3: zoom(2.0); return; |
| 931 | case Qt::Key_4: crop_4_3(); return; |
| 932 | case Qt::Key_6: crop_16_9(); return; |
| 933 | case Qt::Key_7: crop_16_10(); return; |
| 934 | case Qt::Key_A: zoom_mode(ZOOM_PLUS); return; |
| 935 | case Qt::Key_Z: zoom_mode(ZOOM_MINUS); return; |
| 936 | case Qt::Key_L: sendEvent(Q_MyOpenEvent); return; |
| 937 | case Qt::Key_I: sendEvent(Q_MyAboutEvent); return; |
| 938 | case Qt::Key_N: |
| 939 | { |
| 940 | int maxa; |
| 941 | int cura; |
| 942 | player->Get(avm::IAviPlayer::QUERY_AUDIO_STREAMS, &maxa, |
| 943 | avm::IAviPlayer::AUDIO_STREAM, &cura, 0); |
| 944 | cura++; |
| 945 | //printf("ASTREAM %d %d\n", cura, maxa); |
| 946 | if (cura >= maxa) |
| 947 | cura = 0; |
| 948 | player->Set(avm::IAviPlayer::AUDIO_STREAM, cura, 0); |
| 949 | } |
| 950 | return; |
| 951 | case Qt::Key_Return: player->NextFrame(); return; |
| 952 | case Qt::Key_Backspace: player->PrevFrame(); return; |
| 953 | case Qt::Key_Right: player->NextKeyFrame(); return; |
| 954 | case Qt::Key_Left: player->PrevKeyFrame(); return; |
| 955 | case Qt::Key_Home: player->ReseekExact(0); return; |
| 956 | case Qt::Key_End: player->ReseekExact(player->GetLengthTime() - 1.); return; |
| 957 | case Qt::Key_Plus: |
| 958 | case Qt::Key_0: |
| 959 | if (m_pMW) m_pMW->vbar->addStep(); |
| 960 | return; |
| 961 | case Qt::Key_Minus: |
| 962 | case Qt::Key_9: |
| 963 | if (m_pMW) m_pMW->vbar->subtractStep(); |
| 964 | return; |
| 965 | case Qt::Key_Insert: |
| 966 | case Qt::Key_Less: |
| 967 | case Qt::Key_Back: |
| 968 | if (--apip.idx >= apip.urls.size()) |
| 969 | apip.idx = (unsigned int)apip.urls.size() - 1; |
| 970 | if (apip.urls.size() > 1) |
| 971 | initPlayer(apip); |
| 972 | return; |
| 973 | case Qt::Key_Delete: |
| 974 | case Qt::Key_Greater: |
| 975 | case Qt::Key_Forward: |
| 976 | if (++apip.idx >= apip.urls.size()) |
| 977 | apip.idx = 0; |
| 978 | if (apip.urls.size() > 1) |
| 979 | initPlayer(apip); |
| 980 | return; |
| 981 | case Qt::Key_Down: |
| 982 | case Qt::Key_PageDown: |
| 983 | { |
| 984 | double sktime = (kevent->key() == Qt::Key_Down) ? 60. : 10.; |
| 985 | double o = player->GetTime(); |
| 986 | double p = o + sktime; |
| 987 | double len = player->GetLengthTime(); |
| 988 | if (p > len) |
| 989 | // we are at the end - try 5 seconds before end |
| 990 | p = len; |
| 991 | player->ReseekExact(p); |
| 992 | if (player->GetTime() <= (o + 1.0)) |
| 993 | // some movies have very long intervals between KeyFrames |
| 994 | // so always skip at least to the next keyframe |
| 995 | player->NextKeyFrame(); |
| 996 | } |
| 997 | return; |
| 998 | case Qt::Key_Up: |
| 999 | case Qt::Key_PageUp: |
| 1000 | { |
| 1001 | double sktime = (kevent->key() == Qt::Key_Up) ? 60. : 10.; |
| 1002 | double p = player->GetTime() - sktime; |
| 1003 | if (p < 0) |
| 1004 | p = 0.; |
| 1005 | player->ReseekExact(p); |
| 1006 | } |
| 1007 | return; |
| 1008 | case Qt::Key_Question: |
| 1009 | case Qt::Key_H: |
| 1010 | help(); |
| 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | static const struct runtimecnf { |
| 1015 | int qtkey; |
| 1016 | const char attr[12]; |
| 1017 | int add; |
| 1018 | } rttable[] = { |
| 1019 | { Qt::Key_F1, "saturation", -2 }, |
| 1020 | { Qt::Key_F2, "saturation", 2 }, |
| 1021 | { Qt::Key_F5, "brightness", -2 }, |
| 1022 | { Qt::Key_F6, "brightness", 2 }, |
| 1023 | { Qt::Key_F7, "hue", -2 }, |
| 1024 | { Qt::Key_F8, "hue", 2 }, |
| 1025 | { Qt::Key_F9, "contrast", 2 }, |
| 1026 | { Qt::Key_F10, "contrast", -2 }, |
| 1027 | { 0, "", 0 } |
| 1028 | }; |
| 1029 | |
| 1030 | int i = 0; |
| 1031 | avm::IRtConfig* rt = 0; |
| 1032 | bool cset = true; |
| 1033 | while (rttable[i].qtkey) |
| 1034 | { |
| 1035 | if (kevent->key() == rttable[i].qtkey) |
| 1036 | { |
| 1037 | if (rt == 0) |
| 1038 | { |
| 1039 | rt = player->GetRtConfig(); |
| 1040 | if (rt == 0) |
| 1041 | { |
| 1042 | const avm::vector<avm::IVideoRenderer*>& v = player->GetVideoRenderers(); |
| 1043 | if (v.size()) |
| 1044 | { |
| 1045 | rt = v.front()->GetRtConfig(); |
| 1046 | if (!rt) |
| 1047 | break; |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | const avm::vector<avm::AttributeInfo>& attrs = rt ? |
| 1052 | rt->GetAttrs() : player->GetCodecInfo().decoder_info ; |
| 1053 | int val; |
| 1054 | |
| 1055 | for (unsigned j = 0; j < attrs.size(); j++) |
| 1056 | { |
| 1057 | const char* attr = attrs[j].GetName(); |
| 1058 | if (strcasecmp(rttable[i].attr, attr) == 0 |
| 1059 | || strcasecmp(rttable[i].attr, attrs[j].GetAbout()) == 0) |
| 1060 | { |
| 1061 | if (rt->GetValue(attr, &val) == 0) |
| 1062 | { |
| 1063 | val += rttable[i].add; |
| 1064 | if (val < attrs[j].i_min) |
| 1065 | val = attrs[j].i_min; |
| 1066 | else if (val > attrs[j].i_max) |
| 1067 | val = attrs[j].i_max; |
| 1068 | |
| 1069 | if (rt) |
| 1070 | rt->SetValue(attr, val); |
| 1071 | else |
| 1072 | avm::CodecSetAttr(player->GetCodecInfo(), attr, val); |
| 1073 | return; |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | i++; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | void PlayerControl::mouseDoubleClickEvent(QMouseEvent *) |
| 1083 | { |
| 1084 | showconfSlot(); |
| 1085 | } |
| 1086 | |
| 1087 | void PlayerControl::aboutSlot() |
| 1088 | { |
| 1089 | if (!m_pAboutPopup) |
| 1090 | { |
| 1091 | m_pAboutPopup = new QPopupMenu(); |
| 1092 | m_pAboutPopup->insertItem( tr( "&Usage" ), this, SLOT( help() ) ); |
| 1093 | m_pAboutPopup->insertItem( tr( "&About" ), this, SLOT( about() ) ); |
| 1094 | m_pAboutPopup->insertItem( tr( "&Config" ), this, SLOT( showconfSlot() ) ); |
| 1095 | m_pAboutPopup->insertSeparator(); |
| 1096 | m_pAboutPopup->insertItem( tr( "&Properties" ), this, SLOT( aboutMovie() ) ); |
| 1097 | } |
| 1098 | |
| 1099 | m_pAboutPopup->popup( QCursor::pos() ); |
| 1100 | } |
| 1101 | |
| 1102 | void PlayerControl::openpopupSlot() |
| 1103 | { |
| 1104 | if (!m_pOpenPopup) |
| 1105 | { |
| 1106 | m_pOpenPopup = new QPopupMenu(); |
| 1107 | m_pOpenPopup->insertItem( tr( "Open &File" ), this, SLOT( openSlot() ) ); |
| 1108 | m_pOpenPopup->insertItem( tr( "Open &URL" ), this, SLOT( openSlot() ) ); |
| 1109 | m_pOpenPopup->insertItem( tr( "Open &Subtitle File" ), this, SLOT( opensubSlot() ) ); |
| 1110 | m_pOpenPopup->insertItem( tr( "Open &Audio File" ), this, SLOT( openaudSlot() ) ); |
| 1111 | } |
| 1112 | |
| 1113 | m_pOpenPopup->popup( QCursor::pos() ); |
| 1114 | } |
| 1115 | |
| 1116 | void PlayerControl::resizePlayer(int w, int h) |
| 1117 | { |
| 1118 | if (player) |
| 1119 | player->Resize(w, h); |
| 1120 | } |
| 1121 | |
| 1122 | void PlayerControl::refresh() |
| 1123 | { |
| 1124 | if (player) |
| 1125 | player->Refresh(); |
| 1126 | } |
| 1127 | |
| 1128 | void PlayerControl::remote_command() |
| 1129 | { |
| 1130 | char command[32]; |
| 1131 | int command_pos = 0; |
| 1132 | static long oldpos; |
| 1133 | long newpos = (long) getTime(); |
| 1134 | fd_set fds; // stdin changed? |
| 1135 | struct timeval tv; // how long to w8 |
| 1136 | int n; // indicating whether something happened on stdin |
| 1137 | |
| 1138 | if (isStopped()) |
| 1139 | sendEvent(Q_MyCloseEvent); |
| 1140 | if (newpos != oldpos) { |
| 1141 | oldpos = newpos; |
| 1142 | printf ("Pos: %li s / %li s\n", (long) getTime(), |
| 1143 | (long) player->GetLengthTime()); |
| 1144 | } |
| 1145 | tv.tv_sec = 0; |
| 1146 | tv.tv_usec = 50000; |
| 1147 | FD_ZERO(&fds); |
| 1148 | FD_SET(STDIN_FILENO, &fds); |
| 1149 | if ((n = select(32, &fds, NULL, NULL, &tv)) != 0) |
| 1150 | { |
| 1151 | double cpos; |
| 1152 | ssize_t i; |
| 1153 | int complete = 0; |
| 1154 | |
| 1155 | while (command_pos < 32 && |
| 1156 | (i = read (STDIN_FILENO, command + command_pos, 1)) > 0 && |
| 1157 | command[command_pos] != '\r' && |
| 1158 | command[command_pos] != '\n') |
| 1159 | command_pos++; |
| 1160 | |
| 1161 | if (command_pos == 31 || command[command_pos] == '\r' || |
| 1162 | command[command_pos] == '\n') { |
| 1163 | command[command_pos] = 0; |
| 1164 | complete = 1; |
| 1165 | } |
| 1166 | if (complete == 1) { |
| 1167 | if (command[0] == 'p' || command[0] == 'P') |
| 1168 | pauseSlot(); |
| 1169 | else if (command[0] == 'f' || command[0] == 'F') |
| 1170 | fullscreen(); |
| 1171 | else if (command[0] == 'm' || command[0] == 'M') |
| 1172 | maximize(); |
| 1173 | else if (command[0] == 's' || command[0] == 'S') |
| 1174 | stopSlot(); |
| 1175 | else if (command[0] == 'q' || command[0] == 'Q') |
| 1176 | sendEvent(Q_MyCloseEvent); |
| 1177 | else if (command[0] == 'r' || command[0] == 'R') { |
| 1178 | for (i = 1; i < 32 && command[i] >= '0' && command[i] <= '9'; ++i) |
| 1179 | ; |
| 1180 | command[i] = 0; |
| 1181 | cpos = atof(command + 1); |
| 1182 | player->ReseekExact(cpos); |
| 1183 | } else |
| 1184 | printf("Unknown command: %s\n", command); |
| 1185 | command_pos = 0; |
| 1186 | complete = 0; |
| 1187 | } |
| 1188 | return; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | void PlayerControl::aboutMovie() |
| 1193 | { |
| 1194 | if (!player) |
| 1195 | return; |
| 1196 | |
| 1197 | QString s = tr( "Stream: " ); |
| 1198 | s += player->GetFileName(); |
| 1199 | s += "\n\n"; |
| 1200 | |
| 1201 | avm::StreamInfo* info = player->GetVideoStreamInfo(); |
| 1202 | if (info) |
| 1203 | { |
| 1204 | s += info->GetString().c_str(); |
| 1205 | s += tr( "Video decoder: "); |
| 1206 | s += player->GetVideoFormat(); |
| 1207 | s += '\n'; |
| 1208 | delete info; |
| 1209 | } |
| 1210 | |
| 1211 | s += '\n'; |
| 1212 | |
| 1213 | info = player->GetAudioStreamInfo(); |
| 1214 | if (info) |
| 1215 | { |
| 1216 | s += info->GetString().c_str(); |
| 1217 | s += tr( "Audio decoder: " ); |
| 1218 | s += player->GetAudioFormat(); |
| 1219 | s += '\n'; |
| 1220 | delete info; |
| 1221 | } |
| 1222 | |
| 1223 | //printf("%s", s.ascii()); |
| 1224 | // latin-1 ? utf-8 ? |
| 1225 | QMessageBox::information( 0, tr( "About stream" ), s ); |
| 1226 | } |
| 1227 | |
| 1228 | void PlayerControl::middle_button() |
| 1229 | { |
| 1230 | int qtkey = 0, qtascii = 0; |
| 1231 | |
| 1232 | int w, h; |
| 1233 | player->Get(player->QUERY_VIDEO_WIDTH, &w, |
| 1234 | player->QUERY_VIDEO_HEIGHT, &h, |
| 1235 | 0); |
| 1236 | int iw = player->GetWidth(); |
| 1237 | int ih = player->GetHeight(); |
| 1238 | switch((m_iResizeCount + 1) % 3) |
| 1239 | { |
| 1240 | case 0: |
| 1241 | // zoom 50% |
| 1242 | qtkey = Qt::Key_1; |
| 1243 | qtascii = '1'; |
| 1244 | break; |
| 1245 | case 1: |
| 1246 | // zoom 100% |
| 1247 | qtkey = Qt::Key_2; |
| 1248 | qtascii = '2'; |
| 1249 | break; |
| 1250 | case 2: |
| 1251 | // zoom 200% |
| 1252 | qtkey = Qt::Key_3; |
| 1253 | qtascii = '3'; |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | sendKeyEvent(qtkey, qtascii); |
| 1258 | |
| 1259 | m_bKeyProcessed = false; |
| 1260 | // intentionaly setting false here ! |
| 1261 | // this is like sync point - this will |
| 1262 | // reset keyboard processed status |
| 1263 | // just in case something wrong happened before |
| 1264 | } |
| 1265 | |
| 1266 | void PlayerControl::readConfig() |
| 1267 | { |
| 1268 | if (player) |
| 1269 | { |
| 1270 | // FIXME |
| 1271 | bool ht; |
| 1272 | char* vcodecs = 0; |
| 1273 | char* acodecs = 0; |
| 1274 | |
| 1275 | player->Get(player->DISPLAY_FRAME_POS, &m_bDisplayFramePos, |
| 1276 | player->USE_HTTP_PROXY, &ht, |
| 1277 | player->VIDEO_CODECS, &vcodecs, |
| 1278 | player->AUDIO_CODECS, &acodecs, |
| 1279 | 0); |
| 1280 | if (ht) |
| 1281 | { |
| 1282 | char* proxy = 0; |
| 1283 | player->Get(player->HTTP_PROXY, &proxy, 0); |
| 1284 | if (proxy) |
| 1285 | { |
| 1286 | if (strlen(proxy)) |
| 1287 | avm_setenv("HTTP_PROXY", proxy, 1); |
| 1288 | free(proxy); |
| 1289 | } |
| 1290 | } |
| 1291 | else avm_unsetenv("HTTP_PROXY"); |
| 1292 | |
| 1293 | if (vcodecs) |
| 1294 | { |
| 1295 | avm::SortVideoCodecs(vcodecs); |
| 1296 | free(vcodecs); |
| 1297 | } |
| 1298 | if (acodecs) |
| 1299 | { |
| 1300 | avm::SortAudioCodecs(acodecs); |
| 1301 | free(acodecs); |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void PlayerControl::reseekSlot() |
| 1307 | { |
| 1308 | if (!player || !m_pMW) |
| 1309 | return; |
| 1310 | |
| 1311 | double p = (m_pMW->m_pScroller->value() / (double) MAX_MBAR) * m_dLengthTime; |
| 1312 | p += m_dStartTime; |
| 1313 | m_bInReseek = true; |
| 1314 | player->ReseekExact(p); |
| 1315 | updatePos(); |
| 1316 | m_bIsTracking = false; |
| 1317 | m_bInReseek = false; |
| 1318 | } |
| 1319 | |
| 1320 | void killer(int z) |
| 1321 | { |
| 1322 | printf("quit_flag=1\n"); |
| 1323 | } |
| 1324 | |
| 1325 | int PlayerControl::initPlayer(AviPlayerInitParams& uapip) |
| 1326 | { |
| 1327 | if (&apip != &uapip) |
| 1328 | apip = uapip; |
| 1329 | |
| 1330 | last_slider = 0; |
| 1331 | endPlayer(); |
| 1332 | |
| 1333 | if (m_pMW) |
| 1334 | { |
| 1335 | m_pMW->m_pScroller->setValue(0); |
| 1336 | m_pMW->m_pLStatus->setText( tr( "Opening..." ) ); |
| 1337 | } |
| 1338 | |
| 1339 | if (apip.urls.size() == 0) |
| 1340 | apip.urls.push_back(""); |
| 1341 | |
| 1342 | while (apip.urls.size()) |
| 1343 | { |
| 1344 | //printf("INIT %s %d\n", apip.urls[apip.idx].c_str(), apip.idx); |
| 1345 | if (apip.idx >= apip.urls.size()) |
| 1346 | apip.idx = 0; |
| 1347 | |
| 1348 | player = CreateAviPlayer2(this, m_pMW->x11Display(), |
| 1349 | apip.urls[apip.idx].c_str(), |
| 1350 | apip.subname.ascii(), 0, |
| 1351 | apip.vcodec.ascii(), |
| 1352 | apip.acodec.ascii()); |
| 1353 | if (player) |
| 1354 | { |
| 1355 | starterSlot(); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | //printf("URLSIZE %d %d\n", apip.idx, apip.urls.size()); |
| 1359 | apip.urls.erase(&apip.urls[apip.idx]); |
| 1360 | } |
| 1361 | return -1; |
| 1362 | } |
| 1363 | |
| 1364 | void PlayerControl::starterSlot() |
| 1365 | { |
| 1366 | if (!player->IsOpened()) |
| 1367 | { |
| 1368 | if (!m_TimerStarter->isActive()) |
| 1369 | m_TimerStarter->start(100); |
| 1370 | // periodicaly check and loop until the file is opened |
| 1371 | return; |
| 1372 | } |
| 1373 | |
| 1374 | m_TimerStarter->stop(); |
| 1375 | if (!player->IsValid()) |
| 1376 | { |
| 1377 | // may be show a message box here? |
| 1378 | if (m_pMW) |
| 1379 | m_pMW->m_pLStatus->setText( tr( "Failed to open" ) ); |
| 1380 | apip.urls.erase(&apip.urls[apip.idx]); |
| 1381 | if (apip.urls.size()) |
| 1382 | initPlayer(apip); // recursive call - FIXME |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | //printf("OPENED2 %p v:%d r:%d\n", player, player->IsValid(), player->IsRedirector()); |
| 1387 | m_Filename = apip.urls[apip.idx].c_str(); |
| 1388 | if (player->IsRedirector()) |
| 1389 | { |
| 1390 | player->GetURLs(apip.urls); |
| 1391 | if (!apip.urls.size()) |
| 1392 | { |
| 1393 | printf("Redirector with no entries?\n"); |
| 1394 | if (m_pMW) |
| 1395 | m_pMW->m_pLStatus->setText( tr( "No redirector entries" ) ); |
| 1396 | return; |
| 1397 | } |
| 1398 | initPlayer(apip); // recursive call - FIXME |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | WS("url", m_Filename.ascii()); |
| 1403 | |
| 1404 | if (apip.subname) |
| 1405 | { |
| 1406 | WS("subtitle-url", apip.subname); |
| 1407 | m_Subname = apip.subname; |
| 1408 | } |
| 1409 | readConfig(); |
| 1410 | //if (quality == 11) |
| 1411 | // player->SetDecodingMode(IVideoDecoder::REALTIME_QUALITY_AUTO); |
| 1412 | if (m_pMW) |
| 1413 | volumeChanged(m_pMW->vbar->value()); |
| 1414 | //printf("X %d Y %d\n", apip.x, apip.y); |
| 1415 | |
| 1416 | if (m_pMW) |
| 1417 | m_pMW->setCaption( QFile::decodeName( m_Filename.ascii() ) ); |
| 1418 | |
| 1419 | playSlot(); |
| 1420 | |
| 1421 | if (-8192 <= apip.x && apip.x <= 8192 |
| 1422 | && -8192 <= apip.y && apip.y <= 8192) |
| 1423 | { |
| 1424 | const avm::vector<avm::IVideoRenderer*>& v = player->GetVideoRenderers(); |
| 1425 | if (v.size()) |
| 1426 | v.front()->SetPosition(apip.x, apip.y); |
| 1427 | } |
| 1428 | |
| 1429 | //printf("STARTTIME %f\n", m_dStartTime); |
| 1430 | if (apip.seek > 0.0) |
| 1431 | player->ReseekExact(apip.seek); |
| 1432 | |
| 1433 | if (apip.width && apip.height) |
| 1434 | resizePlayer(apip.width, apip.height); |
| 1435 | |
| 1436 | // wait here - so all graphics is initialized & opened |
| 1437 | if (apip.maximize) |
| 1438 | { |
| 1439 | apip.maximize = !apip.maximize; |
| 1440 | sendMaximize(); |
| 1441 | } |
| 1442 | else if (apip.fullscreen) |
| 1443 | { |
| 1444 | apip.fullscreen = !apip.fullscreen; |
| 1445 | sendFullscreen(); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void PlayerControl::endPlayer() |
| 1450 | { |
| 1451 | stopSlot(); |
| 1452 | delete popup; |
| 1453 | popup = 0; |
| 1454 | delete m_pAboutPopup; |
| 1455 | m_pAboutPopup = 0; |
| 1456 | delete m_pOpenPopup; |
| 1457 | m_pOpenPopup = 0; |
| 1458 | |
| 1459 | if (player) |
| 1460 | { |
| 1461 | const avm::vector<avm::IVideoRenderer*>& v = player->GetVideoRenderers(); |
| 1462 | //printf("SETPOSITION %d %d\n", apip.x, apip.y); |
| 1463 | if (v.size()) |
| 1464 | v.front()->GetPosition(apip.x, apip.y); |
| 1465 | delete player; |
| 1466 | } |
| 1467 | player = 0; |
| 1468 | } |
| 1469 | |
| 1470 | void PlayerControl::updatePosDisplay(double timepos) |
| 1471 | { |
| 1472 | if (!player) |
| 1473 | return; |
| 1474 | |
| 1475 | double percent = 0; |
| 1476 | avm::IAviPlayer::State state = player->GetState(&percent); |
| 1477 | |
| 1478 | if (state == avm::IAviPlayer::Playing |
| 1479 | || state == avm::IAviPlayer::Paused |
| 1480 | || state == avm::IAviPlayer::Buffering) |
| 1481 | { |
| 1482 | char timing[50]; |
| 1483 | double len = player->GetLengthTime(); |
| 1484 | double stream_time = player->GetTime(); |
| 1485 | //printf("POS %f %f\n", timepos, stream_time); |
| 1486 | if (timepos > stream_time + 2 || timepos < stream_time - 2) |
| 1487 | //user is seeking - show the time for seek-bar |
| 1488 | stream_time = timepos; |
| 1489 | |
| 1490 | char* spos = timing; |
| 1491 | |
| 1492 | if (stream_time >= 3600) |
| 1493 | spos += sprintf(spos, "%u:%02u:%02u", uint_t(stream_time/3600), |
| 1494 | uint_t(stream_time/60)%60, uint_t(stream_time)%60); |
| 1495 | else |
| 1496 | spos += sprintf(spos, "%u:%02u", uint_t(stream_time/60)%60, |
| 1497 | uint_t(stream_time)%60); |
| 1498 | |
| 1499 | if (m_bDisplayFramePos) |
| 1500 | // more precise timeing with frame position |
| 1501 | spos += sprintf(spos, ".%03u", uint_t(stream_time*1000)%1000); |
| 1502 | |
| 1503 | if (len >= 0x7fffffff) |
| 1504 | spos += sprintf(spos, "/Live"); |
| 1505 | else |
| 1506 | { |
| 1507 | if (len >= 3600) |
| 1508 | spos += sprintf(spos, "/%u:%02u:%02u", uint_t(len/3600), |
| 1509 | uint_t(len/60)%60, uint_t(len)%60); |
| 1510 | else |
| 1511 | spos += sprintf(spos, "/%u:%02u", uint_t(len/60)%60, uint_t(len)%60); |
| 1512 | } |
| 1513 | |
| 1514 | if (player->GetVideoLengthTime() > 0) |
| 1515 | { |
| 1516 | if (m_bDisplayFramePos) |
| 1517 | spos += sprintf(spos, " (%u)", player->GetFramePos()); |
| 1518 | |
| 1519 | if (m_pMW && m_pMW->pbar) |
| 1520 | { |
| 1521 | int prog; |
| 1522 | player->Get(player->QUERY_AVG_QUALITY, &prog, 0); |
| 1523 | #if QT_VERSION <= 220 |
| 1524 | m_pMW->pbar->reset(); |
| 1525 | #endif |
| 1526 | m_pMW->pbar->setProgress(prog); |
| 1527 | } |
| 1528 | } |
| 1529 | else |
| 1530 | { |
| 1531 | if (m_pMW && m_pMW->pbar) |
| 1532 | { |
| 1533 | #if QT_VERSION <= 220 |
| 1534 | m_pMW->pbar->reset(); |
| 1535 | #endif |
| 1536 | m_pMW->pbar->setProgress((int)(percent * 100)); |
| 1537 | } |
| 1538 | |
| 1539 | } |
| 1540 | |
| 1541 | if (percent < 0.01) |
| 1542 | { |
| 1543 | player->Pause(true); |
| 1544 | m_bUnpause = true; |
| 1545 | } |
| 1546 | else if (m_bUnpause && percent > 0.21) |
| 1547 | { |
| 1548 | player->Pause(false); |
| 1549 | m_bUnpause = false; |
| 1550 | } |
| 1551 | if (m_pMW) |
| 1552 | m_pMW->m_pLTime->setText(timing); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | void PlayerControl::movedSlot(int value) |
| 1557 | { |
| 1558 | double t = value * m_dLengthTime / MAX_MBAR + m_dStartTime; |
| 1559 | updatePosDisplay((int)(t)); |
| 1560 | } |
| 1561 | |
| 1562 | void PlayerControl::updatePos() |
| 1563 | { |
| 1564 | if (!player) |
| 1565 | return; |
| 1566 | |
| 1567 | double dpos = player->GetTime(); |
| 1568 | |
| 1569 | if (m_pMW) |
| 1570 | { |
| 1571 | int v; |
| 1572 | player->Get(player->AUDIO_VOLUME, &v, 0); |
| 1573 | m_pMW->vbar->setValue(v * MAX_VBAR / 1000); |
| 1574 | } |
| 1575 | |
| 1576 | if (player->IsPlaying()) |
| 1577 | { |
| 1578 | bool b; |
| 1579 | player->Get(player->QUERY_EOF, &b, 0); |
| 1580 | if (b) |
| 1581 | { |
| 1582 | player->Get(player->AUTOREPEAT, &b, 0); |
| 1583 | //printf("\n\n\nAUTOREP %d %d %d\n", b, apip.urls.size(), apip.idx); |
| 1584 | if (b) |
| 1585 | { |
| 1586 | if (apip.urls.size() > 1) |
| 1587 | { |
| 1588 | apip.idx++; |
| 1589 | initPlayer(apip); |
| 1590 | return; |
| 1591 | } |
| 1592 | else |
| 1593 | player->ReseekExact(0.0); |
| 1594 | } |
| 1595 | else |
| 1596 | { |
| 1597 | if (apip.urls.size() > 1) |
| 1598 | { |
| 1599 | apip.idx++; |
| 1600 | if (apip.idx < apip.urls.size()) |
| 1601 | { |
| 1602 | initPlayer(apip); |
| 1603 | return; |
| 1604 | } |
| 1605 | } |
| 1606 | sendEvent(Q_MyCloseEvent); |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | if (!m_bIsTracking && m_pMW) |
| 1612 | { |
| 1613 | m_bSettingScroller = true; |
| 1614 | m_dLengthTime = player->GetLengthTime(); |
| 1615 | if (m_dLengthTime >= 0x7fffffff) |
| 1616 | m_dLengthTime = 1; |
| 1617 | else |
| 1618 | m_dLengthTime -= m_dStartTime; |
| 1619 | |
| 1620 | // Scroll bar |
| 1621 | m_pMW->m_pScroller->setValue((int) (MAX_MBAR * (dpos - m_dStartTime) / m_dLengthTime)); |
| 1622 | m_bSettingScroller = false; |
| 1623 | } |
| 1624 | |
| 1625 | int w = 400; |
| 1626 | if (m_pMW) { |
| 1627 | double percent; |
| 1628 | QString status; |
| 1629 | int drop; |
| 1630 | avm::IAviPlayer::State state = player->GetState(&percent); |
| 1631 | |
| 1632 | #ifndef HAVE_LIBSDL |
| 1633 | w = m_pMW->width(); |
| 1634 | #endif |
| 1635 | switch(state) |
| 1636 | { |
| 1637 | case avm::IAviPlayer::Invalid: |
| 1638 | status = tr( "Invalid stream" ); |
| 1639 | break; |
| 1640 | case avm::IAviPlayer::Opening: |
| 1641 | status = tr( "Opening..." ); |
| 1642 | break; |
| 1643 | case avm::IAviPlayer::Buffering: |
| 1644 | status.sprintf( tr( "Buffering: %d%%" ).ascii(), int(100.*percent) ); |
| 1645 | break; |
| 1646 | case avm::IAviPlayer::Paused: |
| 1647 | status = tr( "Paused" ); |
| 1648 | break; |
| 1649 | case avm::IAviPlayer::Stopped: |
| 1650 | status = tr( "Stopped" ); |
| 1651 | break; |
| 1652 | case avm::IAviPlayer::Playing: |
| 1653 | player->Get(player->QUERY_AVG_DROP, &drop, 0); |
| 1654 | if (drop > 0) |
| 1655 | status.sprintf( tr( "Drop: %d%%" ).ascii(), drop ); |
| 1656 | else |
| 1657 | status = tr( "Playing..." ); |
| 1658 | break; |
| 1659 | } |
| 1660 | |
| 1661 | m_pMW->m_pLStatus->setText(status); |
| 1662 | } |
| 1663 | |
| 1664 | if(w > 90 && m_bIsTracking != 1) |
| 1665 | updatePosDisplay((int)dpos); |
| 1666 | } |
| 1667 | |
| 1668 | void PlayerControl::help() |
| 1669 | { |
| 1670 | QMessageBox::information( 0, tr( "aviplay usage" ), tr( |
| 1671 | "<h3>Usage:</h3>" |
| 1672 | "aviplay [options] [your-file(s)]<br>" |
| 1673 | "<h3>Key bindings:</h3>" |
| 1674 | "Cursor left/right - previous/next keyframe.<br>" |
| 1675 | "Cursor up/down - 60 seconds backward/forward.<br>" |
| 1676 | "PageUp/PageDown - 10 seconds backward/forward.<br>" |
| 1677 | "Enter/Backspace - display next/previous(slow!) frame.<br>" |
| 1678 | "Home/End - movie begin/end.<br>" |
| 1679 | "Back, Insert, < / >, Delete, Forward - previous/next file. (if more files given)<br>" |
| 1680 | "Keypad '+', 9/0, Keypad'-' - volume up/down.<br>" |
| 1681 | "F, Escape, Alt + Enter - toggles fullscreen/windowed mode.<br>" |
| 1682 | "M - toggles fullscreen/windowed mode with maximization.<br>" |
| 1683 | "N - swith to next audio stream (if available).<br>" |
| 1684 | "Q - quit<br>" |
| 1685 | "X - stop<br>" |
| 1686 | "V - play<br>" |
| 1687 | "[ / ] - adjust A-V sync by 0.1 second.<br>" |
| 1688 | "C, P, Space - pause<br>" |
| 1689 | "1, 2, 3 - switch zoom 0.5x, 1x, 2x.<br>" |
| 1690 | "Left-click in player window - pause/play.<br>" |
| 1691 | "Right-click in movie window brings up zoom/fullscreen menu.<br>" |
| 1692 | "F1/F2, F5/F6, F7/F8, F9/F10 - set Saturation, Brightness, Hue, Contrast.<br>" |
| 1693 | //"Double-click in player window when paused/stopped " |
| 1694 | //"to bring up configuration menu.<br>" |
| 1695 | ), QMessageBox::Ok ); |
| 1696 | } |
| 1697 | |
| 1698 | void PlayerControl::about() |
| 1699 | { |
| 1700 | QMessageBox::information( 0, tr( "aviplay about" ), tr( |
| 1701 | "aviplay version: %1<br>" |
| 1702 | "(C) 2000 - 2009 Zdenek Kabelác, Eugene Kuznetsov <br>" |
| 1703 | "Based on avifile ( <a href=\"http://avifile.sf.net\">http://avifile.sourceforge.net/</a>).<br>" |
| 1704 | "Distributed under the GNU Public Licence (GPL) version 2.<br>" |
| 1705 | "Special thanks to: " |
| 1706 | "<ul>" |
| 1707 | "<li>Authors of ffmpeg project." |
| 1708 | "<li>Authors of Wine project for Win32 DLL loading code." |
| 1709 | "<li>Avery Lee for AVI and ASF parser and his VirtualDub." |
| 1710 | "<li>Hiroshi Yamashita for porting sources to FreeBSD." |
| 1711 | "<li>Jürgen Keil for porting sources to Solaris 8 x86." |
| 1712 | "<li>Árpád Gereöffy (A'rpi/ESP-team) and the rest of Mplayer team." |
| 1713 | "<li>All people from avifile mailing lists for their patience and support." |
| 1714 | "</ul>" ).arg( AVIFILE_BUILD ), QMessageBox::Ok ); |
| 1715 | } |
| 1716 | |
| 1717 | void PlayerControl::dropEvent(QDropEvent* e) |
| 1718 | { |
| 1719 | QStrList i; |
| 1720 | QUriDrag::decode(e, i); |
| 1721 | const char* uri = i.first(); |
| 1722 | |
| 1723 | if (!uri || strlen(uri) < 6) |
| 1724 | return; |
| 1725 | |
| 1726 | QString file; |
| 1727 | |
| 1728 | if (0 == qstrnicmp(uri,"file:/",6) ) |
| 1729 | { |
| 1730 | uri += 6; |
| 1731 | if ( uri[0] != '/' || uri[1] == '/' ) |
| 1732 | { |
| 1733 | // It is local. |
| 1734 | file = QUriDrag::uriToUnicodeUri(uri); |
| 1735 | if ( (uri[1] == '/') && (uri[0]=='/') ) |
| 1736 | file.remove(0,1); |
| 1737 | else |
| 1738 | file.insert(0,'/'); |
| 1739 | |
| 1740 | apip.urls.push_back((const char*)file.ascii()); |
| 1741 | initPlayer(apip); |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | void PlayerControl::dragEnterEvent(QDragEnterEvent* e) |
| 1747 | { |
| 1748 | e->accept(QUriDrag::canDecode(e)); |
| 1749 | } |
| 1750 | |
| 1751 | void PlayerControl::hideSlot() |
| 1752 | { |
| 1753 | m_pTimer->stop(); |
| 1754 | updatePos(); |
| 1755 | } |
| 1756 | |
| 1757 | void PlayerControl::showSlot() |
| 1758 | { |
| 1759 | updatePos(); |
| 1760 | m_pTimer->start(1000); // updatepos timer |
| 1761 | } |