Commit 2718f631 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix crash in linphone_core_reload_sound_devices() and linphone_core_reload_video_devices().

parent 9133e161
......@@ -4625,23 +4625,53 @@ const char** linphone_core_get_video_devices(const LinphoneCore *lc){
}
void linphone_core_reload_sound_devices(LinphoneCore *lc){
const char *ringer,*playback,*capture;
ringer=linphone_core_get_ringer_device(lc);
playback=linphone_core_get_playback_device(lc);
capture=linphone_core_get_capture_device(lc);
const char *ringer;
const char *playback;
const char *capture;
char *ringer_copy = NULL;
char *playback_copy = NULL;
char *capture_copy = NULL;
ringer = linphone_core_get_ringer_device(lc);
if (ringer != NULL) {
ringer_copy = ms_strdup(ringer);
}
playback = linphone_core_get_playback_device(lc);
if (playback != NULL) {
playback_copy = ms_strdup(playback);
}
capture = linphone_core_get_capture_device(lc);
if (capture != NULL) {
capture_copy = ms_strdup(capture);
}
ms_snd_card_manager_reload(ms_snd_card_manager_get());
build_sound_devices_table(lc);
linphone_core_set_ringer_device(lc,ringer);
linphone_core_set_playback_device(lc,playback);
linphone_core_set_capture_device(lc,capture);
if (ringer_copy != NULL) {
linphone_core_set_ringer_device(lc, ringer_copy);
ms_free(ringer_copy);
}
if (playback_copy != NULL) {
linphone_core_set_playback_device(lc, playback_copy);
ms_free(playback_copy);
}
if (capture_copy != NULL) {
linphone_core_set_capture_device(lc, capture_copy);
ms_free(capture_copy);
}
}
void linphone_core_reload_video_devices(LinphoneCore *lc){
const char *devid;
devid=linphone_core_get_video_device(lc);
char *devid_copy = NULL;
const char *devid = linphone_core_get_video_device(lc);
if (devid != NULL) {
devid_copy = ms_strdup(devid);
}
ms_web_cam_manager_reload(ms_web_cam_manager_get());
build_video_devices_table(lc);
linphone_core_set_video_device(lc,devid);
if (devid_copy != NULL) {
linphone_core_set_video_device(lc, devid_copy);
ms_free(devid_copy);
}
}
char linphone_core_get_sound_source(LinphoneCore *lc)
......
......@@ -244,6 +244,28 @@ static void chat_root_test(void) {
linphone_core_destroy(lc);
}
static void devices_reload_test(void) {
char *devid1;
char *devid2;
LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE);
devid1 = ms_strdup(linphone_core_get_capture_device(mgr->lc));
linphone_core_reload_sound_devices(mgr->lc);
devid2 = ms_strdup(linphone_core_get_capture_device(mgr->lc));
CU_ASSERT_STRING_EQUAL(devid1, devid2);
ms_free(devid1);
ms_free(devid2);
devid1 = ms_strdup(linphone_core_get_video_device(mgr->lc));
linphone_core_reload_video_devices(mgr->lc);
devid2 = ms_strdup(linphone_core_get_video_device(mgr->lc));
CU_ASSERT_STRING_EQUAL(devid1, devid2);
ms_free(devid1);
ms_free(devid2);
linphone_core_manager_destroy(mgr);
}
test_t setup_tests[] = {
{ "Version check", linphone_version_test },
{ "Linphone Address", linphone_address_test },
......@@ -256,7 +278,8 @@ test_t setup_tests[] = {
{ "LPConfig zero_len value from buffer", linphone_lpconfig_from_buffer_zerolen_value },
{ "LPConfig zero_len value from file", linphone_lpconfig_from_file_zerolen_value },
{ "LPConfig zero_len value from XML", linphone_lpconfig_from_xml_zerolen_value },
{ "Chat room", chat_root_test }
{ "Chat room", chat_root_test },
{ "Devices reload", devices_reload_test }
};
test_suite_t setup_test_suite = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment