gstmultifdsink.h 5.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
 *
 * 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
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
22 23
#ifndef __GST_MULTI_FD_SINK_H__
#define __GST_MULTI_FD_SINK_H__
24 25

#include <gst/gst.h>
Wim Taymans's avatar
Wim Taymans committed
26
#include <gst/base/gstbasesink.h>
27

Wim Taymans's avatar
Wim Taymans committed
28
G_BEGIN_DECLS
29 30

#include "gsttcp.h"
31
#include "gstfdset.h"
32

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
33 34 35 36 37 38 39 40 41 42 43 44
#define GST_TYPE_MULTI_FD_SINK \
  (gst_multi_fd_sink_get_type())
#define GST_MULTI_FD_SINK(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULTI_FD_SINK,GstMultiFdSink))
#define GST_MULTI_FD_SINK_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULTI_FD_SINK,GstMultiFdSink))
#define GST_IS_MULTI_FD_SINK(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULTI_FD_SINK))
#define GST_IS_MULTI_FD_SINK_CLASS(obj) \
  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULTI_FD_SINK))
#define GST_MULTI_FD_SINK_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MULTI_FD_SINK, GstMultiFdSinkClass))
45 46 47 48 49 50
	

typedef struct _GstMultiFdSink GstMultiFdSink;
typedef struct _GstMultiFdSinkClass GstMultiFdSinkClass;

typedef enum {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
51
  GST_MULTI_FD_SINK_OPEN             = (GST_ELEMENT_FLAG_LAST << 0),
52

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
53
  GST_MULTI_FD_SINK_FLAG_LAST        = (GST_ELEMENT_FLAG_LAST << 2),
54 55 56 57 58
} GstMultiFdSinkFlags;

typedef enum
{
  GST_RECOVER_POLICY_NONE,
59 60
  GST_RECOVER_POLICY_RESYNC_LATEST,
  GST_RECOVER_POLICY_RESYNC_SOFT_LIMIT,
61 62 63
  GST_RECOVER_POLICY_RESYNC_KEYFRAME,
} GstRecoverPolicy;

64 65
typedef enum
{
66 67 68
  GST_SYNC_METHOD_LATEST,
  GST_SYNC_METHOD_NEXT_KEYFRAME,
  GST_SYNC_METHOD_LATEST_KEYFRAME,
69 70
} GstSyncMethod;

71 72
typedef enum
{
73 74 75 76 77 78 79 80 81 82 83 84
  GST_UNIT_TYPE_BUFFERS,
  GST_UNIT_TYPE_TIME,
  GST_UNIT_TYPE_BYTES,
} GstUnitType;

typedef enum
{
  GST_CLIENT_STATUS_OK		= 0,
  GST_CLIENT_STATUS_CLOSED	= 1,
  GST_CLIENT_STATUS_REMOVED	= 2,
  GST_CLIENT_STATUS_SLOW	= 3,
  GST_CLIENT_STATUS_ERROR	= 4,
85
  GST_CLIENT_STATUS_DUPLICATE	= 5,
86 87
} GstClientStatus;

88 89 90
/* structure for a client
 *  */
typedef struct {
91 92
  GstFD fd;

93 94
  gint bufpos;                  /* position of this client in the global queue */

95
  GstClientStatus status;
96
  gboolean is_socket;
97

98
  GSList *sending;              /* the buffers we need to send */
99 100
  gint bufoffset;               /* offset in the first buffer */

101 102
  gboolean discont;

103
  GstTCPProtocol protocol;
104 105 106

  gboolean caps_sent;
  gboolean streamheader_sent;
107
  gboolean new_connection;
108 109 110 111 112

  /* stats */
  guint64 bytes_sent;
  guint64 connect_time;
  guint64 disconnect_time;
113
  guint64 last_activity_time;
114 115
  guint64 dropped_buffers;
  guint64 avg_queue_size;
116

117 118
} GstTCPClient;

