<div class="gmail_quote">On Dec 4, 2013 4:38 PM, <a href="mailto:sathish1000@gmail.com">sathish1000@gmail.com</a> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p><br>
><br>
> Hi,<br>
><br>
> <br>
><br>
> I wrote a small c program to try to load a module.. But the module is not getting loaded.</p>
<p>> Can anybody help me with this ? I have pasted the code below.<br>
><br>
> <br>
></p>
<p>><br>
> <br>
><br>
> #include <stdio.h><br>
><br>
> #include <string.h><br>
><br>
> #include <pulse/pulseaudio.h><br>
><br>
> <br>
><br>
> #define CLEAR_LINE "\n"<br>
><br>
> #define _(x) x<br>
><br>
> <br>
><br>
> /*<br>
><br>
> // From pulsecore/macro.h<br>
><br>
> #define pa_memzero(x,l) (memset((x), 0, (l)))<br>
><br>
> #define pa_zero(x) (pa_memzero(&(x), sizeof(x)))<br>
><br>
> */<br>
><br>
> <br>
><br>
> int ret;<br>
><br>
> pa_context *context;<br>
><br>
> int clientindex;<br>
><br>
> int sink_num_channels;<br>
><br>
> int sink_input_index;<br>
><br>
> <br>
><br>
> void show_error(char *s) {<br>
><br>
> /* stub */<br>
><br>
> }<br>
><br>
> <br>
><br>
> void load_module_cb(pa_context *context, int32_t index, void *userdata)<br>
><br>
> { <br>
><br>
> printf ("Going out \n");<br>
><br>
> int * return_value_pointer = (int *) userdata;<br>
><br>
> if (return_value_pointer) <br>
><br>
> { <br>
><br>
> *return_value_pointer = index; <br>
><br>
> }<br>
><br>
> }<br>
><br>
> <br>
><br>
> // This callback gets called when our context changes state. We really only<br>
><br>
> // care about when it's ready or if it has failed<br>
><br>
> void pa_state_cb(pa_context *c, void *userdata) {<br>
><br>
> pa_context_state_t state;<br>
><br>
> int *pa_ready = userdata;<br>
><br>
> <br>
><br>
> state = pa_context_get_state(c);<br>
><br>
> switch (state) {<br>
><br>
> // There are just here for reference<br>
><br>
> case PA_CONTEXT_UNCONNECTED:<br>
><br>
> case PA_CONTEXT_CONNECTING:<br>
><br>
> case PA_CONTEXT_AUTHORIZING:<br>
><br>
> case PA_CONTEXT_SETTING_NAME:<br>
><br>
> default:<br>
><br>
> break;<br>
><br>
> case PA_CONTEXT_FAILED:<br>
><br>
> case PA_CONTEXT_TERMINATED:<br>
><br>
> *pa_ready = 2;<br>
><br>
> break;<br>
><br>
> case PA_CONTEXT_READY:<br>
><br>
> *pa_ready = 1;<br>
><br>
> break;<br>
><br>
> }<br>
><br>
> }<br>
><br>
> <br>
><br>
> int pa_get_devicelist() {<br>
><br>
> // Define our pulse audio loop and connection variables<br>
><br>
> pa_mainloop *pa_ml;<br>
><br>
> pa_mainloop_api *pa_mlapi;<br>
><br>
> pa_operation *pa_op;<br>
><br>
> pa_context *pa_ctx;<br>
><br>
> <br>
><br>
> // We'll need these state variables to keep track of our requests<br>
><br>
> int state = 0;<br>
><br>
> int pa_ready = 0;<br>
><br>
> <br>
><br>
> <br>
><br>
> // Create a mainloop API and connection to the default server<br>
><br>
> pa_ml = pa_mainloop_new();<br>
><br>
> pa_mlapi = pa_mainloop_get_api(pa_ml);<br>
><br>
> pa_ctx = pa_context_new(pa_mlapi, "test");<br>
><br>
> <br>
><br>
> // This function connects to the pulse server<br>
><br>
> pa_context_connect(pa_ctx, NULL, 0, NULL);<br>
><br>
> <br>
><br>
> // This function defines a callback so the server will tell us it's state.<br>
><br>
> // Our callback will wait for the state to be ready. The callback will<br>
><br>
> // modify the variable to 1 so we know when we have a connection and it's<br>
><br>
> // ready.<br>
><br>
> // If there's an error, the callback will set pa_ready to 2<br>
><br>
> pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);<br>
><br>
> <br>
><br>
> // Now we'll enter into an infinite loop until we get the data we receive<br>
><br>
> // or if there's an error<br>
><br>
> //for (;;) {<br>
><br>
> // We can't do anything until PA is ready, so just iterate the mainloop<br>
><br>
> // and continue<br>
><br>
> if (pa_ready == 0) {<br>
><br>
> printf ("Going in \n");<br>
><br>
> pa_op=pa_context_load_module(pa_ctx, "module-role-cork", NULL, NULL, NULL);<br>
><br>
> printf ("Going in1 \n");<br>
><br>
> if(pa_op) pa_operation_unref(pa_op); <br>
><br>
> //continue;<br>
><br>
> }<br>
><br>
> // We couldn't get a connection to the server, so exit out<br>
><br>
> if (pa_ready == 2) {<br>
><br>
> pa_context_disconnect(pa_ctx);<br>
><br>
> pa_context_unref(pa_ctx);<br>
><br>
> pa_mainloop_free(pa_ml);<br>
><br>
> return -1;<br>
><br>
> }<br>
><br>
> <br>
><br>
> pa_context_disconnect(pa_ctx);<br>
><br>
> pa_context_unref(pa_ctx);<br>
><br>
> pa_mainloop_free(pa_ml);<br>
><br>
> return 0; <br>
><br>
> }<br>
><br>
> <br>
><br>
> int main(int argc, char *argv[]) {<br>
><br>
> <br>
><br>
> if (pa_get_devicelist() < 0) {<br>
><br>
> fprintf(stderr, "failed to get device list\n");<br>
><br>
> return 1;<br>
><br>
> }<br>
><br>
> <br>
><br>
> return 0;<br>
><br>
> }<br>
><br>
> <br>
><br>
> Thanks,<br>
><br>
> Sathish<br>
><br>
></p>
</blockquote></div>