clean pulseaudio recipes
[scm/bb/meta-tizen.git] / recipes-multimedia / pulseaudio / pulseaudio_5.0 / 0033-changes-to-pa-simple-api-samsung.patch
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
4
5 Change-Id: I997c02217a8dc14524480164aa0baeea901c7b4e
6 Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
7 ---
8  src/Makefile.am    |   4 +-
9  src/map-file       |   6 ++
10  src/pulse/simple.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++
11  src/pulse/simple.h |  28 ++++++
12  4 files changed, 324 insertions(+), 2 deletions(-)
13
14 diff --git a/src/Makefile.am b/src/Makefile.am
15 index 2edce5f..5ec8609 100644
16 --- a/src/Makefile.am
17 +++ b/src/Makefile.am
18 @@ -824,7 +824,7 @@ libpulse_la_SOURCES = \
19                 pulse/volume.c pulse/volume.h \
20                 pulse/xmalloc.c pulse/xmalloc.h
21  
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)
26  
27 @@ -834,7 +834,7 @@ libpulse_la_LIBADD += $(DBUS_LIBS)
28  endif
29  
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)
35  
36 diff --git a/src/map-file b/src/map-file
37 index 7dbcd00..95364ae 100644
38 --- a/src/map-file
39 +++ b/src/map-file
40 @@ -282,11 +282,17 @@ pa_signal_new;
41  pa_signal_set_destroy;
42  pa_simple_drain;
43  pa_simple_flush;
44 +pa_simple_mute;
45  pa_simple_free;
46  pa_simple_get_latency;
47  pa_simple_new;
48 +pa_simple_new_proplist;
49  pa_simple_read;
50  pa_simple_write;
51 +pa_simple_set_volume;
52 +pa_simple_get_stream_index;
53 +pa_simple_cork;
54 +pa_simple_is_corked;
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
62 @@ -32,10 +32,12 @@
63  #include <pulse/thread-mainloop.h>
64  #include <pulse/xmalloc.h>
65  
66 +#include <pulsecore/native-common.h>
67  #include <pulsecore/log.h>
68  #include <pulsecore/macro.h>
69  
70  #include "simple.h"
71 +#include "internal.h"
72  
73  struct pa_simple {
74      pa_threaded_mainloop *mainloop;
75 @@ -102,6 +104,24 @@ static void context_state_cb(pa_context *c, void *userdata) {
76      }
77  }
78  
79 +static void stream_success_context_cb(pa_stream *s, int success, void *userdata) {
80 +       pa_simple *p = userdata;
81 +       pa_assert(s);
82 +       pa_assert(p);
83 +
84 +    p->operation_success = success;
85 +    pa_threaded_mainloop_signal(p->mainloop, 0);
86 +}
87 +
88 +static void success_context_cb(pa_context *c, int success, void *userdata) {
89 +       pa_simple *p = userdata;
90 +       pa_assert(c);
91 +       pa_assert(p);
92 +
93 +    p->operation_success = success;
94 +    pa_threaded_mainloop_signal(p->mainloop, 0);
95 +}
96 +
97  static void stream_state_cb(pa_stream *s, void * userdata) {
98      pa_simple *p = userdata;
99      pa_assert(s);
100 @@ -251,6 +271,122 @@ fail:
101      return NULL;
102  }
103  
104 +pa_simple* pa_simple_new_proplist(
105 +        const char *server,
106 +        const char *name,
107 +        pa_stream_direction_t dir,
108 +        const char *dev,
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,
114 +        int *rerror) {
115 +
116 +    pa_simple *p;
117 +    int error = PA_ERR_INTERNAL, r;
118 +
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)
124 +
125 +    p = pa_xnew0(pa_simple, 1);
126 +    p->direction = dir;
127 +
128 +    if (!(p->mainloop = pa_threaded_mainloop_new()))
129 +        goto fail;
130 +
131 +    if (!(p->context = pa_context_new(pa_threaded_mainloop_get_api(p->mainloop), name)))
132 +        goto fail;
133 +
134 +    pa_context_set_state_callback(p->context, context_state_cb, p);
135 +
136 +    if (pa_context_connect(p->context, server, 0, NULL) < 0) {
137 +        error = pa_context_errno(p->context);
138 +        goto fail;
139 +    }
140 +
141 +    pa_threaded_mainloop_lock(p->mainloop);
142 +
143 +    if (pa_threaded_mainloop_start(p->mainloop) < 0)
144 +        goto unlock_and_fail;
145 +
146 +    for (;;) {
147 +        pa_context_state_t state;
148 +
149 +        state = pa_context_get_state(p->context);
150 +
151 +        if (state == PA_CONTEXT_READY)
152 +            break;
153 +
154 +        if (!PA_CONTEXT_IS_GOOD(state)) {
155 +            error = pa_context_errno(p->context);
156 +            goto unlock_and_fail;
157 +        }
158 +
159 +        /* Wait until the context is ready */
160 +        pa_threaded_mainloop_wait(p->mainloop);
161 +    }
162 +
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;
166 +    }
167 +
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);
172 +
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);
178 +    else
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);
184 +
185 +    if (r < 0) {
186 +        error = pa_context_errno(p->context);
187 +        goto unlock_and_fail;
188 +    }
189 +
190 +    for (;;) {
191 +        pa_stream_state_t state;
192 +
193 +        state = pa_stream_get_state(p->stream);
194 +
195 +        if (state == PA_STREAM_READY)
196 +            break;
197 +
198 +        if (!PA_STREAM_IS_GOOD(state)) {
199 +            error = pa_context_errno(p->context);
200 +            goto unlock_and_fail;
201 +        }
202 +
203 +        /* Wait until the stream is ready */
204 +        pa_threaded_mainloop_wait(p->mainloop);
205 +    }
206 +
207 +    pa_threaded_mainloop_unlock(p->mainloop);
208 +
209 +    return p;
210 +
211 +unlock_and_fail:
212 +    pa_threaded_mainloop_unlock(p->mainloop);
213 +
214 +fail:
215 +    if (rerror)
216 +        *rerror = error;
217 +    pa_simple_free(p);
218 +    return NULL;
219 +}
220  void pa_simple_free(pa_simple *s) {
221      pa_assert(s);
222  
223 @@ -452,6 +588,111 @@ unlock_and_fail:
224      return -1;
225  }
226  
227 +int pa_simple_mute(pa_simple *p, int mute, int *rerror) {
228 +    pa_operation *o = NULL;
229 +    uint32_t idx;
230 +
231 +    pa_assert(p);
232 +
233 +    CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1);
234 +
235 +    pa_threaded_mainloop_lock(p->mainloop);
236 +    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
237 +
238 +    CHECK_SUCCESS_GOTO(p, rerror, ((idx = pa_stream_get_index (p->stream)) != PA_INVALID_INDEX), unlock_and_fail);
239 +
240 +
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);
243 +
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);
248 +    }
249 +    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
250 +
251 +    pa_operation_unref(o);
252 +    pa_threaded_mainloop_unlock(p->mainloop);
253 +
254 +    return 0;
255 +
256 +unlock_and_fail:
257 +
258 +    if (o) {
259 +        pa_operation_cancel(o);
260 +        pa_operation_unref(o);
261 +    }
262 +
263 +    pa_threaded_mainloop_unlock(p->mainloop);
264 +    return -1;
265 +}
266 +
267 +int pa_simple_get_stream_index(pa_simple *p, unsigned int *idx, int *rerror) {
268 +    pa_assert(p);
269 +    CHECK_VALIDITY_RETURN_ANY(rerror, idx != NULL, PA_ERR_INVALID, -1);
270 +
271 +    pa_threaded_mainloop_lock(p->mainloop);
272 +
273 +    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
274 +
275 +       *idx = pa_stream_get_index(p->stream);
276 +
277 +    pa_threaded_mainloop_unlock(p->mainloop);
278 +    return 0;
279 +
280 +unlock_and_fail:
281 +    pa_threaded_mainloop_unlock(p->mainloop);
282 +    return -1;
283 +}
284 +
285 +int pa_simple_set_volume(pa_simple *p, int volume, int *rerror) {
286 +    pa_operation *o = NULL;
287 +    pa_stream *s = NULL;
288 +    uint32_t idx;
289 +    pa_cvolume cv;
290 +
291 +
292 +    pa_assert(p);
293 +
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);
297 +
298 +    pa_threaded_mainloop_lock(p->mainloop);
299 +    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
300 +
301 +    CHECK_SUCCESS_GOTO(p, rerror, ((idx = pa_stream_get_index (p->stream)) != PA_INVALID_INDEX), unlock_and_fail);
302 +
303 +    s = p->stream;
304 +    pa_assert(s);
305 +    pa_cvolume_set(&cv, s->sample_spec.channels, volume);
306 +
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);
309 +
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);
314 +    }
315 +    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
316 +
317 +    pa_operation_unref(o);
318 +    pa_threaded_mainloop_unlock(p->mainloop);
319 +
320 +    return 0;
321 +
322 +unlock_and_fail:
323 +
324 +    if (o) {
325 +        pa_operation_cancel(o);
326 +        pa_operation_unref(o);
327 +    }
328 +
329 +    pa_threaded_mainloop_unlock(p->mainloop);
330 +    return -1;
331 +}
332  pa_usec_t pa_simple_get_latency(pa_simple *p, int *rerror) {
333      pa_usec_t t;
334      int negative;
335 @@ -481,3 +722,50 @@ unlock_and_fail:
336      pa_threaded_mainloop_unlock(p->mainloop);
337      return (pa_usec_t) -1;
338  }
339 +
340 +int pa_simple_cork(pa_simple *p, int cork, int *rerror) {
341 +    pa_operation *o = NULL;
342 +
343 +    pa_assert(p);
344 +
345 +    pa_threaded_mainloop_lock(p->mainloop);
346 +    CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
347 +
348 +    o = pa_stream_cork(p->stream, cork, stream_success_context_cb, p);
349 +    CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail);
350 +
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);
355 +    }
356 +    CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail);
357 +
358 +    pa_operation_unref(o);
359 +    pa_threaded_mainloop_unlock(p->mainloop);
360 +
361 +    return 0;
362 +
363 +unlock_and_fail:
364 +
365 +    if (o) {
366 +        pa_operation_cancel(o);
367 +        pa_operation_unref(o);
368 +    }
369 +
370 +    pa_threaded_mainloop_unlock(p->mainloop);
371 +    return -1;
372 +}
373 +
374 +int pa_simple_is_corked(pa_simple *p) {
375 +       int is_cork;
376 +    pa_assert(p);
377 +
378 +    pa_threaded_mainloop_lock(p->mainloop);
379 +
380 +    is_cork = pa_stream_is_corked(p->stream);
381 +
382 +    pa_threaded_mainloop_unlock(p->mainloop);
383 +
384 +    return is_cork;
385 +}
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
390 @@ -31,6 +31,7 @@
391  #include <pulse/cdecl.h>
392  #include <pulse/version.h>
393  
394 +#include <pulse/proplist.h>
395  /** \page simple Simple API
396   *
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. */
400      );
401  
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. */
414 +    );
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);
417  
418 @@ -155,6 +169,20 @@ pa_usec_t pa_simple_get_latency(pa_simple *s, int *error);
419  
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);
424 +
425 +/** Volume control the playback stream */
426 +int pa_simple_set_volume(pa_simple *p, int volume, int *rerror);
427 +
428 +/** Get stream index */
429 +int pa_simple_get_stream_index(pa_simple *p, unsigned int *idx, int *rerror);
430 +
431 +/** Cork on=1/off=0 stream */
432 +int pa_simple_cork(pa_simple *p, int cork, int *rerror);
433 +
434 +/** Check whether stream is corked or not */
435 +int pa_simple_is_corked(pa_simple *p);
436  
437  PA_C_DECL_END
438