From fd75b79477517af5ea70e51808396cae019a60c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Wed, 15 Oct 2014 14:34:15 +0200 Subject: [PATCH] Add a destroy function to the Linphone Player Interface --- coreapi/linphonecore.h | 7 +------ coreapi/localplayer.c | 12 +++++++----- coreapi/player.c | 14 +++++++++++++- coreapi/private.h | 3 +++ tester/player_tester.c | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 2f1036678..9b2ef15ec 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -595,6 +595,7 @@ MSPlayerState linphone_player_get_state(LinphonePlayer *obj); int linphone_player_get_duration(LinphonePlayer *obj); int linphone_player_get_current_position(LinphonePlayer *obj); void linphone_player_close(LinphonePlayer *obj); +void linphone_player_destroy(LinphonePlayer *obj); /** * @brief Create an independent media file player. @@ -607,12 +608,6 @@ void linphone_player_close(LinphonePlayer *obj); */ LINPHONE_PUBLIC LinphonePlayer *linphone_core_create_local_player(LinphoneCore *lc, MSSndCard *snd_card, const char *video_out, void *window_id); -/** - * @brief Destroy a local player - * @param obj File player to destroy - */ -LINPHONE_PUBLIC void linphone_local_player_destroy(LinphonePlayer *obj); - /** * @brief Check whether Matroksa format is supported by the player * @return TRUE if it is supported diff --git a/coreapi/localplayer.c b/coreapi/localplayer.c index 9d6e1b5c3..ad06e1751 100644 --- a/coreapi/localplayer.c +++ b/coreapi/localplayer.c @@ -29,6 +29,7 @@ static MSPlayerState _local_player_get_state(LinphonePlayer *obj); static int _local_player_get_duration(LinphonePlayer *obj); static int _local_player_get_current_position(LinphonePlayer *obj); static void _local_player_close(LinphonePlayer *obj); +static void _local_player_destroy(LinphonePlayer *obj); static void _local_player_eof_callback(void *user_data); LinphonePlayer *linphone_core_create_local_player(LinphoneCore *lc, MSSndCard *snd_card, const char *video_out, void *window_id) { @@ -44,15 +45,11 @@ LinphonePlayer *linphone_core_create_local_player(LinphoneCore *lc, MSSndCard *s obj->get_duration = _local_player_get_duration; obj->get_position = _local_player_get_current_position; obj->close = _local_player_close; + obj->destroy = _local_player_destroy; ms_media_player_set_eof_callback((MSMediaPlayer *)obj->impl, _local_player_eof_callback, obj); return obj; } -void linphone_local_player_destroy(LinphonePlayer *obj) { - ms_media_player_free((MSMediaPlayer *)obj->impl); - ms_free(obj); -} - bool_t linphone_local_player_matroska_supported(void) { return ms_media_player_matroska_supported(); } @@ -86,6 +83,11 @@ static int _local_player_get_current_position(LinphonePlayer *obj) { return ms_media_player_get_current_position((MSMediaPlayer *)obj->impl); } +static void _local_player_destroy(LinphonePlayer *obj) { + ms_media_player_free((MSMediaPlayer *)obj->impl); + _linphone_player_destroy(obj); +} + static void _local_player_close(LinphonePlayer *obj) { ms_media_player_close((MSMediaPlayer *)obj->impl); } diff --git a/coreapi/player.c b/coreapi/player.c index 54573ccb8..1b2a01022 100644 --- a/coreapi/player.c +++ b/coreapi/player.c @@ -97,6 +97,18 @@ void linphone_player_close(LinphonePlayer *obj){ return obj->close(obj); } +/** + * @brief Destroy a player + * @param obj The player + */ +void linphone_player_destroy(LinphonePlayer *obj) { + if(obj->destroy) obj->destroy(obj); +} + +void _linphone_player_destroy(LinphonePlayer *player) { + ms_free(player); +} + /* * Call player implementation below. @@ -169,7 +181,7 @@ static void call_player_close(LinphonePlayer *player){ } static void on_call_destroy(void *obj, belle_sip_object_t *call_being_destroyed){ - ms_free(obj); + _linphone_player_destroy(obj); } LinphonePlayer *linphone_call_build_player(LinphoneCall *call){ diff --git a/coreapi/private.h b/coreapi/private.h index 40777e207..bc0ff038c 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -923,11 +923,14 @@ struct _LinphonePlayer{ int (*get_duration)(struct _LinphonePlayer *player); int (*get_position)(struct _LinphonePlayer *player); void (*close)(struct _LinphonePlayer* player); + void (*destroy)(struct _LinphonePlayer *player); LinphonePlayerEofCallback cb; void *user_data; void *impl; }; +void _linphone_player_destroy(LinphonePlayer *player); + /***************************************************************************** * XML UTILITY FUNCTIONS * diff --git a/tester/player_tester.c b/tester/player_tester.c index 14bb6d3ab..17e692d23 100644 --- a/tester/player_tester.c +++ b/tester/player_tester.c @@ -79,7 +79,7 @@ static void play_file(const char *filename, bool_t unsupported_format) { linphone_player_close(player); fail: - if(player) linphone_local_player_destroy(player); + if(player) linphone_player_destroy(player); if(lc_manager) linphone_core_manager_destroy(lc_manager); }