[vlc-devel] [PATCH] Add new API to libvlc to record the current media to either an application-specified file or a file automatically created by vlc:
Rémi Denis-Courmont
remi at remlab.net
Thu Sep 6 09:46:50 CEST 2012
Le lundi 3 septembre 2012 19:52:18, Mark Lee a écrit :
> diff --git a/lib/media_player.c b/lib/media_player.c
> index a41b8c7..6573197 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -1409,3 +1466,62 @@ void libvlc_media_player_next_frame(
> libvlc_media_player_t *p_mi ) vlc_object_release( p_input_thread );
> }
> }
> +
> +bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi )
> +{
> + input_thread_t *p_input_thread;
> + bool b_can_record;
> +
> + p_input_thread = libvlc_get_input_thread( p_mi );
> + if( !p_input_thread )
> + return false;
> +
> + b_can_record = var_GetBool( p_input_thread, "can-record" );
> +
> + vlc_object_release( p_input_thread );
> + return b_can_record;
> +}
> +
> +bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi )
> +{
> + input_thread_t *p_input_thread;
> + bool b_record;
> +
> + p_input_thread = libvlc_get_input_thread( p_mi );
> + if( !p_input_thread )
> + return false;
> +
> + b_record = var_GetBool( p_input_thread, "record" );
> +
> + vlc_object_release( p_input_thread );
> + return b_record;
> +}
> +
> +int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const
> char* psz_filename ) +{
> + input_thread_t *p_input_thread;
> +
> + p_input_thread = libvlc_get_input_thread( p_mi );
> + if( !p_input_thread )
> + return -1;
> +
> + var_SetString( p_input_thread, "input-record-path", psz_filename );
> + var_SetBool( p_input_thread, "record", true );
> +
> + vlc_object_release( p_input_thread );
> + return 0;
> +}
> +
> +int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi )
> +{
> + input_thread_t *p_input_thread;
> +
> + p_input_thread = libvlc_get_input_thread( p_mi );
> + if( !p_input_thread )
> + return -1;
> +
> + var_SetBool( p_input_thread, "record", false );
> +
> + vlc_object_release( p_input_thread );
> + return 0;
> +}
I'm not sure it makes sense to have a return value here. How is the caller
supposed to deal with a failure?
> diff --git a/modules/stream_out/record.c b/modules/stream_out/record.c
> index de6d32e..40ddfea 100644
> --- a/modules/stream_out/record.c
> +++ b/modules/stream_out/record.c
> @@ -172,6 +176,19 @@ static void Close( vlc_object_t * p_this )
> if( p_sys->p_out )
> sout_StreamChainDelete( p_sys->p_out, p_sys->p_out );
>
> + if( p_sys->psz_record_file ) {
> + for( vlc_object_t *p_mp = p_stream->p_parent; p_mp; p_mp =
> p_mp->p_parent )
> + {
> + if( var_Type( p_mp, "recording-finished" ) )
> + {
> + var_SetString( p_mp, "recording-finished",
> p_sys->psz_record_file ); + break;
> + }
> + }
> +
> + free( p_sys->psz_record_file );
> + }
Oh? That actually works? I thought the parent is the stream output instance
(or the upstream stream out plugin) rather than the input thread...
That's not really the recommended way to provide callbacks.
> +
> TAB_CLEAN( p_sys->i_id, p_sys->id );
> free( p_sys->psz_prefix );
> free( p_sys );
> @@ -352,7 +369,10 @@ static int OutputNew( sout_stream_t *p_stream,
> }
>
> if( psz_file && psz_extension )
> + {
> + p_sys->psz_record_file = strdup( psz_file );
> var_SetString( p_stream->p_libvlc, "record-file", psz_file );
> + }
>
> free( psz_file );
> free( psz_output );
> diff --git a/src/input/var.c b/src/input/var.c
> index 9613fe2..04f33b9 100644
> --- a/src/input/var.c
> +++ b/src/input/var.c
> @@ -210,6 +210,9 @@ void input_ControlVarInit ( input_thread_t *p_input )
> text.psz_string = _("Subtitles Track");
> var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
>
> + /* ES Out */
> + var_Create( p_input, "input-record-path", VLC_VAR_STRING |
> VLC_VAR_DOINHERIT );
> +
> /* Special read only objects variables for intf */
> var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT
> );
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list