1 From: "vivian,zhang" <vivian.zhang@intel.com>
2 Date: Tue, 18 Jun 2013 16:10:15 +0800
3 Subject: changes to pa simple api - samsung
5 Change-Id: I997c02217a8dc14524480164aa0baeea901c7b4e
6 Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
10 src/pulse/simple.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++
11 src/pulse/simple.h | 28 ++++++
12 4 files changed, 324 insertions(+), 2 deletions(-)
14 diff --git a/src/Makefile.am b/src/Makefile.am
15 index 2edce5f..5ec8609 100644
18 @@ -824,7 +824,7 @@ libpulse_la_SOURCES = \
19 pulse/volume.c pulse/volume.h \
20 pulse/xmalloc.c pulse/xmalloc.h
22 -libpulse_la_CFLAGS = $(AM_CFLAGS) $(LIBJSON_CFLAGS)
23 +libpulse_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(LIBJSON_CFLAGS)
24 libpulse_la_LIBADD = $(AM_LIBADD) $(WINSOCK_LIBS) $(LTLIBICONV) $(LIBJSON_LIBS) libpulsecommon-@PA_MAJORMINOR@.la
25 libpulse_la_LDFLAGS = $(AM_LDFLAGS) $(VERSIONING_LDFLAGS) -version-info $(LIBPULSE_VERSION_INFO)
27 @@ -834,7 +834,7 @@ libpulse_la_LIBADD += $(DBUS_LIBS)
30 libpulse_simple_la_SOURCES = pulse/simple.c pulse/simple.h
31 -libpulse_simple_la_CFLAGS = $(AM_CFLAGS)
32 +libpulse_simple_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
33 libpulse_simple_la_LIBADD = $(AM_LIBADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
34 libpulse_simple_la_LDFLAGS = $(AM_LDFLAGS) $(VERSIONING_LDFLAGS) -version-info $(LIBPULSE_SIMPLE_VERSION_INFO)
36 diff --git a/src/map-file b/src/map-file
37 index 7dbcd00..95364ae 100644
40 @@ -282,11 +282,17 @@ pa_signal_new;
41 pa_signal_set_destroy;
46 pa_simple_get_latency;
48 +pa_simple_new_proplist;
51 +pa_simple_set_volume;
52 +pa_simple_get_stream_index;
55 pa_stream_begin_write;
56 pa_stream_cancel_write;
57 pa_stream_connect_playback;
58 diff --git a/src/pulse/simple.c b/src/pulse/simple.c
59 index 1891131..9109ffa 100644
60 --- a/src/pulse/simple.c
61 +++ b/src/pulse/simple.c
63 #include <pulse/thread-mainloop.h>
64 #include <pulse/xmalloc.h>
66 +#include <pulsecore/native-common.h>
67 #include <pulsecore/log.h>
68 #include <pulsecore/macro.h>
71 +#include "internal.h"
74 pa_threaded_mainloop *mainloop;
75 @@ -102,6 +104,24 @@ static void context_state_cb(pa_context *c, void *userdata) {
79 +static void stream_success_context_cb(pa_stream *s, int success, void *userdata) {
80 + pa_simple *p = userdata;
84 + p->operation_success = success;
85 + pa_threaded_mainloop_signal(p->mainloop, 0);
88 +static void success_context_cb(pa_context *c, int success, void *userdata) {
89 + pa_simple *p = userdata;
93 + p->operation_success = success;
94 + pa_threaded_mainloop_signal(p->mainloop, 0);
97 static void stream_state_cb(pa_stream *s, void * userdata) {
98 pa_simple *p = userdata;
100 @@ -251,6 +271,122 @@ fail:
104 +pa_simple* pa_simple_new_proplist(
105 + const char *server,
107 + pa_stream_direction_t dir,
109 + const char *stream_name,
110 + const pa_sample_spec *ss,
111 + const pa_channel_map *map,
112 + const pa_buffer_attr *attr,
113 + pa_proplist *proplist,
117 + int error = PA_ERR_INTERNAL, r;
119 + CHECK_VALIDITY_RETURN_ANY(rerror, !server || *server, PA_ERR_INVALID, NULL);
120 + CHECK_VALIDITY_RETURN_ANY(rerror, dir == PA_STREAM_PLAYBACK || dir == PA_STREAM_RECORD, PA_ERR_INVALID, NULL);
121 + CHECK_VALIDITY_RETURN_ANY(rerror, !dev || *dev, PA_ERR_INVALID, NULL);
122 + CHECK_VALIDITY_RETURN_ANY(rerror, ss && pa_sample_spec_valid(ss), PA_ERR_INVALID, NULL);
123 + CHECK_VALIDITY_RETURN_ANY(rerror, !map || (pa_channel_map_valid(map) && map->channels == ss->channels), PA_ERR_INVALID, NULL)
125 + p = pa_xnew0(pa_simple, 1);
126 + p->direction = dir;
128 + if (!(p->mainloop = pa_threaded_mainloop_new()))
131 + if (!(p->context = pa_context_new(pa_threaded_mainloop_get_api(p->mainloop), name)))
134 + pa_context_set_state_callback(p->context, context_state_cb, p);
136 + if (pa_context_connect(p->context, server, 0, NULL) < 0) {
137 + error = pa_context_errno(p->context);
141 + pa_threaded_mainloop_lock(p->mainloop);
143 + if (pa_threaded_mainloop_start(p->mainloop) < 0)
144 + goto unlock_and_fail;
147 + pa_context_state_t state;
149 + state = pa_context_get_state(p->context);
151 + if (state == PA_CONTEXT_READY)
154 + if (!PA_CONTEXT_IS_GOOD(state)) {
155 + error = pa_context_errno(p->context);
156 + goto unlock_and_fail;
159 + /* Wait until the context is ready */
160 + pa_threaded_mainloop_wait(p->mainloop);
163 + if (!(p->stream = pa_stream_new_with_proplist(p->context, stream_name, ss, map, proplist))) {
164 + error = pa_context_errno(p->context);
165 + goto unlock_and_fail;
168 + pa_stream_set_state_callback(p->stream, stream_state_cb, p);
169 + pa_stream_set_read_callback(p->stream, stream_request_cb, p);
170 + pa_stream_set_write_callback(p->stream, stream_request_cb, p);
171 + pa_stream_set_latency_update_callback(p->stream, stream_latency_update_cb, p);
173 + if (dir == PA_STREAM_PLAYBACK)
174 + r = pa_stream_connect_playback(p->stream, dev, attr,
175 + PA_STREAM_INTERPOLATE_TIMING
176 + |PA_STREAM_ADJUST_LATENCY
177 + |PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
179 + r = pa_stream_connect_record(p->stream, dev, attr,
180 + PA_STREAM_INTERPOLATE_TIMING
181 + |PA_STREAM_ADJUST_LATENCY
182 + |PA_STREAM_AUTO_TIMING_UPDATE
183 + |PA_STREAM_START_CORKED);
186 + error = pa_context_errno(p->context);
187 + goto unlock_and_fail;
191 + pa_stream_state_t state;
193 + state = pa_stream_get_state(p->stream);
195 + if (state == PA_STREAM_READY)
198 + if (!PA_STREAM_IS_GOOD(state)) {
199 + error = pa_context_errno(p->context);
200 + goto unlock_and_fail;
203 + /* Wait until the stream is ready */
204 + pa_threaded_mainloop_wait(p->mainloop);
207 + pa_threaded_mainloop_unlock(p->mainloop);
212 + pa_threaded_mainloop_unlock(p->mainloop);
220 void pa_simple_free(pa_simple *s) {
223 @@ -452,6 +588,111 @@ unlock_and_fail:
227 +int pa_simple_mute(pa_simple *p, int mute, int *rerror) {
228 + pa_operation *o = NULL;
233 + CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1);
235 + pa_threaded_mainloop_lock(p->mainloop);
236 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
238 + CHECK_SUCCESS_GOTO(p, rerror, ((idx = pa_stream_get_index (p->stream)) != PA_INVALID_INDEX), unlock_and_fail);
241 + o = pa_context_set_sink_input_mute (p->context, idx, mute, success_context_cb, p);
242 + CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);
244 + p->operation_success = 0;
245 + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
246 + pa_threaded_mainloop_wait(p->mainloop);
247 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
249 + CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
251 + pa_operation_unref(o);
252 + pa_threaded_mainloop_unlock(p->mainloop);
259 + pa_operation_cancel(o);
260 + pa_operation_unref(o);
263 + pa_threaded_mainloop_unlock(p->mainloop);
267 +int pa_simple_get_stream_index(pa_simple *p, unsigned int *idx, int *rerror) {
269 + CHECK_VALIDITY_RETURN_ANY(rerror, idx != NULL, PA_ERR_INVALID, -1);
271 + pa_threaded_mainloop_lock(p->mainloop);
273 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
275 + *idx = pa_stream_get_index(p->stream);
277 + pa_threaded_mainloop_unlock(p->mainloop);
281 + pa_threaded_mainloop_unlock(p->mainloop);
285 +int pa_simple_set_volume(pa_simple *p, int volume, int *rerror) {
286 + pa_operation *o = NULL;
287 + pa_stream *s = NULL;
294 + CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1);
295 + CHECK_VALIDITY_RETURN_ANY(rerror, volume >= 0, PA_ERR_INVALID, -1);
296 + CHECK_VALIDITY_RETURN_ANY(rerror, volume <= 65535, PA_ERR_INVALID, -1);
298 + pa_threaded_mainloop_lock(p->mainloop);
299 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
301 + CHECK_SUCCESS_GOTO(p, rerror, ((idx = pa_stream_get_index (p->stream)) != PA_INVALID_INDEX), unlock_and_fail);
305 + pa_cvolume_set(&cv, s->sample_spec.channels, volume);
307 + o = pa_context_set_sink_input_volume (p->context, idx, &cv, success_context_cb, p);
308 + CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);
310 + p->operation_success = 0;
311 + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
312 + pa_threaded_mainloop_wait(p->mainloop);
313 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
315 + CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
317 + pa_operation_unref(o);
318 + pa_threaded_mainloop_unlock(p->mainloop);
325 + pa_operation_cancel(o);
326 + pa_operation_unref(o);
329 + pa_threaded_mainloop_unlock(p->mainloop);
332 pa_usec_t pa_simple_get_latency(pa_simple *p, int *rerror) {
335 @@ -481,3 +722,50 @@ unlock_and_fail:
336 pa_threaded_mainloop_unlock(p->mainloop);
337 return (pa_usec_t) -1;
340 +int pa_simple_cork(pa_simple *p, int cork, int *rerror) {
341 + pa_operation *o = NULL;
345 + pa_threaded_mainloop_lock(p->mainloop);
346 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
348 + o = pa_stream_cork(p->stream, cork, stream_success_context_cb, p);
349 + CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);
351 + p->operation_success = 0;
352 + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
353 + pa_threaded_mainloop_wait(p->mainloop);
354 + CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
356 + CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
358 + pa_operation_unref(o);
359 + pa_threaded_mainloop_unlock(p->mainloop);
366 + pa_operation_cancel(o);
367 + pa_operation_unref(o);
370 + pa_threaded_mainloop_unlock(p->mainloop);
374 +int pa_simple_is_corked(pa_simple *p) {
378 + pa_threaded_mainloop_lock(p->mainloop);
380 + is_cork = pa_stream_is_corked(p->stream);
382 + pa_threaded_mainloop_unlock(p->mainloop);
386 diff --git a/src/pulse/simple.h b/src/pulse/simple.h
387 index 54003ff..4f4a988 100644
388 --- a/src/pulse/simple.h
389 +++ b/src/pulse/simple.h
391 #include <pulse/cdecl.h>
392 #include <pulse/version.h>
394 +#include <pulse/proplist.h>
395 /** \page simple Simple API
397 * \section overv_sec Overview
398 @@ -129,6 +130,19 @@ pa_simple* pa_simple_new(
399 int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
402 +/** Create a new connection to the server with proplist */
403 +pa_simple* pa_simple_new_proplist(
404 + const char *server, /**< Server name, or NULL for default */
405 + const char *name, /**< A descriptive name for this client (application name, ...) */
406 + pa_stream_direction_t dir, /**< Open this stream for recording or playback? */
407 + const char *dev, /**< Sink (resp. source) name, or NULL for default */
408 + const char *stream_name, /**< A descriptive name for this client (application name, song title, ...) */
409 + const pa_sample_spec *ss, /**< The sample type to use */
410 + const pa_channel_map *map, /**< The channel map to use, or NULL for default */
411 + const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */
412 + pa_proplist *proplist, /**< Properties, or NULL for default */
413 + int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
415 /** Close and free the connection to the server. The connection object becomes invalid when this is called. */
416 void pa_simple_free(pa_simple *s);
418 @@ -155,6 +169,20 @@ pa_usec_t pa_simple_get_latency(pa_simple *s, int *error);
420 /** Flush the playback or record buffer. This discards any audio in the buffer. */
421 int pa_simple_flush(pa_simple *s, int *error);
422 +/** Mute the playback stream */
423 +int pa_simple_mute(pa_simple *p, int mute, int *rerror);
425 +/** Volume control the playback stream */
426 +int pa_simple_set_volume(pa_simple *p, int volume, int *rerror);
428 +/** Get stream index */
429 +int pa_simple_get_stream_index(pa_simple *p, unsigned int *idx, int *rerror);
431 +/** Cork on=1/off=0 stream */
432 +int pa_simple_cork(pa_simple *p, int cork, int *rerror);
434 +/** Check whether stream is corked or not */
435 +int pa_simple_is_corked(pa_simple *p);