static void pulse_write(void* ptr, int length) { int writeoffs, remain, writable; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); /* break large fragments into smaller fragments. --nenolod */ for (writeoffs = 0, remain = length; writeoffs < length; writeoffs += writable, remain -= writable) { void * pptr = (char *) ptr + writeoffs; writable = length - writeoffs; size_t fragsize = pa_stream_writable_size(stream); /* don't write more than what PA is willing to handle right now. */ if (writable > fragsize) writable = fragsize; if (pa_stream_write(stream, pptr, writable, NULL, PA_SEEK_RELATIVE, 0) < 0) { AUDDBG("pa_stream_write() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } } do_trigger = 0; written += length; fail: pa_threaded_mainloop_unlock(mainloop); }
static void pulse_flush(int time) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); written = time * (int64_t) bytes_per_second / 1000; flush_time = time; if (!(o = pa_stream_flush(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
static void pulse_drain(void) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 0); if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_drain() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_drain() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
static int pulse_get_output_time (void) { int time = 0; CHECK_CONNECTED(0); pa_threaded_mainloop_lock(mainloop); time = written * (int64_t) 1000 / bytes_per_second; pa_usec_t usec; int neg; if (pa_stream_get_latency (stream, & usec, & neg) == PA_OK) time -= usec / 1000; /* fix for AUDPLUG-308: pa_stream_get_latency() still returns positive even * immediately after a flush; fix the result so that we don't return less * than the flush time */ if (time < flush_time) time = flush_time; pa_threaded_mainloop_unlock(mainloop); return time; }
static int pulse_free(void) { ENTER(__FUNCTION__); size_t l = 0; pa_operation *o = NULL; CHECK_CONNECTED(0); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_lock"); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if ((l = pa_stream_writable_size(stream)) == (size_t) -1) { SHOW("pa_stream_writable_size() failed: %s", pa_strerror(pa_context_errno(context))); l = 0; goto fail; } SHOW("pulse_free: %s (ret=%d)\n", "pa_stream_writable_size", l); /* If this function is called twice with no pulse_write() call in * between this means we should trigger the playback */ if (do_trigger) { int success = 0; SHOW("pulse_free: %s (call)\n", "pa_stream_trigger"); if (!(o = pa_stream_trigger(stream, stream_success_cb, &success))) { SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } SHOW("pulse_free: %s (ret)\n", "pa_threaded_main_loop"); if (!success) SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); } fail: SHOW("pulse_free: %s (call)\n", "pa_operation_unref"); if (o) pa_operation_unref(o); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_unlock"); pa_threaded_mainloop_unlock(mainloop); do_trigger = !!l; SHOW("pulse_free: %d (ret)\n", (int)l); return (int) l; }
static int pulse_free(void) { size_t l = 0; pa_operation *o = NULL; CHECK_CONNECTED(0); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if ((l = pa_stream_writable_size(stream)) == (size_t) -1) { AUDDBG("pa_stream_writable_size() failed: %s", pa_strerror(pa_context_errno(context))); l = 0; goto fail; } /* If this function is called twice with no pulse_write() call in * between this means we should trigger the playback */ if (do_trigger) { int success = 0; if (!(o = pa_stream_trigger(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); } fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); do_trigger = !!l; return (int) l; }
static int drain(void) { pa_operation *o = NULL; int success = 0; int ret = PULSE_ERROR; ENTER(__FUNCTION__); CHECK_CONNECTED(ret); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 0); SHOW_TIME("pa_stream_drain (call)"); if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) { SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context))); goto fail; } SHOW_TIME("pa_threaded_mainloop_wait (call)"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } SHOW_TIME("pa_threaded_mainloop_wait (ret)"); if (!success) { SHOW("pa_stream_drain() failed: %s\n", pa_strerror(pa_context_errno(context))); } else { ret = PULSE_OK; } fail: SHOW_TIME("pa_operation_unref (call)"); if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); SHOW_TIME("drain (ret)"); return ret; }
static int pulse_playing(const pa_timing_info *the_timing_info) { ENTER(__FUNCTION__); int r = 0; const pa_timing_info *i; assert(the_timing_info); CHECK_CONNECTED(0); pa_threaded_mainloop_lock(mainloop); for (;;) { CHECK_DEAD_GOTO(fail, 1); if ((i = pa_stream_get_timing_info(stream))) { break; } if (pa_context_errno(context) != PA_ERR_NODATA) { SHOW("pa_stream_get_timing_info() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } pa_threaded_mainloop_wait(mainloop); } r = i->playing; memcpy((void*)the_timing_info, (void*)i, sizeof(pa_timing_info)); // display_timing_info(i); fail: pa_threaded_mainloop_unlock(mainloop); return r; }