• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef __GST_MULTIUDPSINK_H__
21 #define __GST_MULTIUDPSINK_H__
22 
23 #include <gst/gst.h>
24 #include <gst/base/gstbasesink.h>
25 #include <gio/gio.h>
26 
27 G_BEGIN_DECLS
28 
29 #include "gstudpnetutils.h"
30 
31 #define GST_TYPE_MULTIUDPSINK            (gst_multiudpsink_get_type())
32 #define GST_MULTIUDPSINK(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MULTIUDPSINK,GstMultiUDPSink))
33 #define GST_MULTIUDPSINK_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MULTIUDPSINK,GstMultiUDPSinkClass))
34 #define GST_IS_MULTIUDPSINK(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MULTIUDPSINK))
35 #define GST_IS_MULTIUDPSINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MULTIUDPSINK))
36 #define GST_MULTIUDPSINK_CAST(obj)       ((GstMultiUDPSink*)(obj))
37 
38 typedef struct _GstMultiUDPSink GstMultiUDPSink;
39 typedef struct _GstMultiUDPSinkClass GstMultiUDPSinkClass;
40 
41 typedef GOutputMessage GstOutputMessage;
42 
43 typedef struct {
44   gint ref_count;         /* for memory management */
45   gint add_count;         /* how often this address has been added */
46 
47   GSocketAddress *addr;
48   gchar *host;
49   gint port;
50 
51   /* Per-client stats */
52   guint64 bytes_sent;
53   guint64 packets_sent;
54   guint64 connect_time;
55   guint64 disconnect_time;
56 } GstUDPClient;
57 
58 /* sends udp packets to multiple host/port pairs.
59  */
60 struct _GstMultiUDPSink {
61   GstBaseSink parent;
62 
63   GSocket       *used_socket, *used_socket_v6;
64 
65   GCancellable  *cancellable;
66   gboolean       made_cancel_fd;
67 
68   /* client management */
69   GMutex         client_lock;
70   GList         *clients;
71   guint          num_v4_unique;  /* number IPv4 clients (excluding duplicates) */
72   guint          num_v4_all;     /* number IPv4 clients (including duplicates) */
73   guint          num_v6_unique;  /* number IPv6 clients (excluding duplicates) */
74   guint          num_v6_all;     /* number IPv6 clients (including duplicates) */
75   GList         *clients_to_be_removed;
76 
77   /* pre-allocated scrap space for render function */
78   GOutputVector    *vecs;
79   guint             n_vecs;
80   GstMapInfo       *maps;
81   guint             n_maps;
82   GstOutputMessage *messages;
83   guint             n_messages;
84 
85   /* properties */
86   guint64        bytes_to_serve;
87   guint64        bytes_served;
88   GSocket       *socket, *socket_v6;
89   gboolean       close_socket;
90 
91   gboolean       external_socket;
92 
93   gboolean       auto_multicast;
94   gchar         *multi_iface;
95   gint           ttl;
96   gint           ttl_mc;
97   gboolean       loop;
98   gboolean       force_ipv4;
99   gint           qos_dscp;
100 
101   gboolean       send_duplicates;
102   gint           buffer_size;
103   gchar         *bind_address;
104   gint           bind_port;
105 };
106 
107 struct _GstMultiUDPSinkClass {
108   GstBaseSinkClass parent_class;
109 
110   /* element methods */
111   void          (*add)          (GstMultiUDPSink *sink, const gchar *host, gint port);
112   void          (*remove)       (GstMultiUDPSink *sink, const gchar *host, gint port);
113   void          (*clear)        (GstMultiUDPSink *sink);
114   GstStructure* (*get_stats)    (GstMultiUDPSink *sink, const gchar *host, gint port);
115 
116   /* signals */
117   void          (*client_added) (GstElement *element, const gchar *host, gint port);
118   void          (*client_removed) (GstElement *element, const gchar *host, gint port);
119 };
120 
121 GType gst_multiudpsink_get_type(void);
122 
123 void            gst_multiudpsink_add            (GstMultiUDPSink *sink, const gchar *host, gint port);
124 void            gst_multiudpsink_remove         (GstMultiUDPSink *sink, const gchar *host, gint port);
125 void            gst_multiudpsink_clear          (GstMultiUDPSink *sink);
126 GstStructure*   gst_multiudpsink_get_stats      (GstMultiUDPSink *sink, const gchar *host, gint port);
127 
128 G_END_DECLS
129 
130 #endif /* __GST_MULTIUDPSINK_H__ */
131