Releasing and creating media player causes freeze

This forum is about all development around libVLC.
Hanley
Blank Cone
Blank Cone
Posts: 22
Joined: 30 May 2013 04:56

Releasing and creating media player causes freeze

Postby Hanley » 10 Oct 2023 18:35

I've added a feature to my video player that lets users choose the y position of the subtitle, achieved with --sub-margin. Since this argument has to be passed in when creating an instance of libvlc, when the user changes the position, I have to release both the instance and the video player, and then immediately recreate it with the new sub margin. Sometimes, this causes the app to hang in libvlc_media_player_release. I then started detaching media player events before releasing, which made the freezes less frequent, but it still happens.

Is there anything else I should be doing before releasing the media player to prevent it from hanging? Here's a concise version of my code:

Code: Select all

vlc_mediaPlayerEventManager = libvlc_media_player_event_manager(vlc_mplayer); libvlc_event_detach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPositionChanged, callback, this); libvlc_event_detach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPlaying, callback, this); libvlc_event_detach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerStopped, callback, this); libvlc_event_detach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPaused, callback, this); libvlc_media_player_release(vlc_mplayer); libvlc_release(vlc_instan); vlc_mplayer = 0; vlc_instan = 0; vlc_instan = libvlc_new(vlc_args.size(), &vlc_args[0]); libvlc_log_set_file(vlc_instan, file); vlc_media = libvlc_media_new_path (vlc_instan,pmedia.toUTF8().getAddress()); String subtitlePath = "file:///" + vidPath.substring(0, vidPath.lastIndexOf(TopComponent::sysPathChar)) + TopComponent::sysPathChar + subtitleLanguage + ".srt"; int result = libvlc_media_slaves_add(vlc_media, libvlc_media_slave_type_subtitle, 4, subtitlePath.toUTF8().getAddress()); vlc_mediaEventManager = libvlc_media_event_manager(vlc_media); libvlc_event_attach(vlc_mediaEventManager,libvlc_MediaParsedChanged,callback,this); libvlc_media_parse_with_options(vlc_media, libvlc_media_parse_local, 0); vlc_mplayer = libvlc_media_player_new_from_media (vlc_media); libvlc_media_release (vlc_media); vlc_mediaPlayerEventManager = libvlc_media_player_event_manager(vlc_mplayer); libvlc_event_attach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPositionChanged, callback, this); libvlc_event_attach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPlaying, callback, this); libvlc_event_attach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerStopped, callback, this); libvlc_event_attach(vlc_mediaPlayerEventManager, libvlc_MediaPlayerPaused, callback, this); libvlc_media_player_set_hwnd(vlc_mplayer, vlc_visor->getWindowHandle());

Hanley
Blank Cone
Blank Cone
Posts: 22
Joined: 30 May 2013 04:56

Re: Releasing and creating media player causes freeze

Postby Hanley » 16 Oct 2023 17:12

Any thoughts on this?

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

Re: Releasing and creating media player causes freeze

Postby Rémi Denis-Courmont » 16 Oct 2023 21:31

First, I believe that the developer documentation is exceedingly clear about the fact that configuring LibVLC that way is not supported.

And then, without a symbolic threaded stack trace, nobody can really say anything other than hazard a guess that your callback or event loop is causing the deadlock.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Hanley
Blank Cone
Blank Cone
Posts: 22
Joined: 30 May 2013 04:56

Re: Releasing and creating media player causes freeze

Postby Hanley » 17 Oct 2023 22:24

Solution turned out to be simple: call libvlc_media_player_stop before detaching the events and releasing the player and instance.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 8 guests