1 /* GStreamer 2 * Copyright (C) <2005,2009> Wim Taymans <wim.taymans@gmail.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 * Unless otherwise indicated, Source Code is licensed under MIT license. 21 * See further explanation attached in License Statement (distributed in the file 22 * LICENSE). 23 * 24 * Permission is hereby granted, free of charge, to any person obtaining a copy of 25 * this software and associated documentation files (the "Software"), to deal in 26 * the Software without restriction, including without limitation the rights to 27 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 28 * of the Software, and to permit persons to whom the Software is furnished to do 29 * so, subject to the following conditions: 30 * 31 * The above copyright notice and this permission notice shall be included in all 32 * copies or substantial portions of the Software. 33 * 34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 40 * SOFTWARE. 41 */ 42 43 #ifndef __GST_RTSP_CONNECTION_H__ 44 #define __GST_RTSP_CONNECTION_H__ 45 46 #include <glib.h> 47 48 #include <gst/gstconfig.h> 49 #include <gst/rtsp/gstrtspdefs.h> 50 #include <gst/rtsp/gstrtspurl.h> 51 #include <gst/rtsp/gstrtspmessage.h> 52 #include <gio/gio.h> 53 54 G_BEGIN_DECLS 55 56 /** 57 * GstRTSPConnection: 58 * 59 * Opaque RTSP connection object. 60 */ 61 typedef struct _GstRTSPConnection GstRTSPConnection; 62 63 /* opening/closing a connection */ 64 65 GST_RTSP_API 66 GstRTSPResult gst_rtsp_connection_create (const GstRTSPUrl *url, GstRTSPConnection **conn); 67 68 GST_RTSP_API 69 GstRTSPResult gst_rtsp_connection_create_from_socket (GSocket * socket, 70 const gchar * ip, 71 guint16 port, 72 const gchar * initial_buffer, 73 GstRTSPConnection ** conn); 74 75 GST_RTSP_API 76 GstRTSPResult gst_rtsp_connection_accept (GSocket * socket, GstRTSPConnection ** conn, GCancellable * cancellable); 77 78 GST_RTSP_API 79 GstRTSPResult gst_rtsp_connection_connect (GstRTSPConnection * conn, GTimeVal * timeout); 80 81 GST_RTSP_API 82 GstRTSPResult gst_rtsp_connection_connect_with_response (GstRTSPConnection * conn, GTimeVal * timeout, GstRTSPMessage * response); 83 84 GST_RTSP_API 85 GstRTSPResult gst_rtsp_connection_close (GstRTSPConnection *conn); 86 87 GST_RTSP_API 88 GstRTSPResult gst_rtsp_connection_free (GstRTSPConnection *conn); 89 90 /* TLS connections */ 91 92 GST_RTSP_API 93 GTlsConnection * gst_rtsp_connection_get_tls (GstRTSPConnection * conn, GError ** error); 94 95 GST_RTSP_API 96 gboolean gst_rtsp_connection_set_tls_validation_flags (GstRTSPConnection * conn, GTlsCertificateFlags flags); 97 98 GST_RTSP_API 99 GTlsCertificateFlags gst_rtsp_connection_get_tls_validation_flags (GstRTSPConnection * conn); 100 101 GST_RTSP_API 102 void gst_rtsp_connection_set_tls_database (GstRTSPConnection * conn, GTlsDatabase * database); 103 104 GST_RTSP_API 105 GTlsDatabase * gst_rtsp_connection_get_tls_database (GstRTSPConnection * conn); 106 107 GST_RTSP_API 108 void gst_rtsp_connection_set_tls_interaction (GstRTSPConnection * conn, GTlsInteraction * interaction); 109 110 GST_RTSP_API 111 GTlsInteraction * gst_rtsp_connection_get_tls_interaction (GstRTSPConnection * conn); 112 113 typedef gboolean (*GstRTSPConnectionAcceptCertificateFunc) (GTlsConnection *conn, 114 GTlsCertificate *peer_cert, 115 GTlsCertificateFlags errors, 116 gpointer user_data); 117 GST_RTSP_API 118 void gst_rtsp_connection_set_accept_certificate_func (GstRTSPConnection * conn, 119 GstRTSPConnectionAcceptCertificateFunc func, 120 gpointer user_data, 121 GDestroyNotify destroy_notify); 122 123 /* sending/receiving raw bytes */ 124 125 GST_RTSP_API 126 GstRTSPResult gst_rtsp_connection_read (GstRTSPConnection * conn, guint8 * data, 127 guint size, GTimeVal * timeout); 128 129 GST_RTSP_API 130 GstRTSPResult gst_rtsp_connection_write (GstRTSPConnection * conn, const guint8 * data, 131 guint size, GTimeVal * timeout); 132 133 /* sending/receiving messages */ 134 135 GST_RTSP_API 136 GstRTSPResult gst_rtsp_connection_send (GstRTSPConnection *conn, GstRTSPMessage *message, 137 GTimeVal *timeout); 138 139 GST_RTSP_API 140 GstRTSPResult gst_rtsp_connection_send_messages (GstRTSPConnection *conn, GstRTSPMessage *messages, guint n_messages, 141 GTimeVal *timeout); 142 143 GST_RTSP_API 144 GstRTSPResult gst_rtsp_connection_receive (GstRTSPConnection *conn, GstRTSPMessage *message, 145 GTimeVal *timeout); 146 147 /* status management */ 148 149 GST_RTSP_API 150 GstRTSPResult gst_rtsp_connection_poll (GstRTSPConnection *conn, GstRTSPEvent events, 151 GstRTSPEvent *revents, GTimeVal *timeout); 152 153 /* reset the timeout */ 154 155 GST_RTSP_API 156 GstRTSPResult gst_rtsp_connection_next_timeout (GstRTSPConnection *conn, GTimeVal *timeout); 157 158 GST_RTSP_API 159 GstRTSPResult gst_rtsp_connection_reset_timeout (GstRTSPConnection *conn); 160 161 /* flushing state */ 162 163 GST_RTSP_API 164 GstRTSPResult gst_rtsp_connection_flush (GstRTSPConnection *conn, gboolean flush); 165 166 /* HTTP proxy support */ 167 168 GST_RTSP_API 169 GstRTSPResult gst_rtsp_connection_set_proxy (GstRTSPConnection *conn, 170 const gchar *host, guint port); 171 172 /* configure authentication data */ 173 174 GST_RTSP_API 175 GstRTSPResult gst_rtsp_connection_set_auth (GstRTSPConnection *conn, GstRTSPAuthMethod method, 176 const gchar *user, const gchar *pass); 177 178 GST_RTSP_API 179 void gst_rtsp_connection_set_auth_param (GstRTSPConnection *conn, 180 const gchar * param, 181 const gchar *value); 182 183 GST_RTSP_API 184 void gst_rtsp_connection_clear_auth_params (GstRTSPConnection *conn); 185 186 /* configure DSCP */ 187 188 GST_RTSP_API 189 GstRTSPResult gst_rtsp_connection_set_qos_dscp (GstRTSPConnection *conn, 190 guint qos_dscp); 191 192 /* accessors */ 193 194 GST_RTSP_API 195 GstRTSPUrl * gst_rtsp_connection_get_url (const GstRTSPConnection *conn); 196 197 GST_RTSP_API 198 const gchar * gst_rtsp_connection_get_ip (const GstRTSPConnection *conn); 199 200 GST_RTSP_API 201 void gst_rtsp_connection_set_ip (GstRTSPConnection *conn, const gchar *ip); 202 203 GST_RTSP_API 204 GSocket * gst_rtsp_connection_get_read_socket (const GstRTSPConnection *conn); 205 206 GST_RTSP_API 207 GSocket * gst_rtsp_connection_get_write_socket (const GstRTSPConnection *conn); 208 209 GST_RTSP_API 210 void gst_rtsp_connection_set_http_mode (GstRTSPConnection *conn, 211 gboolean enable); 212 213 /* tunneling */ 214 215 GST_RTSP_API 216 void gst_rtsp_connection_set_tunneled (GstRTSPConnection *conn, gboolean tunneled); 217 218 GST_RTSP_API 219 gboolean gst_rtsp_connection_is_tunneled (const GstRTSPConnection *conn); 220 221 GST_RTSP_API 222 const gchar * gst_rtsp_connection_get_tunnelid (const GstRTSPConnection *conn); 223 224 GST_RTSP_API 225 GstRTSPResult gst_rtsp_connection_do_tunnel (GstRTSPConnection *conn, GstRTSPConnection *conn2); 226 227 GST_RTSP_API 228 void gst_rtsp_connection_set_remember_session_id (GstRTSPConnection *conn, gboolean remember); 229 230 GST_RTSP_API 231 gboolean gst_rtsp_connection_get_remember_session_id (GstRTSPConnection *conn); 232 233 /* async IO */ 234 235 /** 236 * GstRTSPWatch: 237 * 238 * Opaque RTSP watch object that can be used for asynchronous RTSP 239 * operations. 240 */ 241 typedef struct _GstRTSPWatch GstRTSPWatch; 242 243 /** 244 * GstRTSPWatchFuncs: 245 * @message_received: callback when a message was received 246 * @message_sent: callback when a message was sent 247 * @closed: callback when the connection is closed 248 * @error: callback when an error occured 249 * @tunnel_start: a client started a tunneled connection. The tunnelid of the 250 * connection must be saved. 251 * @tunnel_complete: a client finished a tunneled connection. In this callback 252 * you usually pair the tunnelid of this connection with the saved one using 253 * gst_rtsp_connection_do_tunnel(). 254 * @error_full: callback when an error occured with more information than 255 * the @error callback. 256 * @tunnel_lost: callback when the post connection of a tunnel is closed. 257 * @tunnel_http_response: callback when an HTTP response to the GET request 258 * is about to be sent for a tunneled connection. The response can be 259 * modified in the callback. Since: 1.4. 260 * 261 * Callback functions from a #GstRTSPWatch. 262 */ 263 typedef struct { 264 GstRTSPResult (*message_received) (GstRTSPWatch *watch, GstRTSPMessage *message, 265 gpointer user_data); 266 GstRTSPResult (*message_sent) (GstRTSPWatch *watch, guint id, 267 gpointer user_data); 268 GstRTSPResult (*closed) (GstRTSPWatch *watch, gpointer user_data); 269 GstRTSPResult (*error) (GstRTSPWatch *watch, GstRTSPResult result, 270 gpointer user_data); 271 GstRTSPStatusCode (*tunnel_start) (GstRTSPWatch *watch, gpointer user_data); 272 GstRTSPResult (*tunnel_complete) (GstRTSPWatch *watch, gpointer user_data); 273 GstRTSPResult (*error_full) (GstRTSPWatch *watch, GstRTSPResult result, 274 GstRTSPMessage *message, guint id, 275 gpointer user_data); 276 GstRTSPResult (*tunnel_lost) (GstRTSPWatch *watch, gpointer user_data); 277 GstRTSPResult (*tunnel_http_response) (GstRTSPWatch *watch, 278 GstRTSPMessage *request, 279 GstRTSPMessage *response, 280 gpointer user_data); 281 282 /*< private >*/ 283 gpointer _gst_reserved[GST_PADDING-1]; 284 } GstRTSPWatchFuncs; 285 286 GST_RTSP_API 287 GstRTSPWatch * gst_rtsp_watch_new (GstRTSPConnection *conn, 288 GstRTSPWatchFuncs *funcs, 289 gpointer user_data, 290 GDestroyNotify notify); 291 292 GST_RTSP_API 293 void gst_rtsp_watch_reset (GstRTSPWatch *watch); 294 295 GST_RTSP_API 296 void gst_rtsp_watch_unref (GstRTSPWatch *watch); 297 298 GST_RTSP_API 299 guint gst_rtsp_watch_attach (GstRTSPWatch *watch, 300 GMainContext *context); 301 302 GST_RTSP_API 303 void gst_rtsp_watch_set_send_backlog (GstRTSPWatch *watch, 304 gsize bytes, guint messages); 305 306 GST_RTSP_API 307 void gst_rtsp_watch_get_send_backlog (GstRTSPWatch *watch, 308 gsize *bytes, guint *messages); 309 310 GST_RTSP_API 311 GstRTSPResult gst_rtsp_watch_write_data (GstRTSPWatch *watch, 312 const guint8 *data, 313 guint size, guint *id); 314 315 GST_RTSP_API 316 GstRTSPResult gst_rtsp_watch_send_message (GstRTSPWatch *watch, 317 GstRTSPMessage *message, 318 guint *id); 319 320 GST_RTSP_API 321 GstRTSPResult gst_rtsp_watch_send_messages (GstRTSPWatch *watch, 322 GstRTSPMessage *messages, 323 guint n_messages, 324 guint *id); 325 326 GST_RTSP_API 327 GstRTSPResult gst_rtsp_watch_wait_backlog (GstRTSPWatch * watch, 328 GTimeVal *timeout); 329 330 GST_RTSP_API 331 void gst_rtsp_watch_set_flushing (GstRTSPWatch * watch, 332 gboolean flushing); 333 G_END_DECLS 334 335 #endif /* __GST_RTSP_CONNECTION_H__ */ 336