2012-01-26 09:08:47 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
* Copyright (C) 2006 Wim Taymans <wim at fluendo dot com>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-01-26 09:08:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-multifdsink
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: multifdsink
|
2012-01-26 09:08:47 +00:00
|
|
|
* @see_also: tcpserversink
|
|
|
|
*
|
|
|
|
* This plugin writes incoming data to a set of file descriptors. The
|
2017-01-23 19:36:11 +00:00
|
|
|
* file descriptors can be added to multifdsink by emitting the #GstMultiFdSink::add signal.
|
2012-01-26 09:08:47 +00:00
|
|
|
* For each descriptor added, the #GstMultiFdSink::client-added signal will be called.
|
|
|
|
*
|
2012-12-02 12:54:17 +00:00
|
|
|
* The multifdsink element needs to be set into READY, PAUSED or PLAYING state
|
|
|
|
* before operations such as adding clients are possible.
|
|
|
|
*
|
2013-11-16 13:06:37 +00:00
|
|
|
* A client can also be added with the #GstMultiFdSink::add-full signal
|
2017-01-23 19:36:11 +00:00
|
|
|
* that allows for more control over what and how much data a client
|
2012-01-26 09:08:47 +00:00
|
|
|
* initially receives.
|
|
|
|
*
|
|
|
|
* Clients can be removed from multifdsink by emitting the #GstMultiFdSink::remove signal. For
|
|
|
|
* each descriptor removed, the #GstMultiFdSink::client-removed signal will be called. The
|
|
|
|
* #GstMultiFdSink::client-removed signal can also be fired when multifdsink decides that a
|
|
|
|
* client is not active anymore or, depending on the value of the
|
|
|
|
* #GstMultiFdSink:recover-policy property, if the client is reading too slowly.
|
|
|
|
* In all cases, multifdsink will never close a file descriptor itself.
|
|
|
|
* The user of multifdsink is responsible for closing all file descriptors.
|
|
|
|
* This can for example be done in response to the #GstMultiFdSink::client-fd-removed signal.
|
|
|
|
* Note that multifdsink still has a reference to the file descriptor when the
|
|
|
|
* #GstMultiFdSink::client-removed signal is emitted, so that "get-stats" can be performed on
|
|
|
|
* the descriptor; it is therefore not safe to close the file descriptor in
|
2017-01-23 19:36:11 +00:00
|
|
|
* the #GstMultiFdSink::client-removed signal handler, and you should use the
|
2012-01-26 09:08:47 +00:00
|
|
|
* #GstMultiFdSink::client-fd-removed signal to safely close the fd.
|
|
|
|
*
|
|
|
|
* Multifdsink internally keeps a queue of the incoming buffers and uses a
|
|
|
|
* separate thread to send the buffers to the clients. This ensures that no
|
|
|
|
* client write can block the pipeline and that clients can read with different
|
|
|
|
* speeds.
|
|
|
|
*
|
|
|
|
* When adding a client to multifdsink, the #GstMultiFdSink:sync-method property will define
|
2017-01-23 19:36:11 +00:00
|
|
|
* which buffer in the queued buffers will be sent first to the client. Clients
|
|
|
|
* can be sent the most recent buffer (which might not be decodable by the
|
|
|
|
* client if it is not a keyframe), the next keyframe received in
|
2012-01-26 09:08:47 +00:00
|
|
|
* multifdsink (which can take some time depending on the keyframe rate), or the
|
2017-01-23 19:36:11 +00:00
|
|
|
* last received keyframe (which will cause a simple burst-on-connect).
|
2012-01-26 09:08:47 +00:00
|
|
|
* Multifdsink will always keep at least one keyframe in its internal buffers
|
|
|
|
* when the sync-mode is set to latest-keyframe.
|
|
|
|
*
|
2013-11-16 13:06:37 +00:00
|
|
|
* There are additional values for the #GstMultiFdSink:sync-method
|
2012-01-26 09:08:47 +00:00
|
|
|
* property to allow finer control over burst-on-connect behaviour. By selecting
|
|
|
|
* the 'burst' method a minimum burst size can be chosen, 'burst-keyframe'
|
2017-01-23 19:36:11 +00:00
|
|
|
* additionally requires that the burst begin with a keyframe, and
|
2012-01-26 09:08:47 +00:00
|
|
|
* 'burst-with-keyframe' attempts to burst beginning with a keyframe, but will
|
|
|
|
* prefer a minimum burst size even if it requires not starting with a keyframe.
|
|
|
|
*
|
|
|
|
* Multifdsink can be instructed to keep at least a minimum amount of data
|
2017-01-23 19:36:11 +00:00
|
|
|
* expressed in time or byte units in its internal queues with the
|
2012-01-26 09:08:47 +00:00
|
|
|
* #GstMultiFdSink:time-min and #GstMultiFdSink:bytes-min properties respectively.
|
2017-01-23 19:36:11 +00:00
|
|
|
* These properties are useful if the application adds clients with the
|
2012-01-26 09:08:47 +00:00
|
|
|
* #GstMultiFdSink::add-full signal to make sure that a burst connect can
|
2017-01-23 19:36:11 +00:00
|
|
|
* actually be honored.
|
2012-01-26 09:08:47 +00:00
|
|
|
*
|
|
|
|
* When streaming data, clients are allowed to read at a different rate than
|
|
|
|
* the rate at which multifdsink receives data. If the client is reading too
|
|
|
|
* fast, no data will be send to the client until multifdsink receives more
|
2017-01-23 19:36:11 +00:00
|
|
|
* data. If the client, however, reads too slowly, data for that client will be
|
|
|
|
* queued up in multifdsink. Two properties control the amount of data
|
|
|
|
* (buffers) that is queued in multifdsink: #GstMultiFdSink:buffers-max and
|
2012-01-26 09:08:47 +00:00
|
|
|
* #GstMultiFdSink:buffers-soft-max. A client that falls behind by
|
|
|
|
* #GstMultiFdSink:buffers-max is removed from multifdsink forcibly.
|
|
|
|
*
|
|
|
|
* A client with a lag of at least #GstMultiFdSink:buffers-soft-max enters the recovery
|
|
|
|
* procedure which is controlled with the #GstMultiFdSink:recover-policy property.
|
|
|
|
* A recover policy of NONE will do nothing, RESYNC_LATEST will send the most recently
|
|
|
|
* received buffer as the next buffer for the client, RESYNC_SOFT_LIMIT
|
|
|
|
* positions the client to the soft limit in the buffer queue and
|
|
|
|
* RESYNC_KEYFRAME positions the client at the most recent keyframe in the
|
|
|
|
* buffer queue.
|
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* multifdsink will by default synchronize on the clock before serving the
|
|
|
|
* buffers to the clients. This behaviour can be disabled by setting the sync
|
2012-01-26 09:08:47 +00:00
|
|
|
* property to FALSE. Multifdsink will by default not do QoS and will never
|
|
|
|
* drop late buffers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst-i18n-plugin.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2012-01-28 10:02:21 +00:00
|
|
|
#include <string.h>
|
2012-01-26 09:08:47 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstmultifdsink.h"
|
|
|
|
|
|
|
|
#define NOT_IMPLEMENTED 0
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (multifdsink_debug);
|
|
|
|
#define GST_CAT_DEFAULT (multifdsink_debug)
|
|
|
|
|
|
|
|
/* MultiFdSink signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* methods */
|
|
|
|
SIGNAL_ADD,
|
|
|
|
SIGNAL_ADD_BURST,
|
|
|
|
SIGNAL_REMOVE,
|
|
|
|
SIGNAL_REMOVE_FLUSH,
|
|
|
|
SIGNAL_GET_STATS,
|
|
|
|
|
|
|
|
/* signals */
|
2012-09-09 00:20:38 +00:00
|
|
|
SIGNAL_CLIENT_ADDED,
|
|
|
|
SIGNAL_CLIENT_REMOVED,
|
2012-09-09 01:00:49 +00:00
|
|
|
SIGNAL_CLIENT_FD_REMOVED,
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this is really arbitrarily chosen */
|
|
|
|
#define DEFAULT_HANDLE_READ TRUE
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2015-04-24 16:10:59 +00:00
|
|
|
PROP_HANDLE_READ
|
2012-01-26 09:08:47 +00:00
|
|
|
};
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
static void gst_multi_fd_sink_stop_pre (GstMultiHandleSink * mhsink);
|
|
|
|
static void gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink);
|
|
|
|
static gboolean gst_multi_fd_sink_start_pre (GstMultiHandleSink * mhsink);
|
|
|
|
static gpointer gst_multi_fd_sink_thread (GstMultiHandleSink * mhsink);
|
2012-01-28 17:07:46 +00:00
|
|
|
|
2012-09-09 00:20:38 +00:00
|
|
|
static void gst_multi_fd_sink_add (GstMultiFdSink * sink, int fd);
|
|
|
|
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);
|
|
|
|
static void gst_multi_fd_sink_remove (GstMultiFdSink * sink, int fd);
|
|
|
|
static void gst_multi_fd_sink_remove_flush (GstMultiFdSink * sink, int fd);
|
|
|
|
static GstStructure *gst_multi_fd_sink_get_stats (GstMultiFdSink * sink,
|
|
|
|
int fd);
|
|
|
|
|
|
|
|
static void gst_multi_fd_sink_emit_client_added (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiSinkHandle handle);
|
|
|
|
static void gst_multi_fd_sink_emit_client_removed (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiSinkHandle handle, GstClientStatus status);
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static GstMultiHandleClient *gst_multi_fd_sink_new_client (GstMultiHandleSink *
|
|
|
|
mhsink, GstMultiSinkHandle handle, GstSyncMethod sync_method);
|
2012-09-09 00:20:38 +00:00
|
|
|
static void gst_multi_fd_sink_client_free (GstMultiHandleSink * m,
|
|
|
|
GstMultiHandleClient * client);
|
2012-01-27 14:46:31 +00:00
|
|
|
static int gst_multi_fd_sink_client_get_fd (GstMultiHandleClient * client);
|
2012-01-28 17:07:46 +00:00
|
|
|
static void gst_multi_fd_sink_handle_debug (GstMultiSinkHandle handle,
|
|
|
|
gchar debug[30]);
|
|
|
|
static gpointer gst_multi_fd_sink_handle_hash_key (GstMultiSinkHandle handle);
|
|
|
|
static void gst_multi_fd_sink_hash_adding (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiHandleClient * mhclient);
|
|
|
|
static void gst_multi_fd_sink_hash_removing (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiHandleClient * mhclient);
|
2012-01-26 22:19:33 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static void gst_multi_fd_sink_hash_changed (GstMultiHandleSink * mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
static void gst_multi_fd_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_multi_fd_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
#define gst_multi_fd_sink_parent_class parent_class
|
2012-01-26 09:49:37 +00:00
|
|
|
G_DEFINE_TYPE (GstMultiFdSink, gst_multi_fd_sink, GST_TYPE_MULTI_HANDLE_SINK);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
static guint gst_multi_fd_sink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleSinkClass *gstmultihandlesink_class;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2012-01-26 09:49:37 +00:00
|
|
|
gstmultihandlesink_class = (GstMultiHandleSinkClass *) klass;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_multi_fd_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_multi_fd_sink_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMultiFdSink::handle-read
|
|
|
|
*
|
|
|
|
* Handle read requests from clients and discard the data.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_HANDLE_READ,
|
|
|
|
g_param_spec_boolean ("handle-read", "Handle Read",
|
|
|
|
"Handle client reads and discard the data",
|
|
|
|
DEFAULT_HANDLE_READ, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMultiFdSink::add:
|
|
|
|
* @gstmultifdsink: the multifdsink element to emit this signal on
|
|
|
|
* @fd: the file descriptor to add to multifdsink
|
|
|
|
*
|
|
|
|
* Hand the given open file descriptor to multifdsink to write to.
|
|
|
|
*/
|
|
|
|
gst_multi_fd_sink_signals[SIGNAL_ADD] =
|
|
|
|
g_signal_new ("add", G_TYPE_FROM_CLASS (klass),
|
2012-01-28 17:07:46 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2012-09-09 00:20:38 +00:00
|
|
|
G_STRUCT_OFFSET (GstMultiFdSinkClass, add), NULL, NULL,
|
2013-04-25 07:20:29 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_INT);
|
2012-01-26 09:08:47 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFdSink::add-full:
|
2012-01-28 17:07:46 +00:00
|
|
|
* @gstmultifdsink: the multifdsink element to emit this signal on
|
|
|
|
* @fd: the file descriptor to add to multifdsink
|
|
|
|
* @sync: the sync method to use
|
|
|
|
* @format_min: the format of @value_min
|
|
|
|
* @value_min: the minimum amount of data to burst expressed in
|
|
|
|
* @format_min units.
|
|
|
|
* @format_max: the format of @value_max
|
|
|
|
* @value_max: the maximum amount of data to burst expressed in
|
|
|
|
* @format_max units.
|
2012-01-26 09:08:47 +00:00
|
|
|
*
|
|
|
|
* Hand the given open file descriptor to multifdsink to write to and
|
|
|
|
* specify the burst parameters for the new connection.
|
|
|
|
*/
|
|
|
|
gst_multi_fd_sink_signals[SIGNAL_ADD_BURST] =
|
|
|
|
g_signal_new ("add-full", G_TYPE_FROM_CLASS (klass),
|
2012-01-28 17:07:46 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2012-09-09 00:20:38 +00:00
|
|
|
G_STRUCT_OFFSET (GstMultiFdSinkClass, add_full), NULL, NULL,
|
2013-04-25 07:20:29 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 6,
|
2012-01-28 17:07:46 +00:00
|
|
|
G_TYPE_INT, GST_TYPE_SYNC_METHOD, GST_TYPE_FORMAT, G_TYPE_UINT64,
|
|
|
|
GST_TYPE_FORMAT, G_TYPE_UINT64);
|
2012-01-26 09:08:47 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFdSink::remove:
|
|
|
|
* @gstmultifdsink: the multifdsink element to emit this signal on
|
|
|
|
* @fd: the file descriptor to remove from multifdsink
|
|
|
|
*
|
|
|
|
* Remove the given open file descriptor from multifdsink.
|
|
|
|
*/
|
|
|
|
gst_multi_fd_sink_signals[SIGNAL_REMOVE] =
|
|
|
|
g_signal_new ("remove", G_TYPE_FROM_CLASS (klass),
|
2012-01-28 17:07:46 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2012-09-09 00:20:38 +00:00
|
|
|
G_STRUCT_OFFSET (GstMultiFdSinkClass, remove), NULL, NULL,
|
2013-04-25 07:20:29 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_INT);
|
2012-01-26 09:08:47 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFdSink::remove-flush:
|
|
|
|
* @gstmultifdsink: the multifdsink element to emit this signal on
|
|
|
|
* @fd: the file descriptor to remove from multifdsink
|
|
|
|
*
|
|
|
|
* Remove the given open file descriptor from multifdsink after flushing all
|
|
|
|
* the pending data to the fd.
|
|
|
|
*/
|
|
|
|
gst_multi_fd_sink_signals[SIGNAL_REMOVE_FLUSH] =
|
|
|
|
g_signal_new ("remove-flush", G_TYPE_FROM_CLASS (klass),
|
2012-01-28 17:07:46 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2012-09-09 00:20:38 +00:00
|
|
|
G_STRUCT_OFFSET (GstMultiFdSinkClass, remove_flush), NULL, NULL,
|
2013-04-25 07:20:29 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_INT);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMultiFdSink::get-stats:
|
|
|
|
* @gstmultifdsink: the multifdsink element to emit this signal on
|
|
|
|
* @fd: the file descriptor to get stats of from multifdsink
|
|
|
|
*
|
2017-03-14 20:30:18 +00:00
|
|
|
* Get statistics about @fd. This function returns a #GstStructure to ease
|
2012-01-26 09:08:47 +00:00
|
|
|
* automatic wrapping for bindings.
|
|
|
|
*
|
2017-03-14 20:30:18 +00:00
|
|
|
* Returns: a #GstStructure with the statistics. The structures
|
|
|
|
* contains guint64 values that represent respectively: total
|
|
|
|
* number of bytes sent (bytes-sent), time when the client was
|
|
|
|
* added (connect-time), time when the client was
|
|
|
|
* disconnected/removed (disconnect-time), time the client
|
|
|
|
* is/was active (connect-duration), last activity time (in
|
|
|
|
* epoch seconds) (last-activity-time), number of buffers
|
|
|
|
* dropped (buffers-dropped), the timestamp of the first buffer
|
|
|
|
* (first-buffer-ts) and of the last buffer (last-buffer-ts).
|
|
|
|
* All times are expressed in nanoseconds (GstClockTime). The
|
|
|
|
* structure can be empty if the client was not found.
|
2012-01-26 09:08:47 +00:00
|
|
|
*/
|
|
|
|
gst_multi_fd_sink_signals[SIGNAL_GET_STATS] =
|
|
|
|
g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass),
|
2012-01-28 17:07:46 +00:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2012-09-09 00:20:38 +00:00
|
|
|
G_STRUCT_OFFSET (GstMultiFdSinkClass, get_stats), NULL, NULL,
|
2013-04-25 07:20:29 +00:00
|
|
|
g_cclosure_marshal_generic, GST_TYPE_STRUCTURE, 1, G_TYPE_INT);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstMultiFdSink::client-added:
|
|
|
|
* @gstmultifdsink: the multifdsink element that emitted this signal
|
|
|
|
* @fd: the file descriptor that was added to multifdsink
|
|
|
|
*
|
|
|
|
* The given file descriptor was added to multifdsink. This signal will
|
|
|
|
* be emitted from the streaming thread so application should be prepared
|
|
|
|
* for that.
|
|
|
|
*/
|
2012-09-09 00:20:38 +00:00
|
|
|
gst_multi_fd_sink_signals[SIGNAL_CLIENT_ADDED] =
|
2012-01-26 09:08:47 +00:00
|
|
|
g_signal_new ("client-added", G_TYPE_FROM_CLASS (klass),
|
2013-04-25 07:20:29 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
|
2012-09-09 00:20:38 +00:00
|
|
|
1, G_TYPE_INT);
|
2012-01-26 09:08:47 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFdSink::client-removed:
|
|
|
|
* @gstmultifdsink: the multifdsink element that emitted this signal
|
|
|
|
* @fd: the file descriptor that is to be removed from multifdsink
|
|
|
|
* @status: the reason why the client was removed
|
|
|
|
*
|
|
|
|
* The given file descriptor is about to be removed from multifdsink. This
|
|
|
|
* signal will be emitted from the streaming thread so applications should
|
|
|
|
* be prepared for that.
|
|
|
|
*
|
|
|
|
* @gstmultifdsink still holds a handle to @fd so it is possible to call
|
|
|
|
* the get-stats signal from this callback. For the same reason it is
|
|
|
|
* not safe to close() and reuse @fd in this callback.
|
|
|
|
*/
|
2012-09-09 00:20:38 +00:00
|
|
|
gst_multi_fd_sink_signals[SIGNAL_CLIENT_REMOVED] =
|
2012-01-26 09:08:47 +00:00
|
|
|
g_signal_new ("client-removed", G_TYPE_FROM_CLASS (klass),
|
2013-04-25 07:20:29 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
2012-01-26 09:08:47 +00:00
|
|
|
G_TYPE_NONE, 2, G_TYPE_INT, GST_TYPE_CLIENT_STATUS);
|
|
|
|
/**
|
|
|
|
* GstMultiFdSink::client-fd-removed:
|
|
|
|
* @gstmultifdsink: the multifdsink element that emitted this signal
|
|
|
|
* @fd: the file descriptor that was removed from multifdsink
|
|
|
|
*
|
|
|
|
* The given file descriptor was removed from multifdsink. This signal will
|
|
|
|
* be emitted from the streaming thread so applications should be prepared
|
|
|
|
* for that.
|
|
|
|
*
|
|
|
|
* In this callback, @gstmultifdsink has removed all the information
|
|
|
|
* associated with @fd and it is therefore not possible to call get-stats
|
|
|
|
* with @fd. It is however safe to close() and reuse @fd in the callback.
|
|
|
|
*/
|
2012-09-09 01:00:49 +00:00
|
|
|
gst_multi_fd_sink_signals[SIGNAL_CLIENT_FD_REMOVED] =
|
|
|
|
g_signal_new ("client-fd-removed", G_TYPE_FROM_CLASS (klass),
|
2013-04-25 07:20:29 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
2012-01-26 09:08:47 +00:00
|
|
|
G_TYPE_NONE, 1, G_TYPE_INT);
|
|
|
|
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-01-26 09:08:47 +00:00
|
|
|
"Multi filedescriptor sink", "Sink/Network",
|
|
|
|
"Send data to multiple filedescriptors",
|
|
|
|
"Thomas Vander Stichele <thomas at apestaart dot org>, "
|
|
|
|
"Wim Taymans <wim@fluendo.com>");
|
|
|
|
|
2012-09-09 00:20:38 +00:00
|
|
|
klass->add = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add);
|
|
|
|
klass->add_full = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add_full);
|
|
|
|
klass->remove = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove);
|
|
|
|
klass->remove_flush = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove_flush);
|
|
|
|
klass->get_stats = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_get_stats);
|
|
|
|
|
|
|
|
gstmultihandlesink_class->emit_client_added =
|
|
|
|
gst_multi_fd_sink_emit_client_added;
|
|
|
|
gstmultihandlesink_class->emit_client_removed =
|
|
|
|
gst_multi_fd_sink_emit_client_removed;
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
gstmultihandlesink_class->stop_pre =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_stop_pre);
|
|
|
|
gstmultihandlesink_class->stop_post =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_stop_post);
|
|
|
|
gstmultihandlesink_class->start_pre =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_start_pre);
|
|
|
|
gstmultihandlesink_class->thread =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_thread);
|
2012-01-28 17:07:46 +00:00
|
|
|
gstmultihandlesink_class->new_client =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_new_client);
|
2012-09-09 00:20:38 +00:00
|
|
|
gstmultihandlesink_class->client_free = gst_multi_fd_sink_client_free;
|
2012-01-27 14:46:31 +00:00
|
|
|
gstmultihandlesink_class->client_get_fd =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_client_get_fd);
|
2012-01-28 10:02:21 +00:00
|
|
|
gstmultihandlesink_class->handle_debug =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_handle_debug);
|
2012-01-28 17:07:46 +00:00
|
|
|
gstmultihandlesink_class->handle_hash_key =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_handle_hash_key);
|
|
|
|
gstmultihandlesink_class->hash_changed =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_changed);
|
|
|
|
gstmultihandlesink_class->hash_adding =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_adding);
|
|
|
|
gstmultihandlesink_class->hash_removing =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_hash_removing);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (multifdsink_debug, "multifdsink", 0, "FD sink");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_init (GstMultiFdSink * this)
|
|
|
|
{
|
2012-01-28 17:06:02 +00:00
|
|
|
GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (this);
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
mhsink->handle_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
this->handle_read = DEFAULT_HANDLE_READ;
|
|
|
|
}
|
|
|
|
|
2012-09-09 00:20:38 +00:00
|
|
|
/* methods to emit signals */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_emit_client_added (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiSinkHandle handle)
|
|
|
|
{
|
|
|
|
g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_ADDED], 0,
|
|
|
|
handle.fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_emit_client_removed (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiSinkHandle handle, GstClientStatus status)
|
|
|
|
{
|
|
|
|
g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_REMOVED], 0,
|
|
|
|
handle.fd, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_client_free (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiHandleClient * client)
|
|
|
|
{
|
2012-09-09 01:00:49 +00:00
|
|
|
g_signal_emit (mhsink, gst_multi_fd_sink_signals[SIGNAL_CLIENT_FD_REMOVED],
|
|
|
|
0, client->handle.fd);
|
2012-09-09 00:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* action signals */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_add (GstMultiFdSink * sink, int fd)
|
|
|
|
{
|
|
|
|
GstMultiSinkHandle handle;
|
|
|
|
|
|
|
|
handle.fd = fd;
|
|
|
|
gst_multi_handle_sink_add (GST_MULTI_HANDLE_SINK_CAST (sink), handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GstMultiSinkHandle handle;
|
|
|
|
|
|
|
|
handle.fd = fd;
|
|
|
|
gst_multi_handle_sink_add_full (GST_MULTI_HANDLE_SINK_CAST (sink), handle,
|
|
|
|
sync, min_format, min_value, max_format, max_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_remove (GstMultiFdSink * sink, int fd)
|
|
|
|
{
|
|
|
|
GstMultiSinkHandle handle;
|
|
|
|
|
|
|
|
handle.fd = fd;
|
|
|
|
gst_multi_handle_sink_remove (GST_MULTI_HANDLE_SINK_CAST (sink), handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_remove_flush (GstMultiFdSink * sink, int fd)
|
|
|
|
{
|
|
|
|
GstMultiSinkHandle handle;
|
|
|
|
|
|
|
|
handle.fd = fd;
|
|
|
|
gst_multi_handle_sink_remove_flush (GST_MULTI_HANDLE_SINK_CAST (sink),
|
|
|
|
handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStructure *
|
|
|
|
gst_multi_fd_sink_get_stats (GstMultiFdSink * sink, int fd)
|
|
|
|
{
|
|
|
|
GstMultiSinkHandle handle;
|
|
|
|
|
|
|
|
handle.fd = fd;
|
|
|
|
return gst_multi_handle_sink_get_stats (GST_MULTI_HANDLE_SINK_CAST (sink),
|
|
|
|
handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vfuncs */
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static GstMultiHandleClient *
|
|
|
|
gst_multi_fd_sink_new_client (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiSinkHandle handle, GstSyncMethod sync_method)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-28 17:07:46 +00:00
|
|
|
struct stat statbuf;
|
2012-01-26 09:08:47 +00:00
|
|
|
GstTCPClient *client;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient;
|
2012-01-28 17:07:46 +00:00
|
|
|
GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
|
2012-01-28 10:02:21 +00:00
|
|
|
GstMultiHandleSinkClass *mhsinkclass =
|
|
|
|
GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* create client datastructure */
|
|
|
|
client = g_new0 (GstTCPClient, 1);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient = (GstMultiHandleClient *) client;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
mhclient->handle = handle;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_poll_fd_init (&client->gfd);
|
|
|
|
client->gfd.fd = mhclient->handle.fd;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_client_init (mhclient, sync_method);
|
|
|
|
mhsinkclass->handle_debug (handle, mhclient->debug);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* set the socket to non blocking */
|
2012-01-28 17:07:46 +00:00
|
|
|
if (fcntl (handle.fd, F_SETFL, O_NONBLOCK) < 0) {
|
2012-02-26 19:36:46 +00:00
|
|
|
GST_ERROR_OBJECT (mhsink, "failed to make socket %s non-blocking: %s",
|
2012-01-27 20:28:05 +00:00
|
|
|
mhclient->debug, g_strerror (errno));
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we always read from a client */
|
2012-01-28 10:02:21 +00:00
|
|
|
gst_poll_add_fd (sink->fdset, &client->gfd);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* we don't try to read from write only fds */
|
|
|
|
if (sink->handle_read) {
|
2012-01-28 17:07:46 +00:00
|
|
|
gint flags;
|
|
|
|
|
|
|
|
flags = fcntl (handle.fd, F_GETFL, 0);
|
2012-01-26 09:08:47 +00:00
|
|
|
if ((flags & O_ACCMODE) != O_WRONLY) {
|
2012-01-28 10:02:21 +00:00
|
|
|
gst_poll_fd_ctl_read (sink->fdset, &client->gfd, TRUE);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* figure out the mode, can't use send() for non sockets */
|
2012-01-28 17:07:46 +00:00
|
|
|
if (fstat (handle.fd, &statbuf) == 0 && S_ISSOCK (statbuf.st_mode)) {
|
2012-01-26 09:08:47 +00:00
|
|
|
client->is_socket = TRUE;
|
2012-01-27 14:46:31 +00:00
|
|
|
gst_multi_handle_sink_setup_dscp_client (mhsink, mhclient);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
return mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static int
|
|
|
|
gst_multi_fd_sink_client_get_fd (GstMultiHandleClient * client)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-28 17:07:46 +00:00
|
|
|
GstTCPClient *tclient = (GstTCPClient *) client;
|
2012-01-26 09:49:37 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
return tclient->gfd.fd;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_handle_debug (GstMultiSinkHandle handle, gchar debug[30])
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-28 17:07:46 +00:00
|
|
|
g_snprintf (debug, 30, "[fd %5d]", handle.fd);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static gpointer
|
|
|
|
gst_multi_fd_sink_handle_hash_key (GstMultiSinkHandle handle)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-28 17:07:46 +00:00
|
|
|
return GINT_TO_POINTER (handle.fd);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
static void
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_fd_sink_hash_changed (GstMultiHandleSink * mhsink)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
|
|
|
|
|
2012-01-26 09:08:47 +00:00
|
|
|
gst_poll_restart (sink->fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle a read on a client fd,
|
|
|
|
* which either indicates a close or should be ignored
|
|
|
|
* returns FALSE if some error occured or the client closed. */
|
|
|
|
static gboolean
|
|
|
|
gst_multi_fd_sink_handle_client_read (GstMultiFdSink * sink,
|
|
|
|
GstTCPClient * client)
|
|
|
|
{
|
|
|
|
int avail, fd;
|
|
|
|
gboolean ret;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 10:02:21 +00:00
|
|
|
fd = client->gfd.fd;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
if (ioctl (fd, FIONREAD, &avail) < 0)
|
|
|
|
goto ioctl_failed;
|
|
|
|
|
2012-01-27 20:28:05 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "%s select reports client read of %d bytes",
|
2012-01-28 10:02:21 +00:00
|
|
|
mhclient->debug, avail);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
if (avail == 0) {
|
|
|
|
/* client sent close, so remove it */
|
2012-01-28 10:02:21 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "%s client asked for close, removing",
|
|
|
|
mhclient->debug);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_CLOSED;
|
2012-01-26 09:08:47 +00:00
|
|
|
ret = FALSE;
|
|
|
|
} else if (avail < 0) {
|
2012-01-28 10:02:21 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "%s avail < 0, removing", mhclient->debug);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
guint8 dummy[512];
|
|
|
|
gint nread;
|
|
|
|
|
|
|
|
/* just Read 'n' Drop, could also just drop the client as it's not supposed
|
|
|
|
* to write to us except for closing the socket, I guess it's because we
|
|
|
|
* like to listen to our customers. */
|
|
|
|
do {
|
|
|
|
/* this is the maximum we can read */
|
|
|
|
gint to_read = MIN (avail, 512);
|
|
|
|
|
2012-01-27 20:28:05 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "%s client wants us to read %d bytes",
|
2012-01-28 10:02:21 +00:00
|
|
|
mhclient->debug, to_read);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
nread = read (fd, dummy, to_read);
|
|
|
|
if (nread < -1) {
|
2012-01-27 20:28:05 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "%s could not read %d bytes: %s (%d)",
|
2012-01-28 10:02:21 +00:00
|
|
|
mhclient->debug, to_read, g_strerror (errno), errno);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
} else if (nread == 0) {
|
2012-01-28 10:02:21 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "%s 0 bytes in read, removing",
|
|
|
|
mhclient->debug);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
avail -= nread;
|
|
|
|
}
|
|
|
|
while (avail > 0);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
ioctl_failed:
|
|
|
|
{
|
2012-01-27 20:28:05 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "%s ioctl failed: %s (%d)",
|
2012-01-28 10:02:21 +00:00
|
|
|
mhclient->debug, g_strerror (errno), errno);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle a write on a client,
|
|
|
|
* which indicates a read request from a client.
|
|
|
|
*
|
|
|
|
* For each client we maintain a queue of GstBuffers that contain the raw bytes
|
|
|
|
* we need to send to the client.
|
|
|
|
*
|
|
|
|
* We first check to see if we need to send streamheaders. If so, we queue them.
|
|
|
|
*
|
|
|
|
* Then we run into the main loop that tries to send as many buffers as
|
2012-01-26 09:49:37 +00:00
|
|
|
* possible. It will first exhaust the mhclient->sending queue and if the queue
|
2012-01-26 09:08:47 +00:00
|
|
|
* is empty, it will pick a buffer from the global queue.
|
|
|
|
*
|
2012-01-26 09:49:37 +00:00
|
|
|
* Sending the buffers from the mhclient->sending queue is basically writing
|
2012-01-26 09:08:47 +00:00
|
|
|
* the bytes to the socket and maintaining a count of the bytes that were
|
|
|
|
* sent. When the buffer is completely sent, it is removed from the
|
2012-01-26 09:49:37 +00:00
|
|
|
* mhclient->sending queue and we try to pick a new buffer for sending.
|
2012-01-26 09:08:47 +00:00
|
|
|
*
|
|
|
|
* When the sending returns a partial buffer we stop sending more data as
|
|
|
|
* the next send operation could block.
|
|
|
|
*
|
|
|
|
* This functions returns FALSE if some error occured.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
gst_multi_fd_sink_handle_client_write (GstMultiFdSink * sink,
|
|
|
|
GstTCPClient * client)
|
|
|
|
{
|
|
|
|
gboolean more;
|
|
|
|
gboolean flushing;
|
|
|
|
GstClockTime now;
|
|
|
|
GTimeVal nowtv;
|
2012-01-27 14:46:31 +00:00
|
|
|
GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (sink);
|
|
|
|
GstMultiHandleSinkClass *mhsinkclass =
|
|
|
|
GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
|
2012-01-28 17:07:46 +00:00
|
|
|
int fd = mhclient->handle.fd;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-26 09:49:37 +00:00
|
|
|
flushing = mhclient->status == GST_CLIENT_STATUS_FLUSHING;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
more = TRUE;
|
|
|
|
do {
|
|
|
|
gint maxsize;
|
|
|
|
|
2013-07-28 11:23:41 +00:00
|
|
|
g_get_current_time (&nowtv);
|
|
|
|
now = GST_TIMEVAL_TO_TIME (nowtv);
|
|
|
|
|
2012-01-26 09:49:37 +00:00
|
|
|
if (!mhclient->sending) {
|
2012-01-26 09:08:47 +00:00
|
|
|
/* client is not working on a buffer */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->bufpos == -1) {
|
2012-01-26 09:08:47 +00:00
|
|
|
/* client is too fast, remove from write queue until new buffer is
|
|
|
|
* available */
|
2012-09-10 10:45:17 +00:00
|
|
|
/* FIXME: specific */
|
2012-01-28 10:02:21 +00:00
|
|
|
gst_poll_fd_ctl_write (sink->fdset, &client->gfd, FALSE);
|
2012-09-10 10:45:17 +00:00
|
|
|
|
2012-01-26 09:08:47 +00:00
|
|
|
/* if we flushed out all of the client buffers, we can stop */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->flushcount == 0)
|
2012-01-26 09:08:47 +00:00
|
|
|
goto flushed;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
/* client can pick a buffer from the global queue */
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
/* for new connections, we need to find a good spot in the
|
|
|
|
* bufqueue to start streaming from */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->new_connection && !flushing) {
|
2012-01-28 17:07:46 +00:00
|
|
|
gint position =
|
|
|
|
gst_multi_handle_sink_new_client_position (mhsink, mhclient);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
if (position >= 0) {
|
|
|
|
/* we got a valid spot in the queue */
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->new_connection = FALSE;
|
|
|
|
mhclient->bufpos = position;
|
2012-01-26 09:08:47 +00:00
|
|
|
} else {
|
|
|
|
/* cannot send data to this client yet */
|
2012-09-10 10:45:17 +00:00
|
|
|
/* FIXME: specific */
|
2012-01-28 10:02:21 +00:00
|
|
|
gst_poll_fd_ctl_write (sink->fdset, &client->gfd, FALSE);
|
2012-01-26 09:08:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we flushed all remaining buffers, no need to get a new one */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->flushcount == 0)
|
2012-01-26 09:08:47 +00:00
|
|
|
goto flushed;
|
|
|
|
|
|
|
|
/* grab buffer */
|
2012-01-26 22:19:33 +00:00
|
|
|
buf = g_array_index (mhsink->bufqueue, GstBuffer *, mhclient->bufpos);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->bufpos--;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* update stats */
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->first_buffer_ts == GST_CLOCK_TIME_NONE)
|
|
|
|
mhclient->first_buffer_ts = timestamp;
|
2012-01-26 09:08:47 +00:00
|
|
|
if (timestamp != -1)
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->last_buffer_ts = timestamp;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* decrease flushcount */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->flushcount != -1)
|
|
|
|
mhclient->flushcount--;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-27 20:28:05 +00:00
|
|
|
GST_LOG_OBJECT (sink, "%s client %p at position %d",
|
|
|
|
mhclient->debug, client, mhclient->bufpos);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* queueing a buffer will ref it */
|
2012-01-27 14:46:31 +00:00
|
|
|
mhsinkclass->client_queue_buffer (mhsink, mhclient, buf);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* need to start from the first byte for this new buffer */
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->bufoffset = 0;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see if we need to send something */
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->sending) {
|
2012-01-26 09:08:47 +00:00
|
|
|
ssize_t wrote;
|
|
|
|
GstBuffer *head;
|
2012-01-26 09:41:22 +00:00
|
|
|
GstMapInfo info;
|
2012-01-26 09:08:47 +00:00
|
|
|
guint8 *data;
|
|
|
|
|
|
|
|
/* pick first buffer from list */
|
2012-01-26 09:49:37 +00:00
|
|
|
head = GST_BUFFER (mhclient->sending->data);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-08-08 09:11:48 +00:00
|
|
|
if (!gst_buffer_map (head, &info, GST_MAP_READ))
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
|
2012-01-26 09:41:22 +00:00
|
|
|
data = info.data;
|
2012-01-26 09:49:37 +00:00
|
|
|
maxsize = info.size - mhclient->bufoffset;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-09-10 10:45:17 +00:00
|
|
|
/* FIXME: specific */
|
2012-01-26 09:08:47 +00:00
|
|
|
/* try to write the complete buffer */
|
|
|
|
#ifdef MSG_NOSIGNAL
|
|
|
|
#define FLAGS MSG_NOSIGNAL
|
|
|
|
#else
|
|
|
|
#define FLAGS 0
|
|
|
|
#endif
|
|
|
|
if (client->is_socket) {
|
2012-01-26 09:49:37 +00:00
|
|
|
wrote = send (fd, data + mhclient->bufoffset, maxsize, FLAGS);
|
2012-01-26 09:08:47 +00:00
|
|
|
} else {
|
2012-01-26 09:49:37 +00:00
|
|
|
wrote = write (fd, data + mhclient->bufoffset, maxsize);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
2012-01-26 09:41:22 +00:00
|
|
|
gst_buffer_unmap (head, &info);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
if (wrote < 0) {
|
|
|
|
/* hmm error.. */
|
|
|
|
if (errno == EAGAIN) {
|
|
|
|
/* nothing serious, resource was unavailable, try again later */
|
|
|
|
more = FALSE;
|
|
|
|
} else if (errno == ECONNRESET) {
|
|
|
|
goto connection_reset;
|
|
|
|
} else {
|
|
|
|
goto write_error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (wrote < maxsize) {
|
|
|
|
/* partial write means that the client cannot read more and we should
|
|
|
|
* stop sending more */
|
|
|
|
GST_LOG_OBJECT (sink,
|
2012-02-26 19:36:46 +00:00
|
|
|
"partial write on %s of %" G_GSSIZE_FORMAT " bytes",
|
2012-01-27 20:28:05 +00:00
|
|
|
mhclient->debug, wrote);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->bufoffset += wrote;
|
2012-01-26 09:08:47 +00:00
|
|
|
more = FALSE;
|
|
|
|
} else {
|
|
|
|
/* complete buffer was written, we can proceed to the next one */
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->sending = g_slist_remove (mhclient->sending, head);
|
2012-01-26 09:08:47 +00:00
|
|
|
gst_buffer_unref (head);
|
|
|
|
/* make sure we start from byte 0 for the next buffer */
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->bufoffset = 0;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
/* update stats */
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->bytes_sent += wrote;
|
|
|
|
mhclient->last_activity_time = now;
|
|
|
|
mhsink->bytes_served += wrote;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (more);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
flushed:
|
|
|
|
{
|
2012-01-28 10:02:21 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "%s flushed, removing", mhclient->debug);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_REMOVED;
|
2012-01-26 09:08:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
connection_reset:
|
|
|
|
{
|
2012-01-28 10:02:21 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "%s connection reset by peer, removing",
|
|
|
|
mhclient->debug);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_CLOSED;
|
2012-01-26 09:08:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
write_error:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (sink,
|
2012-01-27 20:28:05 +00:00
|
|
|
"%s could not write, removing client: %s (%d)", mhclient->debug,
|
2012-01-26 09:08:47 +00:00
|
|
|
g_strerror (errno), errno);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_fd_sink_hash_adding (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiHandleClient * mhclient)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-27 14:46:31 +00:00
|
|
|
GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
|
2012-01-28 17:07:46 +00:00
|
|
|
GstTCPClient *client = (GstTCPClient *) mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_poll_fd_ctl_write (sink->fdset, &client->gfd, TRUE);
|
|
|
|
}
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_hash_removing (GstMultiHandleSink * mhsink,
|
|
|
|
GstMultiHandleClient * mhclient)
|
|
|
|
{
|
|
|
|
GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
|
|
|
|
GstTCPClient *client = (GstTCPClient *) mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_poll_remove_fd (sink->fdset, &client->gfd);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
|
2012-01-26 09:08:47 +00:00
|
|
|
/* Handle the clients. Basically does a blocking select for one
|
|
|
|
* of the client fds to become read or writable. We also have a
|
|
|
|
* filedescriptor to receive commands on that we need to check.
|
|
|
|
*
|
|
|
|
* After going out of the select call, we read and write to all
|
|
|
|
* clients that can do so. Badly behaving clients are put on a
|
|
|
|
* garbage list and removed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_handle_clients (GstMultiFdSink * sink)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
GList *clients, *next;
|
|
|
|
gboolean try_again;
|
|
|
|
GstMultiFdSinkClass *fclass;
|
|
|
|
guint cookie;
|
2012-01-26 22:19:33 +00:00
|
|
|
GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (sink);
|
2012-01-27 20:28:05 +00:00
|
|
|
int fd;
|
2012-01-26 09:49:37 +00:00
|
|
|
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
fclass = GST_MULTI_FD_SINK_GET_CLASS (sink);
|
|
|
|
|
|
|
|
do {
|
|
|
|
try_again = FALSE;
|
|
|
|
|
|
|
|
/* check for:
|
|
|
|
* - server socket input (ie, new client connections)
|
|
|
|
* - client socket input (ie, clients saying goodbye)
|
|
|
|
* - client socket output (ie, client reads) */
|
|
|
|
GST_LOG_OBJECT (sink, "waiting on action on fdset");
|
|
|
|
|
2012-01-26 09:49:37 +00:00
|
|
|
result =
|
|
|
|
gst_poll_wait (sink->fdset,
|
|
|
|
mhsink->timeout != 0 ? mhsink->timeout : GST_CLOCK_TIME_NONE);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
/* Handle the special case in which the sink is not receiving more buffers
|
|
|
|
* and will not disconnect inactive client in the streaming thread. */
|
|
|
|
if (G_UNLIKELY (result == 0)) {
|
|
|
|
GstClockTime now;
|
|
|
|
GTimeVal nowtv;
|
|
|
|
|
|
|
|
g_get_current_time (&nowtv);
|
|
|
|
now = GST_TIMEVAL_TO_TIME (nowtv);
|
|
|
|
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_LOCK (mhsink);
|
2012-01-26 22:19:33 +00:00
|
|
|
for (clients = mhsink->clients; clients; clients = next) {
|
2012-01-26 09:08:47 +00:00
|
|
|
GstTCPClient *client;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
client = (GstTCPClient *) clients->data;
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient = (GstMultiHandleClient *) client;
|
2012-01-26 09:08:47 +00:00
|
|
|
next = g_list_next (clients);
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhsink->timeout > 0
|
|
|
|
&& now - mhclient->last_activity_time > mhsink->timeout) {
|
|
|
|
mhclient->status = GST_CLIENT_STATUS_SLOW;
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_UNLOCK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
return;
|
|
|
|
} else if (result < 0) {
|
|
|
|
GST_WARNING_OBJECT (sink, "wait failed: %s (%d)", g_strerror (errno),
|
|
|
|
errno);
|
|
|
|
if (errno == EBADF) {
|
|
|
|
/* ok, so one or more of the fds is invalid. We loop over them to find
|
|
|
|
* the ones that give an error to the F_GETFL fcntl. */
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_LOCK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
restart:
|
2012-01-26 22:19:33 +00:00
|
|
|
cookie = mhsink->clients_cookie;
|
|
|
|
for (clients = mhsink->clients; clients; clients = next) {
|
2012-01-26 09:08:47 +00:00
|
|
|
GstTCPClient *client;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
long flags;
|
|
|
|
int res;
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
if (cookie != mhsink->clients_cookie) {
|
2012-01-26 09:08:47 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "Cookie changed finding bad fd");
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (GstTCPClient *) clients->data;
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient = (GstMultiHandleClient *) client;
|
2012-01-26 09:08:47 +00:00
|
|
|
next = g_list_next (clients);
|
|
|
|
|
2012-01-28 10:02:21 +00:00
|
|
|
fd = client->gfd.fd;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
res = fcntl (fd, F_GETFL, &flags);
|
|
|
|
if (res == -1) {
|
2015-12-16 11:12:00 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "fcntl failed for %d, removing: %s (%d)",
|
2012-01-26 09:08:47 +00:00
|
|
|
fd, g_strerror (errno), errno);
|
|
|
|
if (errno == EBADF) {
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-26 09:08:47 +00:00
|
|
|
/* releases the CLIENTS lock */
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_UNLOCK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
/* after this, go back in the select loop as the read/writefds
|
|
|
|
* are not valid */
|
|
|
|
try_again = TRUE;
|
|
|
|
} else if (errno == EINTR) {
|
|
|
|
/* interrupted system call, just redo the wait */
|
|
|
|
try_again = TRUE;
|
|
|
|
} else if (errno == EBUSY) {
|
|
|
|
/* the call to gst_poll_wait() was flushed */
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* this is quite bad... */
|
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, READ, (NULL),
|
|
|
|
("select failed: %s (%d)", g_strerror (errno), errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (sink, "wait done: %d sockets with events", result);
|
|
|
|
}
|
|
|
|
} while (try_again);
|
|
|
|
|
|
|
|
/* subclasses can check fdset with this virtual function */
|
|
|
|
if (fclass->wait)
|
|
|
|
fclass->wait (sink, sink->fdset);
|
|
|
|
|
|
|
|
/* Check the clients */
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_LOCK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
|
|
|
restart2:
|
2012-01-26 22:19:33 +00:00
|
|
|
cookie = mhsink->clients_cookie;
|
|
|
|
for (clients = mhsink->clients; clients; clients = next) {
|
2012-01-26 09:08:47 +00:00
|
|
|
GstTCPClient *client;
|
2012-01-26 09:49:37 +00:00
|
|
|
GstMultiHandleClient *mhclient;
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
if (mhsink->clients_cookie != cookie) {
|
2012-01-26 09:08:47 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "Restarting loop, cookie out of date");
|
|
|
|
goto restart2;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (GstTCPClient *) clients->data;
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient = (GstMultiHandleClient *) client;
|
2012-01-26 09:08:47 +00:00
|
|
|
next = g_list_next (clients);
|
|
|
|
|
2012-01-26 09:49:37 +00:00
|
|
|
if (mhclient->status != GST_CLIENT_STATUS_FLUSHING
|
|
|
|
&& mhclient->status != GST_CLIENT_STATUS_OK) {
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-28 10:02:21 +00:00
|
|
|
if (gst_poll_fd_has_closed (sink->fdset, &client->gfd)) {
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_CLOSED;
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-28 10:02:21 +00:00
|
|
|
if (gst_poll_fd_has_error (sink->fdset, &client->gfd)) {
|
|
|
|
GST_WARNING_OBJECT (sink, "gst_poll_fd_has_error for %d", client->gfd.fd);
|
2012-01-26 09:49:37 +00:00
|
|
|
mhclient->status = GST_CLIENT_STATUS_ERROR;
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-28 10:02:21 +00:00
|
|
|
if (gst_poll_fd_can_read (sink->fdset, &client->gfd)) {
|
2012-01-26 09:08:47 +00:00
|
|
|
/* handle client read */
|
|
|
|
if (!gst_multi_fd_sink_handle_client_read (sink, client)) {
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 10:02:21 +00:00
|
|
|
if (gst_poll_fd_can_write (sink->fdset, &client->gfd)) {
|
2012-01-26 09:08:47 +00:00
|
|
|
/* handle client write */
|
|
|
|
if (!gst_multi_fd_sink_handle_client_write (sink, client)) {
|
2012-01-28 17:07:46 +00:00
|
|
|
gst_multi_handle_sink_remove_client_link (mhsink, clients);
|
2012-01-26 09:08:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 17:07:46 +00:00
|
|
|
CLIENTS_UNLOCK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we handle the client communication in another thread so that we do not block
|
|
|
|
* the gstreamer thread while we select() on the client fds */
|
|
|
|
static gpointer
|
2012-01-26 22:19:33 +00:00
|
|
|
gst_multi_fd_sink_thread (GstMultiHandleSink * mhsink)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-26 22:19:33 +00:00
|
|
|
GstMultiFdSink *sink = GST_MULTI_FD_SINK (mhsink);
|
|
|
|
|
|
|
|
while (mhsink->running) {
|
2012-01-26 09:08:47 +00:00
|
|
|
gst_multi_fd_sink_handle_clients (sink);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMultiFdSink *multifdsink;
|
|
|
|
|
|
|
|
multifdsink = GST_MULTI_FD_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_HANDLE_READ:
|
|
|
|
multifdsink->handle_read = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMultiFdSink *multifdsink;
|
|
|
|
|
|
|
|
multifdsink = GST_MULTI_FD_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_HANDLE_READ:
|
|
|
|
g_value_set_boolean (value, multifdsink->handle_read);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-26 22:19:33 +00:00
|
|
|
gst_multi_fd_sink_start_pre (GstMultiHandleSink * mhsink)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-26 22:19:33 +00:00
|
|
|
GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-07-06 11:43:26 +00:00
|
|
|
GST_INFO_OBJECT (mfsink, "starting");
|
2012-01-26 22:19:33 +00:00
|
|
|
if ((mfsink->fdset = gst_poll_new (TRUE)) == NULL)
|
2012-01-26 09:08:47 +00:00
|
|
|
goto socket_pair;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
socket_pair:
|
|
|
|
{
|
2012-01-26 22:19:33 +00:00
|
|
|
GST_ELEMENT_ERROR (mfsink, RESOURCE, OPEN_READ_WRITE, (NULL),
|
2012-01-26 09:08:47 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
multifdsink_hash_remove (gpointer key, gpointer value, gpointer data)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_stop_pre (GstMultiHandleSink * mhsink)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-26 22:19:33 +00:00
|
|
|
GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
gst_poll_set_flushing (mfsink->fdset, TRUE);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
static void
|
|
|
|
gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink)
|
2012-01-26 09:08:47 +00:00
|
|
|
{
|
2012-01-26 22:19:33 +00:00
|
|
|
GstMultiFdSink *mfsink = GST_MULTI_FD_SINK (mhsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
|
2012-01-26 22:19:33 +00:00
|
|
|
if (mfsink->fdset) {
|
|
|
|
gst_poll_free (mfsink->fdset);
|
|
|
|
mfsink->fdset = NULL;
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|
2012-01-28 17:06:02 +00:00
|
|
|
g_hash_table_foreach_remove (mhsink->handle_hash, multifdsink_hash_remove,
|
2012-01-26 22:19:33 +00:00
|
|
|
mfsink);
|
2012-01-26 09:08:47 +00:00
|
|
|
}
|