2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #ifndef __GST_MULTI_FD_SINK_H__
23 #define __GST_MULTI_FD_SINK_H__
26 #include <gst/base/gstbasesink.h>
32 #define GST_TYPE_MULTI_FD_SINK \
33 (gst_multi_fd_sink_get_type())
34 #define GST_MULTI_FD_SINK(obj) \
35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULTI_FD_SINK,GstMultiFdSink))
36 #define GST_MULTI_FD_SINK_CLASS(klass) \
37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULTI_FD_SINK,GstMultiFdSinkClass))
38 #define GST_IS_MULTI_FD_SINK(obj) \
39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULTI_FD_SINK))
40 #define GST_IS_MULTI_FD_SINK_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULTI_FD_SINK))
42 #define GST_MULTI_FD_SINK_GET_CLASS(klass) \
43 (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_MULTI_FD_SINK, GstMultiFdSinkClass))
46 typedef struct _GstMultiFdSink GstMultiFdSink;
47 typedef struct _GstMultiFdSinkClass GstMultiFdSinkClass;
50 GST_MULTI_FD_SINK_OPEN = (GST_ELEMENT_FLAG_LAST << 0),
52 GST_MULTI_FD_SINK_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 2)
53 } GstMultiFdSinkFlags;
57 * @GST_RECOVER_POLICY_NONE : no recovering is done
58 * @GST_RECOVER_POLICY_RESYNC_LATEST : client is moved to last buffer
59 * @GST_RECOVER_POLICY_RESYNC_SOFT_LIMIT: client is moved to the soft limit
60 * @GST_RECOVER_POLICY_RESYNC_KEYFRAME : client is moved to latest keyframe
62 * Possible values for the recovery procedure to use when a client consumes
63 * data too slow and has a backlag of more that soft-limit buffers.
67 GST_RECOVER_POLICY_NONE,
68 GST_RECOVER_POLICY_RESYNC_LATEST,
69 GST_RECOVER_POLICY_RESYNC_SOFT_LIMIT,
70 GST_RECOVER_POLICY_RESYNC_KEYFRAME
75 * @GST_SYNC_METHOD_LATEST : client receives most recent buffer
76 * @GST_SYNC_METHOD_NEXT_KEYFRAME : client receives next keyframe
77 * @GST_SYNC_METHOD_LATEST_KEYFRAME : client receives latest keyframe (burst)
78 * @GST_SYNC_METHOD_BURST : client receives specific amount of data
79 * @GST_SYNC_METHOD_BURST_KEYFRAME : client receives specific amount of data
80 * starting from latest keyframe
81 * @GST_SYNC_METHOD_BURST_WITH_KEYFRAME : client receives specific amount of data from
82 * a keyframe, or if there is not enough data after
83 * the keyframe, starting before the keyframe
85 * This enum defines the selection of the first buffer that is sent
90 GST_SYNC_METHOD_LATEST,
91 GST_SYNC_METHOD_NEXT_KEYFRAME,
92 GST_SYNC_METHOD_LATEST_KEYFRAME,
93 GST_SYNC_METHOD_BURST,
94 GST_SYNC_METHOD_BURST_KEYFRAME,
95 GST_SYNC_METHOD_BURST_WITH_KEYFRAME
100 * @GST_TCP_UNIT_TYPE_UNDEFINED: undefined
101 * @GST_TCP_UNIT_TYPE_BUFFERS : buffers
102 * @GST_TCP_UNIT_TYPE_TIME : timeunits (in nanoseconds)
103 * @GST_TCP_UNIT_TYPE_BYTES : bytes
105 * The units used to specify limits.
109 GST_TCP_UNIT_TYPE_UNDEFINED,
110 GST_TCP_UNIT_TYPE_BUFFERS,
111 GST_TCP_UNIT_TYPE_TIME,
112 GST_TCP_UNIT_TYPE_BYTES
117 * @GST_CLIENT_STATUS_OK : client is ok
118 * @GST_CLIENT_STATUS_CLOSED : client closed the socket
119 * @GST_CLIENT_STATUS_REMOVED : client is removed
120 * @GST_CLIENT_STATUS_SLOW : client is too slow
121 * @GST_CLIENT_STATUS_ERROR : client is in error
122 * @GST_CLIENT_STATUS_DUPLICATE: same client added twice
123 * @GST_CLIENT_STATUS_FLUSHING : client is flushing out the remaining buffers.
125 * This specifies the reason why a client was removed from
126 * multifdsink and is received in the "client-removed" signal.
130 GST_CLIENT_STATUS_OK = 0,
131 GST_CLIENT_STATUS_CLOSED = 1,
132 GST_CLIENT_STATUS_REMOVED = 2,
133 GST_CLIENT_STATUS_SLOW = 3,
134 GST_CLIENT_STATUS_ERROR = 4,
135 GST_CLIENT_STATUS_DUPLICATE = 5,
136 GST_CLIENT_STATUS_FLUSHING = 6
139 /* structure for a client
144 gint bufpos; /* position of this client in the global queue */
145 gint flushcount; /* the remaining number of buffers to flush out or -1 if the
146 client is not flushing. */
148 GstClientStatus status;
151 GSList *sending; /* the buffers we need to send */
152 gint bufoffset; /* offset in the first buffer */
156 GstTCPProtocol protocol;
159 gboolean new_connection;
161 gboolean currently_removing;
163 /* method to sync client when connecting */
164 GstSyncMethod sync_method;
165 GstTCPUnitType burst_min_unit;
166 guint64 burst_min_value;
167 GstTCPUnitType burst_max_unit;
168 guint64 burst_max_value;
170 GstCaps *caps; /* caps of last queued buffer */
174 guint64 connect_time;
175 guint64 disconnect_time;
176 guint64 last_activity_time;
177 guint64 dropped_buffers;
178 guint64 avg_queue_size;
179 guint64 first_buffer_ts;
180 guint64 last_buffer_ts;
183 #define CLIENTS_LOCK_INIT(fdsink) (g_static_rec_mutex_init(&fdsink->clientslock))
184 #define CLIENTS_LOCK_FREE(fdsink) (g_static_rec_mutex_free(&fdsink->clientslock))
185 #define CLIENTS_LOCK(fdsink) (g_static_rec_mutex_lock(&fdsink->clientslock))
186 #define CLIENTS_UNLOCK(fdsink) (g_static_rec_mutex_unlock(&fdsink->clientslock))
191 * The multifdsink object structure.
193 struct _GstMultiFdSink {
197 guint64 bytes_to_serve; /* how much bytes we must serve */
198 guint64 bytes_served; /* how much bytes have we served */
200 GStaticRecMutex clientslock; /* lock to protect the clients list */
201 GList *clients; /* list of clients we are serving */
202 GHashTable *fd_hash; /* index on fd to client */
203 guint clients_cookie; /* Cookie to detect changes to the clients list */
208 GSList *streamheader; /* GSList of GstBuffers to use as streamheader */
209 gboolean previous_buffer_in_caps;
211 GstTCPProtocol protocol;
214 gboolean handle_read;
216 GArray *bufqueue; /* global queue of buffers */
218 gboolean running; /* the thread state */
219 GThread *thread; /* the sender thread */
221 /* these values are used to check if a client is reading fast
222 * enough and to control receovery */
223 GstTCPUnitType unit_type;/* the type of the units */
224 gint64 units_max; /* max units to queue for a client */
225 gint64 units_soft_max; /* max units a client can lag before recovery starts */
226 GstRecoverPolicy recover_policy;
227 GstClockTime timeout; /* max amount of nanoseconds to remain idle */
229 GstSyncMethod def_sync_method; /* what method to use for connecting clients */
230 GstTCPUnitType def_burst_unit;
231 guint64 def_burst_value;
233 /* these values are used to control the amount of data
234 * kept in the queues. It allows clients to perform a burst
236 gint bytes_min; /* min number of bytes to queue */
237 gint64 time_min; /* min time to queue */
238 gint buffers_min; /* min number of buffers to queue */
240 gboolean resend_streamheader; /* resend streamheader if it changes */
243 gint buffers_queued; /* number of queued buffers */
244 gint bytes_queued; /* number of queued bytes */
245 gint time_queued; /* number of queued time */
250 struct _GstMultiFdSinkClass {
251 GstBaseSinkClass parent_class;
253 /* element methods */
254 void (*add) (GstMultiFdSink *sink, int fd);
255 void (*add_full) (GstMultiFdSink *sink, int fd, GstSyncMethod sync,
256 GstTCPUnitType format, guint64 value,
257 GstTCPUnitType max_unit, guint64 max_value);
258 void (*remove) (GstMultiFdSink *sink, int fd);
259 void (*remove_flush) (GstMultiFdSink *sink, int fd);
260 void (*clear) (GstMultiFdSink *sink);
261 GValueArray* (*get_stats) (GstMultiFdSink *sink, int fd);
264 gboolean (*init) (GstMultiFdSink *sink);
265 gboolean (*wait) (GstMultiFdSink *sink, GstPoll *set);
266 gboolean (*close) (GstMultiFdSink *sink);
267 void (*removed) (GstMultiFdSink *sink, int fd);
270 void (*client_added) (GstElement *element, gint fd);
271 void (*client_removed) (GstElement *element, gint fd, GstClientStatus status);
272 void (*client_fd_removed) (GstElement *element, gint fd);
275 GType gst_multi_fd_sink_get_type (void);
277 void gst_multi_fd_sink_add (GstMultiFdSink *sink, int fd);
278 void gst_multi_fd_sink_add_full (GstMultiFdSink *sink, int fd, GstSyncMethod sync,
279 GstTCPUnitType min_unit, guint64 min_value,
280 GstTCPUnitType max_unit, guint64 max_value);
281 void gst_multi_fd_sink_remove (GstMultiFdSink *sink, int fd);
282 void gst_multi_fd_sink_remove_flush (GstMultiFdSink *sink, int fd);
283 void gst_multi_fd_sink_clear (GstMultiFdSink *sink);
284 GValueArray* gst_multi_fd_sink_get_stats (GstMultiFdSink *sink, int fd);
288 #endif /* __GST_MULTI_FD_SINK_H__ */