diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 2d911d0ed..8ca65da17 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -46,6 +46,7 @@ set(LINPHONE_HEADER_FILES linphone_tunnel.h lpc2xml.h lpconfig.h + ringtoneplayer.h sipsetup.h xml2lpc.h xmlrpc.h @@ -105,6 +106,7 @@ set(LINPHONE_SOURCE_FILES_C proxy.c quality_reporting.c remote_provisioning.c + ringtoneplayer.c sal.c siplogin.c sipsetup.c @@ -115,6 +117,12 @@ set(LINPHONE_SOURCE_FILES_C ) set(LINPHONE_SOURCE_FILES_CXX ) +set(LINPHONE_SOURCE_FILES_OBJC) +if (IOS) + list(APPEND LINPHONE_SOURCE_FILES_OBJC ringtoneplayer_ios.m ringtoneplayer_ios.h) +endif() + + if(ENABLE_TUNNEL) list(APPEND LINPHONE_SOURCE_FILES_CXX linphone_tunnel.cc @@ -138,6 +146,7 @@ add_definitions( apply_compile_flags(LINPHONE_SOURCE_FILES_C "CPP" "C") apply_compile_flags(LINPHONE_SOURCE_FILES_CXX "CPP" "CXX") +apply_compile_flags(LINPHONE_SOURCE_FILES_OBJC "CPP" "OBJC") set(LIBS ${BELLESIP_LIBRARIES} @@ -167,10 +176,10 @@ if(INTL_FOUND) endif() if(ENABLE_STATIC) - add_library(linphone STATIC ${LINPHONE_HEADER_FILES} ${LINPHONE_SOURCE_FILES_C} ${LINPHONE_SOURCE_FILES_CXX}) + add_library(linphone STATIC ${LINPHONE_HEADER_FILES} ${LINPHONE_SOURCE_FILES_C} ${LINPHONE_SOURCE_FILES_CXX} ${LINPHONE_SOURCE_FILES_OBJC}) target_link_libraries(linphone ${LIBS}) else() - add_library(linphone SHARED ${LINPHONE_HEADER_FILES} ${LINPHONE_SOURCE_FILES_C} ${LINPHONE_SOURCE_FILES_CXX}) + add_library(linphone SHARED ${LINPHONE_HEADER_FILES} ${LINPHONE_SOURCE_FILES_C} ${LINPHONE_SOURCE_FILES_CXX} ${LINPHONE_SOURCE_FILES_OBJC}) set_target_properties(linphone PROPERTIES VERSION ${LINPHONE_SO_VERSION} LINKER_LANGUAGE CXX) target_link_libraries(linphone ${LIBS}) if(MSVC) @@ -182,6 +191,9 @@ else() endif() endif() endif() +if(IOS) + target_link_libraries(linphone "-framework Foundation" "-framework AVFoundation") +endif() add_dependencies(linphone liblinphone-git-version) if(WIN32 AND CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone") set_target_properties(linphone PROPERTIES PREFIX "lib") diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index d1e87473a..6dd422aa9 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -791,7 +791,7 @@ static void call_terminated(SalOp *op, const char *from){ linphone_core_start_refered_call(lc,call,NULL); } //we stop the call only if we have this current call or if we are in call - if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) { + if ((ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc)) { linphone_core_stop_ringing(lc); } linphone_call_stop_media_streams(call); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index b90f4799c..2e1e8b87f 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -523,7 +523,7 @@ static void process_response_from_post_file_log_collection(void *data, const bel /* Insert it in a multipart body handler which will manage the boundaries of multipart message */ bh = belle_sip_multipart_body_handler_new(log_collection_upload_on_progress, core, (belle_sip_body_handler_t *)first_part_bh, NULL); - ua = ms_strdup_printf("%s/%s", linphone_core_get_user_agent_name(), linphone_core_get_user_agent_version()); + ua = ms_strdup_printf("%s/%s", linphone_core_get_user_agent(core), linphone_core_get_version()); uri = belle_generic_uri_parse(linphone_core_get_log_collection_upload_server_url(core)); req = belle_http_request_create("POST", uri, belle_sip_header_create("User-Agent", ua), NULL); ms_free(ua); @@ -1732,6 +1732,8 @@ static void linphone_core_init(LinphoneCore * lc, const LinphoneCoreVTable *vtab certificates_config_read(lc); + lc->ringtoneplayer = linphone_ringtoneplayer_new(lc); + remote_provisioning_uri = linphone_core_get_provisioning_uri(lc); if (remote_provisioning_uri == NULL) { linphone_configuring_terminated(lc, LinphoneConfiguringSkipped, NULL); @@ -2545,8 +2547,7 @@ static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig } static void linphone_core_do_plugin_tasks(LinphoneCore *lc){ - LinphoneProxyConfig *cfg=NULL; - linphone_core_get_default_proxy(lc,&cfg); + LinphoneProxyConfig *cfg=linphone_core_get_default_proxy_config(lc); if (cfg){ if (lc->bl_refresh){ SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg); @@ -2642,8 +2643,7 @@ void linphone_core_iterate(LinphoneCore *lc){ if (lc->preview_finished){ lc->preview_finished=0; - ring_stop(lc->ringstream); - lc->ringstream=NULL; + linphone_ringtoneplayer_stop(lc->ringtoneplayer); lc_callback_obj_invoke(&lc->preview_finished_cb,lc); } @@ -2758,9 +2758,8 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) * it returns the registered identity on the proxy. **/ const char * linphone_core_get_identity(LinphoneCore *lc){ - LinphoneProxyConfig *proxy=NULL; + LinphoneProxyConfig *proxy=linphone_core_get_default_proxy_config(lc); const char *from; - linphone_core_get_default_proxy(lc,&proxy); if (proxy!=NULL) { from=linphone_proxy_config_get_identity(proxy); }else from=linphone_core_get_primary_contact(lc); @@ -2768,9 +2767,8 @@ const char * linphone_core_get_identity(LinphoneCore *lc){ } const char * linphone_core_get_route(LinphoneCore *lc){ - LinphoneProxyConfig *proxy=NULL; + LinphoneProxyConfig *proxy=linphone_core_get_default_proxy_config(lc); const char *route=NULL; - linphone_core_get_default_proxy(lc,&proxy); if (proxy!=NULL) { route=linphone_proxy_config_get_route(proxy); } @@ -3296,21 +3294,12 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){ /* play the ring if this is the only call*/ if (ms_list_size(lc->calls)==1){ + MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; lc->current_call=call; if (lc->ringstream && lc->dmfs_playing_start_time!=0){ linphone_core_stop_dtmf_stream(lc); } - if (lc->sound_conf.ring_sndcard!=NULL){ - if(lc->ringstream==NULL && lc->sound_conf.local_ring){ - MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; - ms_message("Starting local ring..."); - lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard); - } - else - { - ms_message("the local ring is already started"); - } - } + linphone_ringtoneplayer_start(lc->ringtoneplayer, ringcard, lc->sound_conf.local_ring, 2000); }else{ /* else play a tone within the context of the current call */ call->ringing_beep=TRUE; @@ -3772,7 +3761,7 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call, } /*stop ringing */ - if (lc->ringstream!=NULL) { + if (linphone_ringtoneplayer_is_started(lc->ringtoneplayer)) { ms_message("stop ringing"); linphone_core_stop_ringing(lc); was_ringing=TRUE; @@ -4797,26 +4786,26 @@ void linphone_core_verify_server_cn(LinphoneCore *lc, bool_t yesno){ lp_config_set_int(lc->config,"sip","verify_server_cn",yesno); } -static void notify_end_of_ring(void *ud, MSFilter *f, unsigned int event, void *arg){ - LinphoneCore *lc=(LinphoneCore*)ud; - if (event==MS_PLAYER_EOF){ - lc->preview_finished=1; - } +static void notify_end_of_ringtone( LinphoneRingtonePlayer* rp, void* user_data, int status) { + LinphoneCore *lc=(LinphoneCore*)user_data; + lc->preview_finished=1; } -int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata) +int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc end_of_ringtone,void * userdata) { - if (lc->ringstream!=0){ + int err; + MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; + if (linphone_ringtoneplayer_is_started(lc->ringtoneplayer)){ ms_warning("Cannot start ring now,there's already a ring being played"); return -1; } - lc_callback_obj_init(&lc->preview_finished_cb,func,userdata); + lc_callback_obj_init(&lc->preview_finished_cb,end_of_ringtone,userdata); lc->preview_finished=0; - if (lc->sound_conf.ring_sndcard!=NULL){ - MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; - lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc); + err = linphone_ringtoneplayer_start_with_cb(lc->ringtoneplayer, ringcard, ring, -1, notify_end_of_ringtone,(void *)lc); + if (err) { + lc->preview_finished=1; } - return 0; + return err; } /** @@ -4888,39 +4877,39 @@ static void linphone_core_mute_audio_stream(LinphoneCore *lc, AudioStream *st, b } void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){ + linphone_core_enable_mic(lc, !val); +} + +bool_t linphone_core_is_mic_muted(LinphoneCore *lc) { + return !linphone_core_mic_enabled(lc); +} + +void linphone_core_enable_mic(LinphoneCore *lc, bool_t enable) { LinphoneCall *call; const MSList *list; const MSList *elem; if (linphone_core_is_in_conference(lc)){ - lc->conf_ctx.local_muted=val; - linphone_core_mute_audio_stream(lc, lc->conf_ctx.local_participant, val); + lc->conf_ctx.local_muted=!enable; + linphone_core_mute_audio_stream(lc, lc->conf_ctx.local_participant, !enable); } list = linphone_core_get_calls(lc); for (elem = list; elem != NULL; elem = elem->next) { call = (LinphoneCall *)elem->data; - call->audio_muted = val; - linphone_core_mute_audio_stream(lc, call->audiostream, val); + call->audio_muted = !enable; + linphone_core_mute_audio_stream(lc, call->audiostream, !enable); } } -bool_t linphone_core_is_mic_muted(LinphoneCore *lc) { - LinphoneCall *call=linphone_core_get_current_call(lc); - if (linphone_core_is_in_conference(lc)){ - return lc->conf_ctx.local_muted; - }else if (call==NULL){ - ms_warning("linphone_core_is_mic_muted(): No current call !"); - return FALSE; - } - return call->audio_muted; -} - -void linphone_core_enable_mic(LinphoneCore *lc, bool_t enable) { - linphone_core_mute_mic(lc, (enable == TRUE) ? FALSE : TRUE); -} - bool_t linphone_core_mic_enabled(LinphoneCore *lc) { - return (linphone_core_is_mic_muted(lc) == TRUE) ? FALSE : TRUE; + LinphoneCall *call=linphone_core_get_current_call(lc); + if (linphone_core_is_in_conference(lc)){ + return !lc->conf_ctx.local_muted; + }else if (call==NULL){ + ms_warning("%s(): No current call!", __FUNCTION__); + return TRUE; + } + return !call->audio_muted; } // returns rtp transmission status for an active stream @@ -6460,6 +6449,9 @@ static void linphone_core_uninit(LinphoneCore *lc) if (lc->chat_db_file){ ms_free(lc->chat_db_file); } + if (lc->ringtoneplayer) { + linphone_ringtoneplayer_destroy(lc->ringtoneplayer); + } linphone_core_free_payload_types(lc); if (lc->supported_formats) ms_free(lc->supported_formats); linphone_core_message_storage_close(lc); @@ -6837,6 +6829,9 @@ void linphone_core_start_dtmf_stream(LinphoneCore* lc) { **/ void linphone_core_stop_ringing(LinphoneCore* lc) { LinphoneCall *call=linphone_core_get_current_call(lc); + if (linphone_ringtoneplayer_is_started(lc->ringtoneplayer)) { + linphone_ringtoneplayer_stop(lc->ringtoneplayer); + } if (lc->ringstream) { ring_stop(lc->ringstream); lc->ringstream=NULL; @@ -7435,3 +7430,7 @@ const char *linphone_stream_type_to_string(const LinphoneStreamType type) { } return "INVALID"; } + +LinphoneRingtonePlayer *linphone_core_get_ringtoneplayer(LinphoneCore *lc) { + return lc->ringtoneplayer; +} diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 475fcd65b..edcb6b751 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -4254,6 +4254,11 @@ LINPHONE_PUBLIC LinphoneTransportType linphone_transport_parse(const char* trans */ LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc); +typedef struct _LinphoneRingtonePlayer LinphoneRingtonePlayer; + +LINPHONE_PUBLIC LinphoneRingtonePlayer *linphone_core_get_ringtoneplayer(LinphoneCore *lc); + +#include "ringtoneplayer.h" #ifdef __cplusplus } diff --git a/coreapi/private.h b/coreapi/private.h index 6a2d2591b..38904d266 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -36,6 +36,7 @@ extern "C" { #include "sal/sal.h" #include "sipsetup.h" #include "quality_reporting.h" +#include "ringtoneplayer.h" #include #include @@ -950,6 +951,7 @@ struct _LinphoneCore const char **supported_formats; LinphoneContent *log_collection_upload_information; LinphoneCoreVTable *current_vtable; // the latest vtable to call a callback, see linphone_core_get_current_vtable + LinphoneRingtonePlayer *ringtoneplayer; #ifdef ANDROID jobject wifi_lock; jclass wifi_lock_class; @@ -1436,7 +1438,7 @@ bool_t linphone_core_lime_for_file_sharing_enabled(const LinphoneCore *lc); BELLE_SIP_DECLARE_VPTR(LinphoneTunnelConfig); int linphone_core_get_default_proxy_config_index(LinphoneCore *lc); - + #ifdef __cplusplus } #endif diff --git a/coreapi/ringtoneplayer.c b/coreapi/ringtoneplayer.c new file mode 100644 index 000000000..531ac2250 --- /dev/null +++ b/coreapi/ringtoneplayer.c @@ -0,0 +1,105 @@ +/* +linphone +Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) +Copyright (C) 2010 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#import "private.h" + +int linphone_ringtoneplayer_start(LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms) { + return linphone_ringtoneplayer_start_with_cb(rp, card, ringtone, loop_pause_ms, NULL, NULL); +} + +#ifdef __ios + +#import "ringtoneplayer_ios.h" + +LinphoneRingtonePlayer* linphone_ringtoneplayer_new() { + return linphone_ringtoneplayer_ios_new(); +} + +void linphone_ringtoneplayer_destroy(LinphoneRingtonePlayer* rp) { + linphone_ringtoneplayer_ios_destroy(rp); +} + +int linphone_ringtoneplayer_start_with_cb(LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data) { + return linphone_ringtoneplayer_ios_start_with_cb(rp, ringtone, loop_pause_ms, end_of_ringtone, user_data); +} + +bool_t linphone_ringtoneplayer_is_started(LinphoneRingtonePlayer* rp) { + return linphone_ringtoneplayer_ios_is_started(rp); +} + +int linphone_ringtoneplayer_stop(LinphoneRingtonePlayer* rp) { + return linphone_ringtoneplayer_ios_stop(rp); +} + + +#else + +struct _LinphoneRingtonePlayer { + RingStream *ringstream; + LinphoneRingtonePlayerFunc end_of_ringtone; + void* end_of_ringtone_ud; +}; + +LinphoneRingtonePlayer* linphone_ringtoneplayer_new() { + LinphoneRingtonePlayer* rp = ms_new0(LinphoneRingtonePlayer, 1); + return rp; +} + +void linphone_ringtoneplayer_destroy(LinphoneRingtonePlayer* rp) { + if (rp->ringstream) { + linphone_ringtoneplayer_stop(rp); + } + ms_free(rp); +} + +static void notify_end_of_ringtone(void *ud, MSFilter *f, unsigned int event, void *arg){ + LinphoneRingtonePlayer *rp=(LinphoneRingtonePlayer*)ud; + if (event==MS_PLAYER_EOF && rp->end_of_ringtone){ + rp->end_of_ringtone(rp, rp->end_of_ringtone_ud, 0); + } +} + +int linphone_ringtoneplayer_start_with_cb(LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data) { + if (linphone_ringtoneplayer_is_started(rp)) { + ms_message("the local ringtone is already started"); + return 2; + } + if (card!=NULL && ringtone){ + ms_message("Starting local ringtone..."); + rp->end_of_ringtone = end_of_ringtone; + rp->end_of_ringtone_ud = user_data; + rp->ringstream=ring_start_with_cb(ringtone,loop_pause_ms,card,notify_end_of_ringtone,rp); + return rp->ringstream != NULL ? 0 : 1; + } + return 3; +} + +bool_t linphone_ringtoneplayer_is_started(LinphoneRingtonePlayer* rp) { + return (rp->ringstream!=NULL); +} + +int linphone_ringtoneplayer_stop(LinphoneRingtonePlayer* rp) { + if (rp->ringstream) { + ring_stop(rp->ringstream); + rp->ringstream = NULL; + } + return 0; +} +#endif diff --git a/coreapi/ringtoneplayer.h b/coreapi/ringtoneplayer.h new file mode 100644 index 000000000..79255c5f5 --- /dev/null +++ b/coreapi/ringtoneplayer.h @@ -0,0 +1,40 @@ +/* +linphone +Copyright (C) 2000 - 2010 Simon MORLAT (simon.morlat@linphone.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#ifndef RINGPLAYER_H +#define RINGPLAYER_H + +typedef void (*LinphoneRingtonePlayerFunc)(LinphoneRingtonePlayer* rp, void* user_data, int status); + +LINPHONE_PUBLIC LinphoneRingtonePlayer* linphone_ringtoneplayer_new(); +LINPHONE_PUBLIC void linphone_ringtoneplayer_destroy(LinphoneRingtonePlayer* rp); + +LINPHONE_PUBLIC int linphone_ringtoneplayer_start(LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms); +/** + * Start a ringtone player + * @param rp LinphoneRingtonePlayer object + * @param card unused argument + * @param ringtone path to the ringtone to play + * @param loop_pause_ms pause interval in milliseconds to be observed between end of play and resuming at start. A value of -1 disables loop mode + * @return 0 if the player successfully started, positive error code otherwise + */ +LINPHONE_PUBLIC int linphone_ringtoneplayer_start_with_cb(LinphoneRingtonePlayer* rp, MSSndCard* card, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data); +LINPHONE_PUBLIC bool_t linphone_ringtoneplayer_is_started(LinphoneRingtonePlayer* rp); +LINPHONE_PUBLIC int linphone_ringtoneplayer_stop(LinphoneRingtonePlayer* rp); + +#endif diff --git a/coreapi/ringtoneplayer_ios.h b/coreapi/ringtoneplayer_ios.h new file mode 100644 index 000000000..2fb990f86 --- /dev/null +++ b/coreapi/ringtoneplayer_ios.h @@ -0,0 +1,27 @@ +/* +linphone +Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) +Copyright (C) 2010 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "linphonecore.h" + +LinphoneRingtonePlayer* linphone_ringtoneplayer_ios_new(); +void linphone_ringtoneplayer_ios_destroy(LinphoneRingtonePlayer* rp); +int linphone_ringtoneplayer_ios_start_with_cb(LinphoneRingtonePlayer* rp, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data); +bool_t linphone_ringtoneplayer_ios_is_started(LinphoneRingtonePlayer* rp); +int linphone_ringtoneplayer_ios_stop(LinphoneRingtonePlayer* rp); diff --git a/coreapi/ringtoneplayer_ios.m b/coreapi/ringtoneplayer_ios.m new file mode 100644 index 000000000..ad6bb15f4 --- /dev/null +++ b/coreapi/ringtoneplayer_ios.m @@ -0,0 +1,88 @@ +/* +linphone +Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) +Copyright (C) 2010 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "ringtoneplayer_ios.h" + +#import + +@interface AudioPlayerDelegate : NSObject +@property (assign) LinphoneRingtonePlayer* ringtonePlayer; +@end + +struct _LinphoneRingtonePlayer { + AVAudioPlayer* player; + AudioPlayerDelegate* playerDelegate; + LinphoneRingtonePlayerFunc end_of_ringtone; + void* end_of_ringtone_ud; +}; + +@implementation AudioPlayerDelegate +- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { + if (_ringtonePlayer->end_of_ringtone) { + _ringtonePlayer->end_of_ringtone(_ringtonePlayer, _ringtonePlayer->end_of_ringtone_ud, !flag); + } +} +- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error { + if (_ringtonePlayer->end_of_ringtone) { + _ringtonePlayer->end_of_ringtone(_ringtonePlayer, _ringtonePlayer->end_of_ringtone_ud, 1); + } +} +@end + + + +LinphoneRingtonePlayer* linphone_ringtoneplayer_ios_new() { + LinphoneRingtonePlayer* rp = ms_new0(LinphoneRingtonePlayer, 1); + rp->playerDelegate = [[AudioPlayerDelegate alloc] init]; + rp->playerDelegate.ringtonePlayer = rp; + return rp; +} + +void linphone_ringtoneplayer_ios_destroy(LinphoneRingtonePlayer* rp) { + linphone_ringtoneplayer_ios_stop(rp); + ms_free(rp); +} + +int linphone_ringtoneplayer_ios_start_with_cb(LinphoneRingtonePlayer* rp, const char* ringtone, int loop_pause_ms, LinphoneRingtonePlayerFunc end_of_ringtone, void * user_data) { + NSURL* url = [NSURL URLWithString:[NSString stringWithUTF8String:ringtone]]; + ms_message("%s: using ringtone %s", __FUNCTION__, ringtone); + if (rp->player) { + ms_warning("%s: a player is already instantiated, stopping it first.", __FUNCTION__); + linphone_ringtoneplayer_ios_stop(rp); + } + rp->player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; + [rp->player prepareToPlay]; + rp->player.numberOfLoops = (loop_pause_ms >= 0) ? -1 : 0; + rp->player.delegate = rp->playerDelegate; + rp->end_of_ringtone = end_of_ringtone; + rp->end_of_ringtone_ud = user_data; + return [rp->player play] ? 0 : 1; +} + +bool_t linphone_ringtoneplayer_ios_is_started(LinphoneRingtonePlayer* rp) { + return [rp->player isPlaying]; +} + +int linphone_ringtoneplayer_ios_stop(LinphoneRingtonePlayer* rp) { + [rp->player stop]; + [rp->player release]; + rp->player = nil; + return 0; +} diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index c876697cf..f122dc209 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -72,11 +72,6 @@ set(SOURCE_FILES videowindow.c ) -set(OBJC_FILES) -if (APPLE) - list(APPEND OBJC_FILES mac.m) -endif() - if(ENABLE_ASSISTANT) list(APPEND SOURCE_FILES setupwizard.c) endif() @@ -84,9 +79,13 @@ if(WIN32) list(APPEND SOURCE_FILES linphone.rc) endif() +set(OBJC_FILES) +if (APPLE) + list(APPEND OBJC_FILES mac.m) +endif() -apply_compile_flags(SOURCE_FILES "CPP" "C") apply_compile_flags(OBJC_FILES "CPP" "OBJC") +apply_compile_flags(SOURCE_FILES "CPP" "C") if(WIN32) add_executable(linphone-gtk WIN32 ${SOURCE_FILES}) diff --git a/gtk/main.c b/gtk/main.c index a1b7412db..f9f835d59 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -2179,12 +2179,11 @@ int main(int argc, char *argv[]){ core_start: if (linphone_gtk_init_instance(app_name, start_option, addr_to_call) == FALSE){ - g_warning("Another running instance of linphone has been detected. It has been woken-up."); + g_warning("Another running instance of Linphone has been detected. It has been woken-up."); g_warning("This instance is going to exit now."); gdk_threads_leave(); return 0; } - the_ui=linphone_gtk_create_window("main", NULL); g_object_set_data(G_OBJECT(the_ui),"is_created",GINT_TO_POINTER(FALSE)); diff --git a/mediastreamer2 b/mediastreamer2 index 853609fcd..152049a8b 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 853609fcd048843752c244f1f335a9a664c2db93 +Subproject commit 152049a8be35a38844e29690c4ccce74229ae240