Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

_VlcControl.VclMediaPlayer.Stop() Freeze when stopping a disconnected dshow device #625

Open
DavidVTurley opened this issue Mar 7, 2020 · 5 comments

Comments

@DavidVTurley
Copy link

DavidVTurley commented Mar 7, 2020

  • Vlc.DotNet version : 3.1.0-develop 364
  • Vlc.DotNet project used : WinForms
  • libvlc version : 3.0.8 Ventinari
  • .net version : 4.8
  • Project language : C#
  • Project build architecture : x64
  • Operating system : Windows 10 x64

Hello,

I have been building a camera into an application.
It works really well and have had almost no issues, but i ran into one the other day.
When I am playing a dshow stream in the player if the camera gets disconnected the screen freezes. Same in desktop VLC. However in the desktop VLC i can change to a different video playback. When i try to stop the player in my app it hangs. I have left it running for an hour during lunch bit it stays hanging.

This happens however i try to do it. be it VlcControl.stop() or Vlc.VlcMediaPlayer.Stop(). Same thing happens if i try to dispose the player, or the form it is running in.
I have tried using invoke as suggested in https://github.com/ZeBobo5/Vlc.DotNet/wiki/Vlc.DotNet-freezes-(don't-call-Vlc.DotNet-from-a-Vlc.DotNet-callback):
Invoke(new Action(() => { _vlcControl.VlcMediaPlayer.Stop(); _vlcControl.Dispose(); Dispose(); }));
also tried it with the ThreadPool method. I know i dont have to call stop because dispose calls it to, but the freeze happens there so it narrows it down slightly.
I saw somewhere else that _vlcControlVideoStream.SetMedia(@"C:\Downloads\Rotating_earth_(large).gif"); might work, but it doesnt.

If anyone has an idea, any help would be appreciated!

David

@jeremyVignelles
Copy link
Collaborator

Please send a complete code on github.

I didn't understand the "Same in VLC" part. Does it freeze the same way? If so, there's nothing I can do about that.

@mfkl
Copy link
Contributor

mfkl commented Mar 7, 2020

@DavidVTurley
Copy link
Author

No what i mean is in the desktop vlc the "real" vlc, it freezes as well, but that is to be expected the video source has been turned off. But when i try to switch the media it is playing it can switch it.
However when i try to switch or stop the media in winforms it hangs inside the stop() function.
Under normal opperation when the dshow device is still switched on it can stop or switch the stream, but if the dshow device is switched off or disconects while the player is playing it, when i try to stop it or dispose the player it freezes indefinitely.

private VlcControl _vlcControl;

private void Initialize()
{
    String[] VlcOptions = new []
    {
        ":dshow-vdev=IPEVO VZ-R",
        ":dshow-size=1920x1080",
        ":dshow-adev=none",
        ":dshow-aspect-ratio=16:9"
    }
    _vlcControl.VlcMediaPlayer.Play("dshow://", VlcOptions);
}

private void OnFormClose(Object senderm FormClosingEventArgs e)
{
    // While the form is playing the camera is turned off. The vlc player hangs, but the form and buttons are still responsive. When the _vlcControl.Stop() is called the program hangs there.
    _vlcControl.Stop();
    _vlcControl.Dispose();
    Dispose();
}

@jeremyVignelles
Copy link
Collaborator

Another idea : can you try to trigger the Stop before the FormClose event, from another thread than the main thread?
I suspect that there is some deadlock because the hwnd is already being destroyed by WinForms...

@DavidVTurley
Copy link
Author

I tried it, and with this code it freezes straight away:

private void StartFocusButtonClick(Object sender, EventArgs e)
{
    invoke(new Action(() => {
         _vlcControlVideoStream.Stop();
    }));
}

Whereas when I try this, the interface stays working, but it freezes after a while and on exit.

private void StartFocusButtonClick(Object sender, EventArgs e)
{
    ThreadPool.QueueUserWorkItem(_ => _vlcControlVideoStream.Stop());
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants