diff --git a/coreapi/factory.c b/coreapi/factory.c index 27e30e984..5a71af63c 100644 --- a/coreapi/factory.c +++ b/coreapi/factory.c @@ -94,7 +94,7 @@ static void _linphone_factory_destroying_cb(void) { #define ADD_SUPPORTED_VIDEO_DEFINITION(factory, width, height, name) \ (factory)->supported_video_definitions = bctbx_list_append((factory)->supported_video_definitions, \ - linphone_video_definition_ref(linphone_video_definition_new(width, height, name))) + linphone_video_definition_new(width, height, name)) static void initialize_supported_video_definitions(LinphoneFactory *factory) { #if !defined(__ANDROID__) && !TARGET_OS_IPHONE @@ -179,7 +179,8 @@ LinphoneVcard *linphone_factory_create_vcard(LinphoneFactory *factory) { } LinphoneVideoDefinition * linphone_factory_create_video_definition(const LinphoneFactory *factory, unsigned int width, unsigned int height) { - return linphone_video_definition_ref(linphone_video_definition_new(width, height, NULL)); + LinphoneVideoDefinition *supported = linphone_factory_find_supported_video_definition(factory, width, height); + return supported ? linphone_video_definition_clone(supported) : linphone_video_definition_new(width, height, NULL); } LinphoneVideoDefinition * linphone_factory_create_video_definition_from_name(const LinphoneFactory *factory, const char *name) { @@ -201,16 +202,17 @@ LinphoneVideoDefinition * linphone_factory_find_supported_video_definition(const const bctbx_list_t *item; const bctbx_list_t *supported = linphone_factory_get_supported_video_definitions(factory); LinphoneVideoDefinition *searched_vdef = linphone_video_definition_new(width, height, NULL); + LinphoneVideoDefinition *found = NULL; for (item = supported; item != NULL; item = bctbx_list_next(item)) { LinphoneVideoDefinition *svdef = (LinphoneVideoDefinition *)bctbx_list_get_data(item); if (linphone_video_definition_equals(svdef, searched_vdef)) { - linphone_video_definition_unref(searched_vdef); - return linphone_video_definition_clone(svdef); + found = svdef; + break; } } - - return searched_vdef; + linphone_video_definition_unref(searched_vdef); + return found; } LinphoneVideoDefinition * linphone_factory_find_supported_video_definition_by_name(const LinphoneFactory *factory, const char *name) { @@ -220,7 +222,7 @@ LinphoneVideoDefinition * linphone_factory_find_supported_video_definition_by_na for (item = supported; item != NULL; item = bctbx_list_next(item)) { LinphoneVideoDefinition *svdef = (LinphoneVideoDefinition *)bctbx_list_get_data(item); if (strcmp(linphone_video_definition_get_name(svdef), name) == 0) { - return linphone_video_definition_clone(svdef); + return svdef; } } return NULL; diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 54ccc7640..78f0e69c5 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -2067,10 +2067,10 @@ const LinphoneCallParams * linphone_call_get_current_params(LinphoneCall *call){ if (vstream != NULL) { call->current_params->sent_vsize = video_stream_get_sent_video_size(vstream); call->current_params->recv_vsize = video_stream_get_received_video_size(vstream); - call->current_params->sent_vdef = linphone_video_definition_ref(linphone_factory_find_supported_video_definition( - linphone_factory_get(), call->current_params->sent_vsize.width, call->current_params->sent_vsize.height)); - call->current_params->recv_vdef = linphone_video_definition_ref(linphone_factory_find_supported_video_definition( - linphone_factory_get(), call->current_params->recv_vsize.width, call->current_params->recv_vsize.height)); + call->current_params->sent_vdef = linphone_factory_create_video_definition( + linphone_factory_get(), call->current_params->sent_vsize.width, call->current_params->sent_vsize.height); + call->current_params->recv_vdef = linphone_factory_create_video_definition( + linphone_factory_get(), call->current_params->recv_vsize.width, call->current_params->recv_vsize.height); call->current_params->sent_fps = video_stream_get_sent_framerate(vstream); call->current_params->received_fps = video_stream_get_received_framerate(vstream); } diff --git a/coreapi/video_definition.c b/coreapi/video_definition.c index d193d0363..717fdfd73 100644 --- a/coreapi/video_definition.c +++ b/coreapi/video_definition.c @@ -27,13 +27,23 @@ static void linphone_video_definition_destroy(LinphoneVideoDefinition *vdef) { if (vdef->name) bctbx_free(vdef->name); } +static void _linphone_video_definition_clone(LinphoneVideoDefinition *obj, const LinphoneVideoDefinition *orig){ + obj->name = bctbx_strdup(orig->name); + obj->width = orig->width; + obj->height = orig->height; +} + +belle_sip_error_code _linphone_video_definition_marshal(const LinphoneVideoDefinition* obj, char* buff, size_t buff_size, size_t *offset){ + return belle_sip_snprintf(buff,buff_size,offset,"%s",obj->name); +} + BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneVideoDefinition); BELLE_SIP_INSTANCIATE_VPTR(LinphoneVideoDefinition, belle_sip_object_t, (belle_sip_object_destroy_t)linphone_video_definition_destroy, - NULL, // clone - NULL, // marshal - TRUE + (belle_sip_object_clone_t)_linphone_video_definition_clone, // clone + (belle_sip_object_marshal_t)_linphone_video_definition_marshal, // marshal + FALSE ); @@ -67,7 +77,7 @@ void linphone_video_definition_set_user_data(LinphoneVideoDefinition *vdef, void } LinphoneVideoDefinition * linphone_video_definition_clone(const LinphoneVideoDefinition *vdef) { - return linphone_video_definition_new(linphone_video_definition_get_width(vdef), linphone_video_definition_get_height(vdef), linphone_video_definition_get_name(vdef)); + return (LinphoneVideoDefinition*)belle_sip_object_clone((belle_sip_object_t*)vdef); } unsigned int linphone_video_definition_get_width(const LinphoneVideoDefinition *vdef) {