tizenaudio-sink: add 'block_msec', 'max_request_msec' arguments 56/136456/1
authorKimJeongYeon <jeongyeon.kim@samsung.com>
Wed, 28 Jun 2017 00:28:26 +0000 (09:28 +0900)
committerKimJeongYeon <jeongyeon.kim@samsung.com>
Fri, 30 Jun 2017 01:10:01 +0000 (10:10 +0900)
[Version] 5.0.157
[Profile] Common
[Issue Type] Refactoring

Changes:
* Move 'block_usec', 'max_request' variables to module's arguments.
  Currently, BLOCK_USEC, MAX_REQUEST_USEC values are depend on devices.
  I think that management would be much easier, if they move to module's arguments.
  Because, easy to modify these arguments at 'device-map.json' configuration file.

* Reduce default 'block_usec'.
  To optimize latency configuration, decrease block_usec 64 -> 50 msec.
  That means tizenaudio-sink trying to keep buffer amount of 50msec.

Signed-off-by: KimJeongYeon <jeongyeon.kim@samsung.com>
Change-Id: I985274d9cdcc941209946e88a00cb1fbcf5f2166

packaging/pulseaudio-modules-tizen.spec
src/module-tizenaudio-sink.c

index 4d06c581cdabfa0104fa9beaba3749aedfdd6d6d..e5b555a5598f742dafe6c1d27860074decb3df48 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          5.0.156
+Version:          5.0.157
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 1df1d8d6c758d7bc87675432fee1b218c8f60fc4..35f16a0c1d3c5e439aeb48d9a7cc0ef21f3fd369 100644 (file)
@@ -60,12 +60,17 @@ PA_MODULE_USAGE(
         "channels=<number of channels> "
         "channel_map=<channel map>"
         "fragments=<number of fragments> "
-        "fragment_size=<fragment size> ");
+        "fragment_size=<fragment size> "
+        "block_msec=<sink keep> "
+        "max_request_msec=<maximum buffer request of device> ");
 
 #define DEFAULT_SINK_NAME "tizenaudio-sink"
 
-/* BLOCK_USEC should be less than amount of fragment_size * fragments */
-#define BLOCK_USEC (PA_USEC_PER_SEC * 0.064)
+/* block_usec should be less than amount of fragment_size * fragments */
+#define DEFAULT_BLOCK_USEC (PA_USEC_PER_SEC * 0.05)
+
+/* Sink device consumes that amount of maximum buffer at every request */
+#define DEFAULT_MAX_REQUEST_USEC (PA_USEC_PER_SEC * 0.032)
 
 struct userdata {
     pa_core *core;
@@ -81,6 +86,7 @@ struct userdata {
     uint32_t frag_size;
 
     pa_usec_t block_usec;
+    pa_usec_t max_request_usec;
     pa_usec_t timestamp;
     pa_usec_t timestamp_written;
 
@@ -101,6 +107,8 @@ static const char* const valid_modargs[] = {
     "channel_map",
     "fragments",
     "fragment_size",
+    "block_msec",
+    "max_request_msec",
     NULL
 };
 
@@ -248,7 +256,6 @@ static int sink_process_msg(
 
 static void sink_update_requested_latency_cb(pa_sink *s) {
     struct userdata *u;
-    size_t nbytes;
 
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
@@ -258,9 +265,8 @@ static void sink_update_requested_latency_cb(pa_sink *s) {
     if (u->block_usec == (pa_usec_t)-1)
         u->block_usec = s->thread_info.max_latency;
 
-    nbytes = pa_usec_to_bytes(u->block_usec, &s->sample_spec);
-    pa_sink_set_max_rewind_within_thread(s, nbytes);
-    pa_sink_set_max_request_within_thread(s, nbytes / 2);  /* max_request 32ms seems enough */
+    pa_sink_set_max_rewind_within_thread(s, pa_usec_to_bytes(u->block_usec, &s->sample_spec));
+    pa_sink_set_max_request_within_thread(s, pa_usec_to_bytes(u->max_request_usec, &s->sample_spec));
 }
 
 static void process_rewind(struct userdata *u, pa_usec_t now) {
@@ -324,7 +330,7 @@ static int process_render(struct userdata *u, pa_usec_t now) {
 
         if (u->first) {
             pa_log_debug("Fill initial buffer");
-            frames_to_write = (u->frag_size * u->nfrags) / frame_size;
+            frames_to_write = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec) / frame_size;
             u->timestamp = u->timestamp_written = now;
         } else {
             /* Write pcm every 10ms */
@@ -438,8 +444,9 @@ int pa__init(pa_module*m) {
     pa_channel_map map;
     pa_modargs *ma = NULL;
     pa_sink_new_data data;
-    size_t nbytes;
     uint32_t alternate_sample_rate;
+    uint32_t block_msec;
+    uint32_t max_request_msec;
 
     pa_assert(m);
 
@@ -479,6 +486,19 @@ int pa__init(pa_module*m) {
     }
     pa_log_info("fragment_size(%u), fragments(%u)", u->frag_size, u->nfrags);
 
+    /* Optional */
+    block_msec = DEFAULT_BLOCK_USEC / PA_USEC_PER_MSEC;
+    pa_modargs_get_value_u32(ma, "block_msec", &block_msec);
+    u->block_usec = (pa_usec_t) block_msec * PA_USEC_PER_MSEC;
+
+    /* Optional */
+    max_request_msec = DEFAULT_MAX_REQUEST_USEC / PA_USEC_PER_MSEC;
+    pa_modargs_get_value_u32(ma, "max_request_msec", &max_request_msec);
+    u->max_request_usec = (pa_usec_t) max_request_msec * PA_USEC_PER_MSEC;
+
+    u->timestamp = 0ULL;
+    u->timestamp_written = 0ULL;
+
     pa_sink_new_data_init(&data);
     data.driver = __FILE__;
     data.module = m;
@@ -521,13 +541,8 @@ int pa__init(pa_module*m) {
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
     pa_sink_set_rtpoll(u->sink, u->rtpoll);
 
-    u->block_usec = BLOCK_USEC;
-    u->timestamp = 0ULL;
-    u->timestamp_written = 0ULL;
-
-    nbytes = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec);
     pa_sink_set_max_rewind(u->sink, 0);
-    pa_sink_set_max_request(u->sink, nbytes / 2);  /* max_request 32ms seems enough */
+    pa_sink_set_max_request(u->sink, pa_usec_to_bytes(u->max_request_usec, &u->sink->sample_spec));
 
     if (!(u->thread = pa_thread_new("tizenaudio-sink", thread_func, u))) {
         pa_log_error("Failed to create thread.");