}
static dm_device_class_t device_string_get_class(const char *device_string) {
- if (!device_string) {
+ if (!device_string)
return DM_DEVICE_CLASS_NONE;
- }
- if (device_string == strstr(device_string, "alsa")) {
+ if (device_string == strstr(device_string, "alsa"))
return DM_DEVICE_CLASS_ALSA;
- } else if (device_string == strstr(device_string, "null")) {
+ else if (device_string == strstr(device_string, "null"))
return DM_DEVICE_CLASS_NULL;
- } else if (device_string == strstr(device_string, "tizen")) {
+ else if (device_string == strstr(device_string, "tizen"))
return DM_DEVICE_CLASS_TIZEN;
- } else if (device_string == strstr(device_string, "acm")) {
+ else if (device_string == strstr(device_string, "acm"))
return DM_DEVICE_CLASS_ACM;
- } else {
- return DM_DEVICE_CLASS_NONE;
- }
+
+ return DM_DEVICE_CLASS_NONE;
}
/* device_string looks like "alsa:0,0" or "tizen:0,0"
}
static pa_proplist* pulse_device_get_proplist(pa_object *pdevice) {
- if (pa_sink_isinstance(pdevice))
- return PA_SINK(pdevice)->proplist;
- else
- return PA_SOURCE(pdevice)->proplist;
+ if (!pdevice)
+ return NULL;
+
+ return pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->proplist :
+ PA_SOURCE(pdevice)->proplist;
}
static bool pulse_device_is_alsa(pa_object *pdevice) {
const char *api_name = NULL;
- pa_proplist *prop;
+ pa_proplist *prop = pulse_device_get_proplist(pdevice);
- if ((prop = pulse_device_get_proplist(pdevice)) == NULL)
+ if (!prop)
return false;
- if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) {
- if (pa_safe_streq(api_name, DEVICE_API_ALSA)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
+ if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API)))
+ return pa_safe_streq(api_name, DEVICE_API_ALSA);
+
+ return false;
}
static bool pulse_device_is_bluez(pa_object *pdevice) {
const char *api_name = NULL;
- pa_proplist *prop;
+ pa_proplist *prop = pulse_device_get_proplist(pdevice);
- if ((prop = pulse_device_get_proplist(pdevice)) == NULL)
+ if (!prop)
return false;
- if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API))) {
- if (pa_safe_streq(api_name, DEVICE_API_BLUEZ)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
+ if ((api_name = pa_proplist_gets(prop, PA_PROP_DEVICE_API)))
+ return pa_safe_streq(api_name, DEVICE_API_BLUEZ);
+
+ return false;
}
static bool pulse_device_is_acm(pa_object *pdevice) {
static bool pulse_device_is_usb(pa_object *pdevice) {
const char *bus_name = NULL;
- pa_proplist *prop;
+ pa_proplist *prop = pulse_device_get_proplist(pdevice);
- if ((prop = pulse_device_get_proplist(pdevice)) == NULL)
+ if (!prop)
return false;
- if ((bus_name = pa_proplist_gets(prop, PA_PROP_DEVICE_BUS))) {
- if (pa_safe_streq(bus_name, DEVICE_BUS_USB)) {
- return true;
- } else {
- return false;
- }
- } else {
- pa_log_debug("This device doesn't have property '%s'", PA_PROP_DEVICE_BUS);
- return false;
- }
+ if ((bus_name = pa_proplist_gets(prop, PA_PROP_DEVICE_BUS)))
+ return pa_safe_streq(bus_name, DEVICE_BUS_USB);
+
+ pa_log_debug("This device doesn't have property '%s'", PA_PROP_DEVICE_BUS);
+ return false;
}
static bool pulse_device_is_null(pa_object *pdevice) {
- pa_sink *sink;
- pa_source *source;
-
if (!pdevice)
return false;
- if (pa_sink_isinstance(pdevice)) {
- sink = PA_SINK(pdevice);
- return pa_safe_streq(sink->module->name, "module-null-sink");
- } else {
- source = PA_SOURCE(pdevice);
- return pa_safe_streq(source->module->name, "module-null-source");
- }
+ if (pa_sink_isinstance(pdevice))
+ return pa_safe_streq(PA_SINK(pdevice)->module->name, "module-null-sink");
+ else
+ return pa_safe_streq(PA_SOURCE(pdevice)->module->name, "module-null-source");
}
static bool pulse_device_is_rtsp(pa_object *pdevice) {
const char *params_p, *params;
char *end_p = NULL;
int len = 0, prev_len = 0;
- pa_sink *sink;
- pa_source *source;
- if (pa_sink_isinstance(pdevice)) {
- sink = PA_SINK(pdevice);
- params = sink->module->argument;
- } else {
- source = PA_SOURCE(pdevice);
- params = source->module->argument;
- }
+ params = pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->module->argument :
+ PA_SOURCE(pdevice)->module->argument;
params_p = params;
- if (!params) {
+ if (!params)
return NULL;
- }
- if (!(device_string_p = strstr(params, "device="))) {
+
+ if (!(device_string_p = strstr(params, "device=")))
return params;
- }
next_p = device_string_p;
- while (!isblank(*next_p)) {
+ while (!isblank(*next_p))
next_p++;
- }
- while (isblank(*next_p)) {
+
+ while (isblank(*next_p))
next_p++;
- }
pa_strlcpy(removed_param, next_p, DEVICE_PARAM_STRING_MAX);
return DM_DEVICE_CLASS_NONE;
}
- if (pulse_device_is_null(pdevice)) {
+ if (pulse_device_is_null(pdevice))
return DM_DEVICE_CLASS_NULL;
- } else if (pulse_device_is_alsa(pdevice)) {
+ else if (pulse_device_is_alsa(pdevice))
return DM_DEVICE_CLASS_ALSA;
- } else if (pulse_device_is_tizenaudio(pdevice)) {
+ else if (pulse_device_is_tizenaudio(pdevice))
return DM_DEVICE_CLASS_TIZEN;
- } else if (pulse_device_is_bluez(pdevice)) {
+ else if (pulse_device_is_bluez(pdevice))
return DM_DEVICE_CLASS_BT;
- } else if (pulse_device_is_acm(pdevice)) {
+ else if (pulse_device_is_acm(pdevice))
return DM_DEVICE_CLASS_ACM;
- } else {
- return DM_DEVICE_CLASS_NONE;
- }
+
+ return DM_DEVICE_CLASS_NONE;
}
static dm_device_direction_t pulse_device_get_direction(pa_object *pdevice) {
- if (pa_sink_isinstance(pdevice))
- return DM_DEVICE_DIRECTION_OUT;
- else
- return DM_DEVICE_DIRECTION_IN;
+ return pa_sink_isinstance(pdevice) ? DM_DEVICE_DIRECTION_OUT : DM_DEVICE_DIRECTION_IN;
}
static bool pulse_device_is_monitor(pa_object *pdevice) {
const char *device_class = NULL;
- pa_proplist *prop;
+ pa_proplist *prop = pulse_device_get_proplist(pdevice);
- prop = pulse_device_get_proplist(pdevice);
+ if (!prop)
+ return false;
- if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS))) {
- if (pa_safe_streq(device_class, DEVICE_CLASS_MONITOR))
- return true;
- }
+ if ((device_class = pa_proplist_gets(prop, PA_PROP_DEVICE_CLASS)))
+ return pa_safe_streq(device_class, DEVICE_CLASS_MONITOR);
return false;
}
pa_assert(file_infos);
PA_IDXSET_FOREACH(file_info, file_infos, file_idx) {
- if (pa_safe_streq(file_info->device_string, device_string)) {
+ if (pa_safe_streq(file_info->device_string, device_string))
return file_info;
- }
}
return NULL;
static void _device_status_free(struct device_status_info *status_info) {
if (!status_info)
- return ;
+ return;
pa_xfree(status_info->type);
pa_xfree(status_info->name);
pa_assert(type);
if (!device_type_is_need_detect(type))
- return ;
+ return;
pa_log_info("Set device detected, type(%s) system_id(%s) -> %s(%d)",
type, pa_strempty(system_id),
pa_assert(manager->device_list);
PA_IDXSET_FOREACH(device, manager->device_list, idx) {
- if (pa_tz_device_get_id(device) == id) {
+ if (pa_tz_device_get_id(device) == id)
return device;
- }
}
+
return NULL;
}
static bool pulse_device_params_is_equal(pa_object *pdevice, const char *params) {
const char *removed_module_args;
const char *module_args;
- pa_sink *sink;
- pa_source *source;
pa_assert(pdevice);
- if (pa_sink_isinstance(pdevice)) {
- sink = PA_SINK(pdevice);
- module_args = sink->module->argument;
- } else {
- source = PA_SOURCE(pdevice);
- module_args = source->module->argument;
- }
+ module_args = pa_sink_isinstance(pdevice) ? PA_SINK(pdevice)->module->argument :
+ PA_SOURCE(pdevice)->module->argument;
if (!params && !module_args)
return 0;
return -1;
removed_module_args = pulse_device_get_device_string_removed_argument(pdevice);
+
return device_params_is_equal(params, removed_module_args);
}
static void pulse_device_set_use_internal_codec(pa_object *pdevice, bool use_internal_codec) {
pa_assert(pdevice);
- if (pa_sink_isinstance(pdevice)) {
- pa_sink *sink = PA_SINK(pdevice);
- sink->use_internal_codec = use_internal_codec;
- } else {
- pa_source *source = PA_SOURCE(pdevice);
- source->use_internal_codec = use_internal_codec;
- }
+ if (pa_sink_isinstance(pdevice))
+ PA_SINK(pdevice)->use_internal_codec = use_internal_codec;
+ else
+ PA_SOURCE(pdevice)->use_internal_codec = use_internal_codec;
}
/* Get system_id of physical device, it should be a unique id */
pa_proplist *prop;
prop = pulse_device_get_proplist(pdevice);
+
if (pulse_device_is_usb(pdevice))
return pa_proplist_gets(prop, "sysfs.path");
else if (pulse_device_is_bluez(pdevice))
else if (pulse_device_is_btsco(pdevice))
return pa_proplist_gets(prop, PA_PROP_DEVICE_DESCRIPTION);
#endif
- else
- return NULL;
+
+ return NULL;
}
static pa_sink* _core_get_sink(pa_core *core, const char *device_string, const char *params) {
PA_IDXSET_FOREACH(sink, core->sinks, device_idx) {
if (pulse_device_is_monitor(PA_OBJECT(sink)))
continue;
- if (pulse_device_same_device_string(PA_OBJECT(sink), device_string)) {
- if (params == NULL)
- return sink;
- else if (pulse_device_params_is_equal(PA_OBJECT(sink), params))
+
+ if (pulse_device_same_device_string(PA_OBJECT(sink), device_string))
+ if (params == NULL || pulse_device_params_is_equal(PA_OBJECT(sink), params))
return sink;
- }
}
return NULL;
PA_IDXSET_FOREACH(source, core->sources, device_idx) {
if (pulse_device_is_monitor(PA_OBJECT(source)))
continue;
- if (pulse_device_same_device_string(PA_OBJECT(source), device_string)) {
- if (params == NULL)
- return source;
- else if (pulse_device_params_is_equal(PA_OBJECT(source), params))
+
+ if (pulse_device_same_device_string(PA_OBJECT(source), device_string))
+ if (params == NULL || pulse_device_params_is_equal(PA_OBJECT(source), params))
return source;
- }
}
return NULL;
struct composite_type *ctype;
pa_dynarray *ctypes;
dm_device_direction_t direction;
+ int idx;
pa_assert(pdevice);
pa_assert(dm);
/* Get types which this pulse_device belongs to */
if ((ctypes = pulse_device_get_belongs_type(pdevice, dm)) == NULL) {
pa_log_debug("Failed to get device type. Skip this");
- return ;
+ return;
}
- if (is_loaded) {
- /* Put this pulse_device to already loaded devices */
- for (int i = 0; i < pa_dynarray_size(ctypes); i++) {
- ctype = pa_dynarray_get(ctypes, i);
- pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role);
- if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) {
- pa_log_info("Add this pulse_device to device(%u)", pa_tz_device_get_id(device));
+ /* Put/Remove this pulse_device to already loaded devices */
+ PA_DYNARRAY_FOREACH(ctype, ctypes, idx) {
+ pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role);
+ if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) {
+ pa_log_info("%s this pulse_device to device(%u)", is_loaded ? "Add" : "Remove", pa_tz_device_get_id(device));
+ if (is_loaded) {
if (direction == DM_DEVICE_DIRECTION_OUT)
pa_tz_device_add_sink(device, ctype->role, PA_SINK(pdevice));
else
pa_tz_device_add_source(device, ctype->role, PA_SOURCE(pdevice));
} else {
- pa_log_info("No device for %s.%s", ctype->type, ctype->role);
- }
- }
- } else {
- /* Remove this pulse_device from already loaded devices */
- for (int i = 0; i < pa_dynarray_size(ctypes); i++) {
- ctype = pa_dynarray_get(ctypes, i);
- pa_log_info("Found belongs type %s.%s", ctype->type, ctype->role);
- if ((device = device_list_get_device(dm, ctype->type, ctype->role, NULL))) {
- pa_log_info("Remove this pulse_device from device(%u)", pa_tz_device_get_id(device));
if (direction == DM_DEVICE_DIRECTION_OUT)
pa_tz_device_remove_sink(device, PA_SINK(pdevice));
else
pa_tz_device_remove_source(device, PA_SOURCE(pdevice));
- } else {
- pa_log_info("No device for %s.%s", ctype->type, ctype->role);
}
+ } else {
+ pa_log_info("No device for %s.%s", ctype->type, ctype->role);
}
}
handle_external_btsco_pulse_device(PA_OBJECT(sink), true, dm);
return PA_HOOK_OK;
#endif
- } else {
- pa_log_debug("Don't care this sink");
}
+ pa_log_debug("Don't care this sink");
+
return PA_HOOK_OK;
}
handle_external_btsco_pulse_device(PA_OBJECT(sink), false, dm);
return PA_HOOK_OK;
#endif
- } else {
- pa_log_debug("Don't care this sink");
}
+ pa_log_debug("Don't care this sink");
+
return PA_HOOK_OK;
}
pulse_device_set_use_internal_codec(PA_OBJECT(source), false);
handle_external_btsco_pulse_device(PA_OBJECT(source), true, dm);
#endif
- } else {
- pa_log_debug("Don't care this source");
}
+ pa_log_debug("Don't care this source");
+
return PA_HOOK_OK;
}
handle_external_btsco_pulse_device(PA_OBJECT(source), false, dm);
return PA_HOOK_OK;
#endif
- } else {
- pa_log_debug("Don't care this source");
}
+ pa_log_debug("Don't care this source");
+
return PA_HOOK_OK;
}
pulse_device_set_use_internal_codec(PA_OBJECT(sink), false);
handle_tunnel_pulse_device(PA_OBJECT(sink), pa_proplist_remote_is_allowed(sink->proplist), dm);
}
+
return PA_HOOK_OK;
}
pa_tz_device_new_data_done(&data);
} else {
pa_log_error("Invalid case : not static direction");
- return ;
+ return;
}
}
-
- return ;
}
static int load_builtin_devices(pa_device_manager *dm) {
pa_log_warn("Unknown earjack status : %d", earjack_status);
} else if (device_type_is_equal(type, DEVICE_TYPE_BT_SCO)) {
- device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
+ device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
} else if (device_type_is_equal(type, DEVICE_TYPE_HDMI)) {
- device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
+ device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
} else if (device_type_is_equal(type, DEVICE_TYPE_FORWARDING)) {
int miracast_wfd_status = 0;
device_set_detected(manager, type, NULL, NULL, DEVICE_CONNECTED);
}
}
- return ;
}
static pa_sink* load_sink(pa_device_manager *dm, const char *type, const char *role) {
}
unload_sink(dm, DEVICE_TYPE_NETWORK, DEVICE_ROLE_ACM);
-
- return;
}
pa_idxset* pa_device_manager_get_device_list(pa_device_manager *dm) {