4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #ifdef HAVE_SYS_SOCKET_H
32 #include <sys/socket.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
43 #include <pulse/xmalloc.h>
45 #include <pulsecore/queue.h>
46 #include <pulsecore/log.h>
47 #include <pulsecore/core-scache.h>
48 #include <pulsecore/creds.h>
52 /* We piggyback information if audio data blocks are stored in SHM on the seek mode */
53 #define PA_FLAG_SHMDATA 0x80000000LU
54 #define PA_FLAG_SHMRELEASE 0x40000000LU
55 #define PA_FLAG_SHMREVOKE 0xC0000000LU
56 #define PA_FLAG_SHMMASK 0xFF000000LU
57 #define PA_FLAG_SEEKMASK 0x000000FFLU
59 /* The sequence descriptor header consists of 5 32bit integers: */
61 PA_PSTREAM_DESCRIPTOR_LENGTH
,
62 PA_PSTREAM_DESCRIPTOR_CHANNEL
,
63 PA_PSTREAM_DESCRIPTOR_OFFSET_HI
,
64 PA_PSTREAM_DESCRIPTOR_OFFSET_LO
,
65 PA_PSTREAM_DESCRIPTOR_FLAGS
,
66 PA_PSTREAM_DESCRIPTOR_MAX
69 /* If we have an SHM block, this info follows the descriptor */
71 PA_PSTREAM_SHM_BLOCKID
,
74 PA_PSTREAM_SHM_LENGTH
,
78 typedef uint32_t pa_pstream_descriptor
[PA_PSTREAM_DESCRIPTOR_MAX
];
80 #define PA_PSTREAM_DESCRIPTOR_SIZE (PA_PSTREAM_DESCRIPTOR_MAX*sizeof(uint32_t))
81 #define FRAME_SIZE_MAX_ALLOW PA_SCACHE_ENTRY_SIZE_MAX /* allow uploading a single sample in one frame at max */
82 #define FRAME_SIZE_MAX_USE (1024*64)
86 PA_PSTREAM_ITEM_PACKET
,
87 PA_PSTREAM_ITEM_MEMBLOCK
,
88 PA_PSTREAM_ITEM_SHMRELEASE
,
89 PA_PSTREAM_ITEM_SHMREVOKE
104 pa_seek_mode_t seek_mode
;
106 /* release/revoke info */
113 pa_mainloop_api
*mainloop
;
114 pa_defer_event
*defer_event
;
116 pa_queue
*send_queue
;
121 pa_pstream_descriptor descriptor
;
122 struct item_info
* current
;
123 uint32_t shm_info
[PA_PSTREAM_SHM_MAX
];
129 pa_pstream_descriptor descriptor
;
130 pa_memblock
*memblock
;
132 uint32_t shm_info
[PA_PSTREAM_SHM_MAX
];
138 pa_memimport
*import
;
139 pa_memexport
*export
;
141 pa_pstream_packet_cb_t recieve_packet_callback
;
142 void *recieve_packet_callback_userdata
;
144 pa_pstream_memblock_cb_t recieve_memblock_callback
;
145 void *recieve_memblock_callback_userdata
;
147 pa_pstream_notify_cb_t drain_callback
;
148 void *drain_callback_userdata
;
150 pa_pstream_notify_cb_t die_callback
;
151 void *die_callback_userdata
;
156 pa_creds read_creds
, write_creds
;
157 int read_creds_valid
, send_creds_now
;
161 static int do_write(pa_pstream
*p
);
162 static int do_read(pa_pstream
*p
);
164 static void do_something(pa_pstream
*p
) {
167 p
->mainloop
->defer_enable(p
->defer_event
, 0);
171 if (!p
->dead
&& pa_iochannel_is_readable(p
->io
)) {
174 } else if (!p
->dead
&& pa_iochannel_is_hungup(p
->io
))
177 if (!p
->dead
&& pa_iochannel_is_writable(p
->io
)) {
190 p
->die_callback(p
, p
->die_callback_userdata
);
195 static void io_callback(pa_iochannel
*io
, void *userdata
) {
196 pa_pstream
*p
= userdata
;
204 static void defer_callback(pa_mainloop_api
*m
, pa_defer_event
*e
, void*userdata
) {
205 pa_pstream
*p
= userdata
;
208 assert(p
->defer_event
== e
);
209 assert(p
->mainloop
== m
);
214 static void memimport_release_cb(pa_memimport
*i
, uint32_t block_id
, void *userdata
);
216 pa_pstream
*pa_pstream_new(pa_mainloop_api
*m
, pa_iochannel
*io
, pa_mempool
*pool
) {
223 p
= pa_xnew(pa_pstream
, 1);
226 pa_iochannel_set_callback(io
, io_callback
, p
);
230 p
->defer_event
= m
->defer_new(m
, defer_callback
, p
);
231 m
->defer_enable(p
->defer_event
, 0);
233 p
->send_queue
= pa_queue_new();
234 assert(p
->send_queue
);
236 p
->write
.current
= NULL
;
238 p
->read
.memblock
= NULL
;
239 p
->read
.packet
= NULL
;
242 p
->recieve_packet_callback
= NULL
;
243 p
->recieve_packet_callback_userdata
= NULL
;
244 p
->recieve_memblock_callback
= NULL
;
245 p
->recieve_memblock_callback_userdata
= NULL
;
246 p
->drain_callback
= NULL
;
247 p
->drain_callback_userdata
= NULL
;
248 p
->die_callback
= NULL
;
249 p
->die_callback_userdata
= NULL
;
256 /* We do importing unconditionally */
257 p
->import
= pa_memimport_new(p
->mempool
, memimport_release_cb
, p
);
259 pa_iochannel_socket_set_rcvbuf(io
, 1024*8);
260 pa_iochannel_socket_set_sndbuf(io
, 1024*8);
263 p
->send_creds_now
= 0;
264 p
->read_creds_valid
= 0;
269 static void item_free(void *item
, PA_GCC_UNUSED
void *p
) {
270 struct item_info
*i
= item
;
273 if (i
->type
== PA_PSTREAM_ITEM_MEMBLOCK
) {
274 assert(i
->chunk
.memblock
);
275 pa_memblock_unref(i
->chunk
.memblock
);
276 } else if (i
->type
== PA_PSTREAM_ITEM_PACKET
) {
278 pa_packet_unref(i
->packet
);
284 static void pstream_free(pa_pstream
*p
) {
289 pa_queue_free(p
->send_queue
, item_free
, NULL
);
291 if (p
->write
.current
)
292 item_free(p
->write
.current
, NULL
);
294 if (p
->read
.memblock
)
295 pa_memblock_unref(p
->read
.memblock
);
298 pa_packet_unref(p
->read
.packet
);
303 void pa_pstream_send_packet(pa_pstream
*p
, pa_packet
*packet
, const pa_creds
*creds
) {
313 i
= pa_xnew(struct item_info
, 1);
314 i
->type
= PA_PSTREAM_ITEM_PACKET
;
315 i
->packet
= pa_packet_ref(packet
);
318 if ((i
->with_creds
= !!creds
))
322 pa_queue_push(p
->send_queue
, i
);
323 p
->mainloop
->defer_enable(p
->defer_event
, 1);
326 void pa_pstream_send_memblock(pa_pstream
*p
, uint32_t channel
, int64_t offset
, pa_seek_mode_t seek_mode
, const pa_memchunk
*chunk
) {
331 assert(channel
!= (uint32_t) -1);
337 length
= chunk
->length
;
344 i
= pa_xnew(struct item_info
, 1);
345 i
->type
= PA_PSTREAM_ITEM_MEMBLOCK
;
347 n
= length
< FRAME_SIZE_MAX_USE
? length
: FRAME_SIZE_MAX_USE
;
348 i
->chunk
.index
= chunk
->index
+ idx
;
350 i
->chunk
.memblock
= pa_memblock_ref(chunk
->memblock
);
352 i
->channel
= channel
;
354 i
->seek_mode
= seek_mode
;
359 pa_queue_push(p
->send_queue
, i
);
365 p
->mainloop
->defer_enable(p
->defer_event
, 1);
368 static void memimport_release_cb(pa_memimport
*i
, uint32_t block_id
, void *userdata
) {
369 struct item_info
*item
;
370 pa_pstream
*p
= userdata
;
378 /* pa_log("Releasing block %u", block_id); */
380 item
= pa_xnew(struct item_info
, 1);
381 item
->type
= PA_PSTREAM_ITEM_SHMRELEASE
;
382 item
->block_id
= block_id
;
384 item
->with_creds
= 0;
387 pa_queue_push(p
->send_queue
, item
);
388 p
->mainloop
->defer_enable(p
->defer_event
, 1);
391 static void memexport_revoke_cb(pa_memexport
*e
, uint32_t block_id
, void *userdata
) {
392 struct item_info
*item
;
393 pa_pstream
*p
= userdata
;
401 /* pa_log("Revoking block %u", block_id); */
403 item
= pa_xnew(struct item_info
, 1);
404 item
->type
= PA_PSTREAM_ITEM_SHMREVOKE
;
405 item
->block_id
= block_id
;
407 item
->with_creds
= 0;
410 pa_queue_push(p
->send_queue
, item
);
411 p
->mainloop
->defer_enable(p
->defer_event
, 1);
414 static void prepare_next_write_item(pa_pstream
*p
) {
417 if (!(p
->write
.current
= pa_queue_pop(p
->send_queue
)))
421 p
->write
.data
= NULL
;
423 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
] = 0;
424 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_CHANNEL
] = htonl((uint32_t) -1);
425 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
] = 0;
426 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_LO
] = 0;
427 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
] = 0;
429 if (p
->write
.current
->type
== PA_PSTREAM_ITEM_PACKET
) {
431 assert(p
->write
.current
->packet
);
432 p
->write
.data
= p
->write
.current
->packet
->data
;
433 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
] = htonl(p
->write
.current
->packet
->length
);
435 } else if (p
->write
.current
->type
== PA_PSTREAM_ITEM_SHMRELEASE
) {
437 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
] = htonl(PA_FLAG_SHMRELEASE
);
438 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
] = htonl(p
->write
.current
->block_id
);
440 } else if (p
->write
.current
->type
== PA_PSTREAM_ITEM_SHMREVOKE
) {
442 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
] = htonl(PA_FLAG_SHMREVOKE
);
443 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
] = htonl(p
->write
.current
->block_id
);
447 int send_payload
= 1;
449 assert(p
->write
.current
->type
== PA_PSTREAM_ITEM_MEMBLOCK
);
450 assert(p
->write
.current
->chunk
.memblock
);
452 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_CHANNEL
] = htonl(p
->write
.current
->channel
);
453 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
] = htonl((uint32_t) (((uint64_t) p
->write
.current
->offset
) >> 32));
454 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_LO
] = htonl((uint32_t) ((uint64_t) p
->write
.current
->offset
));
456 flags
= p
->write
.current
->seek_mode
& PA_FLAG_SEEKMASK
;
459 uint32_t block_id
, shm_id
;
460 size_t offset
, length
;
464 if (pa_memexport_put(p
->export
,
465 p
->write
.current
->chunk
.memblock
,
471 flags
|= PA_FLAG_SHMDATA
;
474 p
->write
.shm_info
[PA_PSTREAM_SHM_BLOCKID
] = htonl(block_id
);
475 p
->write
.shm_info
[PA_PSTREAM_SHM_SHMID
] = htonl(shm_id
);
476 p
->write
.shm_info
[PA_PSTREAM_SHM_INDEX
] = htonl((uint32_t) (offset
+ p
->write
.current
->chunk
.index
));
477 p
->write
.shm_info
[PA_PSTREAM_SHM_LENGTH
] = htonl((uint32_t) p
->write
.current
->chunk
.length
);
479 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
] = htonl(sizeof(p
->write
.shm_info
));
480 p
->write
.data
= p
->write
.shm_info
;
483 /* pa_log_warn("Failed to export memory block."); */
487 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
] = htonl(p
->write
.current
->chunk
.length
);
488 p
->write
.data
= (uint8_t*) p
->write
.current
->chunk
.memblock
->data
+ p
->write
.current
->chunk
.index
;
491 p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
] = htonl(flags
);
495 if ((p
->send_creds_now
= p
->write
.current
->with_creds
))
496 p
->write_creds
= p
->write
.current
->creds
;
500 static int do_write(pa_pstream
*p
) {
506 if (!p
->write
.current
)
507 prepare_next_write_item(p
);
509 if (!p
->write
.current
)
512 if (p
->write
.index
< PA_PSTREAM_DESCRIPTOR_SIZE
) {
513 d
= (uint8_t*) p
->write
.descriptor
+ p
->write
.index
;
514 l
= PA_PSTREAM_DESCRIPTOR_SIZE
- p
->write
.index
;
516 assert(p
->write
.data
);
518 d
= (uint8_t*) p
->write
.data
+ p
->write
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
;
519 l
= ntohl(p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
]) - (p
->write
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
);
525 if (p
->send_creds_now
) {
527 if ((r
= pa_iochannel_write_with_creds(p
->io
, d
, l
, &p
->write_creds
)) < 0)
530 p
->send_creds_now
= 0;
534 if ((r
= pa_iochannel_write(p
->io
, d
, l
)) < 0)
539 if (p
->write
.index
>= PA_PSTREAM_DESCRIPTOR_SIZE
+ ntohl(p
->write
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
])) {
540 assert(p
->write
.current
);
541 item_free(p
->write
.current
, (void *) 1);
542 p
->write
.current
= NULL
;
544 if (p
->drain_callback
&& !pa_pstream_is_pending(p
))
545 p
->drain_callback(p
, p
->drain_callback_userdata
);
551 static int do_read(pa_pstream
*p
) {
557 if (p
->read
.index
< PA_PSTREAM_DESCRIPTOR_SIZE
) {
558 d
= (uint8_t*) p
->read
.descriptor
+ p
->read
.index
;
559 l
= PA_PSTREAM_DESCRIPTOR_SIZE
- p
->read
.index
;
561 assert(p
->read
.data
);
562 d
= (uint8_t*) p
->read
.data
+ p
->read
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
;
563 l
= ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
]) - (p
->read
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
);
570 if ((r
= pa_iochannel_read_with_creds(p
->io
, d
, l
, &p
->read_creds
, &b
)) <= 0)
573 p
->read_creds_valid
= p
->read_creds_valid
|| b
;
576 if ((r
= pa_iochannel_read(p
->io
, d
, l
)) <= 0)
582 if (p
->read
.index
== PA_PSTREAM_DESCRIPTOR_SIZE
) {
583 uint32_t flags
, length
, channel
;
584 /* Reading of frame descriptor complete */
586 flags
= ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
]);
588 if (!p
->import
&& (flags
& PA_FLAG_SHMMASK
) != 0) {
589 pa_log_warn("Recieved SHM frame on a socket where SHM is disabled.");
593 if (flags
== PA_FLAG_SHMRELEASE
) {
595 /* This is a SHM memblock release frame with no payload */
597 /* pa_log("Got release frame for %u", ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])); */
600 pa_memexport_process_release(p
->export
, ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
]));
604 } else if (flags
== PA_FLAG_SHMREVOKE
) {
606 /* This is a SHM memblock revoke frame with no payload */
608 /* pa_log("Got revoke frame for %u", ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])); */
611 pa_memimport_process_revoke(p
->import
, ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
]));
616 length
= ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
]);
618 if (length
> FRAME_SIZE_MAX_ALLOW
) {
619 pa_log_warn("Recieved invalid frame size : %lu", (unsigned long) length
);
623 assert(!p
->read
.packet
&& !p
->read
.memblock
);
625 channel
= ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_CHANNEL
]);
627 if (channel
== (uint32_t) -1) {
630 pa_log_warn("Received packet frame with invalid flags value.");
634 /* Frame is a packet frame */
635 p
->read
.packet
= pa_packet_new(length
);
636 p
->read
.data
= p
->read
.packet
->data
;
640 if ((flags
& PA_FLAG_SEEKMASK
) > PA_SEEK_RELATIVE_END
) {
641 pa_log_warn("Received memblock frame with invalid seek mode.");
645 if ((flags
& PA_FLAG_SHMMASK
) == PA_FLAG_SHMDATA
) {
647 if (length
!= sizeof(p
->read
.shm_info
)) {
648 pa_log_warn("Recieved SHM memblock frame with Invalid frame length.");
652 /* Frame is a memblock frame referencing an SHM memblock */
653 p
->read
.data
= p
->read
.shm_info
;
655 } else if ((flags
& PA_FLAG_SHMMASK
) == 0) {
657 /* Frame is a memblock frame */
659 p
->read
.memblock
= pa_memblock_new(p
->mempool
, length
);
660 p
->read
.data
= p
->read
.memblock
->data
;
663 pa_log_warn("Recieved memblock frame with invalid flags value.");
668 } else if (p
->read
.index
> PA_PSTREAM_DESCRIPTOR_SIZE
) {
669 /* Frame payload available */
671 if (p
->read
.memblock
&& p
->recieve_memblock_callback
) {
673 /* Is this memblock data? Than pass it to the user */
674 l
= (p
->read
.index
- r
) < PA_PSTREAM_DESCRIPTOR_SIZE
? p
->read
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
: (size_t) r
;
679 chunk
.memblock
= p
->read
.memblock
;
680 chunk
.index
= p
->read
.index
- PA_PSTREAM_DESCRIPTOR_SIZE
- l
;
683 if (p
->recieve_memblock_callback
) {
687 (((uint64_t) ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
])) << 32) |
688 (((uint64_t) ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_LO
]))));
690 p
->recieve_memblock_callback(
692 ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_CHANNEL
]),
694 ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
]) & PA_FLAG_SEEKMASK
,
696 p
->recieve_memblock_callback_userdata
);
699 /* Drop seek info for following callbacks */
700 p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
] =
701 p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
] =
702 p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_LO
] = 0;
707 if (p
->read
.index
>= ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_LENGTH
]) + PA_PSTREAM_DESCRIPTOR_SIZE
) {
709 if (p
->read
.memblock
) {
711 /* This was a memblock frame. We can unref the memblock now */
712 pa_memblock_unref(p
->read
.memblock
);
714 } else if (p
->read
.packet
) {
716 if (p
->recieve_packet_callback
)
718 p
->recieve_packet_callback(p
, p
->read
.packet
, p
->read_creds_valid
? &p
->read_creds
: NULL
, p
->recieve_packet_callback_userdata
);
720 p
->recieve_packet_callback(p
, p
->read
.packet
, NULL
, p
->recieve_packet_callback_userdata
);
723 pa_packet_unref(p
->read
.packet
);
727 assert((ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
]) & PA_FLAG_SHMMASK
) == PA_FLAG_SHMDATA
);
731 if (!(b
= pa_memimport_get(p
->import
,
732 ntohl(p
->read
.shm_info
[PA_PSTREAM_SHM_BLOCKID
]),
733 ntohl(p
->read
.shm_info
[PA_PSTREAM_SHM_SHMID
]),
734 ntohl(p
->read
.shm_info
[PA_PSTREAM_SHM_INDEX
]),
735 ntohl(p
->read
.shm_info
[PA_PSTREAM_SHM_LENGTH
])))) {
737 pa_log_warn("Failed to import memory block.");
741 if (p
->recieve_memblock_callback
) {
747 chunk
.length
= b
->length
;
750 (((uint64_t) ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI
])) << 32) |
751 (((uint64_t) ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_OFFSET_LO
]))));
753 p
->recieve_memblock_callback(
755 ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_CHANNEL
]),
757 ntohl(p
->read
.descriptor
[PA_PSTREAM_DESCRIPTOR_FLAGS
]) & PA_FLAG_SEEKMASK
,
759 p
->recieve_memblock_callback_userdata
);
762 pa_memblock_unref(b
);
772 p
->read
.memblock
= NULL
;
773 p
->read
.packet
= NULL
;
777 p
->read_creds_valid
= 0;
783 void pa_pstream_set_die_callback(pa_pstream
*p
, pa_pstream_notify_cb_t cb
, void *userdata
) {
787 p
->die_callback
= cb
;
788 p
->die_callback_userdata
= userdata
;
792 void pa_pstream_set_drain_callback(pa_pstream
*p
, pa_pstream_notify_cb_t cb
, void *userdata
) {
796 p
->drain_callback
= cb
;
797 p
->drain_callback_userdata
= userdata
;
800 void pa_pstream_set_recieve_packet_callback(pa_pstream
*p
, pa_pstream_packet_cb_t cb
, void *userdata
) {
804 p
->recieve_packet_callback
= cb
;
805 p
->recieve_packet_callback_userdata
= userdata
;
808 void pa_pstream_set_recieve_memblock_callback(pa_pstream
*p
, pa_pstream_memblock_cb_t cb
, void *userdata
) {
812 p
->recieve_memblock_callback
= cb
;
813 p
->recieve_memblock_callback_userdata
= userdata
;
816 int pa_pstream_is_pending(pa_pstream
*p
) {
822 return p
->write
.current
|| !pa_queue_is_empty(p
->send_queue
);
825 void pa_pstream_unref(pa_pstream
*p
) {
833 pa_pstream
* pa_pstream_ref(pa_pstream
*p
) {
841 void pa_pstream_close(pa_pstream
*p
) {
847 pa_memimport_free(p
->import
);
852 pa_memexport_free(p
->export
);
857 pa_iochannel_free(p
->io
);
861 if (p
->defer_event
) {
862 p
->mainloop
->defer_free(p
->defer_event
);
863 p
->defer_event
= NULL
;
866 p
->die_callback
= NULL
;
867 p
->drain_callback
= NULL
;
868 p
->recieve_packet_callback
= NULL
;
869 p
->recieve_memblock_callback
= NULL
;
874 void pa_pstream_use_shm(pa_pstream
*p
, int enable
) {
883 p
->export
= pa_memexport_new(p
->mempool
, memexport_revoke_cb
, p
);
888 pa_memexport_free(p
->export
);