libvlc_media_player stop doesn't kill sout

This forum is about all development around libVLC.
WhatEver
New Cone
New Cone
Posts: 7
Joined: 12 Apr 2010 17:57

libvlc_media_player stop doesn't kill sout

Postby WhatEver » 08 Oct 2010 12:13

Hi,

I'm trying to save a DVB-T channel directly in an avi file.

Here is the command that works in a term :

Code: Select all

vlc -vvv dvb:// :ts-es-id-pid :dvb-frequency=XXXXX :program=XX ":sout=#duplicate{dst=display,dst=std{dst=XXX.avi,mux=avi,access=file},select='program=XX'}"
When closing vlc, the avi file is correctly formed and perfectly readable.

Now what i'm trying to do is to do the same thing directly with libvlc.

Code: Select all

#include <vlc/libvlc.h> #include <vlc/libvlc_media.h> #include <vlc/libvlc_media_player.h> #include <stdlib.h> int main() { const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ "--extraintf=logger", //log anything "--verbose=2"}; //be much more verbose then normal for debugging purpose libvlc_instance_t* instance1 = libvlc_new (5, vlc_args); libvlc_media_player_t * player = libvlc_media_player_new (instance1); libvlc_media_t* media = libvlc_media_new_location(instance1, "dvb://"); libvlc_media_add_option(media, "dvb-frequency=XXXXX"); libvlc_media_add_option(media, "ts-es-id-pid"); libvlc_media_add_option(media, "program=XX"); libvlc_media_add_option(media, "sout=#duplicate{dst=display,dst=std{dst=XXX,mux=avi,access=file},select='program=XX'}"); libvlc_media_player_set_media(player,media); libvlc_media_player_play(player); sleep(50); libvlc_media_player_stop(player); }
This code doesn't work properly when it comes to stop the player, (the avi file is not closed properly).

After a little research in VLC code, I found that input_resource_TerminateSout wasn't called with libvlc_media_player_stop.
However this function is called when stopping a playlist.

I have VLC 1.1.4.

So what am i doing wrong ?

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: libvlc_media_player stop doesn't kill sout

Postby Jean-Baptiste Kempf » 11 Oct 2010 00:36

It might be a bug in libVLC, but I don't see how.

If you do the same in vlc, does it stop correctly?
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.

WhatEver
New Cone
New Cone
Posts: 7
Joined: 12 Apr 2010 17:57

Re: libvlc_media_player stop doesn't kill sout

Postby WhatEver » 11 Oct 2010 09:54

The command line I posted works fine.

As far as I know, the "playlist stop" command will run "input_resource_TerminateVout" and (somehow) "input_resource_TerminateSout" whereas libvlc_media_player_stop only calls "input_resource_TerminateVout".
I guess it's the cause of the issue, but as it was not present in vlc 1.0x I thought something changed in the API or options and I didn't do it the right way.

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: libvlc_media_player stop doesn't kill sout

Postby Jean-Baptiste Kempf » 11 Oct 2010 11:34

Did you try to patch libvlc?
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.

WhatEver
New Cone
New Cone
Posts: 7
Joined: 12 Apr 2010 17:57

Re: libvlc_media_player stop doesn't kill sout

Postby WhatEver » 11 Oct 2010 13:28

I finally managed to patch libvlc.

I can't procure a patch file right now but here are the modifications :

At the end of "src/libvlccore.sym" add :

Code: Select all

input_resource_TerminateSout
At to the end of "include/vlc_input.h" add :

Code: Select all

/** * Forcefully destroys the stream output (e.g. when the playlist is stopped). */ VLC_EXPORT(void, input_resource_TerminateSout, ( input_resource_t * ) );
Modify the end of the function libvlc_media_player_stop in src/control/media_player.c (around l. 777) :

Code: Select all

if( p_mi->input.p_resource != NULL ) input_resource_TerminateVout( p_mi->input.p_resource );
replace by :

Code: Select all

if( p_mi->input.p_resource != NULL ) { input_resource_TerminateVout( p_mi->input.p_resource ); input_resource_TerminateSout( p_mi->input.p_resource ); }
With this modified version, my program works.
However my knowledge of vlc is quite limited and I don't know if there is any concequencies in other parts of libvlc.

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: libvlc_media_player stop doesn't kill sout

Postby Jean-Baptiste Kempf » 11 Oct 2010 14:59

Do a "git diff" to produce a patch.
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.

WhatEver
New Cone
New Cone
Posts: 7
Joined: 12 Apr 2010 17:57

Re: libvlc_media_player stop doesn't kill sout

Postby WhatEver » 11 Oct 2010 15:50

Here it is :

Code: Select all

diff --git a/include/vlc_input.h b/include/vlc_input.h index e548692..09302b3 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -673,6 +673,11 @@ VLC_EXPORT(void, input_resource_Release, ( input_resource_t * ) ); VLC_EXPORT(void, input_resource_TerminateVout, ( input_resource_t * ) ); /** +* Forcefully destroys the stream output (e.g. when the playlist is stopped). +*/ +VLC_EXPORT(void, input_resource_TerminateSout, ( input_resource_t * ) ); + +/** * This function releases all resources (object). */ VLC_EXPORT( void, input_resource_Terminate, ( input_resource_t * ) ); diff --git a/src/control/media_player.c b/src/control/media_player.c index 3789ddf..8984ca5 100644 --- a/src/control/media_player.c +++ b/src/control/media_player.c @@ -794,7 +794,10 @@ void libvlc_media_player_stop( libvlc_media_player_t *p_mi ) } if( p_mi->input.p_resource != NULL ) + { input_resource_TerminateVout( p_mi->input.p_resource ); + input_resource_TerminateSout( p_mi->input.p_resource ); + } unlock_input(p_mi); } diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 413ab79..3fc7c46 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -676,3 +676,4 @@ xml_ReaderDelete xml_ReaderReset KeyToString StringToKey +input_resource_TerminateSout
You can download the file here.

Please note that I could not test it on the git version of vlc since it won't compile on my current distribution.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 21 guests