Problems embedding VLC in Qt-Widget on MacOS

This forum is about all development around libVLC.
derda
New Cone
New Cone
Posts: 1
Joined: 22 Jun 2009 10:26

Problems embedding VLC in Qt-Widget on MacOS

Postby derda » 22 Jun 2009 11:27

Dear fellow VLC users,

at the moment I am looking for a way to integrate VLC (1.0.0-rc4) into a custom application, which has to be portable accross MacOS and Windows. I used the sample code of Alexander Maringer in the Wiki (LibVLC SampleCode Qt) as a guideline and experienced no problems embedding VLC via libvlc into my own Qt-application (Qt-4.5.1) on Windows.

Trying to do the same on MacOS (Intel, 10.5.7) brought no success yet: the app crashed every time when video was about to be shown. Before the crash a black window is drawn on the screen, probably the window where the output should be rendered. This window is also not located in the boundaries of the Qt-Widget specified for video rendering. This crash also happens when no video output is set at all, so the crash doesn't depend on which function I'm using for embedding the video. After deleting the macosx-plugin and thus forcing VLC to use the minimal_macosx plugin, it plays the video but the output doesn't get embedded into the Qt-Widget, instead it is shown in its own window in original size.

Before putting more effort into this, my questions are if the minimal_macosx module is able to embed the video, if anyone of you has successfully embedded one of the recent VLC versions into a Qt application on MacOS and which functions you were using in case of success. I would like to use the new API with libvlc_media_player_set_agl, but a look into the source of the browser-plugin for Mac shows me, that even there libvlc_video_set_parent is still being used.

When I know of a confirmed working way to embed VLC in Qt on MacOS, I will try again to solve the issue on my own and would only post all the technical details of the specific problem when I'm still experiencing problems.

Thanks in advance for your answers!

Benjamin

Update: Meanwhile I answered some questions myself: minimal_macosx is indeed able to embed the video, my first guess is that in the normal macosx-plugin the EyeTV-part is causing problems. I also managed to get "some" video output embedded in a Qt window, but I still have to get behind the right values for the viewing and clipping rectangles and they need to be updated upon resizing. Maybe I am missing some basic concepts, but embedding VLC on Mac without the use of Objective-C seems to be very cumbersome to me at the moment. Any further comments are still appreciated!

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 06 Jul 2009 16:14

I've got exactly the same problem that Benjamin describes.
( Except that when I removed macosx-plugin, I get another crash now in minimal_macosx, should probably try the 1.0.0 release candidate )

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 10 Jul 2009 16:49

Some thoughts

* Qt 4.5 now has got QMacCocoaViewContainer class, which can wrap any Cocoa NSView in a QWidget. Might that be useful?

* I have a guess that libvlc_media_player_set_nsobject( .. void* .. ) expects a pointer not just to any NSView to render to, but to an instance of VLCOpenGLVoutView (/modules/minimal_macosx/VLCOpenGLVoutView.h)

* Objective-C, after a closer examination, appears to be a paper tiger, at least from the aspect of it's most basic usage. Making a wrapper class for VLCKit in Objective-C++ shouldn't be a big burden.

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 10 Jul 2009 18:29

Managed to embed video inside a Qt window. Here are the main changes to original sample code:

main.cpp

Code: Select all

- | QFrame *_videoWidget; + | QMacCocoaViewContainer *_videoWidget;
vlc_on_qt.mm (vlc_on_qt.cpp renamed)

Code: Select all

+ | #undef slots + | // yes, otherwise there's a confilct in some framework's header file + | // please, suggest a cleaner way to do that. + | #import <VLCKit/VLCKit.h> ___________________________________________________________________________ - | libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); // for vlc 1.0 + | VLCVideoView *videoView = [[VLCVideoView alloc] init]; + | _videoWidget->setCocoaView(videoView); + | [videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable]; + | libvlc_media_player_set_nsobject(_mp, videoView, &_vlcexcep);
So this way it's working with just a few lines of ObjC. All the control is still done through libvlc.

But there's a problem: when playing some hard- or not-enough-bandwidth- to play video, I get that "busy" rainbow circle and the gui gets non-responsive. That's weird, since video is obviously played in separate thread(s).. and there's no visible CPU load.

Qt 4.5.2 - cocoa build, VLCKit got from 1.0.1-pre nightly builds (too lazy/lame to build myself), LibVLC - 1.0.0

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: Problems embedding VLC in Qt-Widget on MacOS

Postby Jean-Baptiste Kempf » 10 Jul 2009 19:06

Can add that to the wiki ? (or ifdef it?)
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.

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 10 Jul 2009 20:38

Can add that to the wiki ? (or ifdef it?)
Well, I'd like too, BUT

