1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
4 * Copyright (C) 2006 Wim Taymans <wim at fluendo dot com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 /**
23 * SECTION:element-multifdsink
24 * @title: multifdsink
25 * @see_also: tcpserversink
26 *
27 * This plugin writes incoming data to a set of file descriptors. The
28 * file descriptors can be added to multifdsink by emitting the #GstMultiFdSink::add signal.
29 * For each descriptor added, the #GstMultiFdSink::client-added signal will be called.
30 *
31 * The multifdsink element needs to be set into READY, PAUSED or PLAYING state
32 * before operations such as adding clients are possible.
33 *
34 * A client can also be added with the #GstMultiFdSink::add-full signal
35 * that allows for more control over what and how much data a client
36 * initially receives.
37 *
38 * Clients can be removed from multifdsink by emitting the #GstMultiFdSink::remove signal. For
39 * each descriptor removed, the #GstMultiFdSink::client-removed signal will be called. The
40 * #GstMultiFdSink::client-removed signal can also be fired when multifdsink decides that a
41 * client is not active anymore or, depending on the value of the
42 * #GstMultiHandleSink:recover-policy property, if the client is reading too slowly.
43 * In all cases, multifdsink will never close a file descriptor itself.
44 * The user of multifdsink is responsible for closing all file descriptors.
45 * This can for example be done in response to the #GstMultiFdSink::client-fd-removed signal.
46 * Note that multifdsink still has a reference to the file descriptor when the
47 * #GstMultiFdSink::client-removed signal is emitted, so that "get-stats" can be performed on
48 * the descriptor; it is therefore not safe to close the file descriptor in
49 * the #GstMultiFdSink::client-removed signal handler, and you should use the
50 * #GstMultiFdSink::client-fd-removed signal to safely close the fd.
51 *
52 * Multifdsink internally keeps a queue of the incoming buffers and uses a
53 * separate thread to send the buffers to the clients. This ensures that no
54 * client write can block the pipeline and that clients can read with different
55 * speeds.
56 *
57 * When adding a client to multifdsink, the #GstMultiHandleSink:sync-method property will define
58 * which buffer in the queued buffers will be sent first to the client. Clients
59 * can be sent the most recent buffer (which might not be decodable by the
60 * client if it is not a keyframe), the next keyframe received in
61 * multifdsink (which can take some time depending on the keyframe rate), or the
62 * last received keyframe (which will cause a simple burst-on-connect).
63 * Multifdsink will always keep at least one keyframe in its internal buffers
64 * when the sync-mode is set to latest-keyframe.
65 *
66 * There are additional values for the #GstMultiHandleSink:sync-method
67 * property to allow finer control over burst-on-connect behaviour. By selecting
68 * the 'burst' method a minimum burst size can be chosen, 'burst-keyframe'
69 * additionally requires that the burst begin with a keyframe, and
70 * 'burst-with-keyframe' attempts to burst beginning with a keyframe, but will
71 * prefer a minimum burst size even if it requires not starting with a keyframe.
72 *
73 * Multifdsink can be instructed to keep at least a minimum amount of data
74 * expressed in time or byte units in its internal queues with the
75 * #GstMultiHandleSink:time-min and #GstMultiHandleSink:bytes-min properties respectively.
76 * These properties are useful if the application adds clients with the
77 * #GstMultiFdSink::add-full signal to make sure that a burst connect can
78 * actually be honored.
79 *
80 * When streaming data, clients are allowed to read at a different rate than
81 * the rate at which multifdsink receives data. If the client is reading too
82 * fast, no data will be send to the client until multifdsink receives more
83 * data. If the client, however, reads too slowly, data for that client will be
84 * queued up in multifdsink. Two properties control the amount of data
85 * (buffers) that is queued in multifdsink: #GstMultiHandleSink:buffers-max and
86 * #GstMultiHandleSink:buffers-soft-max. A client that falls behind by
87 * #GstMultiHandleSink:buffers-max is removed from multifdsink forcibly.
88 *
89 * A client with a lag of at least #GstMultiHandleSink:buffers-soft-max enters the recovery
90 * procedure which is controlled with the #GstMultiHandleSink:recover-policy property.
91 * A recover policy of NONE will do nothing, RESYNC_LATEST will send the most recently
92 * received buffer as the next buffer for the client, RESYNC_SOFT_LIMIT
93 * positions the client to the soft limit in the buffer queue and
94 * RESYNC_KEYFRAME positions the client at the most recent keyframe in the
95 * buffer queue.
96 *
97 * multifdsink will by default synchronize on the clock before serving the
98 * buffers to the clients. This behaviour can be disabled by setting the sync
99 * property to FALSE. Multifdsink will by default not do QoS and will never
100 * drop late buffers.
101 */
102
103 #ifdef HAVE_CONFIG_H
104 #include "config.h"
105 #endif
106
107 #include <gst/gst-i18n-plugin.h>
108
109 #include <sys/ioctl.h>
110
111 #ifdef HAVE_UNISTD_H
112 #include <unistd.h>
113 #endif
114
115 #include <string.h>
116 #include <fcntl.h>
117 #include <sys/types.h>
118 #include <sys/socket.h>
119 #include <sys/stat.h>
120 #include <netinet/in.h>
121
122 #include "gsttcpelements.h"
123 #include "gstmultifdsink.h"
124
125 #if !defined(FIONREAD) && defined(__sun)
126 #include <sys/filio.h>
127 #endif
128
129 #define NOT_IMPLEMENTED 0
130
131 GST_DEBUG_CATEGORY_STATIC (multifdsink_debug);
132 #define GST_CAT_DEFAULT (multifdsink_debug)
133
134 /* MultiFdSink signals and args */
135 enum
136 {
137 /* methods */
138 SIGNAL_ADD,
139 SIGNAL_ADD_BURST,
140 SIGNAL_REMOVE,
141 SIGNAL_REMOVE_FLUSH,
142 SIGNAL_GET_STATS,
143
144 /* signals */
145 SIGNAL_CLIENT_ADDED,
146 SIGNAL_CLIENT_REMOVED,
147 SIGNAL_CLIENT_FD_REMOVED,
148
149 LAST_SIGNAL
150 };
151
152 /* this is really arbitrarily chosen */
153 #define DEFAULT_HANDLE_READ TRUE
154
155 enum
156 {
157 PROP_0,
158 PROP_HANDLE_READ
159 };
160
161 static void gst_multi_fd_sink_stop_pre (GstMultiHandleSink * mhsink);
162 static void gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink);
163 static gboolean gst_multi_fd_sink_start_pre (GstMultiHandleSink * mhsink);
164 static gpointer gst_multi_fd_sink_thread (GstMultiHandleSink * mhsink);
165
166 static void gst_multi_fd_sink_add (GstMultiFdSink * sink, int fd);
167 static void gst_multi_fd_sink_add_full (GstMultiFdSink * sink, int fd,
168 GstSyncMethod sync, GstFormat min_format, guint64 min_value,
169 GstFormat max_format, guint64 max_value);
170 static void gst_multi_fd_sink_remove (GstMultiFdSink * sink, int fd);
171 static void gst_multi_fd_sink_remove_flush (GstMultiFdSink * sink, int fd);
172 static GstStructure *gst_multi_fd_sink_get_stats (GstMultiFdSink * sink,
173 int fd);
174
175 static void gst_multi_fd_sink_emit_client_added (GstMultiHandleSink * mhsink,
176 GstMultiSinkHandle handle);
177 static void gst_multi_fd_sink_emit_client_removed (GstMultiHandleSink * mhsink,
178 GstMultiSinkHandle handle, GstClientStatus status);
179
180 static GstMultiHandleClient *gst_multi_fd_sink_new_client (GstMultiHandleSink *
181 mhsink, GstMultiSinkHandle handle, GstSyncMethod sync_method);
182 static void gst_multi_fd_sink_client_free (GstMultiHandleSink * m,
183 GstMultiHandleClient * client);
184 static int gst_multi_fd_sink_client_get_fd (GstMultiHandleClient * client);
185 static void gst_multi_fd_sink_handle_debug (GstMultiSinkHandle handle,
186 gchar debug[30]);
187 static gpointer gst_multi_fd_sink_handle_hash_key (GstMultiSinkHandle handle);
188 static void gst_multi_fd_sink_hash_adding (GstMultiHandleSink * mhsink,
189 GstMultiHandleClient * mhclient);
190 static void gst_multi_fd_sink_hash_removing (GstMultiHandleSink * mhsink,
191 GstMultiHandleClient * mhclient);
192
193 static void gst_multi_fd_sink_hash_changed (GstMultiHandleSink * mhsink);
194
195 static void gst_multi_fd_sink_set_property (GObject * object, guint prop_id,
196 const GValue * value, GParamSpec * pspec);
197 static void gst_multi_fd_sink_get_property (GObject * object, guint prop_id,
198 GValue * value, GParamSpec * pspec);
199
200 #define gst_multi_fd_sink_parent_class parent_class
201 G_DEFINE_TYPE (GstMultiFdSink, gst_multi_fd_sink, GST_TYPE_MULTI_HANDLE_SINK);
202 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (multifdsink, "multifdsink",
203 GST_RANK_NONE, GST_TYPE_MULTI_FD_SINK, tcp_element_init (plugin));
204
205 static guint gst_multi_fd_sink_signals[LAST_SIGNAL] = { 0 };
206
207 static void
gst_multi_fd_sink_class_init(GstMultiFdSinkClass * klass)208 gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
209 {
210 GObjectClass *gobject_class;
211 GstElementClass *gstelement_class;
212 GstMultiHandleSinkClass *gstmultihandlesink_class;
213
214 gobject_class = (GObjectClass *) klass;
215 gstelement_class = (GstElementClass *) klass;
216 gstmultihandlesink_class = (GstMultiHandleSinkClass *) klass;
217
218 gobject_class->set_property = gst_multi_fd_sink_set_property;
219 gobject_class->get_property = gst_multi_fd_sink_get_property;
220
221 /**
222 * GstMultiFdSink::handle-read
223 *
224 * Handle read requests from clients and discard the data.
225 */
226 g_object_class_install_property (gobject_class, PROP_HANDLE_READ,
227 g_param_spec_boolean ("handle-read", "Handle Read",
228 "Handle client reads and discard the data",
229 DEFAULT_HANDLE_READ, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230
231 /**
232 * GstMultiFdSink::add:
233 * @gstmultifdsink: the multifdsink element to emit this signal on
234 * @fd: the file descriptor to add to multifdsink
235 *
236 * Hand the given open file descriptor to multifdsink to write to.
237 */
238 gst_multi_fd_sink_signals[SIGNAL_ADD] =
239 g_signal_new ("add", G_TYPE_FROM_CLASS (klass),
240 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
241 G_STRUCT_OFFSET (GstMultiFdSinkClass, add), NULL, NULL,
242 NULL, G_TYPE_NONE, 1, G_TYPE_INT);
243 /**
244 * GstMultiFdSink::add-full:
245 * @gstmultifdsink: the multifdsink element to emit this signal on
246 * @fd: the file descriptor to add to multifdsink
247 * @sync: the sync method to use
248 * @format_min: the format of @value_min
249 * @value_min: the minimum amount of data to burst expressed in
250 * @format_min units.
251 * @format_max: the format of @value_max
252 * @value_max: the maximum amount of data to burst expressed in
253 * @format_max units.
254 *
255 * Hand the given open file descriptor to multifdsink to write to and
256 * specify the burst parameters for the new connection.
257 */
258 gst_multi_fd_sink_signals[SIGNAL_ADD_BURST] =
259 g_signal_new ("add-full", G_TYPE_FROM_CLASS (klass),
260 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
261 G_STRUCT_OFFSET (GstMultiFdSinkClass, add_full), NULL, NULL,
262 NULL, G_TYPE_NONE, 6, G_TYPE_INT, GST_TYPE_SYNC_METHOD, GST_TYPE_FORMAT,
263 G_TYPE_UINT64, GST_TYPE_FORMAT, G_TYPE_UINT64);
264 /**
265 * GstMultiFdSink::remove:
266 * @gstmultifdsink: the multifdsink element to emit this signal on
267 * @fd: the file descriptor to remove from multifdsink
268 *
269 * Remove the given open file descriptor from multifdsink.
270 */
271 gst_multi_fd_sink_signals[SIGNAL_REMOVE] =
272 g_signal_new ("remove", G_TYPE_FROM_CLASS (klass),
273 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
274 G_STRUCT_OFFSET (GstMultiFdSinkClass, remove), NULL, NULL,
275 NULL, G_TYPE_NONE, 1, G_TYPE_INT);
276 /**
277 * GstMultiFdSink::remove-flush:
278 * @gstmultifdsink: the multifdsink element to emit this signal on
279 * @fd: the file descriptor to remove from multifdsink
280 *
281 * Remove the given open file descriptor from multifdsink after flushing all
282 * the pending data to the fd.
283 */
284 gst_multi_fd_sink_signals[SIGNAL_REMOVE_FLUSH] =
285 g_signal_new ("remove-flush", G_TYPE_FROM_CLASS (klass),
286 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
287 G_STRUCT_OFFSET (GstMultiFdSinkClass, remove_flush), NULL, NULL,
288 NULL, G_TYPE_NONE, 1, G_TYPE_INT);
289
290 /**
291 * GstMultiFdSink::get-stats:
292 * @gstmultifdsink: the multifdsink element to emit this signal on
293 * @fd: the file descriptor to get stats of from multifdsink
294 *
295 * Get statistics about @fd. This function returns a #GstStructure to ease
296 * automatic wrapping for bindings.
297 *
298 * Returns: a #GstStructure with the statistics. The structures
299 * contains guint64 values that represent respectively: total
300 * number of bytes sent (bytes-sent), time when the client was
301 * added (connect-time), time when the client was
302 * disconnected/removed (disconnect-time), time the client
303 * is/was active (connect-duration), last activity time (in
304 * epoch seconds) (last-activity-time), number of buffers
305 * dropped (buffers-dropped), the timestamp of the first buffer
306 * (first-buffer-ts) and of the last buffer (last-buffer-ts).
307 * All times are expressed in nanoseconds (GstClockTime). The
308 * structure can be empty if the client was not found.
309 */
310 gst_multi_fd_sink_signals[SIGNAL_GET_STATS] =
311 g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass),
312 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
313 G_STRUCT_OFFSET (GstMultiFdSinkClass, get_stats), NULL, NULL,
314 NULL, GST_TYPE_STRUCTURE, 1, G_TYPE_INT);
315
316 /**
317 * GstMultiFdSink::client-added:
318 * @gstmultifdsink: the multifdsink element that emitted this signal
319 * @fd: the file descriptor that was added to multifdsink
320 *
321 * The given file descriptor was added to multifdsink. This signal will
322 * be emitted from the streaming thread so application should be prepared
323 * for that.
324 */
325 gst_multi_fd_sink_signals[SIGNAL_CLIENT_ADDED] =
326 g_signal_new ("client-added", G_TYPE_FROM_CLASS (klass),
327 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_INT);
328 /**
329 * GstMultiFdSink::client-removed:
330 * @gstmultifdsink: the multifdsink element that emitted this signal
331 * @fd: the file descriptor that is to be removed from multifdsink
332 * @status: the reason why the client was removed
333 *
334 * The given file descriptor is about to be removed from multifdsink. This
335 * signal will be emitted from the streaming thread so applications should
336 * be prepared for that.
337 *
338 * @gstmultifdsink still holds a handle to @fd so it is possible to call
339 * the get-stats signal from this callback. For the same reason it is
340 * not safe to `close()` and reuse @fd in this callback.
341 */
342 gst_multi_fd_sink_signals[SIGNAL_CLIENT_REMOVED] =
343 g_signal_new ("client-removed", G_TYPE_FROM_CLASS (klass),
344 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_INT,
345 GST_TYPE_CLIENT_STATUS);
346 /**
347 * GstMultiFdSink::client-fd-removed:
348 * @gstmultifdsink: the multifdsink element that emitted this signal
349 * @fd: the file descriptor that was removed from multifdsink
350 *
351 * The given file descriptor was removed from multifdsink. This signal will
352 * be emitted from the streaming thread so applications should be prepared
353 * for that.
354 *
355 * In this callback, @gstmultifdsink has removed all the information
356 * associated with @fd and it is therefore not possible to call get-stats
357 * with @fd. It is however safe to `close()` and reuse @fd in the callback.
358 */
359 gst_multi_fd_sink_signals[SIGNAL_CLIENT_FD_REMOVED] =
360 g_signal_new ("client-fd-removed", G_TYPE_FROM_CLASS (klass),
361 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_INT);
362
363 gst_element_class_set_static_metadata (gstelement_class,
364 "Multi filedescriptor sink", "Sink/Network",
365 "Send data to multiple filedescriptors",
366 "Thomas Vander Stichele <thomas at apestaart dot org>, "
367 "Wim Taymans <wim@fluendo.com>");
368
369 klass->add = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add);
370 klass->add_full = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add_full);
371 klass->remove = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove);
372 klass->remove_flush = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove_flush);
373 klass->get_stats = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_get_stats);
374
375 gstmultihandlesink_class->emit_client_added =
376 gst_multi_fd_sink_emit_client_added;
377 gstmultihandlesink_class->emit_client_removed =
378 gst_multi_fd_sink_emit_client_removed;
379
380 gstmultihandlesink_class->stop_pre =
381 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_stop_pre);
382 gstmultihandlesink_class->stop_post =
383 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_stop_post);
384 gstmultihandlesink_class->start_pre =
385 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_start_pre);
386 gstmultihandlesink_class->thread =
387 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_thread);
388 gstmultihandlesink_class->new_client =
389 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_new_client);
390 gstmultihandlesink_class->client_free = gst_multi_fd_sink_client_free;
391 gstmultihandlesink_class->client_get_fd =
392 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_client_get_fd);
393 gstmultihandlesink_class->handle_debug =
394 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_handle_debug);
395 gstmultihandlesink_class->handle_hash_key =
396 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_handle_hash_key);
397 gstmultihandlesink_class->hash_changed =
398 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_changed);
399 gstmultihandlesink_class->hash_adding =
400 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_adding);
401 gstmultihandlesink_class->hash_removing =
402 GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_removing);
403
404 GST_DEBUG_CATEGORY_INIT (multifdsink_debug, "multifdsink", 0, "FD sink");
405 }
406
407 static void
gst_multi_fd_sink_init(GstMultiFdSink * this)408 gst_multi_fd_sink_init (GstMultiFdSink * this)
409 {
410 GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (this);
411
412 mhsink->handle_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
413
414 this->handle_read = DEFAULT_HANDLE_READ;
415 }
416
417 /* methods to emit signals */
418
419 static void
gst_multi_fd_sink_emit_client_added(GstMultiHandleSink * mhsink,GstMultiSinkHandle handle)420 gst_multi_fd_sink_emit_client_added (GstMultiHandleSink * mhsink,
421 GstMultiSinkHandle handle)
422 {
423 g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_ADDED], 0,
424 handle.fd);
425 }
426
427 static void
gst_multi_fd_sink_emit_client_removed(GstMultiHandleSink * mhsink,GstMultiSinkHandle handle,GstClientStatus status)428 gst_multi_fd_sink_emit_client_removed (GstMultiHandleSink * mhsink,
429 GstMultiSinkHandle handle, GstClientStatus status)
430 {
431 g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_REMOVED], 0,
432 handle.fd, status);
433 }
434
435 static void
gst_multi_fd_sink_client_free(GstMultiHandleSink * mhsink,GstMultiHandleClient * client)436 gst_multi_fd_sink_client_free (GstMultiHandleSink * mhsink,
437 GstMultiHandleClient * client)
438 {
439 g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_FD_REMOVED],
440 0, client->handle.fd);
441 }
442
443 /* action signals */
444
445 static void
gst_multi_fd_sink_add(GstMultiFdSink * sink,int fd)446 gst_multi_fd_sink_add (GstMultiFdSink * sink, int fd)
447 {
448 GstMultiSinkHandle handle;
449
450 handle.fd = fd;
451 gst_multi_handle_sink_add (GST_MULTI_HANDLE_SINK_CAST (sink), handle);
452 }
453
454 static void
gst_multi_fd_sink_add_full(GstMultiFdSink * sink,int fd,GstSyncMethod sync,GstFormat min_format,guint64 min_value,GstFormat max_format,guint64 max_value)455 gst_multi_fd_sink_add_full (GstMultiFdSink * sink, int fd,
456 GstSyncMethod sync, GstFormat min_format, guint64 min_value,
457 GstFormat max_format, guint64 max_value)
458 {
459 GstMultiSinkHandle handle;
460
461 handle.fd = fd;
462 gst_multi_handle_sink_add_full (GST_MULTI_HANDLE_SINK_CAST (sink), handle,
463 sync, min_format, min_value, max_format, max_value);
464 }
465
466 static void
gst_multi_fd_sink_remove(GstMultiFdSink * sink,int fd)467 gst_multi_fd_sink_remove (GstMultiFdSink * sink, int fd)
468 {
469 GstMultiSinkHandle handle;
470
471 handle.fd = fd;
472 gst_multi_handle_sink_remove (GST_MULTI_HANDLE_SINK_CAST (sink), handle);
473 }
474
475 static void
gst_multi_fd_sink_remove_flush(GstMultiFdSink * sink,int fd)476 gst_multi_fd_sink_remove_flush (GstMultiFdSink * sink, int fd)
477 {
478 GstMultiSinkHandle handle;
479
480 handle.fd = fd;
481 gst_multi_handle_sink_remove_flush (GST_MULTI_HANDLE_SINK_CAST (sink),
482 handle);
483 }
484
485 static GstStructure *
gst_multi_fd_sink_get_stats(GstMultiFdSink * sink,int fd)486 gst_multi_fd_sink_get_stats (GstMultiFdSink * sink, int fd)
487 {
488 GstMultiSinkHandle handle;
489
490 handle.fd = fd;
491 return gst_multi_handle_sink_get_stats (GST_MULTI_HANDLE_SINK_CAST (sink),
492 handle);
493 }
494
495 /* vfuncs */
496
497 static GstMultiHandleClient *
gst_multi_fd_sink_new_client(GstMultiHandleSink * mhsink,GstMultiSinkHandle handle,GstSyncMethod sync_method)498 gst_multi_fd_sink_new_client (GstMultiHandleSink * mhsink,
499 GstMultiSinkHandle handle, GstSyncMethod sync_method)
500 {
501 struct stat statbuf;
502 GstTCPClient *client;
503 GstMultiHandleClient *mhclient;
504 GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
505 GstMultiHandleSinkClass *mhsinkclass =
506 GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
507
508 /* create client datastructure */
509 client = g_new0 (GstTCPClient, 1);
510 mhclient = (GstMultiHandleClient *) client;
511
512 mhclient->handle = handle;
513
514 gst_poll_fd_init (&client->gfd);
515 client->gfd.fd = mhclient->handle.fd;
516
517 gst_multi_handle_sink_client_init (mhclient, sync_method);
518 mhsinkclass->handle_debug (handle, mhclient->debug);
519
520 /* set the socket to non blocking */
521 if (fcntl (handle.fd, F_SETFL, O_NONBLOCK) < 0) {
522 GST_ERROR_OBJECT (mhsink, "failed to make socket %s non-blocking: %s",
523 mhclient->debug, g_strerror (errno));
524 }
525
526 /* we always read from a client */
527 gst_poll_add_fd (sink->fdset, &client->gfd);
528
529 /* we don't try to read from write only fds */
530 if (sink->handle_read) {
531 gint flags;
532
533 flags = fcntl (handle.fd, F_GETFL, 0);
534 if ((flags & O_ACCMODE) != O_WRONLY) {
535 gst_poll_fd_ctl_read (sink->fdset, &client->gfd, TRUE);
536 }
537 }
538 /* figure out the mode, can't use send() for non sockets */
539 if (fstat (handle.fd, &statbuf) == 0 && S_ISSOCK (statbuf.st_mode)) {
540 client->is_socket = TRUE;
541 gst_multi_handle_sink_setup_dscp_client (mhsink, mhclient);
542 }
543
544 return mhclient;
545 }
546
547 static int
gst_multi_fd_sink_client_get_fd(GstMultiHandleClient * client)548 gst_multi_fd_sink_client_get_fd (GstMultiHandleClient * client)
549 {
550 GstTCPClient *tclient = (GstTCPClient *) client;
551
552 return tclient->gfd.fd;
553 }
554
555 static void
gst_multi_fd_sink_handle_debug(GstMultiSinkHandle handle,gchar debug[30])556 gst_multi_fd_sink_handle_debug (GstMultiSinkHandle handle, gchar debug[30])
557 {
558 g_snprintf (debug, 30, "[fd %5d]", handle.fd);
559 }
560
561 static gpointer
gst_multi_fd_sink_handle_hash_key(GstMultiSinkHandle handle)562 gst_multi_fd_sink_handle_hash_key (GstMultiSinkHandle handle)
563 {
564 return GINT_TO_POINTER (handle.fd);
565 }
566
567 static void
gst_multi_fd_sink_hash_changed(GstMultiHandleSink * mhsink)568 gst_multi_fd_sink_hash_changed (GstMultiHandleSink * mhsink)
569 {
570 GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
571
572 gst_poll_restart (sink->fdset);
573 }
574
575 /* handle a read on a client fd,
576 * which either indicates a close or should be ignored
577 * returns FALSE if some error occurred or the client closed. */
578 static gboolean
gst_multi_fd_sink_handle_client_read(GstMultiFdSink * sink,GstTCPClient * client)579 gst_multi_fd_sink_handle_client_read (GstMultiFdSink * sink,
580 GstTCPClient * client)
581 {
582 int avail, fd;
583 gboolean ret;
584 GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
585
586 fd = client->gfd.fd;
587
588 if (ioctl (fd, FIONREAD, &avail) < 0)
589 goto ioctl_failed;
590
591 GST_DEBUG_OBJECT (sink, "%s select reports client read of %d bytes",
592 mhclient->debug, avail);
593
594 ret = TRUE;
595
596 if (avail == 0) {
597 /* client sent close, so remove it */
598 GST_DEBUG_OBJECT (sink, "%s client asked for close, removing",
599 mhclient->debug);
600 mhclient->status = GST_CLIENT_STATUS_CLOSED;
601 ret = FALSE;
602 } else if (avail < 0) {
603 GST_WARNING_OBJECT (sink, "%s avail < 0, removing", mhclient->debug);
604 mhclient->status = GST_CLIENT_STATUS_ERROR;
605 ret = FALSE;
606 } else {
607 guint8 dummy[512];
608 gint nread;
609
610 /* just Read 'n' Drop, could also just drop the client as it's not supposed
611 * to write to us except for closing the socket, I guess it's because we
612 * like to listen to our customers. */
613 do {
614 /* this is the maximum we can read */
615 gint to_read = MIN (avail, 512);
616
617 GST_DEBUG_OBJECT (sink, "%s client wants us to read %d bytes",
618 mhclient->debug, to_read);
619
620 nread = read (fd, dummy, to_read);
621 if (nread < -1) {
622 GST_WARNING_OBJECT (sink, "%s could not read %d bytes: %s (%d)",
623 mhclient->debug, to_read, g_strerror (errno), errno);
624 mhclient->status = GST_CLIENT_STATUS_ERROR;
625 ret = FALSE;
626 break;
627 } else if (nread == 0) {
628 GST_WARNING_OBJECT (sink, "%s 0 bytes in read, removing",
629 mhclient->debug);
630 mhclient->status = GST_CLIENT_STATUS_ERROR;
631 ret = FALSE;
632 break;
633 }
634 avail -= nread;
635 }
636 while (avail > 0);
637 }
638 return ret;
639
640 /* ERRORS */
641 ioctl_failed:
642 {
643 GST_WARNING_OBJECT (sink, "%s ioctl failed: %s (%d)",
644 mhclient->debug, g_strerror (errno), errno);
645 mhclient->status = GST_CLIENT_STATUS_ERROR;
646 return FALSE;
647 }
648 }
649
650 /* Handle a write on a client,
651 * which indicates a read request from a client.
652 *
653 * For each client we maintain a queue of GstBuffers that contain the raw bytes
654 * we need to send to the client.
655 *
656 * We first check to see if we need to send streamheaders. If so, we queue them.
657 *
658 * Then we run into the main loop that tries to send as many buffers as
659 * possible. It will first exhaust the mhclient->sending queue and if the queue
660 * is empty, it will pick a buffer from the global queue.
661 *
662 * Sending the buffers from the mhclient->sending queue is basically writing
663 * the bytes to the socket and maintaining a count of the bytes that were
664 * sent. When the buffer is completely sent, it is removed from the
665 * mhclient->sending queue and we try to pick a new buffer for sending.
666 *
667 * When the sending returns a partial buffer we stop sending more data as
668 * the next send operation could block.
669 *
670 * This functions returns FALSE if some error occurred.
671 */
672 static gboolean
gst_multi_fd_sink_handle_client_write(GstMultiFdSink * sink,GstTCPClient * client)673 gst_multi_fd_sink_handle_client_write (GstMultiFdSink * sink,
674 GstTCPClient * client)
675 {
676 gboolean more;
677 gboolean flushing;
678 GstClockTime now, now_monotonic;
679 GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (sink);
680 GstMultiHandleSinkClass *mhsinkclass =
681 GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
682 GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
683 int fd = mhclient->handle.fd;
684
685 flushing = mhclient->status == GST_CLIENT_STATUS_FLUSHING;
686
687 more = TRUE;
688 do {
689 gint maxsize;
690
691 now = g_get_real_time () * GST_USECOND;
692 now_monotonic = g_get_monotonic_time () * GST_USECOND;
693
694 if (!mhclient->sending) {
695 /* client is not working on a buffer */
696 if (mhclient->bufpos == -1) {
697 /* client is too fast, remove from write queue until new buffer is
698 * available */
699 /* FIXME: specific */
700 gst_poll_fd_ctl_write (sink->fdset, &client->gfd, FALSE);
701
702 /* if we flushed out all of the client buffers, we can stop */
703 if (mhclient->flushcount == 0)
704 goto flushed;
705
706 return TRUE;
707 } else {
708 /* client can pick a buffer from the global queue */
709 GstBuffer *buf;
710 GstClockTime timestamp;
711
712 /* for new connections, we need to find a good spot in the
713 * bufqueue to start streaming from */
714 if (mhclient->new_connection && !flushing) {
715 gint position =
716 gst_multi_handle_sink_new_client_position (mhsink, mhclient);
717
718 if (position >= 0) {
719 /* we got a valid spot in the queue */
720 mhclient->new_connection = FALSE;
721 mhclient->bufpos = position;
722 } else {
723 /* cannot send data to this client yet */
724 /* FIXME: specific */
725 gst_poll_fd_ctl_write (sink->fdset, &client->gfd, FALSE);
726 return TRUE;
727 }
728 }
729
730 /* we flushed all remaining buffers, no need to get a new one */
731 if (mhclient->flushcount == 0)
732 goto flushed;
733
734 /* grab buffer */
735 buf = g_array_index (mhsink->bufqueue, GstBuffer *, mhclient->bufpos);
736 mhclient->bufpos--;
737
738 /* update stats */
739 timestamp = GST_BUFFER_TIMESTAMP (buf);
740 if (mhclient->first_buffer_ts == GST_CLOCK_TIME_NONE)
741 mhclient->first_buffer_ts = timestamp;
742 if (timestamp != -1)
743 mhclient->last_buffer_ts = timestamp;
744
745 /* decrease flushcount */
746 if (mhclient->flushcount != -1)
747 mhclient->flushcount--;
748
749 GST_LOG_OBJECT (sink, "%s client %p at position %d",
750 mhclient->debug, client, mhclient->bufpos);
751
752 /* queueing a buffer will ref it */
753 mhsinkclass->client_queue_buffer (mhsink, mhclient, buf);
754
755 /* need to start from the first byte for this new buffer */
756 mhclient->bufoffset = 0;
757 }
758 }
759
760 /* see if we need to send something */
761 if (mhclient->sending) {
762 ssize_t wrote;
763 GstBuffer *head;
764 GstMapInfo info;
765 guint8 *data;
766
767 /* pick first buffer from list */
768 head = GST_BUFFER (mhclient->sending->data);
769
770 if (!gst_buffer_map (head, &info, GST_MAP_READ))
771 g_return_val_if_reached (FALSE);
772
773 data = info.data;
774 maxsize = info.size - mhclient->bufoffset;
775
776 /* FIXME: specific */
777 /* try to write the complete buffer */
778 #ifdef MSG_NOSIGNAL
779 #define FLAGS MSG_NOSIGNAL
780 #else
781 #define FLAGS 0
782 #endif
783 if (client->is_socket) {
784 wrote = send (fd, data + mhclient->bufoffset, maxsize, FLAGS);
785 } else {
786 wrote = write (fd, data + mhclient->bufoffset, maxsize);
787 }
788 gst_buffer_unmap (head, &info);
789
790 if (wrote < 0) {
791 /* hmm error.. */
792 if (errno == EAGAIN) {
793 /* nothing serious, resource was unavailable, try again later */
794 more = FALSE;
795 } else if (errno == ECONNRESET) {
796 goto connection_reset;
797 } else {
798 goto write_error;
799 }
800 } else {
801 if (wrote < maxsize) {
802 /* partial write means that the client cannot read more and we should
803 * stop sending more */
804 GST_LOG_OBJECT (sink,
805 "partial write on %s of %" G_GSSIZE_FORMAT " bytes",
806 mhclient->debug, wrote);
807 mhclient->bufoffset += wrote;
808 more = FALSE;
809 } else {
810 /* complete buffer was written, we can proceed to the next one */
811 mhclient->sending = g_slist_remove (mhclient->sending, head);
812 gst_buffer_unref (head);
813 /* make sure we start from byte 0 for the next buffer */
814 mhclient->bufoffset = 0;
815 }
816 /* update stats */
817 mhclient->bytes_sent += wrote;
818 mhclient->last_activity_time = now;
819 mhclient->last_activity_time_monotonic = now_monotonic;
820 mhsink->bytes_served += wrote;
821 }
822 }
823 } while (more);
824
825 return TRUE;
826
827 /* ERRORS */
828 flushed:
829 {
830 GST_DEBUG_OBJECT (sink, "%s flushed, removing", mhclient->debug);
831 mhclient->status = GST_CLIENT_STATUS_REMOVED;
832 return FALSE;
833 }
834 connection_reset:
835 {
836 GST_DEBUG_OBJECT (sink, "%s connection reset by peer, removing",
837 mhclient->debug);
838 mhclient->status = GST_CLIENT_STATUS_CLOSED;
839 return FALSE;
840 }
841 write_error:
842 {
843 GST_WARNING_OBJECT (sink,
844 "%s could not write, removing client: %s (%d)", mhclient->debug,
845 g_strerror (errno), errno);
846 mhclient->status = GST_CLIENT_STATUS_ERROR;
847 return FALSE;
848 }
849 }
850
851 static void
gst_multi_fd_sink_hash_adding(GstMultiHandleSink * mhsink,GstMultiHandleClient * mhclient)852 gst_multi_fd_sink_hash_adding (GstMultiHandleSink * mhsink,
853 GstMultiHandleClient * mhclient)
854 {
855 GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
856 GstTCPClient *client = (GstTCPClient *) mhclient;
857
858 gst_poll_fd_ctl_write (sink->fdset, &client->gfd, TRUE);
859 }
860
861 static void
gst_multi_fd_sink_hash_removing(GstMultiHandleSink * mhsink,GstMultiHandleClient * mhclient)862 gst_multi_fd_sink_hash_removing (GstMultiHandleSink * mhsink,
863 GstMultiHandleClient * mhclient)
864 {
865 GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
866 GstTCPClient *client = (GstTCPClient *) mhclient;
867
868 gst_poll_remove_fd (sink->fdset, &client->gfd);
869 }
870
871
872 /* Handle the clients. Basically does a blocking select for one
873 * of the client fds to become read or writable. We also have a
874 * filedescriptor to receive commands on that we need to check.
875 *
876 * After going out of the select call, we read and write to all
877 * clients that can do so. Badly behaving clients are put on a
878 * garbage list and removed.
879 */
880 static void
gst_multi_fd_sink_handle_clients(GstMultiFdSink * sink)881 gst_multi_fd_sink_handle_clients (GstMultiFdSink * sink)
882 {
883 int result;
884 GList *clients, *next;
885 gboolean try_again;
886 GstMultiFdSinkClass *fclass;
887 guint cookie;
888 GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (sink);
889 int fd;
890
891
892 fclass = GST_MULTI_FD_SINK_GET_CLASS (sink);
893
894 do {
895 try_again = FALSE;
896
897 /* check for:
898 * - server socket input (ie, new client connections)
899 * - client socket input (ie, clients saying goodbye)
900 * - client socket output (ie, client reads) */
901 GST_LOG_OBJECT (sink, "waiting on action on fdset");
902
903 result =
904 gst_poll_wait (sink->fdset,
905 mhsink->timeout != 0 ? mhsink->timeout : GST_CLOCK_TIME_NONE);
906
907 /* Handle the special case in which the sink is not receiving more buffers
908 * and will not disconnect inactive client in the streaming thread. */
909 if (G_UNLIKELY (result == 0)) {
910 GstClockTime now;
911
912 now = g_get_monotonic_time () * GST_USECOND;
913
914 CLIENTS_LOCK (mhsink);
915 for (clients = mhsink->clients; clients; clients = next) {
916 GstTCPClient *client;
917 GstMultiHandleClient *mhclient;
918
919 client = (GstTCPClient *) clients->data;
920 mhclient = (GstMultiHandleClient *) client;
921 next = g_list_next (clients);
922 if (mhsink->timeout > 0
923 && now - mhclient->last_activity_time_monotonic > mhsink->timeout) {
924 mhclient->status = GST_CLIENT_STATUS_SLOW;
925 gst_multi_handle_sink_remove_client_link (mhsink, clients);
926 }
927 }
928 CLIENTS_UNLOCK (mhsink);
929 return;
930 } else if (result < 0) {
931 GST_WARNING_OBJECT (sink, "wait failed: %s (%d)", g_strerror (errno),
932 errno);
933 if (errno == EBADF) {
934 /* ok, so one or more of the fds is invalid. We loop over them to find
935 * the ones that give an error to the F_GETFL fcntl. */
936 CLIENTS_LOCK (mhsink);
937 restart:
938 cookie = mhsink->clients_cookie;
939 for (clients = mhsink->clients; clients; clients = next) {
940 GstTCPClient *client;
941 GstMultiHandleClient *mhclient;
942 long flags;
943 int res;
944
945 if (cookie != mhsink->clients_cookie) {
946 GST_DEBUG_OBJECT (sink, "Cookie changed finding bad fd");
947 goto restart;
948 }
949
950 client = (GstTCPClient *) clients->data;
951 mhclient = (GstMultiHandleClient *) client;
952 next = g_list_next (clients);
953
954 fd = client->gfd.fd;
955
956 res = fcntl (fd, F_GETFL, &flags);
957 if (res == -1) {
958 GST_WARNING_OBJECT (sink, "fcntl failed for %d, removing: %s (%d)",
959 fd, g_strerror (errno), errno);
960 if (errno == EBADF) {
961 mhclient->status = GST_CLIENT_STATUS_ERROR;
962 /* releases the CLIENTS lock */
963 gst_multi_handle_sink_remove_client_link (mhsink, clients);
964 }
965 }
966 }
967 CLIENTS_UNLOCK (mhsink);
968 /* after this, go back in the select loop as the read/writefds
969 * are not valid */
970 try_again = TRUE;
971 } else if (errno == EINTR) {
972 /* interrupted system call, just redo the wait */
973 try_again = TRUE;
974 } else if (errno == EBUSY) {
975 /* the call to gst_poll_wait() was flushed */
976 return;
977 } else {
978 /* this is quite bad... */
979 GST_ELEMENT_ERROR (sink, RESOURCE, READ, (NULL),
980 ("select failed: %s (%d)", g_strerror (errno), errno));
981 return;
982 }
983 } else {
984 GST_LOG_OBJECT (sink, "wait done: %d sockets with events", result);
985 }
986 } while (try_again);
987
988 /* subclasses can check fdset with this virtual function */
989 if (fclass->wait)
990 fclass->wait (sink, sink->fdset);
991
992 /* Check the clients */
993 CLIENTS_LOCK (mhsink);
994
995 restart2:
996 cookie = mhsink->clients_cookie;
997 for (clients = mhsink->clients; clients; clients = next) {
998 GstTCPClient *client;
999 GstMultiHandleClient *mhclient;
1000
1001 if (mhsink->clients_cookie != cookie) {
1002 GST_DEBUG_OBJECT (sink, "Restarting loop, cookie out of date");
1003 goto restart2;
1004 }
1005
1006 client = (GstTCPClient *) clients->data;
1007 mhclient = (GstMultiHandleClient *) client;
1008 next = g_list_next (clients);
1009
1010 if (mhclient->status != GST_CLIENT_STATUS_FLUSHING
1011 && mhclient->status != GST_CLIENT_STATUS_OK) {
1012 gst_multi_handle_sink_remove_client_link (mhsink, clients);
1013 continue;
1014 }
1015
1016 if (gst_poll_fd_has_closed (sink->fdset, &client->gfd)) {
1017 mhclient->status = GST_CLIENT_STATUS_CLOSED;
1018 gst_multi_handle_sink_remove_client_link (mhsink, clients);
1019 continue;
1020 }
1021 if (gst_poll_fd_has_error (sink->fdset, &client->gfd)) {
1022 GST_WARNING_OBJECT (sink, "gst_poll_fd_has_error for %d", client->gfd.fd);
1023 mhclient->status = GST_CLIENT_STATUS_ERROR;
1024 gst_multi_handle_sink_remove_client_link (mhsink, clients);
1025 continue;
1026 }
1027 if (gst_poll_fd_can_read (sink->fdset, &client->gfd)) {
1028 /* handle client read */
1029 if (!gst_multi_fd_sink_handle_client_read (sink, client)) {
1030 gst_multi_handle_sink_remove_client_link (mhsink, clients);
1031 continue;
1032 }
1033 }
1034 if (gst_poll_fd_can_write (sink->fdset, &client->gfd)) {
1035 /* handle client write */
1036 if (!gst_multi_fd_sink_handle_client_write (sink, client)) {
1037 gst_multi_handle_sink_remove_client_link (mhsink, clients);
1038 continue;
1039 }
1040 }
1041 }
1042 CLIENTS_UNLOCK (mhsink);
1043 }
1044
1045 /* we handle the client communication in another thread so that we do not block
1046 * the gstreamer thread while we select() on the client fds */
1047 static gpointer
gst_multi_fd_sink_thread(GstMultiHandleSink * mhsink)1048 gst_multi_fd_sink_thread (GstMultiHandleSink * mhsink)
1049 {
1050 GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
1051
1052 while (mhsink->running) {
1053 gst_multi_fd_sink_handle_clients (sink);
1054 }
1055 return NULL;
1056 }
1057
1058 static void
gst_multi_fd_sink_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)1059 gst_multi_fd_sink_set_property (GObject * object, guint prop_id,
1060 const GValue * value, GParamSpec * pspec)
1061 {
1062 GstMultiFdSink *multifdsink;
1063
1064 multifdsink = GST_MULTI_FD_SINK (object);
1065
1066 switch (prop_id) {
1067 case PROP_HANDLE_READ:
1068 multifdsink->handle_read = g_value_get_boolean (value);
1069 break;
1070
1071 default:
1072 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1073 break;
1074 }
1075 }
1076
1077 static void
gst_multi_fd_sink_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)1078 gst_multi_fd_sink_get_property (GObject * object, guint prop_id, GValue * value,
1079 GParamSpec * pspec)
1080 {
1081 GstMultiFdSink *multifdsink;
1082
1083 multifdsink = GST_MULTI_FD_SINK (object);
1084
1085 switch (prop_id) {
1086 case PROP_HANDLE_READ:
1087 g_value_set_boolean (value, multifdsink->handle_read);
1088 break;
1089
1090 default:
1091 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1092 break;
1093 }
1094 }
1095
1096 static gboolean
gst_multi_fd_sink_start_pre(GstMultiHandleSink * mhsink)1097 gst_multi_fd_sink_start_pre (GstMultiHandleSink * mhsink)
1098 {
1099 GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
1100
1101 GST_INFO_OBJECT (mfsink, "starting");
1102 if ((mfsink->fdset = gst_poll_new (TRUE)) == NULL)
1103 goto socket_pair;
1104
1105 return TRUE;
1106
1107 /* ERRORS */
1108 socket_pair:
1109 {
1110 GST_ELEMENT_ERROR (mfsink, RESOURCE, OPEN_READ_WRITE, (NULL),
1111 GST_ERROR_SYSTEM);
1112 return FALSE;
1113 }
1114 }
1115
1116 static gboolean
multifdsink_hash_remove(gpointer key,gpointer value,gpointer data)1117 multifdsink_hash_remove (gpointer key, gpointer value, gpointer data)
1118 {
1119 return TRUE;
1120 }
1121
1122 static void
gst_multi_fd_sink_stop_pre(GstMultiHandleSink * mhsink)1123 gst_multi_fd_sink_stop_pre (GstMultiHandleSink * mhsink)
1124 {
1125 GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
1126
1127 gst_poll_set_flushing (mfsink->fdset, TRUE);
1128 }
1129
1130 static void
gst_multi_fd_sink_stop_post(GstMultiHandleSink * mhsink)1131 gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink)
1132 {
1133 GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
1134
1135 if (mfsink->fdset) {
1136 gst_poll_free (mfsink->fdset);
1137 mfsink->fdset = NULL;
1138 }
1139 g_hash_table_foreach_remove (mhsink->handle_hash, multifdsink_hash_remove,
1140 mfsink);
1141 }
1142