4 This file is part of PulseAudio.
6 Copyright 2006, 2007 Lennart Poettering and Tanu Kaskinen
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <jack/jack.h>
33 #include <jack/ringbuffer.h>
34 #include <jack/types.h>
36 #include <pulse/mainloop-api.h>
37 #include <pulse/sample.h>
38 #include <pulse/channelmap.h>
39 #include <pulse/xmalloc.h>
41 #include <pulsecore/sink.h>
42 #include <pulsecore/module.h>
43 #include <pulsecore/core.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/core-util.h>
46 #include <pulsecore/core-error.h>
47 #include <pulsecore/pipe.h>
48 #include <pulsecore/modargs.h>
49 #include <pulsecore/strbuf.h>
51 #include "module-jack-sink-symdef.h"
53 PA_MODULE_AUTHOR("Lennart Poettering & Tanu Kaskinen")
54 PA_MODULE_DESCRIPTION("Jack Sink")
55 PA_MODULE_VERSION(PACKAGE_VERSION
)
57 "sink_name=<name of sink> "
58 "server_name=<jack server name> "
59 "client_name=<jack client name> "
60 "channels=<number of channels> "
61 "connect=<connect ports automatically?> "
62 "buffersize=<intermediate buffering in frames> "
63 "channel_map=<channel map>")
65 #define DEFAULT_SINK_NAME "jack_out"
66 #define DEFAULT_CLIENT_NAME "PulseAudio(output)"
67 #define DEFAULT_RINGBUFFER_SIZE 4096
76 jack_port_t
* j_ports
[PA_CHANNELS_MAX
];
77 jack_client_t
*j_client
;
79 jack_nframes_t j_buffersize
;
81 /* For avoiding j_buffersize changes at a wrong moment. */
82 pthread_mutex_t buffersize_mutex
;
84 /* The intermediate store where the pulse side writes to and the jack side
86 jack_ringbuffer_t
* ringbuffer
;
88 /* For signaling when there's room in the ringbuffer. */
89 pthread_mutex_t cond_mutex
;
90 pthread_cond_t ringbuffer_cond
;
92 pthread_t filler_thread
; /* Keeps the ringbuffer filled. */
94 int ringbuffer_is_full
;
95 int filler_thread_is_running
;
100 pa_io_event
*io_event
;
108 char* server_name
; /* May be NULL */
109 int server_name_given
;
112 int client_name_given
;
121 int buffersize_given
;
128 static const char* const valid_modargs
[] = {
140 /* Initialization functions. */
141 static int parse_options(struct options
* o
, const char* argument
);
142 static void set_default_channels(pa_module
* self
, struct options
* o
);
143 static int create_sink(pa_module
* self
, struct options
*o
);
144 static void connect_ports(pa_module
* self
);
145 static int start_filling_ringbuffer(pa_module
* self
);
147 /* Various callbacks. */
148 static void jack_error_func(const char* t
);
149 static pa_usec_t
sink_get_latency_cb(pa_sink
* s
);
150 static int jack_process(jack_nframes_t nframes
, void* arg
);
151 static int jack_blocksize_cb(jack_nframes_t nframes
, void* arg
);
152 static void jack_shutdown(void* arg
);
153 static void io_event_cb(pa_mainloop_api
* m
, pa_io_event
* e
, int fd
,
154 pa_io_event_flags_t flags
, void* userdata
);
156 /* The ringbuffer filler thread runs in this function. */
157 static void* fill_ringbuffer(void* arg
);
159 /* request_render asks asynchronously the mainloop to call io_event_cb. */
160 static void request_render(struct userdata
* u
);
163 int pa__init(pa_core
* c
, pa_module
* self
) {
164 struct userdata
* u
= NULL
;
172 o
.server_name
= NULL
;
173 o
.client_name
= NULL
;
175 self
->userdata
= pa_xnew0(struct userdata
, 1);
178 u
->pipe_fds
[0] = u
->pipe_fds
[1] = -1;
180 u
->ringbuffer_is_full
= 0;
181 u
->filler_thread_is_running
= 0;
182 u
->quit_requested
= 0;
183 pthread_mutex_init(&u
->buffersize_mutex
, NULL
);
184 pthread_mutex_init(&u
->cond_mutex
, NULL
);
185 pthread_cond_init(&u
->ringbuffer_cond
, NULL
);
187 if (parse_options(&o
, self
->argument
) != 0)
190 jack_set_error_function(jack_error_func
);
192 if (!(u
->j_client
= jack_client_open(
194 o
.server_name
? JackServerName
: JackNullOption
,
195 NULL
, o
.server_name
))) {
196 pa_log_error("jack_client_open() failed.");
199 pa_log_info("Successfully connected as '%s'",
200 jack_get_client_name(u
->j_client
));
202 if (!o
.channels_given
)
203 set_default_channels(self
, &o
);
205 u
->channels
= o
.channels
;
208 pa_channel_map_init_auto(&o
.map
, u
->channels
, PA_CHANNEL_MAP_ALSA
);
210 for (i
= 0; i
< u
->channels
; i
++) {
211 char* port_name
= pa_sprintf_malloc(
213 pa_channel_position_to_string(o
.map
.map
[i
]));
215 if (!(u
->j_ports
[i
] = jack_port_register(
216 u
->j_client
, port_name
,
217 JACK_DEFAULT_AUDIO_TYPE
,
218 JackPortIsOutput
|JackPortIsTerminal
, 0))) {
219 pa_log("jack_port_register() failed.");
226 if (pipe(u
->pipe_fds
) < 0) {
227 pa_log("pipe() failed: %s", pa_cstrerror(errno
));
230 pa_make_nonblock_fd(u
->pipe_fds
[1]);
232 if (create_sink(self
, &o
) != 0)
235 u
->frame_size
= pa_frame_size(&u
->sink
->sample_spec
);
236 u
->j_buffersize
= jack_get_buffer_size(u
->j_client
);
238 /* If the ringbuffer size were equal to the jack buffer size, a full block
239 would never fit in the ringbuffer, because the ringbuffer can never be
240 totally full: one slot is always wasted. */
241 if (o
.buffersize
<= u
->j_buffersize
) {
242 o
.buffersize
= u
->j_buffersize
+ 1;
244 /* The actual ringbuffer size will be rounded up to the nearest power of
246 if (!(u
->ringbuffer
= jack_ringbuffer_create(
247 o
.buffersize
* u
->frame_size
))) {
248 pa_log("jack_ringbuffer_create() failed.");
251 assert((u
->ringbuffer
->size
% sizeof(float)) == 0);
252 pa_log_info("buffersize is %u frames (%u samples, %u bytes).",
253 u
->ringbuffer
->size
/ u
->frame_size
,
254 u
->ringbuffer
->size
/ sizeof(float),
255 u
->ringbuffer
->size
);
257 jack_set_process_callback(u
->j_client
, jack_process
, u
);
258 jack_set_buffer_size_callback(u
->j_client
, jack_blocksize_cb
, u
);
259 jack_on_shutdown(u
->j_client
, jack_shutdown
, u
);
261 if (jack_activate(u
->j_client
)) {
262 pa_log("jack_activate() failed.");
269 u
->io_event
= c
->mainloop
->io_new(c
->mainloop
, u
->pipe_fds
[0],
270 PA_IO_EVENT_INPUT
, io_event_cb
, self
);
272 if (start_filling_ringbuffer(self
) != 0)
275 pa_xfree(o
.sink_name
);
276 pa_xfree(o
.server_name
);
277 pa_xfree(o
.client_name
);
282 pa_xfree(o
.sink_name
);
283 pa_xfree(o
.server_name
);
284 pa_xfree(o
.client_name
);
291 static int parse_options(struct options
* o
, const char* argument
) {
292 pa_modargs
*ma
= NULL
;
298 if (!(ma
= pa_modargs_new(argument
, valid_modargs
))) {
299 pa_log_error("Failed to parse module arguments.");
303 strbuf
= pa_strbuf_new();
304 if ((arg_val
= pa_modargs_get_value(ma
, "sink_name", NULL
))) {
305 pa_strbuf_puts(strbuf
, arg_val
);
306 o
->sink_name
= pa_strbuf_tostring(strbuf
);
307 o
->sink_name_given
= 1;
309 pa_strbuf_puts(strbuf
, DEFAULT_SINK_NAME
);
310 o
->sink_name
= pa_strbuf_tostring(strbuf
);
311 o
->sink_name_given
= 0;
313 pa_strbuf_free(strbuf
);
315 strbuf
= pa_strbuf_new();
316 if ((arg_val
= pa_modargs_get_value(ma
, "server_name", NULL
))) {
317 pa_strbuf_puts(strbuf
, arg_val
);
318 o
->server_name
= pa_strbuf_tostring(strbuf
);
319 o
->server_name_given
= 1;
321 o
->server_name
= NULL
;
322 o
->server_name_given
= 0;
324 pa_strbuf_free(strbuf
);
326 strbuf
= pa_strbuf_new();
327 if ((arg_val
= pa_modargs_get_value(ma
, "client_name", NULL
))) {
328 pa_strbuf_puts(strbuf
, arg_val
);
329 o
->client_name
= pa_strbuf_tostring(strbuf
);
330 o
->client_name_given
= 1;
332 pa_strbuf_puts(strbuf
, DEFAULT_CLIENT_NAME
);
333 o
->client_name
= pa_strbuf_tostring(strbuf
);
334 o
->client_name_given
= 1;
336 pa_strbuf_free(strbuf
);
338 if (pa_modargs_get_value(ma
, "channels", NULL
)) {
339 o
->channels_given
= 1;
340 if (pa_modargs_get_value_u32(ma
, "channels", &o
->channels
) < 0 ||
342 o
->channels
>= PA_CHANNELS_MAX
) {
343 pa_log_error("Failed to parse the \"channels\" argument.");
347 o
->channels
= 0; /* The actual default value is the number of physical
348 input ports in jack (unknown at the moment), or if
349 that's zero, then the default_sample_spec.channels
351 o
->channels_given
= 0;
354 if (pa_modargs_get_value(ma
, "connect", NULL
)) {
355 o
->connect_given
= 1;
356 if (pa_modargs_get_value_boolean(ma
, "connect", &o
->connect
) < 0) {
357 pa_log_error("Failed to parse the \"connect\" argument.");
362 o
->connect_given
= 0;
365 if (pa_modargs_get_value(ma
, "buffersize", NULL
)) {
366 o
->buffersize_given
= 1;
367 if (pa_modargs_get_value_u32(ma
, "buffersize", &o
->buffersize
) < 0) {
368 pa_log_error("Failed to parse the \"buffersize\" argument.");
372 o
->buffersize
= DEFAULT_RINGBUFFER_SIZE
;
373 o
->buffersize_given
= 0;
376 if (pa_modargs_get_value(ma
, "channel_map", NULL
)) {
378 if (pa_modargs_get_channel_map(ma
, &o
->map
) < 0) {
379 pa_log_error("Failed to parse the \"channel_map\" argument.");
383 /* channel_map specifies the channel count too. */
384 if (o
->channels_given
&& (o
->channels
!= o
->map
.channels
)) {
386 "\"channels\" and \"channel_map\" arguments conficted. If you "
387 "use the \"channel_map\" argument, you can omit the "
388 "\"channels\" argument.");
391 o
->channels
= o
->map
.channels
;
392 o
->channels_given
= 1;
395 /* The actual default value is the default alsa mappings, but that
396 can't be set until the channel count is known. Here we initialize
397 the map to some valid value, although the value won't be used. */
398 pa_channel_map_init_stereo(&o
->map
);
414 static void set_default_channels(pa_module
* self
, struct options
* o
) {
416 const char **ports
, **p
;
420 assert(self
->userdata
);
429 ports
= jack_get_ports(u
->j_client
, NULL
, JACK_DEFAULT_AUDIO_TYPE
,
430 JackPortIsPhysical
|JackPortIsInput
);
432 for (p
= ports
; *p
; p
++)
437 if (o
->channels
>= PA_CHANNELS_MAX
)
438 o
->channels
= PA_CHANNELS_MAX
- 1;
440 if (o
->channels
== 0)
441 o
->channels
= self
->core
->default_sample_spec
.channels
;
445 static int create_sink(pa_module
* self
, struct options
* o
) {
452 assert(self
->userdata
);
458 ss
.channels
= u
->channels
;
459 ss
.rate
= jack_get_sample_rate(u
->j_client
);
460 ss
.format
= PA_SAMPLE_FLOAT32NE
;
461 assert(pa_sample_spec_valid(&ss
));
463 if (!(u
->sink
= pa_sink_new(self
->core
, __FILE__
, o
->sink_name
, 0, &ss
,
465 pa_log("failed to create sink.");
469 u
->sink
->userdata
= u
;
470 pa_sink_set_owner(u
->sink
, self
);
472 pa_sink_set_description(
474 t
= pa_sprintf_malloc("Jack sink (%s)",
475 jack_get_client_name(u
->j_client
)));
478 u
->sink
->get_latency
= sink_get_latency_cb
;
484 static void connect_ports(pa_module
* self
) {
487 const char **ports
, **p
;
490 assert(self
->userdata
);
496 ports
= jack_get_ports(u
->j_client
, NULL
, JACK_DEFAULT_AUDIO_TYPE
,
497 JackPortIsPhysical
|JackPortIsInput
);
499 for (i
= 0, p
= ports
; i
< u
->channels
; i
++, p
++) {
500 assert(u
->j_ports
[i
]);
503 pa_log("Not enough physical output ports, leaving unconnected.");
507 pa_log_info("connecting %s to %s",
508 jack_port_name(u
->j_ports
[i
]), *p
);
510 if (jack_connect(u
->j_client
, jack_port_name(u
->j_ports
[i
]), *p
)) {
511 pa_log("Failed to connect %s to %s, leaving unconnected.",
512 jack_port_name(u
->j_ports
[i
]), *p
);
521 static int start_filling_ringbuffer(pa_module
* self
) {
523 pthread_attr_t thread_attributes
;
526 assert(self
->userdata
);
530 pthread_attr_init(&thread_attributes
);
532 if (pthread_attr_setinheritsched(&thread_attributes
,
533 PTHREAD_INHERIT_SCHED
) != 0) {
534 pa_log("pthread_attr_setinheritsched() failed.");
537 else if (pthread_create(&u
->filler_thread
, &thread_attributes
,
538 fill_ringbuffer
, u
) != 0) {
539 pa_log("pthread_create() failed.");
543 u
->filler_thread_is_running
= 1;
545 pthread_attr_destroy(&thread_attributes
);
550 pthread_attr_destroy(&thread_attributes
);
555 static void jack_error_func(const char* t
) {
556 pa_log_warn("JACK error >%s<", t
);
560 static pa_usec_t
sink_get_latency_cb(pa_sink
* s
) {
561 /* The latency is approximately the sum of the first port's latency,
562 buffersize of jack and the ringbuffer size. Maybe instead of using just
563 the first port, the max of all ports' latencies should be used? */
572 l
= jack_port_get_total_latency(u
->j_client
, u
->j_ports
[0]) +
573 u
->j_buffersize
+ u
->ringbuffer
->size
/ u
->frame_size
;
575 return pa_bytes_to_usec(l
* u
->frame_size
, &s
->sample_spec
);
579 static int jack_process(jack_nframes_t nframes
, void* arg
) {
580 struct userdata
* u
= arg
;
581 float* j_buffers
[PA_CHANNELS_MAX
];
582 unsigned nsamples
= u
->channels
* nframes
;
583 unsigned sample_idx_part1
, sample_idx_part2
;
584 jack_nframes_t frame_idx
;
585 jack_ringbuffer_data_t data
[2]; /* In case the readable area in the
586 ringbuffer is non-continuous, the data
587 will be split in two parts. */
589 unsigned samples_left_over
;
591 for (chan
= 0; chan
< u
->channels
; chan
++) {
592 j_buffers
[chan
] = jack_port_get_buffer(u
->j_ports
[chan
], nframes
);
595 jack_ringbuffer_get_read_vector(u
->ringbuffer
, data
);
597 /* We assume that the possible discontinuity doesn't happen in the middle
598 * of a sample. Should be a safe assumption. */
599 assert(((data
[0].len
% sizeof(float)) == 0) ||
602 /* Copy from the first part of data until enough samples are copied or the
604 sample_idx_part1
= 0;
607 while (sample_idx_part1
< nsamples
&&
608 ((sample_idx_part1
+ 1) * sizeof(float)) <= data
[0].len
) {
609 float *s
= ((float*) data
[0].buf
) + sample_idx_part1
;
610 float *d
= j_buffers
[chan
] + frame_idx
;
614 chan
= (chan
+ 1) % u
->channels
;
615 frame_idx
= sample_idx_part1
/ u
->channels
;
618 samples_left_over
= nsamples
- sample_idx_part1
;
620 /* Copy from the second part of data until enough samples are copied or the
622 sample_idx_part2
= 0;
623 while (sample_idx_part2
< samples_left_over
&&
624 ((sample_idx_part2
+ 1) * sizeof(float)) <= data
[1].len
) {
625 float *s
= ((float*) data
[1].buf
) + sample_idx_part2
;
626 float *d
= j_buffers
[chan
] + frame_idx
;
630 chan
= (chan
+ 1) % u
->channels
;
631 frame_idx
= (sample_idx_part1
+ sample_idx_part2
) / u
->channels
;
634 samples_left_over
-= sample_idx_part2
;
636 /* If there's still samples left, fill the buffers with zeros. */
637 while (samples_left_over
> 0) {
638 float *d
= j_buffers
[chan
] + frame_idx
;
642 chan
= (chan
+ 1) % u
->channels
;
643 frame_idx
= (nsamples
- samples_left_over
) / u
->channels
;
646 jack_ringbuffer_read_advance(
647 u
->ringbuffer
, (sample_idx_part1
+ sample_idx_part2
) * sizeof(float));
649 /* Tell the rendering part that there is room in the ringbuffer. */
650 u
->ringbuffer_is_full
= 0;
651 pthread_cond_signal(&u
->ringbuffer_cond
);
657 static int jack_blocksize_cb(jack_nframes_t nframes
, void* arg
) {
658 /* This gets called in the processing thread, so do we have to be realtime
659 safe? No, we can do whatever we want. User gets silence while we do it.
661 In addition to just updating the j_buffersize field in userdata, we have
662 to create a new ringbuffer, if the new buffer size is bigger or equal to
663 the old ringbuffer size. */
664 struct userdata
* u
= arg
;
668 /* We don't want to change the blocksize and the ringbuffer while rendering
670 pthread_mutex_lock(&u
->buffersize_mutex
);
672 u
->j_buffersize
= nframes
;
674 if ((u
->ringbuffer
->size
/ u
->frame_size
) <= nframes
) {
675 /* We have to create a new ringbuffer. What are we going to do with the
676 old data in the old buffer? We throw it away, because we're lazy
677 coders. The listening experience is likely to get ruined anyway
678 during the blocksize change. */
679 jack_ringbuffer_free(u
->ringbuffer
);
681 /* The actual ringbuffer size will be rounded up to the nearest power
683 if (!(u
->ringbuffer
=
684 jack_ringbuffer_create((nframes
+ 1) * u
->frame_size
))) {
686 "jack_ringbuffer_create() failed while changing jack's buffer "
687 "size, module exiting.");
688 jack_client_close(u
->j_client
);
689 u
->quit_requested
= 1;
691 assert((u
->ringbuffer
->size
% sizeof(float)) == 0);
692 pa_log_info("buffersize is %u frames (%u samples, %u bytes).",
693 u
->ringbuffer
->size
/ u
->frame_size
,
694 u
->ringbuffer
->size
/ sizeof(float),
695 u
->ringbuffer
->size
);
698 pthread_mutex_unlock(&u
->buffersize_mutex
);
704 static void jack_shutdown(void* arg
) {
705 struct userdata
* u
= arg
;
708 u
->quit_requested
= 1;
713 static void io_event_cb(pa_mainloop_api
* m
, pa_io_event
* e
, int fd
,
714 pa_io_event_flags_t flags
, void* userdata
) {
715 pa_module
* self
= userdata
;
718 jack_ringbuffer_data_t buffer
[2]; /* The write area in the ringbuffer may
719 be split in two parts. */
720 pa_memchunk chunk
; /* This is the data source. */
721 unsigned part1_length
, part2_length
;
722 unsigned sample_idx_part1
, sample_idx_part2
;
729 assert(flags
== PA_IO_EVENT_INPUT
);
731 assert(self
->userdata
);
735 assert(u
->pipe_fds
[0] == fd
);
737 pa_read(fd
, &x
, 1, &u
->pipe_fd_type
);
739 if (u
->quit_requested
) {
740 pa_module_unload_request(self
);
744 frame_size
= u
->frame_size
;
746 /* No blocksize changes during rendering, please. */
747 pthread_mutex_lock(&u
->buffersize_mutex
);
749 jack_ringbuffer_get_write_vector(u
->ringbuffer
, buffer
);
750 assert(((buffer
[0].len
% sizeof(float)) == 0) || (buffer
[1].len
== 0));
752 part1_length
= buffer
[0].len
/ sizeof(float);
753 part2_length
= buffer
[1].len
/ sizeof(float);
755 /* If the amount of free space is not a multiple of the frame size, we have
756 to truncate the lengths so that we process only complete frames. */
757 if ((rem
= (part1_length
+ part2_length
) % u
->channels
) != 0) {
758 if (part2_length
>= rem
) {
761 part1_length
-= rem
- part2_length
;
766 /* pa_sink_render_full doesn't accept zero length, so we have do the
767 copying only if there's data to copy, which actually makes a kind of
769 if (part1_length
> 0 || part2_length
> 0) {
770 pa_sink_render_full(u
->sink
,
771 (part1_length
+ part2_length
) * sizeof(float),
774 /* Write to the first part of the buffer. */
775 for (sample_idx_part1
= 0;
776 sample_idx_part1
< part1_length
;
777 sample_idx_part1
++) {
779 ((float*) ((uint8_t*) chunk
.memblock
->data
+ chunk
.index
)) +
781 float *d
= ((float*) buffer
[0].buf
) + sample_idx_part1
;
785 /* Write to the second part of the buffer. */
786 for (sample_idx_part2
= 0;
787 sample_idx_part2
< part2_length
;
788 sample_idx_part2
++) {
790 ((float*) ((uint8_t*) chunk
.memblock
->data
+ chunk
.index
)) +
791 sample_idx_part1
+ sample_idx_part2
;
792 float *d
= ((float*) buffer
[1].buf
) + sample_idx_part2
;
796 pa_memblock_unref(chunk
.memblock
);
798 jack_ringbuffer_write_advance(
799 u
->ringbuffer
, (part1_length
+ part2_length
) * sizeof(float));
802 /* Blocksize can be changed again. */
803 pthread_mutex_unlock(&u
->buffersize_mutex
);
807 static void* fill_ringbuffer(void* arg
) {
808 struct userdata
* u
= arg
;
812 while (!u
->quit_requested
) {
813 if (u
->ringbuffer_is_full
) {
814 pthread_mutex_lock(&u
->cond_mutex
);
815 pthread_cond_wait(&u
->ringbuffer_cond
,
817 pthread_mutex_unlock(&u
->cond_mutex
);
819 /* No, it's not full yet, but this must be set to one as soon as
820 possible, because if the jack thread manages to process another
821 block before we set this to one, we may end up waiting without
823 u
->ringbuffer_is_full
= 1;
832 static void request_render(struct userdata
* u
) {
837 assert(u
->pipe_fds
[1] >= 0);
838 pa_write(u
->pipe_fds
[1], &c
, 1, &u
->pipe_fd_type
);
841 void pa__done(pa_core
* c
, pa_module
* self
) {
852 if (u
->filler_thread_is_running
) {
853 u
->quit_requested
= 1;
854 pthread_cond_signal(&u
->ringbuffer_cond
);
855 pthread_join(u
->filler_thread
, NULL
);
859 jack_client_close(u
->j_client
);
862 c
->mainloop
->io_free(u
->io_event
);
865 pa_sink_disconnect(u
->sink
);
866 pa_sink_unref(u
->sink
);
870 jack_ringbuffer_free(u
->ringbuffer
);
872 if (u
->pipe_fds
[0] >= 0)
873 pa_close(u
->pipe_fds
[0]);
874 if (u
->pipe_fds
[1] >= 0)
875 pa_close(u
->pipe_fds
[1]);
877 pthread_mutex_destroy(&u
->buffersize_mutex
);
878 pthread_cond_destroy(&u
->ringbuffer_cond
);
879 pthread_mutex_destroy(&u
->cond_mutex
);
880 pa_xfree(self
->userdata
);
881 self
->userdata
= NULL
;