gst/: Add padding to our base elements' class and instance structs and to GstIterator...
[platform/upstream/gstreamer.git] / libs / gst / base / gstbasesrc.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *                    2005 Wim Taymans <wim@fluendo.com>
5  *
6  * gstbasesrc.h:
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef __GST_BASE_SRC_H__
25 #define __GST_BASE_SRC_H__
26
27 #include <gst/gst.h>
28
29 G_BEGIN_DECLS
30
31 #define GST_TYPE_BASE_SRC               (gst_base_src_get_type())
32 #define GST_BASE_SRC(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SRC,GstBaseSrc))
33 #define GST_BASE_SRC_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SRC,GstBaseSrcClass))
34 #define GST_BASE_SRC_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SRC, GstBaseSrcClass))
35 #define GST_IS_BASE_SRC(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SRC))
36 #define GST_IS_BASE_SRC_CLASS(obj)      (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SRC))
37
38 typedef enum {
39   GST_BASE_SRC_STARTED           = GST_ELEMENT_FLAG_LAST,
40
41   GST_BASE_SRC_FLAG_LAST         = GST_ELEMENT_FLAG_LAST + 2
42 } GstBaseSrcFlags;
43
44 typedef struct _GstBaseSrc GstBaseSrc;
45 typedef struct _GstBaseSrcClass GstBaseSrcClass;
46
47 #define GST_BASE_SRC_PAD(obj)                 (GST_BASE_SRC (obj)->srcpad)
48
49 #define GST_LIVE_GET_LOCK(elem)               (GST_BASE_SRC(elem)->live_lock)
50 #define GST_LIVE_LOCK(elem)                   g_mutex_lock(GST_LIVE_GET_LOCK(elem))
51 #define GST_LIVE_TRYLOCK(elem)                g_mutex_trylock(GST_LIVE_GET_LOCK(elem))
52 #define GST_LIVE_UNLOCK(elem)                 g_mutex_unlock(GST_LIVE_GET_LOCK(elem))
53 #define GST_LIVE_GET_COND(elem)               (GST_BASE_SRC(elem)->live_cond)
54 #define GST_LIVE_WAIT(elem)                   g_cond_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem))
55 #define GST_LIVE_TIMED_WAIT(elem, timeval)    g_cond_timed_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem),\
56                                                                                 timeval)
57 #define GST_LIVE_SIGNAL(elem)                 g_cond_signal (GST_LIVE_GET_COND (elem));
58 #define GST_LIVE_BROADCAST(elem)              g_cond_broadcast (GST_LIVE_GET_COND (elem));
59
60
61 struct _GstBaseSrc {
62   GstElement     element;
63   GstPad        *srcpad;
64
65   /*< public >*/
66   /* available to subclass implementations */
67   /* MT-protected (with LIVE_LOCK) */
68   GMutex        *live_lock;
69   GCond         *live_cond;
70   gboolean       is_live;
71   gboolean       live_running;
72
73   /* MT-protected (with LOCK) */
74   gint           blocksize;     /* size of buffers when operating push based */
75   gboolean       has_loop;      /* some scheduling properties */
76   gboolean       has_getrange;
77   gboolean       seekable;
78   gboolean       random_access;
79
80   GstClockID     clock_id;      /* for syncing */
81   GstClockTime   end_time;
82
83   /* MT-protected (with STREAM_LOCK) */
84   gint64         segment_start; /* start and end positions for seeking */
85   gint64         segment_end;
86   gboolean       segment_loop;
87   gboolean       need_discont;
88
89   guint64        offset;        /* current offset in the resource */
90   guint64        size;          /* total size of the resource */
91
92   gint           num_buffers;
93   gint           num_buffers_left;
94
95   /*< private >*/
96   gpointer       _gst_reserved[GST_PADDING];
97 };
98
99 /**
100  * _GstBaseSrcClass:
101  * @create: ask the subclass to create a buffer with offset and size
102  * @start: start processing
103  */
104 struct _GstBaseSrcClass {
105   GstElementClass parent_class;
106
107   /*< public >*/
108   /* virtual methods for subclasses */
109
110   /* get caps from subclass */
111   GstCaps*      (*get_caps)     (GstBaseSrc *src);
112   /* notify the subclass of new caps */
113   gboolean      (*set_caps)     (GstBaseSrc *src, GstCaps *caps);
114
115   /* decide on caps */
116   gboolean      (*negotiate)    (GstBaseSrc *src);
117
118   /* start and stop processing, ideal for opening/closing the resource */
119   gboolean      (*start)        (GstBaseSrc *src);
120   gboolean      (*stop)         (GstBaseSrc *src);
121
122   /* given a buffer, return start and stop time when it should be pushed
123    * out. The base class will sync on the clock using these times. */
124   void          (*get_times)    (GstBaseSrc *src, GstBuffer *buffer,
125                                  GstClockTime *start, GstClockTime *end);
126
127   /* get the total size of the resource in bytes */
128   gboolean      (*get_size)     (GstBaseSrc *src, guint64 *size);
129
130   /* check if the resource is seekable */
131   gboolean      (*is_seekable)  (GstBaseSrc *src);
132   /* unlock any pending access to the resource. subclasses should unlock
133    * any function ASAP. */
134   gboolean      (*unlock)       (GstBaseSrc *src);
135
136   /* notify subclasses of an event */
137   gboolean      (*event)        (GstBaseSrc *src, GstEvent *event);
138
139   /* ask the subclass to create a buffer with offset and size */
140   GstFlowReturn (*create)       (GstBaseSrc *src, guint64 offset, guint size,
141                                  GstBuffer **buf);
142
143   /*< private >*/
144   gpointer       _gst_reserved[GST_PADDING];
145 };
146
147 GType gst_base_src_get_type(void);
148
149 void            gst_base_src_set_live   (GstBaseSrc *src, gboolean live);
150 gboolean        gst_base_src_is_live    (GstBaseSrc *src);
151
152 G_END_DECLS
153
154 #endif /* __GST_BASE_SRC_H__ */