[vlc-devel] libvlc_media_player_stop pending when try to stop one in two directshow instances

cong fu fc4976 at gmail.com
Tue Apr 16 11:40:47 CEST 2013


Another version with better layout:)

Hi:

I am a newbee for vlc developing, now I want to do such thing in my corrent
project:

A Win7 App(written in WPF & C#), which:

1. Can Show living streaming video from an DirectShow USB WebCam to a
window of the App

2. Can record the video into a mp4 file

3. Can stop recording the video, but the living show should always there

To make that work, I created two VLC media player instances: one if for
living streaming show on screen, the other is for recording streaming video
into file.

==========================================================================================
Copy some code here:

+++++++++++++++++++++++++++++++++
MyVLCPlayer.cs++++++++++++++++++++++++++++++++++++++++

    class MyVLCPlayer
    {
        private IntPtr libvlc_instance_;
        private IntPtr libvlc_media_player_;
        private double duration_;
....
        public MyVLCPlayer()
        {
            string[] arguments = { "-I", "dummy", "--ignore-config",
"--no-video-title", @"--plugin-path=C:\Program Files
(x86)\VideoLAN\VLC\plugins" };
            libvlc_instance_ = LibVlc.libvlc_new(arguments.Length,
arguments);
            if (libvlc_instance_ != IntPtr.Zero)
            {
                libvlc_media_player_ =
LibVlc.libvlc_media_player_new(libvlc_instance_);
            }
        }
....
        public void PlayDirectShow()
        {
            if (libvlc_instance_ != IntPtr.Zero)
            {
                IntPtr libvlc_media =
LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");
                if (libvlc_media != IntPtr.Zero)
                {
                        string[] options = new string[]
                        {
                    ":dshow-vdev=USB 2861 Device",
                            ":dshow-size=640*480",

                        };
                        foreach (string option in options)
                        {
                            LibVlc.libvlc_media_add_option(libvlc_media,
option);
                        }
                        if (libvlc_media_player_ != IntPtr.Zero)
                        {

LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);
                        }
                        LibVlc.libvlc_media_release(libvlc_media);

LibVlc.libvlc_media_player_play(libvlc_media_player_);

//LibVlc.libvlc_media_player_pause(libvlc_media_player_);
                }
            }
        }
        public void RecordDirectShow(string filePath)
        {
            if (libvlc_instance_ != IntPtr.Zero)
            {
                IntPtr libvlc_media =
LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");
                if (libvlc_media != IntPtr.Zero)
                {
                    string[] options = new string[]
                        {
                    ":dshow-vdev=USB 2861 Device",
                            ":dshow-size=640*480",


":sout=#duplicate{dst=\'transcode{venc=x264{keyint=15,bframes=0},vcodec=h264,vb=400,scale=1,fps=25,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file,mux=mp4,dst="
+ filePath + "}\'}"
                        };
                    foreach (string option in options)
                    {
                        LibVlc.libvlc_media_add_option(libvlc_media,
option);
                    }
                    if (libvlc_media_player_ != IntPtr.Zero)
                    {

LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);
                    }
                    LibVlc.libvlc_media_release(libvlc_media);
                    LibVlc.libvlc_media_player_play(libvlc_media_player_);

//LibVlc.libvlc_media_player_pause(libvlc_media_player_);
                }
            }
        }

        public void Stop()
        {
            if (libvlc_media_player_ != IntPtr.Zero)
            {
                LibVlc.libvlc_media_player_stop(libvlc_media_player_);
            }
        }

.....
}

+++++++++++++++++++++++++++++++++++++MainWindow.xaml.cs+++++++++++++++++++++++++++++++++++++++++

private MyVLCPlayer player;
        private MyVLCPlayer recorder;

        public MainWindow()
        {
            InitializeComponent();
....
player = new MyVLCPlayer();
            recorder = new MyVLCPlayer();
....

        }


