summaryrefslogtreecommitdiff
path: root/gst/gstdata.h
blob: 759d5186cd549748b6df05112d0946ceecd723ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wim.taymans@chello.be>
 *
 * gstdata.h: Header for GstData objects (used for data passing)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifndef __GST_DATA_H__
#define __GST_DATA_H__

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_ATOMIC_H
#include <asm/atomic.h>
#endif

#include <glib-object.h>


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef enum {
  GST_DATA_UNKNOWN,
  GST_DATA_NONE,		/* uninitialized */
  /* buffer */
  GST_DATA_BUFFER,
  GST_DATA_BUFFERPOOL,
  /* events */
  GST_EVENT_FIRST,
  /* instream events */
  GST_EVENT_EOS,
  GST_EVENT_DISCONTINUOUS,
  GST_EVENT_NEWMEDIA,
  GST_EVENT_LENGTH,
  /* upstream events */
  GST_EVENT_SEEK,
  GST_EVENT_EMPTY,
  GST_EVENT_FLUSH,
  GST_EVENT_LOCK,
  GST_EVENT_UNLOCK,  
  /* custom events */
  GST_EVENT_CUSTOM,
  GST_EVENT_CUSTOM_LAST		= 0xFFFF,
  /* addable events */
} GstDataType;

/* number of types */
#define GST_OFFSET_TYPES 		3					/* number of different GstOffsetType types */
#define GST_OFFSET_INVALID 		(~((guint64) 0))			/* invalid (or unitialized) offset */
#define GST_OFFSET_IS_INVLAID(ofset)	(offset == GST_OFFSET_INVALID)
typedef enum {
  GST_OFFSET_TIME	= 0,
  GST_OFFSET_BYTES	= 1,
  GST_OFFSET_FRAMES	= 2,
} GstOffsetType;

#define GST_DATA_MASK			(GST_EVENT_CUSTOM_LAST)

#define GST_DATA(data)			((GstData*)(data))

#define GST_DATA_TYPE(data)		(((GstData*)(data))->type)
#define GST_DATA_OFFSET_TIME(data)	(((GstData*)(data))->offset[GST_OFFSET_TIME])
#define GST_DATA_OFFSET_BYTES(data)	(((GstData*)(data))->offset[GST_OFFSET_BYTES])
#define GST_DATA_OFFSET_FRAMES(data)	(((GstData*)(data))->offset[GST_OFFSET_FRAMES])

/* flags */
#define GST_DATA_FLAGS(data)		(GST_DATA(data)->flags)
#define GST_DATA_FLAG_IS_SET(data,flag)	(GST_DATA_FLAGS(data) & (1<<(flag)))
#define GST_DATA_FLAG_SET(data,flag)	G_STMT_START{ (GST_DATA_FLAGS(data) |= (1<<(flag))); }G_STMT_END
#define GST_DATA_FLAG_UNSET(data,flag) 	G_STMT_START{ (GST_DATA_FLAGS(data) &= ~(1<<(flag))); }G_STMT_END
enum {
  GST_DATA_READONLY,
  /* insert more */
  GST_DATA_FLAG_LAST
};
#define GST_DATA_IS_WRITABLE(data)	(!GST_DATA_FLAG_IS_SET((data), GST_DATA_READONLY))

typedef struct _GstData GstData;

typedef void (*GstDataFreeFunction) (GstData *data);

struct _GstData
{
  GstDataType		type;
  /* could go into class */
  GstDataFreeFunction	dispose;
  GstDataFreeFunction	free;
  
  /* refcounting */
#ifdef HAVE_ATOMIC_H
  atomic_t 		refcount;
#else
  gint 			refcount;
  GMutex *		reflock;
#endif
  
  /* flags */
  guint			flags;
  
  /* offset in stream */
  /* FIXME: only instream data needs that */
  guint64		offset[GST_OFFSET_TYPES];
};

/* inheritance */
void			gst_data_init			(GstData *data);
void 			gst_data_copy	 		(GstData *to, const GstData *from);
void 			gst_data_dispose 		(GstData *data);

/* construction */
GstData *		gst_data_new			(GType type);

/* reference counting */
void			gst_data_ref			(GstData* data);
void			gst_data_unref			(GstData* data);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __GST_DATA_H__ */