annotate src/mediastreamer/msbuffer.c @ 12586:218d0aec518d

[gaim-migrate @ 14914] ignore tweaks... committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Wed, 21 Dec 2005 00:08:21 +0000
parents e67993da8a22
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12024
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 The mediastreamer library aims at providing modular media processing and I/O
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 for linphone, but also for any telephony application.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 Lesser General Public License for more details.
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 You should have received a copy of the GNU Lesser General Public
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 License along with this library; if not, write to the Free Software
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 #include "msbuffer.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include "msutils.h"
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include <string.h>
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 MSBuffer * ms_buffer_new(guint32 size)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 MSBuffer *buf;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 buf=(MSBuffer*)g_malloc(sizeof(MSBuffer)+size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 buf->ref_count=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 buf->size=size;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 ms_trace("ms_buffer_new: Allocating buffer of %i bytes.",size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 /* allocate the data buffer: there is a lot of optmisation that can be done by using a pool of cached buffers*/
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 buf->buffer=((char*)(buf))+sizeof(MSBuffer); /* to avoid to do two allocations,
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 buffer info and buffer are contigous.*/
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 buf->flags=MS_BUFFER_CONTIGUOUS;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 return(buf);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 MSBuffer *ms_buffer_alloc(gint flags)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 MSBuffer *buf;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 buf=(MSBuffer*)g_malloc(sizeof(MSBuffer));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 buf->ref_count=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 buf->size=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 buf->buffer=NULL;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 buf->flags=0;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 return(buf);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 void ms_buffer_destroy(MSBuffer *buf)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 if (buf->flags & MS_BUFFER_CONTIGUOUS){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 g_free(buf);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 else {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 g_free(buf->buffer);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 g_free(buf);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 MSMessage *ms_message_alloc()
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 MSMessage *m=g_malloc(sizeof(MSMessage));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 memset(m,0,sizeof(MSMessage));
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 return m;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 MSMessage *ms_message_new(gint size)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 MSMessage *m=ms_message_alloc();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 MSBuffer *buf=ms_buffer_new(size);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 ms_message_set_buf(m,buf);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 return m;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 void ms_message_destroy(MSMessage *m)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 /* the buffer is freed if its ref_count goes to zero */
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 if (m->buffer!=NULL){
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 m->buffer->ref_count--;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 if (m->buffer->ref_count==0) ms_buffer_destroy(m->buffer);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 g_free(m);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 }
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 MSMessage * ms_message_dup(MSMessage *m)
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 {
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 MSMessage *msg=ms_message_alloc();
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 ms_message_set_buf(msg,m->buffer);
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 return msg;
e67993da8a22 [gaim-migrate @ 14317]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 }