1. It's not usable yet
- After some testing it appeared that GUI gets irresponsive at all times (right after the video starts playing)
Looks like Qt's misbehaving.

2. It seems like a hack,
- and thus may have undesired implications ( 1. possibly being one of them )

Since my knowledge of the VLC project is superficial at best,
guess the only way to go is to find somebody involved and competent, who'd have a look at this whole thing and fix what's wrong here.

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 20 Jul 2009 11:25

Problem with hanging is fixed by making 'lib' and 'modules' symbolic links to respective directories in <Application bundle>/Contents/Frameworks/Versions/Current/
instead of duplicating libraries in the bundle (as it was done before in my test app)

Now got segmentation fault on exiting the application :
When VLCVideoView is destroyed it for some reason tries to resize itself, using the libvlc instance provided by VLCLibrary class (sort of a singleton responsible for proper initialization and destruction of the underlying libvlc_object_t ). Looks like it has problems with initializing the library.

user411
Blank Cone
Blank Cone
Posts: 10
Joined: 26 Mar 2008 22:47

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby user411 » 08 Oct 2009 09:35

Hi there,

Have you had any more success with this? I am working on a Qt project that could use VLC's capabilities for cross-platform video streaming and presentation.

From the look of your code modifications there is going to be a bit more platform specific structural code inside of #ifdef blocks that I was hoping for

Just getting the newest XCode installed now to build VLC libs from scratch. I will report back any success.

WippelDa
Blank Cone
Blank Cone
Posts: 11
Joined: 21 Dec 2009 10:53

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby WippelDa » 21 Dec 2009 11:04

Any update to this? I also ran into the same problem and wasnt able to find a solution...

maleev
New Cone
New Cone
Posts: 6
Joined: 06 Jul 2009 14:46

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby maleev » 21 Dec 2009 14:54

Hi, I haven't been working for that project for a while. But, though I don't really remember what exactly fixed some of the problems, I will post some code from the libvlc wrapper that seemed to work well.

Constructor

Code: Select all

