• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gst/gst.h>
31 #define INET
32 #define INET6
33 #include <usrsctp.h>
34 
35 G_BEGIN_DECLS
36 
37 #define GST_SCTP_TYPE_ASSOCIATION                  (gst_sctp_association_get_type ())
38 #define GST_SCTP_ASSOCIATION(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociation))
39 #define GST_SCTP_IS_ASSOCIATION(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_SCTP_TYPE_ASSOCIATION))
40 #define GST_SCTP_ASSOCIATION_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociationClass))
41 #define GST_SCTP_IS_ASSOCIATION_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_SCTP_TYPE_ASSOCIATION))
42 #define GST_SCTP_ASSOCIATION_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_SCTP_TYPE_ASSOCIATION, GstSctpAssociationClass))
43 
44 typedef struct _GstSctpAssociation GstSctpAssociation;
45 typedef struct _GstSctpAssociationClass GstSctpAssociationClass;
46 
47 typedef enum
48 {
49   GST_SCTP_ASSOCIATION_STATE_NEW,
50   GST_SCTP_ASSOCIATION_STATE_READY,
51   GST_SCTP_ASSOCIATION_STATE_CONNECTING,
52   GST_SCTP_ASSOCIATION_STATE_CONNECTED,
53   GST_SCTP_ASSOCIATION_STATE_DISCONNECTING,
54   GST_SCTP_ASSOCIATION_STATE_DISCONNECTED,
55   GST_SCTP_ASSOCIATION_STATE_ERROR
56 } GstSctpAssociationState;
57 
58 typedef enum
59 {
60   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_NONE = 0x0000,
61   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_TTL = 0x0001,
62   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_BUF = 0x0002,
63   GST_SCTP_ASSOCIATION_PARTIAL_RELIABILITY_RTX = 0x0003
64 } GstSctpAssociationPartialReliability;
65 
66 typedef void (*GstSctpAssociationPacketReceivedCb) (GstSctpAssociation *
67     sctp_association, guint8 * data, gsize length, guint16 stream_id,
68     guint ppid, gpointer user_data);
69 typedef void (*GstSctpAssociationPacketOutCb) (GstSctpAssociation *
70     sctp_association, const guint8 * data, gsize length, gpointer user_data);
71 
72 struct _GstSctpAssociation
73 {
74   GObject parent_instance;
75 
76   guint32 association_id;
77   guint16 local_port;
78   guint16 remote_port;
79   gboolean use_sock_stream;
80   struct socket *sctp_ass_sock;
81 
82   GMutex association_mutex;
83 
84   GstSctpAssociationState state;
85 
86   GstSctpAssociationPacketReceivedCb packet_received_cb;
87   gpointer packet_received_user_data;
88   GDestroyNotify packet_received_destroy_notify;
89 
90   GstSctpAssociationPacketOutCb packet_out_cb;
91   gpointer packet_out_user_data;
92   GDestroyNotify packet_out_destroy_notify;
93 };
94 
95 struct _GstSctpAssociationClass
96 {
97   GObjectClass parent_class;
98 
99   void (*on_sctp_stream_reset) (GstSctpAssociation * sctp_association,
100       guint16 stream_id);
101 };
102 
103 GType gst_sctp_association_get_type (void);
104 
105 GstSctpAssociation *gst_sctp_association_get (guint32 association_id);
106 
107 gboolean gst_sctp_association_start (GstSctpAssociation * self);
108 void gst_sctp_association_set_on_packet_out (GstSctpAssociation * self,
109     GstSctpAssociationPacketOutCb packet_out_cb, gpointer user_data, GDestroyNotify destroy_notify);
110 void gst_sctp_association_set_on_packet_received (GstSctpAssociation * self,
111     GstSctpAssociationPacketReceivedCb packet_received_cb, gpointer user_data, GDestroyNotify destroy_notify);
112 void gst_sctp_association_incoming_packet (GstSctpAssociation * self,
113     const guint8 * buf, guint32 length);
114 GstFlowReturn gst_sctp_association_send_data (GstSctpAssociation * self,
115     const guint8 * buf, guint32 length, guint16 stream_id, guint32 ppid,
116     gboolean ordered, GstSctpAssociationPartialReliability pr,
117     guint32 reliability_param, guint32 *bytes_sent);
118 void gst_sctp_association_reset_stream (GstSctpAssociation * self,
119     guint16 stream_id);
120 void gst_sctp_association_force_close (GstSctpAssociation * self);
121 
122 G_END_DECLS
123 
124 #endif /* __GST_SCTP_ASSOCIATION_H__ */
125