1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
|
/*
***************************************************************************
*
* Author: Teunis van Beelen
*
* Copyright (C) 2007 - 2023 Teunis van Beelen
*
* Email: teuniz@protonmail.com
*
***************************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
***************************************************************************
*/
#include "mainwindow.h"
//#define DEBUG_VIDEOPLAYER
#ifdef DEBUG_VIDEOPLAYER
FILE *debug_vpr;
#endif
void UI_Mainwindow::start_stop_video()
{
int process_start_retries,
sock_connect_retries,
err,
port,
connected=0;
char str[4096]={""};
QEventLoop evlp;
QMessageBox msgbox(QMessageBox::Critical, "Error", "text", QMessageBox::Close);
QString qstr;
if(video_player->status != VIDEO_STATUS_STOPPED)
{
stop_video_generic(0);
video_pause_requested = 0;
return;
}
if(playback_realtime_active)
{
playback_realtime_timer->stop();
playback_realtime_active = 0;
}
if(live_stream_active)
{
msgbox.setText("Can not open a video during a live stream.");
msgbox.exec();
video_pause_requested = 0;
return;
}
if(video_player->status != VIDEO_STATUS_STOPPED)
{
msgbox.setText("There is already a video running.");
msgbox.exec();
video_pause_requested = 0;
return;
}
if(signalcomps < 1)
{
msgbox.setText("Put some signals on the screen first.");
msgbox.exec();
video_pause_requested = 0;
return;
}
// if(annot_editor_active)
// {
// msgbox.setText("Close the annotation editor first.");
// msgbox.exec();
// video_pause_requested = 0;
// return;
// }
if(!session_start_video)
{
strlcpy(videopath, QFileDialog::getOpenFileName(this, "Select media file", QString::fromLocal8Bit(recent_video_opendir),
"Video files (*.mkv *.mp4 *.mpg *.mpeg *.avi *.webm *.ogv *.ogg *.wmv *.mov *.m4v);;Audio files (*.wav *.ogg *.flac *.mp3 *.aac *.m4a *.wma);;All files (*)").toLocal8Bit().data(), MAX_PATH_LENGTH);
}
if(!strcmp(videopath, ""))
{
video_pause_requested = 0;
return;
}
get_directory_from_path(recent_video_opendir, videopath, MAX_PATH_LENGTH);
if(!session_start_video)
{
video_player->utc_starttime = parse_date_time_stamp(videopath);
if(video_player->utc_starttime < 0LL)
{
msgbox.setIcon(QMessageBox::Warning);
msgbox.setWindowTitle("Warning");
msgbox.setText(" \nCannot find startdate and starttime in video filename.\n"
" \nAssume video starttime equals EDF/BDF starttime?\n ");
msgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
msgbox.setDefaultButton(QMessageBox::Yes);
if(msgbox.exec() == QMessageBox::Cancel)
{
video_pause_requested = 0;
return;
}
video_player->utc_starttime = edfheaderlist[sel_viewtime]->utc_starttime;
}
}
else
{
video_player->utc_starttime = session_video_starttime;
}
video_player->stop_det_counter = 0;
video_player->fpos = 0;
video_player->starttime_diff = (int)(edfheaderlist[sel_viewtime]->utc_starttime - video_player->utc_starttime);
msgbox.setIcon(QMessageBox::Critical);
msgbox.setWindowTitle("Error");
msgbox.setStandardButtons(QMessageBox::Close);
if((edfheaderlist[sel_viewtime]->utc_starttime + edfheaderlist[sel_viewtime]->recording_len_sec) < video_player->utc_starttime)
{
msgbox.setText("The video registration and the EDF/BDF registration do not overlap (in time)");
msgbox.exec();
video_pause_requested = 0;
return;
}
if((video_player->utc_starttime + 259200LL) < edfheaderlist[sel_viewtime]->utc_starttime)
{
msgbox.setText("The video registration and the EDF/BDF registration do not overlap (in time)");
msgbox.exec();
video_pause_requested = 0;
return;
}
QStringList arguments;
msgbox.setIcon(QMessageBox::NoIcon);
msgbox.setWindowTitle("Starting");
msgbox.setStandardButtons(QMessageBox::Abort);
msgbox.setText(" \n Starting the video player, please wait ... \n ");
msgbox.show();
for(process_start_retries=0; process_start_retries<3; process_start_retries++)
{
connected = 0;
arguments.clear();
port = (time(NULL) % 1000) + 3000 + process_start_retries;
snprintf(str, 4096, "localhost:%i", port);
video_process = new QProcess(0);
#ifdef Q_OS_WIN32
qstr = QDir::toNativeSeparators(QString::fromLocal8Bit(videopath));
strlcpy(videopath, qstr.toLocal8Bit().data(), MAX_PATH_LENGTH);
arguments << "-I" << "rc" << "--rc-host" << str << "--rc-quiet" << "--video-on-top" << "--width" << "150" << "--height" << "150" << "--ignore-config";
video_process->start("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe", arguments);
if(video_process->waitForStarted(5000) == false)
{
video_process->start("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe", arguments);
if(video_process->waitForStarted(5000) == false)
{
QTimer::singleShot(300, &evlp, SLOT(quit()));
evlp.exec();
delete video_process;
video_process = NULL;
continue;
}
}
#else
arguments << "-I" << "rc" << "--rc-host" << str << "--video-on-top" << "--width" << "150" << "--height" << "150" << "--ignore-config";
#ifdef Q_OS_MACOS
video_process->start("/Applications/VLC.app/Contents/MacOS/VLC", arguments);
#else
video_process->start("vlc", arguments);
#endif
if(video_process->waitForStarted(5000) == false)
{
QTimer::singleShot(300, &evlp, SLOT(quit()));
evlp.exec();
delete video_process;
video_process = NULL;
continue;
}
#endif
// msgbox.setText(" \n Opening a socket to the video player, please wait ... \n ");
for(sock_connect_retries=0; sock_connect_retries<3; sock_connect_retries++)
{
QTimer::singleShot(3000, &evlp, SLOT(quit()));
evlp.exec();
vlc_sock = new QTcpSocket;
vlc_sock->setSocketOption(QAbstractSocket::LowDelayOption, QVariant(1));
vlc_sock->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1));
vlc_sock->connectToHost(QHostAddress("127.0.0.1"), port);
if(vlc_sock->waitForConnected(5000) == true)
{
connected = 1;
break;
}
}
if(connected) break;
if(sock_connect_retries == 3)
{
if(process_start_retries == 2)
{
err = vlc_sock->error();
snprintf(str, 4096, " \n Cannot connect to the video player via localhost loopback port (error %i) \n ", err);
msgbox.setWindowTitle("Error");
msgbox.setStandardButtons(QMessageBox::Close);
msgbox.setText(str);
msgbox.exec();
msgbox.setText(" \n Closing the video player, please wait... \n ");
msgbox.show();
if(vlc_sock->state() != QAbstractSocket::UnconnectedState)
{
vlc_sock->disconnectFromHost();
vlc_sock->waitForDisconnected(5000);
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
}
video_process->kill();
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
delete video_process;
video_process = NULL;
delete vlc_sock;
vlc_sock = NULL;
msgbox.close();
video_pause_requested = 0;
return;
}
else
{
if(vlc_sock->state() != QAbstractSocket::UnconnectedState)
{
vlc_sock->disconnectFromHost();
vlc_sock->waitForDisconnected(5000);
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
}
video_process->kill();
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
delete video_process;
video_process = NULL;
delete vlc_sock;
vlc_sock = NULL;
}
}
}
if(process_start_retries == 3)
{
msgbox.setWindowTitle("Error");
#ifdef Q_OS_WIN32
msgbox.setText(" \n Cannot start the video player. \n"
" \n Check if VLC is installed in C:\\Program Files\\VideoLAN\\VLC\\ \n "
" or\n "
" \n C:\\Program Files (x86)\\VideoLAN\\VLC\\\n ");
#else
#ifdef Q_OS_MACOS
msgbox.setText(" \n Cannot start the video player. \n "
" \n Check if VLC is installed in /Applications/. \n ");
#else
msgbox.setText(" \n Cannot start the video player. \n "
" \n Check your installation of VLC. \n ");
#endif
#endif
msgbox.setStandardButtons(QMessageBox::Close);
msgbox.exec();
video_pause_requested = 0;
return;
}
#ifdef DEBUG_VIDEOPLAYER
debug_vpr = fopen("debug_vpr.txt", "wb");
#endif
msgbox.close();
playback_file_Act->setText("[pause]");
playback_file_Act->setIcon(QIcon(":/images/media-playback-pause-symbolic.symbolic.png"));
video_player->status = VIDEO_STATUS_STARTUP_1;
video_player->poll_timer = 100;
video_player->cntdwn_timer = 5000;
video_player->speed = 1;
video_poll_timer->start(video_player->poll_timer);
video_act->setText("Stop video");
navtoolbar->setVisible(true);
slidertoolbar->setVisible(true);
connect(video_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(video_process_error(QProcess::ProcessError)));
// connect(vlc_sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(vlc_sock_error(QAbstractSocket::SocketError)));
}
void UI_Mainwindow::video_poll_timer_func()
{
int i, p=0, err=0, len, vpos=0;
static int repeat=0;
char buf[4096];
if(video_player->status == VIDEO_STATUS_STOPPED) return;
if(video_player->status != VIDEO_STATUS_PAUSED)
{
video_player->cntdwn_timer -= video_player->poll_timer;
}
if(video_player->cntdwn_timer <= 0)
{
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_cntdwn_timer: <0\n");
#endif
stop_video_generic(2);
return;
}
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status: %i\n", video_player->status);
#endif
len = mpr_read(buf, 4095);
if((len < 1) && (video_player->status == VIDEO_STATUS_PLAYING))
{
video_poll_timer->start(video_player->poll_timer);
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_poll_timer_set & no message & return\n");
#endif
return;
}
if(video_player->status < VIDEO_STATUS_PLAYING)
{
if(video_player->status == VIDEO_STATUS_STARTUP_1)
{
while(mpr_read(buf, 4095) > 0) ;
mpr_write("clear\n");
video_player->status = VIDEO_STATUS_STARTUP_2;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
repeat = 3;
}
else if(video_player->status == VIDEO_STATUS_STARTUP_2)
{
if(repeat)
{
repeat--;
}
else
{
strlcpy(buf, "add ", 4096);
strlcat(buf, videopath, 4096);
strlcat(buf, "\n", 4096);
mpr_write(buf);
video_player->status = VIDEO_STATUS_STARTUP_3;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
repeat = 5;
}
}
else if(video_player->status == VIDEO_STATUS_STARTUP_3)
{
if(repeat)
{
repeat--;
}
else
{
mpr_write("vzoom 0.25\n");
video_player->status = VIDEO_STATUS_STARTUP_4;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
repeat = 5;
}
}
else if(video_player->status == VIDEO_STATUS_STARTUP_4)
{
if(repeat)
{
repeat--;
}
else
{
mpr_write("vzoom 0.25\n");
video_player->status = VIDEO_STATUS_STARTUP_5;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
repeat = 5;
}
}
else if(video_player->status == VIDEO_STATUS_STARTUP_5)
{
if(repeat)
{
repeat--;
}
else
{
mpr_write("volume 255\n");
faster_Act->setVisible(true);
slower_Act->setVisible(true);
if(session_start_video && (session_video_seek > 0))
{
video_player->status = VIDEO_STATUS_STARTUP_6;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
video_player_seek(session_video_seek);
session_video_seek = 0;
repeat = 5;
}
else
{
video_player->status = VIDEO_STATUS_PLAYING;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
video_pause_requested = 0;
session_video_seek = 0;
session_start_video = 0;
mpr_write("get_time\n");
}
}
}
else if(video_player->status == VIDEO_STATUS_STARTUP_6)
{
if(repeat)
{
repeat--;
}
else
{
video_player->status = VIDEO_STATUS_PLAYING;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_status_changed: %i\n", video_player->status);
#endif
if(session_start_video && video_pause_requested)
{
video_player_toggle_pause();
}
video_pause_requested = 0;
session_video_seek = 0;
session_start_video = 0;
mpr_write("get_time\n");
}
}
video_player->cntdwn_timer = 5000;
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_cntdwn_timer set\n");
#endif
video_poll_timer->start(video_player->poll_timer);
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_poll_timer set\n");
#endif
return;
}
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr_poll_timer_checking...\n");
#endif
if((video_player->status == VIDEO_STATUS_PLAYING) || (video_player->status == VIDEO_STATUS_PAUSED))
{
for(p=0; p<len; p++)
{
if((buf[p] != '>') && (buf[p] != ' '))
{
break;
}
}
if((len > (p + 2)) && (buf[len-1] == '\n'))
{
err = 0;
for(i=p; i<(len-1); i++)
{
if((buf[i] < '0') || (buf[i] > '9'))
err = 1;
break;
}
if(!err)
{
vpos = atoi(buf + p);
if(video_player->fpos != vpos)
{
jump_to_time_millisec(((video_player->utc_starttime - edfheaderlist[sel_viewtime]->utc_starttime + vpos) * 1000LL) - (pagetime / 20000LL));
video_player->fpos = vpos;
video_player->stop_det_counter = 0;
}
video_player->cntdwn_timer = 5000;
}
else
{
for(i=0; i<(len-11); i++)
{
if(!strncmp(buf + i, "stop state:", 11))
{
stop_video_generic(1);
return;
}
}
}
}
else if(buf[p] == '\r')
{
video_player->stop_det_counter += video_player->poll_timer;
if(video_player->stop_det_counter > 1500)
{
stop_video_generic(1);
return;
}
}
mpr_write("get_time\n");
}
video_poll_timer->start(video_player->poll_timer);
}
void UI_Mainwindow::video_player_faster()
{
char str[512];
if(video_player->status != VIDEO_STATUS_PLAYING)
{
return;
}
if(video_player->speed >= 4)
{
video_player->speed = 4;
return;
}
video_player->speed *= 2;
snprintf(str, 512, "rate %i\n", video_player->speed);
mpr_write(str);
}
void UI_Mainwindow::video_player_slower()
{
char str[512];
if(video_player->status != VIDEO_STATUS_PLAYING)
{
return;
}
if(video_player->speed <= 1)
{
video_player->speed = 1;
return;
}
video_player->speed /= 2;
snprintf(str, 512, "rate %i\n", video_player->speed);
mpr_write(str);
}
void UI_Mainwindow::video_player_seek(int sec)
{
char str[512];
if(((video_player->status != VIDEO_STATUS_PLAYING) && (video_player->status != VIDEO_STATUS_PAUSED)) &&
(!(session_start_video && (session_video_seek > 0) && (video_player->status == VIDEO_STATUS_STARTUP_6))))
{
return;
}
sec += video_player->starttime_diff;
if(sec < 0) sec = 0;
snprintf(str, 512, "seek %i\n", sec);
mpr_write(str);
video_player->cntdwn_timer = 5000;
}
void UI_Mainwindow::video_player_toggle_pause()
{
if(video_player->status == VIDEO_STATUS_STOPPED)
{
start_stop_video();
return;
}
if((video_player->status != VIDEO_STATUS_PLAYING) && (video_player->status != VIDEO_STATUS_PAUSED))
{
return;
}
mpr_write("pause\n");
if(video_player->status == VIDEO_STATUS_PLAYING)
{
video_player->status = VIDEO_STATUS_PAUSED;
playback_file_Act->setText("[play]");
playback_file_Act->setIcon(QIcon(":/images/media-playback-start-symbolic.symbolic.png"));
video_player->cntdwn_timer = 5000;
}
else
{
video_player->status = VIDEO_STATUS_PLAYING;
playback_file_Act->setText("[pause]");
playback_file_Act->setIcon(QIcon(":/images/media-playback-pause-symbolic.symbolic.png"));
}
}
void UI_Mainwindow::stop_video_generic(int stop_reason)
{
QEventLoop evlp;
video_pause_requested = 0;
faster_Act->setVisible(false);
slower_Act->setVisible(false);
video_poll_timer->stop();
if(video_player->status == VIDEO_STATUS_STOPPED) return;
video_player->status = VIDEO_STATUS_STOPPED;
playback_file_Act->setText("[play]");
playback_file_Act->setIcon(QIcon(":/images/media-playback-start-symbolic.symbolic.png"));
if(video_process == NULL) return;
disconnect(video_process, 0, 0, 0);
if(vlc_sock != NULL)
{
// disconnect(vlc_sock, 0, 0, 0);
}
QMessageBox msgbox(QMessageBox::NoIcon, "Wait", " \n Closing video, please wait ... \n ");
if(stop_reason == 1)
{
msgbox.setText(" \n Video has finished \n \n Closing the video player, please wait ... \n ");
}
if(stop_reason == 2)
{
msgbox.setText(" \n Video timeout error \n \n Closing the video player, please wait ... \n ");
}
msgbox.show();
#ifdef Q_OS_WIN32
mpr_write("quit\n");
#else
mpr_write("shutdown\n");
#endif
QObject::connect(&msgbox, SIGNAL(finished(int)), &evlp, SLOT(quit()));
QTimer::singleShot(2000, &evlp, SLOT(quit()));
evlp.exec();
video_process->waitForFinished(3000);
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
video_process->kill();
QTimer::singleShot(500, &evlp, SLOT(quit()));
evlp.exec();
delete video_process;
video_process = NULL;
if(vlc_sock != NULL)
{
if(vlc_sock->state())
{
vlc_sock->disconnectFromHost();
vlc_sock->waitForDisconnected(5000);
}
delete vlc_sock;
vlc_sock = NULL;
}
video_act->setText("Start video");
msgbox.close();
#ifdef DEBUG_VIDEOPLAYER
fclose(debug_vpr);
#endif
}
void UI_Mainwindow::vlc_sock_error(QAbstractSocket::SocketError)
{
char str[2048],
str2[1024];
if(video_player->status == VIDEO_STATUS_STOPPED) return;
strlcpy(str2, vlc_sock->errorString().toLatin1().data(), 1024);
stop_video_generic(0);
strlcpy(str, " \n The socked that connects to the mediaplayer reported an error: \n \n ", 2048);
strlcat(str, str2, 2048);
QMessageBox msgbox(QMessageBox::Critical, "Error", str);
msgbox.exec();
}
void UI_Mainwindow::video_process_error(QProcess::ProcessError)
{
char str[2048],
str2[1024];
if(video_player->status == VIDEO_STATUS_STOPPED) return;
strlcpy(str2, video_process->errorString().toLatin1().data(), 1024);
stop_video_generic(0);
strlcpy(str, " \n The process that runs the mediaplayer reported an error: \n \n ", 2048);
strlcat(str, str2, 2048);
QMessageBox msgbox(QMessageBox::Critical, "Error", str);
msgbox.exec();
}
void UI_Mainwindow::mpr_write(const char *cmd_str)
{
#ifdef DEBUG_VIDEOPLAYER
fprintf(debug_vpr, "edfbr: %s", cmd_str);
#endif
if(vlc_sock == NULL)
{
return;
}
if(vlc_sock->state() != QAbstractSocket::ConnectedState) return;
vlc_sock->write(cmd_str);
vlc_sock->waitForBytesWritten(200);
}
int UI_Mainwindow::mpr_read(char *buf, int sz)
{
if(vlc_sock == NULL)
{
return 0;
}
#ifdef DEBUG_VIDEOPLAYER
int n;
n = vlc_sock->readLine(buf, sz);
if(n > 0)
{
fprintf(debug_vpr, "vlc: %i bytes: %s ", n, buf);
for(int i=0; i<n; i++)
{
fprintf(debug_vpr, " 0x%02X", buf[i]);
}
fprintf(debug_vpr, "\n");
}
return n;
#else
return vlc_sock->readLine(buf, sz);
#endif
}
|