[vlc-devel] [PATCH] Add methods to libvlc to enable and query recording of current media:

Rémi Denis-Courmont remi at remlab.net
Sun Jul 29 15:49:18 CEST 2012


Le dimanche 29 juillet 2012 16:30:15 Mark Lee, vous avez écrit :
>  * libvlc_media_player_can_record
>  * libvlc_media_player_get_record
>  * libvlc_media_player_set_record
> ---
>  include/vlc/libvlc_media_player.h |   44
> +++++++++++++++++++++++++++++++++++++ lib/libvlc.sym                    | 
>   3 +++
>  lib/media_player.c                |   44
> +++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)
> 
> diff --git a/include/vlc/libvlc_media_player.h
> b/include/vlc/libvlc_media_player.h index 809ed5f..e6e52ad 100644
> --- a/include/vlc/libvlc_media_player.h
> +++ b/include/vlc/libvlc_media_player.h
> @@ -1580,6 +1580,50 @@ LIBVLC_API int libvlc_audio_set_delay(
> libvlc_media_player_t *p_mi, int64_t i_de
> 
>  /** @} audio */
> 
> +/**
> + * Can the media player record the current media?
> + *
> + * Media must be playing or buffering before it can be recorded.
> + *
> + * \param p_mi media player
> + * \return non-zero if the media player can record, zero if it can not
> + * \version LibVLC 2.1.0 or later
> + */
> +LIBVLC_API int libvlc_media_player_can_record( libvlc_media_player_t *p_mi
> );

I don't see how that's supposed to work. How does the caller know when to call 
the function? How does the caller know that the state has not changed since it 
checked the result of the function? This function seems intrinsically broken 
by design.

> +
> +/**
> + * Set whether or not recording is enabled.
> + *
> + * Media must be buffering or playing before it can be recorded.
> + *
> + * Media will be saved to the appropriate media directory, for example
> "~/Videos". The + * file will not be immediately available in that
> directory until recording is finished. + *
> + * Recording can be started and stopped on-the-fly once the media has
> started playing, + * each time recording is stopped and restarted a new
> file will be created. + *
> + * Recording will be stopped when the media stops playing, and must be
> explicitly enabled + * again to restart recording.
> + *
> + * Features such as next/previous chapter, set time or position and so on
> are ineffective + * when recording is enabled.
> + *
> + * \param p_mi media player
> + * \param i_record start recording if non-zero, stop recording if zero
> + * \return zero on success, -1 on error
> + * \version LibVLC 2.1.0 or later
> + */
> +LIBVLC_API int libvlc_media_player_set_record( libvlc_media_player_t
> *p_mi, int i_record );

You can use 'bool' here.

> +
> +/**
> + * Get whether or not the media is currently being recorded.
> + *
> + * \param p_mi media player
> + * \return non-zero if recording, zero if not
> + * \version LibVLC 2.1.0 or later
> + */
> +LIBVLC_API int libvlc_media_player_get_record( libvlc_media_player_t *p_mi
> ); +
>  /** @} media_player */
> 
>  # ifdef __cplusplus
> diff --git a/lib/libvlc.sym b/lib/libvlc.sym
> index 974e04f..059471c 100644
> --- a/lib/libvlc.sym
> +++ b/lib/libvlc.sym
> @@ -116,6 +116,7 @@ libvlc_media_new_from_input_item
>  libvlc_media_parse
>  libvlc_media_parse_async
>  libvlc_media_player_can_pause
> +libvlc_media_player_can_record
>  libvlc_media_player_next_frame
>  libvlc_media_player_event_manager
>  libvlc_media_player_get_agl
> @@ -129,6 +130,7 @@ libvlc_media_player_get_media
>  libvlc_media_player_get_nsobject
>  libvlc_media_player_get_position
>  libvlc_media_player_get_rate
> +libvlc_media_player_get_record
>  libvlc_media_player_get_state
>  libvlc_media_player_get_time
>  libvlc_media_player_get_title
> @@ -153,6 +155,7 @@ libvlc_media_player_set_media
>  libvlc_media_player_set_nsobject
>  libvlc_media_player_set_position
>  libvlc_media_player_set_rate
> +libvlc_media_player_set_record
>  libvlc_media_player_set_time
>  libvlc_media_player_set_title
>  libvlc_media_player_set_xwindow
> diff --git a/lib/media_player.c b/lib/media_player.c
> index f30f184..4d93e42 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -1408,3 +1408,47 @@ void libvlc_media_player_next_frame(
> libvlc_media_player_t *p_mi ) vlc_object_release( p_input_thread );
>      }
>  }
> +
> +int libvlc_media_player_can_record( 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 0;
> +
> +    b_can_record = var_GetBool( p_input_thread, "can-record" );
> +
> +    vlc_object_release( p_input_thread );
> +    return b_can_record;
> +}
> +
> +int libvlc_media_player_set_record( libvlc_media_player_t *p_mi, int
> i_record ) +{
> +    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", i_record );
> +
> +    vlc_object_release( p_input_thread );
> +    return 0;
> +}
> +
> +int libvlc_media_player_get_record( 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 0;
> +
> +    b_record = var_GetBool( p_input_thread, "record" );
> +
> +    vlc_object_release( p_input_thread );
> +    return b_record;
> +}


-- 
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis



More information about the vlc-devel mailing list