playback on mac and memory

This forum is about all development around libVLC.
geostein8888
Cone that earned his stripes
Cone that earned his stripes
Posts: 142
Joined: 15 Dec 2010 11:32

playback on mac and memory

Postby geostein8888 » 10 Nov 2015 15:35

Hello,
I have an application where I wanted to embed a small videoplayer based on libvlc.
right now its only starting always the same video file, and on Mac each time I start the video and stop it, I loose around 1.6MB ram whats not freed after stop.

here the basic code of the player, perhaps I made something wrong here: (im using Qt4.8 and VLC 2.2.1 on Macos)

Code: Select all

QVector<QByteArray> vArgs; vArgs.append("--ignore-config"); vArgs.append("--intf=dummy"); vArgs.append("--no-media-library"); vArgs.append("--no-osd"); //vArgs.append("--no-stats"); vArgs.append("--no-video-title-show"); vArgs.append("--cr-average=10000"); vArgs.append("--clock-jitter=6000"); vArgs.append("--sout-mux-caching=8000"); vArgs.append("--no-plugins-cache");// for accurate seek via internet if (this->logging) { vArgs.append("--verbose=2"); } else { vArgs.append("--verbose=0"); } #if defined(Q_OS_MAC) // QString pluginPath = "--plugin-path="+QCoreApplication::applicationDirPath()+"/plugins"; // vArgs.append(pluginPath.toAscii()); vArgs.append("--vout=macosx"); #endif const char* vlcArgs[12]; for (int i = 0; i < 12; i++) { if (i < vArgs.count()) { vlcArgs[i] = vArgs[i].constData(); } else { vlcArgs[i] = NULL; } } int argc = 0; argc = (vArgs.count() > 12) ? 12 : vArgs.count(); //create a new libvlc instance if((this->vlcInstance = libvlc_new(argc, vlcArgs)) == NULL) { qDebug(Could not init libVLC"); exit(1); } // Create a media player playing environement if (this->vlcInstance){ this->vlcPlayer = libvlc_media_player_new (this->vlcInstance); } else { exit(1); }
playback:

Code: Select all

