1 /*
2  * Copyright (c) 2015, Collabora Ltd.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this
11  * list of conditions and the following disclaimer in the documentation and/or other
12  * materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
23  * OF SUCH DAMAGE.
24  */
25 
26 #ifndef __GST_SCTP_ASSOCIATION_H__
27 #define __GST_SCTP_ASSOCIATION_H__
28 
29 #include <glib-object.h>
30 #define INET
31 #define INET6
32 #include <usrsctp.h>
33 
34 G_BEGIN_DECLS
35 
36 #define GST_SCTP_TYPE_ASSOCIATION                  (gst_sctp_association_get_type ())
37 #define GST_SCTP_ASSOCIATION(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociation))
38 #define GST_SCTP_IS_ASSOCIATION(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_SCTP_TYPE_ASSOCIATION))
39 #define GST_SCTP_ASSOCIATION_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociationClass))
40 #define GST_SCTP_IS_ASSOCIATION_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_SCTP_TYPE_ASSOCIATION))
41 #define GST_SCTP_ASSOCIATION_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociationClass))
42 
43 typedef struct _GstSctpAssociation GstSctpAssociation;
44 typedef struct _GstSctpAssociationClass GstSctpAssociationClass;
45 
46 typedef enum
47 {
48   GST_SCTP_ASSOCIATION_STATE_NEW,
49   GST_SCTP_ASSOCIATION_STATE_READY,
50   GST_SCTP_ASSOCIATION_STATE_CONNECTING,
51   GST_SCTP_ASSOCIATION_STATE_CONNECTED,
52   GST_SCTP_ASSOCIATION_STATE_DISCONNECTING,
53   GST_SCTP_ASSOCIATION_STATE_DISCONNECTED,
54   GST_SCTP_ASSOCIATION_STATE_ERROR
55 } GstSctpAssociationState;
56 
57 typedef enum
58 {
59   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_NONE = 0x0000,
60   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_TTL = 0x0001,
61   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_BUF = 0x0002,
62   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_RTX = 0x0003
63 } GstSctpAssociationPartialReliability;
64 
65 typedef void (*GstSctpAssociationPacketReceivedCb) (GstSctpAssociation *
66     sctp_association, guint8 * data, gsize length, guint16 stream_id,
67     guint ppid, gpointer user_data);
68 typedef void (*GstSctpAssociationPacketOutCb) (GstSctpAssociation *
69     sctp_association, const guint8 * data, gsize length, gpointer user_data);
70 
71 struct _GstSctpAssociation
72 {
73   GObject parent_instance;
74 
75   guint32 association_id;
76   guint16 local_port;
77   guint16 remote_port;
78   gboolean use_sock_stream;
79   struct socket *sctp_ass_sock;
80 
81   GMutex association_mutex;
82 
83   GstSctpAssociationState state;
84 
85   GThread *connection_thread;
86 
87   GstSctpAssociationPacketReceivedCb packet_received_cb;
88   gpointer packet_received_user_data;
89 
90   GstSctpAssociationPacketOutCb packet_out_cb;
91   gpointer packet_out_user_data;
92 };
93 
94 struct _GstSctpAssociationClass
95 {
96   GObjectClass parent_class;
97 
98   void (*on_sctp_stream_reset) (GstSctpAssociation * sctp_association,
99       guint16 stream_id);
100 };
101 
102 GType gst_sctp_association_get_type (void);
103 
104 GstSctpAssociation *gst_sctp_association_get (guint32 association_id);
105 
106 gboolean gst_sctp_association_start (GstSctpAssociation * self);
107 void gst_sctp_association_set_on_packet_out (GstSctpAssociation * self,
108     GstSctpAssociationPacketOutCb packet_out_cb, gpointer user_data);
109 void gst_sctp_association_set_on_packet_received (GstSctpAssociation * self,
110     GstSctpAssociationPacketReceivedCb packet_received_cb, gpointer user_data);
111 void gst_sctp_association_incoming_packet (GstSctpAssociation * self,
112     guint8 * buf, guint32 length);
113 gboolean gst_sctp_association_send_data (GstSctpAssociation * self,
114     guint8 * buf, guint32 length, guint16 stream_id, guint32 ppid,
115     gboolean ordered, GstSctpAssociationPartialReliability pr,
116     guint32 reliability_param);
117 void gst_sctp_association_reset_stream (GstSctpAssociation * self,
118     guint16 stream_id);
119 void gst_sctp_association_force_close (GstSctpAssociation * self);
120 
121 G_END_DECLS
122 
123 #endif /* __GST_SCTP_ASSOCIATION_H__ */
124