Page 1 of 1

Releasing and creating media player causes freeze

Posted: 10 Oct 2023 18:35
by Hanley
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());

Re: Releasing and creating media player causes freeze

Posted: 16 Oct 2023 17:12
by Hanley
Any thoughts on this?

Re: Releasing and creating media player causes freeze

Posted: 16 Oct 2023 21:31
by RĂ©mi Denis-Courmont
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.

Re: Releasing and creating media player causes freeze

Posted: 17 Oct 2023 22:24
by Hanley
Solution turned out to be simple: call libvlc_media_player_stop before detaching the events and releasing the player and instance.