void player::playFile(QString fileName) { this->vlcMedia = libvlc_media_new_path(this->vlcInstance, fileName.toUtf8().constData()); if (this->vlcMedia != NULL){ if (this->vlcPlayer == NULL) { this->vlcPlayer = libvlc_media_player_new_from_media(this->vlcMedia); this->initializePlayer();//needed if not the signals are disconnected /* Integrate the video in the interface */ this->setVideoWidget(this->winID); } else { // qDebug("#### player is initialized"); libvlc_media_player_set_media(this->vlcPlayer, this->vlcMedia); // this->blockEvents = false; } } else { qDebug() << "media NOT INITIALIZED"; return; } if (this->reconnectVideo){ this->setVideoWidget(this->winID); } libvlc_media_release(this->vlcMedia); int started = libvlc_media_player_play(this->vlcPlayer); }
stop:

Code: Select all

void player::slotStopTest() { if (libvlc_media_player_is_playing(this->vlcPlayer) == 1){ libvlc_media_player_stop(this->vlcPlayer); //tested with and without releasing on stop, same memory problem libvlc_media_player_release(this->vlcPlayer); this->vlcPlayer = NULL; if (this->reconnectVideo){ //tested if its getting better when I detach erverytime the video screen - no difference this->unsetVideoWidget(); } } // libvlc_media_player_retain }

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: playback on mac and memory

Postby Rémi Denis-Courmont » 10 Nov 2015 15:51

Missing libvlc_release() ?
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

geostein8888
Cone that earned his stripes
Cone that earned his stripes
Posts: 142
Joined: 15 Dec 2010 11:32

Re: playback on mac and memory

Postby geostein8888 » 10 Nov 2015 17:10

Hell,
I have to do this also after each stop, even when I start after this another file? In the examples I found even libvlc_media_player_release(this->vlcPlayer); was not called when the stop button gets pushd

Georg

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: playback on mac and memory

Postby Rémi Denis-Courmont » 10 Nov 2015 17:18

You have to do this after each libvlc_new().
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

geostein8888
Cone that earned his stripes
Cone that earned his stripes
Posts: 142
Joined: 15 Dec 2010 11:32

Re: playback on mac and memory

Postby geostein8888 » 10 Nov 2015 18:13

as you can see in the source for the stop method, I only call libvlc_media_player_stop(this->vlcPlayer); and then perhaps also libvlc_media_player_release(this->vlcPlayer);
I'm not initiating the vlc instance each time I start a new file, I guess this would take longer

Georg

geostein8888
Cone that earned his stripes
Cone that earned his stripes
Posts: 142
Joined: 15 Dec 2010 11:32

Re: playback on mac and memory

Postby geostein8888 » 11 Nov 2015 15:26

Hello Rémi,
to be here on the save site, I made now a small qt app where I have my player running in, so I'm sure nothing from the rest of the app is producing this problem.
I also added a button what is calling libvlc_release(instance).

Ii get still the same result, with each start of the video the memory of the app is increasing (start was at 8MB, after first start it wenup to 50MB ) by around 1MB, when I push the button to delete the instance the memory is not really going down (perhaps 500k)

Code: Select all

/****************************** * Qt player using libVLC * * By protonux * * * * Under WTFPL * ******************************/ #include "player.h" #include <vlc/vlc.h> #include <qdebug.h> #define qtu( i ) ((i).toUtf8().constData()) #include <QtGui> Mwindow::Mwindow() { vlcPlayer = NULL; this->screenSet = false; this->initVLC(); /* Display libVLC version */ printf("libVLC version: %s\n",libvlc_get_version()); /* Interface initialisation */ initMenus(); initComponents(); } Mwindow::~Mwindow() { if(vlcObject) libvlc_release(vlcObject); } void Mwindow::initVLC() { qDebug() << "Mwindow::initVLC"; const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ // "--extraintf=logger", //log anything "--verbose=0", //be much more verbose then normal for debugging purpose // "--plugin-path=C:\\vlc-0.9.9-win32\\plugins\\" }; /* Init libVLC */ if((vlcObject = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args)) == NULL) { printf("Could not init libVLC"); exit(1); } } void Mwindow::initMenus() { centralWidget = new QWidget; videoWidget = new QWidget; videoWidget->setAutoFillBackground( true ); QPalette plt = palette(); plt.setColor( QPalette::Window, Qt::black ); videoWidget->setPalette( plt ); QMenu *fileMenu = menuBar()->addMenu("&File"); QMenu *editMenu = menuBar()->addMenu("&Edit"); QAction *Open = new QAction("&Open", this); QAction *Quit = new QAction("&Quit", this); QAction *playAc = new QAction("&Play/Pause", this); Open->setShortcut(QKeySequence("Ctrl+O")); Quit->setShortcut(QKeySequence("Ctrl+Q")); fileMenu->addAction(Open); fileMenu->addAction(Quit); editMenu->addAction(playAc); connect(Open, SIGNAL(triggered()), this, SLOT(openFile())); connect(playAc, SIGNAL(triggered()), this, SLOT(play())); connect(Quit, SIGNAL(triggered()), qApp, SLOT(quit())); } void Mwindow::initComponents() { playBut = new QPushButton("Play"); QObject::connect(playBut, SIGNAL(clicked()), this, SLOT(play())); stopBut = new QPushButton("Stop"); QObject::connect(stopBut, SIGNAL(clicked()), this, SLOT(stop())); muteBut = new QPushButton("DELETE VLC"); QObject::connect(muteBut, SIGNAL(clicked()), this, SLOT(deleteVLC())); this->buFullScreen = new QPushButton("FULLSCREEN"); QObject::connect(this->buFullScreen, SIGNAL(clicked()), this, SLOT(fullScreen())); this->buNormalScreen = new QPushButton("NORMAL"); QObject::connect(this->buNormalScreen, SIGNAL(clicked()), this, SLOT(normalScreen())); volumeSlider = new QSlider(Qt::Horizontal); QObject::connect(volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(changeVolume(int))); volumeSlider->setValue(80); slider = new QSlider(Qt::Horizontal); slider->setMaximum(1000); QObject::connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int))); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateInterface())); timer->start(100); QHBoxLayout *layout = new QHBoxLayout; this->layout3 = new QVBoxLayout; layout->addWidget(playBut); layout->addWidget(stopBut); layout->addWidget(muteBut); layout->addWidget(buFullScreen); layout->addWidget(buNormalScreen); layout->addWidget(volumeSlider); layout2 = new QVBoxLayout; this->videobox = new QWidget(); this->videoWidget->setParent(this->videobox); layout3->addWidget(this->videobox); QSize fullsize = this->videobox->size(); this->videoWidget->resize(fullsize); layout2->addLayout(layout3); layout2->addWidget(slider); layout2->addLayout(layout); centralWidget->setLayout(layout2); setCentralWidget(centralWidget); resize( 600, 400); } void Mwindow::fullScreen(){ this->layout3->removeWidget(this->videobox); this->videobox->setParent(0); // this->videobox->activateWindow(); this->videobox->showFullScreen(); QSize fullsize = this->videobox->size(); this->videoWidget->resize(fullsize); } void Mwindow::normalScreen(){ this->videobox->showNormal(); this->videobox->setParent(this); this->layout3->addWidget(this->videobox); QSize fullsize = this->videobox->size(); this->videoWidget->resize(fullsize); } void Mwindow::setVideoScreen() { if (this->screenSet) { return; } this->screenSet = true; /* Integrate the video in the interface */ #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(this->vlcPlayer, (void*)videoWidget->winId()); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(vlcPlayer, videoWidget->winId()); #endif } void Mwindow::unsetVideoScreen() { if (!this->screenSet) { return; } this->screenSet = false; /* Integrate the video in the interface */ #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(this->vlcPlayer, (void *) NULL); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(vlcPlayer, NULL); #endif } void Mwindow::openFile() { if( vlcPlayer && libvlc_media_player_is_playing(vlcPlayer) ) { stop(); } } void Mwindow::play() { if (!this->vlcObject) { } if(vlcPlayer) { if (libvlc_media_player_is_playing(vlcPlayer)) { libvlc_media_player_pause(vlcPlayer); playBut->setText("Play"); } else { libvlc_media_player_play(vlcPlayer); playBut->setText("Pause"); } } #if defined(Q_OS_MAC) libvlc_media_t *vlcMedia = libvlc_media_new_path(vlcObject,"/Users/geostein/msm/data/20151110_103725_tv.ts"); #else libvlc_media_t *vlcMedia = libvlc_media_new_path(vlcObject,"C:\\tmp\\msm\\0.streams\\20151108_74940_Finding_Aurora.ts"); #endif qDebug() << "try playing: 3 MEdia: " << vlcMedia << " instance: " << vlcObject; if( !vlcMedia ) return; if (this->vlcPlayer != NULL) { libvlc_media_player_set_media(this->vlcPlayer, vlcMedia); } else { vlcPlayer = libvlc_media_player_new_from_media (vlcMedia); } qDebug() << "try playing: 4"; libvlc_media_release(vlcMedia); this->setVideoScreen(); libvlc_media_player_play(this->vlcPlayer); //Set vars and text correctly playBut->setText("Pause"); } int Mwindow::changeVolume(int vol) { //Called if you change the volume slider if(vlcPlayer) return libvlc_audio_set_volume (vlcPlayer,vol); return 0; } void Mwindow::changePosition(int pos) { //Called if you change the position slider if(vlcPlayer) //It segfault if vlcPlayer don't exist libvlc_media_player_set_position(vlcPlayer,(float)pos/(float)1000); } void Mwindow::updateInterface() { //Update interface and check if song is finished if(vlcPlayer) { /* update the timeline */ float pos = libvlc_media_player_get_position(vlcPlayer); int siderPos=(int)(pos*(float)(1000)); slider->setValue(siderPos); /* Stop the media */ if (libvlc_media_player_get_state(vlcPlayer) == 6) { this->stop(); } } } void Mwindow::stop() { if(vlcPlayer) { this->unsetVideoScreen(); libvlc_media_player_stop(vlcPlayer); libvlc_media_player_release(vlcPlayer); slider->setValue(0); playBut->setText("Play"); } else { qDebug() << "Mwindow::stop(): ERROR player is gone"; } vlcPlayer = NULL; } void Mwindow::deleteVLC() { qDebug() << "Mwindow::deleteVLC"; if(vlcPlayer) { qDebug() << "Mwindow::deleteVLC 1"; libvlc_media_player_release(this->vlcPlayer); qDebug() << "Mwindow::deleteVLC 2"; this->vlcPlayer = NULL; } if (this->vlcObject) { qDebug() << "Mwindow::deleteVLC 3"; libvlc_release(this->vlcObject); qDebug() << "Mwindow::deleteVLC 4"; this->vlcObject = NULL; } } void Mwindow::closeEvent(QCloseEvent *event) { stop(); event->accept(); }

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: playback on mac and memory

Postby Rémi Denis-Courmont » 11 Nov 2015 15:37

Use a leak checker then
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

geostein8888
Cone that earned his stripes
Cone that earned his stripes
Posts: 142
Joined: 15 Dec 2010 11:32

Re: playback on mac and memory

Postby geostein8888 » 11 Nov 2015 16:11

ok,
but before this I tested the vlc player (for mac) and get here the same result each time when I push play and then stop, its adding here also 1MB around. This looks for me like a leak, but its the obviously not in my code, while its acting the same on the 2.2.1 player I installed from the DMG file form the clv website.

is this a known issue?

Georg

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: playback on mac and memory

Postby Jean-Baptiste Kempf » 25 Nov 2015 17:35

I don't think so.
It could be many things leaking, including the video output or the audio output.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 6 guests