Support long device names and parameters 66/297266/13
authorJaechul Lee <jcsing.lee@samsung.com>
Thu, 10 Aug 2023 08:02:26 +0000 (17:02 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Mon, 28 Aug 2023 04:35:19 +0000 (13:35 +0900)
It supports various types of devices such as file, pipe, and
audio-share.

e.g) device-map.json in media-config repo

    {
        "device-string":"tizen2:file,/opt/usr/media/test.raw",
        "role":{"normal":"rate=16000 channels=1 fragment_size=320 fragments=4 rtpoll_timeout=10"}
    }
    or,
    {
        "device-string":"tizen2:audio-share,0",
        "role":{"normal":"rate=16000 channels=1 fragment_size=320 fragments=4 rtpoll_timeout=10"}
    }
    or,
    {
        "device-string":"tizen2:pipe,/tmp/pipe",
        "role":{"normal":"rate=16000 channels=1 fragment_size=320 fragments=4 rtpoll_timeout=10"}
    }

[Version] 15.0.53
[Issue Type] Update

Change-Id: I02309b8028707bac27f3a5532650808f874482ce
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/device-manager.c
src/module-tizenaudio-sink2.c
src/module-tizenaudio-source2.c
src/tizenaudio-sink2.c
src/tizenaudio-source2.c
src/tizenaudio-util.c

index 1c8a722..0141ccf 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.52
+Version:          15.0.53
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 2d697ff..6e35e90 100644 (file)
 
 #define DEVICE_MAP_FILE                     PA_DEFAULT_CONFIG_DIR"/device-map.json"
 #define DEVICE_MAP_FILE_CONTAINER           PA_DEFAULT_CONFIG_DIR"/device-map-container.json"
-#define DEVICE_STR_MAX                      40
+#define DEVICE_STR_MAX                      256
 #define DEVICE_DIRECTION_MAX                3
 #define DEVICE_MODULE_STRING_MAX            256
-#define DEVICE_PARAM_STRING_MAX             150
+#define DEVICE_PARAM_STRING_MAX             512
 #define DEVICE_AVAIL_COND_NUM_MAX           2
 #define DEVICE_AVAIL_COND_STR_MAX           6
 #define DEVICE_FILE_PER_TYPE_MAX            4
@@ -74,7 +74,7 @@
 #define DEVICE_TYPE_PROP_ROLE               "role"
 
 #define DEVICE_TYPE_STR_MAX                 20
-#define DEVICE_NAME_MAX                     30
+#define DEVICE_NAME_MAX                     128
 
 
 /* Properties of sink/sources */
