bool VlcLib::init() { //Debug::warning() << "[PLAYER] -> VlcLib::init"; //! init args for vlc libs QList<QByteArray> args; /* NOTE 1: warning from vlc doc : There is absolutely no warranty or promise of forward, backward and cross-platform compatibility with regards to libvlc_new() arguments. We recommend that you do not use them, other than when debugging. */ /* NOTE 2: --no-plugins-cache CRASH on ubuntu 15.10 frash install */ args << "--no-media-library" << "--no-one-instance" << "--no-stats" << "--no-osd" << "--no-loop" << "--no-xlib" << "--no-video-title-show" << "--drop-late-frames" << "--no-video"; // Convert arguments to required format QVarLengthArray<const char *, 64> vlcArgs(args.size()); for (int i = 0; i < args.size(); ++i) { vlcArgs[i] = args.at(i).constData(); } // Create new libvlc instance m_vlcInstance = libvlc_new(vlcArgs.size(), vlcArgs.constData()); // Check if instance is running if(m_vlcInstance) { Debug::debug() << "[EngineVlc] vlc initialised"; Debug::debug() << "[EngineVlc] using libvlc version:" << QString(libvlc_get_version()); } else { Debug::error() << "vlc initialization error :" << libvlc_errmsg(); return false; } return true; }
bool LibVLC::init(QList<QByteArray> more_args) { Q_ASSERT_X(!self, "LibVLC", "there should be only one LibVLC object"); LibVLC::self = new LibVLC; QList<QByteArray> args; // Ends up as something like $HOME/.config/Phonon/vlc.conf const QString configFileName = QSettings("Phonon", "vlc").fileName(); if (QFile::exists(configFileName)) { args << QByteArray("--config=").append(QFile::encodeName(configFileName)); args << "--no-ignore-config"; } int debugLevel = qgetenv("PHONON_SUBSYSTEM_DEBUG").toInt(); debugLevel = 21473647; if (debugLevel > 0) { args << QByteArray("--verbose=").append(QByteArray::number(debugLevel)); args << QByteArray("--extraintf=logger"); #ifdef Q_WS_WIN QDir logFilePath(QString(qgetenv("APPDATA")).append("/vlc")); #else QDir logFilePath(QDir::homePath().append("/.vlc")); #endif //Q_WS_WIN logFilePath.mkdir("log"); const QString logFile = logFilePath.path() .append("/log/vlc-log-") .append(QString::number(qApp->applicationPid())) .append(".txt"); args << QByteArray("--logfile=").append(QFile::encodeName(QDir::toNativeSeparators(logFile))); } args << "--no-media-library"; args << "--no-osd"; args << "--no-stats"; #if (LIBVLC_VERSION_INT < LIBVLC_VERSION(2, 1, 0, 0)) // Replaced by API call, see MediaPlayer::MediaPlayer. args << "--no-video-title-show"; #endif // By default VLC will put a picture-in-picture when making a snapshot. // This is unexpected behaviour for us, so we force it off. args << "--no-snapshot-preview"; // Do not load xlib dependent modules as we cannot ensure proper init // order as expected by xlib thus leading to crashes. // KDE BUG: 240001 args << "--no-xlib"; // Do not preload services discovery modules, we don't use them. args << "--services-discovery=''"; // Allow multiple starts (one gets to wonder whether that makes a difference). #if !defined(Q_OS_MAC) && (defined(Q_OS_WIN) || !defined(PHONON_NO_DBUS)) args << "--no-one-instance"; #endif args << "--no-audio"; args << "--no-video"; args << more_args; // 6 seconds disk read buffer (up from vlc 2.1 default of 300ms) when using alsa, prevents most buffer underruns // when the disk is very busy. We expect the pulse buffer after decoding to solve the same problem. Phonon::PulseSupport *pulse = Phonon::PulseSupport::getInstance(); if (!pulse || !pulse->isActive()) { args << "--file-caching=6000"; } // Build const char* array QVarLengthArray<const char *, 64> vlcArgs(args.size()); for (int i = 0; i < args.size(); ++i) { vlcArgs[i] = args.at(i).constData(); } // Create and initialize a libvlc instance (it should be done only once) self->m_vlcInstance = libvlc_new(vlcArgs.size(), vlcArgs.constData()); if (!self->m_vlcInstance) { fatal() << "libVLC: could not initialize"; return false; } return true; }
VlcVideoWidget::VlcVideoWidget(const QList<QByteArray> &args) : QFrame(0), vlcInstance_(0), vlcPlayer_(0), vlcMedia_(0), hasVideoOut_(false) { /// Convert the arguments into a proper form QVarLengthArray<const char*, 64> vlcArgs(args.size()); for (int i = 0; i < args.size(); ++i) vlcArgs[i] = args.at(i).constData(); // Create new libvlc instance vlcInstance_ = libvlc_new(vlcArgs.size(), vlcArgs.constData()); // Check if instance is running if (!vlcInstance_) { std::string errorMsg; if (libvlc_errmsg()) errorMsg = std::string("VlcVideoWidget: Failed to create VLC instance: ") + libvlc_errmsg(); else errorMsg = "VlcVideoWidget: Failed to create VLC instance"; LogError(errorMsg); return; } libvlc_set_user_agent(vlcInstance_, "realXtend Tundra Media Player 1.0", "Tundra/1.0"); /// Create the vlc player and set event callbacks vlcPlayer_ = libvlc_media_player_new(vlcInstance_); libvlc_event_manager_t *em = libvlc_media_player_event_manager(vlcPlayer_); libvlc_event_attach(em, libvlc_MediaPlayerMediaChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerOpening, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerBuffering, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerPlaying, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerPaused, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerStopped, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerEncounteredError, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerTimeChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerSeekableChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerPausableChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerTitleChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaPlayerLengthChanged, &VlcEventHandler, this); /// register callbacks so that we can implement custom drawing of video frames libvlc_video_set_callbacks( vlcPlayer_, &CallBackLock, &CallBackUnlock, &CallBackDisplay, this); // Initialize rendering //idleLogo_ = QImage(":/images/vlc-cone.png"); idleLogo_ = QImage(":/images/play-video.png"); idleLogo_ = idleLogo_.convertToFormat(QImage::Format_ARGB32); //audioLogo_ = QImage(":/images/audio.png"); audioLogo_ = QImage(":/images/play-audio.png"); audioLogo_ = audioLogo_.convertToFormat(QImage::Format_ARGB32); pausePixmap_ = QPixmap(":/images/pause-big.png"); bufferingPixmap_ = QPixmap(":/images/buffering.png"); QSize startSize(600, 360); renderPixmap_ = QImage(startSize.width(), startSize.height(), QImage::Format_RGB32); libvlc_video_set_format(vlcPlayer_, "RV32", renderPixmap_.width(), renderPixmap_.height(), renderPixmap_.bytesPerLine()); // Initialize widget properties setMinimumSize(startSize); resize(startSize); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setStyleSheet("background-color: black;"); // Connect and start status poller connect(&pollTimer_, SIGNAL(timeout()), SLOT(StatusPoller())); pollTimer_.start(10); }