Wim Taymans's avatar
Wim Taymans committed
119 120 121 122 123
#define CLIENTS_LOCK_INIT(fdsink)	(g_static_rec_mutex_init(&fdsink->clientslock))
#define CLIENTS_LOCK_FREE(fdsink)	(g_static_rec_mutex_free(&fdsink->clientslock))
#define CLIENTS_LOCK(fdsink)		(g_static_rec_mutex_lock(&fdsink->clientslock))
#define CLIENTS_UNLOCK(fdsink)		(g_static_rec_mutex_unlock(&fdsink->clientslock))

124
struct _GstMultiFdSink {
Wim Taymans's avatar
Wim Taymans committed
125
  GstBaseSink element;
126

127 128
  guint64 bytes_to_serve; /* how much bytes we must serve */
  guint64 bytes_served; /* how much bytes have we served */
129

Wim Taymans's avatar
Wim Taymans committed
130
  GStaticRecMutex clientslock;	/* lock to protect the clients list */
131
  GList *clients;	/* list of clients we are serving */
132
  GHashTable *fd_hash;  /* index on fd to client */
133

134 135 136 137
  GstFDSetMode mode;
  GstFDSet *fdset;

  GstFD control_sock[2];/* sockets for controlling the select call */
138

139
  GSList *streamheader; /* GSList of GstBuffers to use as streamheader */
140 141
  gboolean previous_buffer_in_caps;

142
  GstTCPProtocol protocol;
143 144 145 146 147 148 149
  guint mtu;

  GArray *bufqueue;	/* global queue of buffers */

  gboolean running;	/* the thread state */
  GThread *thread;	/* the sender thread */

150 151 152
  GstUnitType unit_type;/* the type of the units */
  gint units_max;	/* max units to queue */
  gint units_soft_max;	/* max units a client can lag before recovery starts */
153
  GstRecoverPolicy recover_policy;
154
  GstClockTime timeout;	/* max amount of nanoseconds to remain idle */
155
  GstSyncMethod sync_method;	/* what method to use for connecting clients */
156

157 158
  /* stats */
  gint buffers_queued;	/* number of queued buffers */
159 160
  gint bytes_queued;	/* number of queued bytes */
  gint time_queued;	/* number of queued time */
161 162 163
};

struct _GstMultiFdSinkClass {
Wim Taymans's avatar
Wim Taymans committed
164
  GstBaseSinkClass parent_class;
165

166
  /* element methods */
167 168 169 170
  void 		(*add)    	(GstMultiFdSink *sink, int fd);
  void 		(*remove) 	(GstMultiFdSink *sink, int fd);
  void 		(*clear)  	(GstMultiFdSink *sink);
  GValueArray* 	(*get_stats)  	(GstMultiFdSink *sink, int fd);
171 172

  /* vtable */
173
  gboolean (*init)   (GstMultiFdSink *sink);
174
  gboolean (*wait)   (GstMultiFdSink *sink, GstFDSet *set);
175
  gboolean (*close)  (GstMultiFdSink *sink);
176
  void (*removed) (GstMultiFdSink *sink, int fd);
177 178 179 180 181 182

  /* signals */
  void (*client_added) (GstElement *element, gchar *host, gint fd);
  void (*client_removed) (GstElement *element, gchar *host, gint fd);
};

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
183
GType gst_multi_fd_sink_get_type (void);
184

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
185 186 187 188
void gst_multi_fd_sink_add (GstMultiFdSink *sink, int fd);
void gst_multi_fd_sink_remove (GstMultiFdSink *sink, int fd);
void gst_multi_fd_sink_clear (GstMultiFdSink *sink);
GValueArray* gst_multi_fd_sink_get_stats (GstMultiFdSink *sink, int fd);
189

Wim Taymans's avatar
Wim Taymans committed
190
G_END_DECLS
191

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
192
#endif /* __GST_MULTI_FD_SINK_H__ */