mirror of
https://github.com/videolan/vlc.git
synced 2024-12-12 03:06:13 +08:00
lib/media_player: add record method
Co-Authored-by: Thomas Guillem <thomas@gllm.fr>
This commit is contained in:
parent
e31cdb43cc
commit
89dbd92813
@ -31,6 +31,8 @@
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# else
|
||||
# include <stdbool.h>
|
||||
# endif
|
||||
|
||||
typedef struct libvlc_renderer_item_t libvlc_renderer_item_t;
|
||||
@ -147,6 +149,7 @@ enum libvlc_event_e {
|
||||
*/
|
||||
libvlc_MediaPlayerTitleSelectionChanged,
|
||||
libvlc_MediaPlayerChapterChanged,
|
||||
libvlc_MediaPlayerRecordChanged,
|
||||
|
||||
/**
|
||||
* A \link #libvlc_media_t media item\endlink was added to a
|
||||
@ -400,6 +403,13 @@ typedef struct libvlc_event_t
|
||||
const char *device;
|
||||
} media_player_audio_device;
|
||||
|
||||
struct
|
||||
{
|
||||
bool recording;
|
||||
/** Only valid when recording ends (recording == false) */
|
||||
const char *recorded_file_path;
|
||||
} media_player_record_changed;
|
||||
|
||||
struct
|
||||
{
|
||||
libvlc_renderer_item_t *item;
|
||||
|
@ -2650,6 +2650,22 @@ LIBVLC_API int libvlc_media_player_get_role(libvlc_media_player_t *p_mi);
|
||||
LIBVLC_API int libvlc_media_player_set_role(libvlc_media_player_t *p_mi,
|
||||
unsigned role);
|
||||
|
||||
/**
|
||||
* Start/stop recording
|
||||
*
|
||||
* \note The user should listen to the libvlc_MediaPlayerRecordChanged event,
|
||||
* to monitor the recording state.
|
||||
*
|
||||
* \version LibVLC 4.0.0 and later.
|
||||
*
|
||||
* \param p_mi media player
|
||||
* \param enable true to start recording, false to stop
|
||||
* \param dir_path path of the recording directory or NULL (use default path),
|
||||
* has only an effect when first enabling recording.
|
||||
*/
|
||||
LIBVLC_API void libvlc_media_player_record(libvlc_media_player_t *p_mi,
|
||||
bool enable, const char *dir_path);
|
||||
|
||||
/** @} audio */
|
||||
|
||||
/** \defgroup libvlc_media_player_watch_time LibVLC media player time watch API
|
||||
|
@ -160,6 +160,7 @@ libvlc_media_player_set_pause
|
||||
libvlc_media_player_pause
|
||||
libvlc_media_player_play
|
||||
libvlc_media_player_previous_chapter
|
||||
libvlc_media_player_record
|
||||
libvlc_media_player_release
|
||||
libvlc_media_player_retain
|
||||
libvlc_media_player_set_android_context
|
||||
|
@ -110,6 +110,25 @@ on_state_changed(vlc_player_t *player, enum vlc_player_state new_state,
|
||||
libvlc_event_send(&mp->event_manager, &event);
|
||||
}
|
||||
|
||||
static void
|
||||
on_recording_changed(vlc_player_t *player, bool recording, void *data)
|
||||
{
|
||||
(void) player;
|
||||
libvlc_media_player_t *mp = data;
|
||||
|
||||
/* "record-file" is only valid when recording ends */
|
||||
char *file_path = !recording ? var_GetString(mp, "record-file") : NULL;
|
||||
|
||||
libvlc_event_t event;
|
||||
event.type = libvlc_MediaPlayerRecordChanged;
|
||||
event.u.media_player_record_changed.recorded_file_path = file_path;
|
||||
event.u.media_player_record_changed.recording = recording;
|
||||
|
||||
libvlc_event_send(&mp->event_manager, &event);
|
||||
|
||||
free(file_path);
|
||||
}
|
||||
|
||||
static void
|
||||
on_error_changed(vlc_player_t *player, enum vlc_player_error error, void *data)
|
||||
{
|
||||
@ -504,6 +523,7 @@ static const struct vlc_player_cbs vlc_player_cbs = {
|
||||
.on_media_subitems_changed = on_media_subitems_changed,
|
||||
.on_cork_changed = on_cork_changed,
|
||||
.on_vout_changed = on_vout_changed,
|
||||
.on_recording_changed = on_recording_changed,
|
||||
};
|
||||
|
||||
static const struct vlc_player_aout_cbs vlc_player_aout_cbs = {
|
||||
@ -717,8 +737,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
|
||||
var_Create (mp, "equalizer-vlcfreqs", VLC_VAR_BOOL);
|
||||
var_Create (mp, "equalizer-bands", VLC_VAR_STRING);
|
||||
|
||||
mp->timer.id = NULL;
|
||||
/* variables for signalling creation of new files */
|
||||
var_Create(mp, "record-file", VLC_VAR_STRING);
|
||||
|
||||
mp->timer.id = NULL;
|
||||
mp->p_md = NULL;
|
||||
mp->p_libvlc_instance = instance;
|
||||
/* use a reentrant lock to allow calling libvlc functions from callbacks */
|
||||
@ -2209,6 +2231,17 @@ int libvlc_media_player_get_role(libvlc_media_player_t *mp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void libvlc_media_player_record( libvlc_media_player_t *p_mi,
|
||||
bool enable,
|
||||
const char *path)
|
||||
{
|
||||
vlc_player_t *player = p_mi->player;
|
||||
|
||||
vlc_player_Lock(player);
|
||||
vlc_player_SetRecordingEnabled(player, enable, path);
|
||||
vlc_player_Unlock(player);
|
||||
}
|
||||
|
||||
#define PLAYER_TIME_CORE_TO_LIB(point) { \
|
||||
.position = point->position, \
|
||||
.rate = point->rate, \
|
||||
|
Loading…
Reference in New Issue
Block a user