tizenaudio-sink/source: Remove card of module argument 16/191516/1 accepted/tizen/unified/20181107.082057 submit/tizen/20181106.060307
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 18 Oct 2018 02:49:24 +0000 (11:49 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 18 Oct 2018 03:00:10 +0000 (12:00 +0900)
This card argument is removed and is incorporated into the
device argument. User can pass the device argument as below.

e.g.) in case of card 0, device 0
  device=0,0 rate=44100

device-manager is also revised to parse the device-string from
device-map.json properly in case of device class is for tizen.

[Version] 11.1.29
[Issue type] Bug fix

Change-Id: I56d99dbc29ad7729c5842e41110f7f0c24478fee
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/device-manager.c
src/module-tizenaudio-sink.c
src/module-tizenaudio-source.c

index a78b672..75a6851 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.28
+Version:          11.1.29
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 98abee1..c3a28f8 100644 (file)
@@ -320,7 +320,7 @@ static dm_device_class_t device_string_get_class(const char *device_string) {
     }
 }
 
-/* device_string looks like "alsa:0,0"
+/* device_string looks like "alsa:0,0" or "tizen:0,0"
  * in this case name is "0,0" */
 static int device_string_get_name(const char *device_string, char *name) {
     char *colon_p;
@@ -346,42 +346,6 @@ static int device_string_get_name(const char *device_string, char *name) {
     return 0;
 }
 
-static int device_name_get_card(const char *device_name, char *card) {
-    const char *name_p;
-    char *card_p;
-
-    if (!strchr(device_name, ',')) {
-        pa_log_error("Failed to parse name : no comma");
-        return -1;
-    }
-
-    name_p = device_name;
-    card_p = card;
-    while (*name_p != ',')
-        *(card_p++) = *(name_p++);
-    *card_p = '\0';
-
-    return 0;
-}
-
-static int device_name_get_device(const char *device_name, char *device) {
-    const char *comma_p;
-    char *device_p;
-
-    if (!(comma_p = strchr(device_name, ','))) {
-        pa_log_error("Failed to parse name : no comma");
-        return -1;
-    }
-
-    comma_p++;
-    device_p = device;
-    while (*comma_p != '\0')
-        *(device_p++) = *(comma_p++);
-    *device_p = '\0';
-
-    return 0;
-}
-
 static pa_proplist* pulse_device_get_proplist(pa_object *pdevice) {
     if (pa_sink_isinstance(pdevice))
         return PA_SINK(pdevice)->proplist;
@@ -842,17 +806,10 @@ static int build_params_to_load_device(const char *device_string, const char *pa
         return -1;
     }
 
-    if (device_class == DM_DEVICE_CLASS_ALSA) {
+    if (device_class == DM_DEVICE_CLASS_ALSA)
         snprintf(target, DEVICE_PARAM_STRING_MAX, "device=hw:%s ", device_name);
-    } else if (device_class == DM_DEVICE_CLASS_TIZEN) {
-        char card[DEVICE_NAME_MAX];
-        char device[DEVICE_NAME_MAX];
-
-        device_name_get_card(device_name, card);
-        device_name_get_device(device_name, device);
-
-        snprintf(target, DEVICE_PARAM_STRING_MAX, "card=%s device=%s ", card, device);
-    }
+    else if (device_class == DM_DEVICE_CLASS_TIZEN)
+        snprintf(target, DEVICE_PARAM_STRING_MAX, "device=%s ", device_name);
 
     if (params)
         strncat(target, params, DEVICE_PARAM_STRING_MAX - strlen(target));
index 3d81cbb..7fe87db 100644 (file)
@@ -55,8 +55,7 @@ PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_USAGE(
         "sink_name=<name of sink> "
         "sink_properties=<properties for the sink> "
-        "card=<card to use> "
-        "device=<device to use> "
+        "device=<device to use, card comma device (e.g. 0,0)> "
         "format=<sample format> "
         "rate=<sample rate> "
         "channels=<number of channels> "
@@ -74,6 +73,8 @@ PA_MODULE_USAGE(
 /* Sink device consumes that amount of maximum buffer at every request */
 #define DEFAULT_MAX_REQUEST_USEC (PA_USEC_PER_SEC * 0.032)
 
+#define DEVICE_NAME_MAX                     30
+
 struct userdata {
     pa_core *core;
     pa_module *module;
@@ -105,7 +106,6 @@ struct userdata {
 static const char* const valid_modargs[] = {
     "sink_name",
     "sink_properties",
-    "card",
     "device",
     "format",
     "rate",
@@ -459,6 +459,42 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
+static int parse_to_get_card(const char *modarg_device, char *card) {
+    const char *name_p;
+    char *card_p;
+
+    if (!strchr(modarg_device, ',')) {
+        pa_log_error("Failed to parse device argument : no comma");
+        return -1;
+    }
+
+    name_p = modarg_device;
+    card_p = card;
+    while (*name_p != ',')
+        *(card_p++) = *(name_p++);
+    *card_p = '\0';
+
+    return 0;
+}
+
+static int parse_to_get_device(const char *modarg_device, char *device) {
+    const char *comma_p;
+    char *device_p;
+
+    if (!(comma_p = strchr(modarg_device, ','))) {
+        pa_log_error("Failed to parse device argument : no comma");
+        return -1;
+    }
+
+    comma_p++;
+    device_p = device;
+    while (*comma_p != '\0')
+        *(device_p++) = *(comma_p++);
+    *device_p = '\0';
+
+    return 0;
+}
+
 int pa__init(pa_module*m) {
     struct userdata *u = NULL;
     pa_sample_spec ss;
@@ -468,7 +504,9 @@ int pa__init(pa_module*m) {
     uint32_t alternate_sample_rate;
     uint32_t block_msec;
     uint32_t max_request_msec;
-    const char *card, *device;
+    const char *modarg_device;
+    char card[DEVICE_NAME_MAX];
+    char device[DEVICE_NAME_MAX];
 
     pa_assert(m);
 
@@ -498,9 +536,13 @@ int pa__init(pa_module*m) {
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
 
-    if (!(card = pa_modargs_get_value(ma, "card", NULL)) ||
-        !(device = pa_modargs_get_value(ma, "device", NULL))) {
-        pa_log_error("card or device are invalid");
+    if (!(modarg_device = pa_modargs_get_value(ma, "device", NULL))) {
+        pa_log_error("device is invalid");
+        goto fail;
+    }
+
+    if (parse_to_get_card(modarg_device, card) || parse_to_get_device(modarg_device, device)) {
+        pa_log_error("failed to parse device module argument, %s", modarg_device);
         goto fail;
     }
 
index f4c12ab..613025a 100644 (file)
@@ -55,8 +55,7 @@ PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_USAGE(
         "source_name=<name of source> "
         "source_properties=<properties for the source> "
-        "card=<card to use> "
-        "device=<device to use> "
+        "device=<device to use, card comma device (e.g. 0,0)> "
         "format=<sample format> "
         "rate=<sample rate> "
         "channels=<number of channels> "
@@ -70,6 +69,8 @@ PA_MODULE_USAGE(
 /* BLOCK_USEC should be less than amount of fragment_size * fragments */
 #define BLOCK_USEC (PA_USEC_PER_SEC * 0.032)
 
+#define DEVICE_NAME_MAX                     30
+
 struct userdata {
     pa_core *core;
     pa_module *module;
@@ -100,7 +101,6 @@ struct userdata {
 static const char* const valid_modargs[] = {
     "source_name",
     "source_properties",
-    "card",
     "device",
     "format",
     "rate",
@@ -405,6 +405,42 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
+static int parse_to_get_card(const char *modarg_device, char *card) {
+    const char *name_p;
+    char *card_p;
+
+    if (!strchr(modarg_device, ',')) {
+        pa_log_error("Failed to parse device argument : no comma");
+        return -1;
+    }
+
+    name_p = modarg_device;
+    card_p = card;
+    while (*name_p != ',')
+        *(card_p++) = *(name_p++);
+    *card_p = '\0';
+
+    return 0;
+}
+
+static int parse_to_get_device(const char *modarg_device, char *device) {
+    const char *comma_p;
+    char *device_p;
+
+    if (!(comma_p = strchr(modarg_device, ','))) {
+        pa_log_error("Failed to parse device argument : no comma");
+        return -1;
+    }
+
+    comma_p++;
+    device_p = device;
+    while (*comma_p != '\0')
+        *(device_p++) = *(comma_p++);
+    *device_p = '\0';
+
+    return 0;
+}
+
 int pa__init(pa_module*m) {
     struct userdata *u = NULL;
     pa_sample_spec ss;
@@ -412,7 +448,9 @@ int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     pa_source_new_data data;
     uint32_t alternate_sample_rate;
-    const char *card, *device;
+    const char *modarg_device;
+    char card[DEVICE_NAME_MAX];
+    char device[DEVICE_NAME_MAX];
 
     pa_assert(m);
 
@@ -442,9 +480,13 @@ int pa__init(pa_module*m) {
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
 
-    if (!(card = pa_modargs_get_value(ma, "card", NULL)) ||
-        !(device = pa_modargs_get_value(ma, "device", NULL))) {
-        pa_log_error("card or device are invalid");
+    if (!(modarg_device = pa_modargs_get_value(ma, "device", NULL))) {
+        pa_log_error("device is invalid");
+        goto fail;
+    }
+
+    if (parse_to_get_card(modarg_device, card) || parse_to_get_device(modarg_device, device)) {
+        pa_log_error("failed to parse device module argument, %s", modarg_device);
         goto fail;
     }