Then, do something like that:

1. player. PlayDirectShow();
2. recorder.RecordDirectShow(filepath);
3. recorder.Stop();

The 1 and 2 works well, I can see the living video on screen and the mp4
file recorded on the fly, but

*the stop will never return!!*

can someone tell me why?


2013/4/16 cong fu <fc4976 at gmail.com>

> Hi:
>
> I am a newbee for vlc developing, now I want to do such thing in my
> corrent project:
>
> a windows application, which can:
> 1. Show living show from an directshow usb device on screen forever
> 2. click a button to start to record the video into a mp4 file
> 3. click another button to stop recording the video, but the living show
> should always there
>
> to make it work, I created two VLC media player instances, one if for
> living show on screen, the other is for recording into file, copy some code
> here:
>
> MyVLCPlayer.cs
>
>         public MyVLCPlayer()
>         {
>             string[] arguments = { "-I", "dummy", "--ignore-config",
> "--no-video-title", @"--plugin-path=C:\Program Files
> (x86)\VideoLAN\VLC\plugins" };
>             libvlc_instance_ = LibVlc.libvlc_new(arguments.Length,
> arguments);
>             if (libvlc_instance_ != IntPtr.Zero)
>             {
>                 libvlc_media_player_ =
> LibVlc.libvlc_media_player_new(libvlc_instance_);
>             }
>         }
>
>         public void PlayDirectShow()
>         {
>             if (libvlc_instance_ != IntPtr.Zero)
>             {
>                 IntPtr libvlc_media =
> LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");
>                 if (libvlc_media != IntPtr.Zero)
>                 {
>                         string[] options = new string[]
>                         {
>                     ":dshow-vdev=USB 2861 Device",
>                             ":dshow-size=640*480",
>
>                         };
>                         foreach (string option in options)
>                         {
>                             LibVlc.libvlc_media_add_option(libvlc_media,
> option);
>                         }
>                         if (libvlc_media_player_ != IntPtr.Zero)
>                         {
>
> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);
>                         }
>                         LibVlc.libvlc_media_release(libvlc_media);
>
> LibVlc.libvlc_media_player_play(libvlc_media_player_);
>
> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);
>                 }
>             }
>         }
>         public void RecordDirectShow(string filePath)
>         {
>             if (libvlc_instance_ != IntPtr.Zero)
>             {
>                 IntPtr libvlc_media =
> LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");
>                 if (libvlc_media != IntPtr.Zero)
>                 {
>                     string[] options = new string[]
>                         {
>                     ":dshow-vdev=USB 2861 Device",
>                             ":dshow-size=640*480",
>
>
> ":sout=#duplicate{dst=\'transcode{venc=x264{keyint=15,bframes=0},vcodec=h264,vb=400,scale=1,fps=25,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file,mux=mp4,dst="
> + filePath + "}\'}"
>                         };
>                     foreach (string option in options)
>                     {
>                         LibVlc.libvlc_media_add_option(libvlc_media,
> option);
>                     }
>                     if (libvlc_media_player_ != IntPtr.Zero)
>                     {
>
> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);
>                     }
>                     LibVlc.libvlc_media_release(libvlc_media);
>                     LibVlc.libvlc_media_player_play(libvlc_media_player_);
>
> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);
>                 }
>             }
>         }
>
> MainWindow.xaml.cs
>
> private MyVLCPlayer player;
>         private MyVLCPlayer recorder;
>
>         public MainWindow()
>         {
>             InitializeComponent();
> ....
> player = new MyVLCPlayer();
>             recorder = new MyVLCPlayer();
> ....
>
>         }
>
>  Then,
>
> 1. player. PlayDirectShow();
> 2. recorder.RecordDirectShow(filepath);
> 3. recorder.Stop();
>
> the stop will never return!!
>
> can someone tell me why?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20130416/11aadccd/attachment.html>


More information about the vlc-devel mailing list