59e857d0623a2cfc2b7326d21ebd9a0fb322746c
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 */
24 #ifndef __GST_BASE_SRC_H__
25 #define __GST_BASE_SRC_H__
27 #include <gst/gst.h>
29 G_BEGIN_DECLS
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))
38 /**
39 * GstBaseSrcFlags:
40 * @GST_BASE_SRC_STARTED: has source been started
41 * @GST_BASE_SRC_FLAG_LAST: offset to define more flags
42 *
43 * The #GstElement flags that a basesrc element may have.
44 */
45 typedef enum {
46 GST_BASE_SRC_STARTED = GST_ELEMENT_FLAG_LAST,
48 GST_BASE_SRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2
49 } GstBaseSrcFlags;
51 typedef struct _GstBaseSrc GstBaseSrc;
52 typedef struct _GstBaseSrcClass GstBaseSrcClass;
54 /**
55 * GST_BASE_SRC_PAD:
56 * @obj: base source instance
57 *
58 * Gives the pointer to the #GstPad object of the element.
59 */
60 #define GST_BASE_SRC_PAD(obj) (GST_BASE_SRC (obj)->srcpad)
62 #define GST_LIVE_GET_LOCK(elem) (GST_BASE_SRC(elem)->live_lock)
63 #define GST_LIVE_LOCK(elem) g_mutex_lock(GST_LIVE_GET_LOCK(elem))
64 #define GST_LIVE_TRYLOCK(elem) g_mutex_trylock(GST_LIVE_GET_LOCK(elem))
65 #define GST_LIVE_UNLOCK(elem) g_mutex_unlock(GST_LIVE_GET_LOCK(elem))
66 #define GST_LIVE_GET_COND(elem) (GST_BASE_SRC(elem)->live_cond)
67 #define GST_LIVE_WAIT(elem) g_cond_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem))
68 #define GST_LIVE_TIMED_WAIT(elem, timeval) g_cond_timed_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem),\
69 timeval)
70 #define GST_LIVE_SIGNAL(elem) g_cond_signal (GST_LIVE_GET_COND (elem));
71 #define GST_LIVE_BROADCAST(elem) g_cond_broadcast (GST_LIVE_GET_COND (elem));
74 struct _GstBaseSrc {
75 GstElement element;
76 GstPad *srcpad;
78 /*< public >*/
79 /* available to subclass implementations */
80 /* MT-protected (with LIVE_LOCK) */
81 GMutex *live_lock;
82 GCond *live_cond;
83 gboolean is_live;
84 gboolean live_running;
86 /* MT-protected (with LOCK) */
87 gint blocksize; /* size of buffers when operating push based */
88 gboolean can_activate_push; /* some scheduling properties */
89 GstActivateMode pad_mode;
90 gboolean seekable;
91 gboolean random_access;
93 GstClockID clock_id; /* for syncing */
94 GstClockTime end_time;
96 /* MT-protected (with STREAM_LOCK) */
97 gint64 segment_start; /* start and end positions for seeking */
98 gint64 segment_end;
99 gboolean segment_loop;
100 gboolean need_discont;
102 guint64 offset; /* current offset in the resource */
103 guint64 size; /* total size of the resource */
105 gint num_buffers;
106 gint num_buffers_left;
108 /*< private >*/
109 gpointer _gst_reserved[GST_PADDING];
110 };
112 /**
113 * _GstBaseSrcClass:
114 * @create: ask the subclass to create a buffer with offset and size
115 * @start: start processing
116 */
117 struct _GstBaseSrcClass {
118 GstElementClass parent_class;
120 /*< public >*/
121 /* virtual methods for subclasses */
123 /* get caps from subclass */
124 GstCaps* (*get_caps) (GstBaseSrc *src);
125 /* notify the subclass of new caps */
126 gboolean (*set_caps) (GstBaseSrc *src, GstCaps *caps);
128 /* decide on caps */
129 gboolean (*negotiate) (GstBaseSrc *src);
131 /* start and stop processing, ideal for opening/closing the resource */
132 gboolean (*start) (GstBaseSrc *src);
133 gboolean (*stop) (GstBaseSrc *src);
135 /* given a buffer, return start and stop time when it should be pushed
136 * out. The base class will sync on the clock using these times. */
137 void (*get_times) (GstBaseSrc *src, GstBuffer *buffer,
138 GstClockTime *start, GstClockTime *end);
140 /* get the total size of the resource in bytes */
141 gboolean (*get_size) (GstBaseSrc *src, guint64 *size);
143 /* check if the resource is seekable */
144 gboolean (*is_seekable) (GstBaseSrc *src);
145 /* unlock any pending access to the resource. subclasses should unlock
146 * any function ASAP. */
147 gboolean (*unlock) (GstBaseSrc *src);
149 /* notify subclasses of an event */
150 gboolean (*event) (GstBaseSrc *src, GstEvent *event);
152 /* ask the subclass to create a buffer with offset and size */
153 GstFlowReturn (*create) (GstBaseSrc *src, guint64 offset, guint size,
154 GstBuffer **buf);
156 /*< private >*/
157 gpointer _gst_reserved[GST_PADDING];
158 };
160 GType gst_base_src_get_type (void);
162 void gst_base_src_set_live (GstBaseSrc *src, gboolean live);
163 gboolean gst_base_src_is_live (GstBaseSrc *src);
165 G_END_DECLS
167 #endif /* __GST_BASE_SRC_H__ */