]> code.delx.au - pulseaudio/blob - src/pulsecore/packet.c
Huge trailing whitespace cleanup. Let's keep the tree pure from here on,
[pulseaudio] / src / pulsecore / packet.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <stdlib.h>
28
29 #include <pulse/xmalloc.h>
30
31 #include "packet.h"
32
33 pa_packet* pa_packet_new(size_t length) {
34 pa_packet *p;
35
36 assert(length);
37
38 p = pa_xmalloc(sizeof(pa_packet)+length);
39 p->ref = 1;
40 p->length = length;
41 p->data = (uint8_t*) (p+1);
42 p->type = PA_PACKET_APPENDED;
43
44 return p;
45 }
46
47 pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
48 pa_packet *p;
49
50 assert(data);
51 assert(length);
52
53 p = pa_xnew(pa_packet, 1);
54 p->ref = 1;
55 p->length = length;
56 p->data = data;
57 p->type = PA_PACKET_DYNAMIC;
58
59 return p;
60 }
61
62 pa_packet* pa_packet_ref(pa_packet *p) {
63 assert(p);
64 assert(p->ref >= 1);
65
66 p->ref++;
67 return p;
68 }
69
70 void pa_packet_unref(pa_packet *p) {
71 assert(p);
72 assert(p->ref >= 1);
73
74 if (--p->ref == 0) {
75 if (p->type == PA_PACKET_DYNAMIC)
76 pa_xfree(p->data);
77 pa_xfree(p);
78 }
79 }