- Removed bufferpool code and move that to gstbuffer.c
[platform/upstream/gstreamer.git] / gst / gstdata.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstdata.h: Header for GstData objects (used for data passing)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #ifndef __GST_DATA_H__
25 #define __GST_DATA_H__
26
27 #include <glib-object.h>
28 #include <gst/gstatomic.h>
29
30 G_BEGIN_DECLS
31
32 /* type */
33 #define GST_DATA(data)          ((GstData*)(data))
34 #define GST_DATA_TYPE(data)     (GST_DATA(data)->type)
35
36 /* flags */
37 #define GST_DATA_FLAGS(data)            (GST_DATA(data)->flags)
38 #define GST_DATA_FLAG_SHIFT(flag)       (1<<(flag))
39 #define GST_DATA_FLAG_IS_SET(data,flag) (GST_DATA_FLAGS(data) & (1<<(flag)))
40 #define GST_DATA_FLAG_SET(data,flag)    G_STMT_START{ (GST_DATA_FLAGS(data) |= (1<<(flag))); }G_STMT_END
41 #define GST_DATA_FLAG_UNSET(data,flag)  G_STMT_START{ (GST_DATA_FLAGS(data) &= ~(1<<(flag))); }G_STMT_END
42
43 typedef struct _GstData GstData;
44
45 typedef void            (*GstDataFreeFunction)          (GstData *data);
46 typedef GstData*        (*GstDataCopyFunction)          (const GstData *data);
47
48 typedef enum
49 {
50   GST_DATA_READONLY     = 1,
51
52   /* insert more */
53   GST_DATA_FLAG_LAST    = 8,
54 } GstDataFlags;
55
56 #define GST_DATA_IS_READONLY(data)              (GST_DATA_FLAG_IS_SET((data), GST_DATA_READONLY))
57
58 /* refcount */
59 #define GST_DATA_REFCOUNT(data)                 ((GST_DATA(data))->refcount)
60 #define GST_DATA_REFCOUNT_VALUE(data)           (GST_ATOMIC_INT_VALUE((&GST_DATA_REFCOUNT (data))))
61 #define GST_DATA_REFCOUNT_READ(data,value)      (GST_ATOMIC_INT_READ(&(GST_DATA_REFCOUNT (data)),value)
62
63 /* copy/free functions */
64 #define GST_DATA_COPY_FUNC(data)                (GST_DATA(data)->copy)
65 #define GST_DATA_FREE_FUNC(data)                (GST_DATA(data)->free)
66
67
68 struct _GstData {
69   GType                  type;
70
71   /* refcounting */
72   GstAtomicInt           refcount;
73
74   guint16                flags;
75  
76   /* utility function pointers, can override default */
77   GstDataFreeFunction    free;          /* free the data */
78   GstDataCopyFunction    copy;          /* free the data */
79 };
80
81 /* function used by subclasses only */
82 void                    _gst_data_init                  (GstData *data, GType type, guint16 flags,
83                                                          GstDataFreeFunction free,
84                                                          GstDataCopyFunction copy);
85 void                    _gst_data_free                  (GstData *data);
86 GstData*                _gst_data_copy                  (const GstData *data);
87
88 /* basic operations on data */
89 GstData*                gst_data_copy                   (const GstData *data);
90 GstData*                gst_data_copy_on_write          (const GstData *data);
91 void                    gst_data_free                   (GstData *data);
92
93 /* reference counting */
94 GstData*                gst_data_ref                    (GstData* data);
95 GstData*                gst_data_ref_by_count           (GstData* data, gint count);
96 void                    gst_data_unref                  (GstData* data);
97
98 G_END_DECLS
99
100 #endif /* __GST_DATA_H__ */