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
|
/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>
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; either version 2 of the License, or
(at your option) any later version.
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mpvprocess.h"
#include <QRegExp>
#include <QStringList>
#include <QApplication>
#include <QDebug>
#include "global.h"
#include "preferences.h"
#include "mplayerversion.h"
#include "colorutils.h"
using namespace Global;
#define CUSTOM_STATUS
#define TOO_CHAPTERS_WORKAROUND
MPVProcess::MPVProcess(QObject * parent)
: PlayerProcess(parent)
, notified_mplayer_is_running(false)
, notified_pause(false)
, received_end_of_file(false)
, last_sub_id(-1)
, mplayer_svn(-1) // Not found yet
, verbose(false)
#if NOTIFY_SUB_CHANGES
, subtitle_info_received(false)
, subtitle_info_changed(false)
, selected_subtitle(-1)
#endif
#if NOTIFY_AUDIO_CHANGES
, audio_info_changed(false)
, selected_audio(-1)
#endif
#if NOTIFY_VIDEO_CHANGES
, video_info_changed(false)
, selected_video(-1)
#endif
#if NOTIFY_CHAPTER_CHANGES
, chapter_info_changed(false)
#endif
, dvd_current_title(-1)
, br_current_title(-1)
{
player_id = PlayerID::MPV;
connect( this, SIGNAL(lineAvailable(QByteArray)),
this, SLOT(parseLine(QByteArray)) );
connect( this, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(processFinished(int,QProcess::ExitStatus)) );
connect( this, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(gotError(QProcess::ProcessError)) );
/* int svn = MplayerVersion::mplayerVersion("mpv unknown version (C)"); */
initializeOptionVars();
initializeRX();
}
MPVProcess::~MPVProcess() {
}
bool MPVProcess::start() {
md.reset();
notified_mplayer_is_running = false;
notified_pause = false;
last_sub_id = -1;
mplayer_svn = -1; // Not found yet
received_end_of_file = false;
#if NOTIFY_SUB_CHANGES
subs.clear();
subtitle_info_received = false;
subtitle_info_changed = false;
selected_subtitle = -1;
#endif
#if NOTIFY_AUDIO_CHANGES
audios.clear();
audio_info_changed = false;
selected_audio = -1;
#endif
#if NOTIFY_VIDEO_CHANGES
videos.clear();
video_info_changed = false;
selected_video = -1;
#endif
#if NOTIFY_CHAPTER_CHANGES
chapters.clear();
chapter_info_changed = false;
#endif
dvd_current_title = -1;
br_current_title = -1;
MyProcess::start();
return waitForStarted();
}
void MPVProcess::initializeRX() {
#ifdef CUSTOM_STATUS
rx_av.setPattern("^STATUS: ([0-9\\.-]+) / ([0-9\\.-]+) P: (yes|no) B: (yes|no) I: (yes|no) VB: ([0-9\\.-]+) AB: ([0-9\\.-]+)");
#else
rx_av.setPattern("^(\\((.*)\\) |)(AV|V|A): ([0-9]+):([0-9]+):([0-9]+) / ([0-9]+):([0-9]+):([0-9]+)"); //AV: 00:02:15 / 00:09:56
#endif
rx_dsize.setPattern("^INFO_VIDEO_DSIZE=(\\d+)x(\\d+)");
rx_vo.setPattern("^VO: \\[(.*)\\]");
rx_ao.setPattern("^AO: \\[(.*)\\]");
rx_paused.setPattern("^\\(Paused\\)");
rx_endoffile.setPattern("^Exiting... \\(End of file\\)");
rx_audio.setPattern("^.* Audio\\s+--aid=(\\d+)( --alang=([a-zA-Z-]+)|)([ \\(\\)\\*]+)('(.*)'|)");
rx_subs.setPattern("^.* Subs\\s+--sid=(\\d+)( --slang=([a-zA-Z-]+)|)([ \\(\\)\\*]+)('(.*)'|)");
rx_videocodec.setPattern("^INFO_VIDEO_CODEC=(.*)\\s");
rx_videocodec.setMinimal(true);
rx_audiocodec.setPattern("^INFO_AUDIO_CODEC=(.*)\\s");
rx_audiocodec.setMinimal(true);
#if !NOTIFY_VIDEO_CHANGES
rx_video.setPattern("^.* Video\\s+--vid=(\\d+)([ \\(\\)\\*]+)('(.*)'|)");
#endif
rx_chaptername.setPattern("^INFO_CHAPTER_(\\d+)_NAME=(.*)");
rx_trackinfo.setPattern("^INFO_TRACK_(\\d+): (audio|video|sub) (\\d+) '(.*)' '(.*)' (yes|no)");
rx_forbidden.setPattern("HTTP error 403 Forbidden");
#if DVDNAV_SUPPORT
rx_switch_title.setPattern("^\\[dvdnav\\] DVDNAV, switched to title: (\\d+)");
#endif
rx_playing.setPattern("^Playing:.*|^\\[ytdl_hook\\].*");
rx_generic.setPattern("^([A-Z_]+)=(.*)");
rx_stream_title.setPattern("icy-title: (.*)");
rx_debug.setPattern("^(INFO|METADATA)_.*=\\$.*");
#if 0
static QRegExp rx_subs2("^Sub:( >|) \\((\\d+)\\) '(.*)'");
static QRegExp rx_videoinfo("^\\[vd\\] VIDEO: .* (\\d+)x(\\d+) .* ([0-9.]+) fps"); // [vd] VIDEO: 624x352 25.000 fps 1018.5 kbps (127.3 kB/s)
#endif
}
void MPVProcess::parseLine(QByteArray ba) {
//qDebug() << "MPVProcess::parseLine:" << ba;
if (ba.isEmpty()) return;
QString tag;
QString value;
#if COLOR_OUTPUT_SUPPORT
QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
#else
#ifdef Q_OS_WIN
QString line = QString::fromUtf8(ba);
#else
QString line = QString::fromLocal8Bit(ba);
#endif
#endif
if (verbose) {
line.replace("[statusline] ", "");
line.replace("[cplayer] ", "");
line.replace("[term-msg] ", "");
if (rx_debug.indexIn(line) > -1) {
line = "[debug] " + line;
}
}
static double last_sec = -1;
// Parse A: V: line
//qDebug("MPVProcess::parseLine: %s", line.toUtf8().data());
if (rx_av.indexIn(line) > -1) {
#ifdef CUSTOM_STATUS
double sec = rx_av.cap(1).toDouble();
double length = rx_av.cap(2).toDouble();
bool paused = (rx_av.cap(3) == "yes");
bool buffering = (rx_av.cap(4) == "yes");
bool idle = (rx_av.cap(5) == "yes");
int video_bitrate = rx_av.cap(6).toInt();
int audio_bitrate = rx_av.cap(7).toInt();
if (length != md.duration) {
md.duration = length;
#if DVDNAV_SUPPORT
emit receivedDuration(length);
#endif
}
if (paused && notified_pause) {
if (last_sec != sec) {
last_sec = sec;
emit receivedCurrentSec(sec);
emit receivedPause();
}
return;
}
if (paused) {
notified_pause = true;
qDebug("MPVProcess::parseLine: paused");
emit receivedPause();
return;
}
else
if (buffering) {
qDebug("MPVProcess::parseLine: buffering");
emit receivedBuffering();
return;
}
else
if (idle) {
qDebug("MPVProcess::parseLine: idle");
emit receivedBuffering();
return;
}
notified_pause = false;
if (video_bitrate != md.video_bitrate) {
md.video_bitrate = video_bitrate;
emit receivedVideoBitrate(video_bitrate);
}
if (audio_bitrate != md.audio_bitrate) {
md.audio_bitrate = audio_bitrate;
emit receivedAudioBitrate(audio_bitrate);
}
#else
//qDebug() << rx_av.cap(1);
//qDebug() << rx_av.cap(2);
QString status = rx_av.cap(2).trimmed();
int i = 4;
int h = rx_av.cap(i++).toInt();
int m = rx_av.cap(i++).toInt();
int s = rx_av.cap(i++).toInt();
//qDebug("%d:%d:%d", h, m, s);
double sec = h * 3600 + m * 60 + s;
h = rx_av.cap(i++).toInt();
m = rx_av.cap(i++).toInt();
s = rx_av.cap(i++).toInt();
double length = h * 3600 + m * 60 + s;
if (length != md.duration) {
md.duration = length;
emit receivedDuration(length);
}
if (status == "Paused") {
emit receivedPause();
return;
}
else
if ((status == "...") || (status == "Buffering")) {
emit receivedBuffering();
return;
}
if (!status.isEmpty()) {
qDebug() << "MPVProcess::parseLine: status:" << status;
}
#endif
#if NOTIFY_SUB_CHANGES
if (notified_mplayer_is_running) {
if (subtitle_info_changed && sec > 0.4) {
qDebug("MPVProcess::parseLine: subtitle_info_changed");
subtitle_info_changed = false;
subtitle_info_received = false;
emit subtitleInfoChanged(subs, selected_subtitle);
}
if (subtitle_info_received) {
qDebug("MPVProcess::parseLine: subtitle_info_received");
subtitle_info_received = false;
emit subtitleInfoReceivedAgain(subs);
}
}
#endif
#if NOTIFY_AUDIO_CHANGES
if (notified_mplayer_is_running) {
if (audio_info_changed && sec > 0.4) {
qDebug("MPVProcess::parseLine: audio_info_changed");
audio_info_changed = false;
emit audioInfoChanged(audios, selected_audio);
}
}
#endif
#if NOTIFY_VIDEO_CHANGES
if (notified_mplayer_is_running) {
if (video_info_changed) {
qDebug("MPVProcess::parseLine: video_info_changed");
video_info_changed = false;
emit videoInfoChanged(videos, selected_video);
}
}
#endif
#if NOTIFY_CHAPTER_CHANGES
if (notified_mplayer_is_running) {
if (chapter_info_changed) {
qDebug("MPVProcess::parseLine: chapter_info_changed");
chapter_info_changed = false;
emit chaptersChanged(chapters);
}
}
#endif
if (!notified_mplayer_is_running) {
qDebug() << "MPVProcess::parseLine: starting sec:" << sec;
if (md.video_width == 0 || md.video_height == 0) {
md.novideo = true;
emit receivedNoVideo();
}
/*
if ( (md.n_chapters <= 0) && (dvd_current_title > 0) &&
(md.titles.find(dvd_current_title) != -1) )
{
int idx = md.titles.find(dvd_current_title);
md.n_chapters = md.titles.itemAt(idx).chapters();
qDebug("MPVProcess::parseLine: setting chapters to %d", md.n_chapters);
}
*/
/*
#if CHECK_VIDEO_CODEC_FOR_NO_VIDEO
// Another way to find out if there's no video
if (md.video_codec.isEmpty()) {
md.novideo = true;
emit receivedNoVideo();
}
#endif
*/
emit receivedStartingTime(sec);
emit mplayerFullyLoaded();
emit receivedCurrentFrame(0); // Ugly hack: set the frame counter to 0
notified_mplayer_is_running = true;
// Wait some secs to ask for bitrate
/*
QTimer::singleShot(12000, this, SLOT(requestBitrateInfo()));
*/
}
emit receivedCurrentSec( sec );
}
else {
emit lineAvailable(line);
// Parse other things
qDebug() << "MPVProcess::parseLine:" << line;
// End of file
if (rx_endoffile.indexIn(line) > -1) {
qDebug("MVPProcess::parseLine: detected end of file");
if (!received_end_of_file) {
// In case of playing VCDs or DVDs, maybe the first title
// is not playable, so the GUI doesn't get the info about
// available titles. So if we received the end of file
// first let's pretend the file has started so the GUI can have
// the data.
if ( !notified_mplayer_is_running) {
emit mplayerFullyLoaded();
}
// Send signal once the process is finished, not now!
received_end_of_file = true;
}
}
else
// Window resolution
if (rx_dsize.indexIn(line) > -1) {
int w = rx_dsize.cap(1).toInt();
int h = rx_dsize.cap(2).toInt();
emit receivedWindowResolution( w, h );
}
else
// VO
if (rx_vo.indexIn(line) > -1) {
emit receivedVO( rx_vo.cap(1) );
// Ask for window resolution
writeToStdin("print_text INFO_VIDEO_DSIZE=${=dwidth}x${=dheight}");
}
else
// AO
if (rx_ao.indexIn(line) > -1) {
emit receivedAO( rx_ao.cap(1) );
}
else
// Audio
if (rx_audio.indexIn(line) > -1) {
int ID = rx_audio.cap(1).toInt();
QString lang = rx_audio.cap(3);
QString title = rx_audio.cap(6);
qDebug() << "MPVProcess::parseLine: audio id:" << ID << "lang:" << lang << "name:" << title;
#if NOTIFY_AUDIO_CHANGES
updateAudioTrack(ID, title, lang, false);
#else
if (md.taudios.find(ID) == -1) {
md.taudios.addID(ID);
md.taudios.addName(ID, title);
md.taudios.addLang(ID, lang);
}
#endif
}
else
if (rx_stream_title.indexIn(line) > -1) {
QString s = rx_stream_title.cap(1);
qDebug() << "MPVProcess::parseLine: stream_title:" << s;
md.stream_title = s;
emit receivedStreamTitle(s);
}
else
// Subtitles
if (rx_subs.indexIn(line) > -1) {
int ID = rx_subs.cap(1).toInt();
QString lang = rx_subs.cap(3);
QString title = rx_subs.cap(6);
qDebug() << "MPVProcess::parseLine: sub id:" << ID << "lang:" << lang << "name:" << title;
#if NOTIFY_SUB_CHANGES
updateSubtitleTrack(ID, title, lang, false);
#else
if (md.tsubs.find(SubData::Sub, ID) == -1) {
md.tsubs.add(SubData::Sub, ID);
md.tsubs.changeName(SubData::Sub, ID, title);
md.tsubs.changeLang(SubData::Sub, ID, lang);
}
#endif
}
else
#if 0
if (rx_subs2.indexIn(line) > -1) {
bool selected = (rx_subs2.cap(1) == " >");
int ID = rx_subs2.cap(2).toInt();
QString title = rx_subs2.cap(3);
qDebug("MPVProcess::parseLine: sub id: %d title: '%s' selected: %d", ID, title.toUtf8().constData(), selected);
if (md.subs.find(SubData::Sub, ID) == -1) {
md.subs.add(SubData::Sub, ID);
md.subs.changeName(SubData::Sub, ID, title);
}
}
else
#endif
#if !NOTIFY_VIDEO_CHANGES
// Video
if (rx_video.indexIn(line) > -1) {
int ID = rx_video.cap(1).toInt();
QString title = rx_video.cap(4);
qDebug("MPVProcess::parseLine: video id: %d, name: '%s'", ID, title.toUtf8().constData());
//md.videos.addID(ID);
md.tvideos.addName(ID, title);
}
else
#endif
#if 0
// Video info
if (rx_videoinfo.indexIn(line) > -1) {
md.video_width = rx_videoinfo.cap(1).toInt();
md.video_height = rx_videoinfo.cap(2).toInt();
md.video_fps = rx_videoinfo.cap(3);
qDebug("MPVProcess::parseLine: width: %d height: %d fps: %s", md.video_width, md.video_height, md.video_fps.toUtf8().constData());
}
else
#endif
// Chapters
if (rx_chaptername.indexIn(line) > -1) {
int ID = rx_chaptername.cap(1).toInt();
QString title = rx_chaptername.cap(2);
if (title.isEmpty()) title = QString::number(ID + 1);
#if NOTIFY_CHAPTER_CHANGES
chapters.addName(ID, title);
chapter_info_changed = true;
#else
md.chapters.addName(ID, title);
#endif
qDebug() << "MPVProcess::parseLine: chapter id:" << ID << "title:" << title;
//md.chapters.list();
}
else
#if NOTIFY_VIDEO_CHANGES || NOTIFY_AUDIO_CHANGES || NOTIFY_SUB_CHANGES
// Track info
if (rx_trackinfo.indexIn(line) > -1) {
int ID = rx_trackinfo.cap(3).toInt();
QString type = rx_trackinfo.cap(2);
QString name = rx_trackinfo.cap(5);
QString lang = rx_trackinfo.cap(4);
QString selected = rx_trackinfo.cap(6);
qDebug() << "MPVProcess::parseLine: ID:" << ID << "type:" << type << "name:" << name << "lang:" << lang << "selected:" << selected;
/*
if (lang == "(unavailable)") lang = "";
if (name == "(unavailable)") name = "";
*/
if (type == "video") {
#if NOTIFY_VIDEO_CHANGES
updateVideoTrack(ID, name, lang, (selected == "yes"));
#endif
}
else
if (type == "audio") {
#if NOTIFY_AUDIO_CHANGES
updateAudioTrack(ID, name, lang, (selected == "yes"));
#endif
}
else
if (type == "sub") {
#if NOTIFY_SUB_CHANGES
updateSubtitleTrack(ID, name, lang, (selected == "yes"));
#endif
}
}
else
#endif
#if DVDNAV_SUPPORT
if (rx_switch_title.indexIn(line) > -1) {
int title = rx_switch_title.cap(1).toInt();
qDebug("MPVProcess::parseLine: title changed to %d", title);
// Ask for track info
// Wait 10 secs. because it can take a while until the title start to play
QTimer::singleShot(10000, this, SLOT(requestChapterInfo()));
}
else
#endif
//Playing
if (rx_playing.indexIn(line) > -1) {
emit receivedPlaying();
}
else
if (rx_videocodec.indexIn(line) > -1) {
md.video_codec = rx_videocodec.cap(1);
qDebug() << "MPVProcess::parseLine: md.video_codec:" << md.video_codec;
}
else
if (rx_audiocodec.indexIn(line) > -1) {
md.audio_codec = rx_audiocodec.cap(1);
qDebug() << "MPVProcess::parseLine: md.audio_codec:" << md.audio_codec;
}
else
if (rx_forbidden.indexIn(line) > -1) {
qDebug("MVPProcess::parseLine: 403 forbidden");
emit receivedForbiddenText();
}
//Generic things
if (rx_generic.indexIn(line) > -1) {
tag = rx_generic.cap(1);
value = rx_generic.cap(2);
//qDebug("MPVProcess::parseLine: tag: %s", tag.toUtf8().constData());
//qDebug("MPVProcess::parseLine: value: %s", value.toUtf8().constData());
if (tag == "INFO_VIDEO_WIDTH") {
md.video_width = value.toInt();
qDebug("MPVProcess::parseLine: md.video_width set to %d", md.video_width);
}
else
if (tag == "INFO_VIDEO_HEIGHT") {
md.video_height = value.toInt();
qDebug("MPVProcess::parseLine: md.video_height set to %d", md.video_height);
}
else
if (tag == "INFO_VIDEO_ASPECT") {
md.video_aspect = value.toDouble();
if ( md.video_aspect == 0.0 ) {
// I hope width & height are already set.
md.video_aspect = (double) md.video_width / md.video_height;
}
qDebug() << "MPVProcess::parseLine: md.video_aspect set to" << md.video_aspect;
}
if (tag == "INFO_VIDEO_BITRATE") {
int bitrate = value.toInt();
emit receivedVideoBitrate(bitrate);
}
else
if (tag == "INFO_LENGTH") {
md.duration = value.toDouble();
qDebug() << "MPVProcess::parseLine: md.duration set to" << md.duration;
}
else
if (tag == "INFO_DEMUXER") {
md.demuxer = value;
}
else
if (tag == "INFO_VIDEO_FORMAT") {
md.video_format = value;
}
if (tag == "INFO_VIDEO_FPS") {
md.video_fps = value;
}
else
/*
if (tag == "INFO_VIDEO_CODEC") {
md.video_codec = value;
}
else
if (tag == "INFO_AUDIO_CODEC") {
md.audio_codec = value;
}
else
*/
if (tag == "INFO_AUDIO_BITRATE") {
int bitrate = value.toInt();
emit receivedAudioBitrate(bitrate);
}
else
if (tag == "INFO_AUDIO_RATE") {
md.audio_rate = value.toInt();
}
else
if (tag == "INFO_AUDIO_NCH") {
md.audio_nch = value.toInt();
}
else
if (tag == "INFO_AUDIO_FORMAT") {
md.audio_format = value;
}
else
if (tag == "INFO_CHAPTERS") {
md.n_chapters = value.toInt();
#ifdef TOO_CHAPTERS_WORKAROUND
if (md.n_chapters > 1000) {
qDebug("MPVProcess::parseLine: warning too many chapters: %d", md.n_chapters);
qDebug(" chapters will be ignored");
md.n_chapters = 0;
}
#endif
for (int n = 0; n < md.n_chapters; n++) {
writeToStdin(QString("print_text INFO_CHAPTER_%1_NAME=${chapter-list/%1/title}").arg(n));
}
}
else
if (tag == "INFO_TITLES") {
int n_titles = value.toInt();
for (int ID = 0; ID < n_titles; ID++) {
md.titles.addName(ID, QString::number(ID+1));
}
}
else
if (tag == "METADATA_TITLE") {
if (!value.isEmpty()) md.clip_name = value;
}
else
if (tag == "METADATA_ARTIST") {
if (!value.isEmpty()) md.clip_artist = value;
}
else
if (tag == "METADATA_DATE") {
if (!value.isEmpty()) md.clip_date = value;
}
else
if (tag == "METADATA_ALBUM") {
if (!value.isEmpty()) md.clip_album = value;
}
else
if (tag == "METADATA_COPYRIGHT") {
if (!value.isEmpty()) md.clip_copyright = value;
}
else
if (tag == "METADATA_TRACK") {
if (!value.isEmpty()) md.clip_track = value;
}
else
if (tag == "METADATA_GENRE") {
if (!value.isEmpty()) md.clip_genre = value;
}
else
if (tag == "INFO_MEDIA_TITLE") {
if (!value.isEmpty() && value != "mp4" && !value.startsWith("mp4&") /*&& md.clip_name.isEmpty()*/) {
md.clip_name = value;
}
}
else
if (tag == "INFO_STREAM_PATH") {
QRegExp rx("edl://%\\d+%(.*)");
if (rx.indexIn(line) > -1) {
md.stream_path = rx.cap(1);
} else {
md.stream_path = value;
}
}
else
if (tag == "MPV_VERSION") {
mpv_version = value;
if (mpv_version.startsWith("mpv ")) mpv_version = mpv_version.mid(4);
qDebug() << "MPVProcess::parseLine: mpv version:" << mpv_version;
MplayerVersion::mplayerVersion("mpv " + mpv_version + " (C)");
}
#if NOTIFY_VIDEO_CHANGES || NOTIFY_AUDIO_CHANGES || NOTIFY_SUB_CHANGES
else
if (tag == "INFO_TRACKS_COUNT") {
int tracks = value.toInt();
for (int n = 0; n < tracks; n++) {
writeToStdin(QString("print_text \"INFO_TRACK_%1: "
"${track-list/%1/type} "
"${track-list/%1/id} "
"'${track-list/%1/lang:}' "
"'${track-list/%1/title:}' "
"${track-list/%1/selected}\"").arg(n));
}
}
#endif
}
}
}
void MPVProcess::requestChapterInfo() {
writeToStdin("print_text \"INFO_CHAPTERS=${=chapters}\"");
}
/*
void MPVProcess::requestBitrateInfo() {
writeToStdin("print_text INFO_VIDEO_BITRATE=${=video-bitrate}");
writeToStdin("print_text INFO_AUDIO_BITRATE=${=audio-bitrate}");
}
*/
#if NOTIFY_VIDEO_CHANGES
void MPVProcess::updateVideoTrack(int ID, const QString & name, const QString & lang, bool selected) {
qDebug("MPVProcess::updateVideoTrack: ID: %d", ID);
int idx = videos.find(ID);
if (idx == -1) {
video_info_changed = true;
videos.addName(ID, name);
videos.addLang(ID, lang);
} else {
// Track already existed
if (videos.itemAt(idx).name() != name) {
video_info_changed = true;
videos.addName(ID, name);
}
if (videos.itemAt(idx).lang() != lang) {
video_info_changed = true;
videos.addLang(ID, lang);
}
}
if (selected && selected_video != ID) {
selected_video = ID;
video_info_changed = true;
}
}
#endif
#if NOTIFY_AUDIO_CHANGES
void MPVProcess::updateAudioTrack(int ID, const QString & name, const QString & lang, bool selected) {
qDebug("MPVProcess::updateAudioTrack: ID: %d", ID);
int idx = audios.find(ID);
if (idx == -1) {
audio_info_changed = true;
audios.addName(ID, name);
audios.addLang(ID, lang);
} else {
// Track already existed
if (audios.itemAt(idx).name() != name) {
audio_info_changed = true;
audios.addName(ID, name);
}
if (audios.itemAt(idx).lang() != lang) {
audio_info_changed = true;
audios.addLang(ID, lang);
}
}
if (selected && selected_audio != ID) {
selected_audio = ID;
audio_info_changed = true;
}
}
#endif
#if NOTIFY_SUB_CHANGES
void MPVProcess::updateSubtitleTrack(int ID, const QString & name, const QString & lang, bool selected) {
qDebug("MPVProcess::updateSubtitleTrack: ID: %d", ID);
int idx = subs.find(SubData::Sub, ID);
if (idx == -1) {
subtitle_info_changed = true;
subs.add(SubData::Sub, ID);
subs.changeName(SubData::Sub, ID, name);
subs.changeLang(SubData::Sub, ID, lang);
}
else {
// Track already existed
if (subs.itemAt(idx).name() != name) {
subtitle_info_changed = true;
subs.changeName(SubData::Sub, ID, name);
}
if (subs.itemAt(idx).lang() != lang) {
subtitle_info_changed = true;
subs.changeLang(SubData::Sub, ID, lang);
}
}
if (selected && selected_subtitle != ID) {
selected_subtitle = ID;
subtitle_info_changed = true;
}
}
#endif
// Called when the process is finished
void MPVProcess::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
qDebug("MPVProcess::processFinished: exitCode: %d, status: %d", exitCode, (int) exitStatus);
// Send this signal before the endoffile one, otherwise
// the playlist will start to play next file before all
// objects are notified that the process has exited.
emit processExited();
if (received_end_of_file) emit receivedEndOfFile();
}
void MPVProcess::gotError(QProcess::ProcessError error) {
qDebug("MPVProcess::gotError: %d", (int) error);
}
#include "mpvoptions.cpp"
#include "moc_mpvprocess.cpp"
|