index 49410e0..51b2e50 100644 (file)
@@ -40,7 +40,8 @@ PA_MODULE_USAGE(
         "channels=<number of channels> "
         "channel_map=<channel map>"
         "fragments=<number of fragments> "
-        "fragment_size=<fragment size> ");
+        "fragment_size=<fragment size> "
+        "rtpoll_timeout=<rtpoll loop timeout>");
 
 static const char* const valid_modargs[] = {
     "sink_name",
@@ -52,6 +53,7 @@ static const char* const valid_modargs[] = {
     "channel_map",
     "fragments",
     "fragment_size",
+    "rtpoll_timeout",
     NULL
 };
 
index cb821fb..ff1e223 100644 (file)
@@ -40,7 +40,8 @@ PA_MODULE_USAGE(
         "channels=<number of channels> "
         "channel_map=<channel map>"
         "fragments=<number of fragments> "
-        "fragment_size=<fragment size> ");
+        "fragment_size=<fragment size> "
+        "rtpoll_timeout=<rtpoll loop timeout>");
 
 static const char* const valid_modargs[] = {
     "source_name",
@@ -52,6 +53,7 @@ static const char* const valid_modargs[] = {
     "channel_map",
     "fragments",
     "fragment_size",
+    "rtpoll_timeout",
     NULL
 };
 
index 38c7650..30071f3 100644 (file)
@@ -56,7 +56,6 @@
 
 #define DEFAULT_SINK_NAME "tizenaudio-sink2"
 
-#define DEVICE_NAME_MAX                     30
 #define DEFAULT_FRAGMENT_MSEC               10
 #define DEFAULT_FRAGMENTS                    4
 
@@ -80,6 +79,7 @@ struct userdata {
     bool preprocess_state;
 
     pa_rtpoll_item *rtpoll_item;
+    uint32_t rtpoll_timeout;
 
     uint64_t write_count;
     pa_hal_interface *hal_interface;
@@ -104,13 +104,21 @@ static int build_pollfd(struct userdata *u) {
     if (u->rtpoll_item)
         pa_rtpoll_item_free(u->rtpoll_item);
 
-    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
-    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
     ret = pa_hal_interface_pcm_get_fd(u->hal_interface, u->pcm_handle, &fd);
     if (ret < 0 || fd < 0) {
-        pa_log_error("Failed to get fd(%d) of PCM device %d", fd, ret);
-        return -1;
+        if (u->rtpoll_timeout == 0) {
+            pa_log_error("Failed to get fd of PCM device %d", ret);
+            return -1;
+        }
+
+        pa_log_info("Failed to get fd but It will render every rtpoll_timeout(%d)", u->rtpoll_timeout);
+
+        return 0;
     }
+
+    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
+    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+
     pollfd->fd = fd;
     pollfd->events = POLLOUT | POLLERR | POLLNVAL;
 
@@ -397,7 +405,11 @@ static void thread_func(void *userdata) {
                 pa_hal_interface_pcm_start(u->hal_interface, u->pcm_handle);
                 u->first = false;
             }
-        }
+
+            if (u->rtpoll_timeout)
+                pa_rtpoll_set_timer_relative(u->rtpoll, (u->rtpoll_timeout * PA_USEC_PER_MSEC));
+        } else
+            pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
         if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
@@ -600,6 +612,8 @@ pa_sink *pa_tizenaudio_sink2_new(pa_module *m,
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%zu", buffer_frames * frame_size);
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%zu", period_frames * frame_size);
 
+    pa_modargs_get_value_u32(ma, "rtpoll_timeout", &u->rtpoll_timeout);
+
     if (pa_modargs_get_value(ma, "device_id", NULL))
         pa_proplist_sets(data.proplist, PA_PROP_DEVICE_BUS, "usb");
 
index 3887c52..9d8b871 100644 (file)
@@ -55,7 +55,6 @@
 
 #define DEFAULT_SOURCE_NAME "tizenaudio-source2"
 
-#define DEVICE_NAME_MAX                     30
 #define DEFAULT_FRAGMENT_MSEC               10
 #define DEFAULT_FRAGMENTS                    4
 
@@ -80,6 +79,7 @@ struct userdata {
     bool preprocess_state;
 
     pa_rtpoll_item *rtpoll_item;
+    uint32_t rtpoll_timeout;
 
     uint64_t read_count;
     pa_usec_t latency_time;
@@ -104,13 +104,21 @@ static int build_pollfd(struct userdata *u) {
     if (u->rtpoll_item)
         pa_rtpoll_item_free(u->rtpoll_item);
 
-    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
-    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
     ret = pa_hal_interface_pcm_get_fd(u->hal_interface, u->pcm_handle, &fd);
     if (ret < 0 || fd < 0) {
-        pa_log_error("Failed to get fd(%d) of PCM device %d", fd, ret);
-        return -1;
+        if (u->rtpoll_timeout == 0) {
+            pa_log_error("Failed to get fd of PCM device %d", ret);
+            return -1;
+        }
+
+        pa_log_info("Failed to get fd but It will render every rtpoll_timeout(%d)", u->rtpoll_timeout);
+
+        return 0;
     }
+
+    u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
+    pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+
     pollfd->fd = fd;
     pollfd->events = POLLIN | POLLERR | POLLNVAL;
 
@@ -316,8 +324,6 @@ static int process_render(struct userdata *u) {
 
     pa_assert(u);
 
-    /* Fill the buffer up the latency size */
-
     pa_hal_interface_pcm_available(u->hal_interface, u->pcm_handle, &avail);
     if (frames_to_read > avail) {
         pa_log_debug("not enough avail size. frames_to_read(%zu), avail(%u)", frames_to_read, avail);
@@ -377,7 +383,11 @@ static void thread_func(void *userdata) {
                 pa_hal_interface_pcm_start(u->hal_interface, u->pcm_handle);
                 u->first = false;
             }
-        }
+
+            if (u->rtpoll_timeout)
+                pa_rtpoll_set_timer_relative(u->rtpoll, (u->rtpoll_timeout * PA_USEC_PER_MSEC));
+        } else
+            pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
         if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
@@ -579,6 +589,8 @@ pa_source *pa_tizenaudio_source2_new(pa_module *m,
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%zu", buffer_frames * frame_size);
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%zu", period_frames * frame_size);
 
+    pa_modargs_get_value_u32(ma, "rtpoll_timeout", &u->rtpoll_timeout);
+
     if (pa_modargs_get_value(ma, "device_id", NULL))
         pa_proplist_sets(data.proplist, PA_PROP_DEVICE_BUS, "usb");
 
index c4fbc49..5c5d289 100644 (file)
@@ -31,8 +31,8 @@
 #include "hal-interface.h"
 #include "tizenaudio-util.h"
 
-#define CARD_NAME_MAX 32
-#define DEVICE_NAME_MAX 32
+#define CARD_NAME_MAX 256
+#define DEVICE_NAME_MAX 256
 
 /*
  * Extract card string from the device_string that contains device name like 'hw:1,2'