]> code.delx.au - pulseaudio/blobdiff - src/modules/module-sine-source.c
bluetooth: Fire DEVICE_CONNECTION_CHANGED in set_device_info_valid()
[pulseaudio] / src / modules / module-sine-source.c
index 5626c2ab7e7b94b016c379e214bfe57dbe058524..bb3f8c41146e652d5d911c6beda853e96aad7829 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #endif
 
 #include <stdlib.h>
 #endif
 
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <stdio.h>
 #include <errno.h>
 #include <stdio.h>
 #include <errno.h>
-#include <string.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <limits.h>
-#include <sys/ioctl.h>
-#include <sys/poll.h>
 
 
-#include <pulse/xmalloc.h>
+#include <pulse/rtclock.h>
 #include <pulse/timeval.h>
 #include <pulse/timeval.h>
+#include <pulse/xmalloc.h>
 
 
-#include <pulsecore/core-error.h>
 #include <pulsecore/source.h>
 #include <pulsecore/module.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/source.h>
 #include <pulsecore/module.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
 #include <pulsecore/rtpoll.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
 #include <pulsecore/rtpoll.h>
-#include <pulsecore/rtclock.h>
 
 #include "module-sine-source-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION("Sine wave generator source");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 
 #include "module-sine-source-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION("Sine wave generator source");
 PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(FALSE);
+PA_MODULE_LOAD_ONCE(false);
 PA_MODULE_USAGE(
 PA_MODULE_USAGE(
-        "rate=<sample rate> "
         "source_name=<name for the source> "
         "source_name=<name for the source> "
+        "source_properties=<properties for the source> "
+        "rate=<sample rate> "
         "frequency=<frequency in Hz>");
 
 #define DEFAULT_SOURCE_NAME "sine_input"
         "frequency=<frequency in Hz>");
 
 #define DEFAULT_SOURCE_NAME "sine_input"
-#define MAX_LATENCY_USEC (PA_USEC_PER_SEC * 2)
+#define BLOCK_USEC (PA_USEC_PER_SEC * 2)
 
 struct userdata {
     pa_core *core;
 
 struct userdata {
     pa_core *core;
@@ -79,8 +73,9 @@ struct userdata {
 };
 
 static const char* const valid_modargs[] = {
 };
 
 static const char* const valid_modargs[] = {
-    "rate",
     "source_name",
     "source_name",
+    "source_properties",
+    "rate",
     "frequency",
     NULL
 };
     "frequency",
     NULL
 };
@@ -99,14 +94,14 @@ static int source_process_msg(
         case PA_SOURCE_MESSAGE_SET_STATE:
 
             if (PA_PTR_TO_UINT(data) == PA_SOURCE_RUNNING)
         case PA_SOURCE_MESSAGE_SET_STATE:
 
             if (PA_PTR_TO_UINT(data) == PA_SOURCE_RUNNING)
-                u->timestamp = pa_rtclock_usec();
+                u->timestamp = pa_rtclock_now();
 
             break;
 
         case PA_SOURCE_MESSAGE_GET_LATENCY: {
             pa_usec_t now, left_to_fill;
 
 
             break;
 
         case PA_SOURCE_MESSAGE_GET_LATENCY: {
             pa_usec_t now, left_to_fill;
 
-            now = pa_rtclock_usec();
+            now = pa_rtclock_now();
             left_to_fill = u->timestamp > now ? u->timestamp - now : 0ULL;
 
             *((pa_usec_t*) data) = u->block_usec > left_to_fill ? u->block_usec - left_to_fill : 0ULL;
             left_to_fill = u->timestamp > now ? u->timestamp - now : 0ULL;
 
             *((pa_usec_t*) data) = u->block_usec > left_to_fill ? u->block_usec - left_to_fill : 0ULL;
@@ -164,9 +159,8 @@ static void thread_func(void *userdata) {
     pa_log_debug("Thread starting up");
 
     pa_thread_mq_install(&u->thread_mq);
     pa_log_debug("Thread starting up");
 
     pa_thread_mq_install(&u->thread_mq);
-    pa_rtpoll_install(u->rtpoll);
 
 
-    u->timestamp = pa_rtclock_usec();
+    u->timestamp = pa_rtclock_now();
 
     for (;;) {
         int ret;
 
     for (;;) {
         int ret;
@@ -174,7 +168,7 @@ static void thread_func(void *userdata) {
         if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
             pa_usec_t now;
 
         if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
             pa_usec_t now;
 
-            now = pa_rtclock_usec();
+            now = pa_rtclock_now();
 
             if (u->timestamp <= now)
                 process_render(u, now);
 
             if (u->timestamp <= now)
                 process_render(u, now);
@@ -184,7 +178,7 @@ static void thread_func(void *userdata) {
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
-        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
+        if ((ret = pa_rtpoll_run(u->rtpoll, true)) < 0)
             goto fail;
 
         if (ret == 0)
             goto fail;
 
         if (ret == 0)
@@ -248,6 +242,12 @@ int pa__init(pa_module*m) {
     pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency);
     pa_source_new_data_set_sample_spec(&data, &ss);
 
     pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency);
     pa_source_new_data_set_sample_spec(&data, &ss);
 
+    if (pa_modargs_get_proplist(ma, "source_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
+        pa_log("Invalid properties");
+        pa_source_new_data_done(&data);
+        goto fail;
+    }
+
     u->source = pa_source_new(m->core, &data, PA_SOURCE_LATENCY);
     pa_source_new_data_done(&data);
 
     u->source = pa_source_new(m->core, &data, PA_SOURCE_LATENCY);
     pa_source_new_data_done(&data);
 
@@ -260,13 +260,13 @@ int pa__init(pa_module*m) {
     u->source->update_requested_latency = source_update_requested_latency_cb;
     u->source->userdata = u;
 
     u->source->update_requested_latency = source_update_requested_latency_cb;
     u->source->userdata = u;
 
+    u->block_usec = BLOCK_USEC;
+
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
     pa_source_set_rtpoll(u->source, u->rtpoll);
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
     pa_source_set_rtpoll(u->source, u->rtpoll);
+    pa_source_set_fixed_latency(u->source, u->block_usec);
 
 
-    pa_source_set_latency_range(u->source, (pa_usec_t) -1, MAX_LATENCY_USEC);
-    u->block_usec = u->source->thread_info.max_latency;
-
-    if (!(u->thread = pa_thread_new(thread_func, u))) {
+    if (!(u->thread = pa_thread_new("sine-source", thread_func, u))) {
         pa_log("Failed to create thread.");
         goto fail;
     }
         pa_log("Failed to create thread.");
         goto fail;
     }