Revise testsuite log prints and fix glib assertion related to g_variant_unref() 28/245928/2 accepted/tizen/unified/20201029.124853 submit/tizen/20201028.023739
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 20 Oct 2020 04:03:04 +0000 (13:03 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 20 Oct 2020 05:22:23 +0000 (14:22 +0900)
[Version] 0.6.29
[Issue Type] Revise

Change-Id: I7cfec3533c51eade741c7f95138b66b56a1a05ed

packaging/capi-media-sound-manager.spec
src/sound_manager_private.c
test/sound_manager_test.c

index 5fc5142ffa1dbcb87319d4a550867647c5ab5a74..67a949cf68ce89fda3fb68d6a4ffb8f39186143c 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.6.28
+Version:    0.6.29
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index d333def2bd1bd15df3a021a8041c4aab83d8644f..48988c5c915568c4d8d0f2b2fac28cdf2e89b3f7 100644 (file)
@@ -1108,7 +1108,8 @@ int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info)
        }
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1184,7 +1185,8 @@ int _set_manual_route_info(unsigned int index, manual_route_info_s *info)
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        if (builder_for_in_devices)
                g_variant_builder_unref(builder_for_in_devices);
        if (builder_for_out_devices)
@@ -1239,7 +1241,8 @@ int _set_route_option(unsigned int index, const char *name, int value)
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1292,7 +1295,8 @@ int _get_volume_max_level(const char *direction, const char *volume_type, unsign
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1343,7 +1347,8 @@ int _get_volume_level(const char *direction, const char *volume_type, unsigned i
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1398,7 +1403,8 @@ int _set_volume_level(const char *direction, const char *volume_type, unsigned i
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1456,7 +1462,8 @@ int _get_current_volume_type(const char *direction, char **volume_type)
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1513,7 +1520,8 @@ int _get_current_media_routing_path(const char *direction, sound_device_type_e *
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1554,7 +1562,8 @@ void _update_focus_status(unsigned int index, unsigned int acquired_focus_status
                LOGE("failed to UPDATE_FOCUS_STATUS error (%s)", dbus_ret);//LCOV_EXCL_LINE
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 }
 
@@ -1595,7 +1604,8 @@ int _is_device_running_by_id(int device_id, bool *is_running)
        }
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1673,8 +1683,10 @@ int _get_supported_sample_formats(int device_id, sound_sample_format_e **formats
        LOGI("num[%d]", *num);
 
 LEAVE:
-       g_variant_iter_free(iter);
-       g_variant_unref(result);
+       if (iter)
+               g_variant_iter_free(iter);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1751,9 +1763,9 @@ int _get_sample_format(int device_id, sound_sample_format_e *format)
        if ((ret = _convert_sample_format_str_to_enum((const char *)format_str, &format_e)) == SOUND_MANAGER_ERROR_NONE)
                *format = format_e;
 
-       g_variant_unref(result);
-
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1831,8 +1843,10 @@ int _get_supported_sample_rates(int device_id, sound_sample_rate_e **rates, unsi
        LOGI("num[%d]", *num);
 
 LEAVE:
-       g_variant_iter_free(iter);
-       g_variant_unref(result);
+       if (iter)
+               g_variant_iter_free(iter);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1909,9 +1923,9 @@ int _get_sample_rate(int device_id, sound_sample_rate_e *rate)
        if ((ret = _convert_sample_rate_to_enum(_rate, &rate_e)) == SOUND_MANAGER_ERROR_NONE)
                *rate = rate_e;
 
-       g_variant_unref(result);
-
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -1982,11 +1996,12 @@ int _get_avoid_resampling(int device_id, bool *enabled)
 
        g_variant_get(result, "(b)", &_enabled);
        *enabled = (bool)_enabled;
-       g_variant_unref(result);
 
        LOGI("enabled[%d]", *enabled);
 
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -2067,11 +2082,11 @@ int _get_media_stream_only(int device_id, bool *enabled)
        else
                *enabled = false;
 
-       g_variant_unref(result);
-
        LOGI("enabled[%d]", *enabled);
 
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -2208,8 +2223,6 @@ void _destroy_pa_connection(sound_pa_info_s *pa_info)
                pa_threaded_mainloop_free(pa_info->mainloop);
                pa_info->mainloop = NULL;
        }
-
-       return;
 }
 
 int _destroy_pa_connection_and_unregister_focus(sound_stream_info_s *stream_h)
@@ -3064,7 +3077,8 @@ int _set_volume_ratio(uint32_t stream_index, sound_stream_direction_e direction,
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3130,7 +3144,8 @@ int _set_acm_master_mode(bool on)
        }
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3176,7 +3191,8 @@ int _activate_ducking(uint32_t stream_index, bool enable, const char *target_str
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3233,7 +3249,8 @@ int _get_ducking_state(sound_pa_info_s *pa_info, bool *is_ducked)
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3280,8 +3297,6 @@ static int __invoke_ipc_set_preferred_device_id(sound_stream_info_s *stream_info
                        ret = _convert_sound_manager_error_code(__func__, _convert_dbus_error(err ? err->message : NULL));
                        if (err)
                                g_error_free(err);
-                       if (result)
-                               g_variant_unref(result);
                        goto LEAVE;
                }
 
@@ -3298,7 +3313,6 @@ static int __invoke_ipc_set_preferred_device_id(sound_stream_info_s *stream_info
 
                LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
-               g_variant_unref(result);
                if (ret)
                        goto LEAVE;
 
@@ -3309,7 +3323,10 @@ static int __invoke_ipc_set_preferred_device_id(sound_stream_info_s *stream_info
        }
 
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
+
        return ret;
 }
 
@@ -3454,7 +3471,8 @@ int _get_preferred_device(sound_stream_info_s *stream_info, int *in_device_id, i
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3499,8 +3517,10 @@ static int __invoke_ipc_set_preemptive_device(sound_stream_type_e stream_type, s
                        ret = _convert_sound_manager_error_code(__func__, _convert_dbus_error(err ? err->message : NULL));
                        if (err)
                                g_error_free(err);
-                       if (result)
+                       if (result) {
                                g_variant_unref(result);
+                               result = NULL;
+                       }
                        continue;
                }
 
@@ -3517,13 +3537,15 @@ static int __invoke_ipc_set_preemptive_device(sound_stream_type_e stream_type, s
 
                LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
-               g_variant_unref(result);
                if (ret)
                        goto LEAVE;
        }
 
 LEAVE:
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
+
        return ret;
 }
 
@@ -3580,7 +3602,8 @@ static int __invoke_ipc_get_preemptive_device(sound_stream_type_e stream_type, i
        LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret);
 
 LEAVE:
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
@@ -3664,7 +3687,8 @@ int _get_latest_stream_pid(int stream_type, unsigned int *pid)
 LEAVE:
        if (builder_for_stream_types)
                g_variant_builder_unref(builder_for_stream_types);
-       g_variant_unref(result);
+       if (result)
+               g_variant_unref(result);
        g_object_unref(conn);
 
        return ret;
index 5035e99d91606f3b0eb1975d56f2d1e1ca722425..f831237a0361c0544ad56bdf3b51eb130c794111 100644 (file)
@@ -137,7 +137,6 @@ int g_device_state_cb_id;
 int g_device_running_cb_id;
 
 static const char *g_device_direction_str[] = {"IN", "OUT", "BOTH"};
-static const char *g_device_state_str[] = {"De-Activated", "Activated"};
 static const char *g_device_type_str[] = {"builtin-speaker", "builtin-receiver", "builtin-mic",
                                                        "audio-jack", "bt-media", "hdmi",
                                                        "forwarding", "usb-audio", "bt-voice",
@@ -450,8 +449,8 @@ void display_sub_basic()
        g_print("sms. Set Media Stream Only\n");
        g_print("gar. Get Avoid Resampling\t");
        g_print("gms. Get Media Stream Only\n");
-       g_print("adcc. Add Device Connenection Changed CB\t\t");
-       g_print("rdcc. Remove Device Connenection Changed CB\n");
+       g_print("adcc. Add Device Connection Changed CB\t\t");
+       g_print("rdcc. Remove Device Connection Changed CB\n");
        g_print("adrc. Add Device Running Changed CB\t\t");
        g_print("rdrc. Remove Device Running Changed CB\n");
        g_print("-----------------------------------------------------------------------------------------\n");
@@ -570,7 +569,7 @@ static void displaymenu()
        else if (g_menu_state == CURRENT_STATUS_SET_SAMPLE_RATE)
                g_print("*** input sample rate (0:8kHz, 1:16KHz, 2:22.05kHz, 3:44.1kHz, 4:48kHz, 5:88.2kHz, 6:96kHz, 7:192kHz)\n");
        else if (g_menu_state == CURRENT_STATUS_GET_SAMPLE_RATE)
-               g_print("*** press enter to get sample ratet\n");
+               g_print("*** press enter to get sample rate\n");
        else if (g_menu_state == CURRENT_STATUS_SET_AVOID_RESAMPLING)
                g_print("*** input avoid resampling (0:disable, 1:enable)\n");
        else if (g_menu_state == CURRENT_STATUS_GET_AVOID_RESAMPLING)
@@ -775,7 +774,7 @@ void _volume_changed_cb_internal(sound_type_internal_e type, unsigned int volume
 
 /* If failed to get some property, just give some default value */
 void _get_device_props_simple(sound_device_h device, int *id, const char **type, char **name,
-               const char **direction, const char **state, int *vendor_id, int *product_id, bool *is_running)
+               const char **direction, bool *is_activated, int *vendor_id, int *product_id, bool *is_running)
 {
        int ret;
        sound_device_type_e _type;
@@ -784,8 +783,8 @@ void _get_device_props_simple(sound_device_h device, int *id, const char **type,
        bool running;
 
        *id = -1;
-       *vendor_id = -1;
-       *product_id = -1;
+       *vendor_id = 0;
+       *product_id = 0;
 
        if ((ret = sound_manager_get_device_type(device, &_type)))
                g_print("failed to get device type, ret[0x%x]\n",  ret);
@@ -795,19 +794,16 @@ void _get_device_props_simple(sound_device_h device, int *id, const char **type,
        if ((ret = sound_manager_get_device_id(device, id)))
                g_print("failed to get device id, ret[0x%x]\n", ret);
 
-       if (_type == SOUND_DEVICE_BLUETOOTH_MEDIA || _type == SOUND_DEVICE_BLUETOOTH_VOICE || _type == SOUND_DEVICE_USB_AUDIO) {
-               if ((ret = sound_manager_get_device_name(device, name))) {
-                       g_print("failed to get device name, ret[0x%x]\n", ret);
-                       *name = NOT_AVAIL;
-               }
-               if (_type == SOUND_DEVICE_USB_AUDIO) {
-                       if ((ret = sound_manager_get_device_vendor_id(device, vendor_id)))
-                               g_print("failed to get device vendor id, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_product_id(device, product_id)))
-                               g_print("failed to get device product id, ret[0x%x]\n", ret);
-               }
-       } else {
-               *name = "";
+       if ((ret = sound_manager_get_device_name(device, name))) {
+               g_print("failed to get device name, ret[0x%x]\n", ret);
+               *name = NOT_AVAIL;
+       }
+
+       if (_type == SOUND_DEVICE_USB_AUDIO) {
+               if ((ret = sound_manager_get_device_vendor_id(device, vendor_id)))
+                       g_print("failed to get device vendor id, ret[0x%x]\n", ret);
+               if ((ret = sound_manager_get_device_product_id(device, product_id)))
+                       g_print("failed to get device product id, ret[0x%x]\n", ret);
        }
 
        if ((ret = sound_manager_get_device_io_direction(device, &_direc))) {
@@ -819,9 +815,9 @@ void _get_device_props_simple(sound_device_h device, int *id, const char **type,
 
        if ((ret = sound_manager_get_device_state(device, &_state))) {
                g_print("failed to get device state, ret[0x%x]\n", ret);
-               *state = NOT_AVAIL;
+               *is_activated = false;
        } else {
-               *state = g_device_state_str[_state];
+               *is_activated = (bool)_state;
        }
 
        if ((ret = sound_manager_is_device_running(device, &running))) {
@@ -835,33 +831,35 @@ void _get_device_props_simple(sound_device_h device, int *id, const char **type,
 void _device_connected_cb(sound_device_h device, bool is_connected, void *user_data)
 {
        int id = -1;
-       int vendor_id = -1;
-       int product_id = -1;
+       int vendor_id = 0;
+       int product_id = 0;
        char *name;
-       const char *type, *direction, *state;
+       const char *type, *direction;
+       bool is_activated = false;
        bool is_running = false;
 
-       _get_device_props_simple(device, &id, &type, &name, &direction, &state, &vendor_id, &product_id, &is_running);
+       _get_device_props_simple(device, &id, &type, &name, &direction, &is_activated, &vendor_id, &product_id, &is_running);
 
-       g_print("\n[ Device #%d %20s %s ] %15s : ", id, type, name, is_connected ? "Connected" : "Disconnected");
-       g_print("    Direction[ %-4s ] State[ %-12s ] Running[ %d ] VendorID[ %04x ], ProductID[ %04x ]\n",
-            direction, state, is_running, vendor_id, product_id);
+       g_print("\n[ Device #%d %-20s ] %15s : ", id, type, is_connected ? "Connected" : "Disconnected");
+       g_print("Direction[%-4s] Activated[%d] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
+            direction, is_activated, is_running, vendor_id, product_id, name);
 }
 
 void _device_running_changed_cb(sound_device_h device, bool is_running, void *user_data)
 {
        int id = -1;
-       int vendor_id = -1;
-       int product_id = -1;
+       int vendor_id = 0;
+       int product_id = 0;
        char *name;
-       const char *type, *direction, *state;
+       const char *type, *direction;
+       bool is_activated = false;
        bool _is_running = false;
 
-       _get_device_props_simple(device, &id, &type, &name, &direction, &state, &vendor_id, &product_id, &_is_running);
+       _get_device_props_simple(device, &id, &type, &name, &direction, &is_activated, &vendor_id, &product_id, &_is_running);
 
-       g_print("\n[ Device #%d %20s %s ] running changed to [ %d ] : ", id, type, name, is_running);
-       g_print("    Direction[ %-4s ] State[ %-12s ] Running[ %d ] VendorID[ %04x ], ProductID[ %04x ]\n",
-            direction, state, _is_running, vendor_id, product_id);
+       g_print("\n[ Device #%d %-20s ] running changed to [%d] : ", id, type, is_running);
+       g_print("Direction [%-4s] Activated[%d] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
+            direction, is_activated, _is_running, vendor_id, product_id, name);
 }
 
 void reset_menu_state(void)
@@ -880,7 +878,7 @@ static void interpret(char *cmd)
                int max;
                if (convert_sound_type(&type, cmd) == 1) {
                        if (sound_manager_get_max_volume(type, &max) != SOUND_MANAGER_ERROR_NONE)
-                               g_print("failt to get max volume\n");
+                               g_print("fail to get max volume\n");
                        else
                                g_print("the max volume of this type(%d) is %d\n", type, max);
                }
@@ -938,7 +936,7 @@ static void interpret(char *cmd)
                int max;
                if (convert_sound_type_internal(&type, cmd) == 1) {
                        if (sound_manager_get_max_volume_internal(type, &max) != SOUND_MANAGER_ERROR_NONE)
-                               g_print("failt to get max volume\n");
+                               g_print("fail to get max volume\n");
                        else
                                g_print("the max volume of this type(%d) is %d\n", type, max);
                }
@@ -1133,12 +1131,12 @@ static void interpret(char *cmd)
                sound_device_h device;
                int ret = SOUND_MANAGER_ERROR_NONE;
                int id = -1;
-               int vendor_id = -1;
-               int product_id = -1;
+               int vendor_id = 0;
+               int product_id = 0;
                char *name;
                const char *type;
                const char *direction;
-               const char *state;
+               bool is_activated;
                bool is_running;
                unsigned int num;
                sound_sample_format_e *formats;
@@ -1147,21 +1145,23 @@ static void interpret(char *cmd)
                if (!(ret = sound_manager_get_device_list(g_device_mask, &device_list))) {
                        g_print("success to get current device list\n");
                        while (!sound_manager_get_next_device(device_list, &device)) {
-                               _get_device_props_simple(device, &id, &type, &name, &direction, &state, &vendor_id, &product_id, &is_running);
-                               g_print("[ Device #%d %20s %s ] : ", id, type, name);
-                               g_print("    Direction[ %-4s ] State[ %-12s ] Running[ %d ] VendorID[ %04x ] ProductID[ %04x ]\n",
-                                       direction, state, is_running, vendor_id, product_id);
+                               _get_device_props_simple(device, &id, &type, &name, &direction, &is_activated, &vendor_id, &product_id, &is_running);
+                               g_print("[ Device #%d %-20s ] : ", id, type);
+                               g_print("Direction[%-4s] Activated[%d] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s] \n",
+                                               direction, is_activated, is_running, vendor_id, product_id, name);
 
                                if (!(ret = sound_manager_get_supported_sample_formats(device, &formats, &num))) {
+                                       g_print(" => [ ");
                                        while (num--)
                                                g_print("format(%u) ", formats[num]);
-                                       g_print("are supported.\n");
+                                       g_print("] is(are) supported.\n");
                                        free(formats);
                                }
                                if (!(ret = sound_manager_get_supported_sample_rates(device, &rates, &num))) {
+                                       g_print(" => [ ");
                                        while (num--)
                                                g_print("rate(%u) ", rates[num]);
-                                       g_print("are supported.\n");
+                                       g_print("] is(are) supported.\n");
                                        free(rates);
                                }
                        }