gst/tcp/: Added multifdsink, made tcpserversink a subclass of fdsink, removed one...
[platform/upstream/gstreamer.git] / gst / tcp / gstmultifdsink.h
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  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21
22 #ifndef __GST_MULTIFDSINK_H__
23 #define __GST_MULTIFDSINK_H__
24
25
26 #include <gst/gst.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <sys/time.h>
38 #include <sys/types.h>
39 #include <netinet/in.h>
40 #include <netdb.h>
41 #include <sys/socket.h>
42 #include <sys/wait.h>
43 #include <fcntl.h>
44 #include <arpa/inet.h>
45 #include "gsttcp.h"
46
47 #define GST_TYPE_MULTIFDSINK \
48   (gst_multifdsink_get_type())
49 #define GST_MULTIFDSINK(obj) \
50   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULTIFDSINK,GstMultiFdSink))
51 #define GST_MULTIFDSINK_CLASS(klass) \
52   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULTIFDSINK,GstMultiFdSink))
53 #define GST_IS_MULTIFDSINK(obj) \
54   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULTIFDSINK))
55 #define GST_IS_MULTIFDSINK_CLASS(obj) \
56   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULTIFDSINK))
57 #define GST_MULTIFDSINK_GET_CLASS(obj) \
58   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MULTIFDSINK, GstMultiFdSinkClass))
59         
60
61 typedef struct _GstMultiFdSink GstMultiFdSink;
62 typedef struct _GstMultiFdSinkClass GstMultiFdSinkClass;
63
64 typedef enum {
65   GST_MULTIFDSINK_OPEN             = GST_ELEMENT_FLAG_LAST,
66
67   GST_MULTIFDSINK_FLAG_LAST        = GST_ELEMENT_FLAG_LAST + 2,
68 } GstMultiFdSinkFlags;
69
70 typedef enum
71 {
72   GST_RECOVER_POLICY_NONE,
73   GST_RECOVER_POLICY_RESYNC_START,
74   GST_RECOVER_POLICY_RESYNC_SOFT,
75   GST_RECOVER_POLICY_RESYNC_KEYFRAME,
76 } GstRecoverPolicy;
77
78 /* structure for a client
79  *  */
80 typedef struct {
81   int fd;
82   gint bufpos;                  /* position of this client in the global queue */
83
84   GList *sending;               /* the buffers we need to send */
85   gint bufoffset;               /* offset in the first buffer */
86
87   GstTCPProtocolType protocol;
88
89   gboolean caps_sent;
90   gboolean streamheader_sent;
91 } GstTCPClient;
92
93 struct _GstMultiFdSink {
94   GstElement element;
95
96   /* pad */
97   GstPad *sinkpad;
98
99   size_t data_written; /* how much bytes have we written ? */
100
101   GMutex *clientslock;  /* lock to protect the clients list */
102   GList *clients;       /* list of clients we are serving */
103   
104   fd_set readfds; /* all the client file descriptors that we can read from */
105   fd_set writefds; /* all the client file descriptors that we can write to */
106
107   int control_sock[2];  /* sockets for controlling the select call */
108
109   GList *streamheader; /* GList of GstBuffers to use as streamheader */
110   GstTCPProtocolType protocol;
111   guint mtu;
112
113   GArray *bufqueue;     /* global queue of buffers */
114
115   gboolean running;     /* the thread state */
116   GThread *thread;      /* the sender thread */
117
118   gint buffers_max;     /* max buffers to queue */
119   gint buffers_soft_max;        /* max buffers a client can lay before recoevery starts */
120   GstRecoverPolicy recover_policy;
121   /* stats */
122   gint buffers_queued;  /* number of queued buffers */
123 };
124
125 struct _GstMultiFdSinkClass {
126   GstElementClass parent_class;
127
128   gboolean (*init)   (GstMultiFdSink *sink);
129   gboolean (*select) (GstMultiFdSink *sink, fd_set *readfds, fd_set *writefds);
130   gboolean (*close)  (GstMultiFdSink *sink);
131
132   /* signals */
133   void (*client_added) (GstElement *element, gchar *host, gint fd);
134   void (*client_removed) (GstElement *element, gchar *host, gint fd);
135 };
136
137 GType gst_multifdsink_get_type (void);
138
139
140 #ifdef __cplusplus
141 }
142 #endif /* __cplusplus */
143
144
145 #endif /* __GST_MULTIFDSINK_H__ */