VLCPlayer::VLCPlayer() : QWidget() { const char * const vlc_args[] = { "-I", "dummy" // Don't use any interface ,"--ignore-config" // Don't use VLC's config ,"--verbose=-1" ,"--quiet" #ifdef Q_WS_MAC , "--vout=minimal_macosx" , "--opengl-provider=minimal_macosx" #endif }; int argc = sizeof(vlc_args) / sizeof(vlc_args[0]); _vlcinstance = libvlc_new( argc, vlc_args, &VLCException(this) ); _media_player = libvlc_media_player_new( _vlcinstance, &VLCException(this) ); _media_descr = NULL; #ifdef Q_WS_MAC && VLC_VERSION_1_0 _videoWidget = NULL; _wrapperLayout = new QVBoxLayout; _wrapperLayout->setContentsMargins(0,0,0,0); setLayout(_wrapperLayout); #endif // Create a timer to poll player state. That way it works. Using vlc's event manager caused some problems with threads. // That's it. Window will be attached once we actually start playing. }
Destructor

Code: Select all

VLCPlayer::~VLCPlayer() { _poller->stop(); Stop(); libvlc_media_player_release (_media_player); libvlc_release (_vlcinstance); }
Load()

Code: Select all

void VLCPlayer::Load( IN QString & url) { Stop(); if (_media_descr) libvlc_media_release( _media_descr ); _media_descr = libvlc_media_new (_vlcinstance, url.toAscii(), &VLCException(this) ); // Creating parameter string 'options' libvlc_media_add_option ( _media_descr, options, &VLCException(this) ); libvlc_media_player_set_media ( _media_player, _media_descr, &VLCException(this) ); attachPlayerToWnd(); }
attachPlayerToWnd()

Code: Select all

// Tell LibVLC to render video into our widget void VLCPlayer::attachPlayerToWnd() { #if defined(Q_WS_WIN) #if defined( VLC_VERSION_0_9 ) libvlc_media_player_set_drawable(_media_player, reinterpret_cast<unsigned int>(winId()), &VLCException(this) ); #elif defined ( VLC_VERSION 1_0 ) libvlc_media_player_set_hwnd(_media_player, winId(), &VLCException(this) ); #endif #elif defined(Q_WS_MAC) #if defined( VLC_VERSION_0_9 ) libvlc_media_player_set_drawable(_media_player, winId(), &VLCException(this) ); #elif defined( VLC_VERSION_1_0 ) _videoWidget = new QMacCocoaViewContainer(0); _wrapperLayout->addWidget(_videoWidget); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; VLCVideoView *videoView = [[VLCVideoView alloc] init]; _videoWidget->setCocoaView(videoView); libvlc_media_player_set_nsobject(_media_player, videoView, &VLCException(this) ); [videoView release]; [pool release]; //@ _videoWidget->hide(); #endif #elif defined( Q_WS_X11 ) #if defined( VLC_VERSION_0_9 ) libvlc_media_player_set_drawable(_media_player, winId(), &VLCException(this) ); #elif defined( VLC_VERSION_1_0 ) libvlc_media_player_set_xwindow(_media_player, winId(), &VLCException(this) ); #endif #endif }
And finally Play() and Stop()

Code: Select all

void VLCPlayer::Play() { libvlc_media_player_play( _media_player, &VLCException(this) ); #ifdef Q_WS_MAC if (_videoWidget) _videoWidget->show(); #endif _poller->start(); }

Code: Select all

#ifdef Q_WS_MAC && VLC_VERSION_1_0 if (_videoWidget) { delete _videoWidget; _videoWidget = NULL; } #endif if (libvlc_media_player_get_media (_media_player, &VLCException(this) ) != NULL && _media_descr != NULL) { libvlc_media_player_stop( _media_player, &VLCException(this) ); }
note: VLCException class is a convenience hack, and using vlc's exception structure won't change anything.

I haven't solved the problem with fullscreen. You will have to study sources of VLC Player for Mac to find out how.

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: Problems embedding VLC in Qt-Widget on MacOS

Postby Jean-Baptiste Kempf » 22 Dec 2009 09:34

Can you update the Wiki accordingly?
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.

vlan4us
New Cone
New Cone
Posts: 4
Joined: 23 Feb 2010 12:57

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby vlan4us » 06 May 2010 01:21

Hi I tried the above things on Mac.And it compiled successfully on Mac using Qt.

But when I try to play a file, vlc throws an error:
vlc: unknown option or missing mandatory argument `--opengl-provider=minimal_macosx' thus causing vlc initialization fail.
But I have clearly specified this argument in my constructor for vlc arguments below
player.mm:-
Player::Player()
: QWidget()
{
const char * const vlc_args[] = {
"-I", "dummy"
,"--ignore-config"
,"--verbose=-1"
,"--quiet"
, "--vout=minimal_macosx"
, "--opengl-provider=minimal_macosx"
}; //log anything
}

I am using VLC 1.0.5
.pro settings:
QMAKE_LFLAGS += -F/Library/Frameworks/
INCLUDE += -framework VLCKit

TARGET = playerApp
CONFIG += console
CONFIG -= app_bundle

# Input
HEADERS += test_player.h \
vlc/deprecated.h \
vlc/libvlc.h \
vlc/libvlc_events.h \
vlc/libvlc_media.h \
vlc/libvlc_media_discoverer.h \
vlc/libvlc_media_library.h \
vlc/libvlc_media_list.h \
vlc/libvlc_media_list_player.h \
vlc/libvlc_media_list_view.h \
vlc/libvlc_media_player.h \
vlc/libvlc_structures.h \
vlc/libvlc_vlm.h \
vlc/mediacontrol.h \
vlc/mediacontrol_structures.h \
vlc/vlc.h

SOURCES += main.cpp
OBJECTIVE_SOURCES += player.mm
RESOURCES += player.qrc
LIBS += libvlc.2.dylib -framework VLCKit -lobjc -framework Foundation

Note: If I rename my player.mm to player.cpp code and just replace "libvlc_media_player_set_drawable" call instead of "attach_palyer_wind()" call without any other change, I can observe the playback without the embedded video with the separate video window.

Any pointers for resolving this issue.

Thanks in advance for your answers!

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: Problems embedding VLC in Qt-Widget on MacOS

Postby Jean-Baptiste Kempf » 08 May 2010 19:22

I believe you need VLC 1.1.0 to solve this issue.
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.

vlan4us
New Cone
New Cone
Posts: 4
Joined: 23 Feb 2010 12:57

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby vlan4us » 13 May 2010 20:09

Thanks j-b,

I used vlc 1.1 libraries which I got it from installing "VLC Media Player 1.1.0-pre1" from below link
http://www.macupdate.com/info.php/id/57 ... dia-player.
But this issue still exist.

I tried compiling the vlc-1.1.0-pre3.tar.bz2 code but was not able to do so.

I managed to compile the code from latest git along with VLCKit. I am using the same for my application.
I built the code for x86_64.And my mac(10.6) supports that .But still i get the error
vlc: unknown option or missing mandatory argument `--opengl-provider=minimal_macosx' thus causing vlc initialization fail.

Any pointers for resolving this issue.
Thanks in advance for your answers.

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

Re: Problems embedding VLC in Qt-Widget on MacOS

Postby geostein8888 » 21 Mar 2011 17:54

Hello,
is there already a solution, or is this problem still present?
i got everything to work under QT Creator on my mac except that the video is not connected to the Applicatiosn widget (i use the libvlc libs not the VLCKit)

Georg


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 25 guests